Exemple #1
0
        /// <summary>
        /// Adds the save/restore lists buttons to the bottom of the Mods screen.
        /// </summary>
        /// <param name="instance">The object hosting the mods screen.</param>
        /// <param name="bottom">The panel where the buttons should be added.</param>
        internal static void AddExtraButtons(GameObject instance, GameObject bottom)
        {
            var handler = instance.AddOrGet <AllModsHandler>();
            var cb      = new PCheckBox("AllMods")
            {
                CheckSize = new Vector2(24.0f, 24.0f), Text = DebugNotIncludedStrings.
                                                              BUTTON_ALL, ToolTip = DebugNotIncludedStrings.TOOLTIP_ALL, Margin =
                    new RectOffset(5, 5, 0, 0)
            };

            // When clicked, enable/disable all
            if (handler != null)
            {
                cb.OnChecked = handler.OnClick;
            }
            handler.checkbox = cb.AddTo(bottom, 0);
            handler.UpdateCheckedState();
            // Current PLib version
            string version = PSharedData.GetData <string>("PLib.Version");
            string name    = ModDebugRegistry.Instance.OwnerOfAssembly(DebugNotIncludedPatches.
                                                                       RunningPLibAssembly)?.ModName ?? "Unknown";

            new PLabel("PLibVersion")
            {
                TextStyle = PUITuning.Fonts.UILightStyle, Text = string.Format(
                    DebugNotIncludedStrings.LABEL_PLIB, version ?? PVersion.VERSION), ToolTip =
                    string.Format(DebugNotIncludedStrings.TOOLTIP_PLIB, name),
                Margin = new RectOffset(5, 5, 0, 0)
            }.AddTo(bottom, 0);
        }
Exemple #2
0
        /// <summary>
        /// Adds the save/restore lists buttons to the bottom of the Mods screen.
        /// </summary>
        /// <param name="instance">The object hosting the mods screen.</param>
        /// <param name="bottom">The panel where the buttons should be added.</param>
        internal static void AddExtraButtons(GameObject instance, GameObject bottom)
        {
#if ALL_MODS_CHECKBOX
            var handler = instance.AddOrGet <AllModsHandler>();
            var cb      = new PCheckBox("AllMods")
            {
                CheckSize = new Vector2(24.0f, 24.0f), Text = UI.MODSSCREEN.BUTTON_ALL,
                ToolTip   = UI.TOOLTIPS.DNI_ALL, Margin = new RectOffset(5, 5, 0, 0)
            };
            // When clicked, enable/disable all
            if (handler != null)
            {
                cb.OnChecked = handler.OnClick;
            }
            handler.checkbox = cb.AddTo(bottom, 0);
            handler.UpdateCheckedState();
#endif
            // Current PLib version
            string version = PRegistry.Instance.GetLatestVersion(
                "PeterHan.PLib.Core.PLibCorePatches")?.Version?.ToString() ?? "Unknown";
            string name = ModDebugRegistry.Instance.OwnerOfAssembly(DebugNotIncludedPatches.
                                                                    RunningPLibAssembly)?.ModName ?? "Unknown";
            new PLabel("PLibVersion")
            {
                TextStyle = PUITuning.Fonts.UILightStyle, Text = string.Format(
                    UI.MODSSCREEN.LABEL_PLIB, version ?? PVersion.VERSION), ToolTip =
                    string.Format(UI.TOOLTIPS.DNI_PLIB, name), Margin = new RectOffset(5, 5, 0, 0)
            }.AddTo(bottom, 0);
        }
        /// <summary>
        /// Populates the menu with the available destroy modes.
        /// </summary>
        /// <param name="parameters">The modes to show in the menu.</param>
        internal void PopulateMenu(IList <DestroyFilter> parameters)
        {
            int i      = 0;
            var prefab = ToolMenu.Instance.toolParameterMenu.widgetPrefab;

            ClearMenu();
            foreach (var parameter in parameters)
            {
                // Create prefab based on existing Klei menu
                var widgetPrefab = Util.KInstantiateUI(prefab, choiceList, true);
                PUIElements.SetText(widgetPrefab, parameter.Title);
                var toggle   = widgetPrefab.GetComponentInChildren <MultiToggle>();
                var checkbox = toggle?.gameObject;
                if (checkbox != null)
                {
                    // Set initial state, note that ChangeState is only called by SetCheckState
                    // if it appears to be different, but since this executes before the
                    // parent is active it must be set to something different
                    var option = new DestroyMenuOption(parameter, checkbox);
                    PCheckBox.SetCheckState(checkbox, 2);
                    if (i == 0 || SandboxToolsPatches.AdvancedFilterEnabled)
                    {
                        option.State = ToolParameterMenu.ToggleState.On;
                    }
                    options.Add(parameter.ID, option);
                    toggle.onClick += () => OnClick(checkbox);
                }
                else
                {
                    PUtil.LogWarning("Could not find destroy menu checkbox!");
                }
                i++;
            }
        }
