Exemple #1
0
        protected override void AwakeActions()
        {
            KlyteMonoUtils.CreateUIElement(out UIPanel layoutPanel, MainPanel.transform, "LayoutPanel", new Vector4(0, 40, PanelWidth, PanelHeight - 40));
            layoutPanel.padding             = new RectOffset(8, 8, 10, 10);
            layoutPanel.autoLayout          = true;
            layoutPanel.autoLayoutDirection = LayoutDirection.Vertical;
            layoutPanel.autoLayoutPadding   = new RectOffset(0, 0, 10, 10);
            var uiHelper = new UIHelperExtension(layoutPanel);

            CreateSlider(uiHelper, "K45_TR_TREES_IN_TERRAIN", new Action <int>(FactorsData.Instance.SetMultiplierTree), new Func <int>(FactorsData.Instance.GetMultiplierTree));
            CreateSlider(uiHelper, "K45_TR_TREES_IN_LOTS", new Action <int>(FactorsData.Instance.SetMultiplierBuilding), new Func <int>(FactorsData.Instance.GetMultiplierBuilding));
            CreateSlider(uiHelper, "K45_TR_TREES_IN_ROADS", new Action <int>(FactorsData.Instance.SetMultiplierNet), new Func <int>(FactorsData.Instance.GetMultiplierNet));


            UILabel  labelAccuracy  = null;
            UISlider accuracySlider = uiHelper.AddSlider(Locale.Get("K45_TR_SIMULATION_ACCURACY"), 1, TRController.MAX_ACCURACY_VALUE, 1, FactorsData.Instance.GetSimulationAccuracy(), (x) =>
            {
                FactorsData.Instance.SetSimulationAccuracy(Mathf.RoundToInt(x));
                labelAccuracy.suffix = (1 << Mathf.RoundToInt(x + 3)).ToString();
                TreesRespirationMod.Controller.UpdateDivisors();
            }, out labelAccuracy);

            accuracySlider.width         = PanelWidth - 15;
            labelAccuracy.width          = PanelWidth - 15;
            labelAccuracy.minimumSize    = new Vector2(PanelWidth - 15, 0);
            labelAccuracy.suffix         = (1 << Mathf.RoundToInt(FactorsData.Instance.GetSimulationAccuracy() + 3)).ToString();
            labelAccuracy.parent.tooltip = Locale.Get("K45_TR_SIMULATION_ACCURACY_TOOLTIP");
            labelAccuracy.wordWrap       = false;
            ((UIPanel)(labelAccuracy.parent)).autoLayoutPadding = new RectOffset();
            KlyteMonoUtils.LimitWidthAndBox(labelAccuracy);
        }
Exemple #2
0
        public UISlider GenerateSliderField(UIHelperExtension uiHelper, OnValueChanged action, out UILabel label, out UIPanel container)
        {
            var budgetMultiplier = (UISlider)uiHelper.AddSlider("", 0f, 5, 0.05f, 1, action);

            label           = budgetMultiplier.transform.parent.GetComponentInChildren <UILabel>();
            label.autoSize  = true;
            label.wordWrap  = false;
            label.text      = string.Format(" x{0:0.00}", 0);
            container       = budgetMultiplier.GetComponentInParent <UIPanel>();
            container.width = 300;
            container.autoLayoutDirection = LayoutDirection.Horizontal;
            container.autoLayoutPadding   = new RectOffset(5, 5, 3, 3);
            container.wrapLayout          = true;
            return(budgetMultiplier);
        }
        private static UISlider GenerateBudgetMultiplierField(UIHelperExtension uiHelper, string title, OnValueChanged action, out UILabel label, out UIPanel panel)
        {
            UISlider budgetMultiplier = (UISlider)uiHelper.AddSlider(Locale.Get("TLM_BUDGET_MULTIPLIER_LABEL"), 0f, 5, 0.05f, 1, action);

            label                     = budgetMultiplier.transform.parent.GetComponentInChildren <UILabel>();
            label.prefix              = title;
            label.autoSize            = true;
            label.wordWrap            = false;
            label.text                = string.Format(" x{0:0.00}", 0);
            panel                     = budgetMultiplier.GetComponentInParent <UIPanel>();
            panel.width               = 300;
            panel.autoLayoutDirection = LayoutDirection.Horizontal;
            panel.autoLayoutPadding   = new RectOffset(5, 5, 3, 3);
            panel.wrapLayout          = true;
            return(budgetMultiplier);
        }
