Beispiel #1
0
        public TestControl(bool disableIcons = false)
        {
            var cp = new PPanel("Categories")
            {
                Direction = PanelDirection.Vertical,
                Alignment = TextAnchor.UpperLeft,
                Spacing   = ROW_SPACING
            };

            cp.AddChild(new PTextField()
            {
                FlexSize = Vector2.one,
            });
            cp.AddChild(new PTextField()
            {
            });
            cp.AddChild(new PTextField()
            {
            });
            cp.AddChild(new PTextField()
            {
            });
            cp.AddChild(new PTextField()
            {
            });
            cp.OnRealize += (obj) => { childPanel = obj; };
            RootPanel     = new PPanel("GridFilterableSideScreen")
            {
                // White background for scroll bar
                Direction = PanelDirection.Vertical,
                Margin    = OUTER_MARGIN,
                Alignment = TextAnchor.MiddleCenter,
                Spacing   = 0,
                BackColor = PUITuning.Colors.BackgroundLight,
                FlexSize  = Vector2.one
            }.AddChild(new PScrollPane("Scroll")
            {
                // Scroll to select elements
                Child = new PPanel("SelectType")
                {
                    Direction = PanelDirection.Vertical,
                    Margin    = ELEMENT_MARGIN,
                    FlexSize  = new Vector2(1.0f, 0.0f),
                    Alignment = TextAnchor.UpperLeft
                }.AddChild(cp),
                ScrollHorizontal   = false,
                ScrollVertical     = true,
                AlwaysShowVertical = true,
                TrackSize          = 8.0f,
                FlexSize           = Vector2.one,
                BackColor          = PUITuning.Colors.BackgroundLight,
            }).SetKleiBlueColor().Build();
        }
Beispiel #2
0
        // штуки для создания сидескреенов
        // чекбокс и слидер с обвязкой и подгрузкой строк, добавляемые на панельку
        // установка и считывание значений реализованы через акции-каллбаки
        public static PPanel AddCheckBox(this PPanel parent, string prefix, string name, Action <bool> onChecked, out Action <bool> setChecked, out Action <bool> setActive)
        {
            prefix = (prefix + name).ToUpperInvariant();
            GameObject cb_go = null;
            var        cb    = new PCheckBox(name)
            {
                CheckColor    = PUITuning.Colors.ComponentLightStyle,
                CheckSize     = new Vector2(26f, 26f),
                Text          = Strings.Get(prefix + ".NAME"),
                TextAlignment = TextAnchor.MiddleLeft,
                TextStyle     = PUITuning.Fonts.TextDarkStyle,
                ToolTip       = Strings.Get(prefix + ".TOOLTIP"),
                OnChecked     = (go, state) =>
                {
                    // переворачиваем предыдующее значение
                    bool @checked = state == PCheckBox.STATE_UNCHECKED;
                    PCheckBox.SetCheckState(go, @checked ? PCheckBox.STATE_CHECKED : PCheckBox.STATE_UNCHECKED);
                    onChecked?.Invoke(@checked);
                    // внесапно, численное значение состояния чекбокса совпало с индексом таблицы звуков
                    KFMOD.PlayUISound(WidgetSoundPlayer.getSoundPath(ToggleSoundPlayer.default_values[state]));
                },
            }.AddOnRealize(realized => cb_go = realized);

            setChecked = @checked =>
            {
                if (cb_go != null)
                {
                    PCheckBox.SetCheckState(cb_go, @checked ? PCheckBox.STATE_CHECKED : PCheckBox.STATE_UNCHECKED);
                }
            };
            setActive = on => cb_go?.SetActive(on);
            return(parent.AddChild(cb));
        }
        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();
        }
