diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AccountAdvancedListItem.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AccountAdvancedListItem.java index 8c9da5ec1..49b7fcf18 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AccountAdvancedListItem.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AccountAdvancedListItem.java @@ -68,6 +68,10 @@ public class AccountAdvancedListItem extends AdvancedListItem { }; public AccountAdvancedListItem() { + this(null); + } + + public AccountAdvancedListItem(Account account) { tooltip = new Tooltip(); FXUtils.installFastTooltip(this, tooltip); @@ -76,9 +80,13 @@ public class AccountAdvancedListItem extends AdvancedListItem { setActionButtonVisible(false); - FXUtils.onScroll(this, Accounts.getAccounts(), - accounts -> accounts.indexOf(account.get()), - Accounts::setSelectedAccount); + if (account != null) { + this.accountProperty().set(account); + } else { + FXUtils.onScroll(this, Accounts.getAccounts(), + accounts -> accounts.indexOf(accountProperty().get()), + Accounts::setSelectedAccount); + } } public ObjectProperty accountProperty() { diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/RootPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/RootPage.java index 169bea429..5ee32ae01 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/RootPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/RootPage.java @@ -17,9 +17,11 @@ */ package org.jackhuang.hmcl.ui.main; +import com.jfoenix.controls.JFXPopup; import javafx.beans.property.ReadOnlyObjectProperty; - +import javafx.scene.input.MouseButton; import org.jackhuang.hmcl.Metadata; +import org.jackhuang.hmcl.auth.Account; import org.jackhuang.hmcl.event.EventBus; import org.jackhuang.hmcl.event.RefreshedVersionsEvent; import org.jackhuang.hmcl.game.HMCLGameRepository; @@ -39,6 +41,7 @@ import org.jackhuang.hmcl.ui.animation.AnimationUtils; import org.jackhuang.hmcl.ui.construct.AdvancedListBox; import org.jackhuang.hmcl.ui.construct.AdvancedListItem; import org.jackhuang.hmcl.ui.construct.MessageDialogPane; +import org.jackhuang.hmcl.ui.construct.PopupMenu; import org.jackhuang.hmcl.ui.decorator.DecoratorAnimatedPage; import org.jackhuang.hmcl.ui.decorator.DecoratorPage; import org.jackhuang.hmcl.ui.download.ModpackInstallWizardProvider; @@ -64,8 +67,8 @@ import java.util.stream.Collectors; import static org.jackhuang.hmcl.ui.FXUtils.runInFX; import static org.jackhuang.hmcl.ui.versions.VersionPage.wrap; -import static org.jackhuang.hmcl.util.logging.Logger.LOG; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; +import static org.jackhuang.hmcl.util.logging.Logger.LOG; public class RootPage extends DecoratorAnimatedPage implements DecoratorPage { private MainPage mainPage = null; @@ -144,6 +147,13 @@ public class RootPage extends DecoratorAnimatedPage implements DecoratorPage { // first item in left sidebar AccountAdvancedListItem accountListItem = new AccountAdvancedListItem(); accountListItem.setOnAction(e -> Controllers.navigate(Controllers.getAccountListPage())); + accountListItem.setOnMouseClicked(e -> { + if (e.getButton() == MouseButton.SECONDARY) { + if (!Accounts.getAccounts().isEmpty()) + showAccountListPopupMenu(accountListItem); + e.consume(); + } + }); accountListItem.accountProperty().bind(Accounts.selectedAccountProperty()); // second item in left sidebar @@ -241,6 +251,29 @@ public class RootPage extends DecoratorAnimatedPage implements DecoratorPage { setCenter(getSkinnable().getMainPage()); } + public void showAccountListPopupMenu( + AccountAdvancedListItem accountListItem + ) { + PopupMenu popupMenu = new PopupMenu(); + JFXPopup popup = new JFXPopup(popupMenu); + AdvancedListBox scrollPane = new AdvancedListBox(); + scrollPane.getStyleClass().add("no-padding"); + scrollPane.setPrefWidth(220); + scrollPane.setPrefHeight(-1); + scrollPane.setMaxHeight(260); + + for (Account account : Accounts.getAccounts()) { + AccountAdvancedListItem item = new AccountAdvancedListItem(account); + item.setOnAction(e -> { + Accounts.setSelectedAccount(account); + popup.hide(); + }); + scrollPane.add(item); + } + + popupMenu.getContent().add(scrollPane); + popup.show(accountListItem, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, accountListItem.getWidth(), 0); + } } private boolean checkedModpack = false; diff --git a/HMCL/src/main/resources/assets/css/root.css b/HMCL/src/main/resources/assets/css/root.css index 5b0ade9c9..a314be045 100644 --- a/HMCL/src/main/resources/assets/css/root.css +++ b/HMCL/src/main/resources/assets/css/root.css @@ -265,6 +265,10 @@ -fx-spacing: 0; } +.no-padding .advanced-list-box-content { + -fx-padding: 0 0 0 0; +} + .iconed-item { -jfx-rippler-fill: -monet-secondary-container; }