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 void SetupControls_ExtraPanel(UiBuilder <UPanel> innerPanelB, U.AtlasBuilder atlasBuilder, AddButtonsResult toolButtonsResult) { // This is toggle despawn and clear traffic panel using (UiBuilder <UPanel> rightPanelB = innerPanelB.ChildPanel <U.UPanel>( setupFn: p => { p.name = "TMPE_MainMenu_ExtraPanel"; // Silver background panel p.atlas = TextureUtil.FindAtlas("Ingame"); p.backgroundSprite = "GenericPanel"; // The panel will be Dark Silver at 50% dark 100% alpha p.color = new Color32(128, 128, 128, 255); })) { rightPanelB.ResizeFunction(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( builder: rightPanelB, atlasBuilder: atlasBuilder, buttonDefs: EXTRA_BUTTON_DEFS, minRowLength: toolButtonsResult.Layout.Rows == 2 ? 1 : 2); ExtraButtonsList = extraButtonsResult.Buttons; } }
private AddButtonsResult SetupControls_ToolPanel(UiBuilder <UPanel> innerPanelB, U.AtlasBuilder atlasBuilder) { // This is tool buttons panel using (UiBuilder <UPanel> leftPanelB = innerPanelB.ChildPanel <U.UPanel>( setupFn: panel => { panel.name = "TMPE_MainMenu_ToolPanel"; })) { leftPanelB.ResizeFunction(r => { r.Stack(mode: UStackMode.Below); r.FitToChildren(); }); // Create 1 or 2 rows of button objects var toolButtonsResult = AddButtonsFromButtonDefinitions( builder: leftPanelB, atlasBuilder: atlasBuilder, buttonDefs: TOOL_BUTTON_DEFS, minRowLength: 4); ToolButtonsList = toolButtonsResult.Buttons; return(toolButtonsResult); } }
public override void Start() { base.Start(); this.Skin = new ButtonSkin { BackgroundPrefix = "Clear", Prefix = "Clear", BackgroundHovered = true, BackgroundActive = true, ForegroundHovered = true, ForegroundActive = true, }; // This creates an atlas for a single button var atlasBuilder = new U.AtlasBuilder(); this.Skin.UpdateAtlasBuilder( atlasBuilder: atlasBuilder, spriteSize: new IntVector2(50)); this.atlas = atlasBuilder.CreateAtlas( atlasName: "RemoveCitizenButton_Atlas", loadingPath: "Clear", atlasSizeHint: new IntVector2(256)); UpdateButtonImageAndTooltip(); width = height = 30; }
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); }
/// <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); }
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 = new ButtonSkin { BackgroundPrefix = "MainMenuButton", Prefix = "MainMenuButton", BackgroundHovered = true, BackgroundActive = true, ForegroundHovered = true, ForegroundActive = true, }; var atlasBuilder = new U.AtlasBuilder(); this.Skin.UpdateAtlasBuilder( atlasBuilder: atlasBuilder, spriteSize: new IntVector2(50)); this.atlas = atlasBuilder.CreateAtlas( atlasName: "MainTMPEButton_Atlas", loadingPath: "MainMenu", atlasSizeHint: new IntVector2(256)); UpdateButtonImageAndTooltip(); // 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; } }
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; }
/// <summary>Called from ModUI to setup children for the window.</summary> /// <param name="builder">The UI Builder.</param> public void SetupControls(UiBuilder <MainMenuWindow> builder) { // Create and populate list of background atlas keys, used by all buttons // And also each button will have a chance to add their own atlas keys for loading. var tmpSkin = new U.ButtonSkin { Prefix = "MainMenuPanel", BackgroundPrefix = "RoundButton", ForegroundNormal = false, BackgroundHovered = true, BackgroundActive = true, }; // By default the atlas will include backgrounds: DefaultRound-bg-normal var atlasBuilder = new U.AtlasBuilder(); tmpSkin.UpdateAtlasBuilder( atlasBuilder: atlasBuilder, spriteSize: new IntVector2(50)); // Create Version Label and Help button: // [ TM:PE 11.x ] [?] UILabel versionLabel = SetupControls_TopRow(builder, atlasBuilder); // Main menu contains 2 panels side by side, one for tool buttons and another for // despawn & clear buttons. ButtonsDict = new Dictionary <ToolMode, BaseMenuButton>(); // U.UPanel leftPanel; using (var innerPanelB = builder.ChildPanel <U.UPanel>(setupFn: p => { p.name = "TMPE_MainMenu_InnerPanel"; })) { innerPanelB.ResizeFunction(r => { r.Stack(mode: UStackMode.Below, spacing: 0f, stackRef: versionLabel); r.FitToChildren(); }); AddButtonsResult toolButtonsResult = SetupControls_ToolPanel(innerPanelB, atlasBuilder); SetupControls_ExtraPanel(innerPanelB, atlasBuilder, toolButtonsResult); } // Create atlas and give it to all buttons allButtonsAtlas_ = atlasBuilder.CreateAtlas( atlasName: "MainMenu_Atlas", loadingPath: "MainMenu.Tool", atlasSizeHint: new IntVector2(512)); foreach (BaseMenuButton b in ToolButtonsList) { b.atlas = allButtonsAtlas_; } foreach (BaseMenuButton b in ExtraButtonsList) { b.atlas = allButtonsAtlas_; } this.toggleOsdButton_.atlas = allButtonsAtlas_; //------------------------------------------------------------------------- // Foldable panel with keybinds, starts hidden below or above the main menu //------------------------------------------------------------------------- SetupControls_OnscreenDisplayPanel(builder); // Floating labels under TM:PE window SetupControls_DebugLabels(builder, this.OnscreenDisplayPanel); }
/// <summary> /// When creating the main panel, texture atlas is created for all buttons. Here /// each button is given a chance to add their own required sprites to that atlas. /// </summary> /// <param name="atlasKeys">List to modify.</param> public abstract void SetupButtonSkin(U.AtlasBuilder atlasBuilder);