示例#1
0
        public ColoredButton(string text, Font font, Brush textColor, float r, float g, float b, float a)
        {
            label = new Label(text, font, textColor);

            float width = label.Width + 20, height = label.Height + 10;

            var up =
                new ColoredRectangle(0, 0, width, height / 2, r, g, b, a);
            var upBottom =
                new ColoredRectangle(0, height / 2, width, height / 2, Math.Max(r - 0.1F, 0), Math.Max(g - 0.1F, 0), Math.Max(b - 0.1F, 0), a);
            up.AddChild(upBottom);

            var down =
                new ColoredRectangle(0, 0, width, height / 2, Math.Max(r - 0.05F, 0), Math.Max(g - 0.05F, 0), Math.Max(b - 0.05F, 0), a);
            var downBottom =
                new ColoredRectangle(0, height / 2, width, height / 2, Math.Min(r + 0.05F, 1), Math.Min(g + 0.05F, 1), Math.Min(b + 0.05F, 1), a);
            down.AddChild(downBottom);

            var hover =
                new ColoredRectangle(0, 0, width, height / 2, Math.Min(r + 0.1F, 1), Math.Min(g + 0.1F, 1), Math.Min(b + 0.1F, 1), a);
            var hoverBottom =
                new ColoredRectangle(0, height / 2, width, height / 2, r, g, b, a);
            hover.AddChild(hoverBottom);

            Skin = new ButtonSkin(up, down, hover);
            Initialize(width, height);
            AddChild(label);

            Resize();
        }
示例#2
0
        private UITextureAtlas GetAtlas()
        {
            if (laneArrowButtonAtlas_ != null)
            {
                return(laneArrowButtonAtlas_);
            }

            // Create base atlas with backgrounds and no foregrounds
            ButtonSkin backgroundOnlySkin = ButtonSkin.CreateDefaultNoForeground("LaneArrow");
            var        futureAtlas        = new U.AtlasBuilder();

            backgroundOnlySkin.UpdateAtlasBuilder(
                atlasBuilder: futureAtlas,
                spriteSize: new IntVector2(64));

            // Merge names of all foreground sprites for 3 directions into atlasKeySet
            foreach (string prefix in new[]
                     { "LaneArrowLeft", "LaneArrowRight", "LaneArrowForward" })
            {
                ButtonSkin skin = ButtonSkin.CreateDefaultNoBackground(prefix);

                // Create keysets for lane arrow button icons and merge to the shared atlas
                skin.UpdateAtlasBuilder(
                    atlasBuilder: futureAtlas,
                    spriteSize: new IntVector2(64));
            }

            // Load actual graphics into an atlas
            laneArrowButtonAtlas_ = futureAtlas.CreateAtlas(
                atlasName: "LaneArrowsTool_Atlas",
                loadingPath: "LaneArrows",
                atlasSizeHint: new IntVector2(256));
            return(laneArrowButtonAtlas_);
        }
        private UITextureAtlas GetUiAtlas()
        {
            if (guiAtlas_ != null)
            {
                return(guiAtlas_);
            }

            // Create base atlas with backgrounds and no foregrounds
            var futureAtlas = new AtlasBuilder(
                atlasName: "SpeedLimits_Atlas",
                loadingPath: "SpeedLimits",
                sizeHint: new IntVector2(512));

            // Merge names of all button sprites atlasBuilder
            foreach (string prefix in new[]
                     { "MphToggle", "EditSegments", "EditLanes", "EditDefaults" })
            {
                ButtonSkin skin = ButtonSkin.CreateSimple(
                    foregroundPrefix: prefix,
                    backgroundPrefix: UConst.MAINMENU_ROUND_BUTTON_BG)
                                  .CanActivate(background: false)
                                  .CanHover(foreground: false);

                // Create keysets for lane arrow button icons and merge to the shared atlas
                skin.UpdateAtlasBuilder(
                    atlasBuilder: futureAtlas,
                    spriteSize: new IntVector2(50));
            }

            // Load actual graphics into an atlas
            return(futureAtlas.CreateAtlas());
        }
 private static ButtonSkin CreateDefaultButtonSkin()
 {
     return(ButtonSkin.CreateSimple(
                foregroundPrefix: string.Empty,
                backgroundPrefix: "LaneArrow")
            .CanActivate()
            .CanDisable(foreground: false)
            .CanHover(foreground: false));
 }
示例#5
0
 public void SetSkin(ButtonSkin _skin)
 {
     skin           = _skin;
     mSprite.atlas  = skin.atlas;
     normalSprite   = skin.spNameNormal;
     hoverSprite    = skin.spNameHover;
     pressedSprite  = skin.spNamePressed;
     disabledSprite = skin.spNameDisabled;
 }
