private void SetProbingRadiusUI(int radius)
        {
            if ((UnityEngine.Object) this.target == (UnityEngine.Object)null || (UnityEngine.Object) this.configurator == (UnityEngine.Object)null)
            {
                return;
            }

            PSliderSingle.SetCurrentValue(this.ProbingRadiusSlider, radius);

            StationaryChoreRangeVisualizer choreRangeVisualizer = this.target.GetComponent <StationaryChoreRangeVisualizer>();

            if ((UnityEngine.Object)choreRangeVisualizer == (UnityEngine.Object)null)
            {
                return;
            }

            choreRangeVisualizer.x     = -radius;
            choreRangeVisualizer.width = 2 + 2 * radius;
            Traverse.Create(choreRangeVisualizer).Method("UpdateVisualizers").GetValue();

            if ((UnityEngine.Object) this.ProbingRadiusText == (UnityEngine.Object)null)
            {
                return;
            }

            PUIElements.SetText(this.ProbingRadiusText, radius.ToString("0"));
        }
        /// <summary>
        /// Updates the displayed value.
        /// </summary>
        protected override void Update()
        {
            var field = textField?.GetComponentInChildren <TMP_InputField>();

            if (field != null)
            {
                field.text = FieldText;
            }
            if (slider != null && value != null)
            {
                PSliderSingle.SetCurrentValue(slider, (float)value);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Updates the displayed value.
        /// </summary>
        protected override void Update()
        {
            var field = textField?.GetComponentInChildren <TMP_InputField>();

            if (field != null)
            {
                field.text = value.ToString(Format ?? "D");
            }
            if (slider != null)
            {
                PSliderSingle.SetCurrentValue(slider, value);
            }
        }
        private void SetMovespeedUI(float speed)
        {
            if ((UnityEngine.Object) this.target == (UnityEngine.Object)null || (UnityEngine.Object) this.configurator == (UnityEngine.Object)null)
            {
                return;
            }

            PSliderSingle.SetCurrentValue(this.MoveSpeedSlider, speed);

            if ((UnityEngine.Object) this.MoveSpeedText == (UnityEngine.Object)null)
            {
                return;
            }
            PUIElements.SetText(this.MoveSpeedText, speed.ToString("0.00"));
        }
Esempio n. 5
0
        public static PPanel AddSliderBox(this PPanel parent, string prefix, string name, float min, float max, Action <float> onValueUpdate, out Action <float> setValue, Func <float, string> customTooltip = null)
        {
            float      value     = 0;
            GameObject text_go   = null;
            GameObject slider_go = null;

            setValue = newValue =>
            {
                value = newValue;
                Update();
            };
            if (!(min > float.NegativeInfinity && max < float.PositiveInfinity && min < max))
            {
                PUtil.LogError("Invalid min max parameters");
                return(parent);
            }
            prefix = (prefix + name).ToUpperInvariant();

            void Update()
            {
                var field = text_go?.GetComponentInChildren <TMP_InputField>();

                if (field != null)
                {
                    field.text = value.ToString("F0");
                }
                if (slider_go != null)
                {
                    PSliderSingle.SetCurrentValue(slider_go, value);
                }
                onValueUpdate?.Invoke(value);
            }

            void OnTextChanged(GameObject _, string text)
            {
                if (float.TryParse(text, out float newValue))
                {
                    value = Mathf.Clamp(newValue, min, max);
                }
                Update();
            }

            void OnSliderChanged(GameObject _, float newValue)
            {
                value = Mathf.Clamp(Mathf.Round(newValue), min, max);
                Update();
            }

            var small    = PUITuning.Fonts.TextDarkStyle.DeriveStyle(size: 12);
            var minLabel = new PLabel("min_" + name)
            {
                TextStyle = small,
                Text      = string.Format(Strings.Get(prefix + ".MIN_MAX"), min),
            };
            var maxLabel = new PLabel("max_" + name)
            {
                TextStyle = small,
                Text      = string.Format(Strings.Get(prefix + ".MIN_MAX"), max),
            };
            var preLabel = new PLabel("pre_" + name)
            {
                TextStyle = PUITuning.Fonts.TextDarkStyle,
                Text      = Strings.Get(prefix + ".PRE"),
            };
            var pstLabel = new PLabel("pst_" + name)
            {
                TextStyle = PUITuning.Fonts.TextDarkStyle,
                Text      = Strings.Get(prefix + ".PST"),
            };

            var textField = new PTextField("text_" + name)
            {
                MinWidth      = 40,
                Type          = PTextField.FieldType.Integer,
                OnTextChanged = OnTextChanged,
            }.AddOnRealize(realized => text_go = realized);

            var margin    = new RectOffset(12, 12, 0, 0);
            var panel_top = new PPanel("slider_top_" + name)
            {
                Alignment = TextAnchor.MiddleCenter,
                Direction = PanelDirection.Horizontal,
                FlexSize  = Vector2.right,
                Margin    = margin,
                Spacing   = 4,
            };

            panel_top.AddChild(minLabel).AddChild(new PSpacer()).AddChild(preLabel)
            .AddChild(textField).AddChild(pstLabel).AddChild(new PSpacer()).AddChild(maxLabel);

            var slider = new PSliderSingle("slider_" + name)
            {
                MinValue       = min,
                MaxValue       = max,
                IntegersOnly   = true,
                Direction      = UnityEngine.UI.Slider.Direction.LeftToRight,
                FlexSize       = Vector2.right,
                HandleSize     = 24,
                TrackSize      = 16,
                ToolTip        = Strings.Get(prefix + ".TOOLTIP"),
                OnDrag         = OnSliderChanged,
                OnValueChanged = OnSliderChanged,
            }.AddOnRealize(realized =>
            {
                slider_go = realized;
                if (customTooltip != null)
                {
                    var ks      = slider_go.GetComponent <KSlider>();
                    var toolTip = slider_go.GetComponent <ToolTip>();
                    if (ks != null && toolTip != null)
                    {
                        toolTip.OnToolTip            = () => customTooltip(ks.value);
                        toolTip.refreshWhileHovering = true;
                    }
                }
            });

            var panel_bottom = new PPanel("slider_bottom_" + name)
            {
                Alignment = TextAnchor.MiddleCenter,
                Direction = PanelDirection.Horizontal,
                FlexSize  = Vector2.right,
                Margin    = margin,
                Spacing   = 4,
            };

            panel_bottom.AddChild(slider);
            return(parent.AddChild(panel_top).AddChild(panel_bottom));
        }