/// <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; } } }
public void SetupControls(SpeedLimitsToolWindow window, UBuilder builder) { this.name = GAMEOBJECT_NAME + "_ModesPanel"; void ButtonpanelResizeFn(UResizer r) { r.Stack( mode: UStackMode.NewRowBelow, spacing: UConst.UIPADDING, stackRef: window.windowTitleLabel_); r.FitToChildren(); } this.ResizeFunction(ButtonpanelResizeFn); Vector2 buttonSize = new Vector2(40f, 40f); UITextureAtlas uiAtlas = window.GetUiAtlas(); LookupTable translation = Translation.SpeedLimits; //---------------- // Edit Segments/Lanes mode button //---------------- this.SegmentModeButton = builder.Button <UButton>( parent: this, text: string.Empty, tooltip: translation.Get("Tooltip:Edit segment speed limits"), size: buttonSize, stack: UStackMode.Below); this.SegmentModeButton.atlas = uiAtlas; // Note the atlas is loaded before this skin is created in window.GetUiAtlas() this.SegmentModeButton.Skin = ButtonSkin.CreateSimple( foregroundPrefix: "EditSegments", backgroundPrefix: UConst.MAINMENU_ROUND_BUTTON_BG) .CanActivate(background: false) .CanHover(foreground: false); this.SegmentModeButton.ApplyButtonSkin(); // the onclick handler is set by SpeedLimitsTool outside of this module //---------------- // Edit Lanes mode button //---------------- this.LaneModeButton = builder.Button <UButton>( parent: this, text: string.Empty, tooltip: translation.Get("Tooltip:Edit lane speed limits"), size: buttonSize, stack: UStackMode.ToTheRight); this.LaneModeButton.atlas = uiAtlas; // Note the atlas is loaded before this skin is created in window.GetUiAtlas() this.LaneModeButton.Skin = ButtonSkin .CreateSimple( foregroundPrefix: "EditLanes", backgroundPrefix: UConst.MAINMENU_ROUND_BUTTON_BG) .CanActivate(background: false) .CanHover(foreground: false); this.LaneModeButton.ApplyButtonSkin(); // the onclick handler is set by SpeedLimitsTool outside of this module //---------------- // Edit Defaults mode button //---------------- this.DefaultsModeButton = builder.Button <UButton>( parent: this, text: string.Empty, tooltip: translation.Get("Tooltip:Default speed limits per road type"), size: buttonSize, stack: UStackMode.NewRowBelow); this.DefaultsModeButton.atlas = uiAtlas; // Note the atlas is loaded before this skin is created in window.GetUiAtlas() this.DefaultsModeButton.Skin = ButtonSkin .CreateSimple( foregroundPrefix: "EditDefaults", backgroundPrefix: UConst.MAINMENU_ROUND_BUTTON_BG) .CanActivate(background: false) .CanHover(foreground: false); this.DefaultsModeButton.ApplyButtonSkin(); // the onclick handler is set by SpeedLimitsTool outside of this module //---------------- // MPH/Kmph switch //---------------- bool displayMph = GlobalConfig.Instance.Main.DisplaySpeedLimitsMph; this.ToggleMphButton = builder.Button <MphToggleButton>( parent: this, text: string.Empty, tooltip: displayMph ? translation.Get("Miles per hour") : translation.Get("Kilometers per hour"), size: buttonSize, stack: UStackMode.ToTheRight); this.ToggleMphButton.atlas = uiAtlas; // Note the atlas is loaded before this skin is created in window.GetUiAtlas() this.ToggleMphButton.Skin = ButtonSkin.CreateSimple( foregroundPrefix: "MphToggle", backgroundPrefix: UConst.MAINMENU_ROUND_BUTTON_BG) .CanActivate(background: false) .CanHover(foreground: false); this.ToggleMphButton.ApplyButtonSkin(); // the onclick handler is set by SpeedLimitsTool outside of this module }