Beispiel #4
0
        /// <summary>
        /// Fills in the actual mod option fields.
        /// </summary>
        /// <param name="dialog">The dialog to populate.</param>
        private void FillModOptions(PDialog dialog)
        {
            PPanel body   = dialog.Body;
            var    margin = body.Margin;

            // For each option, add its UI component to panel
            body.Margin = new RectOffset();
            var scrollBody = new PPanel("ScrollContent")
            {
                Spacing = OUTER_MARGIN, Direction = PanelDirection.Vertical, Alignment =
                    TextAnchor.UpperCenter, FlexSize = Vector2.right
            };

            // Display all categories
            foreach (var catEntries in optionCategories)
            {
                string category = catEntries.Key;
                if (catEntries.Value.Count > 0)
                {
                    string name = string.IsNullOrEmpty(category) ? "Default" : category;
                    int    i    = 0;
                    // Not optimal for layout performance, but the panel is needed to have a
                    // different background color for each category "box"
                    var container = new PGridPanel("Category_" + name)
                    {
                        Margin   = margin, BackColor = PUITuning.Colors.DialogDarkBackground,
                        FlexSize = Vector2.right
                    };
                    // Needs to be a separate panel so that it can be collapsed
                    var contents = new PGridPanel("Entries")
                    {
                        FlexSize = Vector2.right
                    };
                    AddCategoryHeader(container, catEntries.Key, contents);
                    foreach (var entry in catEntries.Value)
                    {
                        contents.AddRow(new GridRowSpec());
                        entry.CreateUIEntry(contents, i++);
                    }
                    scrollBody.AddChild(container);
                }
            }
            // Manual config button
            scrollBody.AddChild(new PButton("ManualConfig")
            {
                Text    = PUIStrings.BUTTON_MANUAL, ToolTip = PUIStrings.TOOLTIP_MANUAL,
                OnClick = OnManualConfig, TextAlignment = TextAnchor.MiddleCenter, Margin =
                    PDialog.BUTTON_MARGIN
            }.SetKleiBlueStyle());
            body.AddChild(new PScrollPane()
            {
                ScrollHorizontal     = false, ScrollVertical = optionCategories.Count > 0,
                Child                = scrollBody, FlexSize = Vector2.right, TrackSize = 8,
                AlwaysShowHorizontal = false, AlwaysShowVertical = false
            });
        }
Beispiel #5
0
        protected override void OnSpawn()
        {
            base.OnSpawn();
            // One long linear row
            var panel = new PPanel("MoreModActions")
            {
                BackColor = PUITuning.Colors.DialogDarkBackground, Spacing = 6,
                BackImage = PUITuning.Images.BoxBorder, ImageMode = Image.Type.Sliced,
                Direction = PanelDirection.Horizontal, Margin = new RectOffset(6, 6, 6, 6)
            }.AddChild(MakeButton("MoveToFirst", UI.TOOLTIPS.DNI_TOP,
                                  SpriteRegistry.GetTopIcon(), OnMoveFirst, (obj) =>
                                  buttonFirst = obj.GetComponent <KButton>()))
            .AddChild(MakeButton("MoveUpTen", UI.TOOLTIPS.DNI_UP,
                                 Assets.GetSprite("icon_priority_up_2"), OnMoveUp, (obj) =>
                                 buttonUp = obj.GetComponent <KButton>()))
            .AddChild(MakeButton("MoveDownTen", UI.TOOLTIPS.DNI_DOWN,
                                 Assets.GetSprite("icon_priority_down_2"), OnMoveDown, (obj) =>
                                 buttonDown = obj.GetComponent <KButton>()))
            .AddChild(MakeButton("MoveToLast", UI.TOOLTIPS.DNI_BOTTOM,
                                 SpriteRegistry.GetBottomIcon(), OnMoveLast, (obj) =>
                                 buttonLast = obj.GetComponent <KButton>()))
            .AddChild(new PButton("ManageMod")
            {
                Text    = UI.MODSSCREEN.BUTTON_SUBSCRIPTION, DynamicSize = false,
                OnClick = OnManage, ToolTip = "Manage Mod", Margin = DebugUtils.BUTTON_MARGIN
            }.SetKleiBlueStyle().AddOnRealize((obj) => buttonManage = obj))
            .AddChild(new PButton("UnsubMod")
            {
                Text    = UI.MODSSCREEN.BUTTON_UNSUB, DynamicSize = false,
                OnClick = OnUnsub, ToolTip = UI.TOOLTIPS.DNI_UNSUB, Margin = DebugUtils.
                                                                             BUTTON_MARGIN
            }.SetKleiBlueStyle().AddOnRealize((obj) => buttonUnsub = obj.
                                                                     GetComponent <KButton>()));

#if DEBUG
            panel.AddChild(new PButton("ModifyMod")
            {
                Text    = UI.MODSSCREEN.BUTTON_MODIFY, DynamicSize = false,
                OnClick = OnModify, ToolTip = UI.TOOLTIPS.DNI_MODIFY, Margin = DebugUtils.
                                                                               BUTTON_MARGIN
            }.SetKleiPinkStyle().AddOnRealize((obj) => buttonModify = obj.
                                                                      GetComponent <KButton>()));
#endif
            var actionsObj = panel.AddTo(gameObject);
#if DEBUG
            PButton.SetButtonEnabled(buttonModify.gameObject, false);
#endif
            actionsObj.SetActive(false);
            // Blacklist from auto layout
            actionsObj.AddOrGet <LayoutElement>().ignoreLayout = true;
            PUIElements.SetAnchors(actionsObj, PUIAnchoring.End, PUIAnchoring.Center);
            unsubCaller = new CallResult <RemoteStorageUnsubscribePublishedFileResult_t>(
                OnUnsubComplete);
            actionsScreen = actionsObj.AddComponent <ModActionsScreen>();
            callingButton = null;
        }
