feat: account popup above the bottom-left entry with add and manage actions
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0531d0cbc2
commit
b3f649c026
6 files changed
+42
-3
No files matched your search
@@ -13,7 +13,10 @@ import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import org.jackhuang.hmcl.auth.Account;
|
||||
import org.jackhuang.hmcl.setting.Accounts;
|
||||
import org.jackhuang.hmcl.ui.Controllers;
|
||||
import org.jackhuang.hmcl.ui.FXUtils;
|
||||
import org.jackhuang.hmcl.ui.SVG;
|
||||
import org.jackhuang.hmcl.ui.construct.AdvancedListItem;
|
||||
import org.jackhuang.hmcl.ui.construct.AdvancedListBox;
|
||||
|
||||
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
|
||||
@@ -31,12 +34,26 @@ public final class AccountListPopupMenu extends StackPane {
|
||||
@SuppressWarnings("FieldCanBeLocal")
|
||||
private final InvalidationListener listener;
|
||||
|
||||
/// Creates a footer entry shown below the account list.
|
||||
private static AdvancedListItem footerItem(SVG icon, String title) {
|
||||
AdvancedListItem item = new AdvancedListItem();
|
||||
item.setLeftIcon(icon);
|
||||
item.setTitle(title);
|
||||
return item;
|
||||
}
|
||||
|
||||
/// Closes the popup that currently hosts this menu, if any.
|
||||
private void hidePopup() {
|
||||
if (getScene() != null && getScene().getWindow() instanceof JFXPopup popup)
|
||||
popup.hide();
|
||||
}
|
||||
|
||||
public AccountListPopupMenu() {
|
||||
AdvancedListBox box = new AdvancedListBox();
|
||||
box.getStyleClass().add("no-padding");
|
||||
box.setPrefWidth(220);
|
||||
box.setPrefHeight(-1);
|
||||
box.setMaxHeight(260);
|
||||
box.setMaxHeight(320);
|
||||
|
||||
listener = o -> {
|
||||
box.clear();
|
||||
@@ -52,6 +69,20 @@ public final class AccountListPopupMenu extends StackPane {
|
||||
box.add(item);
|
||||
}
|
||||
|
||||
// Footer actions: add another account, or open the full account page.
|
||||
AdvancedListItem addItem = footerItem(SVG.ADD_CIRCLE, i18n("account.add"));
|
||||
addItem.setOnAction(e -> {
|
||||
hidePopup();
|
||||
Controllers.dialog(new CreateAccountPane());
|
||||
});
|
||||
AdvancedListItem manageItem = footerItem(SVG.SETTINGS, i18n("account.open_manage"));
|
||||
manageItem.setOnAction(e -> {
|
||||
hidePopup();
|
||||
Controllers.navigate(Controllers.getAccountListPage());
|
||||
});
|
||||
box.add(addItem);
|
||||
box.add(manageItem);
|
||||
|
||||
// https://github.com/HMCL-dev/HMCL/issues/5343
|
||||
Platform.runLater(() -> box.setVvalue(0.0));
|
||||
};
|
||||
|
||||
@@ -44,8 +44,8 @@ public class RootPage extends DecoratorAnimatedPage implements DecoratorPage {
|
||||
|
||||
// first item in left sidebar
|
||||
AccountAdvancedListItem accountListItem = new AccountAdvancedListItem();
|
||||
accountListItem.setOnAction(e -> Controllers.navigate(Controllers.getAccountListPage()));
|
||||
FXUtils.onSecondaryButtonClicked(accountListItem, () -> AccountListPopupMenu.show(accountListItem, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, accountListItem.getWidth(), 0));
|
||||
// Clicking the account opens a popup above it (the entry sits at the bottom-left): switch, add or manage.
|
||||
accountListItem.setOnAction(e -> AccountListPopupMenu.show(accountListItem, JFXPopup.PopupVPosition.BOTTOM, JFXPopup.PopupHPosition.LEFT, 0, -accountListItem.getHeight()));
|
||||
accountListItem.accountProperty().bind(Accounts.selectedAccountProperty());
|
||||
|
||||
// second item in left sidebar
|
||||
|
||||
@@ -798,6 +798,8 @@ home.pack=Modpack
|
||||
home.route=Route
|
||||
home.not_installed=Not installed
|
||||
launcher.name=Server Launcher
|
||||
account.add=Add account
|
||||
account.open_manage=Manage accounts
|
||||
server.join=Join Server
|
||||
instance.launch_and_enter_world=Play World
|
||||
instance.launch.empty=Start Game
|
||||
|
||||
@@ -618,6 +618,8 @@ home.pack=整合包
|
||||
home.route=路
|
||||
home.not_installed=未裝
|
||||
launcher.name=服啟
|
||||
account.add=增帳
|
||||
account.open_manage=理帳
|
||||
server.join=入服
|
||||
# instance.launch_and_enter_world=
|
||||
instance.launch.empty=啟戲
|
||||
|
||||
@@ -621,6 +621,8 @@ home.pack=整合包
|
||||
home.route=线路
|
||||
home.not_installed=尚未安装
|
||||
launcher.name=服务器启动器
|
||||
account.add=添加账号
|
||||
account.open_manage=管理账号
|
||||
server.join=进入服务器
|
||||
instance.launch_and_enter_world=进入世界
|
||||
instance.launch.empty=开始游戏
|
||||
|
||||
@@ -615,6 +615,8 @@ home.pack=整合包
|
||||
home.route=線路
|
||||
home.not_installed=尚未安裝
|
||||
launcher.name=伺服器啟動器
|
||||
account.add=新增帳號
|
||||
account.open_manage=管理帳號
|
||||
server.join=進入伺服器
|
||||
instance.launch_and_enter_world=進入世界
|
||||
instance.launch.empty=開始遊戲
|
||||
|
||||
Reference in new issue
Block a user