Ejemplo n.º 1
0
        static public void EnumField(string hash, string name, ref object value, float ident = 0.0f, bool noSpace = false, bool noTypeLabel = false)
        {
            GUILayout.BeginHorizontal();

            try
            {
                if (ident != 0.0f)
                {
                    GUILayout.Space(ident);
                }

                var enumType = value.GetType();

                if (!noTypeLabel)
                {
                    GUI.contentColor = config.typeColor;
                    GUILayout.Label(enumType.FullName);
                }

                GUI.contentColor = config.nameColor;
                GUILayout.Label(name);
                GUI.contentColor = config.valueColor;

                if (!noSpace)
                {
                    GUILayout.FlexibleSpace();
                }

                var enumNames = Enum.GetNames(enumType).ToArray();

                if (TypeUtil.IsBitmaskEnum(enumType))
                {
                    GUILayout.Label(value.ToString());
                }
                else
                {
                    int i = 0;
                    for (; i < enumNames.Length; i++)
                    {
                        if (value.ToString() == enumNames[i])
                        {
                            break;
                        }
                    }

                    int newIndex = GUIComboBox.Box(i, enumNames, hash);
                    value = Enum.Parse(enumType, enumNames[newIndex]);
                }

                GUI.contentColor = Color.white;
            }
            catch (Exception)
            {
                GUILayout.EndHorizontal();
                throw;
            }

            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();
        }
        protected override void DrawWindow()
        {
            var config = MainWindow.Instance.Config;

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

            var newSelectedFont = GUIComboBox.Box(selectedFont, availableFonts, "AppearanceSettingsFonts");

            if (newSelectedFont != selectedFont && newSelectedFont >= 0)
            {
                config.FontName = availableFonts[newSelectedFont];
                selectedFont    = newSelectedFont;
                UpdateFont();
            }

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

            GUILayout.Label("Font size");

            var newFontSize = (int)GUILayout.HorizontalSlider(config.FontSize, 13.0f, 39.0f, GUILayout.Width(256));

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

            GUILayout.EndHorizontal();

            var newColor = DrawColorControl("Background", config.BackgroundColor);

            if (newColor != config.BackgroundColor)
            {
                config.BackgroundColor = newColor;
                BgTexture.SetPixel(0, 0, config.BackgroundColor);
                BgTexture.Apply();
            }

            newColor = DrawColorControl("Title bar", config.TitleBarColor);
            if (newColor != config.TitleBarColor)
            {
                config.TitleBarColor = newColor;
                MoveNormalTexture.SetPixel(0, 0, config.TitleBarColor);
                MoveNormalTexture.Apply();

                MoveHoverTexture.SetPixel(0, 0, config.TitleBarColor * 1.2f);
                MoveHoverTexture.Apply();
            }

            config.TitleBarTextColor = DrawColorControl("Title bar text", config.TitleBarTextColor);

            config.GameObjectColor        = DrawColorControl("GameObject", config.GameObjectColor);
            config.EnabledComponentColor  = DrawColorControl("Component (enabled)", config.EnabledComponentColor);
            config.DisabledComponentColor = DrawColorControl("Component (disabled)", config.DisabledComponentColor);
            config.SelectedComponentColor = DrawColorControl("Selected component", config.SelectedComponentColor);
            config.KeywordColor           = DrawColorControl("Keyword", config.KeywordColor);
            config.NameColor       = DrawColorControl("Member name", config.NameColor);
            config.TypeColor       = DrawColorControl("Member type", config.TypeColor);
            config.ModifierColor   = DrawColorControl("Member modifier", config.ModifierColor);
            config.MemberTypeColor = DrawColorControl("Field type", config.MemberTypeColor);
            config.ValueColor      = DrawColorControl("Member value", config.ValueColor);

            GUILayout.FlexibleSpace();

            GUILayout.BeginHorizontal();

            GUILayout.FlexibleSpace();

            if (GUILayout.Button("OK", GUILayout.Width(100)))
            {
                MainWindow.Instance.SaveConfig();
                Visible = false;
            }

            if (GUILayout.Button("Defaults", GUILayout.Width(100)))
            {
                ResetDoDefault(config);
                selectedFont = Array.IndexOf(availableFonts, config.FontName);
            }

            GUILayout.EndHorizontal();
        }