Beispiel #6
0
        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>();
        }
Beispiel #7
0
 /// <summary>
 /// Adds a category header to the dialog.
 /// </summary>
 /// <param name="body">The parent of the header.</param>
 /// <param name="category">The header title.</param>
 private void AddCategoryHeader(PPanel body, string category)
 {
     if (!string.IsNullOrEmpty(category))
     {
         body.AddChild(new PLabel("CategoryHeader_" + category)
         {
             Text          = category, TextStyle = POptions.TITLE_STYLE,
             TextAlignment = TextAnchor.LowerCenter, DynamicSize = true,
             Margin        = new RectOffset(0, 0, 0, 2), FlexSize = new Vector2(1.0f, 0.0f),
         });
     }
 }
Beispiel #8
0
 /// <summary>
 /// Triggered when the Mod Options button is clicked.
 /// </summary>
 public void OnModOptions(GameObject _)
 {
     if (path != null)
     {
         // Close current dialog if open
         CloseDialog();
         // Ensure that it is on top of other screens (which may be +100 modal)
         var pDialog = new PDialog("ModOptions")
         {
             Title = POptions.DIALOG_TITLE.text.F(modSpec.title), Size = POptions.
                                                                         SETTINGS_DIALOG_SIZE, SortKey = 150.0f, DialogBackColor = PUITuning.Colors.
                                                                                                                                   OptionsBackground, DialogClosed = OnOptionsSelected
         }.AddButton("ok", STRINGS.UI.CONFIRMDIALOG.OK, POptions.TOOLTIP_OK);
         pDialog.AddButton("manual", POptions.BUTTON_MANUAL, POptions.TOOLTIP_MANUAL).
         AddButton(PDialog.DIALOG_KEY_CLOSE, STRINGS.UI.CONFIRMDIALOG.CANCEL,
                   POptions.TOOLTIP_CANCEL);
         PPanel body = pDialog.Body, current;
         var    margin = body.Margin;
         // For each option, add its UI component to panel
         body.Spacing = 10;
         body.Margin  = new RectOffset(0, 0, 0, 0);
         // Display all categories
         foreach (var catEntries in optionCategories)
         {
             string category = catEntries.Key;
             current = new PPanel("Entries_" + category)
             {
                 Alignment = TextAnchor.UpperCenter, Spacing = 5,
                 BackColor = PUITuning.Colors.DialogDarkBackground,
                 FlexSize  = new Vector2(1.0f, 0.0f), Margin = margin
             };
             AddCategoryHeader(current, catEntries.Key);
             foreach (var entry in catEntries.Value)
             {
                 current.AddChild(entry.GetUIEntry());
             }
             body.AddChild(current);
         }
         options = POptions.ReadSettings(path, optionsType);
         if (options == null)
         {
             CreateOptions();
         }
         // Manually build the dialog so the options can be updated after realization
         var obj = pDialog.Build();
         UpdateOptions();
         dialog = obj.GetComponent <KScreen>();
         dialog.Activate();
     }
 }
