/// <summary> /// Given the tool window already created with its buttons set up, /// go through them and assign click events, disable some, activate some etc. /// </summary> private void SetupLaneArrowsWindowButtons(IList <LanePos> laneList, bool startNode) { // For all lanes, go through our buttons and update their onClick, etc. for (var i = 0; i < laneList.Count; i++) { uint laneId = laneList[i].laneId; LaneArrowButton buttonLeft = ToolWindow.Buttons[i * 3]; buttonLeft.LaneId = laneId; buttonLeft.NetlaneFlagsMask = NetLane.Flags.Left; buttonLeft.StartNode = startNode; buttonLeft.ToggleFlag = API.Traffic.Enums.LaneArrows.Left; buttonLeft.UpdateButtonImageAndTooltip(); buttonLeft.ParentTool = this; // to access error reporting function on click LaneArrowButton buttonForward = ToolWindow.Buttons[(i * 3) + 1]; buttonForward.LaneId = laneId; buttonForward.NetlaneFlagsMask = NetLane.Flags.Forward; buttonForward.StartNode = startNode; buttonForward.ToggleFlag = API.Traffic.Enums.LaneArrows.Forward; buttonForward.UpdateButtonImageAndTooltip(); buttonForward.ParentTool = this; // to access error reporting function on click LaneArrowButton buttonRight = ToolWindow.Buttons[(i * 3) + 2]; buttonRight.LaneId = laneId; buttonRight.NetlaneFlagsMask = NetLane.Flags.Right; buttonRight.StartNode = startNode; buttonRight.ToggleFlag = API.Traffic.Enums.LaneArrows.Right; buttonRight.UpdateButtonImageAndTooltip(); buttonRight.ParentTool = this; // to access error reporting function on click } }
/// <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(UBuilder builder, int numLanes) { Buttons = new List <LaneArrowButton>(); var buttonRowPanel = builder.Panel_(parent: this, stack: UStackMode.NewRowBelow); buttonRowPanel.name = "TMPE_ButtonRow"; buttonRowPanel.SetPadding(UPadding.Default); buttonRowPanel.ResizeFunction((UResizer r) => { 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}"; UPanel buttonGroupPanel = builder.Panel_( parent: buttonRowPanel, stack: i == 0 ? UStackMode.Below : UStackMode.ToTheRight); buttonGroupPanel.name = buttonName; buttonGroupPanel.atlas = TextureUtil.Ingame; buttonGroupPanel.backgroundSprite = "GenericPanel"; int i1 = i; // copy of the loop variable, for the resizeFunction below buttonGroupPanel.ResizeFunction((UResizer r) => { r.FitToChildren(); }); buttonGroupPanel.SetPadding(UPadding.Default); // Create a label with "Lane #" title string labelText = Translation.LaneRouting.Get("Format.Label:Lane") + " " + (i + 1); ULabel laneLabel = builder.Label_( parent: buttonGroupPanel, t: 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", }) { LaneArrowButton arrowButton = builder.Button <LaneArrowButton>( parent: buttonGroupPanel, text: string.Empty, tooltip: null, size: new Vector2(40f, 40f), stack: prefix == "LaneArrowLeft" ? UStackMode.Below : UStackMode.ToTheRight); arrowButton.atlas = GetAtlas(); arrowButton.Skin = CreateDefaultButtonSkin(); arrowButton.Skin.ForegroundPrefix = prefix; Buttons.Add(arrowButton); } // for each button } // end button loop, for each lane }