示例#1
0
            /// <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;
                    }
                }
            }
示例#2
0
            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);
            }
示例#3
0
            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
            }