修改AccountAdvancedListItem 控件, 在 RootPage 中添加快速选择账户 (#4932)
This commit is contained in:
@@ -68,6 +68,10 @@ public class AccountAdvancedListItem extends AdvancedListItem {
|
|||||||
};
|
};
|
||||||
|
|
||||||
public AccountAdvancedListItem() {
|
public AccountAdvancedListItem() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AccountAdvancedListItem(Account account) {
|
||||||
tooltip = new Tooltip();
|
tooltip = new Tooltip();
|
||||||
FXUtils.installFastTooltip(this, tooltip);
|
FXUtils.installFastTooltip(this, tooltip);
|
||||||
|
|
||||||
@@ -76,9 +80,13 @@ public class AccountAdvancedListItem extends AdvancedListItem {
|
|||||||
|
|
||||||
setActionButtonVisible(false);
|
setActionButtonVisible(false);
|
||||||
|
|
||||||
FXUtils.onScroll(this, Accounts.getAccounts(),
|
if (account != null) {
|
||||||
accounts -> accounts.indexOf(account.get()),
|
this.accountProperty().set(account);
|
||||||
Accounts::setSelectedAccount);
|
} else {
|
||||||
|
FXUtils.onScroll(this, Accounts.getAccounts(),
|
||||||
|
accounts -> accounts.indexOf(accountProperty().get()),
|
||||||
|
Accounts::setSelectedAccount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObjectProperty<Account> accountProperty() {
|
public ObjectProperty<Account> accountProperty() {
|
||||||
|
|||||||
@@ -17,9 +17,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hmcl.ui.main;
|
package org.jackhuang.hmcl.ui.main;
|
||||||
|
|
||||||
|
import com.jfoenix.controls.JFXPopup;
|
||||||
import javafx.beans.property.ReadOnlyObjectProperty;
|
import javafx.beans.property.ReadOnlyObjectProperty;
|
||||||
|
import javafx.scene.input.MouseButton;
|
||||||
import org.jackhuang.hmcl.Metadata;
|
import org.jackhuang.hmcl.Metadata;
|
||||||
|
import org.jackhuang.hmcl.auth.Account;
|
||||||
import org.jackhuang.hmcl.event.EventBus;
|
import org.jackhuang.hmcl.event.EventBus;
|
||||||
import org.jackhuang.hmcl.event.RefreshedVersionsEvent;
|
import org.jackhuang.hmcl.event.RefreshedVersionsEvent;
|
||||||
import org.jackhuang.hmcl.game.HMCLGameRepository;
|
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.AdvancedListBox;
|
||||||
import org.jackhuang.hmcl.ui.construct.AdvancedListItem;
|
import org.jackhuang.hmcl.ui.construct.AdvancedListItem;
|
||||||
import org.jackhuang.hmcl.ui.construct.MessageDialogPane;
|
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.DecoratorAnimatedPage;
|
||||||
import org.jackhuang.hmcl.ui.decorator.DecoratorPage;
|
import org.jackhuang.hmcl.ui.decorator.DecoratorPage;
|
||||||
import org.jackhuang.hmcl.ui.download.ModpackInstallWizardProvider;
|
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.FXUtils.runInFX;
|
||||||
import static org.jackhuang.hmcl.ui.versions.VersionPage.wrap;
|
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.i18n.I18n.i18n;
|
||||||
|
import static org.jackhuang.hmcl.util.logging.Logger.LOG;
|
||||||
|
|
||||||
public class RootPage extends DecoratorAnimatedPage implements DecoratorPage {
|
public class RootPage extends DecoratorAnimatedPage implements DecoratorPage {
|
||||||
private MainPage mainPage = null;
|
private MainPage mainPage = null;
|
||||||
@@ -144,6 +147,13 @@ public class RootPage extends DecoratorAnimatedPage implements DecoratorPage {
|
|||||||
// first item in left sidebar
|
// first item in left sidebar
|
||||||
AccountAdvancedListItem accountListItem = new AccountAdvancedListItem();
|
AccountAdvancedListItem accountListItem = new AccountAdvancedListItem();
|
||||||
accountListItem.setOnAction(e -> Controllers.navigate(Controllers.getAccountListPage()));
|
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());
|
accountListItem.accountProperty().bind(Accounts.selectedAccountProperty());
|
||||||
|
|
||||||
// second item in left sidebar
|
// second item in left sidebar
|
||||||
@@ -241,6 +251,29 @@ public class RootPage extends DecoratorAnimatedPage implements DecoratorPage {
|
|||||||
setCenter(getSkinnable().getMainPage());
|
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;
|
private boolean checkedModpack = false;
|
||||||
|
|||||||
@@ -265,6 +265,10 @@
|
|||||||
-fx-spacing: 0;
|
-fx-spacing: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.no-padding .advanced-list-box-content {
|
||||||
|
-fx-padding: 0 0 0 0;
|
||||||
|
}
|
||||||
|
|
||||||
.iconed-item {
|
.iconed-item {
|
||||||
-jfx-rippler-fill: -monet-secondary-container;
|
-jfx-rippler-fill: -monet-secondary-container;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user