Skip to content

Commit

Permalink
在游戏下载列表中添加 Minecraft Wiki 链接 (#3435)
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavo authored Nov 14, 2024
1 parent fa66549 commit 355df21
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.jackhuang.hmcl.setting.Theme;
import org.jackhuang.hmcl.ui.FXUtils;
import org.jackhuang.hmcl.ui.SVG;
import org.jackhuang.hmcl.util.Lazy;
import org.jackhuang.hmcl.util.StringUtils;

public class IconedTwoLineListItem extends HBox {
Expand All @@ -29,13 +28,8 @@ public class IconedTwoLineListItem extends HBox {

private final ImageView imageView = new ImageView();
private final TwoLineListItem twoLineListItem = new TwoLineListItem();
private final Lazy<JFXButton> externalLinkButton = new Lazy<>(() -> {
JFXButton button = new JFXButton();
button.getStyleClass().add("toggle-icon4");
button.setGraphic(SVG.OPEN_IN_NEW.createIcon(Theme.blackFill(), -1, -1));
button.setOnAction(e -> FXUtils.openLink(externalLink.get()));
return button;
});
private JFXButton externalLinkButton;

@SuppressWarnings("FieldCanBeLocal")
private final InvalidationListener observer;

Expand All @@ -52,7 +46,7 @@ public IconedTwoLineListItem() {
getChildren().clear();
if (image.get() != null) getChildren().add(imageView);
getChildren().add(twoLineListItem);
if (StringUtils.isNotBlank(externalLink.get())) getChildren().add(externalLinkButton.get());
if (StringUtils.isNotBlank(externalLink.get())) getChildren().add(getExternalLinkButton());
}, image, externalLink);
}

Expand Down Expand Up @@ -111,4 +105,14 @@ public void setImage(Image image) {
public ImageView getImageView() {
return imageView;
}

public JFXButton getExternalLinkButton() {
if (externalLinkButton == null) {
externalLinkButton = new JFXButton();
externalLinkButton.getStyleClass().add("toggle-icon4");
externalLinkButton.setGraphic(SVG.OPEN_IN_NEW.createIcon(Theme.blackFill(), -1, -1));
externalLinkButton.setOnAction(e -> FXUtils.openLink(externalLink.get()));
}
return externalLinkButton;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public VersionsPage(Navigation navigation, String title, String gameVersion, Dow
btnRefresh.setGraphic(wrap(SVG.REFRESH.createIcon(Theme.blackFill(), -1, -1)));

Holder<RemoteVersionListCell> lastCell = new Holder<>();
list.setCellFactory(listView -> new RemoteVersionListCell(lastCell));
list.setCellFactory(listView -> new RemoteVersionListCell(lastCell, libraryId));

FXUtils.onClicked(list, () -> {
if (list.getSelectionModel().getSelectedIndex() < 0)
Expand Down Expand Up @@ -272,8 +272,12 @@ private static class RemoteVersionListCell extends ListCell<RemoteVersion> {

private final Holder<RemoteVersionListCell> lastCell;

RemoteVersionListCell(Holder<RemoteVersionListCell> lastCell) {
RemoteVersionListCell(Holder<RemoteVersionListCell> lastCell, String libraryId) {
this.lastCell = lastCell;
if ("game".equals(libraryId)) {
content.getExternalLinkButton().setGraphic(SVG.EARTH.createIcon(Theme.blackFill(), -1, -1));
FXUtils.installFastTooltip(content.getExternalLinkButton(), i18n("wiki.tooltip"));
}

pane.getStyleClass().add("md-list-cell");
StackPane.setMargin(content, new Insets(10, 16, 10, 16));
Expand Down Expand Up @@ -307,14 +311,19 @@ public void updateItem(RemoteVersion remoteVersion, boolean empty) {
case RELEASE:
content.getTags().setAll(i18n("version.game.release"));
content.setImage(VersionIconType.GRASS.getIcon());
content.setExternalLink(i18n("wiki.version.game.release", remoteVersion.getGameVersion()));
break;
case SNAPSHOT:
content.getTags().setAll(i18n("version.game.snapshot"));
content.setImage(VersionIconType.COMMAND.getIcon());


content.setExternalLink(i18n("wiki.version.game.snapshot", remoteVersion.getGameVersion()));
break;
default:
content.getTags().setAll(i18n("version.game.old"));
content.setImage(VersionIconType.CRAFT_TABLE.getIcon());
content.setExternalLink(null);
break;
}
} else {
Expand All @@ -339,6 +348,7 @@ else if (remoteVersion instanceof QuiltRemoteVersion || remoteVersion instanceof
content.setSubtitle(remoteVersion.getGameVersion());
else
content.getTags().setAll(remoteVersion.getGameVersion());
content.setExternalLink(null);
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions HMCL/src/main/resources/assets/lang/I18N.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,10 @@ version.manage.rename.fail=Failed to rename the instance, some files might be in
version.settings=Settings
version.update=Update Modpack

wiki.tooltip=Minecraft Wiki Page
wiki.version.game.release=https://minecraft.wiki/w/Java_Edition_%s
wiki.version.game.snapshot=https://minecraft.wiki/w/Java_Edition_%s

wizard.prev=< Prev
wizard.failed=Failed
wizard.finish=Finish
Expand Down
4 changes: 4 additions & 0 deletions HMCL/src/main/resources/assets/lang/I18N_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,10 @@ version.manage.rename.fail=重新命名版本失敗,可能檔案被佔用或
version.settings=遊戲設定
version.update=更新模組包

wiki.tooltip=Minecraft Wiki 頁面
wiki.version.game.release=https://zh.minecraft.wiki/w/Java版%s?variant=zh-tw
wiki.version.game.snapshot=https://zh.minecraft.wiki/w/%s?variant=zh-tw

wizard.prev=< 上一步
wizard.failed=失敗
wizard.finish=完成
Expand Down
4 changes: 4 additions & 0 deletions HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,10 @@ version.manage.rename.fail=重命名版本失败,可能文件被占用或者
version.settings=游戏设置
version.update=更新整合包

wiki.tooltip=Minecraft Wiki 页面
wiki.version.game.release=https://zh.minecraft.wiki/w/Java版%s?variant=zh-cn
wiki.version.game.snapshot=https://zh.minecraft.wiki/w/%s?variant=zh-cn

wizard.prev=< 上一步
wizard.failed=失败
wizard.finish=完成
Expand Down

0 comments on commit 355df21

Please sign in to comment.