Beispiel #9
0
        /// <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 = infoAttr.Image, version = GetModVersionText(optionsType);
            var    body = dialog.Body;

            // Try to load the mod image sprite if possible
            if (modImage == null && !string.IsNullOrEmpty(image))
            {
                string rootDir = handler.ConfigPath;
                modImage = PUIUtils.LoadSprite(rootDir == null ? image : Path.Combine(rootDir,
                                                                                      image));
            }
            var websiteButton = new PButton("ModSite")
            {
                Text    = PUIStrings.MOD_HOMEPAGE, ToolTip = PUIStrings.TOOLTIP_HOMEPAGE,
                OnClick = VisitModHomepage, Margin = PDialog.BUTTON_MARGIN
            }.SetKleiBlueStyle();
            var versionLabel = new PLabel("ModVersion")
            {
                Text = version, ToolTip = PUIStrings.TOOLTIP_VERSION, TextStyle = PUITuning.
                                                                                  Fonts.UILightStyle, Margin = new RectOffset(0, 0, OUTER_MARGIN, 0)
            };
            // Find mod URL
            string modURL = infoAttr?.URL;

            if (string.IsNullOrEmpty(modURL))
            {
                modURL = handler.DefaultURL;
            }
            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);
            }
        }
Beispiel #10
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));
        }
        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);
        }
Beispiel #12
0
        private void PressItBaby()
        {
            address       = Z.address;
            port          = Z.port;
            ping_interval = Z.ping_interval;

            var dialog = new PDialog("ZTransportOptions")
            {
                Title           = "ZTransport Options",
                Size            = new Vector2(320f, 200f),
                DialogBackColor = PUITuning.Colors.OptionsBackground,
                DialogClosed    = OnDialogClosed,
                MaxSize         = new Vector2(320f, 400f),
            };

            dialog
            .AddButton("ok", STRINGS.UI.CONFIRMDIALOG.OK,
                       STRINGS.ZTRANSPORT.UI.OK_TOOLTIP,
                       PUITuning.Colors.ButtonPinkStyle)
            .AddButton(PDialog.DIALOG_KEY_CLOSE,
                       STRINGS.UI.CONFIRMDIALOG.CANCEL,
                       PUIStrings.TOOLTIP_CANCEL,
                       PUITuning.Colors.ButtonBlueStyle);
            var body  = dialog.Body;
            var panel = new PPanel("ConnectionSettings")
            {
                Direction = PanelDirection.Vertical,
                Alignment = TextAnchor.UpperLeft,
                FlexSize  = Vector2.right,
            };

            panel.AddChild(new PLabel("ServerAddressLabel")
            {
                TextAlignment = TextAnchor.UpperLeft,
                Text          = STRINGS.ZTRANSPORT.UI.SERVER_ADDRESS,
                FlexSize      = Vector2.right,
                Margin        = new RectOffset(0, 10, 0, 10),
            });
            panel.AddChild(new PTextField("ServerAddressField")
            {
                Text          = Z.address,
                TextStyle     = PUITuning.Fonts.TextDarkStyle,
                FlexSize      = Vector2.right,
                ToolTip       = STRINGS.ZTRANSPORT.UI.ADDRESS_TOOLTIP,
                OnTextChanged = ServerAddressChanged,
            });
            panel.AddChild(new PLabel("ServerPortLabel")
            {
                TextAlignment = TextAnchor.UpperLeft,
                Text          = STRINGS.ZTRANSPORT.UI.SERVER_PORT,
                FlexSize      = Vector2.right,
                Margin        = new RectOffset(0, 10, 0, 10),
            });
            panel.AddChild(new PTextField("ServerPortField")
            {
                Text          = Z.port.ToString(),
                TextStyle     = PUITuning.Fonts.TextDarkStyle,
                FlexSize      = Vector2.right,
                ToolTip       = STRINGS.ZTRANSPORT.UI.PORT_TOOLTIP,
                OnTextChanged = ServerPortChanged,
                OnValidate    = ServerPortValidate,
            });
            panel.AddChild(new PLabel("PingIntervalLabel")
            {
                TextAlignment = TextAnchor.UpperLeft,
                Text          = STRINGS.ZTRANSPORT.UI.PING_INTERVAL,
                FlexSize      = Vector2.right,
                Margin        = new RectOffset(0, 10, 0, 10),
            });
            panel.AddChild(new PTextField("PingIntervalField")
            {
                Text          = Z.ping_interval.ToString(),
                TextStyle     = PUITuning.Fonts.TextDarkStyle,
                FlexSize      = Vector2.right,
                ToolTip       = STRINGS.ZTRANSPORT.UI.PING_TOOLTIP,
                OnTextChanged = PingIntervalChanged,
                OnValidate    = PingIntervalValidate,
            });
            body.AddChild(panel);
            var built  = dialog.Build();
            var screen = built.GetComponent <KScreen>();

            screen.Activate();
        }
