Beispiel #1
0
        private UILabel SetupControls_TopRow(UiBuilder <MainMenuWindow> builder,
                                             U.AtlasBuilder atlasBuilder)
        {
            UILabel versionLabel;

            using (var versionLabelB = builder.Label <U.ULabel>(TrafficManagerMod.ModName)) {
                versionLabelB.ResizeFunction(r => r.Stack(UStackMode.Below));
                this.VersionLabel = versionLabel = versionLabelB.Control;
            }

            using (var btnBuilder = builder.Button <U.UButton>()) {
                UButton control = btnBuilder.Control;
                this.toggleOsdButton_ = control;
                control.atlas         = this.allButtonsAtlas_;
                control.name          = "TMPE_MainMenu_HelpButton";

                // Texture for Help will be included in the `allButtonsAtlas_`
                ButtonSkin skin = new ButtonSkin {
                    BackgroundPrefix  = "RoundButton",
                    Prefix            = "Help",
                    BackgroundHovered = true,
                    BackgroundActive  = true,
                    ForegroundActive  = true,
                };
                skin.UpdateAtlasBuilder(
                    atlasBuilder,
                    spriteSize: new IntVector2(50));

                control.Skin = skin;
                control.UpdateButtonImage();

                // This has to be done later when form setup is done:
                // helpB.Control.atlas = allButtonsAtlas_;

                btnBuilder.ResizeFunction(
                    resizeFn: r => {
                    r.Control.isVisible = true;     // not sure why its hidden on create? TODO
                    r.Stack(mode: UStackMode.ToTheRight,
                            spacing: UConst.UIPADDING * 3f,
                            stackRef: versionLabel);
                    r.Width(UValue.FixedSize(18f));     // assume Version label is 18pt high
                    r.Height(UValue.FixedSize(18f));
                });

                control.uCanActivate = c => true;
                control.uTooltip     = Translation.Menu.Get("Tooltip:Toggle onscreen display panel");

                control.uIsActive =
                    c => GlobalConfig.Instance.Main.KeybindsPanelVisible;

                control.uOnClick += (component, eventParam) => {
                    ModUI.Instance.MainMenu.OnToggleOsdButtonClicked(component as U.UButton);
                };
            }

            return(versionLabel);
        }
Beispiel #2
0
        /// <summary>Create buttons and add them to the given panel UIBuilder.</summary>
        /// <param name="builder">UI builder to use.</param>
        /// <param name="atlasKeysSet">Atlas keys to update for button images.</param>
        /// <param name="buttonDefs">Button defs collection to create from it.</param>
        /// <param name="minRowLength">Longest the row can be without breaking.</param>
        /// <returns>A list of created buttons.</returns>
        private AddButtonsResult AddButtonsFromButtonDefinitions(UiBuilder <UPanel> builder,
                                                                 U.AtlasBuilder atlasBuilder,
                                                                 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 buttonBuilder = builder.Button <BaseMenuButton>(buttonDef.ButtonType);

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

                buttonBuilder.ResizeFunction(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
                buttonBuilder.Control.SetupButtonSkin(atlasBuilder);

                string buttonName = buttonDef.ButtonType.ToString().Split('.').Last();
                buttonBuilder.Control.name = $"TMPE_MainMenuButton_{buttonName}";

                ButtonsDict.Add(buttonDef.Mode, buttonBuilder.Control);
                result.Buttons.Add(buttonBuilder.Control);
            }

            return(result);
        }
Beispiel #3
0
        private UILabel SetupControls_TopRow(UiBuilder <MainMenuWindow> builder,
                                             HashSet <string> atlasKeySet)
        {
            UILabel versionLabel;

            using (var versionLabelB = builder.Label <U.Label.ULabel>(TrafficManagerMod.ModName)) {
                versionLabelB.ResizeFunction(r => r.Stack(UStackMode.Below));
                this.VersionLabel = versionLabel = versionLabelB.Control;
            }

            using (var helpB = builder.Button <U.Button.UButton>()) {
                this.helpButton_    = helpB.Control;
                helpB.Control.atlas = this.allButtonsAtlas_;
                helpB.Control.name  = "TMPE_MainMenu_HelpButton";

                // Texture for Help will be included in the `allButtonsAtlas_`
                ButtonSkin skin = new ButtonSkin {
                    BackgroundPrefix  = "RoundButton",
                    Prefix            = "Help",
                    BackgroundHovered = true,
                    BackgroundActive  = true,
                    ForegroundActive  = true,
                };
                atlasKeySet.AddRange(skin.CreateAtlasKeyset());

                helpB.Control.Skin = skin;
                helpB.Control.UpdateButtonImage();

                // This has to be done later when form setup is done:
                // helpB.Control.atlas = allButtonsAtlas_;

                helpB.ResizeFunction(
                    resizeFn: r => {
                    r.Control.isVisible = true;     // not sure why its hidden on create? TODO
                    r.Stack(mode: UStackMode.ToTheRight,
                            spacing: UConst.UIPADDING * 3f,
                            stackRef: versionLabel);
                    r.Width(UValue.FixedSize(18f));     // assume Version label is 18pt high
                    r.Height(UValue.FixedSize(18f));
                });

                helpB.Control.uCanActivate = c => true;

                helpB.Control.uIsActive =
                    c => GlobalConfig.Instance.Main.KeybindsPanelVisible;

                helpB.Control.uOnClick += (component, eventParam) => {
                    ModUI.Instance.MainMenu.OnHelpButtonClicked(component as U.Button.UButton);
                };
            }

            return(versionLabel);
        }