示例#1
0
        /// <summary>
        /// On Screen Display feature: Add a click info to the panel.
        /// </summary>
        /// <param name="localizedText">Text from Translation.Get() or English if doesn't exist.</param>
        public static void Click(bool shift, bool ctrl, bool alt, string localizedText)
        {
            MainMenuWindow mainMenu = ModUI.Instance.MainMenu;

            mainMenu.KeybindsPanel.isVisible = true;

            var builder = new UiBuilder <U.Panel.UPanel>(mainMenu.KeybindsPanel);

            using (var modifierLabel = builder.ModifierLabel(shift, ctrl, alt)) {
                modifierLabel.ResizeFunction(r => { r.Stack(UStackMode.NewRowBelow); });
            }

            using (var plusLabel = builder.Label <U.Label.ULabel>("+ ")) {
                plusLabel.ResizeFunction(r => { r.Stack(UStackMode.ToTheRight); });
            }

            string clickText = Translation.Options.Get("Shortcut:Click");

            using (var clickLabel = builder.Label <U.Label.ULabel>(clickText)) {
                clickLabel.Control.backgroundSprite = "GenericPanelDark";
                clickLabel.Control.textColor        = UConst.SHORTCUT_KEYBIND_TEXT;
                clickLabel.ResizeFunction(r => { r.Stack(UStackMode.ToTheRight); });
            }

            using (var descriptionLabel = builder.Label <U.Label.ULabel>(localizedText)) {
                descriptionLabel.ResizeFunction(
                    r => {
                    r.Stack(
                        mode: UStackMode.ToTheRight,
                        spacing: UConst.UIPADDING * 2f);     // double space
                });
            }
        }
示例#2
0
        /// <summary>Resize everything in MainMenu to fit the new panel contents.</summary>
        public static void Done()
        {
            MainMenuWindow mainMenu = ModUI.Instance.MainMenu;

            // Recalculate now
            UResizer.UpdateControl(mainMenu);
        }
示例#3
0
            /// <summary>Create buttons and add them to the given panel UIBuilder.</summary>
            /// <param name="window">The parent window.</param>
            /// <param name="parentComponent">The parent panel component to host the buttons.</param>
            /// <param name="builder">UI builder to use.</param>
            /// <param name="buttonDefs">The button definitions array.</param>
            /// <param name="minRowLength">Shortest horizontal row length allowed before breaking new row.</param>
            /// <returns>A list of created buttons.</returns>
            private AddButtonsResult AddButtonsFromButtonDefinitions(
                MainMenuWindow window,
                UIComponent parentComponent,
                UBuilder builder,
                MenuButtonDef[] buttonDefs,
                int minRowLength)
            {
                AddButtonsResult result;

                result.Buttons = new List <BaseMenuButton>();

                // Count the button objects and set their layout
                result.Layout = new MainMenuLayout();
                result.Layout.CountEnabledButtons(buttonDefs);
                int placedInARow = 0;

                foreach (MenuButtonDef buttonDef in buttonDefs)
                {
                    if (!buttonDef.IsEnabledFunc())
                    {
                        // Skip buttons which are not enabled
                        continue;
                    }

                    // Create and populate the panel with buttons
                    var button = parentComponent.AddUIComponent(buttonDef.ButtonType) as BaseMenuButton;

                    // Count buttons in a row and break the line
                    bool doRowBreak = result.Layout.IsRowBreak(placedInARow, minRowLength);

                    button.ResizeFunction(
                        resizeFn: (UResizer r) => {
                        r.Stack(doRowBreak ? UStackMode.NewRowBelow : UStackMode.ToTheRight);
                        r.Width(UValue.FixedSize(40f));
                        r.Height(UValue.FixedSize(40f));
                    });

                    if (doRowBreak)
                    {
                        placedInARow = 0;
                        result.Layout.Rows++;
                    }
                    else
                    {
                        placedInARow++;
                    }

                    // Also ask each button what sprites they need
                    button.SetupButtonSkin(builder.AtlasBuilder);

                    // Take button classname, split by ".", and the last word becomes the button name
                    string buttonName = buttonDef.ButtonType.ToString().Split('.').Last();
                    button.name = $"TMPE_MainMenuButton_{buttonName}";

                    window.ButtonsDict.Add(buttonDef.Mode, button);
                    result.Buttons.Add(button);
                }

                return(result);
            }
示例#4
0
            public void SetupExtraButtons(MainMenuWindow window,
                                          UBuilder builder,
                                          AddButtonsResult toolButtonsResult)
            {
                this.name = "TMPE_MainMenu_ExtraPanel";

                // Silver background panel
                this.atlas            = TextureUtil.Ingame;
                this.backgroundSprite = "GenericPanel";

                // The panel will be Dark Silver at 50% dark 100% alpha
                this.color = new Color32(128, 128, 128, 255);

                this.ResizeFunction(
                    resizeFn: (UResizer r) => {
                    // Step to the right by 4px
                    r.Stack(
                        mode: UStackMode.ToTheRight,
                        spacing: UConst.UIPADDING);
                    r.FitToChildren();
                });

                // Place two extra buttons (despawn & clear traffic).
                // Use as many rows as in the other panel.
                var extraButtonsResult = AddButtonsFromButtonDefinitions(
                    window,
                    parentComponent: this,
                    builder,
                    buttonDefs: EXTRA_BUTTON_DEFS,
                    minRowLength: toolButtonsResult.Layout.Rows == 2 ? 1 : 2);

                window.ExtraButtonsList = extraButtonsResult.Buttons;
            }
