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 void SetupControls_OnscreenDisplayPanel(UiBuilder <MainMenuWindow> builder) { using (var osdBuilder = builder.ChildPanel <U.UPanel>( p => { p.name = "TMPE_MainMenu_KeybindsPanel"; // the GenericPanel sprite is Light Silver, make it dark p.atlas = TextureUtil.FindAtlas("Ingame"); p.backgroundSprite = "GenericPanel"; p.color = new Color32(64, 64, 64, 240); p.opacity = GlobalConfig.Instance.Main.KeybindsPanelVisible ? 1f : 0f; })) { osdBuilder.SetPadding(UConst.UIPADDING); // The keybinds panel belongs to main menu but does not expand it to fit UResizerConfig.From(osdBuilder.Control).ContributeToBoundingBox = false; this.OnscreenDisplayPanel = osdBuilder.Control; // bool keybindsVisible = GlobalConfig.Instance.Main.KeybindsPanelVisible; // this.OnscreenDisplayPanel.gameObject.SetActive(keybindsVisible); osdBuilder.ResizeFunction( r => { r.Stack(mode: UStackMode.Below, spacing: UConst.UIPADDING * 2); // As the control technically belongs inside the mainmenu, it will respect // the 4px padding, we want to shift it slightly left to line up with the // main menu panel. r.MoveBy(new Vector2(-UConst.UIPADDING, 0f)); r.FitToChildren(); }); } }
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); } }
/// <summary> /// Create button triples for number of lanes. /// Buttons are linked to lanes later by LaneArrowTool class. /// </summary> /// <param name="builder">The UI Builder.</param> /// <param name="numLanes">How many lane groups.</param> public void SetupControls(UiBuilder <LaneArrowToolWindow> builder, int numLanes) { Buttons = new List <LaneArrowButton>(); using (var buttonRowBuilder = builder.ChildPanel <U.Panel.UPanel>( setupFn: p => { p.name = "TMPE_ButtonRow"; })) { buttonRowBuilder.ResizeFunction( r => { r.Stack(mode: UStackMode.Below, spacing: UConst.UIPADDING); r.FitToChildren(); }); // ----------------------------------- // Create a row of button groups // [ Lane 1 ] [ Lane 2 ] [ Lane 3 ] ... // [ [←] [↑] [→] ] [... ] [ ... ] // ----------------------------------- for (var i = 0; i < numLanes; i++) { string buttonName = $"TMPE_LaneArrow_ButtonGroup{i + 1}"; using (var buttonGroupBuilder = buttonRowBuilder.ChildPanel <U.Panel.UPanel>( setupFn: p => { p.name = buttonName; p.atlas = TextureUtil.FindAtlas("Ingame"); p.backgroundSprite = "GenericPanel"; })) { int i1 = i; // copy of the loop variable, for the resizeFunction below buttonGroupBuilder.SetPadding(UConst.UIPADDING); buttonGroupBuilder.ResizeFunction( r => { // attach below "Lane #" label, // else: attach to the right of the previous button group r.Stack( mode: i1 == 0 ? UStackMode.Below : UStackMode.ToTheRight, spacing: UConst.UIPADDING); r.FitToChildren(); }); // Create a label with "Lane #" title string labelText = Translation.LaneRouting.Get("Format.Label:Lane") + " " + (i + 1); using (var laneLabel = buttonGroupBuilder.Label <U.Label.ULabel>(labelText)) { // The label will be repositioned to the top of the parent laneLabel.ResizeFunction(r => { r.Stack(UStackMode.Below); }); } // Create and populate the panel with buttons // 3 buttons are created [←] [↑] [→], // The click event is assigned outside in LaneArrowTool.cs foreach (string prefix in new[] { "LaneArrowLeft", "LaneArrowForward", "LaneArrowRight", }) { using (UiBuilder <LaneArrowButton> buttonBuilder = buttonGroupBuilder.Button <LaneArrowButton>()) { buttonBuilder.Control.atlas = GetAtlas(); buttonBuilder.Control.Skin = CreateDefaultButtonSkin(); buttonBuilder.Control.Skin.Prefix = prefix; Buttons.Add(buttonBuilder.Control); buttonBuilder.ResizeFunction( r => { // First button in the group will be stacking vertical // under the "Lane #" label, while 2nd and 3rd will be // stacking horizontal r.Stack( mode: prefix == "LaneArrowLeft" ? UStackMode.Below : UStackMode.ToTheRight, spacing: UConst.UIPADDING); r.Width(UValue.FixedSize(40f)); r.Height(UValue.FixedSize(40f)); }); } } // for each button } // end button group panel } // end button loop, for each lane } // end button row }
/// <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); }