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); } }
/// <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")); }
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)); }
protected override void OnPrefabInit() { Color backColour = new Color(0.998f, 0.998f, 0.998f); RectOffset rectOffset = new RectOffset(8, 8, 8, 8); PPanel moveTitle_panel = new PPanel("MovespeedTitleRow"); moveTitle_panel.BackColor = backColour; moveTitle_panel.Alignment = TextAnchor.MiddleCenter; moveTitle_panel.Direction = PanelDirection.Horizontal; moveTitle_panel.Spacing = 10; moveTitle_panel.Margin = rectOffset; moveTitle_panel.FlexSize = Vector2.right; PLabel moveTitle_label = new PLabel("MovespeedTitleLabel"); moveTitle_label.TextAlignment = TextAnchor.MiddleRight; moveTitle_label.Text = SweepyStrings.MoveSpeedTitleName; moveTitle_label.ToolTip = SweepyStrings.MoveSpeedTitleTooltip; moveTitle_label.TextStyle = PUITuning.Fonts.TextDarkStyle; PTextField moveTitle_textField = new PTextField("MovespeedSliderTextField") { Text = SweepyConfigChecker.BaseMovementSpeed.ToString("0.00"), MaxLength = 10, }; moveTitle_textField.OnTextChanged = this.ChangeTextFieldMovespeed; moveTitle_textField.OnRealize += (PUIDelegates.OnRealize)(obj => this.MoveSpeedText = obj); PPanel moveTitle_components = moveTitle_panel.AddChild((IUIComponent)moveTitle_label); moveTitle_components = moveTitle_panel.AddChild((IUIComponent)moveTitle_textField); moveTitle_components.AddTo(this.gameObject, -2); PPanel moveSlider_panel = new PPanel("MovespeedSliderRow"); moveSlider_panel.BackColor = backColour; moveSlider_panel.ImageMode = Image.Type.Sliced; moveSlider_panel.Alignment = TextAnchor.MiddleCenter; moveSlider_panel.Direction = PanelDirection.Horizontal; moveSlider_panel.Spacing = 10; moveSlider_panel.Margin = new RectOffset(8, 8, 6, 32); moveSlider_panel.FlexSize = Vector2.right; PLabel moveSliderMin_label = new PLabel("MovespeedSliderMinLabel"); moveSliderMin_label.Text = Mathf.RoundToInt(SweepyConfigChecker.MinSpeedSliderValue).ToString(); moveSliderMin_label.TextStyle = PUITuning.Fonts.TextDarkStyle; PPanel moveSlider_components = moveSlider_panel.AddChild((IUIComponent)moveSliderMin_label); PSliderSingle moveSpeedSlider = new PSliderSingle("Movespeed") { Direction = Slider.Direction.LeftToRight, HandleColor = PUITuning.Colors.ButtonPinkStyle, HandleSize = 16.0f, InitialValue = SweepyConfigChecker.BaseMovementSpeed, IntegersOnly = false, MaxValue = SweepyConfigChecker.MaxSpeedSliderValue, MinValue = SweepyConfigChecker.MinSpeedSliderValue, PreferredLength = 140.0f, TrackSize = 16.0f, }; moveSpeedSlider.OnRealize += (PUIDelegates.OnRealize)(obj => this.MoveSpeedSlider = obj); moveSpeedSlider.OnValueChanged = ChangeMovespeed; moveSlider_components.AddChild(moveSpeedSlider); PLabel moveSliderMax_label = new PLabel("MovespeedSliderMaxLabel"); moveSliderMax_label.Text = Mathf.RoundToInt(SweepyConfigChecker.MaxSpeedSliderValue).ToString(); moveSliderMax_label.TextStyle = PUITuning.Fonts.TextDarkStyle; moveSlider_components.AddChild(moveSliderMax_label); moveSlider_components.AddTo(this.gameObject, -2); PPanel probingTitle_panel = new PPanel("ProbingRadiusTitleRow"); probingTitle_panel.BackColor = backColour; probingTitle_panel.Alignment = TextAnchor.MiddleCenter; probingTitle_panel.Direction = PanelDirection.Horizontal; probingTitle_panel.Spacing = 10; probingTitle_panel.Margin = rectOffset; probingTitle_panel.FlexSize = Vector2.right; PLabel probingTitle_label = new PLabel("ProbingRadiusTitleLabel"); probingTitle_label.TextAlignment = TextAnchor.MiddleRight; probingTitle_label.Text = SweepyStrings.ProbingRadiusTitleName; probingTitle_label.ToolTip = SweepyStrings.ProbingRadiusTitleTooltip; probingTitle_label.TextStyle = PUITuning.Fonts.TextDarkStyle; PTextField probingTitle_TextField = new PTextField("ProbingSliderTextField") { Text = SweepyConfigChecker.BaseProbingRadius.ToString("0"), MaxLength = 8, }; probingTitle_TextField.OnTextChanged = this.ChangeTextFieldProbingRadius; probingTitle_TextField.OnRealize += (PUIDelegates.OnRealize)(obj => this.ProbingRadiusText = obj); PPanel probingTitle_components = probingTitle_panel.AddChild((IUIComponent)probingTitle_label); probingTitle_components = probingTitle_panel.AddChild((IUIComponent)probingTitle_TextField); probingTitle_components.AddTo(this.gameObject, -2); PPanel probingSlider_panel = new PPanel("ProbingRadiusSliderRow"); probingSlider_panel.BackColor = backColour; probingSlider_panel.ImageMode = Image.Type.Sliced; probingSlider_panel.Alignment = TextAnchor.MiddleCenter; probingSlider_panel.Direction = PanelDirection.Horizontal; probingSlider_panel.Spacing = 10; probingSlider_panel.Margin = new RectOffset(8, 8, 6, 32); probingSlider_panel.FlexSize = Vector2.right; PLabel probingSliderMin_label = new PLabel("ProbingSliderMinLabel"); probingSliderMin_label.Text = Mathf.RoundToInt(SweepyConfigChecker.MinProbingSliderValue).ToString(); probingSliderMin_label.TextStyle = PUITuning.Fonts.TextDarkStyle; PPanel probingSlider_components = probingSlider_panel.AddChild((IUIComponent)probingSliderMin_label); PSliderSingle probingSpeedSlider = new PSliderSingle("Probing Radius") { Direction = Slider.Direction.LeftToRight, HandleColor = PUITuning.Colors.ButtonPinkStyle, HandleSize = 16.0f, InitialValue = SweepyConfigChecker.BaseProbingRadius, IntegersOnly = true, MaxValue = SweepyConfigChecker.MaxProbingSliderValue, MinValue = SweepyConfigChecker.MinProbingSliderValue, PreferredLength = 140.0f, TrackSize = 16.0f, }; probingSpeedSlider.OnRealize += (PUIDelegates.OnRealize)(obj => this.ProbingRadiusSlider = obj); probingSpeedSlider.OnValueChanged = ChangeProbingRadius; probingSlider_components.AddChild(probingSpeedSlider); PLabel probingSliderMax_label = new PLabel("ProbingSliderMaxLabel"); probingSliderMax_label.Text = Mathf.RoundToInt(SweepyConfigChecker.MaxProbingSliderValue).ToString(); probingSliderMax_label.TextStyle = PUITuning.Fonts.TextDarkStyle; probingSlider_components.AddChild(probingSliderMax_label); probingSlider_components.AddTo(this.gameObject, -2); PPanel bottomRow_panel = new PPanel("BottomRow"); bottomRow_panel.BackColor = backColour; bottomRow_panel.Alignment = TextAnchor.MiddleCenter; bottomRow_panel.Direction = PanelDirection.Horizontal; bottomRow_panel.Margin = rectOffset; bottomRow_panel.Spacing = 10; PButton findButton = new PButton(); findButton.Color = PUITuning.Colors.ButtonBlueStyle; findButton.Margin = new RectOffset(16, 16, 8, 8); findButton.TextStyle = PUITuning.Fonts.TextLightStyle; findButton.OnClick = new PUIDelegates.OnButtonPressed(this.FindSweepyBot); findButton.Text = SweepyStrings.FindSweepyButtonText; findButton.ToolTip = SweepyStrings.FindSweepyButtonTooltip; findButton.OnRealize += (PUIDelegates.OnRealize)(obj => this.FindSweepyButton = obj); PButton resetButton = new PButton(); resetButton.Color = PUITuning.Colors.ButtonBlueStyle; resetButton.Margin = new RectOffset(16, 16, 8, 8); resetButton.TextStyle = PUITuning.Fonts.TextLightStyle; resetButton.OnClick = new PUIDelegates.OnButtonPressed(this.ResetSweepyBot); resetButton.Text = SweepyStrings.ResetSweepyButtonText; resetButton.ToolTip = SweepyStrings.ResetSweepyButtonTooltip; resetButton.OnRealize += (PUIDelegates.OnRealize)(obj => this.ResetSweepyButton = obj); bottomRow_panel.AddChild(findButton); bottomRow_panel.AddChild(resetButton); bottomRow_panel.AddTo(this.gameObject, -2); this.ContentContainer = this.gameObject; base.OnPrefabInit(); this.SetTarget(this.target.gameObject); }