Skip to content

Commit 000a737

Browse files
committed
update
1 parent 66e75fd commit 000a737

3 files changed

Lines changed: 95 additions & 33 deletions

File tree

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Hello Minecraft! Launcher
3+
* Copyright (C) 2026 huangyuhui <huanghongxun2008@126.com> and contributors
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
package org.jackhuang.hmcl.ui.account;
19+
20+
import com.jfoenix.controls.JFXPopup;
21+
import javafx.beans.InvalidationListener;
22+
import javafx.beans.WeakInvalidationListener;
23+
import javafx.beans.binding.Bindings;
24+
import javafx.beans.binding.BooleanBinding;
25+
import javafx.scene.Node;
26+
import javafx.scene.control.Label;
27+
import javafx.scene.layout.StackPane;
28+
import org.jackhuang.hmcl.auth.Account;
29+
import org.jackhuang.hmcl.setting.Accounts;
30+
import org.jackhuang.hmcl.ui.FXUtils;
31+
import org.jackhuang.hmcl.ui.construct.AdvancedListBox;
32+
33+
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
34+
35+
public final class AccountListPopupMenu extends StackPane {
36+
public static void show(Node owner, JFXPopup.PopupVPosition vAlign, JFXPopup.PopupHPosition hAlign,
37+
double initOffsetX, double initOffsetY) {
38+
var menu = new AccountListPopupMenu();
39+
JFXPopup popup = new JFXPopup(menu);
40+
popup.show(owner, vAlign, hAlign, initOffsetX, initOffsetY);
41+
}
42+
43+
@SuppressWarnings("FieldCanBeLocal")
44+
private final BooleanBinding isEmpty = Bindings.isEmpty(Accounts.getAccounts());
45+
@SuppressWarnings("FieldCanBeLocal")
46+
private final InvalidationListener listener;
47+
48+
public AccountListPopupMenu() {
49+
AdvancedListBox box = new AdvancedListBox();
50+
box.getStyleClass().add("no-padding");
51+
box.setPrefWidth(220);
52+
box.setPrefHeight(-1);
53+
box.setMaxHeight(260);
54+
55+
listener = o -> {
56+
box.clear();
57+
58+
for (Account account : Accounts.getAccounts()) {
59+
AccountAdvancedListItem item = new AccountAdvancedListItem(account);
60+
item.setOnAction(e -> {
61+
Accounts.setSelectedAccount(account);
62+
if (getScene().getWindow() instanceof JFXPopup popup)
63+
popup.hide();
64+
});
65+
box.add(item);
66+
}
67+
};
68+
listener.invalidated(null);
69+
Accounts.getAccounts().addListener(new WeakInvalidationListener(listener));
70+
71+
Label placeholder = new Label(i18n("account.empty"));
72+
placeholder.setStyle("-fx-padding: 10px; -fx-text-fill: -monet-on-surface-variant; -fx-font-style: italic;");
73+
74+
FXUtils.onChangeAndOperate(isEmpty, empty -> {
75+
getChildren().setAll(empty ? placeholder : box);
76+
});
77+
}
78+
79+
}

HMCL/src/main/java/org/jackhuang/hmcl/ui/main/RootPage.java

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919

