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)); }
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; } }
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_); }
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; }
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 }