Example #1
0
        public static UIButton CreateQuartzButton(Skin.ModuleClass moduleClass)
        {
            Debug.Log("Creating button");
            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;

            if (button != null)
            {
                button.name            = "QuartzButton";
                button.gameObject.name = "QuartzButton";
                button.width           = 32;
                button.height          = 32;

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

                button.atlas                = EmbeddedResources.GetQuartzAtlas();
                button.normalFgSprite       = "QuartzIcon";
                button.hoveredFgSprite      = "QuartzIconHover";
                button.pressedFgSprite      = "QuartzIconPressed";
                button.foregroundSpriteMode = UIForegroundSpriteMode.Scale;
                button.scaleFactor          = 1.0f;

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

                Vector2 viewSize = uiView.GetScreenResolution();

                button.relativePosition = moduleClass == Skin.ModuleClass.MainMenu
                                              ? new Vector3(viewSize.x - 4.0f - button.width, 2.0f, 0.0f)
                                              : new Vector3(viewSize.x - 19.0f - button.width, 34.0f + button.height, 0.0f);
            }
            return(button);
        }
Example #2
0
        private UIPanel CreateQuartzPanel()
        {
            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;

            if (panel != null)
            {
                panel.size             = new Vector2(300, 290);
                panel.isVisible        = false;
                panel.atlas            = EmbeddedResources.GetQuartzAtlas();
                panel.backgroundSprite = "DefaultPanelBackground";

                Vector2 viewSize = uiView.GetScreenResolution();

                panel.relativePosition = _currentModuleClass == Skin.ModuleClass.MainMenu
                    ? new Vector3(viewSize.x - 2.0f - panel.size.x, 34.0f)
                    : new Vector3(viewSize.x - 2.0f - panel.size.x, 34.0f + 64.0f + 15.0f);

                panel.name = "QuartzSkinManager";

                var title = panel.AddUIComponent <UILabel>();
                title.relativePosition = new Vector3(2.0f, 2.0f);
                title.text             = "Quartz Skin Manager";
                title.textColor        = Color.black;
            }

            float y = 32.0f;

            UIUtil.MakeCheckbox(panel, "ShowIconInGame", "Show Quartz icon in-game", new Vector2(4.0f, y), ConfigManager.ShowQuartzIconInGame, value =>
            {
                ConfigManager.ShowQuartzIconInGame = value;

                if (_quartzButton != null && !ConfigManager.ShowQuartzIconInGame && _currentModuleClass == Skin.ModuleClass.InGame)
                {
                    _quartzButton.isVisible = false;
                    if (_quartzPanel != null)
                    {
                        _quartzPanel.isVisible = false;
                    }
                }
                else if (_quartzButton != null)
                {
                    _quartzButton.isVisible = true;
                }
            });

            y += 28.0f;

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

            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;

            UIUtil.MakeCheckbox(panel, "IgnoreMissing", "Force load (May break stuff)", new Vector2(4.0f, y), ConfigManager.IgnoreMissingComponents, value =>
            {
                ConfigManager.IgnoreMissingComponents = value;
            });

            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}){2}", skin.Name, skin.Author, skin.Legacy ? " [LEGACY]" : string.Empty));
            }

            _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.Path == _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.Path)
                {
                    return;
                }

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

                _currentSkin = Skin.FromXmlFile(Path.Combine(skin.Path, "skin.xml"), _autoReloadSkinOnChange);

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

                ConfigManager.SelectedSkinPath = _currentSkin.SapphirePath;
                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+Shift+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);
        }