private void CreateAssetLineTemplate()
        {
            var     go    = new GameObject();
            UIPanel panel = go.AddComponent <UIPanel>();

            panel.size                = new Vector2(m_scrollablePanel.width - 40f, 36);
            panel.autoLayout          = true;
            panel.wrapLayout          = false;
            panel.autoLayoutDirection = LayoutDirection.Horizontal;

            UICheckBox uiCheckbox = UIHelperExtension.AddCheckbox(panel, "AAAAAA", false);

            uiCheckbox.name   = "AssetCheckbox";
            uiCheckbox.height = 29f;
            uiCheckbox.width  = 290f;
            uiCheckbox.label.processMarkup = true;
            uiCheckbox.label.textScale     = 0.8f;

            KlyteMonoUtils.CreateUIElement(out UITextField capEditField, panel.transform, "Cap", new Vector4(0, 0, 50, 30));
            KlyteMonoUtils.UiTextFieldDefaults(capEditField);
            KlyteMonoUtils.InitButtonFull(capEditField, false, "OptionsDropboxListbox");
            capEditField.isTooltipLocalized = true;
            capEditField.tooltipLocaleID    = "K45_TLM_ASSET_CAPACITY_FIELD_DESCRIPTION";
            capEditField.numericalOnly      = true;
            capEditField.maxLength          = 6;
            capEditField.padding            = new RectOffset(2, 2, 4, 2);

            TLMUiTemplateUtils.GetTemplateDict()["K45_TLM_AssetSelectionTabLineTemplate"] = panel;
        }
Example #2
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);
            button.relativePosition = Vector2.zero;
            button.name             = "StopButton";

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

            panel.AttachUIComponent(uilabel.gameObject);
            uilabel.relativePosition  = new Vector3(32, 12);
            uilabel.processMarkup     = true;
            uilabel.isVisible         = true;
            uilabel.minimumSize       = new Vector2(180, 50);
            uilabel.verticalAlignment = UIVerticalAlignment.Middle;

            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(uilabel.relativePosition.x, uilabel.relativePosition.y, 180, 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          = 14;
            lineNameField.padding.bottom       = 24;
            KlyteMonoUtils.InitButtonFull(lineNameField, false, "TextFieldPanel");


            TLMUiTemplateUtils.GetTemplateDict()["StopButtonPanel"] = panel;
        }
Example #3
0
 private static void CreateTopButton(UIPanel _mainPanel, string name, string tooltipLocale, string sprite, Vector2 position, MouseEventHandler onClicked)
 {
     KlyteMonoUtils.CreateUIElement(out UIButton button, _mainPanel.transform, name, new Vector4(10, 50, 40, 40));
     KlyteMonoUtils.InitButtonFull(button, false, "OptionBase");
     button.focusedBgSprite  = "";
     button.normalFgSprite   = sprite;
     button.relativePosition = position;
     button.tooltipLocaleID  = tooltipLocale;
     button.eventClicked    += onClicked;
     button.scaleFactor      = .6f;
 }