Exemple #4
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));
        }
Exemple #5
0
            internal TypeSelectCategory(TypeSelectControl parent, Tag categoryTag,
                                        string overrideName = null)
            {
                Control     = parent ?? throw new ArgumentNullException("parent");
                CategoryTag = categoryTag;
                string title = string.IsNullOrEmpty(overrideName) ? CategoryTag.ProperName() :
                               overrideName;
                var selectBox = new PCheckBox("SelectCategory")
                {
                    Text      = title, DynamicSize = true, OnChecked = OnCheck,
                    CheckSize = ROW_SIZE, InitialState = PCheckBox.STATE_CHECKED,
                    TextStyle = PUITuning.Fonts.TextDarkStyle
                };

                selectBox.OnRealize += (obj) => { CheckBox = obj; };
                Header = new PPanel("TypeSelectCategory")
                {
                    Direction = PanelDirection.Horizontal, Alignment = TextAnchor.MiddleLeft,
                    Spacing   = 5
                }.AddChild(new PToggle("ShowHide")
                {
                    OnStateChanged = OnToggle, Size = new Vector2(ROW_SIZE.x * 0.5f,
                                                                  ROW_SIZE.y * 0.5f), Color = PUITuning.Colors.ComponentLightStyle
                }).AddChild(selectBox).Build();
                children = new SortedList <Tag, TypeSelectElement>(16, TagAlphabetComparer.
                                                                   INSTANCE);
                ChildPanel = new PPanel("Children")
                {
                    Direction = PanelDirection.Vertical, Alignment = TextAnchor.UpperLeft,
                    Spacing   = ROW_SPACING, Margin = new RectOffset(INDENT, 0, 0, 0)
                }.Build();
                ChildPanel.transform.localScale = Vector3.zero;
            }
        /// <summary>
        /// Updates the visible checkboxes to correspond with the layer settings.
        /// </summary>
        private void OnChange()
        {
            bool all = true;

            foreach (var option in options.Values)
            {
                var checkbox = option.Checkbox;
                switch (option.State)
                {
                case ToolParameterMenu.ToggleState.On:
                    PCheckBox.SetCheckState(checkbox, 1);
                    break;

                case ToolParameterMenu.ToggleState.Off:
                    PCheckBox.SetCheckState(checkbox, 0);
                    all = false;
                    break;

                case ToolParameterMenu.ToggleState.Disabled:
                default:
                    PCheckBox.SetCheckState(checkbox, 2);
                    all = false;
                    break;
                }
            }
            AllSelected = all;
        }
Exemple #7
0
 /// <summary>
 /// Selects all items.
 /// </summary>
 public void CheckAll()
 {
     PCheckBox.SetCheckState(allItems, PCheckBox.STATE_CHECKED);
     foreach (var child in children)
     {
         child.Value.CheckAll();
     }
 }
Exemple #8
0
 /// <summary>
 /// Deselects all items in this category.
 /// </summary>
 public void ClearAll()
 {
     PCheckBox.SetCheckState(CheckBox, PCheckBox.STATE_UNCHECKED);
     foreach (var child in children)
     {
         PCheckBox.SetCheckState(child.Value.CheckBox, PCheckBox.STATE_UNCHECKED);
     }
 }
