diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/LeftPaneController.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/LeftPaneController.java index 7bf44aa17..a6ccc5fa6 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/LeftPaneController.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/LeftPaneController.java @@ -60,7 +60,7 @@ public final class LeftPaneController extends AdvancedListBox { profileListItem.setOnAction(e -> Controllers.navigate(Controllers.getProfileListPage())); profileListItem.profileProperty().bind(Profiles.selectedProfileProperty()); - IconedItem launcherSettingsItem = new IconedItem(SVG.gear(Theme.blackFillBinding(), 20, 20)); + IconedItem launcherSettingsItem = new IconedItem(SVG.gear(Theme.blackFillBinding(), 20, 20), "iconed-item"); launcherSettingsItem.getLabel().textProperty().bind( new When(UpdateChecker.outdatedProperty()) @@ -72,7 +72,6 @@ public final class LeftPaneController extends AdvancedListBox { .then(Color.RED) .otherwise(Color.BLACK)); - launcherSettingsItem.maxWidthProperty().bind(widthProperty()); launcherSettingsItem.setOnMouseClicked(e -> Controllers.navigate(Controllers.getSettingsPage())); this diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/SVG.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/SVG.java index 8925dd194..379454f80 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/SVG.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/SVG.java @@ -91,6 +91,10 @@ public final class SVG { return createSVGPath("M1008 6.286q18.857 13.714 15.429 36.571l-146.286 877.714q-2.857 16.571-18.286 25.714-8 4.571-17.714 4.571-6.286 0-13.714-2.857l-258.857-105.714-138.286 168.571q-10.286 13.143-28 13.143-7.429 0-12.571-2.286-10.857-4-17.429-13.429t-6.571-20.857v-199.429l493.714-605.143-610.857 528.571-225.714-92.571q-21.143-8-22.857-31.429-1.143-22.857 18.286-33.714l950.857-548.571q8.571-5.143 18.286-5.14311.429 0 20.571 6.286z", fill, width, height); } + public static Node launch2(ObjectBinding fill, double width, double height) { + return createSVGPath("M14,3V5H17.59L7.76,14.83L9.17,16.24L19,6.41V10H21V3M19,19H5V5H12V3H5C3.89,3 3,3.89 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V12H19V19Z", fill, width, height); + } + public static Node script(ObjectBinding fill, double width, double height) { return createSVGPath("M14,20A2,2 0 0,0 16,18V5H9A1,1 0 0,0 8,6V16H5V5A3,3 0 0,1 8,2H19A3,3 0 0,1 22,5V6H18V18L18,19A3,3 0 0,1 15,22H5A3,3 0 0,1 2,19V18H12A2,2 0 0,0 14,20Z", fill, width, height); } @@ -138,4 +142,8 @@ public final class SVG { public static Node importIcon(ObjectBinding fill, double width, double height) { return createSVGPath("M14,12L10,8V11H2V13H10V16M20,18V6C20,4.89 19.1,4 18,4H6A2,2 0 0,0 4,6V9H6V6H18V18H6V15H4V18A2,2 0 0,0 6,20H18A2,2 0 0,0 20,18Z", fill, width, height); } + + public static Node export(ObjectBinding fill, double width, double height) { + return createSVGPath("M23,12L19,8V11H10V13H19V16M1,18V6C1,4.89 1.9,4 3,4H15A2,2 0 0,1 17,6V9H15V6H3V18H15V15H17V18A2,2 0 0,1 15,20H3A2,2 0 0,1 1,18Z", fill, width, height); + } } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/IconedItem.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/IconedItem.java index 7a35595c0..3ed7583a1 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/IconedItem.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/IconedItem.java @@ -26,30 +26,33 @@ public class IconedItem extends RipplerContainer { private Label label; - public IconedItem(Node icon, String text) { - this(icon); + public IconedItem(Node icon, String text, String styleClass) { + this(icon, styleClass); label.setText(text); } - public IconedItem(Node icon) { - super(createHBox(icon)); + public IconedItem(Node icon, String styleClass) { + super(createHBox(icon, styleClass)); label = ((Label) lookup("#label")); } - private static HBox createHBox(Node icon) { + private static HBox createHBox(Node icon, String styleClass) { HBox hBox = new HBox(); + hBox.getStyleClass().setAll(styleClass); icon.setMouseTransparent(true); Label textLabel = new Label(); textLabel.setId("label"); - textLabel.setAlignment(Pos.CENTER); textLabel.setMouseTransparent(true); hBox.getChildren().addAll(icon, textLabel); - hBox.setStyle("-fx-padding: 10 16 10 16; -fx-spacing: 10; -fx-font-size: 14;"); - hBox.setAlignment(Pos.CENTER_LEFT); return hBox; } public Label getLabel() { return label; } + + public IconedItem setClickedAction(Runnable r) { + setOnMouseClicked(e -> r.run()); + return this; + } } 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 f59273765..bc42550f5 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 @@ -24,16 +24,22 @@ import com.jfoenix.controls.JFXPopup; import com.jfoenix.controls.JFXRadioButton; import com.jfoenix.effects.JFXDepthManager; import javafx.geometry.Pos; +import javafx.scene.Node; import javafx.scene.control.SkinBase; import javafx.scene.image.ImageView; import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; import javafx.scene.layout.StackPane; +import javafx.scene.layout.VBox; import org.jackhuang.hmcl.setting.Theme; import org.jackhuang.hmcl.ui.FXUtils; import org.jackhuang.hmcl.ui.SVG; +import org.jackhuang.hmcl.ui.construct.IconedItem; import org.jackhuang.hmcl.ui.construct.TwoLineListItem; +import java.util.function.Consumer; +import java.util.function.Function; + import static org.jackhuang.hmcl.util.i18n.I18n.i18n; public class GameListItemSkin extends SkinBase { @@ -68,42 +74,30 @@ public class GameListItemSkin extends SkinBase { center.getChildren().setAll(imageView, item); root.setCenter(center); - JFXListView menu = new JFXListView<>(); - menu.getItems().setAll( - i18n("settings"), - i18n("version.manage.rename"), - i18n("version.manage.remove"), - i18n("modpack.export"), - i18n("folder.game"), - i18n("version.launch"), - i18n("version.launch_script")); + VBox menu = new VBox(); JFXPopup popup = new JFXPopup(menu); - menu.setOnMouseClicked(e -> { + + Function wrap = r -> () -> { + r.run(); popup.hide(); - switch (menu.getSelectionModel().getSelectedIndex()) { - case 0: - skinnable.modifyGameSettings(); - break; - case 1: - skinnable.rename(); - break; - case 2: - skinnable.remove(); - break; - case 3: - skinnable.export(); - break; - case 4: - skinnable.browse(); - break; - case 5: - skinnable.launch(); - break; - case 6: - skinnable.generateLaunchScript(); - break; - } - }); + }; + + Function limitWidth = node -> { + StackPane pane = new StackPane(node); + pane.setAlignment(Pos.CENTER); + FXUtils.setLimitWidth(pane, 14); + FXUtils.setLimitHeight(pane, 14); + return pane; + }; + + menu.getChildren().setAll( + new IconedItem(limitWidth.apply(SVG.gear(Theme.blackFillBinding(), 14, 14)), i18n("settings"), "menu-iconed-item").setClickedAction(wrap.apply(skinnable::modifyGameSettings)), + new IconedItem(limitWidth.apply(SVG.pencil(Theme.blackFillBinding(), 14, 14)), i18n("version.manage.rename"), "menu-iconed-item").setClickedAction(wrap.apply(skinnable::rename)), + new IconedItem(limitWidth.apply(SVG.delete(Theme.blackFillBinding(), 14, 14)), i18n("version.manage.remove"), "menu-iconed-item").setClickedAction(wrap.apply(skinnable::remove)), + new IconedItem(limitWidth.apply(SVG.export(Theme.blackFillBinding(), 14, 14)), i18n("modpack.export"), "menu-iconed-item").setClickedAction(wrap.apply(skinnable::export)), + new IconedItem(limitWidth.apply(SVG.folderOpen(Theme.blackFillBinding(), 14, 14)), i18n("folder.game"), "menu-iconed-item").setClickedAction(wrap.apply(skinnable::browse)), + new IconedItem(limitWidth.apply(SVG.launch(Theme.blackFillBinding(), 14, 14)), i18n("version.launch"), "menu-iconed-item").setClickedAction(wrap.apply(skinnable::launch)), + new IconedItem(limitWidth.apply(SVG.script(Theme.blackFillBinding(), 14, 14)), i18n("version.launch_script"), "menu-iconed-item").setClickedAction(wrap.apply(skinnable::generateLaunchScript))); HBox right = new HBox(); right.setAlignment(Pos.CENTER_RIGHT); @@ -118,7 +112,6 @@ public class GameListItemSkin extends SkinBase { JFXButton btnManage = new JFXButton(); btnManage.setOnMouseClicked(e -> { - menu.getSelectionModel().select(-1); popup.show(root, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.RIGHT, 0, root.getHeight()); }); btnManage.getStyleClass().add("toggle-icon4");