Exemple #1
0
        public override void Start()
        {
            name      = "PRT_MainWindow";
            isVisible = false;
            size      = new Vector2(500, 240);
            autoFitChildrenVertically = true;
            absolutePosition          = new Vector3(SavedWindowX.value, SavedWindowY.value);

            var bg = AddUIComponent <UIPanel>();

            bg.atlas                     = ResourceLoader.GetAtlas("Ingame");
            bg.backgroundSprite          = "SubcategoriesPanel";
            bg.size                      = size;
            bg.padding                   = new RectOffset(8, 8, 8, 8);
            bg.autoLayoutPadding         = new RectOffset(0, 0, 0, 4);
            bg.autoLayout                = true;
            bg.autoLayoutDirection       = LayoutDirection.Vertical;
            bg.autoFitChildrenVertically = true;

            var label = bg.AddUIComponent <UILabel>();

            label.name      = "PRT_TitleLabel";
            label.textScale = 0.9f;
            label.text      = "Parallel Road Tool";
            label.autoSize  = false;
            label.width     = 500;
            label.SendToBack();

            var dragHandle = label.AddUIComponent <UIDragHandle>();

            dragHandle.target           = this;
            dragHandle.relativePosition = Vector3.zero;
            dragHandle.size             = label.size;

            _mainPanel = bg.AddUIComponent(typeof(UIOptionsPanel)) as UIOptionsPanel;
            _netList   = bg.AddUIComponent(typeof(UINetList)) as UINetList;
            if (_netList != null)
            {
                _netList.List = ParallelRoadTool.SelectedRoadTypes;
                _netList.OnChangedCallback = NetListOnChangedCallback;
            }

            var space = bg.AddUIComponent <UIPanel>();

            space.size = new Vector2(1, 1);

            // Add main tool button to road options panel
            if (_toolToggleButton != null)
            {
                return;
            }

            var tsBar = UIUtil.FindComponent <UIComponent>("TSBar", null, UIUtil.FindOptions.NameContains);

            if (tsBar == null || !tsBar.gameObject.activeInHierarchy)
            {
                return;
            }
            var button = UIUtil.FindComponent <UICheckBox>("PRT_Parallel");

            if (button != null)
            {
                Destroy(button);
            }
            _toolToggleButton = UIUtil.CreateCheckBox(tsBar, "Parallel", "Parallel Road Tool", false);
            _toolToggleButton.relativePosition = new Vector3(424, -6);

            SubscribeToUIEvents();

            OnPositionChanged();
            DebugUtils.Log($"UIMainWindow created {size} | {position}");
        }
        public override void Start()
        {
            name      = "PRT_MainWindow";
            isVisible = false;
            size      = new Vector2(500, 240);
            autoFitChildrenVertically = true;
            absolutePosition          = new Vector3(SavedWindowX.value, SavedWindowY.value);

            var bg = AddUIComponent <UIPanel>();

            bg.atlas                     = ResourceLoader.GetAtlas("Ingame");
            bg.backgroundSprite          = "SubcategoriesPanel";
            bg.size                      = size;
            bg.padding                   = new RectOffset(8, 8, 8, 8);
            bg.autoLayoutPadding         = new RectOffset(0, 0, 0, 4);
            bg.autoLayout                = true;
            bg.autoLayoutDirection       = LayoutDirection.Vertical;
            bg.autoFitChildrenVertically = true;

            var label = bg.AddUIComponent <UILabel>();

            label.name      = "PRT_TitleLabel";
            label.textScale = 0.9f;
            label.text      = "Parallel Road Tool";
            label.autoSize  = false;
            label.width     = 500;
            label.SendToBack();

            var dragHandle = label.AddUIComponent <UIDragHandle>();

            dragHandle.target           = this;
            dragHandle.relativePosition = Vector3.zero;
            dragHandle.size             = label.size;

            _mainPanel = bg.AddUIComponent(typeof(UIOptionsPanel)) as UIOptionsPanel;
            _netList   = bg.AddUIComponent(typeof(UINetList)) as UINetList;
            if (_netList != null)
            {
                _netList.List = ParallelRoadTool.SelectedRoadTypes;
                _netList.OnChangedCallback = NetListOnChangedCallback;
            }

            var space = bg.AddUIComponent <UIPanel>();

            space.size = new Vector2(1, 1);

            // Add options
            _snappingToggleButton = UIUtil.CreateCheckBox(_mainPanel, "Snapping", Locale.Get("PRT_TOOLTIPS", "SnappingToggleButton"), false);
            _snappingToggleButton.relativePosition = new Vector3(166, 38);
            _snappingToggleButton.BringToFront();

            _tutorialToggleButton = UIUtil.CreateCheckBox(_mainPanel, "ToolbarIconHelp", Locale.Get("PRT_TOOLTIPS", "TutorialToggleButton"), false, true);
            _tutorialToggleButton.relativePosition = new Vector3(166, 38);
            _tutorialToggleButton.BringToFront();
            _tutorialToggleButton.isVisible = ParallelRoadTool.IsInGameMode;

            // Add main tool button to road options panel
            if (_toolToggleButton != null)
            {
                return;
            }

            var tsBar = UIUtil.FindComponent <UIComponent>("TSBar", null, UIUtil.FindOptions.NameContains);

            if (tsBar == null || !tsBar.gameObject.activeInHierarchy)
            {
                return;
            }

            var toolModeBar = UIUtil.FindComponent <UITabstrip>("ToolMode", tsBar, UIUtil.FindOptions.NameContains);

            if (toolModeBar == null)
            {
                return;
            }

            var button = UIUtil.FindComponent <UICheckBox>("PRT_Parallel");

            if (button != null)
            {
                Destroy(button);
            }

            _toolToggleButton = UIUtil.CreateCheckBox(tsBar, "Parallel", Locale.Get("PRT_TOOLTIPS", "ToolToggleButton"), false);
            if (SavedToggleX.value != -1000 && SavedToggleY.value != -1000)
            {
                _toolToggleButton.absolutePosition = new Vector3(SavedToggleX.value, SavedToggleY.value);
            }
            else
            {
                _toolToggleButton.absolutePosition = new Vector3(toolModeBar.absolutePosition.x + toolModeBar.size.x + 1, toolModeBar.absolutePosition.y);
            }

            // HACK - [ISSUE-26] Tool's main button must be draggable to prevent overlapping other mods buttons.
            _buttonDragHandle                  = _toolToggleButton.AddUIComponent <UIRightDragHandle>();
            _buttonDragHandle.size             = _toolToggleButton.size;
            _buttonDragHandle.relativePosition = Vector3.zero;
            _buttonDragHandle.target           = _toolToggleButton;

            SubscribeToUIEvents();

            OnPositionChanged();
            DebugUtils.Log($"UIMainWindow created {size} | {position}");
        }
        public override void Start()
        {
            name      = $"{Configuration.ResourcePrefix}MainWindow";
            isVisible = false;
            size      = new Vector2(500, 240);
            autoFitChildrenVertically = true;
            absolutePosition          = new Vector3(SavedWindowX.value, SavedWindowY.value);

            var bg = AddUIComponent <UIPanel>();

            bg.atlas                     = UIUtil.DefaultAtlas;
            bg.backgroundSprite          = "SubcategoriesPanel";
            bg.size                      = size;
            bg.padding                   = new RectOffset(8, 8, 8, 8);
            bg.autoLayoutPadding         = new RectOffset(0, 0, 0, 4);
            bg.autoLayout                = true;
            bg.autoLayoutDirection       = LayoutDirection.Vertical;
            bg.autoFitChildrenVertically = true;

            var topPanel = bg.AddUIComponent <UIPanel>();

            topPanel.size    = new Vector2(500, 28);
            topPanel.padding = new RectOffset(8, 8, 8, 8);

            var label = topPanel.AddUIComponent <UILabel>();

            label.name             = $"{Configuration.ResourcePrefix}TitleLabel";
            label.text             = ModInfo.ModName;
            label.relativePosition = Vector2.zero;
            label.SendToBack();

            _closeButton                  = topPanel.AddUIComponent <UIButton>();
            _closeButton.text             = "";
            _closeButton.normalBgSprite   = "buttonclose";
            _closeButton.hoveredBgSprite  = "buttonclosehover";
            _closeButton.pressedBgSprite  = "buttonclosepressed";
            _closeButton.size             = new Vector2(32, 32);
            _closeButton.relativePosition = new Vector3(width - 44, -8);

            var dragHandle = topPanel.AddUIComponent <UIDragHandle>();

            dragHandle.target           = this;
            dragHandle.relativePosition = Vector3.zero;
            dragHandle.size             = topPanel.size - new Vector2(60, 0);

            _mainPanel = bg.AddUIComponent(typeof(UIOptionsPanel)) as UIOptionsPanel;
            _netList   = bg.AddUIComponent(typeof(UINetList)) as UINetList;

            var space = bg.AddUIComponent <UIPanel>();

            space.size = new Vector2(1, 1);

            // Add filter box
            _dropdownFilterField                  = UIUtil.CreateTextField(this);
            _dropdownFilterField.size             = new Vector2(size.x - 160, 32);
            _dropdownFilterField.relativePosition = new Vector2(16, 38);
            _dropdownFilterField.isVisible        = false;

            // Add options
            _snappingToggleButton = UIUtil.CreateCheckBox(_mainPanel, "Snapping",
                                                          Locale.Get($"{Configuration.ResourcePrefix}TOOLTIPS", "SnappingToggleButton"), false);
            _snappingToggleButton.relativePosition = new Vector3(166, 38);
            _snappingToggleButton.BringToFront();

            _savePresetsButton = UIUtil.CreateUiButton(_mainPanel, string.Empty, Locale.Get($"{Configuration.ResourcePrefix}TOOLTIPS", "SaveButton"),
                                                       new Vector2(36, 36), "Save");
            _savePresetsButton.relativePosition = new Vector3(166, 38);
            _savePresetsButton.BringToFront();
            _loadPresetsButton = UIUtil.CreateUiButton(_mainPanel, string.Empty, Locale.Get($"{Configuration.ResourcePrefix}TOOLTIPS", "LoadButton"),
                                                       new Vector2(36, 36), "Load");
            _loadPresetsButton.relativePosition = new Vector3(166, 38);
            _loadPresetsButton.BringToFront();

            // Add main tool button to road options panel
            if (_toolToggleButton == null)
            {
                DestroyImmediate(_toolToggleButton);
                _toolToggleButton = null;
            }

            var tsBar = UIUtil.FindComponent <UIComponent>("TSBar", null, UIUtil.FindOptions.NameContains);

            if (tsBar == null || !tsBar.gameObject.activeInHierarchy)
            {
                return;
            }

            var toolModeBar = UIUtil.FindComponent <UITabstrip>("ToolMode", tsBar, UIUtil.FindOptions.NameContains);

            if (toolModeBar == null)
            {
                return;
            }

            var button = UIUtil.FindComponent <UICheckBox>($"{Configuration.ResourcePrefix}Parallel");

            if (button != null)
            {
                DestroyImmediate(button);
            }

            _toolToggleButton = UIUtil.CreateCheckBox(tsBar, "Parallel",
                                                      Locale.Get($"{Configuration.ResourcePrefix}TOOLTIPS", "ToolToggleButton"), false);
            if (SavedToggleX.value != -1000 && SavedToggleY.value != -1000)
            {
                _toolToggleButton.absolutePosition = new Vector3(SavedToggleX.value, SavedToggleY.value);
            }
            else
            {
                _toolToggleButton.absolutePosition =
                    new Vector3(toolModeBar.absolutePosition.x + toolModeBar.size.x + 1,
                                toolModeBar.absolutePosition.y);
            }

            // HACK - [ISSUE-26] Tool's main button must be draggable to prevent overlapping other mods buttons.
            _buttonDragHandle                  = _toolToggleButton.AddUIComponent <UIRightDragHandle>();
            _buttonDragHandle.size             = _toolToggleButton.size;
            _buttonDragHandle.relativePosition = Vector3.zero;
            _buttonDragHandle.target           = _toolToggleButton;

            SubscribeToUIEvents();

            OnPositionChanged();

            Log.Info($"[{nameof(UIMainWindow)}.{nameof(Start)}] UIMainWindow created with size {size} and position {position}");
        }