Exemple #9
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
            };

            cp.OnRealize += (obj) => { childPanel = obj; };
            RootPanel     = new PPanel("Border")
            {
                // 1px dark border for contrast
                Margin    = new RectOffset(1, 1, 1, 1), Direction = PanelDirection.Vertical,
                Alignment = TextAnchor.MiddleCenter, Spacing = 1
            }.AddChild(new PLabel("Title")
            {
                // Title bar
                TextAlignment = TextAnchor.MiddleCenter, Text = SweepByTypeStrings.
                                                                DIALOG_TITLE, FlexSize = new Vector2(1.0f, 0.0f), DynamicSize = true,
                Margin = new RectOffset(1, 1, 1, 1)
            }.SetKleiPinkColor()).AddChild(new PPanel("TypeSelectControl")
            {
                // 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(allCheckBox).AddChild(cp), ScrollHorizontal = false,
                ScrollVertical = true, AlwaysShowVertical = true, TrackSize = 8.0f,
                FlexSize       = Vector2.one, BackColor = PUITuning.Colors.BackgroundLight,
            })).SetKleiBlueColor().BuildWithFixedSize(PANEL_SIZE);
            // Cache the vertical scroll bar
            var vst = RootPanel.transform.Find("TypeSelectControl/Scroll/Viewport/SelectType");

#pragma warning disable IDE0031 // Use null propagation
            vScroll = (vst == null) ? null : vst.gameObject;
#pragma warning restore IDE0031 // Use null propagation
            children = new SortedList <Tag, TypeSelectCategory>(16, TagAlphabetComparer.
                                                                INSTANCE);
            position = Vector3.zero;
            Screen   = RootPanel.AddComponent <TypeSelectScreen>();
        }
Exemple #10
0
        /// <summary>Raises the <see cref="E:System.Windows.Forms.CheckBox.CheckStateChanged" /> event.</summary>
        /// <param name="e">An <see cref="T:System.EventArgs" /> that contains the event data. </param>
        protected override void OnCheckStateChanged(EventArgs e)
        {
            bool?checkedValue = CheckState == CheckState.Indeterminate
                ? (bool?)null
                : (CheckState == CheckState.Checked);

            PCheckBox.SetModelValue(this, PCheckBox.IsCheckedProperty, checkedValue, EBindingSourceUpdateReason.PropertyChanged);
            base.OnCheckStateChanged(e);
        }
Exemple #11
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>();
        }
Exemple #12
0
 /// <summary>
 /// Adds selected types in this category to the list of items to sweep.
 /// </summary>
 /// <param name="items">The location where selected types will be stored.</param>
 internal void AddTypesToSweep(ICollection <Tag> items)
 {
     foreach (var child in children)
     {
         var element = child.Value;
         if (PCheckBox.GetCheckState(element.CheckBox) == PCheckBox.STATE_CHECKED)
         {
             items.Add(child.Key);
         }
     }
 }
Exemple #13
0
 /// <summary>
 /// Deselects all items.
 /// </summary>
 public void ClearAll()
 {
     PCheckBox.SetCheckState(allItems, PCheckBox.STATE_UNCHECKED);
     foreach (var child in children)
     {
         foreach (var entity in child.Children)
         {
             PCheckBox.SetCheckState(entity.CheckBox, PCheckBox.STATE_UNCHECKED);
         }
     }
 }
Exemple #14
0
 internal TypeSelectElement(TypeSelectCategory parent, Tag elementTag)
 {
     this.parent = parent ?? throw new ArgumentNullException("parent");
     ElementTag  = elementTag;
     CheckBox    = new PCheckBox("Select")
     {
         CheckSize = ROW_SIZE, SpriteSize = ROW_SIZE, OnChecked = OnCheck,
         Text      = ElementTag.ProperName(), InitialState = PCheckBox.
                                                             STATE_CHECKED, Sprite = GetStorageObjectSprite(elementTag),
         TextStyle = PUITuning.Fonts.TextDarkStyle
     }.Build();
 }
 /// <summary>
 /// Deselects all items.
 /// </summary>
 public void ClearAll()
 {
     PCheckBox.SetCheckState(allItems, PCheckBox.STATE_UNCHECKED);
     foreach (var row in rows)
     {
         foreach (var entity in row.entities)
         {
             PCheckBox.SetCheckState(entity.CheckBox, PCheckBox.STATE_UNCHECKED);
             Target.GetComponent <UncategorizedFilterable>().RemoveTagFromFilter(entity.ElementTag);
         }
     }
 }
 private void OnCheck(GameObject source, int state)
 {
     if (state == PCheckBox.STATE_UNCHECKED)
     {
         // Clicked when unchecked, check and possibly check all
         PCheckBox.SetCheckState(CheckBox, PCheckBox.STATE_CHECKED);
     }
     else
     {
         // Clicked when checked, clear and possibly uncheck
         PCheckBox.SetCheckState(CheckBox, PCheckBox.STATE_UNCHECKED);
     }
     parent.UpdateFromChildren();
 }
        protected override IUIComponent GetUIComponent()
        {
            var cb = new PCheckBox()
            {
                OnChecked = (source, state) => {
                    // Swap the check: checked and partial -> unchecked
                    check = state == PCheckBox.STATE_UNCHECKED;
                    Update();
                }, ToolTip = ToolTip
            }.SetKleiBlueStyle();

            cb.OnRealize += OnRealizeCheckBox;
            return(cb);
        }
