Exemplo n.º 1
0
        public ItemSlider(MenuCategoryBase category, string title, float min, float max, float defaultValue, int rounding,
                          Func <float> getter,
                          Action <float> setter       = null,
                          Action <float> sliding      = null,
                          Action <float> cancelled    = null,
                          Func <float, string> format = null) : base(category)
        {
            Title        = title;
            Min          = min;
            Max          = max;
            Rounding     = rounding;
            Getter       = getter;
            Setter       = setter;
            Sliding      = sliding;
            Cancelled    = cancelled;
            Format       = format;
            DefaultValue = defaultValue;

            if (Format == null)
            {
                string formatString = "N" + rounding.ToString();
                Format = (val) => val.ToString(formatString);
            }

            float initialPercent = ValueToPercent(Min, Max, Getter());

            Item = new MenuSliderInput(string.Empty, category, initialPercent, title, OnSubmit, OnSlide, OnCancel);

            UpdateTitle();
        }
Exemplo n.º 2
0
        private MenuCategoryBase AddCategory(string name, MenuCategoryBase parent, string header = null, ItemGroup group = null)
        {
            ItemSubMenu item = new ItemSubMenu(parent, name, header);

            group?.Add(item);
            return(item.Item);
        }
Exemplo n.º 3
0
 public ItemButton(MenuCategoryBase category, string title, Action action) : base(category)
 {
     Title  = title;
     Action = action;
     Item   = new MenuItem(string.Empty, category, OnClick);
     UpdateTitle();
 }
Exemplo n.º 4
0
 /// <summary>
 /// Creates a sub category, must attach to either Root or another Sub Category.
 /// </summary>
 /// <param name="Text">Text displayed in the category list</param>
 /// <param name="Parent">Must be either a MenuRootCategory or MenuSubCategory objectMust be either a MenuRootCategory or MenuSubCategory object</param>
 /// <param name="HeaderText">Header text of this menu list.</param>
 public MenuSubCategory(string Text, MenuCategoryBase Parent, string HeaderText = "Default Header")
 {
     Instance.RegisterCheck();
     BackingObject = Instance.CreateMessage(MessageTypes.MenuSubCategory);
     this.Text     = Text;
     this.Header   = HeaderText;
     this.Parent   = Parent;
 }
Exemplo n.º 5
0
            /// <summary>
            /// Basic toggle. You can use this to create on/off toggles, checkbox lists or option lists.
            /// </summary>
            /// <param name="Text">Text displayed in the category list</param>
            /// <param name="Parent">Must be either a MenuRootCategory or MenuSubCategory object</param>
            /// <param name="OnClick">On click event that will be fired if the user selects this item.</param>
            /// <param name="Interactable">User can select this item. true by default</param>
            public MenuItem(string Text, MenuCategoryBase Parent, Action OnClick = null, bool Interactable = true)
            {
                Instance.RegisterCheck();
                BackingObject = Instance.CreateMessage(MessageTypes.MenuItem);

                this.Text         = Text;
                this.Parent       = Parent;
                this.OnClick      = OnClick;
                this.Interactable = Interactable;
            }
Exemplo n.º 6
0
        public ItemInput(MenuCategoryBase category, string title, Func <ControlCombination> getter, Action <ControlCombination> setter, ControlCombination defaultValue) : base(category)
        {
            Title        = title;
            Getter       = getter;
            Setter       = setter;
            DefaultValue = defaultValue;

            Item = new MenuKeybindInput(string.Empty, category, "Press a key to bind.\nCan be combined with alt/ctrl/shift.\nUnbind by confirming without a key.", OnSubmit);

            UpdateTitle();
        }
Exemplo n.º 7
0
 public ItemToggle(MenuCategoryBase category, string title, Func <bool> getter, Action <bool> setter, bool defaultValue = true, string onText = "On", string offText = "Off") : base(category)
 {
     Title        = title;
     OnText       = onText;
     OffText      = offText;
     Getter       = getter;
     Setter       = setter;
     DefaultValue = defaultValue;
     Item         = new MenuItem(string.Empty, category, OnClick);
     UpdateTitle();
 }
