feat: open mcbbs/mcmod page in mod info/mod donwload page.

This commit is contained in:
huanghongxun 2021-09-12 01:09:16 +08:00
parent d7f5109a65
commit 5057691fb3
2 changed files with 39 additions and 22 deletions

View File

@ -22,6 +22,13 @@ import org.jackhuang.hmcl.setting.Theme;
import org.jackhuang.hmcl.ui.SVG; import org.jackhuang.hmcl.ui.SVG;
public class JFXHyperlink extends Hyperlink { public class JFXHyperlink extends Hyperlink {
public JFXHyperlink() {
super();
setGraphic(SVG.launchOutline(Theme.blackFillBinding(), 16, 16));
}
public JFXHyperlink(String text) { public JFXHyperlink(String text) {
super(text); super(text);

View File

@ -35,6 +35,7 @@ import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority; import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane; import javafx.scene.layout.StackPane;
import org.jackhuang.hmcl.mod.ModInfo; import org.jackhuang.hmcl.mod.ModInfo;
import org.jackhuang.hmcl.mod.ModManager;
import org.jackhuang.hmcl.setting.Theme; import org.jackhuang.hmcl.setting.Theme;
import org.jackhuang.hmcl.task.Schedulers; import org.jackhuang.hmcl.task.Schedulers;
import org.jackhuang.hmcl.task.Task; import org.jackhuang.hmcl.task.Task;
@ -202,15 +203,29 @@ class ModListPageSkin extends SkinBase<ModListPage> {
Label description = new Label(modInfo.getModInfo().getDescription().toString()); Label description = new Label(modInfo.getModInfo().getDescription().toString());
setBody(description); setBody(description);
JFXButton okButton = new JFXButton(); if (StringUtils.isNotBlank(modInfo.getModInfo().getUrl())) {
okButton.getStyleClass().add("dialog-accept"); JFXHyperlink officialPageButton = new JFXHyperlink();
okButton.setText(i18n("button.ok")); officialPageButton.setText(i18n("mods.url"));
okButton.setOnAction(e -> fireEvent(new DialogCloseEvent())); officialPageButton.setOnAction(e -> {
fireEvent(new DialogCloseEvent());
FXUtils.openLink(modInfo.getModInfo().getUrl());
});
JFXButton searchButton = new JFXButton(); getActions().add(officialPageButton);
searchButton.getStyleClass().add("dialog-cancel"); }
if (modInfo.getMod() != null && StringUtils.isNotBlank(modInfo.getMod().getMcbbs())) {
JFXHyperlink mcbbsButton = new JFXHyperlink();
mcbbsButton.setText(i18n("mods.mcbbs"));
mcbbsButton.setOnAction(e -> {
fireEvent(new DialogCloseEvent());
FXUtils.openLink(ModManager.getMcbbsUrl(modInfo.getMod().getMcbbs()));
});
getActions().add(mcbbsButton);
}
if (modInfo.getMod() == null || StringUtils.isBlank(modInfo.getMod().getMcmod())) { if (modInfo.getMod() == null || StringUtils.isBlank(modInfo.getMod().getMcmod())) {
JFXHyperlink searchButton = new JFXHyperlink();
searchButton.setText(i18n("mods.mcmod.search")); searchButton.setText(i18n("mods.mcmod.search"));
searchButton.setOnAction(e -> { searchButton.setOnAction(e -> {
fireEvent(new DialogCloseEvent()); fireEvent(new DialogCloseEvent());
@ -220,27 +235,22 @@ class ModListPageSkin extends SkinBase<ModListPage> {
pair("filter", "0") pair("filter", "0")
))); )));
}); });
getActions().add(searchButton);
} else { } else {
searchButton.setText(i18n("mods.mcmod.page")); JFXHyperlink mcmodButton = new JFXHyperlink();
searchButton.setOnAction(e -> { mcmodButton.setText(i18n("mods.mcmod.page"));
mcmodButton.setOnAction(e -> {
fireEvent(new DialogCloseEvent()); fireEvent(new DialogCloseEvent());
FXUtils.openLink("https://www.mcmod.cn/class/" + modInfo.getMod().getMcmod() + ".html"); FXUtils.openLink(ModManager.getMcmodUrl(modInfo.getMod().getMcmod()));
}); });
getActions().add(mcmodButton);
} }
if (StringUtils.isNotBlank(modInfo.getModInfo().getUrl())) { JFXButton okButton = new JFXButton();
JFXButton officialPageButton = new JFXButton(); okButton.getStyleClass().add("dialog-accept");
officialPageButton.getStyleClass().add("dialog-cancel"); okButton.setText(i18n("button.ok"));
officialPageButton.setText(i18n("mods.url")); okButton.setOnAction(e -> fireEvent(new DialogCloseEvent()));
officialPageButton.setOnAction(e -> { getActions().add(okButton);
fireEvent(new DialogCloseEvent());
FXUtils.openLink(modInfo.getModInfo().getUrl());
});
setActions(okButton, officialPageButton, searchButton);
} else {
setActions(okButton, searchButton);
}
onEscPressed(this, okButton::fire); onEscPressed(this, okButton::fire);
} }