From 5edd7a7b72e011a214ac8246561a8866e5e54a15 Mon Sep 17 00:00:00 2001 From: huanghongxun Date: Thu, 26 Aug 2021 03:11:23 +0800 Subject: [PATCH] feat: help page --- .../main/java/org/jackhuang/hmcl/ui/SVG.java | 6 + .../org/jackhuang/hmcl/ui/main/AboutPage.java | 18 +++ .../org/jackhuang/hmcl/ui/main/HelpPage.java | 129 ++++++++++++++++++ .../hmcl/ui/main/LauncherSettingsPage.java | 13 +- .../jackhuang/hmcl/ui/main/SettingsView.java | 2 +- .../resources/assets/lang/I18N.properties | 3 +- .../assets/lang/I18N_zh_CN.properties | 3 +- 7 files changed, 170 insertions(+), 4 deletions(-) create mode 100644 HMCL/src/main/java/org/jackhuang/hmcl/ui/main/HelpPage.java 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 336400396..f69d95746 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/SVG.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/SVG.java @@ -206,6 +206,12 @@ public final class SVG { fill, width, height); } + public static Node helpCircleOutline(ObjectBinding fill, double width, double height) { + return createSVGPath( + "M11,18H13V16H11V18M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,6A4,4 0 0,0 8,10H10A2,2 0 0,1 12,8A2,2 0 0,1 14,10C14,12 11,11.75 11,15H13C13,12.75 16,12.5 16,10A4,4 0 0,0 12,6Z", + fill, width, height); + } + public static Node alert(ObjectBinding fill, double width, double height) { return createSVGPath("M13,14H11V10H13M13,18H11V16H13M1,21H23L12,2L1,21Z", fill, width, height); } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/AboutPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/AboutPage.java index 0f05b5fc8..a6cab81c4 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/AboutPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/AboutPage.java @@ -1,3 +1,20 @@ +/* + * Hello Minecraft! Launcher + * Copyright (C) 2021 huangyuhui and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.jackhuang.hmcl.ui.main; import javafx.geometry.Insets; @@ -63,6 +80,7 @@ public class AboutPage extends StackPane { contributors.setTitle(i18n("about.thanks_to.contributors")); contributors.setSubtitle(i18n("about.thanks_to.contributors.statement")); contributors.setExternalLink("https://github.com/huanghongxun/HMCL/graphs/contributors"); + mcbbs.setExternalLink("https://hmcl.huangyuhui.net/api/redirect/sponsor"); IconedTwoLineListItem users = new IconedTwoLineListItem(); users.setImage(new Image("/assets/img/craft_table.png", 32, 32, false, true)); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/HelpPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/HelpPage.java new file mode 100644 index 000000000..12549d3e0 --- /dev/null +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/HelpPage.java @@ -0,0 +1,129 @@ +/* + * Hello Minecraft! Launcher + * Copyright (C) 2021 huangyuhui and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jackhuang.hmcl.ui.main; + +import com.google.gson.annotations.SerializedName; +import com.google.gson.reflect.TypeToken; +import javafx.geometry.Insets; +import javafx.scene.layout.VBox; +import org.jackhuang.hmcl.task.Schedulers; +import org.jackhuang.hmcl.task.Task; +import org.jackhuang.hmcl.ui.construct.ComponentList; +import org.jackhuang.hmcl.ui.construct.IconedTwoLineListItem; +import org.jackhuang.hmcl.ui.construct.SpinnerPane; +import org.jackhuang.hmcl.util.io.HttpRequest; + +import java.util.Collections; +import java.util.List; + +public class HelpPage extends SpinnerPane { + + private final VBox content; + + public HelpPage() { + content = new VBox(); + content.setPadding(new Insets(10)); + content.setSpacing(10); + content.setFillWidth(true); + setContent(content); + + loadHelp(); + } + + private void loadHelp() { + showSpinner(); + Task.>supplyAsync(() -> HttpRequest.GET("https://hmcl.huangyuhui.net/api/help/").getJson(new TypeToken>() { + }.getType())) + .thenAcceptAsync(Schedulers.javafx(), helpCategories -> { + for (HelpCategory category : helpCategories) { + ComponentList categoryPane = new ComponentList(); + + for (Help help : category.getItems()) { + IconedTwoLineListItem item = new IconedTwoLineListItem(); + item.setTitle(help.getTitle()); + item.setSubtitle(help.getSubtitle()); + item.setExternalLink(help.getUrl()); + + categoryPane.getContent().add(item); + } + + content.getChildren().add(ComponentList.createComponentListTitle(category.title)); + content.getChildren().add(categoryPane); + } + hideSpinner(); + }).start(); + } + + private static class HelpCategory { + @SerializedName("title") + private final String title; + + @SerializedName("items") + private final List items; + + public HelpCategory() { + this("", Collections.emptyList()); + } + + public HelpCategory(String title, List items) { + this.title = title; + this.items = items; + } + + public String getTitle() { + return title; + } + + public List getItems() { + return items; + } + } + + private static class Help { + @SerializedName("title") + private final String title; + + @SerializedName("subtitle") + private final String subtitle; + + @SerializedName("url") + private final String url; + + public Help() { + this("", "", ""); + } + + public Help(String title, String subtitle, String url) { + this.title = title; + this.subtitle = subtitle; + this.url = url; + } + + public String getTitle() { + return title; + } + + public String getSubtitle() { + return subtitle; + } + + public String getUrl() { + return url; + } + } +} diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/LauncherSettingsPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/LauncherSettingsPage.java index b63a6967c..77fca2189 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/LauncherSettingsPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/LauncherSettingsPage.java @@ -36,15 +36,17 @@ public class LauncherSettingsPage extends BorderPane implements DecoratorPage { private final ReadOnlyObjectWrapper state = new ReadOnlyObjectWrapper<>(new State(i18n("settings.launcher"), null, true, false, true, false, 200)); private final TabHeader tab; private final TabHeader.Tab settingsTab = new TabHeader.Tab<>("settingsPage"); + private final TabHeader.Tab helpTab = new TabHeader.Tab<>("helpPage"); private final TabHeader.Tab aboutTab = new TabHeader.Tab<>("aboutPage"); private final TabHeader.Tab sponsorTab = new TabHeader.Tab<>("sponsorPage"); private final TransitionPane transitionPane = new TransitionPane(); public LauncherSettingsPage() { settingsTab.setNodeSupplier(SettingsPage::new); + helpTab.setNodeSupplier(HelpPage::new); sponsorTab.setNodeSupplier(SponsorPage::new); aboutTab.setNodeSupplier(AboutPage::new); - tab = new TabHeader(settingsTab, sponsorTab, aboutTab); + tab = new TabHeader(settingsTab, helpTab, sponsorTab, aboutTab); tab.getSelectionModel().select(settingsTab); FXUtils.onChangeAndOperate(tab.getSelectionModel().selectedItemProperty(), newValue -> { @@ -61,6 +63,14 @@ public class LauncherSettingsPage extends BorderPane implements DecoratorPage { settingsItem.activeProperty().bind(tab.getSelectionModel().selectedItemProperty().isEqualTo(settingsTab)); settingsItem.setOnAction(e -> tab.getSelectionModel().select(settingsTab)); + AdvancedListItem helpItem = new AdvancedListItem(); + helpItem.getStyleClass().add("navigation-drawer-item"); + helpItem.setTitle(i18n("help")); + helpItem.setLeftGraphic(wrap(SVG.helpCircleOutline(null, 20, 20))); + helpItem.setActionButtonVisible(false); + helpItem.activeProperty().bind(tab.getSelectionModel().selectedItemProperty().isEqualTo(helpTab)); + helpItem.setOnAction(e -> tab.getSelectionModel().select(helpTab)); + AdvancedListItem sponsorItem = new AdvancedListItem(); sponsorItem.getStyleClass().add("navigation-drawer-item"); sponsorItem.setTitle(i18n("sponsor")); @@ -79,6 +89,7 @@ public class LauncherSettingsPage extends BorderPane implements DecoratorPage { AdvancedListBox sideBar = new AdvancedListBox() .add(settingsItem) + .add(helpItem) .add(sponsorItem) .add(aboutItem); FXUtils.setLimitWidth(sideBar, 200); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/SettingsView.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/SettingsView.java index b19ac13fd..467b25abc 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/SettingsView.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/SettingsView.java @@ -163,7 +163,7 @@ public abstract class SettingsView extends StackPane { { VBox headerLeft = new VBox(); - Label help = new Label(i18n("help")); + Label help = new Label(i18n("help.doc")); Label helpSubtitle = new Label(i18n("help.detail")); helpSubtitle.getStyleClass().add("subtitle-label"); diff --git a/HMCL/src/main/resources/assets/lang/I18N.properties b/HMCL/src/main/resources/assets/lang/I18N.properties index 4e6c178fd..b14d6c2d8 100644 --- a/HMCL/src/main/resources/assets/lang/I18N.properties +++ b/HMCL/src/main/resources/assets/lang/I18N.properties @@ -203,7 +203,8 @@ folder.resourcepacks=Resource packs folder.saves=Saves folder.screenshots=Screenshots -help=Documentations +help=Help +help.doc=Documentations help.detail=For manufacturers of datapacks, modpacks, etc. input.email=Username must be an email. diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties index 1b9c00157..261909fad 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties @@ -204,7 +204,8 @@ folder.resourcepacks=资源包文件夹 folder.saves=存档文件夹 folder.screenshots=截图文件夹 -help=Hello Minecraft! Launcher 帮助文档 +help=帮助 +help.doc=Hello Minecraft! Launcher 帮助文档 help.detail=可查阅数据包、整合包制作指南等内容。 input.email=用户名必须是邮箱