在世界管理界面显示世界图标 (#3689)

* 在世界管理界面显示世界图标

* update

* update
This commit is contained in:
Glavo
2025-03-03 02:12:07 +08:00
committed by GitHub
parent 4292d47fe8
commit 0540f3c9cd
4 changed files with 37 additions and 3 deletions

View File

@@ -48,8 +48,8 @@ public class WorldListItem extends Control {
this.world = world;
title.set(parseColorEscapes(world.getWorldName()));
subtitle.set(i18n("world.description", world.getFileName(), formatDateTime(Instant.ofEpochMilli(world.getLastPlayed())), world.getGameVersion() == null ? i18n("message.unknown") : world.getGameVersion()));
image.set(world.getIcon());
FXUtils.onClicked(this, this::showInfo);
}

View File

@@ -19,9 +19,11 @@ package org.jackhuang.hmcl.ui.versions;
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXPopup;
import javafx.beans.value.ChangeListener;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.SkinBase;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
@@ -38,6 +40,9 @@ import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
public class WorldListItemSkin extends SkinBase<WorldListItem> {
@SuppressWarnings({"FieldCanBeLocal", "unused"})
private final ChangeListener<Image> iconListener;
public WorldListItemSkin(WorldListItem skinnable) {
super(skinnable);
@@ -54,14 +59,15 @@ public class WorldListItemSkin extends SkinBase<WorldListItem> {
ImageView imageView = new ImageView();
FXUtils.limitSize(imageView, 32, 32);
imageView.imageProperty().bind(skinnable.imageProperty());
iconListener = FXUtils.onWeakChangeAndOperate(skinnable.imageProperty(), image ->
imageView.setImage(image == null ? FXUtils.newBuiltinImage("/assets/img/unknown_server.png") : image));
imageViewContainer.getChildren().setAll(imageView);
TwoLineListItem item = new TwoLineListItem();
item.titleProperty().bind(skinnable.titleProperty());
item.subtitleProperty().bind(skinnable.subtitleProperty());
BorderPane.setAlignment(item, Pos.CENTER);
center.getChildren().setAll(imageView, item);
center.getChildren().setAll(imageViewContainer, item);
root.setCenter(center);
PopupMenu menu = new PopupMenu();

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB