Esempio n. 1
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);
            }
        /// <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
        }