Exemple #4
0
        private void CreateSlider(UIHelperExtension uiHelper, string labelContent, Action <int> setter, Func <int> getter)
        {
            UILabel  label  = null;
            UISlider slider = uiHelper.AddSlider(Locale.Get(labelContent), 0, 9, 1, getter(), (x) =>
            {
                setter(x < 0.1 ? 0 : 1 << Mathf.RoundToInt(x - 1));
                label.suffix = getter().ToString();
            }, out label);

            slider.width      = PanelWidth - 15;
            label.minimumSize = new Vector2(PanelWidth - 15, 0);
            label.suffix      = getter().ToString();
            label.wordWrap    = false;
            KlyteMonoUtils.LimitWidthAndBox(label);
            ((UIPanel)(label.parent)).autoLayoutPadding = new RectOffset();
        }
Exemple #5
0
        private UISlider GenerateVerticalBudgetMultiplierField(UIHelperExtension uiHelper, int idx)
        {
            UISlider bugdetSlider = (UISlider)uiHelper.AddSlider(Locale.Get("TLM_BUDGET_MULTIPLIER_LABEL"), 0f, 5, 0.05f, -1,
                                                                 (x) =>
            {
            });
            UILabel budgetSliderLabel = bugdetSlider.transform.parent.GetComponentInChildren <UILabel>();
            UIPanel budgetSliderPanel = bugdetSlider.GetComponentInParent <UIPanel>();

            budgetSliderPanel.relativePosition = new Vector2(45 * idx + 15, 50);
            budgetSliderPanel.width            = 40;
            budgetSliderPanel.height           = 160;
            bugdetSlider.zOrder          = 0;
            budgetSliderPanel.autoLayout = true;

            bugdetSlider.size = new Vector2(40, 100);
            bugdetSlider.scrollWheelAmount = 0;
            bugdetSlider.orientation       = UIOrientation.Vertical;
            bugdetSlider.clipChildren      = true;
            bugdetSlider.thumbOffset       = new Vector2(0, -100);
            bugdetSlider.color             = Color.black;

            bugdetSlider.thumbObject.width  = 40;
            bugdetSlider.thumbObject.height = 200;
            ((UISprite)bugdetSlider.thumbObject).spriteName = "ScrollbarThumb";
            ((UISprite)bugdetSlider.thumbObject).color      = new Color32(1, 140, 46, 255);

            budgetSliderLabel.textScale     = 0.5f;
            budgetSliderLabel.autoSize      = false;
            budgetSliderLabel.wordWrap      = true;
            budgetSliderLabel.pivot         = UIPivotPoint.TopCenter;
            budgetSliderLabel.textAlignment = UIHorizontalAlignment.Center;
            budgetSliderLabel.text          = string.Format(" x{0:0.00}", 0);
            budgetSliderLabel.prefix        = Locale.Get("TLM_BUDGET_MULTIPLIER_PERIOD_LABEL", idx);
            budgetSliderLabel.width         = 40;
            budgetSliderLabel.font          = UIHelperExtension.defaultFontCheckbox;

            var idx_loc = idx;

            bugdetSlider.eventValueChanged += delegate(UIComponent c, float val)
            {
                budgetSliderLabel.text = string.Format(" x{0:0.00}", val);
                setBudgetHour(val, idx_loc);
            };

            return(bugdetSlider);
        }
Exemple #6
0
        public static void AddSlider(string label, out UISlider slider, UIHelperExtension parentHelper, OnValueChanged onChange, float min, float max, float step, Func <float, string> valueLabelFunc)
        {
            UILabel labelValue = null;

            slider = (UISlider)parentHelper.AddSlider(label, min, max, step, min, (x) =>
            {
                onChange(x);
                labelValue.text = valueLabelFunc(x);
            });
            slider.GetComponentInParent <UIPanel>().autoLayoutDirection       = LayoutDirection.Horizontal;
            slider.GetComponentInParent <UIPanel>().autoFitChildrenVertically = true;
            KlyteMonoUtils.LimitWidthAndBox(slider.parent.GetComponentInChildren <UILabel>(), (parentHelper.Self.width / 2) - 10, true);
            labelValue = slider.GetComponentInParent <UIPanel>().AddUIComponent <UILabel>();
            labelValue.textAlignment = UIHorizontalAlignment.Center;
            labelValue.padding       = new RectOffset(4, 4, 0, 0);
            KlyteMonoUtils.LimitWidthAndBox(labelValue, (parentHelper.Self.width / 2) - slider.width, true);
        }