Exemple #18
0
 /// <summary>
 /// Sets the selected state of this type.
 /// </summary>
 /// <param name="selected">true to select this type, or false otherwise.</param>
 public void SetSelected(bool selected)
 {
     if (selected)
     {
         // Clicked when unchecked, check and possibly check all
         PCheckBox.SetCheckState(CheckBox, PCheckBox.STATE_CHECKED);
     }
     else
     {
         // Clicked when checked, clear and possibly uncheck
         PCheckBox.SetCheckState(CheckBox, PCheckBox.STATE_UNCHECKED);
     }
     parent.UpdateFromChildren();
 }
Exemple #19
0
 public GridFilterableSelectableEntity(GridFilterableRow parent, Tag elementTag)
 {
     this.Parent = parent ?? throw new ArgumentNullException("parent");
     ElementTag  = elementTag;
     CheckBox    = new PCheckBox("Select")
     {
         OnChecked    = OnCheck,
         Text         = ElementTag.ProperName(),
         InitialState = PCheckBox.
                        STATE_CHECKED,
         Sprite     = GetStorageObjectSprite(elementTag),
         CheckSize  = ROW_SIZE,
         SpriteSize = ROW_SIZE,
     }.Build();
 }
Exemple #20
0
        public TypeSelectControl()
        {
            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
            };

            cp.OnRealize += (obj) => { childPanel = obj; };
            RootPanel     = new PPanel("Border")
            {
                // 1px dark border for contrast
                Margin    = new RectOffset(1, 1, 1, 1), Direction = PanelDirection.Vertical,
                Alignment = TextAnchor.MiddleCenter, Spacing = 1
            }.AddChild(new PLabel("Title")
            {
                // Title bar
                TextAlignment = TextAnchor.MiddleCenter, Text = SweepByTypeStrings.
                                                                DIALOG_TITLE, FlexSize = new Vector2(1.0f, 0.0f), DynamicSize = true,
                Margin = new RectOffset(1, 1, 1, 1)
            }.SetKleiPinkColor()).AddChild(new PPanel("TypeSelectControl")
            {
                // 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(allCheckBox).AddChild(cp), ScrollHorizontal = false,
                ScrollVertical = true, AlwaysShowVertical = true, TrackSize = 8.0f,
                FlexSize       = Vector2.one, BackColor = PUITuning.Colors.BackgroundLight
            })).SetKleiBlueColor().BuildWithFixedSize(PANEL_SIZE);
            children = new SortedList <Tag, TypeSelectCategory>(16, this);
            Screen   = RootPanel.AddComponent <TypeSelectScreen>();
        }
Exemple #21
0
            internal TypeSelectElement(TypeSelectCategory parent, Tag elementTag)
            {
                this.parent = parent ?? throw new ArgumentNullException("parent");
                var tint   = Color.white;
                var sprite = parent.Control.DisableIcons ? null :
                             GetStorageObjectSprite(elementTag, out tint);

                ElementTag = elementTag;
                CheckBox   = new PCheckBox("Select")
                {
                    CheckSize = ROW_SIZE, SpriteSize = ROW_SIZE, OnChecked = OnCheck,
                    Text      = ElementTag.ProperName(), InitialState = PCheckBox.
                                                                        STATE_CHECKED, Sprite = sprite, SpriteTint = tint,
                    TextStyle = PUITuning.Fonts.TextDarkStyle
                }.Build();
            }
Exemple #22
0
            private void OnCheck(GameObject source, int state)
            {
                switch (state)
                {
                case PCheckBox.STATE_UNCHECKED:
                    // Clicked when unchecked, check and possibly check all
                    PCheckBox.SetCheckState(CheckBox, PCheckBox.STATE_CHECKED);
                    break;

                default:
                    // Clicked when checked, clear and possibly uncheck
                    PCheckBox.SetCheckState(CheckBox, PCheckBox.STATE_UNCHECKED);
                    break;
                }
                parent.UpdateFromChildren();
            }
