public override void CreateUIEntry(PGridPanel parent, ref int row) { if (getTitle != null) { Title = getTitle.Invoke(); } else { // Only displayed in error cases, should not be localized Title = "<No Title>"; } var label = new PLabel("Label") { Text = LookInStrings(Title), TextStyle = PUITuning.Fonts.TextLightStyle }; label.OnRealize += OnRealizeLabel; parent.AddChild(label, new GridComponentSpec(row, 0) { Margin = LABEL_MARGIN, Alignment = TextAnchor.MiddleLeft }); parent.AddChild(this, new GridComponentSpec(row, 1) { Alignment = TextAnchor.MiddleRight, Margin = CONTROL_MARGIN }); }
protected override IUIComponent GetUIComponent() { // Find largest option to size the label appropriately string longestText = " "; foreach (var option in options) { string optionText = option.Title; if (optionText.Length > longestText.Length) { longestText = optionText; } } var lbl = new PLabel("Item") { ToolTip = "Loading", Text = longestText }; lbl.OnRealize += OnRealizeItemLabel; // Build UI with 2 arrow buttons and a label to display the option return(new PPanel("Select") { Direction = PanelDirection.Horizontal, Spacing = 5 }.AddChild(new PButton("Previous") { SpriteSize = ARROW_SIZE, OnClick = OnPrevious, ToolTip = POptions. TOOLTIP_PREVIOUS }.SetKleiBlueStyle().SetImageLeftArrow()).AddChild(lbl). AddChild(new PButton("Next") { SpriteSize = ARROW_SIZE, OnClick = OnNext, ToolTip = POptions.TOOLTIP_NEXT }.SetKleiBlueStyle().SetImageRightArrow())); }
/// <summary> /// Fills in the mod info screen, assuming that infoAttr is non-null. /// </summary> /// <param name="dialog">The dialog to populate.</param> private void AddModInfoScreen(PDialog dialog) { string image = displayInfo.Image; var body = dialog.Body; // Try to load the mod image sprite if possible if (modImage == null && !string.IsNullOrEmpty(image)) { string rootDir = PUtil.GetModPath(optionsType.Assembly); modImage = PUIUtils.LoadSpriteFile(rootDir == null ? image : Path.Combine( rootDir, image)); } var websiteButton = new PButton("ModSite") { Text = PLibStrings.MOD_HOMEPAGE, ToolTip = PLibStrings.TOOLTIP_HOMEPAGE, OnClick = VisitModHomepage, Margin = PDialog.BUTTON_MARGIN }.SetKleiBlueStyle(); var versionLabel = new PLabel("ModVersion") { Text = displayInfo.Version, ToolTip = PLibStrings.TOOLTIP_VERSION, TextStyle = PUITuning.Fonts.UILightStyle, Margin = new RectOffset(0, 0, OUTER_MARGIN, 0) }; // Find mod URL string modURL = displayInfo.URL; if (modImage != null) { // 2 rows and 1 column if (optionCategories.Count > 0) { body.Direction = PanelDirection.Horizontal; } var infoPanel = new PPanel("ModInfo") { FlexSize = Vector2.up, Direction = PanelDirection.Vertical, Alignment = TextAnchor.UpperCenter }.AddChild(new PLabel("ModImage") { SpriteSize = MOD_IMAGE_SIZE, TextAlignment = TextAnchor.UpperLeft, Margin = new RectOffset(0, OUTER_MARGIN, 0, OUTER_MARGIN), Sprite = modImage }); if (!string.IsNullOrEmpty(modURL)) { infoPanel.AddChild(websiteButton); } body.AddChild(infoPanel.AddChild(versionLabel)); } else { if (!string.IsNullOrEmpty(modURL)) { body.AddChild(websiteButton); } body.AddChild(versionLabel); } }
public TypeSelectControl(bool disableIcons = false) { DisableIcons = disableIcons; // Select/deselect all types var allCheckBox = new PCheckBox("SelectAll") { Text = STRINGS.UI.UISIDESCREENS.TREEFILTERABLESIDESCREEN.ALLBUTTON, CheckSize = ROW_SIZE, InitialState = PCheckBox.STATE_CHECKED, OnChecked = OnCheck, TextStyle = PUITuning.Fonts.TextDarkStyle }; allCheckBox.OnRealize += (obj) => { allItems = obj; }; var cp = new PPanel("Categories") { Direction = PanelDirection.Vertical, Alignment = TextAnchor.UpperLeft, Spacing = ROW_SPACING, Margin = ELEMENT_MARGIN, FlexSize = Vector2.right, }; cp.AddChild(allCheckBox); cp.OnRealize += (obj) => { childPanel = obj; }; // Scroll to select elements var sp = new PScrollPane("Scroll") { Child = cp, ScrollHorizontal = false, ScrollVertical = true, AlwaysShowVertical = true, TrackSize = 8.0f, FlexSize = Vector2.one }; // Title bar var title = new PLabel("Title") { TextAlignment = TextAnchor.MiddleCenter, Text = SweepByTypeStrings. DIALOG_TITLE, FlexSize = Vector2.right, Margin = TITLE_MARGIN }.SetKleiPinkColor(); // Bottom border on the title for contrast title.OnRealize += (obj) => { var img = obj.AddOrGet <Image>(); img.sprite = PUITuning.Images.BoxBorder; img.type = Image.Type.Sliced; }; // 1px black border on the rest of the dialog for contrast var panel = new PRelativePanel("Border") { BackImage = PUITuning.Images.BoxBorder, ImageMode = Image.Type.Sliced, DynamicSize = false, BackColor = PUITuning.Colors.BackgroundLight }.AddChild(sp).AddChild(title); RootPanel = panel.SetMargin(sp, OUTER_MARGIN). SetLeftEdge(title, fraction: 0.0f).SetRightEdge(title, fraction: 1.0f). SetLeftEdge(sp, fraction: 0.0f).SetRightEdge(sp, fraction: 1.0f). SetTopEdge(title, fraction: 1.0f).SetBottomEdge(sp, fraction: 0.0f). SetTopEdge(sp, below: title).Build(); RootPanel.SetMinUISize(PANEL_SIZE); children = new SortedList <Tag, TypeSelectCategory>(16, TagAlphabetComparer. INSTANCE); Screen = RootPanel.AddComponent <TypeSelectScreen>(); }
public NotepadControl() { descriptionField = DescriptionArea(); // this button does nothing but it enable to deselect the textarea and to valide the input without closing the sidescreen PButton validationButton = new PButton("button") { Sprite = PUITuning.Images.Checked, SpriteSize = new Vector2(25, 30), }; PLabel descriptionLabel = new PLabel("description label") { Text = "Description", TextAlignment = TextAnchor.MiddleCenter, }; PPanel panel = new PPanel("Text panel") { Direction = PanelDirection.Vertical, Alignment = TextAnchor.UpperLeft, Spacing = ROW_SPACING, FlexSize = Vector2.one, }; panel.AddChild(descriptionLabel); panel.AddChild(descriptionField); panel.AddChild(validationButton); PPanel root = new PPanel("NotepadSideScreen") { Direction = PanelDirection.Vertical, Margin = OUTER_MARGIN, Alignment = TextAnchor.MiddleCenter, Spacing = 0, BackColor = PUITuning.Colors.BackgroundLight, FlexSize = Vector2.one, }; root.AddChild(panel); RootPanel = root.SetKleiBlueColor().Build(); }
/// <summary> /// Adds a category header to the dialog. /// </summary> /// <param name="container">The parent of the header.</param> /// <param name="category">The header title.</param> /// <param name="contents">The panel containing the options in this category.</param> private void AddCategoryHeader(PGridPanel container, string category, PGridPanel contents) { contents.AddColumn(new GridColumnSpec(flex: 1.0f)).AddColumn(new GridColumnSpec()); if (!string.IsNullOrEmpty(category)) { bool state = !(infoAttr?.ForceCollapseCategories ?? false); var handler = new CategoryExpandHandler(state); container.AddColumn(new GridColumnSpec()).AddColumn(new GridColumnSpec( flex: 1.0f)).AddRow(new GridRowSpec()).AddRow(new GridRowSpec(flex: 1.0f)); // Toggle is upper left, header is upper right var header = new PLabel("CategoryHeader") { Text = OptionsEntry.LookInStrings(category), TextStyle = CATEGORY_TITLE_STYLE, TextAlignment = TextAnchor.LowerCenter }; var toggle = new PToggle("CategoryToggle") { Color = PUITuning.Colors.ComponentDarkStyle, InitialState = state, ToolTip = PUIStrings.TOOLTIP_TOGGLE, Size = TOGGLE_SIZE, OnStateChanged = handler.OnExpandContract }; header.OnRealize += handler.OnRealizeHeader; toggle.OnRealize += handler.OnRealizeToggle; container.AddChild(header, new GridComponentSpec(0, 1) { Margin = new RectOffset(OUTER_MARGIN, OUTER_MARGIN, 0, 0) }).AddChild(toggle, new GridComponentSpec(0, 0)); if (contents != null) { contents.OnRealize += handler.OnRealizePanel; } container.AddChild(contents, new GridComponentSpec(1, 0) { ColumnSpan = 2 }); } else { // Default of unconstrained fills the whole panel container.AddColumn(new GridColumnSpec(flex: 1.0f)).AddRow(new GridRowSpec( flex: 1.0f)).AddChild(contents, new GridComponentSpec(0, 0)); } }
public override void CreateUIEntry(PGridPanel parent, ref int row) { double minLimit, maxLimit; base.CreateUIEntry(parent, ref row); if (limits != null && (minLimit = limits.Minimum) > float.MinValue && (maxLimit = limits.Maximum) < float.MaxValue && maxLimit > minLimit) { // NaN will be false on either comparison var slider = GetSlider(); // Min and max labels var minLabel = new PLabel("MinValue") { TextStyle = PUITuning.Fonts.TextLightStyle, Text = minLimit. ToString("G4"), TextAlignment = TextAnchor.MiddleRight }; var maxLabel = new PLabel("MaxValue") { TextStyle = PUITuning.Fonts.TextLightStyle, Text = maxLimit. ToString("G4"), TextAlignment = TextAnchor.MiddleLeft }; // Lay out left to right var panel = new PRelativePanel("Slider Grid") { FlexSize = Vector2.right, DynamicSize = false }.AddChild(slider).AddChild(minLabel).AddChild(maxLabel).AnchorYAxis(slider). AnchorYAxis(minLabel, 0.5f).AnchorYAxis(maxLabel, 0.5f).SetLeftEdge( minLabel, fraction: 0.0f).SetRightEdge(maxLabel, fraction: 1.0f). SetLeftEdge(slider, toRight: minLabel).SetRightEdge(slider, toLeft: maxLabel).SetMargin(slider, SLIDER_MARGIN); slider.OnRealize += OnRealizeSlider; // Add another row for the slider parent.AddRow(new GridRowSpec()); parent.AddChild(panel, new GridComponentSpec(++row, 0) { ColumnSpan = 2, Margin = ENTRY_MARGIN }); } }
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); }