From f826eb224cb8850af5e378a585b3135b5d671923 Mon Sep 17 00:00:00 2001 From: huangyuhui Date: Fri, 2 Mar 2018 10:41:25 +0800 Subject: [PATCH] AccountPage maintainence --- .../org/jackhuang/hmcl/ui/AccountPage.java | 30 ++++- .../jackhuang/hmcl/ui/LeftPaneController.java | 34 ++--- .../jackhuang/hmcl/ui/VersionListItem.java | 14 +- .../resources/assets/fxml/account-item.fxml | 51 ------- .../main/resources/assets/fxml/account.fxml | 126 +++++++++--------- .../assets/fxml/version-list-item.fxml | 2 +- 6 files changed, 100 insertions(+), 157 deletions(-) delete mode 100644 HMCL/src/main/resources/assets/fxml/account-item.fxml diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/AccountPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/AccountPage.java index 2738bdc95..8515f563e 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/AccountPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/AccountPage.java @@ -32,6 +32,7 @@ import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilAccount; import org.jackhuang.hmcl.game.AccountHelper; import org.jackhuang.hmcl.setting.Accounts; import org.jackhuang.hmcl.setting.Settings; +import org.jackhuang.hmcl.setting.Theme; import org.jackhuang.hmcl.task.Schedulers; import org.jackhuang.hmcl.task.Task; import org.jackhuang.hmcl.ui.construct.ComponentList; @@ -53,8 +54,12 @@ public class AccountPage extends StackPane implements DecoratorPage { @FXML private BorderPane paneServer; @FXML + private BorderPane paneEmail; + @FXML private ComponentList componentList; @FXML + private JFXButton btnDelete; + @FXML private JFXButton btnRefresh; public AccountPage(Account account) { @@ -63,24 +68,29 @@ public class AccountPage extends StackPane implements DecoratorPage { FXUtils.loadFXML(this, "/assets/fxml/account.fxml"); + FXUtils.setLimitWidth(this, 300); if (account instanceof AuthlibInjectorAccount) { Accounts.getAuthlibInjectorServerNameAsync((AuthlibInjectorAccount) account) .subscribe(Schedulers.javafx(), variables -> lblServer.setText(variables.get("serverName"))); + FXUtils.setLimitHeight(this, 182); } else { componentList.removeChildren(paneServer); + + if (account instanceof OfflineAccount) { + componentList.removeChildren(paneEmail); + FXUtils.setLimitHeight(this, 110); + } else + FXUtils.setLimitHeight(this, 145); } + btnDelete.setGraphic(SVG.delete(Theme.blackFillBinding(), 15, 15)); + btnRefresh.setGraphic(SVG.refresh(Theme.blackFillBinding(), 15, 15)); + lblCharacter.setText(account.getCharacter()); lblType.setText(AddAccountPane.accountType(account)); lblEmail.setText(account.getUsername()); - btnRefresh.setDisable(account instanceof OfflineAccount); - - if (account instanceof YggdrasilAccount) { - btnRefresh.setOnMouseClicked(e -> { - AccountHelper.refreshSkinAsync((YggdrasilAccount) account).start(); - }); - } + btnRefresh.setVisible(account instanceof YggdrasilAccount); } @FXML @@ -89,6 +99,12 @@ public class AccountPage extends StackPane implements DecoratorPage { Controllers.navigate(null); } + @FXML + private void onRefresh() { + if (account instanceof YggdrasilAccount) + AccountHelper.refreshSkinAsync((YggdrasilAccount) account).start(); + } + public String getTitle() { return title.get(); } 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 a83019242..2ca95b0bf 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/LeftPaneController.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/LeftPaneController.java @@ -19,7 +19,6 @@ package org.jackhuang.hmcl.ui; import com.jfoenix.concurrency.JFXUtilities; import com.jfoenix.controls.JFXButton; -import com.jfoenix.controls.JFXListView; import com.jfoenix.controls.JFXPopup; import javafx.application.Platform; import javafx.scene.Node; @@ -127,7 +126,7 @@ public final class LeftPaneController { for (Profile profile : Settings.INSTANCE.getProfiles()) { VersionListItem item = new VersionListItem(Profiles.getProfileDisplayName(profile)); RipplerContainer ripplerContainer = new RipplerContainer(item); - item.setOnSettingsButtonClicked(() -> Controllers.getDecorator().showPage(new ProfilePage(profile))); + item.setOnSettingsButtonClicked(e -> Controllers.getDecorator().showPage(new ProfilePage(profile))); ripplerContainer.setOnMouseClicked(e -> Settings.INSTANCE.setSelectedProfile(profile)); ripplerContainer.getProperties().put("profile", profile.getName()); ripplerContainer.maxWidthProperty().bind(leftPane.widthProperty()); @@ -148,32 +147,14 @@ public final class LeftPaneController { for (Account account : Settings.INSTANCE.getAccounts()) { VersionListItem item = new VersionListItem(account.getCharacter(), accountType(account)); RipplerContainer ripplerContainer = new RipplerContainer(item); - item.setOnSettingsButtonClicked(() -> Controllers.getDecorator().showPage(new AccountPage(account))); + item.setOnSettingsButtonClicked(e -> { + AccountPage accountPage = new AccountPage(account); + JFXPopup popup = new JFXPopup(accountPage); + popup.show((Node) e.getSource(), JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, e.getX(), e.getY()); + }); ripplerContainer.setOnMouseClicked(e -> { if (e.getButton() == MouseButton.PRIMARY) Settings.INSTANCE.setSelectedAccount(account); - else if (e.getButton() == MouseButton.SECONDARY) { - JFXListView listView = new JFXListView<>(); - JFXPopup popup = new JFXPopup(listView); - listView.getStyleClass().add("option-list-view"); - listView.getItems().add(Launcher.i18n("button.delete")); - if (account instanceof YggdrasilAccount) - listView.getItems().add(Launcher.i18n("button.refresh")); - listView.setOnMouseClicked(e2 ->{ - popup.hide(); - switch (listView.getSelectionModel().getSelectedIndex()) { - case 0: - Settings.INSTANCE.deleteAccount(account); - break; - case 1: - if (account instanceof YggdrasilAccount) - AccountHelper.refreshSkinAsync((YggdrasilAccount) account).start(); - break; - default: - throw new Error(); - }}); - popup.show(item, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, e.getX(), e.getY()); - } }); ripplerContainer.getProperties().put("account", account); ripplerContainer.maxWidthProperty().bind(leftPane.widthProperty()); @@ -196,7 +177,8 @@ public final class LeftPaneController { if (Settings.INSTANCE.getAccounts().isEmpty()) { RipplerContainer container = new RipplerContainer(missingAccountItem); - missingAccountItem.setOnSettingsButtonClicked(this::addNewAccount); + missingAccountItem.setOnSettingsButtonClicked(e -> addNewAccount()); + container.setOnMouseClicked(e -> addNewAccount()); list.add(container); } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/VersionListItem.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/VersionListItem.java index 7078d9dd9..140c64fd2 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/VersionListItem.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/VersionListItem.java @@ -17,11 +17,14 @@ */ package org.jackhuang.hmcl.ui; +import com.jfoenix.controls.JFXButton; +import javafx.event.EventHandler; import javafx.fxml.FXML; import javafx.geometry.Rectangle2D; import javafx.scene.control.Label; import javafx.scene.image.Image; import javafx.scene.image.ImageView; +import javafx.scene.input.MouseEvent; import javafx.scene.layout.StackPane; public final class VersionListItem extends StackPane { @@ -33,7 +36,7 @@ public final class VersionListItem extends StackPane { private Label lblGameVersion; @FXML private ImageView imageView; - private Runnable handler; + @FXML private JFXButton btnSettings; public VersionListItem(String versionName) { this(versionName, ""); @@ -48,13 +51,8 @@ public final class VersionListItem extends StackPane { FXUtils.limitSize(imageView, 32, 32); } - @FXML - private void onSettings() { - handler.run(); - } - - public void setOnSettingsButtonClicked(Runnable handler) { - this.handler = handler; + public void setOnSettingsButtonClicked(EventHandler handler) { + btnSettings.setOnMouseClicked(handler); } public void setVersionName(String versionName) { diff --git a/HMCL/src/main/resources/assets/fxml/account-item.fxml b/HMCL/src/main/resources/assets/fxml/account-item.fxml deleted file mode 100644 index 347b92021..000000000 --- a/HMCL/src/main/resources/assets/fxml/account-item.fxml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/HMCL/src/main/resources/assets/fxml/account.fxml b/HMCL/src/main/resources/assets/fxml/account.fxml index c79517b9e..ea116d355 100644 --- a/HMCL/src/main/resources/assets/fxml/account.fxml +++ b/HMCL/src/main/resources/assets/fxml/account.fxml @@ -1,82 +1,80 @@ - - + - - - - + - + - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + - - - + + - + - + diff --git a/HMCL/src/main/resources/assets/fxml/version-list-item.fxml b/HMCL/src/main/resources/assets/fxml/version-list-item.fxml index bc3fa3872..34109b66b 100644 --- a/HMCL/src/main/resources/assets/fxml/version-list-item.fxml +++ b/HMCL/src/main/resources/assets/fxml/version-list-item.fxml @@ -31,7 +31,7 @@ - +