示例#6
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);
        }
示例#7
0
        public ColoredButton(string text, Font font, Brush textColor, ButtonSkin skin, float width, float height)
        {
            label = new Label(text, font, textColor);

            Skin = skin.Clone();
            Initialize(width, height);
            AddChild(label);

            Resize();
        }
示例#8
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);
        }
示例#9
0
 public override void SetupButtonSkin(AtlasBuilder futureAtlas)
 {
     // Button backround (from BackgroundPrefix) is provided by MainMenuPanel.Start
     this.Skin = ButtonSkin.CreateSimple(
         foregroundPrefix: "JunctionRestrictions",
         backgroundPrefix: UConst.MAINMENU_ROUND_BUTTON_BG)
                 .CanHover(foreground: false)
                 .CanActivate();
     this.Skin.UpdateAtlasBuilder(
         atlasBuilder: futureAtlas,
         spriteSize: new IntVector2(50));
 }
        public override void Start()
        {
            U.UIUtil.MakeUniqueAndSetName(this.gameObject, "TMPE_MainMenuButton");

            // Place the button.
            OnUpdate(GlobalConfig.Instance);

            confDisposable_ = GlobalConfig.Instance.Subscribe(this);

            // Let the mainmenu atlas know we need this texture and assign it to self.atlas.
            this.Skin = ButtonSkin.CreateSimple(
                backgroundPrefix: "MainMenuButton",
                foregroundPrefix: "MainMenuButton")
                        .CanActivate()
                        .CanHover();
            var atlasBuilder = new U.AtlasBuilder(
                atlasName: "MainTMPEButton_Atlas",
                loadingPath: "MainMenu",
                sizeHint: new IntVector2(256));

            this.Skin.UpdateAtlasBuilder(
                atlasBuilder: atlasBuilder,
                spriteSize: new IntVector2(50));
            this.atlas = atlasBuilder.CreateAtlas();
            UpdateButtonSkinAndTooltip();

            // Set the button dimensions to smallest of 2.6% of screen width or 4.6% of screen height
            // Which approximately equals to 50 pixels in 1080p.
            width = height = GetButtonDimensions();

            // Enable button sounds.
            playAudioEvents = true;

            var dragHandler = new GameObject("TMPE_MainButton_DragHandler");

            dragHandler.transform.parent        = transform;
            dragHandler.transform.localPosition = Vector3.zero;
            Drag = dragHandler.AddComponent <UIDragHandle>();

            Drag.width   = width;
            Drag.height  = height;
            Drag.enabled = !GlobalConfig.Instance.Main.MainMenuButtonPosLocked;

            // Set up the tooltip
            var uiView = GetUIView();

            if (uiView != null)
            {
                m_TooltipBox = uiView.defaultTooltipBox;
            }
        }
示例#11
0
            public static T FromButtonSkin <T>(ButtonSkin buttonSkin) where T : ButtonSkinSave, new()
            {
                T buttonSkinSave = WindowSkinSave.FromWindowSkin <T>(buttonSkin);

                if (buttonSkin.Font != null)
                {
                    buttonSkinSave.BitmapFontSave = BitmapFontSave.FromBitmapFont(buttonSkin.Font);
                }

                buttonSkinSave.TextSpacing = buttonSkin.TextSpacing;
                buttonSkinSave.TextScale   = buttonSkin.TextScale;

                return(buttonSkinSave);
            }
示例#12
0
        /// <summary>
        /// Create the button.
        /// </summary>
        /// <param name="text">Text for the button label.</param>
        /// <param name="skin">Button skin (texture to use).</param>
        /// <param name="anchor">Position anchor.</param>
        /// <param name="size">Button size (if not defined will use default size).</param>
        /// <param name="offset">Offset from anchor position.</param>
        public Button(string text, ButtonSkin skin = ButtonSkin.Default, Anchor anchor = Anchor.Auto, Vector2?size = null, Vector2?offset = null) :
            base(size, anchor, offset)
        {
            // store style
            _skin = skin;

            // update styles
            UpdateStyle(DefaultStyle);

            // create and set button paragraph
            ButtonParagraph = new Paragraph(text, Anchor.Center);
            ButtonParagraph.UpdateStyle(DefaultParagraphStyle);
            AddChild(ButtonParagraph, true);
        }
示例#13
0
        public TexturedButton(Texture button)
        {
            var up = new TexturedRectangle(button);

            var down = new TexturedRectangle(button);
            var shadow = new ColoredRectangle(0, 0, button.Width, button.Height, 0, 0, 0, 0.1F);
            down.AddChild(shadow);

            var hover = new TexturedRectangle(button);
            var light = new ColoredRectangle(0, 0, button.Width, button.Height, 1, 1, 1, 0.1F);
            hover.AddChild(light);

            var skin = new ButtonSkin(up, down, hover);

            Initialize(button.Width, button.Height);
        }
