From d75c3bbf96852129a07996c07cdf0219a27a30df Mon Sep 17 00:00:00 2001 From: yushijinhun Date: Sat, 26 Jan 2019 12:53:49 +0800 Subject: [PATCH] Refactor TwoLineListItem --- .../java/org/jackhuang/hmcl/ui/MainPage.java | 3 - .../org/jackhuang/hmcl/ui/SettingsView.java | 2 +- .../hmcl/ui/account/AddAccountPane.java | 1 + .../hmcl/ui/construct/FontComboBox.java | 14 +-- .../hmcl/ui/construct/TwoLineListItem.java | 96 +------------------ .../hmcl/ui/versions/VersionSettingsPage.java | 7 +- HMCL/src/main/resources/assets/css/root.css | 57 ++++------- .../resources/assets/lang/I18N.properties | 2 +- .../resources/assets/lang/I18N_zh.properties | 2 +- .../assets/lang/I18N_zh_CN.properties | 2 +- 10 files changed, 38 insertions(+), 148 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/MainPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/MainPage.java index 378e0db7c..6b6d65a54 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/MainPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/MainPage.java @@ -87,11 +87,8 @@ public final class MainPage extends StackPane implements DecoratorPage { lblIcon.setGraphic(SVG.update(Theme.whiteFillBinding(), 20, 20)); TwoLineListItem prompt = new TwoLineListItem(); - prompt.setTitleFill(Color.WHITE); - prompt.setSubtitleFill(Color.WHITE); prompt.setSubtitle(i18n("update.bubble.subtitle")); prompt.setPickOnBounds(false); - prompt.setStyle("-jfx-title-font-weight: BOLD;"); prompt.titleProperty().bind(latestVersionProperty()); hBox.getChildren().setAll(lblIcon, prompt); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsView.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsView.java index 566880966..07638486c 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsView.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsView.java @@ -359,7 +359,7 @@ public abstract class SettingsView extends StackPane { HBox hBox = new HBox(); hBox.setSpacing(3); - cboFont = new FontComboBox(12, false); + cboFont = new FontComboBox(12); txtFontSize = new JFXTextField(); FXUtils.setLimitWidth(txtFontSize, 50); hBox.getChildren().setAll(cboFont, txtFontSize); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AddAccountPane.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AddAccountPane.java index 0e117dc90..c35783ed6 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AddAccountPane.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AddAccountPane.java @@ -19,6 +19,7 @@ package org.jackhuang.hmcl.ui.account; import com.jfoenix.concurrency.JFXUtilities; import com.jfoenix.controls.*; + import javafx.beans.binding.Bindings; import javafx.beans.property.ReadOnlyObjectProperty; import javafx.fxml.FXML; diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/FontComboBox.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/FontComboBox.java index 81f2130de..abb1d10f3 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/FontComboBox.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/FontComboBox.java @@ -24,27 +24,27 @@ import static javafx.collections.FXCollections.singletonObservableList; import org.jackhuang.hmcl.util.javafx.MultiStepBinding; import com.jfoenix.controls.JFXComboBox; +import com.jfoenix.controls.JFXListCell; import javafx.beans.NamedArg; import javafx.beans.binding.Bindings; -import javafx.scene.control.ListCell; import javafx.scene.text.Font; public class FontComboBox extends JFXComboBox { private boolean loaded = false; - public FontComboBox(@NamedArg(value = "fontSize", defaultValue = "12.0") double fontSize, - @NamedArg(value = "enableStyle", defaultValue = "false") boolean enableStyle) { + public FontComboBox(@NamedArg(value = "fontSize", defaultValue = "12.0") double fontSize) { styleProperty().bind(Bindings.concat("-fx-font-family: \"", valueProperty(), "\"")); - setCellFactory(listView -> new ListCell() { + setCellFactory(listView -> new JFXListCell() { @Override - protected void updateItem(String item, boolean empty) { + public void updateItem(String item, boolean empty) { super.updateItem(item, empty); - if (item != null) { + if (!empty) { setText(item); - setFont(new Font(item, fontSize)); + setGraphic(null); + setStyle("-fx-font-family: \"" + item + "\""); } } }); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TwoLineListItem.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TwoLineListItem.java index 48d9f9b12..158576d92 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TwoLineListItem.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TwoLineListItem.java @@ -19,32 +19,15 @@ package org.jackhuang.hmcl.ui.construct; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; -import javafx.css.CssMetaData; -import javafx.css.SimpleStyleableObjectProperty; -import javafx.css.Styleable; -import javafx.css.StyleableObjectProperty; -import javafx.css.StyleablePropertyFactory; import javafx.scene.control.Label; -import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; -import javafx.scene.paint.Color; -import javafx.scene.paint.Paint; -import javafx.scene.text.Font; -import java.util.List; - -public class TwoLineListItem extends StackPane { +public class TwoLineListItem extends VBox { private static final String DEFAULT_STYLE_CLASS = "two-line-list-item"; private final StringProperty title = new SimpleStringProperty(this, "title"); private final StringProperty subtitle = new SimpleStringProperty(this, "subtitle"); - private final StyleableObjectProperty titleFont = new SimpleStyleableObjectProperty<>(StyleableProperties.TITLE_FONT, this, "title-font", Font.font(15)); - private final StyleableObjectProperty subtitleFont = new SimpleStyleableObjectProperty<>(StyleableProperties.SUBTITLE_FONT, this, "subtitle-font", Font.getDefault()); - - private final StyleableObjectProperty titleFill = new SimpleStyleableObjectProperty<>(StyleableProperties.TITLE_FILL, this, "title-fill", Color.BLACK); - private final StyleableObjectProperty subtitleFill = new SimpleStyleableObjectProperty<>(StyleableProperties.SUBTITLE_FILL, this, "subtitle-fill", Color.GRAY); - public TwoLineListItem(String titleString, String subtitleString) { this(); @@ -55,19 +38,14 @@ public class TwoLineListItem extends StackPane { public TwoLineListItem() { setMouseTransparent(true); Label lblTitle = new Label(); - lblTitle.textFillProperty().bind(titleFill); - lblTitle.fontProperty().bind(titleFont); + lblTitle.getStyleClass().add("title"); lblTitle.textProperty().bind(title); Label lblSubtitle = new Label(); - lblSubtitle.textFillProperty().bind(subtitleFill); - lblSubtitle.fontProperty().bind(subtitleFont); + lblSubtitle.getStyleClass().add("subtitle"); lblSubtitle.textProperty().bind(subtitle); - VBox vbox = new VBox(); - vbox.getChildren().setAll(lblTitle, lblSubtitle); - getChildren().setAll(vbox); - + getChildren().setAll(lblTitle, lblSubtitle); getStyleClass().add(DEFAULT_STYLE_CLASS); } @@ -95,74 +73,8 @@ public class TwoLineListItem extends StackPane { this.subtitle.set(subtitle); } - public Font getTitleFont() { - return titleFont.get(); - } - - public StyleableObjectProperty titleFontProperty() { - return titleFont; - } - - public void setTitleFont(Font titleFont) { - this.titleFont.set(titleFont); - } - - public Font getSubtitleFont() { - return subtitleFont.get(); - } - - public StyleableObjectProperty subtitleFontProperty() { - return subtitleFont; - } - - public void setSubtitleFont(Font subtitleFont) { - this.subtitleFont.set(subtitleFont); - } - - public Paint getTitleFill() { - return titleFill.get(); - } - - public StyleableObjectProperty titleFillProperty() { - return titleFill; - } - - public void setTitleFill(Paint titleFill) { - this.titleFill.set(titleFill); - } - - public Paint getSubtitleFill() { - return subtitleFill.get(); - } - - public StyleableObjectProperty subtitleFillProperty() { - return subtitleFill; - } - - public void setSubtitleFill(Paint subtitleFill) { - this.subtitleFill.set(subtitleFill); - } - @Override public String toString() { return getTitle(); } - - @Override - public List> getCssMetaData() { - return getClassCssMetaData(); - } - - public static List> getClassCssMetaData() { - return StyleableProperties.FACTORY.getCssMetaData(); - } - - private static class StyleableProperties { - private static final StyleablePropertyFactory FACTORY = new StyleablePropertyFactory<>(StackPane.getClassCssMetaData()); - - private static final CssMetaData TITLE_FONT = FACTORY.createFontCssMetaData("-jfx-title-font", s -> s.titleFont, Font.font(15)); - private static final CssMetaData SUBTITLE_FONT = FACTORY.createFontCssMetaData("-jfx-subtitle-font", s -> s.subtitleFont); - private static final CssMetaData TITLE_FILL = FACTORY.createPaintCssMetaData("-jfx-title-fill", s -> s.titleFill); - private static final CssMetaData SUBTITLE_FILL = FACTORY.createPaintCssMetaData("-jfx-subtitle-fill", s -> s.subtitleFill, Color.GREY); - } } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionSettingsPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionSettingsPage.java index a16ca63d4..b9b7f365d 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionSettingsPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionSettingsPage.java @@ -35,6 +35,7 @@ import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; import javafx.stage.FileChooser; import org.jackhuang.hmcl.setting.EnumGameDirectory; +import org.jackhuang.hmcl.setting.LauncherVisibility; import org.jackhuang.hmcl.setting.Profile; import org.jackhuang.hmcl.setting.Profiles; import org.jackhuang.hmcl.setting.VersionSetting; @@ -60,6 +61,7 @@ import java.util.List; import java.util.logging.Level; import java.util.stream.Collectors; +import static org.jackhuang.hmcl.ui.FXUtils.stringConverter; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; public final class VersionSettingsPage extends StackPane implements DecoratorPage { @@ -85,7 +87,7 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag @FXML private ComponentList advancedSettingsPane; @FXML private ComponentList componentList; @FXML private ComponentList iconPickerItemWrapper; - @FXML private JFXComboBox cboLauncherVisibility; + @FXML private JFXComboBox cboLauncherVisibility; @FXML private JFXCheckBox chkFullscreen; @FXML private Label lblPhysicalMemory; @FXML private JFXToggleButton chkNoJVMArgs; @@ -100,6 +102,9 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag public VersionSettingsPage() { FXUtils.loadFXML(this, "/assets/fxml/version/version-settings.fxml"); + + cboLauncherVisibility.getItems().setAll(LauncherVisibility.values()); + cboLauncherVisibility.setConverter(stringConverter(e -> i18n("settings.advanced.launcher_visibility." + e.name().toLowerCase()))); } @FXML diff --git a/HMCL/src/main/resources/assets/css/root.css b/HMCL/src/main/resources/assets/css/root.css index aef827b80..1e5b15ad2 100644 --- a/HMCL/src/main/resources/assets/css/root.css +++ b/HMCL/src/main/resources/assets/css/root.css @@ -104,20 +104,24 @@ -fx-padding: 4 0 4 0; } +.two-line-list-item > .title { + -fx-text-fill: black; + -fx-font-size: 15px; +} + +.two-line-list-item > .subtitle { + -fx-text-fill: gray; +} + .bubble { -fx-background-color: gray; -fx-background-radius: 2px; + -fx-text-fill: white; } -.bubble .two-line-list-item { - -jfx-title-fill: white; - -jfx-subtitle-fill: white; -} - -.two-line-list-item { - -jfx-title-font-size: 15px; - -jfx-title-fill: black; - -jfx-subtitle-fill: gray; +.bubble .two-line-list-item > .title, +.bubble .two-line-list-item > .subtitle { + -fx-text-fill: white; } .window-title-bar .separator { @@ -678,20 +682,12 @@ * * *******************************************************************************/ -.jfx-list-cell:odd, -.jfx-list-cell:even, -.list-cell:odd, -.list-cell:even { +.jfx-list-cell, .list-cell { -fx-background-color: WHITE; } -.list-cell:selected, .jfx-list-cell:selected { - -fx-background-insets: 0.0; - -fx-text-fill: BLACK; -} - -.jfx-list-cell:filled:hover, -.jfx-list-cell:selected .label { +.list-cell:selected, .jfx-list-cell:selected, +.list-cell:hover, .jfx-list-cell:hover { -fx-text-fill: black; } @@ -1109,31 +1105,10 @@ -fx-fill: #D34336; } -.combo-box-popup .list-view .jfx-list-cell .label, -.combo-box-popup .list-view .jfx-list-cell:filled:hover .label { - -fx-text-fill: BLACK; -} - -.combo-box-popup .list-view .jfx-list-cell .custom-jfx-list-view-icon, -.combo-box-popup .list-view .jfx-list-cell:filled:hover .custom-jfx-list-view-icon, -.combo-box-popup .list-view .jfx-list-cell:selected .custom-jfx-list-view-icon { - -fx-fill: -fx-base-color; -} - -.combo-box-popup .list-view .jfx-list-cell:odd:selected > .jfx-rippler > StackPane, -.combo-box-popup .list-view .jfx-list-cell:even:selected > .jfx-rippler > StackPane { - -fx-background-color: rgba(0.0, 0.0, 255.0, 0.2); -} - .combo-box-popup .list-view .jfx-list-cell { -fx-background-insets: 0.0; } -.combo-box-popup .list-view .jfx-list-cell:odd, -.combo-box-popup .list-view .jfx-list-cell:even { - -fx-background-color: WHITE; -} - .combo-box-popup .list-view .jfx-list-cell .jfx-rippler { -jfx-rippler-fill: -fx-base-color; } diff --git a/HMCL/src/main/resources/assets/lang/I18N.properties b/HMCL/src/main/resources/assets/lang/I18N.properties index 62997be15..5c2d448fe 100644 --- a/HMCL/src/main/resources/assets/lang/I18N.properties +++ b/HMCL/src/main/resources/assets/lang/I18N.properties @@ -307,7 +307,7 @@ settings.advanced.java_permanent_generation_space=PermGen Space/MB settings.advanced.jvm_args=Java VM Arguments settings.advanced.launcher_visibility.close=Close the launcher when the game launched. settings.advanced.launcher_visibility.hide=Hide the launcher when the game launched. -settings.advanced.launcher_visibility.hide_reopen=Hide the launcher and re-open when game closes. +settings.advanced.launcher_visibility.hide_and_reopen=Hide the launcher and re-open when game closes. settings.advanced.launcher_visibility.keep=Keep the launcher visible. settings.advanced.launcher_visible=Launcher Visibility settings.advanced.minecraft_arguments=Minecraft Arguments diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh.properties b/HMCL/src/main/resources/assets/lang/I18N_zh.properties index 48feef601..e448ffbb7 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh.properties @@ -306,7 +306,7 @@ settings.advanced.java_permanent_generation_space=記憶體永久儲存區域( settings.advanced.jvm_args=Java 虛擬機參數(不必填寫) settings.advanced.launcher_visibility.close=遊戲啟動後結束啟動器 settings.advanced.launcher_visibility.hide=遊戲啟動後隱藏啟動器 -settings.advanced.launcher_visibility.hide_reopen=隱藏啟動器並在遊戲結束後重新開啟 +settings.advanced.launcher_visibility.hide_and_reopen=隱藏啟動器並在遊戲結束後重新開啟 settings.advanced.launcher_visibility.keep=不隱藏啟動器 settings.advanced.launcher_visible=啟動器可見性 settings.advanced.minecraft_arguments=Minecraft 額外參數(不必填寫) diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties index c4ce1b21c..5c72e9066 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties @@ -306,7 +306,7 @@ settings.advanced.java_permanent_generation_space=内存永久保存区域(不 settings.advanced.jvm_args=Java 虚拟机参数(不必填写) settings.advanced.launcher_visibility.close=游戏启动后结束启动器 settings.advanced.launcher_visibility.hide=游戏启动后隐藏启动器 -settings.advanced.launcher_visibility.hide_reopen=隐藏启动器并在游戏结束后重新打开 +settings.advanced.launcher_visibility.hide_and_reopen=隐藏启动器并在游戏结束后重新打开 settings.advanced.launcher_visibility.keep=保持启动器可见 settings.advanced.launcher_visible=启动器可见性 settings.advanced.minecraft_arguments=Minecraft 额外参数(不必填写)