diff --git a/Studio/CelesteStudio/Editing/Theme.cs b/Studio/CelesteStudio/Editing/Theme.cs index 8f29b80b8..7a7d3a3c8 100644 --- a/Studio/CelesteStudio/Editing/Theme.cs +++ b/Studio/CelesteStudio/Editing/Theme.cs @@ -23,7 +23,7 @@ public void Dispose() { } } -public struct Theme() { +public class Theme { // Editor public Color Background; public Color Caret; diff --git a/Studio/CelesteStudio/Editing/ThemeEditor.cs b/Studio/CelesteStudio/Editing/ThemeEditor.cs index 9f4d8e6ac..b3a86cfca 100644 --- a/Studio/CelesteStudio/Editing/ThemeEditor.cs +++ b/Studio/CelesteStudio/Editing/ThemeEditor.cs @@ -334,83 +334,6 @@ private void InitializeThemeParameters() { styleLayout.EndHorizontal(); styleLayout.EndVertical(); - - /* - colorsLayout.Add(new Label { Text = field.Name }); - colorsLayout.BeginVertical(); - - colorsLayout.BeginHorizontal(); - colorsLayout.Add(new Label { Text = "Foreground" }); - var fgPicker = new ColorPicker { Value = style.ForegroundColor, AllowAlpha = true }; - fgPicker.ValueChanged += (_, _) => { - style.ForegroundColor = fgPicker.Value; - UpdateField(field, style); - }; - colorsLayout.Add(fgPicker); - pickers.Add(fgPicker); - - colorsLayout.EndBeginHorizontal(); - - if (style.BackgroundColor is Color bgColor) { - colorsLayout.Add(new Label { Text = "Background" }); - // var enable = new CheckBox { Checked = true }; - // enable.CheckedChanged += (_, _) => { - // style.BackgroundColor = null; - // UpdateField(field, style); - // }; - // colorsLayout.Add(enable); - var bgPicker = new ColorPicker { Value = bgColor, AllowAlpha = true }; - bgPicker.ValueChanged += (_, _) => { - style.BackgroundColor = bgPicker.Value; - UpdateField(field, style); - }; - colorsLayout.Add(bgPicker); - pickers.Add(bgPicker); - } else { - // colorsLayout.Add(new Label { Text = "Background" }); - // var enable = new CheckBox { Checked = false }; - // enable.CheckedChanged += (_, _) => { - // style.BackgroundColor = Color.FromRgb(0); - // UpdateField(field, style); - // }; - // colorsLayout.Add(enable); - } - - colorsLayout.EndBeginHorizontal(); - - colorsLayout.Add(new Label { Text = "Italic" }); - var italic = new CheckBox { Checked = (style.FontStyle & FontStyle.Italic) != 0 }; - italic.CheckedChanged += (_, _) => { - if (italic.Checked is bool it) { - if (it) { - style.FontStyle |= FontStyle.Italic; - } else { - style.FontStyle &= ~FontStyle.Italic; - } - } - UpdateField(field, style); - }; - colorsLayout.Add(italic); - - colorsLayout.EndBeginHorizontal(); - - colorsLayout.Add(new Label { Text = "Bold" }); - var bold = new CheckBox { Checked = (style.FontStyle & FontStyle.Bold) != 0 }; - bold.CheckedChanged += (_, _) => { - if (bold.Checked is bool b) { - if (b) { - style.FontStyle |= FontStyle.Bold; - } else { - style.FontStyle &= ~FontStyle.Bold; - } - } - UpdateField(field, style); - }; - colorsLayout.Add(bold); - - colorsLayout.EndHorizontal(); - colorsLayout.EndVertical(); - */ } fieldsLayout.EndHorizontal(); @@ -422,9 +345,8 @@ private void UpdateField(FieldInfo field, object value) { if (IsBuiltin()) { return; } - object theme = Settings.Instance.Theme; - field.SetValue(theme, value); - Settings.Instance.CustomThemes[Settings.Instance.ThemeName] = (Theme) theme; + + field.SetValue(Settings.Instance.Theme, value); Settings.OnThemeChanged(); Settings.Save(); } diff --git a/Studio/CelesteStudio/Settings.cs b/Studio/CelesteStudio/Settings.cs index 1cd2ce888..4786522ef 100644 --- a/Studio/CelesteStudio/Settings.cs +++ b/Studio/CelesteStudio/Settings.cs @@ -13,7 +13,6 @@ using Eto.Forms; using StudioCommunication.Util; using System.Diagnostics; -using System.Net; using Tomlet; using Tomlet.Attributes; using Tomlet.Exceptions; @@ -65,10 +64,10 @@ public static string BaseConfigPath { [TomlNonSerialized] public Theme Theme { get { - if (Theme.BuiltinThemes.TryGetValue(ThemeName, out Theme builtinTheme)) { + if (Theme.BuiltinThemes.TryGetValue(ThemeName, out var builtinTheme)) { return builtinTheme; } - if (CustomThemes.TryGetValue(ThemeName, out Theme customTheme)) { + if (CustomThemes.TryGetValue(ThemeName, out var customTheme)) { return customTheme; } // Fall back to light theme @@ -223,19 +222,14 @@ public static void Load() { ? Theme.BuiltinThemes[Theme.BuiltinDark] : Theme.BuiltinThemes[Theme.BuiltinLight]; - // Need to box the theme, since it's a struct - var currentThemeBox = (object)currentTheme; - foreach (var field in typeof(Theme).GetFields(BindingFlags.Public | BindingFlags.Instance)) { if (!themeTable.ContainsKey(field.Name)) { var fallbackValue = field.GetValue(fallbackTheme); - field.SetValue(currentThemeBox, fallbackValue); + field.SetValue(currentTheme, fallbackValue); Console.WriteLine($"Warning: Custom theme '{themeName}' is missing field '{field.Name}'! Defaulting to {fallbackValue}"); } } - - Instance.CustomThemes[themeName] = (Theme)currentThemeBox; } }