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 4993bb7019..dbb1338f53 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java @@ -192,6 +192,18 @@ public static void prepareDownloadPage() { } } + public static void resetPages() { + versionPage = null; + downloadPage = null; + settingsPage = null; + + rootPage.reset(); + terracottaPage.reset(); + accountListPage.reset(); + gameListPage.reset(); + getDecorator().setRoot(rootPage.get()); + } + // FXThread public static Node getTerracottaPage() { return terracottaPage.get(); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/Navigator.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/Navigator.java index 6d0f8f8010..f8ed08c195 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/Navigator.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/Navigator.java @@ -215,6 +215,10 @@ protected void invalidated() { } }; + public void setRoot(Node node) { + stack.set(0, node); + } + public static final class NavigationEvent extends Event { public static final EventType EXITED = new EventType<>("EXITED"); public static final EventType NAVIGATED = new EventType<>("NAVIGATED"); 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 64601aa68c..b5604f2c91 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 @@ -363,6 +363,10 @@ private Image loadDefaultBackgroundImage() { // ==== Navigation ==== + public void setRoot(Node node) { + navigator.setRoot(node); + } + public void navigate(Node node, AnimationProducer animationProducer, Duration duration, Interpolator interpolator) { navigator.navigate(node, animationProducer, duration, interpolator); } @@ -379,7 +383,7 @@ private void close() { navigator.clear(); } - private void back() { + public void back() { if (navigator.getCurrentPage() instanceof DecoratorPage) { DecoratorPage page = (DecoratorPage) navigator.getCurrentPage(); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/SettingsPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/SettingsPage.java index 4b9a5a405b..4e11f4fdce 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/SettingsPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/SettingsPage.java @@ -256,10 +256,8 @@ public SettingsPage() { VBox left = new VBox(); Label title = new Label(i18n("settings.launcher.language")); - title.getStyleClass().add("title"); - Label subtitle = new Label(i18n("settings.take_effect_after_restart")); - subtitle.getStyleClass().add("subtitle"); - left.getChildren().setAll(title, subtitle); + left.getChildren().setAll(title); + left.setAlignment(Pos.CENTER_LEFT); languagePane.setLeft(left); SupportedLocale currentLocale = I18n.getLocale(); @@ -274,6 +272,11 @@ else if (locale.isSameLanguage(currentLocale)) })); cboLanguage.getItems().setAll(SupportedLocale.getSupportedLocales()); selectedItemPropertyFor(cboLanguage).bindBidirectional(config().localizationProperty()); + selectedItemPropertyFor(cboLanguage).addListener((observable, oldValue, newValue) -> { + I18n.setLocale(newValue); + Controllers.resetPages(); + Controllers.getDecorator().back(); + }); FXUtils.setLimitWidth(cboLanguage, 300); languagePane.setRight(cboLanguage); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/util/Lazy.java b/HMCL/src/main/java/org/jackhuang/hmcl/util/Lazy.java index dacdea2d3a..a6bd427b81 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/util/Lazy.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/util/Lazy.java @@ -26,7 +26,7 @@ * @param value type */ public final class Lazy { - private Supplier supplier; + private final Supplier supplier; private T value = null; public Lazy(Supplier supplier) { @@ -34,10 +34,13 @@ public Lazy(Supplier supplier) { } public T get() { - if (supplier != null) { + if (value == null) { value = supplier.get(); - supplier = null; } return value; } + + public void reset() { + value = null; + } }