Example #1
0
        private static void AddNewStopTemplate()
        {
            var     go    = new GameObject();
            UIPanel panel = go.AddComponent <UIPanel>();

            panel.size = new Vector2(36, 36);
            UIButton button = UITemplateManager.Get <UIButton>("StopButton");

            panel.AttachUIComponent(button.gameObject).transform.localScale = Vector3.one;
            button.relativePosition   = Vector2.zero;
            button.name               = "StopButton";
            button.scaleFactor        = 1f;
            button.spritePadding.top  = 2;
            button.isTooltipLocalized = true;
            KlyteMonoUtils.InitButtonFg(button, false, "DistrictOptionBrushMedium");
            KlyteMonoUtils.InitButtonSameSprite(button, "");

            UILabel uilabel = button.Find <UILabel>("PassengerCount");

            panel.AttachUIComponent(uilabel.gameObject).transform.localScale = Vector3.one;
            uilabel.relativePosition  = new Vector3(38, 12);
            uilabel.processMarkup     = true;
            uilabel.isVisible         = true;
            uilabel.minimumSize       = new Vector2(175, 50);
            uilabel.verticalAlignment = UIVerticalAlignment.Middle;
            KlyteMonoUtils.LimitWidthAndBox(uilabel, 175, true);


            UIPanel connectionPanel = panel.AddUIComponent <UIPanel>();

            connectionPanel.name                = "ConnectionPanel";
            connectionPanel.relativePosition    = new Vector3(-50, 5);
            connectionPanel.size                = new Vector3(50, 40);
            connectionPanel.autoLayout          = true;
            connectionPanel.wrapLayout          = true;
            connectionPanel.autoLayoutDirection = LayoutDirection.Vertical;
            connectionPanel.autoLayoutStart     = LayoutStart.TopRight;


            UILabel distLabel = panel.AddUIComponent <UILabel>();

            distLabel.name             = "Distance";
            distLabel.relativePosition = new Vector3(-12, 37);
            distLabel.textAlignment    = UIHorizontalAlignment.Center;
            distLabel.textScale        = 0.65f;
            distLabel.suffix           = "m";
            distLabel.useOutline       = true;
            distLabel.minimumSize      = new Vector2(60, 0);
            distLabel.outlineColor     = Color.black;

            KlyteMonoUtils.CreateUIElement(out UITextField lineNameField, panel.transform, "StopNameField", new Vector4(38, -6, 175, 50));
            lineNameField.maxLength            = 256;
            lineNameField.isVisible            = false;
            lineNameField.verticalAlignment    = UIVerticalAlignment.Middle;
            lineNameField.horizontalAlignment  = UIHorizontalAlignment.Left;
            lineNameField.selectionSprite      = "EmptySprite";
            lineNameField.builtinKeyNavigation = true;
            lineNameField.textScale            = uilabel.textScale;
            lineNameField.padding.top          = 18;
            lineNameField.padding.left         = 5;
            lineNameField.padding.bottom       = 14;
            KlyteMonoUtils.InitButtonFull(lineNameField, false, "TextFieldPanel");


            TLMUiTemplateUtils.GetTemplateDict()["StopButtonPanel"] = panel;
        }