Beispiel #13
0
        /// <summary>
        /// Fills in the actual mod option fields.
        /// </summary>
        /// <param name="dialog">The dialog to populate.</param>
        private void FillModOptions(PDialog dialog)
        {
            IEnumerable <IOptionsEntry> dynamicOptions;
            var body   = dialog.Body;
            var margin = new RectOffset(CATEGORY_MARGIN, CATEGORY_MARGIN, CATEGORY_MARGIN,
                                        CATEGORY_MARGIN);

            // For each option, add its UI component to panel
            body.Margin = new RectOffset();
            var scrollBody = new PPanel("ScrollContent")
            {
                Spacing = OUTER_MARGIN, Direction = PanelDirection.Vertical, Alignment =
                    TextAnchor.UpperCenter, FlexSize = Vector2.right
            };
            var allOptions = optionCategories;

            // Add options from the user's class
            if (options is IOptions dynOptions && (dynamicOptions = dynOptions.
                                                                    CreateOptions()) != null)
            {
                allOptions = new Dictionary <string, OptionsList>(optionCategories);
                foreach (var dynamicOption in dynamicOptions)
                {
                    OptionsEntry.AddToCategory(allOptions, dynamicOption);
                }
            }
            // Display all categories
            foreach (var catEntries in allOptions)
            {
                string category = catEntries.Key;
                if (catEntries.Value.Count > 0)
                {
                    string name = string.IsNullOrEmpty(category) ? "Default" : category;
                    int    i    = 0;
                    // Not optimal for layout performance, but the panel is needed to have a
                    // different background color for each category "box"
                    var container = new PGridPanel("Category_" + name)
                    {
                        Margin   = margin, BackColor = PUITuning.Colors.DialogDarkBackground,
                        FlexSize = Vector2.right
                    };
                    // Needs to be a separate panel so that it can be collapsed
                    var contents = new PGridPanel("Entries")
                    {
                        FlexSize = Vector2.right
                    };
                    AddCategoryHeader(container, catEntries.Key, contents);
                    foreach (var entry in catEntries.Value)
                    {
                        contents.AddRow(new GridRowSpec());
                        entry.CreateUIEntry(contents, ref i);
                        i++;
                    }
                    scrollBody.AddChild(container);
                }
            }
            // Manual config and reset button
            scrollBody.AddChild(new PPanel("ConfigButtons")
            {
                Spacing = 10, Direction = PanelDirection.Horizontal, Alignment =
                    TextAnchor.MiddleCenter, FlexSize = Vector2.right
            }.AddChild(new PButton("ManualConfig")
            {
                Text    = PLibStrings.BUTTON_MANUAL, ToolTip = PLibStrings.TOOLTIP_MANUAL,
                OnClick = OnManualConfig, TextAlignment = TextAnchor.MiddleCenter, Margin =
                    PDialog.BUTTON_MARGIN
            }.SetKleiBlueStyle()).AddChild(new PButton("ResetConfig")
            {
                Text    = PLibStrings.BUTTON_RESET, ToolTip = PLibStrings.TOOLTIP_RESET,
                OnClick = OnResetConfig, TextAlignment = TextAnchor.MiddleCenter, Margin =
                    PDialog.BUTTON_MARGIN
            }.SetKleiBlueStyle()));
            body.AddChild(new PScrollPane()
            {
                ScrollHorizontal     = false, ScrollVertical = allOptions.Count > 0,
                Child                = scrollBody, FlexSize = Vector2.right, TrackSize = 8,
                AlwaysShowHorizontal = false, AlwaysShowVertical = false
            });
        }
