diff --git a/src/main/java/org/saturnclient/config/Config.java b/src/main/java/org/saturnclient/config/Config.java index c986eca..d215197 100644 --- a/src/main/java/org/saturnclient/config/Config.java +++ b/src/main/java/org/saturnclient/config/Config.java @@ -28,6 +28,9 @@ public class Config { public static FloatProperty titleScale = guiScale(); public static FloatProperty menuScale = guiScale(); public static FloatProperty hudMenuScale = guiScale(); + + /** Added in 0.1.3, so a config without it was saved by an older version */ + static final String MENU_BLUR = "Menu blur"; public static KeybindingProperty openEmoteWheel = Property.keybinding(GLFWProvider.GLFW_KEY_B); private static FloatProperty guiScale() { @@ -57,7 +60,7 @@ public class Config { config.property("Cloak Physics", cloakPhysics, "Let cloaks swing as you move"); config.property("Stagger Animations", stagger, "Animate list items one after another"); config.property("World blur", backgroundBlur, "How much the world or panorama behind Saturn's screens is blurred"); - config.property("Menu blur", menuBlur, "How much the game is blurred through translucent menus"); + config.property(MENU_BLUR, menuBlur, "How much the game is blurred through translucent menus"); config.property("Widget blur", widgetBlur, "How much the game is blurred through translucent buttons and the dock"); config.property("Title screen scale", titleScale, "How big the title screen is, relative to Minecraft's GUI scale"); config.property("Menu scale", menuScale, "How big the mods, settings and cosmetics menus are, relative to Minecraft's GUI scale"); diff --git a/src/main/java/org/saturnclient/config/ConfigManager.java b/src/main/java/org/saturnclient/config/ConfigManager.java index f844fe0..d9c4535 100644 --- a/src/main/java/org/saturnclient/config/ConfigManager.java +++ b/src/main/java/org/saturnclient/config/ConfigManager.java @@ -156,10 +156,25 @@ public class ConfigManager { * Load only a single property immediately after creation */ private void loadSingleProperty(String name, Property prop) { + JsonNode element = getSaved(name); + if (element != null) { + prop.loadFromJson(element); + } + } + + /** + * Whether the config file has a value for {@code name} in this namespace, + * which tells which version last saved it. + */ + public boolean isSaved(String name) { + return getSaved(name) != null; + } + + private JsonNode getSaved(String name) { JsonNode source = cachedJson != null ? cachedJson : loadAndCache(); if (source == null || !source.isObject()) - return; + return null; JsonNode currentScope = source; @@ -170,16 +185,12 @@ public class ConfigManager { if (next != null && next.isObject()) { currentScope = next; } else { - return; + return null; } } - JsonNode element = currentScope.get(name); - - if (element != null) { - prop.loadFromJson(element); - } + return currentScope.get(name); } /** diff --git a/src/main/java/org/saturnclient/config/Theme.java b/src/main/java/org/saturnclient/config/Theme.java index a0b0eaf..d2269c2 100644 --- a/src/main/java/org/saturnclient/config/Theme.java +++ b/src/main/java/org/saturnclient/config/Theme.java @@ -81,6 +81,29 @@ public class Theme { config.property("Widget Radius", WIDGET_RADIUS, "Corner rounding of buttons and cards"); config.property("Font", FONT, "Font of every Saturn screen"); + + if (!parent.isSaved(Config.MENU_BLUR)) { + upgradeOpaqueColors(); + } + } + + /** + * Before 0.1.3 panels and cards were made translucent in code, and the + * background and primary colors were saved fully opaque. Saved colors that + * are an old default or preset get the translucency the colors now carry + * themselves; colors the player picked are left as they are. Runs only on + * configs from older versions, so a preset color later set opaque on + * purpose stays opaque. + */ + private static void upgradeOpaqueColors() { + for (Preset preset : PRESETS) { + if (BACKGROUND.value == (preset.background() | 0xFF000000)) { + BACKGROUND.value = preset.background(); + } + if (PRIMARY.value == (preset.primary() | 0xFF000000)) { + PRIMARY.value = preset.primary(); + } + } } /**