Exemplo n.º 8
0
        public ItemBoxMove(MenuCategoryBase category, string title, Vector2D min, Vector2D max, Vector2D defaultValue, int rounding,
                           Func <Vector2D> getter,
                           Action <Vector2D> setter    = null,
                           Action <Vector2D> selected  = null,
                           Action <Vector2D> moving    = null,
                           Action <Vector2D> cancelled = null) : base(category)
        {
            Title        = title;
            Min          = min;
            Max          = max;
            DefaultValue = defaultValue;
            Rounding     = rounding;
            format       = "N" + rounding.ToString();
            Getter       = getter;
            Setter       = setter;
            Selected     = selected;
            Moving       = moving;
            Cancelled    = cancelled;

            // HACK using `" "` instead of string.Empty due to an issue with textAPI.
            Item = new MenuScreenInput(string.Empty, category, Getter(), Vector2D.Zero, " ", OnSubmit, OnMove, OnCancel, OnSelect);
            UpdateTitle();
        }
Exemplo n.º 9
0
 public ItemSubMenu(MenuCategoryBase category, string title, string header = null) : base(category)
 {
     Title = title;
     Item  = new MenuSubCategory(string.Empty, category, header ?? title);
     UpdateTitle();
 }
Exemplo n.º 10
0
 public ItemBase(MenuCategoryBase category)
 {
     Category = category;
 }
