mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-11 04:46:18 -04:00
支持临时隐藏预览版提示 (#3603)
This commit is contained in:
parent
d8e7e0e97e
commit
8795d522b0
@ -1,52 +0,0 @@
|
|||||||
/*
|
|
||||||
* Hello Minecraft! Launcher
|
|
||||||
* Copyright (C) 2021 huangyuhui <huanghongxun2008@126.com> 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 <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
|
@ -28,13 +28,16 @@ import javafx.collections.FXCollections;
|
|||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
|
import javafx.scene.Cursor;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
|
import javafx.scene.layout.BorderPane;
|
||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
import javafx.scene.layout.StackPane;
|
import javafx.scene.layout.StackPane;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.scene.shape.Rectangle;
|
import javafx.scene.shape.Rectangle;
|
||||||
|
import javafx.scene.text.TextFlow;
|
||||||
import javafx.util.Duration;
|
import javafx.util.Duration;
|
||||||
import org.jackhuang.hmcl.Metadata;
|
import org.jackhuang.hmcl.Metadata;
|
||||||
import org.jackhuang.hmcl.game.Version;
|
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.AnimationUtils;
|
||||||
import org.jackhuang.hmcl.ui.animation.ContainerAnimations;
|
import org.jackhuang.hmcl.ui.animation.ContainerAnimations;
|
||||||
import org.jackhuang.hmcl.ui.animation.TransitionPane;
|
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.MessageDialogPane;
|
||||||
import org.jackhuang.hmcl.ui.construct.PopupMenu;
|
import org.jackhuang.hmcl.ui.construct.PopupMenu;
|
||||||
import org.jackhuang.hmcl.ui.construct.TwoLineListItem;
|
import org.jackhuang.hmcl.ui.construct.TwoLineListItem;
|
||||||
@ -102,23 +104,49 @@ public final class MainPage extends StackPane implements DecoratorPage {
|
|||||||
setPadding(new Insets(20));
|
setPadding(new Insets(20));
|
||||||
|
|
||||||
if (Metadata.isNightly() || (Metadata.isDev() && !Objects.equals(Metadata.VERSION, config().getShownTips().get(ANNOUNCEMENT)))) {
|
if (Metadata.isNightly() || (Metadata.isDev() && !Objects.equals(Metadata.VERSION, config().getShownTips().get(ANNOUNCEMENT)))) {
|
||||||
AnnouncementCard announcementCard = null;
|
String title;
|
||||||
|
String content;
|
||||||
if (Metadata.isNightly()) {
|
if (Metadata.isNightly()) {
|
||||||
announcementCard = new AnnouncementCard(i18n("update.channel.nightly.title"), i18n("update.channel.nightly.hint"), null);
|
title = i18n("update.channel.nightly.title");
|
||||||
} else if (Metadata.isDev()) {
|
content = i18n("update.channel.nightly.hint");
|
||||||
announcementCard = new AnnouncementCard(i18n("update.channel.dev.title"), i18n("update.channel.dev.hint"), this::hideAnnouncementPane);
|
} else {
|
||||||
|
title = i18n("update.channel.dev.title");
|
||||||
|
content = i18n("update.channel.dev.hint");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (announcementCard != null) {
|
VBox announcementCard = new VBox();
|
||||||
VBox announcementBox = new VBox(16);
|
|
||||||
announcementBox.getChildren().add(announcementCard);
|
|
||||||
|
|
||||||
announcementPane = new TransitionPane();
|
BorderPane titleBar = new BorderPane();
|
||||||
announcementPane.setContent(announcementBox, ContainerAnimations.NONE);
|
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();
|
updatePane = new StackPane();
|
||||||
@ -297,13 +325,6 @@ public final class MainPage extends StackPane implements DecoratorPage {
|
|||||||
showUpdate.set(false);
|
showUpdate.set(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hideAnnouncementPane() {
|
|
||||||
if (announcementPane != null) {
|
|
||||||
config().getShownTips().put(ANNOUNCEMENT, Metadata.VERSION);
|
|
||||||
announcementPane.setContent(new StackPane(), ContainerAnimations.FADE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ReadOnlyObjectWrapper<State> stateProperty() {
|
public ReadOnlyObjectWrapper<State> stateProperty() {
|
||||||
return state;
|
return state;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user