diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsPage.java index be56e0d43..83df018f3 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsPage.java @@ -20,6 +20,7 @@ package org.jackhuang.hmcl.ui; import com.jfoenix.controls.*; import com.jfoenix.effects.JFXDepthManager; import javafx.application.Platform; +import javafx.beans.binding.When; import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleStringProperty; @@ -46,7 +47,6 @@ import org.jackhuang.hmcl.util.Lang; import org.jackhuang.hmcl.util.i18n.Locales; import static org.jackhuang.hmcl.setting.ConfigHolder.CONFIG; -import static org.jackhuang.hmcl.ui.FXUtils.onInvalidating; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; import java.net.Proxy; @@ -194,9 +194,10 @@ public final class SettingsPage extends StackPane implements DecoratorPage { backgroundItem.setCustomUserData(EnumBackgroundImage.CUSTOM); backgroundItem.getGroup().getToggles().stream().filter(it -> it.getUserData() == CONFIG.getBackgroundImageType()).findFirst().ifPresent(it -> it.setSelected(true)); - CONFIG.backgroundImageProperty().addListener(onInvalidating(this::initBackgroundItemSubtitle)); - CONFIG.backgroundImageTypeProperty().addListener(onInvalidating(this::initBackgroundItemSubtitle)); - initBackgroundItemSubtitle(); + backgroundItem.subtitleProperty().bind( + new When(CONFIG.backgroundImageTypeProperty().isEqualTo(EnumBackgroundImage.DEFAULT)) + .then(i18n("launcher.background.default")) + .otherwise(CONFIG.backgroundImageProperty())); backgroundItem.setToggleSelectedListener(newValue -> CONFIG.setBackgroundImageType((EnumBackgroundImage) newValue.getUserData())); @@ -215,17 +216,6 @@ public final class SettingsPage extends StackPane implements DecoratorPage { Platform.runLater(() -> JFXDepthManager.setDepth(picker, 0)); } - private void initBackgroundItemSubtitle() { - switch (CONFIG.getBackgroundImageType()) { - case DEFAULT: - backgroundItem.setSubtitle(i18n("launcher.background.default")); - break; - case CUSTOM: - backgroundItem.setSubtitle(CONFIG.getBackgroundImage()); - break; - } - } - public String getTitle() { return title.get(); }