From 5ab93e02fbae60237e021d7a10def24b34b7cef2 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Thu, 22 Aug 2024 16:14:14 +0700 Subject: [PATCH] [REFACTOR] Disabled settings checkboxes --- .../scenes/settings/BaseSettingsScene.java | 24 ++++++++----------- .../scenes/settings/GlobalSettingsScene.java | 4 ++-- .../gui/scenes/settings/SettingsScene.java | 16 +++++-------- 3 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/main/java/pro/gravit/launcher/gui/scenes/settings/BaseSettingsScene.java b/src/main/java/pro/gravit/launcher/gui/scenes/settings/BaseSettingsScene.java index abca470a..47ea8ab8 100644 --- a/src/main/java/pro/gravit/launcher/gui/scenes/settings/BaseSettingsScene.java +++ b/src/main/java/pro/gravit/launcher/gui/scenes/settings/BaseSettingsScene.java @@ -34,22 +34,18 @@ public void reset() { settingsList.getChildren().add(settingsListHeader); } - public void add(String languageName, boolean value, Consumer onChanged) { + public void add(String languageName, boolean value, Consumer onChanged, boolean disabled) { String nameKey = "runtime.scenes.settings.properties.%s.name".formatted(languageName.toLowerCase()); - String descriptionKey = "runtime.scenes.settings.properties.%s.description".formatted( - languageName.toLowerCase()); - add(application.getTranslation(nameKey, languageName), application.getTranslation(descriptionKey, languageName), - value, onChanged); - } - public void addDisabled(String languageName, String transferredTo, boolean value) { - String nameKey = "runtime.scenes.settings.properties.%s.name".formatted(languageName.toLowerCase()); - String descriptionKey = "runtime.scenes.settings.properties.%s.disabled".formatted( - transferredTo.toLowerCase()); + String descriptionKey; + if(disabled) { + descriptionKey = "runtime.scenes.settings.properties.%s.disabled".formatted( + languageName.toLowerCase()); + } else { + descriptionKey = "runtime.scenes.settings.properties.%s.description".formatted( + languageName.toLowerCase()); + } add(application.getTranslation(nameKey, languageName), application.getTranslation(descriptionKey, languageName), - value, unused -> {}, true); - } - public void add(String name, String description, boolean value, Consumer onChanged) { - add(name, description, value, onChanged, false); + value, onChanged, disabled); } public void add(String name, String description, boolean value, Consumer onChanged, boolean disabled) { diff --git a/src/main/java/pro/gravit/launcher/gui/scenes/settings/GlobalSettingsScene.java b/src/main/java/pro/gravit/launcher/gui/scenes/settings/GlobalSettingsScene.java index 07dbefa0..41b4f809 100644 --- a/src/main/java/pro/gravit/launcher/gui/scenes/settings/GlobalSettingsScene.java +++ b/src/main/java/pro/gravit/launcher/gui/scenes/settings/GlobalSettingsScene.java @@ -106,7 +106,7 @@ protected void doInit() { public void reset() { super.reset(); RuntimeSettings.GlobalSettings settings = application.runtimeSettings.globalSettings; - add("PrismVSync", settings.prismVSync, (value) -> settings.prismVSync = value); - add("DebugAllClients", settings.debugAllClients, (value) -> settings.debugAllClients = value); + add("PrismVSync", settings.prismVSync, (value) -> settings.prismVSync = value, false); + add("DebugAllClients", settings.debugAllClients, (value) -> settings.debugAllClients = value, false); } } diff --git a/src/main/java/pro/gravit/launcher/gui/scenes/settings/SettingsScene.java b/src/main/java/pro/gravit/launcher/gui/scenes/settings/SettingsScene.java index b3903495..fed33dcf 100644 --- a/src/main/java/pro/gravit/launcher/gui/scenes/settings/SettingsScene.java +++ b/src/main/java/pro/gravit/launcher/gui/scenes/settings/SettingsScene.java @@ -114,21 +114,17 @@ public void reset() { } }); serverButton.enableResetButton(null, (e) -> reset()); - if (!application.runtimeSettings.globalSettings.debugAllClients) { - add("Debug", profileSettings.debug, (value) -> profileSettings.debug = value); - } else { - addDisabled("Debug", application.gui.globalSettingsScene.getName(), profileSettings.debug); - } - add("AutoEnter", profileSettings.autoEnter, (value) -> profileSettings.autoEnter = value); - add("Fullscreen", profileSettings.fullScreen, (value) -> profileSettings.fullScreen = value); + add("Debug", profileSettings.debug, (value) -> profileSettings.debug = value, application.runtimeSettings.globalSettings.debugAllClients); + add("AutoEnter", profileSettings.autoEnter, (value) -> profileSettings.autoEnter = value, false); + add("Fullscreen", profileSettings.fullScreen, (value) -> profileSettings.fullScreen = value, false); if(JVMHelper.OS_TYPE == JVMHelper.OS.LINUX) { - add("WaylandSupport", profileSettings.waylandSupport, (value) -> profileSettings.waylandSupport = value); + add("WaylandSupport", profileSettings.waylandSupport, (value) -> profileSettings.waylandSupport = value, false); } if(application.authService.checkDebugPermission("skipupdate")) { - add("DebugSkipUpdate", profileSettings.debugSkipUpdate, (value) -> profileSettings.debugSkipUpdate = value); + add("DebugSkipUpdate", profileSettings.debugSkipUpdate, (value) -> profileSettings.debugSkipUpdate = value, false); } if(application.authService.checkDebugPermission("skipfilemonitor")) { - add("DebugSkipFileMonitor", profileSettings.debugSkipFileMonitor, (value) -> profileSettings.debugSkipFileMonitor = value); + add("DebugSkipFileMonitor", profileSettings.debugSkipFileMonitor, (value) -> profileSettings.debugSkipFileMonitor = value, false); } userBlock.reset(); }