From 602114af55cb24887e875d39c3423063e8bb42a6 Mon Sep 17 00:00:00 2001 From: huanghongxun Date: Tue, 20 Feb 2018 10:48:59 +0800 Subject: [PATCH] UI maintainence --- .../jackhuang/hmcl/game/LauncherHelper.java | 2 +- .../org/jackhuang/hmcl/ui/AccountsPage.java | 4 +- .../jackhuang/hmcl/ui/LeftPaneController.java | 6 +- .../java/org/jackhuang/hmcl/ui/ModItem.java | 15 +- .../jackhuang/hmcl/ui/TwoLineListItem.java | 186 ++++++++++++++++-- .../main/resources/assets/fxml/account.fxml | 9 +- 6 files changed, 190 insertions(+), 32 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java b/HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java index eb53305a2..ee70e5fea 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java @@ -249,7 +249,7 @@ public final class LauncherHelper { } } - class LaunchTask extends TaskResult { + private static class LaunchTask extends TaskResult { private final ExceptionalSupplier supplier; public LaunchTask(ExceptionalSupplier supplier) { diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/AccountsPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/AccountsPage.java index 59a3be412..4b15c0d7a 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/AccountsPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/AccountsPage.java @@ -65,6 +65,7 @@ public final class AccountsPage extends StackPane implements DecoratorPage { @FXML private JFXTextField txtUsername; @FXML private JFXPasswordField txtPassword; @FXML private Label lblCreationWarning; + @FXML private Label lblPassword; @FXML private JFXComboBox cboType; @FXML private JFXComboBox cboServers; @FXML private JFXProgressBar progressBar; @@ -82,6 +83,7 @@ public final class AccountsPage extends StackPane implements DecoratorPage { cboType.getItems().setAll(Main.i18n("account.methods.offline"), Main.i18n("account.methods.yggdrasil"), Main.i18n("account.methods.authlib_injector")); cboType.getSelectionModel().selectedIndexProperty().addListener((a, b, newValue) -> { txtPassword.setVisible(newValue.intValue() != 0); + lblPassword.setVisible(newValue.intValue() != 0); cboServers.setVisible(newValue.intValue() == 2); linkAddInjectorServer.setVisible(newValue.intValue() == 2); lblAddInjectorServer.setVisible(newValue.intValue() == 2); @@ -238,7 +240,7 @@ public final class AccountsPage extends StackPane implements DecoratorPage { else throw new Error(Main.i18n("account.methods.no_method") + ": " + account); } - class CharacterSelector extends BorderPane implements MultiCharacterSelector { + private static class CharacterSelector extends BorderPane implements MultiCharacterSelector { private AdvancedListBox listBox = new AdvancedListBox(); private JFXButton cancel = new JFXButton(); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/LeftPaneController.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/LeftPaneController.java index f4f48ab01..43b9bd235 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/LeftPaneController.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/LeftPaneController.java @@ -110,8 +110,8 @@ public final class LeftPaneController { Platform.runLater(() -> { for (Node node : profilePane.getChildren()) { - if (node instanceof RipplerContainer && node.getProperties().get("profile") instanceof Pair) { - boolean current = Objects.equals(((Pair) node.getProperties().get("profile")).getKey(), profile.getName()); + if (node instanceof RipplerContainer && node.getProperties().get("profile") instanceof String) { + boolean current = Objects.equals(node.getProperties().get("profile"), profile.getName()); ((RipplerContainer) node).setSelected(current); ((VersionListItem) ((RipplerContainer) node).getContainer()).setGameVersion(current ? Main.i18n("profile.selected") : ""); } @@ -126,7 +126,7 @@ public final class LeftPaneController { RipplerContainer ripplerContainer = new RipplerContainer(item); item.setOnSettingsButtonClicked(() -> Controllers.getDecorator().showPage(new ProfilePage(profile))); ripplerContainer.setOnMouseClicked(e -> Settings.INSTANCE.setSelectedProfile(profile)); - ripplerContainer.getProperties().put("profile", new Pair<>(profile.getName(), item)); + ripplerContainer.getProperties().put("profile", profile.getName()); ripplerContainer.maxWidthProperty().bind(leftPane.widthProperty()); list.add(ripplerContainer); } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/ModItem.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/ModItem.java index 730a4e2e7..4f9d0a7c9 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/ModItem.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/ModItem.java @@ -30,20 +30,15 @@ import org.jackhuang.hmcl.mod.ModInfo; import java.util.function.Consumer; public final class ModItem extends BorderPane { - private final Label lblModFileName = new Label(); - private final Label lblModAuthor = new Label(); + private final TwoLineListItem modItem = new TwoLineListItem(); private final JFXCheckBox chkEnabled = new JFXCheckBox(); public ModItem(ModInfo info, Consumer deleteCallback) { - lblModFileName.setStyle("-fx-font-size: 15;"); - lblModAuthor.setStyle("-fx-font-size: 10;"); BorderPane.setAlignment(chkEnabled, Pos.CENTER); setLeft(chkEnabled); - VBox center = new VBox(); - BorderPane.setAlignment(center, Pos.CENTER); - center.getChildren().addAll(lblModFileName, lblModAuthor); - setCenter(center); + BorderPane.setAlignment(modItem, Pos.CENTER); + setCenter(modItem); JFXButton right = new JFXButton(); right.setOnMouseClicked(e -> deleteCallback.accept(this)); @@ -54,8 +49,8 @@ public final class ModItem extends BorderPane { setStyle("-fx-background-radius: 2; -fx-background-color: white; -fx-padding: 8;"); JFXDepthManager.setDepth(this, 1); - lblModFileName.setText(info.getFileName()); - lblModAuthor.setText(info.getName() + ", " + Main.i18n("archive.version") + ": " + info.getVersion() + ", " + Main.i18n("archive.game_version") + ": " + info.getGameVersion() + ", " + Main.i18n("archive.author") + ": " + info.getAuthors()); + modItem.setTitle(info.getFileName()); + modItem.setSubtitle(info.getName() + ", " + Main.i18n("archive.version") + ": " + info.getVersion() + ", " + Main.i18n("archive.game_version") + ": " + info.getGameVersion() + ", " + Main.i18n("archive.author") + ": " + info.getAuthors()); chkEnabled.setSelected(info.isActive()); chkEnabled.selectedProperty().addListener((a, b, newValue) -> { info.activeProperty().set(newValue); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/TwoLineListItem.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/TwoLineListItem.java index 576d5a837..6794e8d6c 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/TwoLineListItem.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/TwoLineListItem.java @@ -1,29 +1,49 @@ package org.jackhuang.hmcl.ui; +import javafx.beans.property.*; +import javafx.css.*; +import javafx.scene.Node; 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 org.jackhuang.hmcl.ui.construct.RipplerContainer; import org.jackhuang.hmcl.util.Pair; -public class TwoLineListItem extends StackPane { - private final Label lblTitle = new Label(); - private final Label lblSubtitle = new Label(); - private final String title; - private final String subtitle; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; - public TwoLineListItem(Pair pair) { - this(pair.getKey(), pair.getValue()); +public class TwoLineListItem extends StackPane { + + 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(); + + title.set(titleString); + subtitle.set(subtitleString); } - public TwoLineListItem(String title, String subtitle) { - lblTitle.setStyle("-fx-font-size: 15;"); - lblSubtitle.setStyle("-fx-font-size: 10; -fx-text-fill: gray;"); + public TwoLineListItem() { + Label lblTitle = new Label(); + lblTitle.textFillProperty().bind(titleFill); + lblTitle.fontProperty().bind(titleFont); + lblTitle.textProperty().bind(title); - this.title = title; - this.subtitle = subtitle; - - lblTitle.setText(title); - lblSubtitle.setText(subtitle); + Label lblSubtitle = new Label(); + lblSubtitle.textFillProperty().bind(subtitleFill); + lblSubtitle.fontProperty().bind(subtitleFont); + lblSubtitle.textProperty().bind(subtitle); VBox vbox = new VBox(); vbox.getChildren().setAll(lblTitle, lblSubtitle); @@ -31,15 +51,151 @@ public class TwoLineListItem extends StackPane { } public String getTitle() { + return title.get(); + } + + public StringProperty titleProperty() { return title; } + public void setTitle(String title) { + this.title.set(title); + } + public String getSubtitle() { + return subtitle.get(); + } + + public StringProperty subtitleProperty() { return subtitle; } + public void setSubtitle(String subtitle) { + 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.STYLEABLES; + } + + private static class StyleableProperties { + + private static final FontCssMetaData TITLE_FONT = new FontCssMetaData("-jfx-title-font", Font.font(15)) { + @Override + public boolean isSettable(TwoLineListItem control) { + return control.title == null || !control.title.isBound(); + } + + @Override + public StyleableProperty getStyleableProperty(TwoLineListItem control) { + return control.titleFontProperty(); + } + }; + + private static final FontCssMetaData SUBTITLE_FONT = new FontCssMetaData("-jfx-subtitle-font", Font.getDefault()) { + @Override + public boolean isSettable(TwoLineListItem control) { + return control.subtitle == null || !control.subtitle.isBound(); + } + + @Override + public StyleableProperty getStyleableProperty(TwoLineListItem control) { + return control.subtitleFontProperty(); + } + }; + + private static final CssMetaData TITLE_FILL = new CssMetaData("-jfx-title-fill", StyleConverter.getPaintConverter(), Color.BLACK) { + @Override + public boolean isSettable(TwoLineListItem control) { + return control.titleFill == null || !control.titleFill.isBound(); + } + + @Override + public StyleableProperty getStyleableProperty(TwoLineListItem control) { + return control.titleFillProperty(); + } + }; + + private static final CssMetaData SUBTITLE_FILL = new CssMetaData("-jfx-subtitle-fill", StyleConverter.getPaintConverter(), Color.GRAY) { + @Override + public boolean isSettable(TwoLineListItem control) { + return control.subtitleFill == null || !control.subtitleFill.isBound(); + } + + @Override + public StyleableProperty getStyleableProperty(TwoLineListItem control) { + return control.subtitleFillProperty(); + } + }; + + private static final List> STYLEABLES; + + private StyleableProperties() { + } + + static { + List> styleables = new ArrayList<>(Node.getClassCssMetaData()); + Collections.addAll(styleables, TITLE_FONT); + Collections.addAll(styleables, SUBTITLE_FONT); + STYLEABLES = Collections.unmodifiableList(styleables); + } + } } diff --git a/HMCL/src/main/resources/assets/fxml/account.fxml b/HMCL/src/main/resources/assets/fxml/account.fxml index 4a3273708..75fc2add3 100644 --- a/HMCL/src/main/resources/assets/fxml/account.fxml +++ b/HMCL/src/main/resources/assets/fxml/account.fxml @@ -44,13 +44,18 @@ - +