Exemplo n.º 11
0
        private void TextAPI_Detected()
        {
            Category_Mod = new MenuRootCategory(Log.ModName, MenuFlag.PlayerMenu, Log.ModName + " Settings");

            new ItemButton(Category_Mod, "Help Window", () =>
            {
                // HACK: schedule to be shown after chat is closed, due to a soft lock bug with ShowMissionScreen() when chat is opened.
                SetUpdateMethods(UpdateFlags.UPDATE_AFTER_SIM, true);
            });

            #region Tool
            Category_Tool = AddCategory("Tool", Category_Mod);

            groupAll.Add(new ItemToggle(Category_Tool, "Spray Particles",
                                        getter: () => Main.Settings.sprayParticles,
                                        setter: (v) =>
            {
                Main.Settings.sprayParticles = v;
                Main.Settings.ChangedByModConfig();
            },
                                        defaultValue: true));

            groupAll.Add(new ItemSlider(Category_Tool, "Spray Sound Volume", min: 0, max: 1, defaultValue: 0.8f, rounding: 2,
                                        getter: () => Main.Settings.spraySoundVolume,
                                        setter: (val) =>
            {
                Main.Settings.spraySoundVolume = val;
                Main.Settings.ChangedByModConfig();
            },
                                        sliding: (val) =>
            {
                Main.Settings.spraySoundVolume = val;
            },
                                        cancelled: (orig) =>
            {
                Main.Settings.spraySoundVolume = orig;
            }));

            groupAll.Add(new ItemToggle(Category_Tool, "Extra Sounds",
                                        getter: () => Main.Settings.extraSounds,
                                        setter: (v) =>
            {
                Main.Settings.extraSounds = v;
                Main.Settings.ChangedByModConfig();
            },
                                        defaultValue: true));
            #endregion Tool

            #region Palette
            Category_Palette = AddCategory("HUD Palette", Category_Mod);

            groupAll.Add(new ItemToggle(Category_Palette, "Select Color in Zig-Zag",
                                        getter: () => Main.Settings.selectColorZigZag,
                                        setter: (v) =>
            {
                Main.Settings.selectColorZigZag = v;
                Main.Settings.ChangedByModConfig();
            },
                                        defaultValue: false));

            groupAll.Add(new ItemToggle(Category_Palette, "Require CTRL for Color Cycle",
                                        getter: () => Main.Settings.requireCtrlForColorCycle,
                                        setter: (v) =>
            {
                Main.Settings.requireCtrlForColorCycle = v;
                Main.Settings.ChangedByModConfig();
            },
                                        defaultValue: false));

            groupAll.Add(new ItemToggle(Category_Palette, "Hide Palette with HUD",
                                        getter: () => Main.Settings.hidePaletteWithHUD,
                                        setter: (v) =>
            {
                Main.Settings.hidePaletteWithHUD = v;
                Main.Settings.ChangedByModConfig();
            },
                                        defaultValue: true));

            groupAll.Add(new ItemSlider(Category_Palette, "Background Opacity", min: -0.1f, max: 1f, defaultValue: -0.1f, rounding: 2,
                                        getter: () => Main.Settings.paletteBackgroundOpacity,
                                        setter: (val) =>
            {
                Main.Settings.paletteBackgroundOpacity = (val < 0 ? -1 : val);
                Main.Settings.ChangedByModConfig();
            },
                                        sliding: (val) =>
            {
                Main.Settings.paletteBackgroundOpacity = (val < 0 ? -1 : val);
                Main.PaletteHUD.UpdateUI();
            },
                                        cancelled: (orig) =>
            {
                Main.Settings.paletteBackgroundOpacity = (orig < 0 ? -1 : orig);
                Main.PaletteHUD.UpdateUI();
            },
                                        format: (val) =>
            {
                return(val < 0 ? "HUD" : val.ToString("0.00"));
            }));

            groupAll.Add(new ItemBoxMove(Category_Palette, "Screen Position", min: -Vector2D.One, max: Vector2D.One, defaultValue: Settings.paletteScreenPosDefault, rounding: 3,
                                         getter: () => Main.Settings.paletteScreenPos,
                                         setter: (pos) =>
            {
                Main.Settings.paletteScreenPos = pos;
                Main.Settings.ChangedByModConfig();
            },
                                         selected: (pos) =>
            {
                Main.Settings.paletteScreenPos = pos;
                Main.PaletteHUD.UpdateUI();
            },
                                         moving: (pos) =>
            {
                Main.Settings.paletteScreenPos = pos;
                Main.PaletteHUD.UpdateUI();
            },
                                         cancelled: (origPos) =>
            {
                Main.Settings.paletteScreenPos = origPos;
                Main.PaletteHUD.UpdateUI();
            }));

            groupAll.Add(new ItemSlider(Category_Palette, "Scale", min: 0.1f, max: 2f, defaultValue: Settings.paletteScaleDefault, rounding: 2,
                                        getter: () => Main.Settings.paletteScale,
                                        setter: (val) =>
            {
                Main.Settings.paletteScale = val;
                Main.Settings.ChangedByModConfig();
            },
                                        sliding: (val) =>
            {
                Main.Settings.paletteScale = val;
                Main.PaletteHUD.UpdateUI();
            },
                                        cancelled: (orig) =>
            {
                Main.Settings.paletteScale = orig;
                Main.PaletteHUD.UpdateUI();
            }));
            #endregion Palette

            #region Toggle skins shown list
            Category_HideSkins = AddCategory("Skins Shown in Palette", Category_Mod);

            groupAll.Add(new ItemToggle(Category_HideSkins, "Toggle ALL",
                                        getter: () => Main.Settings.hideSkinsFromPalette.Count == 0,
                                        setter: (v) =>
            {
                Main.Settings.hideSkinsFromPalette.Clear();

                if (!v)
                {
                    foreach (SkinInfo skin in Main.Palette.Skins.Values)
                    {
                        if (skin.SubtypeId == MyStringHash.NullOrEmpty)
                        {
                            continue;     // ignore "no skin"
                        }
                        Main.Settings.hideSkinsFromPalette.Add(skin.SubtypeId.String);
                    }
                }

                Main.Settings.ChangedByModConfig();
                groupSkins.Update();
            },
                                        defaultValue: true));

            StringBuilder label = new StringBuilder();

            foreach (IGrouping <SkinGroup, SkinInfo> group in Main.Palette.Skins.Values.GroupBy(s => s.MenuGroup).OrderBy(g => g.Key))
            {
                IEnumerable <SkinInfo> skins;
                switch (group.Key)
                {
                default: skins = group.OrderBy(s => s.SubtypeId.String); break;

                case SkinGroup.ModAdded: skins = group.OrderBy(s => s.Mod); break;

                case SkinGroup.DLC: skins = group.OrderBy(s => s.DLCSort); break;
                }

                foreach (SkinInfo skin in skins)
                {
                    if (skin.SubtypeId == MyStringHash.NullOrEmpty)
                    {
                        continue; // ignore "no skin"
                    }
                    label.Clear().Append(skin.Name);

                    if (skin.DLC != null)
                    {
                        bool owned = MyAPIGateway.DLC.HasDefinitionDLC(skin.Definition, MyAPIGateway.Multiplayer.MyId);

                        label.Append(" (").Append(owned ? "<color=skyblue>" : "<color=255,25,0>");
                        foreach (string dlc in skin.Definition.DLCs)
                        {
                            IMyDLC dlcInfo = MyAPIGateway.DLC.GetDLC(dlc);
                            label.Append(MyTexts.GetString(dlcInfo.DisplayName)).Append(", ");
                        }

                        label.Length -= 2; // remove last comma
                        label.Append("<reset>)");
                    }
                    else if (skin.Mod != null)
                    {
                        label.Append(" (<color=200,120,25>").Append(skin.Mod).Append("<reset>)");
                    }

                    // necessary in loops to avoid wrong thing being captured
                    MyStringHash skinId = skin.SubtypeId;

                    ItemToggle item = new ItemToggle(Category_HideSkins, label.ToString(),
                                                     getter: () => !Main.Settings.hideSkinsFromPalette.Contains(skinId.String),
                                                     setter: (v) =>
                    {
                        if (!v)
                        {
                            Main.Settings.hideSkinsFromPalette.Add(skinId.String);
                        }
                        else
                        {
                            Main.Settings.hideSkinsFromPalette.Remove(skinId.String);
                        }
                        Main.Settings.ChangedByModConfig();
                    },
                                                     defaultValue: true);

                    groupAll.Add(item);
                    groupSkins.Add(item);
                }
            }
            #endregion Palette >>> SkinsShown

            #region AimInfo
            Category_AimInfo = AddCategory("Aimed Object Info", Category_Mod);

            // TODO: make it work with scale?
            //groupAll.Add(new ItemSlider(Category_AimInfo, "Scale", min: 0.1f, max: 2f, defaultValue: Settings.aimInfoScaleDefault, rounding: 2,
            //    getter: () => Settings.aimInfoScale,
            //    setter: (val) =>
            //    {
            //        Settings.aimInfoScale = val;
            //        Settings.ChangedByModConfig();
            //    },
            //    sliding: (val) =>
            //    {
            //        Settings.aimInfoScale = val;
            //        SelectionGUI.UpdateUISettings();
            //    },
            //    cancelled: (orig) =>
            //    {
            //        Settings.aimInfoScale = orig;
            //        SelectionGUI.UpdateUISettings();
            //    }));

            groupAll.Add(new ItemSlider(Category_AimInfo, "Background Opacity", min: -0.1f, max: 1f, defaultValue: -0.1f, rounding: 2,
                                        getter: () => Main.Settings.aimInfoBackgroundOpacity,
                                        setter: (val) =>
            {
                Main.Settings.aimInfoBackgroundOpacity = (val < 0 ? -1 : val);
                Main.Settings.ChangedByModConfig();
            },
                                        sliding: (val) =>
            {
                Main.Settings.aimInfoBackgroundOpacity = (val < 0 ? -1 : val);
                Main.SelectionGUI.UpdateUISettings();
            },
                                        cancelled: (orig) =>
            {
                Main.Settings.aimInfoBackgroundOpacity = (orig < 0 ? -1 : orig);
                Main.SelectionGUI.UpdateUISettings();
            },
                                        format: (val) =>
            {
                return(val < 0 ? "HUD" : val.ToString("0.00"));
            }));

            groupAll.Add(new ItemBoxMove(Category_AimInfo, "Screen Position", min: -Vector2D.One, max: Vector2D.One, defaultValue: Settings.aimInfoScreenPosDefault, rounding: 3,
                                         getter: () => Main.Settings.aimInfoScreenPos,
                                         setter: (pos) =>
            {
                Main.Settings.aimInfoScreenPos = pos;
                Main.Settings.ChangedByModConfig();
            },
                                         selected: (pos) =>
            {
                Main.Settings.aimInfoScreenPos = pos;
                Main.SelectionGUI.UpdateUISettings();
            },
                                         moving: (pos) =>
            {
                Main.Settings.aimInfoScreenPos = pos;
                Main.SelectionGUI.UpdateUISettings();
            },
                                         cancelled: (origPos) =>
            {
                Main.Settings.aimInfoScreenPos = origPos;
                Main.SelectionGUI.UpdateUISettings();
            }));
            #endregion AimInfo

            #region Hotkeys
            Category_Hotkeys = AddCategory("Hotkeys", Category_Mod);

            groupAll.Add(new ItemInput(Category_Hotkeys, "Color Pick Mode (Bind 1)",
                                       getter: () => Main.Settings.colorPickMode1,
                                       setter: (combination) =>
            {
                Main.Settings.colorPickMode1 = combination;
                Main.Settings.ChangedByModConfig();
            },
                                       defaultValue: Main.Settings.default_colorPickMode1));

            groupAll.Add(new ItemInput(Category_Hotkeys, "Color Pick Mode (Bind 2)",
                                       getter: () => Main.Settings.colorPickMode2,
                                       setter: (combination) =>
            {
                Main.Settings.colorPickMode2 = combination;
                Main.Settings.ChangedByModConfig();
            },
                                       defaultValue: Main.Settings.default_colorPickMode2));

            groupAll.Add(new ItemInput(Category_Hotkeys, "Instant Color Pick (Bind 1)",
                                       getter: () => Main.Settings.instantColorPick1,
                                       setter: (combination) =>
            {
                Main.Settings.instantColorPick1 = combination;
                Main.Settings.ChangedByModConfig();
            },
                                       defaultValue: Main.Settings.default_instantColorPick1));

            groupAll.Add(new ItemInput(Category_Hotkeys, "Instant Color Pick (Bind 2)",
                                       getter: () => Main.Settings.instantColorPick2,
                                       setter: (combination) =>
            {
                Main.Settings.instantColorPick2 = combination;
                Main.Settings.ChangedByModConfig();
            },
                                       defaultValue: Main.Settings.default_instantColorPick2));

            groupAll.Add(new ItemInput(Category_Hotkeys, "Replace Color Mode (Bind 1)",
                                       getter: () => Main.Settings.replaceColorMode1,
                                       setter: (combination) =>
            {
                Main.Settings.replaceColorMode1 = combination;
                Main.Settings.ChangedByModConfig();
            },
                                       defaultValue: Main.Settings.default_replaceColorMode1));

            groupAll.Add(new ItemInput(Category_Hotkeys, "Replace Color Mode (Bind 2)",
                                       getter: () => Main.Settings.replaceColorMode2,
                                       setter: (combination) =>
            {
                Main.Settings.replaceColorMode2 = combination;
                Main.Settings.ChangedByModConfig();
            },
                                       defaultValue: Main.Settings.default_replaceColorMode2));
            #endregion Hotkeys

            Main.Settings.SettingsLoaded += SettingsLoaded;
        }
Exemplo n.º 12
0
 private void AddSpacer(MenuCategoryBase category, string label = null)
 {
     new MenuItem($"<color=0,55,0>{(label == null ? new string('=', 10) : $"=== {label} ===")}", category);