Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<NavigationEvent> EXITED = new EventType<>("EXITED");
public static final EventType<NavigationEvent> NAVIGATED = new EventType<>("NAVIGATED");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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();

Expand Down
11 changes: 7 additions & 4 deletions HMCL/src/main/java/org/jackhuang/hmcl/ui/main/SettingsPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down
9 changes: 6 additions & 3 deletions HMCL/src/main/java/org/jackhuang/hmcl/util/Lazy.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,21 @@
* @param <T> value type
*/
public final class Lazy<T> {
private Supplier<T> supplier;
private final Supplier<T> supplier;
private T value = null;

public Lazy(Supplier<T> supplier) {
this.supplier = Objects.requireNonNull(supplier);
}

public T get() {
if (supplier != null) {
if (value == null) {
value = supplier.get();
supplier = null;
}
return value;
}

public void reset() {
value = null;
}
}