From a1d9b52b9dcbde6a045402c10b8b0f7e26b3df40 Mon Sep 17 00:00:00 2001 From: yushijinhun Date: Sat, 27 Oct 2018 19:10:02 +0800 Subject: [PATCH] Refactor uiVersion --- .../org/jackhuang/hmcl/setting/Config.java | 9 ++++++++ .../jackhuang/hmcl/setting/ConfigHolder.java | 7 ------- .../org/jackhuang/hmcl/ui/Controllers.java | 1 - .../ui/decorator/DecoratorController.java | 21 +++++++++++++++---- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java index 19598fb6c..b1a2b8588 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java @@ -50,6 +50,8 @@ import java.util.stream.Stream; public final class Config implements Cloneable, Observable { + public static final int CURRENT_UI_VERSION = 0; + private static final Gson CONFIG_GSON = new GsonBuilder() .registerTypeAdapter(VersionSetting.class, VersionSetting.Serializer.INSTANCE) .registerTypeAdapter(Profile.class, Profile.Serializer.INSTANCE) @@ -145,6 +147,13 @@ public final class Config implements Cloneable, Observable { @SerializedName("_version") private IntegerProperty configVersion = new SimpleIntegerProperty(0); + /** + * The version of UI that the user have last used. + * If there is a major change in UI, {@link Config#CURRENT_UI_VERSION} should be increased. + * When {@link #CURRENT_UI_VERSION} is higher than the property, the user guide should be shown, + * then this property is set to the same value as {@link #CURRENT_UI_VERSION}. + * In particular, the property is default to 0, so that whoever open the application for the first time will see the guide. + */ @SerializedName("uiVersion") private IntegerProperty uiVersion = new SimpleIntegerProperty(0); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/setting/ConfigHolder.java b/HMCL/src/main/java/org/jackhuang/hmcl/setting/ConfigHolder.java index 92c3e164c..52ed04f1f 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/setting/ConfigHolder.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/setting/ConfigHolder.java @@ -52,13 +52,6 @@ public final class ConfigHolder { return configInstance; } - public static boolean isNewlyCreated() { - if (configInstance == null) { - throw new IllegalStateException("Configuration hasn't been loaded"); - } - return newlyCreated; - } - public synchronized static void init() throws IOException { if (configInstance != null) { throw new IllegalStateException("Configuration is already loaded"); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java index d6c96a637..aa500f36b 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java @@ -60,7 +60,6 @@ import static org.jackhuang.hmcl.setting.ConfigHolder.config; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; public final class Controllers { - public static final int UI_VERSION = 1; private static Scene scene; private static Stage stage; diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorController.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorController.java index b4ae5c6e8..de287459a 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorController.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorController.java @@ -40,7 +40,7 @@ import javafx.util.Duration; import org.jackhuang.hmcl.Launcher; import org.jackhuang.hmcl.Metadata; import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorDnD; -import org.jackhuang.hmcl.setting.ConfigHolder; +import org.jackhuang.hmcl.setting.Config; import org.jackhuang.hmcl.setting.EnumBackgroundImage; import org.jackhuang.hmcl.task.TaskExecutor; import org.jackhuang.hmcl.ui.Controllers; @@ -108,9 +108,11 @@ public class DecoratorController { nowAnimation.play(); }); - if (ConfigHolder.config().getUiVersion() < Controllers.UI_VERSION && config().getLocalization().getLocale() == Locale.CHINA) { - ConfigHolder.config().setUiVersion(Controllers.UI_VERSION); - decorator.getContainer().setAll(welcomeView); + if (switchedToNewUI()) { + if (config().getLocalization().getLocale() == Locale.CHINA) { + // currently, user guide is only available in Chinese + decorator.getContainer().setAll(welcomeView); + } } setupBackground(); @@ -122,6 +124,17 @@ public class DecoratorController { return decorator; } + /** + * @return true if the user is seeing the current version of UI for the first time. + */ + private boolean switchedToNewUI() { + if (config().getUiVersion() < Config.CURRENT_UI_VERSION) { + config().setUiVersion(Config.CURRENT_UI_VERSION); + return true; + } + return false; + } + // ==== Background ==== private void setupBackground() {