From 0639d8291469f1b6bd710e74931129e1508cca82 Mon Sep 17 00:00:00 2001 From: huanghongxun Date: Sat, 18 Apr 2020 10:45:39 +0800 Subject: [PATCH] add: launch button in gamelist --- .../org/jackhuang/hmcl/ui/main/RootPage.java | 18 +++++++---- .../hmcl/ui/versions/GameListItemSkin.java | 30 +++++++++++++------ 2 files changed, 34 insertions(+), 14 deletions(-) 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 0b69a049e..2d2558947 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 @@ -200,6 +200,14 @@ public class RootPage extends DecoratorTabPage { return profileTab; } + private void selectPage(Tab tab) { + if (getSelectionModel().getSelectedItem() == tab) { + getSelectionModel().select(getMainTab()); + } else { + getSelectionModel().select(tab); + } + } + private static class Skin extends SkinBase { protected Skin(RootPage control) { @@ -208,7 +216,7 @@ public class RootPage extends DecoratorTabPage { // first item in left sidebar AccountAdvancedListItem accountListItem = new AccountAdvancedListItem(); accountListItem.activeProperty().bind(control.accountTab.selectedProperty()); - accountListItem.setOnAction(e -> control.getSelectionModel().select(control.accountTab)); + accountListItem.setOnAction(e -> control.selectPage(control.accountTab)); accountListItem.accountProperty().bind(Accounts.selectedAccountProperty()); // second item in left sidebar @@ -218,7 +226,7 @@ public class RootPage extends DecoratorTabPage { Profile profile = Profiles.getSelectedProfile(); String version = Profiles.getSelectedVersion(); if (version == null) { - control.getSelectionModel().select(control.gameTab); + control.selectPage(control.gameTab); } else { Versions.modifyGameSettings(profile, version); } @@ -229,12 +237,12 @@ public class RootPage extends DecoratorTabPage { gameItem.activeProperty().bind(control.gameTab.selectedProperty()); gameItem.setImage(newImage("/assets/img/bookshelf.png")); gameItem.setTitle(i18n("version.manage")); - gameItem.setOnAction(e -> control.getSelectionModel().select(control.gameTab)); + gameItem.setOnAction(e -> control.selectPage(control.gameTab)); // forth item in left sidebar ProfileAdvancedListItem profileListItem = new ProfileAdvancedListItem(); profileListItem.activeProperty().bind(control.profileTab.selectedProperty()); - profileListItem.setOnAction(e -> control.getSelectionModel().select(control.profileTab)); + profileListItem.setOnAction(e -> control.selectPage(control.profileTab)); profileListItem.profileProperty().bind(Profiles.selectedProfileProperty()); // fifth item in left sidebar @@ -242,7 +250,7 @@ public class RootPage extends DecoratorTabPage { launcherSettingsItem.activeProperty().bind(control.settingsTab.selectedProperty()); launcherSettingsItem.setImage(newImage("/assets/img/command.png")); launcherSettingsItem.setTitle(i18n("settings.launcher")); - launcherSettingsItem.setOnAction(e -> control.getSelectionModel().select(control.settingsTab)); + launcherSettingsItem.setOnAction(e -> control.selectPage(control.settingsTab)); // the left sidebar AdvancedListBox sideBar = new AdvancedListBox() diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/GameListItemSkin.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/GameListItemSkin.java index d0d2a3c7a..873bdb590 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/GameListItemSkin.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/GameListItemSkin.java @@ -87,15 +87,27 @@ public class GameListItemSkin extends SkinBase { right.getChildren().add(btnUpgrade); } - JFXButton btnManage = new JFXButton(); - btnManage.setOnMouseClicked(e -> { - currentSkinnable = skinnable; - popup.show(root, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.RIGHT, 0, root.getHeight()); - }); - btnManage.getStyleClass().add("toggle-icon4"); - BorderPane.setAlignment(btnManage, Pos.CENTER); - btnManage.setGraphic(SVG.dotsVertical(Theme.blackFillBinding(), -1, -1)); - right.getChildren().add(btnManage); + { + JFXButton btnLaunch = new JFXButton(); + btnLaunch.setOnMouseClicked(e -> skinnable.launch()); + btnLaunch.getStyleClass().add("toggle-icon4"); + BorderPane.setAlignment(btnLaunch, Pos.CENTER); + btnLaunch.setGraphic(SVG.launch(Theme.blackFillBinding(), 20, 20)); + right.getChildren().add(btnLaunch); + } + + { + JFXButton btnManage = new JFXButton(); + btnManage.setOnMouseClicked(e -> { + currentSkinnable = skinnable; + popup.show(root, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.RIGHT, 0, root.getHeight()); + }); + btnManage.getStyleClass().add("toggle-icon4"); + BorderPane.setAlignment(btnManage, Pos.CENTER); + btnManage.setGraphic(SVG.dotsVertical(Theme.blackFillBinding(), -1, -1)); + right.getChildren().add(btnManage); + } + root.setRight(right); root.getStyleClass().add("card");