Beispiel #14
0
        private void RebuildPanel()
        {
            // Rebuild UI

            if (ContentContainer != null)
            {
                Destroy(ContentContainer);
                ContentContainer = null;
            }

            var margin     = new RectOffset(8, 8, 8, 8);
            var baseLayout = gameObject.GetComponent <BoxLayoutGroup>();

            if (baseLayout != null)
            {
                baseLayout.Params = new BoxLayoutParams()
                {
                    Margin    = margin,
                    Direction = PanelDirection.Vertical,
                    Alignment = TextAnchor.UpperCenter,
                    Spacing   = 8
                };
            }

            var mainPanel = new PPanel();

            if (engine != null)
            {
                var efficiencyRow = new PPanel("EfficiencyRow")
                {
                    FlexSize  = Vector2.right,
                    Alignment = TextAnchor.MiddleCenter,
                    Spacing   = 10,
                    Direction = PanelDirection.Horizontal,
                    Margin    = margin
                };

                efficiencyRow.AddChild(new PLabel("Efficiency")
                {
                    TextAlignment = TextAnchor.MiddleRight,
                    ToolTip       = "Indicates the percentage of input heat that is currently being converted to power.",
                    Text          = $"Current Efficiency: {(engine.currentEfficiency * 100f):F0} %",
                    TextStyle     = PUITuning.Fonts.TextDarkStyle
                });

                mainPanel.AddChild(efficiencyRow);

                var powerRow = new PPanel("PowerRow")
                {
                    FlexSize  = Vector2.right,
                    Alignment = TextAnchor.MiddleCenter,
                    Spacing   = 10,
                    Direction = PanelDirection.Horizontal,
                    Margin    = margin
                };

                powerRow.AddChild(new PLabel("Power")
                {
                    TextAlignment = TextAnchor.MiddleRight,
                    ToolTip       = "Indicates the amount of power currently being output into the circuit.",
                    Text          = $"Estimated Power Output: {engine.currentGeneratedPower:F0} W",
                    TextStyle     = PUITuning.Fonts.TextDarkStyle
                });

                mainPanel.AddChild(powerRow);

                var heatRow = new PPanel("HeatRow")
                {
                    FlexSize  = Vector2.right,
                    Alignment = TextAnchor.MiddleCenter,
                    Spacing   = 10,
                    Direction = PanelDirection.Horizontal,
                    Margin    = margin
                };

                heatRow.AddChild(new PLabel("Heat")
                {
                    TextAlignment = TextAnchor.MiddleRight,
                    ToolTip       = "Indicates the amount of heat currently being added to the building temperature.",
                    Text          = $"Estimated Heat Output: {engine.currentGeneratedHeat:F0} DTU/s",
                    TextStyle     = PUITuning.Fonts.TextDarkStyle
                });

                mainPanel.AddChild(heatRow);

                ContentContainer = mainPanel.Build();
                ContentContainer.SetParent(gameObject);
            }
        }
Beispiel #15
0
        private void RebuildPanel()
        {
            // Update schedule data

            int selectedSchedule = (sensor != null) ? sensor.scheduleIndex : 0;
            int selectedGroup    = (sensor != null) ? sensor.blockTypeIndex : 0;

            schedules = new List <StringListOption>();
            var slist = ScheduleManager.Instance.GetSchedules();

            foreach (Schedule s in slist)
            {
                schedules.Add(new StringListOption(s.name));
            }

            if (selectedSchedule < 0 || selectedSchedule >= schedules.Count)
            {
                selectedSchedule = 0;
                if (sensor != null)
                {
                    sensor.scheduleIndex = selectedSchedule;
                }
            }

            groups = new List <StringListOption>();
            var glist = Db.Get().ScheduleGroups.allGroups;

            foreach (ScheduleGroup g in glist)
            {
                groups.Add(new StringListOption(g.Name));
            }

            if (selectedGroup < 0 || selectedGroup >= groups.Count)
            {
                selectedGroup = 0;
                if (sensor != null)
                {
                    sensor.blockTypeIndex = selectedGroup;
                }
            }

            // Rebuild UI

            if (ContentContainer != null)
            {
                Destroy(ContentContainer);
                ContentContainer = null;
            }

            var margin     = new RectOffset(8, 8, 8, 8);
            var baseLayout = gameObject.GetComponent <BoxLayoutGroup>();

            if (baseLayout != null)
            {
                baseLayout.Params = new BoxLayoutParams()
                {
                    Margin    = margin,
                    Direction = PanelDirection.Vertical,
                    Alignment = TextAnchor.UpperCenter,
                    Spacing   = 8
                };
            }

            var mainPanel = new PPanel();

            var scheduleRow = new PPanel("Schedule Select")
            {
                FlexSize  = Vector2.right,
                Alignment = TextAnchor.MiddleCenter,
                Spacing   = 10,
                Direction = PanelDirection.Horizontal,
                Margin    = margin
            };

            scheduleRow.AddChild(new PLabel("Schedule")
            {
                TextAlignment = TextAnchor.MiddleRight,
                ToolTip       = "TODO: Schedule Label Tooltip",
                Text          = "Schedule",
                TextStyle     = PUITuning.Fonts.TextDarkStyle
            });

            var scb = new PeterHan.PLib.UI.PComboBox <StringListOption>("Schedule Select")
            {
                Content          = schedules,
                MinWidth         = 100,
                InitialItem      = schedules[selectedSchedule],
                ToolTip          = "TODO: Schedule Select Tooltip",
                TextStyle        = PUITuning.Fonts.TextLightStyle,
                TextAlignment    = TextAnchor.MiddleLeft,
                OnOptionSelected = SetSchedule
            };

            scb.OnRealize += (obj) =>
            {
                scheduleCombo = obj;
            };
            scheduleRow.AddChild(scb);
            mainPanel.AddChild(scheduleRow);

            var groupRow = new PPanel("Group Select")
            {
                FlexSize  = Vector2.right,
                Alignment = TextAnchor.MiddleCenter,
                Spacing   = 10,
                Direction = PanelDirection.Horizontal,
                Margin    = margin
            };

            groupRow.AddChild(new PLabel("Group")
            {
                TextAlignment = TextAnchor.MiddleRight,
                ToolTip       = "TODO: Group Label Tooltip",
                Text          = "Group",
                TextStyle     = PUITuning.Fonts.TextDarkStyle
            });

            var bcb = new PComboBox <StringListOption>("Group Select")
            {
                Content          = groups,
                MinWidth         = 100,
                InitialItem      = groups[selectedGroup],
                ToolTip          = "TODO: Group Select Tooltip",
                TextStyle        = PUITuning.Fonts.TextLightStyle,
                TextAlignment    = TextAnchor.MiddleLeft,
                OnOptionSelected = SetGroup
            };

            bcb.OnRealize += (obj) =>
            {
                groupCombo = obj;
            };
            groupRow.AddChild(bcb);
            mainPanel.AddChild(groupRow);

            ContentContainer = mainPanel.Build();
            ContentContainer.SetParent(gameObject);

            if (scheduleCombo != null)
            {
                PComboBox <StringListOption> .SetSelectedItem(scheduleCombo, schedules[selectedSchedule]);
            }

            if (groupCombo != null)
            {
                PComboBox <StringListOption> .SetSelectedItem(groupCombo, groups[selectedGroup]);
            }
        }
