Example #1
0
        public static UIButton CreateSapphireButton(Skin.ModuleClass moduleClass)
        {
            var uiView = GameObject.Find("UIView").GetComponent <UIView>();

            if (uiView == null)
            {
                Debug.LogError("UIView is null!");
                return(null);
            }

            var button = uiView.AddUIComponent(typeof(UIButton)) as UIButton;

            button.name            = "SapphireButton";
            button.gameObject.name = "SapphireButton";
            button.width           = 32;
            button.height          = 32;

            button.pressedBgSprite  = "";
            button.normalBgSprite   = "";
            button.hoveredBgSprite  = "";
            button.disabledBgSprite = "";

            button.atlas                = EmbeddedResources.GetSapphireAtlas();
            button.normalFgSprite       = "SapphireIcon";
            button.hoveredFgSprite      = "SapphireIconHover";
            button.pressedFgSprite      = "SapphireIconPressed";
            button.foregroundSpriteMode = UIForegroundSpriteMode.Scale;
            button.scaleFactor          = 1.0f;

            button.tooltip    = "Sapphire Skin Manager";
            button.tooltipBox = uiView.defaultTooltipBox;

            if (moduleClass == Skin.ModuleClass.MainMenu)
            {
                button.relativePosition = new Vector3(4.0f, 2.0f, 0.0f);
            }
            else
            {
                button.relativePosition = new Vector3(64.0f, 16.0f, 0.0f);
            }

            return(button);
        }