2020
import com.jfoenix.controls.JFXPopup;
2121
import javafx.beans.property.ReadOnlyObjectProperty;
22-
import javafx.scene.control.Label;
2322
import javafx.scene.input.MouseButton;
2423
import org.jackhuang.hmcl.Metadata;
25-
import org.jackhuang.hmcl.auth.Account;
2624
import org.jackhuang.hmcl.event.EventBus;
2725
import org.jackhuang.hmcl.event.RefreshedVersionsEvent;
2826
import org.jackhuang.hmcl.game.HMCLGameRepository;
@@ -38,11 +36,11 @@
3836
import org.jackhuang.hmcl.ui.FXUtils;
3937
import org.jackhuang.hmcl.ui.SVG;
4038
import org.jackhuang.hmcl.ui.account.AccountAdvancedListItem;
39+
import org.jackhuang.hmcl.ui.account.AccountListPopupMenu;
4140
import org.jackhuang.hmcl.ui.animation.AnimationUtils;
4241
import org.jackhuang.hmcl.ui.construct.AdvancedListBox;
4342
import org.jackhuang.hmcl.ui.construct.AdvancedListItem;
4443
import org.jackhuang.hmcl.ui.construct.MessageDialogPane;
45-
import org.jackhuang.hmcl.ui.construct.PopupMenu;
4644
import org.jackhuang.hmcl.ui.decorator.DecoratorAnimatedPage;
4745
import org.jackhuang.hmcl.ui.decorator.DecoratorPage;
4846
import org.jackhuang.hmcl.ui.download.ModpackInstallWizardProvider;
@@ -150,7 +148,7 @@ protected Skin(RootPage control) {
150148
accountListItem.setOnAction(e -> Controllers.navigate(Controllers.getAccountListPage()));
151149
accountListItem.setOnMouseClicked(e -> {
152150
if (e.getButton() == MouseButton.SECONDARY) {
153-
showAccountListPopupMenu(accountListItem);
151+
AccountListPopupMenu.show(accountListItem, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, accountListItem.getWidth(), 0);
154152
e.consume();
155153
}
156154
});
@@ -254,35 +252,6 @@ else if (Platform.SYSTEM_PLATFORM.equals(OperatingSystem.LINUX, Architecture.LOO
254252
setCenter(getSkinnable().getMainPage());
255253
}
256254

257-
public void showAccountListPopupMenu(
258-
AccountAdvancedListItem accountListItem
259-
) {
260-
PopupMenu popupMenu = new PopupMenu();
261-
JFXPopup popup = new JFXPopup(popupMenu);
262-
AdvancedListBox scrollPane = new AdvancedListBox();
263-
scrollPane.getStyleClass().add("no-padding");
264-
scrollPane.setPrefWidth(220);
265-
scrollPane.setPrefHeight(-1);
266-
scrollPane.setMaxHeight(260);
267-
268-
if (Accounts.getAccounts().isEmpty()) {
269-
Label placeholder = new Label(i18n("account.empty"));
270-
placeholder.setStyle("-fx-padding: 10px; -fx-text-fill: -monet-on-surface-variant; -fx-font-style: italic;");
271-
scrollPane.add(placeholder);
272-
} else {
273-
for (Account account : Accounts.getAccounts()) {
274-
AccountAdvancedListItem item = new AccountAdvancedListItem(account);
275-
item.setOnAction(e -> {
276-
Accounts.setSelectedAccount(account);
277-
popup.hide();
278-
});
279-
scrollPane.add(item);
280-
}
281-
}
282-
283-
popupMenu.getContent().add(scrollPane);
284-
popup.show(accountListItem, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, accountListItem.getWidth(), 0);
285-
}
286255
}
287256

288257
private boolean checkedModpack = false;

HMCL/src/main/java/org/jackhuang/hmcl/ui/terracotta/TerracottaPage.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,18 @@
2121
import javafx.beans.property.ReadOnlyObjectWrapper;
2222
import javafx.beans.value.ChangeListener;
2323
import javafx.geometry.Insets;
24+
import javafx.scene.input.MouseButton;
2425
import javafx.scene.layout.BorderPane;
2526
import javafx.scene.layout.Priority;
2627
import javafx.scene.layout.VBox;
28+
import org.jackhuang.hmcl.setting.Accounts;
2729
import org.jackhuang.hmcl.setting.Profile;
2830
import org.jackhuang.hmcl.setting.Profiles;
2931
import org.jackhuang.hmcl.terracotta.TerracottaMetadata;
3032
import org.jackhuang.hmcl.ui.Controllers;
3133
import org.jackhuang.hmcl.ui.FXUtils;
3234
import org.jackhuang.hmcl.ui.SVG;
35+
import org.jackhuang.hmcl.ui.account.AccountAdvancedListItem;
3336
import org.jackhuang.hmcl.ui.animation.TransitionPane;
3437
import org.jackhuang.hmcl.ui.construct.*;
3538
import org.jackhuang.hmcl.ui.decorator.DecoratorAnimatedPage;
@@ -67,7 +70,18 @@ public TerracottaPage() {
6770
.addNavigationDrawerTab(tab, statusPage, i18n("terracotta.status"), SVG.TUNE);
6871
left.setTop(sideBar);
6972

73+
AccountAdvancedListItem accountListItem = new AccountAdvancedListItem();
74+
accountListItem.setOnAction(e -> Controllers.navigate(Controllers.getAccountListPage()));
75+
// accountListItem.setOnMouseClicked(e -> {
76+
// if (e.getButton() == MouseButton.SECONDARY) {
77+
// showAccountListPopupMenu(accountListItem);
78+
// e.consume();
79+
// }
80+
// });
81+
accountListItem.accountProperty().bind(Accounts.selectedAccountProperty());
82+
7083
AdvancedListBox toolbar = new AdvancedListBox()
84+
.add(accountListItem)
7185
.addNavigationDrawerItem(i18n("version.launch"), SVG.ROCKET_LAUNCH, () -> {
7286
Profile profile = Profiles.getSelectedProfile();
7387
Versions.launch(profile, profile.getSelectedVersion(), launcherHelper -> {

0 commit comments

Comments
 (0)