Example #1
0
        public static void Serialize(string filename, Configuration config)
        {
            var serializer = new XmlSerializer(typeof(Configuration));

            using (var writer = new StreamWriter(filename))
            {
                config.OnPreSerialize();
                serializer.Serialize(writer, config);
            }
        }
Example #2
0
        public void LoadConfig()
        {
            config = Configuration.Deserialize(configPath);
            if (config == null)
            {
                config = new Configuration();
                SaveConfig();
            }

            logExceptionsToConsole = config.logExceptionsToConsole;
            extendGamePanels = config.extendGamePanels;
            useModToolsConsole = config.useModToolsConsole;

            if (console != null)
            {
                console.rect = config.consoleRect;
                console.visible = config.consoleVisible;
            }

            watches.rect = config.watchesRect;
            watches.visible = config.watchesVisible;

            sceneExplorer.rect = config.sceneExplorerRect;
            sceneExplorer.visible = config.sceneExplorerVisible;

            if (sceneExplorer.visible)
            {
                sceneExplorer.Refresh();
            }
        }
        void DrawExpandedHeader()
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label("Log message format:", GUILayout.ExpandWidth(false));
            config.consoleFormatString = GUILayout.TextField(config.consoleFormatString, GUILayout.ExpandWidth(true));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Max items in history:", GUILayout.ExpandWidth(false));
            GUIControls.IntField("ConsoleMaxItemsInHistory", "", ref config.consoleMaxHistoryLength, 0.0f, true, true);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Show console on:", GUILayout.ExpandWidth(false));
            GUILayout.FlexibleSpace();
            GUILayout.Label("Message", GUILayout.ExpandWidth(false));
            config.showConsoleOnMessage = GUILayout.Toggle(config.showConsoleOnMessage, "", GUILayout.ExpandWidth(false));
            GUILayout.FlexibleSpace();
            GUILayout.Label("Warning", GUILayout.ExpandWidth(false));
            config.showConsoleOnWarning = GUILayout.Toggle(config.showConsoleOnWarning, "", GUILayout.ExpandWidth(false));
            GUILayout.FlexibleSpace();
            GUILayout.Label("Error", GUILayout.ExpandWidth(false));
            config.showConsoleOnError = GUILayout.Toggle(config.showConsoleOnError, "", GUILayout.ExpandWidth(false));

            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Auto-scroll on new messages:");
            config.consoleAutoScrollToBottom = GUILayout.Toggle(config.consoleAutoScrollToBottom, "");
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();

            if (GUILayout.Button("▲", GUILayout.ExpandWidth(false)))
            {
                headerExpanded = false;
                RecalculateAreas();
            }

            GUILayout.Label("Hide console configuration");

            GUILayout.FlexibleSpace();

            if (GUILayout.Button("Save"))
            {
                ModTools.Instance.SaveConfig();
            }

            if (GUILayout.Button("Reset"))
            {
                var template = new Configuration();
                config.consoleMaxHistoryLength = template.consoleMaxHistoryLength;
                config.consoleFormatString = template.consoleFormatString;
                config.showConsoleOnMessage = template.showConsoleOnMessage;
                config.showConsoleOnWarning = template.showConsoleOnWarning;
                config.showConsoleOnError = template.showConsoleOnError;

                ModTools.Instance.SaveConfig();
            }

            if (GUILayout.Button("Clear", GUILayout.ExpandWidth(false)))
            {
                lock (historyLock)
                {
                    history.Clear();
                }
            }

            GUILayout.EndHorizontal();
        }
        void DrawWindow()
        {
            var config = ModTools.Instance.config;

            GUILayout.BeginHorizontal();
            GUILayout.Label("Font");

            var newSelectedFont = GUIComboBox.Box(selectedFont, availableFonts, "SceneExplorerColorConfigFontsComboBox");
            if (newSelectedFont != selectedFont)
            {
                config.fontName = availableFonts[newSelectedFont];
                selectedFont = newSelectedFont;
                UpdateFont();
            }

            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();

            GUILayout.Label("Font size");

            var newFontSize = (int)GUILayout.HorizontalSlider((float) config.fontSize, 13.0f, 17.0f, GUILayout.Width(256));

            if (newFontSize != config.fontSize)
            {
                config.fontSize = newFontSize;
                UpdateFont();
            }

            GUILayout.EndHorizontal();

            DrawColorControl("Background", ref config.backgroundColor, color =>
            {
                config.backgroundColor = color;
                bgTexture.SetPixel(0, 0, config.backgroundColor);
                bgTexture.Apply();
            });

            DrawColorControl("Titlebar", ref config.titlebarColor, color =>
            {
                config.titlebarColor = color;
                moveNormalTexture.SetPixel(0, 0, config.titlebarColor);
                moveNormalTexture.Apply();

                moveHoverTexture.SetPixel(0, 0, config.titlebarColor * 1.2f);
                moveHoverTexture.Apply();
            });

            DrawColorControl("Titlebar text", ref config.titlebarTextColor, color =>
            {
                config.titlebarTextColor = color;
            });

            DrawColorControl("GameObject", ref config.gameObjectColor, color => config.gameObjectColor = color);
            DrawColorControl("Component (enabled)", ref config.enabledComponentColor, color => config.enabledComponentColor = color);
            DrawColorControl("Component (disabled)", ref config.disabledComponentColor, color => config.disabledComponentColor = color);
            DrawColorControl("Selected component", ref config.selectedComponentColor, color => config.selectedComponentColor = color);
            DrawColorControl("Keyword", ref config.keywordColor, color => config.keywordColor = color);
            DrawColorControl("Member name", ref config.nameColor, color => config.nameColor = color);
            DrawColorControl("Member type", ref config.typeColor, color => config.typeColor = color);
            DrawColorControl("Member modifier", ref config.modifierColor, color => config.modifierColor = color);
            DrawColorControl("Field type", ref config.memberTypeColor, color => config.memberTypeColor = color);
            DrawColorControl("Member value", ref config.valueColor, color => config.valueColor = color);

            GUILayout.BeginHorizontal();

            if (GUILayout.Button("Save", GUILayout.Width(128)))
            {
                ModTools.Instance.SaveConfig();
            }

            if (GUILayout.Button("Reset", GUILayout.Width(128)))
            {
                var template = new Configuration();

                config.backgroundColor = template.backgroundColor;
                bgTexture.SetPixel(0, 0, config.backgroundColor);
                bgTexture.Apply();

                config.titlebarColor = template.titlebarColor;
                moveNormalTexture.SetPixel(0, 0, config.titlebarColor);
                moveNormalTexture.Apply();

                moveHoverTexture.SetPixel(0, 0, config.titlebarColor * 1.2f);
                moveHoverTexture.Apply();

                config.titlebarTextColor = template.titlebarTextColor;

                config.gameObjectColor = template.gameObjectColor;
                config.enabledComponentColor = template.enabledComponentColor;
                config.disabledComponentColor = template.disabledComponentColor;
                config.selectedComponentColor = template.selectedComponentColor;
                config.nameColor = template.nameColor;
                config.typeColor = template.typeColor;
                config.modifierColor = template.modifierColor;
                config.memberTypeColor = template.memberTypeColor;
                config.valueColor = template.valueColor;
                config.fontName = template.fontName;
                config.fontSize = template.fontSize;

                UpdateFont();
                ModTools.Instance.SaveConfig();
            }

            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
        }