/// <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)); }
/// <summary>Create speeds palette based on the current options choices.</summary> /// <param name="window">Containing <see cref="SpeedLimitsToolWindow"/>.</param> /// <param name="builder">The UI builder to use.</param> /// <param name="parentTool">The tool object.</param> public void SetupControls(SpeedLimitsToolWindow window, UBuilder builder, SpeedLimitsTool parentTool) { this.parentTool_ = parentTool; this.name = GAMEOBJECT_NAME + "_PalettePanel"; this.position = Vector3.zero; this.SetPadding(UPadding.Default); this.ResizeFunction( resizeFn: r => { r.Stack( mode: UStackMode.Below, stackRef: window.modeDescriptionWrapPanel_); r.FitToChildren(); }); bool showMph = GlobalConfig.Instance.Main.DisplaySpeedLimitsMph; // Fill with buttons // [ 10 20 30 ... 120 130 140 0(no limit) ] //----------------------------------------- // the Current Selected Speed is highlighted List <SetSpeedLimitAction> actions = new(); actions.Add(SetSpeedLimitAction.ResetToDefault()); // add: Default actions.AddRange(PaletteGenerator.AllSpeedLimits(SpeedUnit.CurrentlyConfigured)); actions.Add(SetSpeedLimitAction.Unlimited()); // add: Unlimited this.buttonsByNumber_ = new(); this.PaletteButtons.Clear(); foreach (SetSpeedLimitAction action in actions) { SpeedLimitPaletteButton nextButton = this.SetupControls_SpeedPalette_Button( builder: builder, parent: this, parentTool: parentTool, showMph: showMph, actionOnClick: action); this.PaletteButtons.Add(nextButton); // If this is a numbered button, and its a multiple of 10... if (action.Type == SetSpeedLimitAction.ActionType.SetOverride) { int number = (int)(showMph ? action.GuardedValue.Override.GetMph() : action.GuardedValue.Override.GetKmph()); this.buttonsByNumber_.Add(number, nextButton); } else if (action.Type == SetSpeedLimitAction.ActionType.Unlimited) { this.unlimitedButton_ = nextButton; } else if (action.Type == SetSpeedLimitAction.ActionType.ResetToDefault) { this.resetToDefaultButton_ = nextButton; } } }
/// <summary> /// Creates a button with speed value on it, and label under it, showing opposite units. /// Also can be zero (reset to default) and 1000 km/h (unlimited speed button). /// </summary> /// <param name="builder">UI builder.</param> /// <param name="actionOnClick">What happens if clicked.</param> /// <param name="parentTool">Parent speedlimits tool.</param> /// <param name="buttonPanel">Panel where buttons are added to.</param> /// <param name="speedInteger">Integer value of the speed in the selected units.</param> /// <param name="speedValue">Speed value of the button we're creating.</param> /// <returns>The new button.</returns> private SpeedLimitPaletteButton CreatePaletteButton(UBuilder builder, SetSpeedLimitAction actionOnClick, SpeedLimitsTool parentTool, UPanel buttonPanel, int speedInteger, SpeedValue speedValue) { // Helper function to choose text for the button string GetSpeedButtonText() { if (speedInteger == 0) { return("✖"); // Unicode symbol U+2716 Heavy Multiplication X } if (speedValue.GameUnits >= SpeedValue.UNLIMITED) { return("⊘"); // Unicode symbol U+2298 Circled Division Slash } return(speedInteger.ToString()); } var button = builder.Button <SpeedLimitPaletteButton>(parent: buttonPanel); button.text = GetSpeedButtonText(); button.textScale = UIScaler.UIScale; button.textHorizontalAlignment = UIHorizontalAlignment.Center; button.normalBgSprite = button.hoveredBgSprite = "GenericPanel"; button.color = new Color32(128, 128, 128, 240); // button must know what to do with its speed value button.AssignedAction = actionOnClick; // The click events will be routed via the parent tool OnPaletteButtonClicked button.ParentTool = parentTool; button.SetStacking(UStackMode.NewRowBelow); // Width will be overwritten in SpeedLimitPaletteButton.UpdateSpeedLimitButton button.SetFixedSize( new Vector2( SpeedLimitPaletteButton.DEFAULT_WIDTH, SpeedLimitPaletteButton.DEFAULT_HEIGHT)); return(button); }
/// <summary>Populate the window using UIBuilder of the window panel.</summary> /// <param name="builder">The root builder of this window.</param> public void SetupControls(UBuilder builder, SpeedLimitsTool parentTool) { this.parentTool_ = parentTool; // "Speed Limits - Kilometers per Hour" // "Showing speed limit overrides per road segment." // [ Lane/Segment ] [ 10 20 30 40 50 ... 120 130 140 Max Reset] // [ Edit Default ] | | | | | | | | | | | | // [_MPH/KM_______] [___+__+__+__+__+...+___+___+___+___+_____] // Goes first on top of the window SetupControls_TitleBar(builder); // Vertical panel goes under the titlebar SetupControls_ModeButtons(builder); // Text below for "Current mode: " and "Hold Alt, hold Shift, etc..." modeDescriptionWrapPanel_ = builder.Panel <ModeDescriptionPanel>( parent: this, stack: UStackMode.None); modeDescriptionWrapPanel_.SetupControls(window: this, builder, parentTool); // Palette: Goes right of the modebuttons panel palettePanel_ = builder.Panel <PalettePanel>( parent: this, stack: UStackMode.None); palettePanel_.SetupControls(window: this, builder, parentTool); // palette was built for the current configured MPH/KM display this.DisplaySpeedLimitsMph = GlobalConfig.Instance.Main.DisplaySpeedLimitsMph; cursorTooltip_ = builder.Label <UFloatingTooltip>( parent: this, t: string.Empty, stack: UStackMode.None); // this will hide it, and update it after setup is done cursorTooltip_.SetTooltip(t: null, show: false); this.gameObject.AddComponent <CustomKeyHandler>(); // Force buttons resize and show the current speed limit on the palette this.UpdatePaletteButtonsOnClick(); this.FocusWindow(); }
SetupControls_SpeedPalette_Button(UBuilder builder, UIComponent parent, bool showMph, SetSpeedLimitAction actionOnClick, SpeedLimitsTool parentTool) { SpeedValue speedValue = actionOnClick.Type == SetSpeedLimitAction.ActionType.ResetToDefault ? default : actionOnClick.GuardedValue.Override; int speedInteger = showMph ? speedValue.ToMphRounded(RoadSignThemes.MPH_STEP).Mph : speedValue.ToKmphRounded(RoadSignThemes.KMPH_STEP).Kmph; //-------------------------------- // Create vertical combo: // |[ 100 ]| // | "65 mph" | //-------------------------------- // Create a small panel which stacks together with other button panels horizontally var buttonPanel = builder.Panel_(parent: parent); buttonPanel.name = $"{GAMEOBJECT_NAME}_Button_{speedInteger}"; buttonPanel.ResizeFunction( resizeFn: (UResizer r) => { r.Stack(UStackMode.ToTheRight, spacing: 2f); r.FitToChildren(); }); SpeedLimitPaletteButton button = this.CreatePaletteButton( builder, actionOnClick, parentTool, buttonPanel, speedInteger, speedValue); this.CreatePaletteButtonHintLabel(builder, showMph, speedValue, button, buttonPanel); return(button); }