示例#14
0
        /// <summary>
        /// Create the button.
        /// </summary>
        /// <param name="text">Text for the button label.</param>
        /// <param name="skin">Button skin (texture to use).</param>
        /// <param name="anchor">Position anchor.</param>
        /// <param name="size">Button size (if not defined will use default size).</param>
        /// <param name="offset">Offset from anchor position.</param>
        public Button(string text, ButtonSkin skin = ButtonSkin.Default, Anchor anchor = Anchor.Auto, Vector2?size = null, Vector2?offset = null) :
            base(size, anchor, offset)
        {
            // store style
            _skin = skin;

            // update styles
            UpdateStyle(DefaultStyle);

            if (!UserInterface.Active._isDeserializing)
            {
                // create and set button paragraph
                ButtonParagraph = UserInterface.DefaultParagraph(text, Anchor.Center);
                ButtonParagraph._hiddenInternalEntity = true;
                ButtonParagraph.UpdateStyle(DefaultParagraphStyle);
                ButtonParagraph.Identifier = "_button_caption";
                AddChild(ButtonParagraph, true);
            }
        }
        private UITextureAtlas GetAtlas()
        {
            if (laneArrowButtonAtlas_ != null)
            {
                return(laneArrowButtonAtlas_);
            }

            // Create base atlas with backgrounds and no foregrounds
            ButtonSkin backgroundOnlySkin = ButtonSkin.CreateSimple(
                foregroundPrefix: "LaneArrow",
                backgroundPrefix: "LaneArrow")
                                            .CanHover(foreground: false)
                                            .CanActivate(foreground: false)
                                            .NormalForeground(false);
            var futureAtlas = new AtlasBuilder(
                atlasName: "TMPE_LaneArrowsTool_Atlas",
                loadingPath: "LaneArrows",
                sizeHint: new IntVector2(256));

            backgroundOnlySkin.UpdateAtlasBuilder(
                atlasBuilder: futureAtlas,
                spriteSize: new IntVector2(64));

            // Merge names of all foreground sprites for 3 directions into atlasKeySet
            foreach (string prefix in new[]
                     { "LaneArrowLeft", "LaneArrowRight", "LaneArrowForward" })
            {
                ButtonSkin skin = ButtonSkin.CreateSimple(
                    foregroundPrefix: prefix,
                    backgroundPrefix: string.Empty)
                                  .CanActivate(background: false);

                // Create keysets for lane arrow button icons and merge to the shared atlas
                skin.UpdateAtlasBuilder(
                    atlasBuilder: futureAtlas,
                    spriteSize: new IntVector2(64));
            }

            // Load actual graphics into an atlas
            laneArrowButtonAtlas_ = futureAtlas.CreateAtlas();
            return(laneArrowButtonAtlas_);
        }
示例#16
0
            public override void Start()
            {
                base.Start();
                this.Skin = ButtonSkin.CreateSimple(
                    backgroundPrefix: "Clear",
                    foregroundPrefix: "Clear")
                            .CanActivate()
                            .CanHover();

                // This creates an atlas for a single button
                var atlasBuilder = new U.AtlasBuilder(
                    atlasName: "RemoveCitizenButton_Atlas",
                    loadingPath: "Clear",
                    sizeHint: new IntVector2(256));

                this.Skin.UpdateAtlasBuilder(
                    atlasBuilder: atlasBuilder,
                    spriteSize: new IntVector2(50));
                this.atlas = atlasBuilder.CreateAtlas();

                UpdateButtonSkinAndTooltip();
                width = height = 30;
            }