Exemple #23
0
        /// <summary>
        /// Updates the list of available elements.
        /// </summary>
        public void Update(GridFilterableSideScreen screen)
        {
            Console.WriteLine("updating with the storage");
            Storage    storage = screen.storage;
            GameObject target  = screen.target;

            if (storage.storageFilters != null && storage.storageFilters.Count >= 1)
            {
                // check for which ones aren't added already and add them
                foreach (Tag tag in storage.storageFilters)
                {
                    Console.WriteLine($"Should be checking presence of tag {tag.ToString()}");
                    if (!HasElement(tag))
                    {
                        Console.WriteLine($"Attempted to add {tag.ToString()} to the panel");
                        if (children.Count <= 0)
                        {
                            GridFilterableRow firstRow = new GridFilterableRow(this);
                            children.Add(firstRow);
                            PUIElements.SetParent(firstRow.ChildPanel, childPanel);
                            PUIElements.SetAnchors(firstRow.ChildPanel, PUIAnchoring.Stretch, PUIAnchoring.Stretch);
                        }
                        GridFilterableRow lastRow = children[children.Count - 1];
                        if (lastRow.RowSize >= PER_ROW)
                        {
                            lastRow = new GridFilterableRow(this);
                            PUIElements.SetParent(lastRow.ChildPanel, childPanel);
                            PUIElements.SetAnchors(lastRow.ChildPanel, PUIAnchoring.Stretch, PUIAnchoring.Stretch);
                            children.Add(lastRow);
                        }
                        GridFilterableSelectableEntity entity = new GridFilterableSelectableEntity(lastRow, tag);
                        lastRow.Children.Add(entity);
                        PUIElements.SetParent(entity.CheckBox, lastRow.ChildPanel);
                        if (PCheckBox.GetCheckState(entity.CheckBox) == PCheckBox.STATE_CHECKED)
                        {
                            // Set to checked
                            PCheckBox.SetCheckState(entity.CheckBox, PCheckBox.STATE_CHECKED);
                        }
                    }
                }
            }
            else
            {
                Debug.LogError((object)"If you're filtering, your storage filter should have the filters set on it");
            }
        }
Exemple #24
0
        public GridFilterableControl()
        {
            // 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
            };

            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 PPanel("SelectType")
            {
                Direction = PanelDirection.Vertical,
                Margin    = ELEMENT_MARGIN,
                FlexSize  = new Vector2(1.0f, 0.0f),
                Alignment = TextAnchor.UpperLeft
            }.AddChild(allCheckBox).AddChild(cp)).SetKleiBlueColor().BuildWithFixedSize(PANEL_SIZE);
            children = new List <GridFilterableRow>(16);
            if (Instance != null)
            {
                Debug.LogError("ISSUE! created grid filterable control more than once");
            }
            Instance = this;
        }
Exemple #25
0
        private void OnCheck(GameObject source, int state)
        {
            UncategorizedFilterable uncategorizedFilterable = Parent.Parent.Target.GetComponent <UncategorizedFilterable>();

            switch (state)
            {
            case PCheckBox.STATE_UNCHECKED:
                // Clicked when unchecked, check and possibly check all
                PCheckBox.SetCheckState(CheckBox, PCheckBox.STATE_CHECKED);
                uncategorizedFilterable.AddTagToFilter(ElementTag);
                break;

            default:
                // Clicked when checked, clear and possibly uncheck
                PCheckBox.SetCheckState(CheckBox, PCheckBox.STATE_UNCHECKED);
                uncategorizedFilterable.RemoveTagFromFilter(ElementTag);
                break;
            }
            Parent.UpdateFromChildren();
        }
Exemple #26
0
 private void OnDialogClosed(string option)
 {
     if (option == "ok")
     {
         editor.Description = PTextField.GetText(descriptionField);
         editor.PatchInfo   = PTextField.GetText(patchNotesField);
         editor.Title       = PTextField.GetText(titleField);
         editor.DataPath    = PTextField.GetText(dataPathField);
         editor.UpdateData  = PCheckBox.GetCheckState(doUpdateData) == PCheckBox.
                              STATE_CHECKED;
         editor.PreviewPath   = PTextField.GetText(imagePathField);
         editor.UpdatePreview = PCheckBox.GetCheckState(doUpdateImg) == PCheckBox.
                                STATE_CHECKED;
         editor.StartModify();
     }
     else
     {
         Dispose();
     }
 }
