public override void Build(U.UiBuilder <U.Panel.UPanel> builder) { // Capacity 9 will fit all modifiers and separators and the text StringBuilder text = new StringBuilder(capacity: 9); text.Append($"<color {UConst.SHORTCUT_TEXT_HEX}>"); if (this.shift_) { text.Append(Translation.Options.Get("Shortcut.Modifier:Shift")); text.Append("+"); } if (this.ctrl_) { text.Append(Translation.Options.Get("Shortcut.Modifier:Ctrl")); text.Append("+"); } if (this.alt_) { text.Append(Translation.Options.Get("Shortcut.Modifier:Alt")); text.Append("+"); } text.Append(TranslationForMouseButton(this.button_)); text.Append("</color> "); text.Append(this.localizedText_); using (UiBuilder <ULabel> labelB = builder.Label <U.Label.ULabel>(text.ToString())) { labelB.Control.processMarkup = true; labelB.ResizeFunction( r => { r.Stack(mode: UStackMode.NewRowBelow); }); } }
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 Build(U.UiBuilder <U.UPanel> builder) { StringBuilder text = new StringBuilder(); List <string> keybindStrings = this.keybindSetting_.ToLocalizedStringList(); bool firstShortcut = true; // tracking | separators between multiple keybinds using (UiBuilder <ULabel> labelB = builder.Label <U.ULabel>(string.Empty)) { labelB.Control.processMarkup = true; labelB.ResizeFunction( r => { r.Stack(mode: UStackMode.NewRowBelow); }); foreach (string keybindStr in keybindStrings) { if (!firstShortcut) { text.Append("| "); } else { firstShortcut = false; } text.Append($"<color {UConst.SHORTCUT_TEXT_HEX}>{keybindStr}</color>"); } text.Append(" "); text.Append(this.localizedText_); labelB.Control.text = text.ToString(); } }
public override void Build(U.UiBuilder <U.Panel.UPanel> builder) { using (UiBuilder <ULabel> labelB = builder.Label <U.Label.ULabel>(string.Empty)) { labelB.ResizeFunction(r => { r.Stack(mode: UStackMode.NewRowBelow); }); labelB.Control.text = this.localizedText_; labelB.Control.opacity = 0.8f; } }
/// <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 }