示例#5
0
            public void SetupControls(MainMenuWindow window, UBuilder builder)
            {
                this.name = "TMPE_MainMenu_KeybindsPanel";

                // the GenericPanel sprite is Light Silver, make it dark
                this.atlas            = TextureUtil.Ingame;
                this.backgroundSprite = "GenericPanel";
                this.color            = new Color32(64, 64, 64, 240);
                this.opacity          = GlobalConfig.Instance.Main.KeybindsPanelVisible
                                   ? 1f
                                   : 0f;

                this.SetPadding(UPadding.Default);

                // The keybinds panel belongs to main menu but does not expand it to fit
                this.ContributeToBoundingBox(false);

                this.ResizeFunction(
                    resizeFn: (UResizer r) => {
                    r.Stack(mode: UStackMode.NewRowBelow, spacing: UConst.UIPADDING * 2);

                    // As the control technically belongs inside the mainmenu, it will respect
                    // the 4px padding, we want to shift it slightly left to line up with the
                    // main menu panel.
                    r.MoveBy(new Vector2(-UConst.UIPADDING, 0f));
                    r.FitToChildren();
                });
            }
示例#6
0
        /// <summary>On Screen Display feature: Clear and maybe hide the keybind panel.</summary>
        public static void Begin()
        {
            MainMenuWindow mainMenu = ModUI.Instance.MainMenu;

            foreach (Transform c in mainMenu.KeybindsPanel.transform)
            {
                c.gameObject.SetActive(false);
                UnityEngine.Object.Destroy(c.gameObject);
            }

            mainMenu.KeybindsPanel.transform.DetachChildren();
            mainMenu.KeybindsPanel.isVisible = false;
        }
示例#7
0
        /// <summary>
        /// Called from ModUI when need to create or re-create the MainMenu panel.
        /// </summary>
        /// <returns>The created panel.</returns>
        internal static MainMenuWindow CreateMainMenuWindow()
        {
            UIView         parent = UIView.GetAView();
            MainMenuWindow window = (MainMenuWindow)parent.AddUIComponent(typeof(MainMenuWindow));

            window.gameObject.AddComponent <CustomKeyHandler>();

            using (var builder = new U.UiBuilder <MainMenuWindow>(window)) {
                builder.ResizeFunction(r => { r.FitToChildren(); });
                builder.SetPadding(UConst.UIPADDING);

                window.SetupControls(builder);
                // window.SetTransparency(GlobalConfig.Instance.Main.GuiTransparency);

                // Resize everything correctly
                builder.Done();
            }

            return(window);
        }
示例#8
0
        /// <summary>
        /// On Screen Display feature: Add another keybind to the panel.
        /// </summary>
        /// <param name="kbSetting">KeybindSetting to show.</param>
        /// <param name="localizedText">Text from Translation.Get() or English if doesn't exist.</param>
        public static void Shortcut(KeybindSetting kbSetting, string localizedText)
        {
            MainMenuWindow mainMenu = ModUI.Instance.MainMenu;

            mainMenu.KeybindsPanel.isVisible = true;

            var builder = new UiBuilder <U.Panel.UPanel>(mainMenu.KeybindsPanel);

            using (var shortcutLabel = builder.ShortcutLabel(kbSetting)) {
                shortcutLabel.ResizeFunction(r => { r.Stack(UStackMode.NewRowBelow); });
            }

            using (var descriptionLabel = builder.Label <U.Label.ULabel>(localizedText)) {
                descriptionLabel.ResizeFunction(
                    r => {
                    r.Stack(
                        mode: UStackMode.ToTheRight,
                        spacing: UConst.UIPADDING * 2f);     // double space
                });
            }
        }
示例#9
0
            public AddButtonsResult SetupToolButtons(MainMenuWindow window, UBuilder builder)
            {
                this.name = "TMPE_MainMenu_ToolPanel";
                this.ResizeFunction(
                    (UResizer r) => {
                    r.Stack(mode: UStackMode.Below);
                    r.FitToChildren();
                });

                // Create 1 or 2 rows of button objects
                var toolButtonsResult = AddButtonsFromButtonDefinitions(
                    window,
                    parentComponent: this,
                    builder,
                    buttonDefs: TOOL_BUTTON_DEFS,
                    minRowLength: 4);

                window.ToolButtonsList = toolButtonsResult.Buttons;

                return(toolButtonsResult);
            }