Esempio n. 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
                });
            }
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        private void SetupControls_DebugLabels(UiBuilder <MainMenuWindow> builder,
                                               UIComponent stackUnder)
        {
            // Pathfinder stats label (debug only)
            if (Options.showPathFindStats)
            {
                using (var statsLabelB = builder.Label <StatsLabel>(string.Empty)) {
                    // Allow the label to hang outside the parent box
                    UResizerConfig.From(statsLabelB.Control).ContributeToBoundingBox = false;

                    UIComponent under = stackUnder; // copy for the closure to work
                    statsLabelB.ResizeFunction(
                        r => {
                        // Extra 2x spacing because of form's inner padding
                        r.Stack(
                            mode: UStackMode.Below,
                            spacing: 2f * UConst.UIPADDING,
                            stackRef: under);
                    });
                    stackUnder = this.StatsLabel = statsLabelB.Control;
                }
            }

            // Hot Reload version label (debug only)
            if (TrafficManagerMod.Instance.InGameHotReload)
            {
                // Hot Reload version label (debug only)
                string text = $"HOT RELOAD {Assembly.GetExecutingAssembly().GetName().Version}";
                using (var hotReloadB = builder.Label <U.ULabel>(text)) {
                    // Allow the label to hang outside the parent box
                    UResizerConfig.From(hotReloadB.Control).ContributeToBoundingBox = false;

                    hotReloadB.ResizeFunction(
                        r => {
                        // If pathFind stats label above was not visible, we need extra spacing
                        float extraSpacing = Options.showPathFindStats ? UConst.UIPADDING : 0f;
                        r.Stack(
                            mode: UStackMode.Below,
                            spacing: extraSpacing + UConst.UIPADDING,
                            stackRef: stackUnder);
                    });
                }
            }
        }
Esempio n. 4
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);
        }
Esempio n. 5
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
                });
            }
        }