示例#17
0
            public void SetupControls(SpeedLimitsToolWindow window, UBuilder builder)
            {
                this.name = GAMEOBJECT_NAME + "_ModesPanel";

                void ButtonpanelResizeFn(UResizer r)
                {
                    r.Stack(
                        mode: UStackMode.NewRowBelow,
                        spacing: UConst.UIPADDING,
                        stackRef: window.windowTitleLabel_);
                    r.FitToChildren();
                }

                this.ResizeFunction(ButtonpanelResizeFn);

                Vector2        buttonSize  = new Vector2(40f, 40f);
                UITextureAtlas uiAtlas     = window.GetUiAtlas();
                LookupTable    translation = Translation.SpeedLimits;

                //----------------
                // Edit Segments/Lanes mode button
                //----------------
                this.SegmentModeButton = builder.Button <UButton>(
                    parent: this,
                    text: string.Empty,
                    tooltip: translation.Get("Tooltip:Edit segment speed limits"),
                    size: buttonSize,
                    stack: UStackMode.Below);
                this.SegmentModeButton.atlas = uiAtlas;

                // Note the atlas is loaded before this skin is created in window.GetUiAtlas()
                this.SegmentModeButton.Skin =
                    ButtonSkin.CreateSimple(
                        foregroundPrefix: "EditSegments",
                        backgroundPrefix: UConst.MAINMENU_ROUND_BUTTON_BG)
                    .CanActivate(background: false)
                    .CanHover(foreground: false);
                this.SegmentModeButton.ApplyButtonSkin();

                // the onclick handler is set by SpeedLimitsTool outside of this module

                //----------------
                // Edit Lanes mode button
                //----------------
                this.LaneModeButton = builder.Button <UButton>(
                    parent: this,
                    text: string.Empty,
                    tooltip: translation.Get("Tooltip:Edit lane speed limits"),
                    size: buttonSize,
                    stack: UStackMode.ToTheRight);
                this.LaneModeButton.atlas = uiAtlas;
                // Note the atlas is loaded before this skin is created in window.GetUiAtlas()
                this.LaneModeButton.Skin = ButtonSkin
                                           .CreateSimple(
                    foregroundPrefix: "EditLanes",
                    backgroundPrefix: UConst.MAINMENU_ROUND_BUTTON_BG)
                                           .CanActivate(background: false)
                                           .CanHover(foreground: false);
                this.LaneModeButton.ApplyButtonSkin();
                // the onclick handler is set by SpeedLimitsTool outside of this module

                //----------------
                // Edit Defaults mode button
                //----------------
                this.DefaultsModeButton = builder.Button <UButton>(
                    parent: this,
                    text: string.Empty,
                    tooltip: translation.Get("Tooltip:Default speed limits per road type"),
                    size: buttonSize,
                    stack: UStackMode.NewRowBelow);
                this.DefaultsModeButton.atlas = uiAtlas;

                // Note the atlas is loaded before this skin is created in window.GetUiAtlas()
                this.DefaultsModeButton.Skin = ButtonSkin
                                               .CreateSimple(
                    foregroundPrefix: "EditDefaults",
                    backgroundPrefix: UConst.MAINMENU_ROUND_BUTTON_BG)
                                               .CanActivate(background: false)
                                               .CanHover(foreground: false);
                this.DefaultsModeButton.ApplyButtonSkin();

                // the onclick handler is set by SpeedLimitsTool outside of this module

                //----------------
                // MPH/Kmph switch
                //----------------
                bool displayMph = GlobalConfig.Instance.Main.DisplaySpeedLimitsMph;

                this.ToggleMphButton = builder.Button <MphToggleButton>(
                    parent: this,
                    text: string.Empty,
                    tooltip: displayMph
                                 ? translation.Get("Miles per hour")
                                 : translation.Get("Kilometers per hour"),
                    size: buttonSize,
                    stack: UStackMode.ToTheRight);
                this.ToggleMphButton.atlas = uiAtlas;

                // Note the atlas is loaded before this skin is created in window.GetUiAtlas()
                this.ToggleMphButton.Skin = ButtonSkin.CreateSimple(
                    foregroundPrefix: "MphToggle",
                    backgroundPrefix: UConst.MAINMENU_ROUND_BUTTON_BG)
                                            .CanActivate(background: false)
                                            .CanHover(foreground: false);
                this.ToggleMphButton.ApplyButtonSkin();

                // the onclick handler is set by SpeedLimitsTool outside of this module
            }
示例#18
0
 public TexturedButton(ButtonSkin skin, float width, float height)
     : base(skin, width, height)
 {
 }
示例#19
0
        public TexturedButton(Texture up, Texture down, Texture hover)
        {
            var skin = new ButtonSkin(new TexturedRectangle(up), new TexturedRectangle(down), new TexturedRectangle(hover));

            Initialize(up.Width, up.Height);
        }
示例#20
0
 public MenuButton(string text, Action click = null, ButtonSkin skin = ButtonSkin.Default, Anchor anchor = Anchor.Auto, Vector2?size = default(Vector2?), Vector2?offset = default(Vector2?)) : base(text, skin, anchor, size, offset)
 {
     OnClick += (e) => click?.Invoke();
 }
示例#21
0
        public Button(ButtonSkin skin, float width, float height)
        {
            Skin = skin.Clone();

            Initialize(width, height);
        }
示例#22
0
        public Button(DisplayObject up, DisplayObject down, DisplayObject hover, float width, float height)
        {
            Skin = new ButtonSkin(up, down, hover);

            Initialize(width, height);
        }