From b78f5407cc048c0a0f91d2cf75858bdaa95ab161 Mon Sep 17 00:00:00 2001 From: Haowei Wen Date: Tue, 7 Sep 2021 00:46:46 +0800 Subject: [PATCH] redesign account list page sidebar --- .../hmcl/ui/account/AccountListPage.java | 131 ++++++++++-------- .../account/AddAuthlibInjectorServerPane.java | 2 +- .../hmcl/ui/account/CreateAccountPane.java | 15 +- 3 files changed, 86 insertions(+), 62 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AccountListPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AccountListPage.java index a3531cbd0..28c307b6c 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AccountListPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AccountListPage.java @@ -24,6 +24,7 @@ import javafx.beans.property.*; import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; import javafx.collections.ObservableList; +import javafx.geometry.Insets; import javafx.scene.control.ScrollPane; import javafx.scene.control.Skin; import javafx.scene.control.SkinBase; @@ -48,6 +49,8 @@ import static org.jackhuang.hmcl.ui.versions.VersionPage.wrap; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; import static org.jackhuang.hmcl.util.javafx.ExtendedProperties.createSelectedItemPropertyFor; +import java.net.URI; + public class AccountListPage extends ListPageBase implements DecoratorPage { private final ReadOnlyObjectWrapper state = new ReadOnlyObjectWrapper<>(State.fromTitle(i18n("account.manage"), -1)); private final ListProperty accounts = new SimpleListProperty<>(this, "accounts", FXCollections.observableArrayList()); @@ -91,81 +94,89 @@ public class AccountListPage extends ListPageBase implements De BorderPane root = new BorderPane(); { - VBox left = new VBox(); - left.getStyleClass().add("advanced-list-box-content"); - - left.getChildren().add(new ClassTitle(i18n("account.create"))); - - AdvancedListItem offlineItem = new AdvancedListItem(); - offlineItem.getStyleClass().add("navigation-drawer-item"); - offlineItem.setActionButtonVisible(false); - offlineItem.setTitle(i18n("account.methods.offline")); - offlineItem.setLeftGraphic(wrap(SVG.account(Theme.blackFillBinding(), 24, 24))); - offlineItem.setOnAction(e -> Controllers.dialog(new CreateAccountPane(Accounts.FACTORY_OFFLINE))); - left.getChildren().add(offlineItem); - - AdvancedListItem mojangItem = new AdvancedListItem(); - mojangItem.getStyleClass().add("navigation-drawer-item"); - mojangItem.setActionButtonVisible(false); - mojangItem.setTitle(i18n("account.methods.yggdrasil")); - mojangItem.setLeftGraphic(wrap(SVG.mojang(Theme.blackFillBinding(), 24, 24))); - mojangItem.setOnAction(e -> Controllers.dialog(new CreateAccountPane(Accounts.FACTORY_MOJANG))); - left.getChildren().add(mojangItem); - - AdvancedListItem microsoftItem = new AdvancedListItem(); - microsoftItem.getStyleClass().add("navigation-drawer-item"); - microsoftItem.setActionButtonVisible(false); - microsoftItem.setTitle(i18n("account.methods.microsoft")); - microsoftItem.setLeftGraphic(wrap(SVG.microsoft(Theme.blackFillBinding(), 24, 24))); - microsoftItem.setOnAction(e -> Controllers.dialog(new CreateAccountPane(Accounts.FACTORY_MICROSOFT))); - left.getChildren().add(microsoftItem); - - left.getChildren().add(new ClassTitle(i18n("account.methods.authlib_injector"))); + BorderPane left = new BorderPane(); + FXUtils.setLimitWidth(left, 200); { - VBox wrapper = new VBox(); - FXUtils.setLimitWidth(wrapper, 200); + VBox boxItemList = new VBox(); + boxItemList.getStyleClass().add("advanced-list-box-content"); - VBox box = new VBox(); - authServerItems = MappedObservableList.create(skinnable.authServersProperty(), server -> { - AdvancedListItem item = new AdvancedListItem(); - item.getStyleClass().add("navigation-drawer-item"); - item.setLeftGraphic(SVG.server(Theme.blackFillBinding(), 24, 24)); - item.setOnAction(e -> Controllers.dialog(new CreateAccountPane(server))); + boxItemList.getChildren().add(new ClassTitle(i18n("account.create"))); - JFXButton btnRemove = new JFXButton(); - btnRemove.setOnAction(e -> { - skinnable.authServersProperty().remove(server); - e.consume(); + { + VBox boxMethods = new VBox(); + FXUtils.setLimitWidth(boxMethods, 200); + + AdvancedListItem offlineItem = new AdvancedListItem(); + offlineItem.getStyleClass().add("navigation-drawer-item"); + offlineItem.setActionButtonVisible(false); + offlineItem.setTitle(i18n("account.methods.offline")); + offlineItem.setLeftGraphic(wrap(SVG.account(Theme.blackFillBinding(), 24, 24))); + offlineItem.setOnAction(e -> Controllers.dialog(new CreateAccountPane(Accounts.FACTORY_OFFLINE))); + boxMethods.getChildren().add(offlineItem); + + AdvancedListItem mojangItem = new AdvancedListItem(); + mojangItem.getStyleClass().add("navigation-drawer-item"); + mojangItem.setActionButtonVisible(false); + mojangItem.setTitle(i18n("account.methods.yggdrasil")); + mojangItem.setLeftGraphic(wrap(SVG.mojang(Theme.blackFillBinding(), 24, 24))); + mojangItem.setOnAction(e -> Controllers.dialog(new CreateAccountPane(Accounts.FACTORY_MOJANG))); + boxMethods.getChildren().add(mojangItem); + + AdvancedListItem microsoftItem = new AdvancedListItem(); + microsoftItem.getStyleClass().add("navigation-drawer-item"); + microsoftItem.setActionButtonVisible(false); + microsoftItem.setTitle(i18n("account.methods.microsoft")); + microsoftItem.setLeftGraphic(wrap(SVG.microsoft(Theme.blackFillBinding(), 24, 24))); + microsoftItem.setOnAction(e -> Controllers.dialog(new CreateAccountPane(Accounts.FACTORY_MICROSOFT))); + boxMethods.getChildren().add(microsoftItem); + + VBox boxAuthServers = new VBox(); + authServerItems = MappedObservableList.create(skinnable.authServersProperty(), server -> { + AdvancedListItem item = new AdvancedListItem(); + item.getStyleClass().add("navigation-drawer-item"); + item.setLeftGraphic(wrap(SVG.server(Theme.blackFillBinding(), 24, 24))); + item.setOnAction(e -> Controllers.dialog(new CreateAccountPane(server))); + + JFXButton btnRemove = new JFXButton(); + btnRemove.setOnAction(e -> { + skinnable.authServersProperty().remove(server); + e.consume(); + }); + btnRemove.getStyleClass().add("toggle-icon4"); + btnRemove.setGraphic(SVG.close(Theme.blackFillBinding(), 14, 14)); + item.setRightGraphic(btnRemove); + + ObservableValue title = BindingMapping.of(server, AuthlibInjectorServer::getName); + item.titleProperty().bind(title); + item.subtitleProperty().set(URI.create(server.getUrl()).getHost()); + Tooltip tooltip = new Tooltip(); + tooltip.textProperty().bind(Bindings.format("%s (%s)", title, server.getUrl())); + FXUtils.installFastTooltip(item, tooltip); + + return item; }); - btnRemove.getStyleClass().add("toggle-icon4"); - btnRemove.setGraphic(SVG.close(Theme.blackFillBinding(), 14, 14)); - item.setRightGraphic(btnRemove); + Bindings.bindContent(boxAuthServers.getChildren(), authServerItems); + boxMethods.getChildren().add(boxAuthServers); - ObservableValue title = BindingMapping.of(server, AuthlibInjectorServer::getName); - String url = server.getUrl(); - item.titleProperty().bind(title); - item.subtitleProperty().set(url); - Tooltip tooltip = new Tooltip(); - tooltip.textProperty().bind(Bindings.format("%s (%s)", title, url)); - FXUtils.installFastTooltip(item, tooltip); + boxItemList.getChildren().add(new ScrollPane(boxMethods)); + } - return item; - }); - Bindings.bindContent(box.getChildren(), authServerItems); + left.setCenter(boxItemList); + } + { AdvancedListItem addAuthServerItem = new AdvancedListItem(); addAuthServerItem.getStyleClass().add("navigation-drawer-item"); addAuthServerItem.setTitle(i18n("account.injector.add")); + addAuthServerItem.setSubtitle(i18n("account.methods.authlib_injector")); addAuthServerItem.setActionButtonVisible(false); - addAuthServerItem.setLeftGraphic(SVG.plusCircleOutline(Theme.blackFillBinding(), 24, 24)); + addAuthServerItem.setLeftGraphic(wrap(SVG.plusCircleOutline(Theme.blackFillBinding(), 24, 24))); addAuthServerItem.setOnAction(e -> Controllers.dialog(new AddAuthlibInjectorServerPane())); - - wrapper.getChildren().addAll(box, addAuthServerItem); - left.getChildren().add(new ScrollPane(wrapper)); + BorderPane.setMargin(addAuthServerItem, new Insets(0, 0, 12, 0)); + left.setBottom(addAuthServerItem); } - FXUtils.setLimitWidth(left, 200); root.setLeft(left); } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AddAuthlibInjectorServerPane.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AddAuthlibInjectorServerPane.java index 59d05cd72..d59e2c4eb 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AddAuthlibInjectorServerPane.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AddAuthlibInjectorServerPane.java @@ -132,7 +132,7 @@ public class AddAuthlibInjectorServerPane extends StackPane implements DialogAwa @FXML private void onAddFinish() { if (!config().getAuthlibInjectorServers().contains(serverBeingAdded)) { - config().getAuthlibInjectorServers().add(0, serverBeingAdded); + config().getAuthlibInjectorServers().add(serverBeingAdded); } fireEvent(new DialogCloseEvent()); } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/CreateAccountPane.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/CreateAccountPane.java index 7cf6a82e8..a3186791e 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/CreateAccountPane.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/CreateAccountPane.java @@ -62,7 +62,7 @@ import static org.jackhuang.hmcl.ui.FXUtils.*; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; import static org.jackhuang.hmcl.util.javafx.ExtendedProperties.classPropertyFor; -public class CreateAccountPane extends JFXDialogLayout { +public class CreateAccountPane extends JFXDialogLayout implements DialogAware { private boolean showMethodSwitcher; private AccountFactory factory; @@ -424,6 +424,12 @@ public class CreateAccountPane extends JFXDialogLayout { public void selectAuthServer(AuthlibInjectorServer authserver) { cboServers.getSelectionModel().select(authserver); } + + public void focus() { + if (txtUsername != null) { + txtUsername.requestFocus(); + } + } } private static class DialogCharacterSelector extends BorderPane implements CharacterSelector { @@ -486,4 +492,11 @@ public class CreateAccountPane extends JFXDialogLayout { } } } + + @Override + public void onDialogShown() { + if (detailsPane instanceof AccountDetailsInputPane) { + ((AccountDetailsInputPane) detailsPane).focus(); + } + } }