Beispiel #16
0
        private void BuildPanel()
        {
            if (ContentContainer != null)
            {
                Destroy(ContentContainer);
                ContentContainer = null;
            }

            var margin     = new RectOffset(8, 8, 8, 8);
            var baseLayout = gameObject.GetComponent <BoxLayoutGroup>();

            if (baseLayout != null)
            {
                baseLayout.Params = new BoxLayoutParams()
                {
                    Margin    = margin,
                    Direction = PanelDirection.Vertical,
                    Alignment = TextAnchor.UpperCenter,
                    Spacing   = 8
                };
            }

            var mainPanel = new PPanel();

            var mainRow = new PPanel("Toggle Lock")
            {
                FlexSize  = Vector2.right,
                Alignment = TextAnchor.MiddleCenter,
                Spacing   = 10,
                Direction = PanelDirection.Horizontal,
                Margin    = margin
            };

            var lockBtn = new PButton("LockButton")
            {
                Text = "Lock"
            };

            lockBtn.SetKleiBlueStyle();
            lockBtn.OnClick = (obj) =>
            {
                if (curtain == null)
                {
                    return;
                }
                curtain.QueueStateChange(Curtain.ControlState.Locked);
            };

            var unlockBtn = new PButton("UnlockButton")
            {
                Text = "Auto"
            };

            unlockBtn.SetKleiBlueStyle();
            unlockBtn.OnClick = (obj) =>
            {
                if (curtain == null)
                {
                    return;
                }
                curtain.QueueStateChange(Curtain.ControlState.Auto);
            };

            var openBtn = new PButton("OpenButton")
            {
                Text = "Open"
            };

            openBtn.SetKleiBlueStyle();
            openBtn.OnClick = (obj) =>
            {
                if (curtain == null)
                {
                    return;
                }
                curtain.QueueStateChange(Curtain.ControlState.Open);
            };

            mainRow.AddChild(lockBtn);
            mainRow.AddChild(unlockBtn);
            mainRow.AddChild(openBtn);
            mainPanel.AddChild(mainRow);
            ContentContainer = mainPanel.Build();
            ContentContainer.SetParent(gameObject);
        }