Exemple #27
0
            /// <summary>
            /// Attempts to add a type to this category.
            /// </summary>
            /// <param name="element">The type to add.</param>
            /// <returns>true if it was added, or false if it already exists.</returns>
            public bool TryAddType(Tag element)
            {
                bool add = !children.ContainsKey(element);

                if (add)
                {
                    var child = new TypeSelectElement(this, element);
                    var cb    = child.CheckBox;
                    // Add the element to the list, then get its index and move it in the panel
                    // to maintain sorted order
                    children.Add(element, child);
                    cb.SetParent(ChildPanel);
                    if (PCheckBox.GetCheckState(cb) == PCheckBox.STATE_CHECKED)
                    {
                        // Set to checked
                        PCheckBox.SetCheckState(cb, PCheckBox.STATE_CHECKED);
                    }
                    cb.transform.SetSiblingIndex(children.IndexOfKey(element));
                }
                return(add);
            }
Exemple #28
0
 /// <summary>
 /// Updates the all check box state from the children.
 /// </summary>
 /// <param name="allItems">The "all" or "none" check box.</param>
 /// <param name="children">The child check boxes.</param>
 internal static void UpdateAllItems <T>(GameObject allItems,
                                         IEnumerable <T> children) where T : IHasCheckBox
 {
     if (allItems != null)
     {
         bool all = true, none = true;
         foreach (var child in children)
         {
             if (PCheckBox.GetCheckState(child.CheckBox) == PCheckBox.STATE_CHECKED)
             {
                 none = false;
             }
             else
             {
                 // Partially checked or unchecked
                 all = false;
             }
         }
         PCheckBox.SetCheckState(allItems, none ? PCheckBox.STATE_UNCHECKED : (all ?
                                                                               PCheckBox.STATE_CHECKED : PCheckBox.STATE_PARTIAL));
     }
 }
        public GH_Project_Attributes(GH_Project_Component owner) : base(owner)
        {
            _checkboxPanelHeight = 2 * CHECKBOXHEIGHT + 3 * CHECKBOXPANELPADDING;
            _buttonPanelHeight   = BUTTONSIZE + 2 * BUTTONPANELPADDING;

            _topLabelString      = owner.Name;
            _topLabelStringWidth = GH_FontServer.StringWidth(_topLabelString, GH_FontServer.LargeAdjusted);

            _calcBtn = new PButton("Calculate", owner.PrepareCalculation);

            _cbStream           = new PCheckBox("Stream dat", owner.ToggleStream, owner.StreamContent);
            _cbSilent           = new PCheckBox("Silent calculation", owner.ToggleSilent, owner.SilentCalc);
            _cbStream.IsEnabled = true;
            _cbSilent.IsEnabled = true;

            _btnOpenExplorer = new PButton(owner.IconOpenExplorer, owner.OpenPath);
            _btnTeddy        = new PButton(owner.IconTeddy, owner.OpenTeddy);
            _btnAnimator     = new PButton(owner.IconAnimator, owner.OpenAnimator);
            _btnGraphic      = new PButton(owner.IconGraphic, owner.OpenGraphic);
            _btnResult       = new PButton(owner.IconResult, owner.OpenResult);
            _btnReport       = new PButton(owner.IconReport, owner.OpenReport);
        }
Exemple #30
0
        /// <summary>
        /// Updates the checkbox state based on the current mod selections.
        /// </summary>
        internal void UpdateCheckedState()
        {
            bool all = true, some = false;
            var  mods = Global.Instance.modManager.mods;

            // Check to see if all, some, or none are enabled
            foreach (var mod in mods)
            {
                if (mod.enabled)
                {
                    some = true;
                }
                else
                {
                    all = false;
                }
            }
            // Apply to checkbox
            if (checkbox != null)
            {
                PCheckBox.SetCheckState(checkbox, all ? PCheckBox.STATE_CHECKED : (some ?
                                                                                   PCheckBox.STATE_PARTIAL : PCheckBox.STATE_UNCHECKED));
            }
        }