From 8795d522b0cc4e64751bcf8bc9f5643b982a8eea Mon Sep 17 00:00:00 2001 From: Glavo Date: Tue, 11 Feb 2025 19:00:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=B8=B4=E6=97=B6=E9=9A=90?= =?UTF-8?q?=E8=97=8F=E9=A2=84=E8=A7=88=E7=89=88=E6=8F=90=E7=A4=BA=20(#3603?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hmcl/ui/construct/AnnouncementCard.java | 52 ---------------- .../org/jackhuang/hmcl/ui/main/MainPage.java | 61 +++++++++++++------ 2 files changed, 41 insertions(+), 72 deletions(-) delete mode 100644 HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/AnnouncementCard.java diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/AnnouncementCard.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/AnnouncementCard.java deleted file mode 100644 index 5e80222c4..000000000 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/AnnouncementCard.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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.construct; - -import javafx.scene.Cursor; -import javafx.scene.Node; -import javafx.scene.control.Label; -import javafx.scene.layout.BorderPane; -import javafx.scene.layout.VBox; -import javafx.scene.text.TextFlow; -import org.jackhuang.hmcl.setting.Theme; -import org.jackhuang.hmcl.ui.Controllers; -import org.jackhuang.hmcl.ui.FXUtils; -import org.jackhuang.hmcl.ui.SVG; - -public final class AnnouncementCard extends VBox { - - public AnnouncementCard(String title, String content, Runnable onClose) { - TextFlow body = FXUtils.segmentToTextFlow(content, Controllers::onHyperlinkAction); - body.setLineSpacing(4); - - BorderPane titleBar = new BorderPane(); - titleBar.getStyleClass().add("title"); - titleBar.setLeft(new Label(title)); - - if (onClose != null) { - Node hideNode = SVG.CLOSE.createIcon(Theme.blackFill(), 20, 20); - hideNode.setOnMouseClicked(e -> onClose.run()); - hideNode.setCursor(Cursor.HAND); - titleBar.setRight(hideNode); - } - - getChildren().setAll(titleBar, body); - setSpacing(16); - getStyleClass().addAll("card", "announcement"); - } -} diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/MainPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/MainPage.java index 7cded1d27..5727d2cba 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/MainPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/MainPage.java @@ -28,13 +28,16 @@ import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.geometry.Insets; import javafx.geometry.Pos; +import javafx.scene.Cursor; import javafx.scene.Node; import javafx.scene.control.Label; 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 javafx.scene.shape.Rectangle; +import javafx.scene.text.TextFlow; import javafx.util.Duration; import org.jackhuang.hmcl.Metadata; import org.jackhuang.hmcl.game.Version; @@ -47,7 +50,6 @@ import org.jackhuang.hmcl.ui.SVG; import org.jackhuang.hmcl.ui.animation.AnimationUtils; import org.jackhuang.hmcl.ui.animation.ContainerAnimations; import org.jackhuang.hmcl.ui.animation.TransitionPane; -import org.jackhuang.hmcl.ui.construct.AnnouncementCard; import org.jackhuang.hmcl.ui.construct.MessageDialogPane; import org.jackhuang.hmcl.ui.construct.PopupMenu; import org.jackhuang.hmcl.ui.construct.TwoLineListItem; @@ -102,23 +104,49 @@ public final class MainPage extends StackPane implements DecoratorPage { setPadding(new Insets(20)); if (Metadata.isNightly() || (Metadata.isDev() && !Objects.equals(Metadata.VERSION, config().getShownTips().get(ANNOUNCEMENT)))) { - AnnouncementCard announcementCard = null; - + String title; + String content; if (Metadata.isNightly()) { - announcementCard = new AnnouncementCard(i18n("update.channel.nightly.title"), i18n("update.channel.nightly.hint"), null); - } else if (Metadata.isDev()) { - announcementCard = new AnnouncementCard(i18n("update.channel.dev.title"), i18n("update.channel.dev.hint"), this::hideAnnouncementPane); + title = i18n("update.channel.nightly.title"); + content = i18n("update.channel.nightly.hint"); + } else { + title = i18n("update.channel.dev.title"); + content = i18n("update.channel.dev.hint"); } - if (announcementCard != null) { - VBox announcementBox = new VBox(16); - announcementBox.getChildren().add(announcementCard); + VBox announcementCard = new VBox(); - announcementPane = new TransitionPane(); - announcementPane.setContent(announcementBox, ContainerAnimations.NONE); + BorderPane titleBar = new BorderPane(); + titleBar.getStyleClass().add("title"); + titleBar.setLeft(new Label(title)); - getChildren().add(announcementPane); - } + Node hideNode = SVG.CLOSE.createIcon(Theme.blackFill(), 20, 20); + hideNode.setCursor(Cursor.HAND); + titleBar.setRight(hideNode); + FXUtils.onClicked(hideNode, () -> { + if (announcementPane != null) { + if (Metadata.isDev()) { + config().getShownTips().put(ANNOUNCEMENT, Metadata.VERSION); + } + + announcementPane.setContent(new StackPane(), ContainerAnimations.FADE); + } + }); + + TextFlow body = FXUtils.segmentToTextFlow(content, Controllers::onHyperlinkAction); + body.setLineSpacing(4); + + announcementCard.getChildren().setAll(titleBar, body); + announcementCard.setSpacing(16); + announcementCard.getStyleClass().addAll("card", "announcement"); + + VBox announcementBox = new VBox(16); + announcementBox.getChildren().add(announcementCard); + + announcementPane = new TransitionPane(); + announcementPane.setContent(announcementBox, ContainerAnimations.NONE); + + getChildren().add(announcementPane); } updatePane = new StackPane(); @@ -297,13 +325,6 @@ public final class MainPage extends StackPane implements DecoratorPage { showUpdate.set(false); } - public void hideAnnouncementPane() { - if (announcementPane != null) { - config().getShownTips().put(ANNOUNCEMENT, Metadata.VERSION); - announcementPane.setContent(new StackPane(), ContainerAnimations.FADE); - } - } - @Override public ReadOnlyObjectWrapper stateProperty() { return state;