Beispiel #1
0
        void OnDestroy()
        {
            try
            {
                if (_currentSkin != null)
                {
                    _currentSkin.Rollback();
                }

                _currentSkin = null;

                if (_quartzPanel != null)
                {
					Debug.Log("Unload Quartz Panel");
                    Destroy(_quartzPanel);
                }

                if (_quartzButton != null)
                {
					Debug.Log("Unload Quartz Button");
					Destroy(_quartzButton);
                }

                SetCameraRectHelper.Deinitialize();

                _bootstrapped = false;
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
        }
Beispiel #2
0
        public static void Bootstrap(Skin.ModuleClass moduleClass)
        {
			if (!MyInfo().isEnabled)
			{
				Deinitialize();
				return;
			}
			Debug.LogWarning("Trying to bootstrap moduleClass: " + Enum.GetName(typeof(Skin.ModuleClass), moduleClass) + " status of bootstrap is: " + _bootstrapped);
			if (_bootstrapped && moduleClass != _currentModuleClass)
            {
				Debug.LogWarning("De-strapping moduleClass: " + Enum.GetName(typeof(Skin.ModuleClass), moduleClass) + " because bootstrap was " + _bootstrapped);
				Deinitialize();
            }
			else if (_bootstrapped && moduleClass == _currentModuleClass)
			{
				Debug.Log("Already bootstrapped for this class, skipping");
				return;
			}

            ErrorLogger.ResetSettings();

            _currentModuleClass = moduleClass;
			Debug.LogWarning("Success bootstrapping moduleClass: " + Enum.GetName(typeof(Skin.ModuleClass), moduleClass));

            FindObjectOfType<UIView>().gameObject.AddComponent<Core>();
            _bootstrapped = true;
        }
Beispiel #3
0
        public static Skin FromXmlFile(string skinXmlPath, bool autoReloadOnChange)
        {
            Skin skin = null;

            try
            {
                skin = new Skin(skinXmlPath, autoReloadOnChange);
            }
            catch (XmlNodeException ex)
            {
                Debug.LogErrorFormat("{0} while parsing xml \"{1}\" at node \"{2}\": {3}",
                    ex.GetType(), skinXmlPath, ex.Node == null ? "null" : ex.Node.Name, ex.ToString());
            }
            catch (XmlException ex)
            {
                Debug.LogErrorFormat("XmlException while parsing xml \"{0}\" at line {1}, col {2}: {3}",
                    skinXmlPath, ex.LineNumber, ex.LinePosition, ex.Message);
            }
            catch (Exception ex)
            {
                Debug.LogErrorFormat("{0} while parsing xml \"{1}\": {2}", ex.GetType(),
                    skinXmlPath, ex.ToString());
            }

            return skin;
        }
Beispiel #4
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 - 64.0f - button.width, 16.0f, 0.0f);
	        }
			return button;
        }
 public SkinApplicator(Skin _skin)
 {
     this._skin = _skin;
 }
Beispiel #6
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);

				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;
        }
Beispiel #7
0
        void Start()
        {
			Debug.Log("Start ran!");
			if (!MyInfo().isEnabled)
			{
				Deinitialize();
				return;
			}
            SetCameraRectHelper.Initialize();

            if (!Directory.Exists(OverrideDirectory))
            {
                try
                {
                    Directory.CreateDirectory(OverrideDirectory);
                }
                catch (Exception ex)
                {
                    Debug.LogException(ex);
                }
            }

            InitializeInGamePanels();

            _availableSkins = SkinLoader.FindAllSkins();

			if (!string.IsNullOrEmpty(ConfigManager.SelectedSkinPath) && ConfigManager.ApplySkinOnStartup)
            {
                foreach (var metadata in _availableSkins)
                {
					if (metadata.Path == ConfigManager.SelectedSkinPath)
                    {
                        _currentSkin = Skin.FromXmlFile(Path.Combine(metadata.Path, "skin.xml"), false);
                        _needToApplyCurrentSkin = true;
                        break;
                    }
                }
            }
            
            CreateUI();

            _debugRenderer = gameObject.AddComponent<DebugRenderer>();
        }