Beispiel #1
0
        /* The code below was copied from Fine Road Tool and More Shortcuts mod by SamsamTS. Thanks! */

        public static UICheckBox CreateCheckBox(UIComponent parent)
        {
            UICheckBox checkBox = (UICheckBox)parent.AddUIComponent <UICheckBox>();

            checkBox.width        = 300f;
            checkBox.height       = 20f;
            checkBox.clipChildren = true;

            UISprite sprite = checkBox.AddUIComponent <UISprite>();

            sprite.atlas            = ResourceLoader.GetAtlas("Ingame");
            sprite.spriteName       = "ToggleBase";
            sprite.size             = new Vector2(16f, 16f);
            sprite.relativePosition = Vector3.zero;

            checkBox.checkedBoxObject = sprite.AddUIComponent <UISprite>();
            ((UISprite)checkBox.checkedBoxObject).atlas      = ResourceLoader.GetAtlas("Ingame");
            ((UISprite)checkBox.checkedBoxObject).spriteName = "ToggleBaseFocused";
            checkBox.checkedBoxObject.size             = new Vector2(16f, 16f);
            checkBox.checkedBoxObject.relativePosition = Vector3.zero;

            checkBox.label                  = checkBox.AddUIComponent <UILabel>();
            checkBox.label.text             = " ";
            checkBox.label.textScale        = 0.9f;
            checkBox.label.relativePosition = new Vector3(22f, 2f);

            checkBox.playAudioEvents = true;

            return(checkBox);
        }
        //private PopulationMode m_populationMode;

        public UINetInfoDropDown()
        {
            atlas                = ResourceLoader.GetAtlas("Ingame");
            size                 = new Vector2(90f, 30f);
            listBackground       = "GenericPanelLight";
            itemHeight           = 25;
            itemHover            = "ListItemHover";
            itemHighlight        = "ListItemHighlight";
            normalBgSprite       = "ButtonMenu";
            disabledBgSprite     = "ButtonMenuDisabled";
            hoveredBgSprite      = "ButtonMenuHovered";
            focusedBgSprite      = "ButtonMenu";
            listWidth            = 90;
            listHeight           = 1000;
            listPosition         = UIDropDown.PopupListPosition.Below;
            clampListToScreen    = true;
            builtinKeyNavigation = true;
            foregroundSpriteMode = UIForegroundSpriteMode.Stretch;
            popupColor           = new Color32(45, 52, 61, 255);
            popupTextColor       = new Color32(170, 170, 170, 255);
            zOrder               = 1;
            textScale            = 0.8f;
            verticalAlignment    = UIVerticalAlignment.Middle;
            horizontalAlignment  = UIHorizontalAlignment.Left;
            selectedIndex        = 0;
            textFieldPadding     = new RectOffset(8, 0, 8, 0);
            itemPadding          = new RectOffset(14, 0, 8, 0);

            UIButton button = AddUIComponent <UIButton>();

            triggerButton                  = button;
            button.atlas                   = ResourceLoader.GetAtlas("Ingame");
            button.text                    = "";
            button.size                    = size;
            button.relativePosition        = new Vector3(0f, 0f);
            button.textVerticalAlignment   = UIVerticalAlignment.Middle;
            button.textHorizontalAlignment = UIHorizontalAlignment.Left;
            button.normalFgSprite          = "IconDownArrow";
            button.hoveredFgSprite         = "IconDownArrowHovered";
            button.pressedFgSprite         = "IconDownArrowPressed";
            button.focusedFgSprite         = "IconDownArrowFocused";
            button.disabledFgSprite        = "IconDownArrowDisabled";
            button.foregroundSpriteMode    = UIForegroundSpriteMode.Fill;
            button.horizontalAlignment     = UIHorizontalAlignment.Right;
            button.verticalAlignment       = UIVerticalAlignment.Middle;
            button.zOrder                  = 0;
            button.textScale               = 0.8f;

            eventSizeChanged += new PropertyChangedEventHandler <Vector2>((c, t) =>
            {
                button.size = t; listWidth = (int)t.x;
            });

            Populate();
        }
        public static UIButton CreateButton(UIComponent parent)
        {
            UIButton button = (UIButton)parent.AddUIComponent <UIButton>();

            button.atlas           = ResourceLoader.GetAtlas("Ingame");
            button.size            = new Vector2(90f, 30f);
            button.textScale       = 0.9f;
            button.normalBgSprite  = "ButtonMenu";
            button.hoveredBgSprite = "ButtonMenuHovered";
            button.pressedBgSprite = "ButtonMenuPressed";
            button.canFocus        = false;
            button.playAudioEvents = true;

            return(button);
        }
        public override void Start()
        {
            var roadsOptionPanel = UIUtils.Instance.FindComponent <UIComponent>("RoadsOptionPanel", null, UIUtils.FindOptions.NameContains);
            var builtinTabstrip  = UIUtils.Instance.FindComponent <UITabstrip>("ToolMode", roadsOptionPanel, UIUtils.FindOptions.None);

            UIButton uibutton = (UIButton)builtinTabstrip.tabs[0];

            int num  = 31;
            int num2 = 31;

            string[] spriteNames = new string[]
            {
                "RoundaboutButtonBg",
                "RoundaboutButtonBgPressed",
                "RoundaboutButtonBgHovered",
                "RoundaboutIcon",
                "RoundaboutIconPressed"
            };
            if (ResourceLoader.GetAtlas("RoundaboutUI") == UIView.GetAView().defaultAtlas)
            {
                atlas = ResourceLoader.CreateTextureAtlas("sprites.png", "RoundaboutUI", uibutton.atlas.material, num, num2, spriteNames);
            }
            else
            {
                atlas = ResourceLoader.GetAtlas("RoundaboutUI");
            }

            name             = "RoundaboutButton";
            size             = new Vector2((float)num, (float)num2);
            normalBgSprite   = "RoundaboutButtonBg";
            disabledBgSprite = "RoundaboutButtonBg";
            hoveredBgSprite  = "RoundaboutButtonBgHovered";
            pressedBgSprite  = "RoundaboutButtonBgPressed";
            //focusedBgSprite = "RoundaboutButtonBgPressed";
            focusedBgSprite  = "RoundaboutButtonBg";
            playAudioEvents  = true;
            tooltip          = "Roundabout Builder (CTRL+O)";
            normalFgSprite   = (disabledFgSprite = (hoveredFgSprite = (focusedFgSprite = "RoundaboutIcon")));
            pressedFgSprite  = "RoundaboutIconPressed";
            relativePosition = new Vector3(BUTTON_HORIZONTAL_POSITION, 38f); //94,38
            size             = new Vector2((float)num, (float)num2);
        }
 public NumericTextField()
 {
     atlas   = ResourceLoader.GetAtlas("Ingame");
     size    = new Vector2(50, 20);
     padding = new RectOffset(4, 4, 3, 3);
     builtinKeyNavigation     = true;
     isInteractive            = true;
     readOnly                 = false;
     horizontalAlignment      = UIHorizontalAlignment.Center;
     selectionSprite          = "EmptySprite";
     selectionBackgroundColor = new Color32(0, 172, 234, 255);
     normalBgSprite           = "TextFieldPanelHovered";
     disabledBgSprite         = "TextFieldPanelHovered";
     textColor                = new Color32(0, 0, 0, 255);
     disabledTextColor        = new Color32(80, 80, 80, 128);
     color         = new Color32(255, 255, 255, 255);
     textScale     = 0.9f;
     useDropShadow = true;
     text          = DefaultVal.ToString();
 }
Beispiel #6
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;
        }