/// <summary>Creates a draggable label with current unit (mph or km/h).</summary> /// <param name="builder">The UI builder to use.</param> private void SetupControls_TitleBar(UBuilder builder) { string unitTitle = string.Format( format: "{0} - {1}", Translation.SpeedLimits.Get("Window.Title:Speed Limits"), GlobalConfig.Instance.Main.DisplaySpeedLimitsMph ? Translation.SpeedLimits.Get("Miles per hour") : Translation.SpeedLimits.Get("Kilometers per hour")); // The label will be repositioned to the top of the parent this.windowTitleLabel_ = builder.Label_( parent: this, t: unitTitle, stack: UStackMode.Below); this.dragHandle_ = this.CreateDragHandle(); // On window drag - clamp to screen and then save in the config this.eventPositionChanged += (_, value) => { GlobalConfig.Instance.Main.SpeedLimitsWindowX = (int)value.x; GlobalConfig.Instance.Main.SpeedLimitsWindowY = (int)value.y; if (!queuedClampToScreen) { // Prevent multiple invocations by setting a flag queuedClampToScreen = true; Invoke(eventName: "OnPeriodicClampToScreen", 2.0f); } }; }
/// <summary> /// Sets up two stacked labels: for mode description (what the user sees) and for hint. /// The text is empty but is updated after every mode or view change. /// </summary> public void SetupControls(SpeedLimitsToolWindow window, UBuilder builder, SpeedLimitsTool parentTool) { this.position = Vector3.zero; this.backgroundSprite = "GenericPanel"; this.color = new Color32(64, 64, 64, 255); this.SetPadding(UPadding.Default); this.ResizeFunction( resizeFn: (UResizer r) => { r.Stack( UStackMode.ToTheRight, spacing: UConst.UIPADDING, stackRef: window.modeButtonsPanel_); r.FitToChildren(); }); this.ModeDescriptionLabel = builder.Label_( parent: this, t: string.Empty, stack: UStackMode.Below, processMarkup: true); this.ModeDescriptionLabel.SetPadding( new UPadding(top: 12f, right: 0f, bottom: 0f, left: 0f)); }
private void CreatePaletteButtonHintLabel(UBuilder builder, bool showMph, SpeedValue speedValue, SpeedLimitPaletteButton button, UPanel buttonPanel) { // Other speed unit info label string otherUnit = showMph ? ToKmphPreciseString(speedValue) : ToMphPreciseString(speedValue); // Choose label text under the button string GetSpeedButtonHintText() { if (FloatUtil.NearlyEqual(speedValue.GameUnits, 0.0f)) { return(Translation.SpeedLimits.Get("Palette.Text:Default")); } if (speedValue.GameUnits >= SpeedValue.UNLIMITED) { return(Translation.SpeedLimits.Get("Palette.Text:Unlimited")); } return(otherUnit); } ULabel label = button.AltUnitsLabel = builder.Label_( parent: buttonPanel, t: GetSpeedButtonHintText(), stack: UStackMode.Below); label.width = SpeedLimitPaletteButton.SELECTED_WIDTH; label.textAlignment = UIHorizontalAlignment.Center; label.ContributeToBoundingBox(false); // parent ignore our width }
/// <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 }