diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Theme.java b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Theme.java index 32f102b1a..db901e1bb 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Theme.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Theme.java @@ -79,9 +79,18 @@ public class Theme { return isLight() ? Color.BLACK : Color.WHITE; } - public String[] getStylesheets() { + public String[] getStylesheets(String overrideFontFamily) { Color textFill = getForegroundColor(); + String fontFamily; + if (System.getProperty("hmcl.font.override") != null) { + fontFamily = System.getProperty("hmcl.font.override"); + } else if (overrideFontFamily != null) { + fontFamily = overrideFontFamily; + } else { + fontFamily = null; + } + String css; try { File temp = File.createTempFile("hmcl", ".css"); @@ -93,7 +102,7 @@ public class Theme { .replace("%base-rippler-color%", String.format("rgba(%d, %d, %d, 0.3)", (int) Math.ceil(paint.getRed() * 256), (int) Math.ceil(paint.getGreen() * 256), (int) Math.ceil(paint.getBlue() * 256))) .replace("%disabled-font-color%", String.format("rgba(%d, %d, %d, 0.7)", (int) Math.ceil(textFill.getRed() * 256), (int) Math.ceil(textFill.getGreen() * 256), (int) Math.ceil(textFill.getBlue() * 256))) .replace("%font-color%", getColorDisplayName(getForegroundColor())) - .replace("%font%", Optional.ofNullable(System.getProperty("hmcl.font.override")).map(fontFamily -> "-fx-font-family: " + fontFamily + ";").orElse(""))); + .replace("%font%", Optional.ofNullable(fontFamily).map(f -> "-fx-font-family: \"" + f + "\";").orElse(""))); css = temp.toURI().toString(); } catch (IOException | NullPointerException e) { Logging.LOG.log(Level.SEVERE, "Unable to create theme stylesheet. Fallback to blue theme.", e); 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 eb7459fdf..60b8793a5 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java @@ -195,7 +195,7 @@ public final class Controllers { stage.setMinWidth(800 + 2 + 16); // bg width + border width*2 + shadow width*2 decorator.getDecorator().prefWidthProperty().bind(scene.widthProperty()); decorator.getDecorator().prefHeightProperty().bind(scene.heightProperty()); - scene.getStylesheets().setAll(config().getTheme().getStylesheets()); + scene.getStylesheets().setAll(config().getTheme().getStylesheets(config().getLauncherFontFamily())); stage.getIcons().add(newImage("/assets/img/icon.png")); stage.setTitle(Metadata.FULL_TITLE); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/GameCrashWindow.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/GameCrashWindow.java index 4014bee77..a049e2da6 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/GameCrashWindow.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/GameCrashWindow.java @@ -90,7 +90,7 @@ public class GameCrashWindow extends Stage { this.view = new View(); setScene(new Scene(view, 800, 480)); - getScene().getStylesheets().addAll(config().getTheme().getStylesheets()); + getScene().getStylesheets().addAll(config().getTheme().getStylesheets(config().getLauncherFontFamily())); setTitle(i18n("game.crash.title")); getIcons().add(newImage("/assets/img/icon.png")); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/LogWindow.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/LogWindow.java index 74da97ed4..acc205a2b 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/LogWindow.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/LogWindow.java @@ -91,7 +91,7 @@ public final class LogWindow extends Stage { public LogWindow() { setScene(new Scene(impl, 800, 480)); - getScene().getStylesheets().addAll(config().getTheme().getStylesheets()); + getScene().getStylesheets().addAll(config().getTheme().getStylesheets(config().getLauncherFontFamily())); setTitle(i18n("logwindow.title")); getIcons().add(newImage("/assets/img/icon.png")); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/SVG.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/SVG.java index 04649a8ce..27811e708 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/SVG.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/SVG.java @@ -486,4 +486,10 @@ public final class SVG { "M7,10L12,15L17,10H7Z", fill, width, height); } + + public static Node restore(ObjectBinding fill, double width, double height) { + return createSVGPath( + "M13,3A9,9 0 0,0 4,12H1L4.89,15.89L4.96,16.03L9,12H6A7,7 0 0,1 13,5A7,7 0 0,1 20,12A7,7 0 0,1 13,19C11.07,19 9.32,18.21 8.06,16.94L6.64,18.36C8.27,20 10.5,21 13,21A9,9 0 0,0 22,12A9,9 0 0,0 13,3Z", + fill, width, height); + } } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/WebStage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/WebStage.java index 0cc1f386b..0e7207626 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/WebStage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/WebStage.java @@ -42,7 +42,7 @@ public class WebStage extends Stage { public WebStage(int width, int height) { setScene(new Scene(pane, width, height)); - getScene().getStylesheets().addAll(config().getTheme().getStylesheets()); + getScene().getStylesheets().addAll(config().getTheme().getStylesheets(config().getLauncherFontFamily())); getIcons().add(newImage("/assets/img/icon.png")); webView.getEngine().setUserDataDirectory(Metadata.HMCL_DIRECTORY.toFile()); webView.setContextMenuEnabled(false); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/PersonalizationPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/PersonalizationPage.java index d89d6c21d..6d597bff8 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/PersonalizationPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/PersonalizationPage.java @@ -17,6 +17,7 @@ */ package org.jackhuang.hmcl.ui.main; +import com.jfoenix.controls.JFXButton; import com.jfoenix.controls.JFXScrollPane; import com.jfoenix.controls.JFXTextField; import com.jfoenix.effects.JFXDepthManager; @@ -38,6 +39,7 @@ import org.jackhuang.hmcl.setting.EnumBackgroundImage; import org.jackhuang.hmcl.setting.Theme; import org.jackhuang.hmcl.ui.Controllers; import org.jackhuang.hmcl.ui.FXUtils; +import org.jackhuang.hmcl.ui.SVG; import org.jackhuang.hmcl.ui.construct.*; import org.jackhuang.hmcl.util.javafx.SafeStringConverter; @@ -75,7 +77,7 @@ public class PersonalizationPage extends StackPane { picker.setOnAction(e -> { Theme theme = Theme.custom(Theme.getColorDisplayName(picker.getValue())); config().setTheme(theme); - Controllers.getScene().getStylesheets().setAll(theme.getStylesheets()); + Controllers.getScene().getStylesheets().setAll(theme.getStylesheets(config().getLauncherFontFamily())); }); themeColorPickerContainer.getChildren().setAll(picker); Platform.runLater(() -> JFXDepthManager.setDepth(picker, 0)); @@ -180,12 +182,17 @@ public class PersonalizationPage extends StackPane { { HBox hBox = new HBox(); - hBox.setSpacing(3); + hBox.setSpacing(8); FontComboBox cboFont = new FontComboBox(12); cboFont.valueProperty().bindBidirectional(config().launcherFontFamilyProperty()); - hBox.getChildren().setAll(cboFont); + JFXButton clearButton = new JFXButton(); + clearButton.getStyleClass().add("toggle-icon4"); + clearButton.setGraphic(SVG.restore(Theme.blackFillBinding(), -1, -1)); + clearButton.setOnAction(e -> config().setLauncherFontFamily(null)); + + hBox.getChildren().setAll(cboFont, clearButton); borderPane.setRight(hBox); } @@ -195,6 +202,9 @@ public class PersonalizationPage extends StackPane { lblFontDisplay.fontProperty().bind(Bindings.createObjectBinding( () -> Font.font(config().getLauncherFontFamily(), 12), config().launcherFontFamilyProperty())); + config().launcherFontFamilyProperty().addListener((a, b, newValue) -> { + Controllers.getScene().getStylesheets().setAll(config().getTheme().getStylesheets(newValue)); + }); vbox.getChildren().add(lblFontDisplay);