public void InitPanels()
 {
     //bool enabledS = this.enabled;
     //enabled = false;
     if (P_RoundAboutPanel != null)
     {
         RemoveUIComponent(P_RoundAboutPanel);
         RemoveUIComponent(P_FreeToolPanel);
     }
     if (P_EllipsePanel_1 != null)
     {
         RemoveUIComponent(P_EllipsePanel_1);
         RemoveUIComponent(P_EllipsePanel_2);
         RemoveUIComponent(P_EllipsePanel_3);
     }
     P_RoundAboutPanel = AddUIComponent <RoundAboutPanel>();
     P_FreeToolPanel   = AddUIComponent <FreeToolPanel>();
     if (RoundAboutBuilder.LegacyEllipticRoundabouts.value)
     {
         P_EllipsePanel_1 = AddUIComponent <EllipsePanel_1>();
         P_EllipsePanel_2 = AddUIComponent <EllipsePanel_2>();
         P_EllipsePanel_3 = AddUIComponent <EllipsePanel_3>();
     }
     // this.enabled = enabledS;
 }
Exemplo n.º 2
0
        private void CreateOptionPanel()
        {
            name             = "RAB_ToolOptionsPanel";
            atlas            = ResourceLoader.GetAtlas("Ingame");
            backgroundSprite = "SubcategoriesPanel";
            size             = new Vector2(204, 180);
            absolutePosition = new Vector3(RoundAboutBuilder.savedWindowX.value, RoundAboutBuilder.savedWindowY.value);

            isVisible = false;

            //DebugUtils.Log("absolutePosition: " + absolutePosition);

            eventPositionChanged += (c, p) =>
            {
                if (absolutePosition.x < 0)
                {
                    absolutePosition = RoundAboutBuilder.defWindowPosition;
                }

                Vector2 resolution = GetUIView().GetScreenResolution();

                absolutePosition = new Vector2(
                    Mathf.Clamp(absolutePosition.x, 0, resolution.x - width),
                    Mathf.Clamp(absolutePosition.y, 0, resolution.y - height));

                RoundAboutBuilder.savedWindowX.value = (int)absolutePosition.x;
                RoundAboutBuilder.savedWindowY.value = (int)absolutePosition.y;
            };

            UIDragHandle dragHandle = AddUIComponent <UIDragHandle>();

            dragHandle.width            = width;
            dragHandle.relativePosition = Vector3.zero;
            dragHandle.target           = parent;

            P_RoundAboutPanel = AddUIComponent <RoundAboutPanel>();
            P_EllipsePanel_1  = AddUIComponent <EllipsePanel_1>();
            P_EllipsePanel_2  = AddUIComponent <EllipsePanel_2>();
            P_EllipsePanel_3  = AddUIComponent <EllipsePanel_3>();
            P_TmpeSetupPanel  = AddUIComponent <TmpeSetupPanel>();
            P_FreeToolPanel   = AddUIComponent <FreeToolPanel>();
            //P_RoundAboutPanel.height = 104f; // cheat

            // From Elektrix's Road Tools
            UIButton openDescription = AddUIComponent <UIButton>();

            openDescription.relativePosition = new Vector3(width - 24f, 8f);
            openDescription.size             = new Vector3(15f, 15f);
            openDescription.normalFgSprite   = "ToolbarIconHelp";
            openDescription.name             = "RAB_workshopButton";
            openDescription.tooltip          = "Roundabout Builder [" + RoundAboutBuilder.VERSION + "] by Strad\nOpen in Steam Workshop";
            SetupButtonStateSprites(ref openDescription, "OptionBase", true);
            if (!PlatformService.IsOverlayEnabled())
            {
                openDescription.isVisible = false;
                openDescription.isEnabled = false;
            }
            openDescription.eventClicked += delegate(UIComponent component, UIMouseEventParameter click)
            {
                if (PlatformService.IsOverlayEnabled() && RoundAboutBuilder.WORKSHOP_FILE_ID != null)
                {
                    PlatformService.ActivateGameOverlayToWorkshopItem(RoundAboutBuilder.WORKSHOP_FILE_ID);
                }
                openDescription.Unfocus();
            };
            // -- Elektrix

            float cummulativeHeight = 8;

            /* Top section */
            m_topSection = AddUIComponent <UIPanel>();
            m_topSection.relativePosition = new Vector2(0, 0);
            m_topSection.SendToBack();

            UILabel label = m_topSection.AddUIComponent <UILabel>();

            label.textScale        = 0.9f;
            label.text             = "Roundabout Builder";
            label.relativePosition = new Vector2(8, cummulativeHeight);
            label.SendToBack();
            cummulativeHeight += label.height + 8;

            m_topSection.height = cummulativeHeight;
            m_topSection.width  = width;
            dragHandle.height   = cummulativeHeight;

            dropDown = AddUIComponent <UINetInfoDropDown>();
            //dropDown.relativePosition = new Vector2(8, cummulativeHeight);
            dropDown.width = width - 16;
            //cummulativeHeight += dropDown.height + 8;


            /* Bottom section */

            m_setupTmpeSection              = AddUIComponent <UIPanel>();
            m_setupTmpeSection.width        = 204f;
            m_setupTmpeSection.clipChildren = true;
            var setupTmpe = CreateCheckBox(m_setupTmpeSection);

            setupTmpe.name               = "RAB_setupTmpe";
            setupTmpe.label.text         = "Set up TMPE";
            setupTmpe.tooltip            = "Apply TMPE policies to the roundabout";
            setupTmpe.isChecked          = SavedSetupTmpe;
            setupTmpe.relativePosition   = new Vector3(8, 0);
            setupTmpe.eventCheckChanged += (c, state) =>
            {
                SavedSetupTmpe.value = state;
            };
            var tmpeButton = CreateButton(m_setupTmpeSection);

            tmpeButton.text             = "...";
            tmpeButton.tooltip          = "TMPE settings";
            tmpeButton.height           = setupTmpe.height;
            tmpeButton.width            = 30;
            tmpeButton.relativePosition = new Vector2(width - tmpeButton.width - 8, 0);
            tmpeButton.eventClick      += (c, p) =>
            {
                bool holder = this.keepOpen;
                this.keepOpen    = true;
                toolOnUI.enabled = false;
                this.keepOpen    = holder;
                SwitchWindow(P_TmpeSetupPanel);
            };
            m_setupTmpeSection.height = setupTmpe.height + 8;
            //cummulativeHeight += keepOpen.height + 8;

            cummulativeHeight = 0;
            m_bottomSection   = AddUIComponent <UIPanel>();

            var keepOpen = CreateCheckBox(m_bottomSection);

            keepOpen.name               = "RAB_keepOpen";
            keepOpen.label.text         = "Keep open";
            keepOpen.tooltip            = "Window won't close automatically when the tool is unselected";
            keepOpen.isChecked          = true;
            keepOpen.relativePosition   = new Vector3(8, cummulativeHeight);
            keepOpen.width              = 196; // width - padding
            keepOpen.eventCheckChanged += (c, state) =>
            {
                this.keepOpen = state;
            };
            cummulativeHeight += keepOpen.height + 8;

            // Back button
            backButton                  = CreateButton(m_bottomSection);
            backButton.text             = "Back";
            backButton.relativePosition = new Vector2(8, cummulativeHeight);
            backButton.width            = width - 16;
            backButton.eventClick      += (c, p) =>
            {
                if (backButton.isVisible)
                {
                    if (m_panelOnUI.IsSpecialWindow)
                    {
                        SwitchWindow(m_lastStandardPanel);
                        toolOnUI.enabled = true;
                    }
                    else
                    {
                        toolOnUI.GoToFirstStage();
                        SwitchTool(RoundaboutTool.Instance);
                    }
                }
            };

            cummulativeHeight += backButton.height + 8;

            closeButton                  = CreateButton(m_bottomSection);
            closeButton.text             = "Close";
            closeButton.relativePosition = new Vector2(8, cummulativeHeight);
            closeButton.eventClick      += (c, p) =>
            {
                enabled = false;
                if (toolOnUI != null)
                {
                    toolOnUI.enabled = false;
                }
            };

            undoButton                  = CreateButton(m_bottomSection);
            undoButton.text             = "Undo";
            undoButton.tooltip          = "Remove last built roundabout (CTRL+Z). Warning: Use only right after the roundabout has been built";
            undoButton.relativePosition = new Vector2(16 + closeButton.width, cummulativeHeight);
            undoButton.isEnabled        = false;
            undoButton.eventClick      += (c, p) =>
            {
                ModThreading.UndoAction();
            };

            cummulativeHeight += closeButton.height + 8;

            m_bottomSection.height = cummulativeHeight;
            m_bottomSection.width  = width;

            m_hoveringLabel           = AddUIComponent <HoveringLabel>();
            m_hoveringLabel.isVisible = false;

            /* Enable roundabout tool as default */
            SwitchTool(RoundaboutTool.Instance);

            // Is done by modthreading from 1.5.3 on

            /*try
             * {
             *  if(RoundAboutBuilder.ShowUIButton)
             *     UIPanelButton.CreateButton();
             * }
             * catch(Exception e)
             * {
             *  Debug.LogWarning("Failed to create UI button.");
             *  Debug.LogWarning(e);
             * }*/


            enabled = false;
        }