Example #2
0
        private UIPanel CreateSapphirePanel()
        {
            var uiView = GameObject.Find("UIView").GetComponent <UIView>();

            if (uiView == null)
            {
                Debug.LogError("UIView is null!");
                return(null);
            }

            var panel = uiView.AddUIComponent(typeof(UIPanel)) as UIPanel;

            panel.size             = new Vector2(300, 250);
            panel.isVisible        = false;
            panel.atlas            = EmbeddedResources.GetSapphireAtlas();
            panel.backgroundSprite = "DefaultPanelBackground";

            if (currentModuleClass == Skin.ModuleClass.MainMenu)
            {
                panel.relativePosition = new Vector3(2.0f, 34.0f);
            }
            else
            {
                panel.relativePosition = new Vector3(2.0f, 34.0f + 64.0f);
            }

            panel.name = "SapphireSkinManager";

            var title = panel.AddUIComponent <UILabel>();

            title.relativePosition = new Vector3(2.0f, 2.0f);
            title.text             = "Sapphire Skin Manager";
            title.textColor        = Color.black;

            float y = 32.0f;

            UIUtil.MakeCheckbox(panel, "ShowIconInGame", "Show Sapphire icon in-game", new Vector2(4.0f, y), config.showSapphireIconInGame, value =>
            {
                config.showSapphireIconInGame = value;
                SaveConfig();

                if (sapphireButton != null && !config.showSapphireIconInGame && currentModuleClass == Skin.ModuleClass.InGame)
                {
                    sapphireButton.isVisible = false;
                    if (sapphirePanel != null)
                    {
                        sapphirePanel.isVisible = false;
                    }
                }
                else if (sapphireButton != null)
                {
                    sapphireButton.isVisible = true;
                }
            });

            y += 28.0f;

            UIUtil.MakeCheckbox(panel, "AutoApplySkin", "Apply skin on start-up", new Vector2(4.0f, y), config.applySkinOnStartup, value =>
            {
                config.applySkinOnStartup = value;
                SaveConfig();
            });

            y += 28.0f;

            UIUtil.MakeCheckbox(panel, "DrawDebugInfo", "Developer mode (Ctrl+D)", new Vector2(4.0f, y), false, value =>
            {
                if (debugRenderer != null)
                {
                    debugRenderer.drawDebugInfo = value;
                }
            });

            y += 28.0f;

            UIUtil.MakeCheckbox(panel, "AutoReload", "Auto-reload active skin on file change", new Vector2(4.0f, y), false, value =>
            {
                autoReloadSkinOnChange = value;
                ReloadAndApplyActiveSkin();
            });


            y += 28.0f;

            skinsDropdown = panel.AddUIComponent <UIDropDown>();

            skinsDropdown.AddItem("Vanilla (by Colossal Order)");
            foreach (var skin in availableSkins)
            {
                skinsDropdown.AddItem(String.Format("{0} (by {1})", skin.name, skin.author));
            }

            skinsDropdown.size                 = new Vector2(296.0f, 32.0f);
            skinsDropdown.relativePosition     = new Vector3(2.0f, y);
            skinsDropdown.listBackground       = "GenericPanelLight";
            skinsDropdown.itemHeight           = 32;
            skinsDropdown.itemHover            = "ListItemHover";
            skinsDropdown.itemHighlight        = "ListItemHighlight";
            skinsDropdown.normalBgSprite       = "ButtonMenu";
            skinsDropdown.listWidth            = 300;
            skinsDropdown.listHeight           = 500;
            skinsDropdown.foregroundSpriteMode = UIForegroundSpriteMode.Stretch;
            skinsDropdown.popupColor           = new Color32(45, 52, 61, 255);
            skinsDropdown.popupTextColor       = new Color32(170, 170, 170, 255);
            skinsDropdown.zOrder               = 1;
            skinsDropdown.textScale            = 0.8f;
            skinsDropdown.verticalAlignment    = UIVerticalAlignment.Middle;
            skinsDropdown.horizontalAlignment  = UIHorizontalAlignment.Center;
            skinsDropdown.textFieldPadding     = new RectOffset(8, 0, 8, 0);
            skinsDropdown.itemPadding          = new RectOffset(8, 0, 2, 0);

            skinsDropdown.selectedIndex = 0;

            if (currentSkin != null)
            {
                int i = 1;
                foreach (var skin in availableSkins)
                {
                    if (skin.sapphirePath == currentSkin.SapphirePath)
                    {
                        skinsDropdown.selectedIndex = i;
                    }

                    i++;
                }
            }

            skinsDropdown.eventSelectedIndexChanged += (component, index) =>
            {
                if (index == 0)
                {
                    if (currentSkin != null)
                    {
                        currentSkin.Dispose();
                    }

                    currentSkin = null;
                    return;
                }

                var skin = availableSkins[index - 1];
                if (currentSkin != null && currentSkin.SapphirePath == skin.sapphirePath)
                {
                    return;
                }

                if (currentSkin != null)
                {
                    currentSkin.Dispose();
                }

                currentSkin = Skin.FromXmlFile(Path.Combine(skin.sapphirePath, "skin.xml"), autoReloadSkinOnChange);

                if (currentSkin.IsValid)
                {
                    currentSkin.Apply(currentModuleClass);
                }
                else
                {
                    Debug.LogWarning("Skin is invalid, will not apply.. (check messages above for errors)");
                }

                config.selectedSkinPath = currentSkin.SapphirePath;
                SaveConfig();
                panel.isVisible = false;
            };

            var skinsDropdownButton = skinsDropdown.AddUIComponent <UIButton>();

            skinsDropdown.triggerButton = skinsDropdownButton;

            skinsDropdownButton.text                    = "";
            skinsDropdownButton.size                    = skinsDropdown.size;
            skinsDropdownButton.relativePosition        = new Vector3(0.0f, 0.0f);
            skinsDropdownButton.textVerticalAlignment   = UIVerticalAlignment.Middle;
            skinsDropdownButton.textHorizontalAlignment = UIHorizontalAlignment.Center;
            skinsDropdownButton.normalFgSprite          = "IconDownArrow";
            skinsDropdownButton.hoveredFgSprite         = "IconDownArrowHovered";
            skinsDropdownButton.pressedFgSprite         = "IconDownArrowPressed";
            skinsDropdownButton.focusedFgSprite         = "IconDownArrowFocused";
            skinsDropdownButton.disabledFgSprite        = "IconDownArrowDisabled";
            skinsDropdownButton.foregroundSpriteMode    = UIForegroundSpriteMode.Fill;
            skinsDropdownButton.horizontalAlignment     = UIHorizontalAlignment.Right;
            skinsDropdownButton.verticalAlignment       = UIVerticalAlignment.Middle;
            skinsDropdownButton.zOrder                  = 0;
            skinsDropdownButton.textScale               = 0.8f;

            y += 40.0f;

            UIUtil.MakeButton(panel, "ReloadSkin", "Reload active skin (Ctrl+S)", new Vector2(4.0f, y), ReloadAndApplyActiveSkin);

            y += 36.0f;

            UIUtil.MakeButton(panel, "RefreshSkins", "Refresh available skins", new Vector2(4.0f, y), () =>
            {
                RefreshSkinsList();
            });

            return(panel);
        }