Example #4
0
        protected override void AwakeActions()
        {
            CreateTopButton(MainPanel, "ExportAsDefault", "K45_ER_EXPORT_DEFAULT_BTN", CommonsSpriteNames.K45_Save.ToString(), new Vector2(10, 50), (x, y) => ClassesData.Instance.SaveAsDefault());
            CreateTopButton(MainPanel, "ImportDefault", "K45_ER_IMPORT_DEFAULT_BTN", CommonsSpriteNames.K45_Load.ToString(), new Vector2(95, 50), (x, y) => ClassesData.Instance.LoadDefaults());
            CreateTopButton(MainPanel, "SelectAll", "K45_ER_SELECT_ALL_BTN", "check-checked", new Vector2(180, 50), (x, y) => ClassesData.Instance.SelectAll());
            CreateTopButton(MainPanel, "SelectNone", "K45_ER_SELECT_NONE_BTN", "check-unchecked", new Vector2(265, 50), (x, y) => ClassesData.Instance.UnselectAll());
            CreateTopButton(MainPanel, "Reset", "K45_ER_RESET_BTN", CommonsSpriteNames.K45_Reload.ToString(), new Vector2(350, 50), (x, y) => ClassesData.Instance.SafeCleanAll(m_allClasses.Keys));

            KlyteMonoUtils.CreateScrollPanel(MainPanel, out UIScrollablePanel scrollPanel, out _, MainPanel.width - 25, MainPanel.height - 105, new Vector3(5, 100));
            scrollPanel.autoLayout          = true;
            scrollPanel.autoLayoutDirection = LayoutDirection.Vertical;
            scrollPanel.autoLayoutPadding   = new RectOffset(0, 0, 5, 5);
            scrollPanel.backgroundSprite    = "ScrollbarTrack";
            scrollPanel.scrollPadding       = new RectOffset(5, 5, 5, 5);

            m_allClasses = ((FastList <PrefabCollection <NetInfo> .PrefabData>) typeof(PrefabCollection <NetInfo>).GetField("m_scenePrefabs", RedirectorUtils.allFlags).GetValue(null))
                           .m_buffer
                           .Select(x => x.m_prefab)
                           .Where(x => x?.m_class != null && (x.m_class.m_layer == ItemClass.Layer.Default || x.m_class.m_layer == ItemClass.Layer.MetroTunnels || x.m_class.m_layer == ItemClass.Layer.WaterPipes || x.m_class.m_layer == ItemClass.Layer.WaterStructures))
                           .GroupBy(x => x.m_class.name)
                           .ToDictionary(x => x.First().m_class, x => x.ToList());

            foreach (KeyValuePair <ItemClass, List <NetInfo> > clazz in m_allClasses)
            {
                List <NetInfo> itemList  = clazz.Value;
                ItemClass      clazzKey  = clazz.Key;
                string         className = clazzKey.name;

                KlyteMonoUtils.CreateUIElement(out UIPanel row, scrollPanel.transform, $"{clazz.Key.name}", new Vector4(0, 0, scrollPanel.width, 20));
                row.autoLayout     = true;
                row.padding        = new RectOffset(5, 5, 0, 0);
                row.stringUserData = className;

                UICheckBox uiCheckbox = UIHelperExtension.AddCheckbox(row, $"{clazz.Key.name}", ClassesData.Instance.GetConductibility(clazzKey));
                uiCheckbox.name   = "ClassCheckbox";
                uiCheckbox.height = 20f;
                uiCheckbox.width  = 335f;
                uiCheckbox.label.processMarkup = true;
                uiCheckbox.label.textScale     = 0.8f;
                uiCheckbox.objectUserData      = clazzKey;
                uiCheckbox.eventCheckChanged  += SetItemClassValue;
                KlyteMonoUtils.LimitWidthAndBox(uiCheckbox.label, 325);
                ClassesData.Instance.eventOnValueChanged += (x, y) =>
                {
                    if (x == className && y is bool b)
                    {
                        SetNewValue(uiCheckbox, b);
                    }
                };
                ClassesData.Instance.eventAllChanged += () => SetNewValue(uiCheckbox, ClassesData.Instance.GetConductibility(clazzKey));

                KlyteMonoUtils.CreateUIElement(out UIButton help, row.transform, "?", new Vector4(0, 0, 20, 20));
                help.text             = "?";
                help.hoveredTextColor = Color.blue;
                KlyteMonoUtils.InitButtonFull(help, false, "OptionBase");

                help.eventClicked += (x, y) =>
                {
                    K45DialogControl.ShowModal(new K45DialogControl.BindProperties()
                    {
                        icon         = ElectricRoadsMod.Instance.IconName,
                        messageAlign = UIHorizontalAlignment.Left,
                        showButton1  = true,
                        showButton2  = true,
                        showButton3  = true,
                        showClose    = true,
                        textButton1  = Locale.Get("K45_ER_ACTIVATE_CLASS_BTN"),
                        textButton2  = Locale.Get("K45_ER_DEACTIVATE_CLASS_BTN"),
                        textButton3  = Locale.Get("K45_ER_RETURN_BTN"),
                        title        = string.Format(Locale.Get("K45_ER_TITLE_NET_LIST_WINDOW"), className),
                        message      = string.Format(Locale.Get(itemList.Count <= 20 ? "K45_ER_PATTERN_NET_LIST_FEW" : "K45_ER_PATTERN_NET_LIST_FULL"), string.Join("\n", itemList.Take(20).Select(x => $"\t- {x.GetLocalizedTitle()}").ToArray()), itemList.Count - 20)
                    }, (x) =>
                    {
                        if (x == 1)
                        {
                            uiCheckbox.isChecked = true;
                        }
                        else if (x == 2)
                        {
                            uiCheckbox.isChecked = false;
                        }
                        return(true);
                    });
                };
            }
            Quicksort(scrollPanel.components, new Comparison <UIComponent>(CompareNames), false);
        }