From b7d538c1e91587d28d31059b7418f4d889577a88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=9D=E6=9F=90=E4=BA=BABH?= <1218271192@qq.com> Date: Wed, 3 Sep 2025 19:27:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=AF=8F=E9=9A=94=E4=B8=A4=E7=A7=92=E6=9B=B4?= =?UTF-8?q?=E6=8D=A2=E2=80=9D=E5=B0=8F=E6=8F=90=E7=A4=BA=E2=80=9C=E3=80=82?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=8D=A2=E8=A1=8C=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/construct/TaskExecutorDialogPane.java | 24 +++++++++++++++++-- .../org/jackhuang/hmcl/util/RandomTip.java | 15 +++++++++--- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TaskExecutorDialogPane.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TaskExecutorDialogPane.java index d22f5f90b..ae8366648 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TaskExecutorDialogPane.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TaskExecutorDialogPane.java @@ -18,16 +18,22 @@ package org.jackhuang.hmcl.ui.construct; import com.jfoenix.controls.JFXButton; +import javafx.animation.Animation; +import javafx.animation.KeyFrame; +import javafx.animation.Timeline; import javafx.application.Platform; import javafx.beans.property.StringProperty; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.control.Label; import javafx.scene.layout.BorderPane; +import javafx.scene.layout.HBox; import javafx.scene.layout.Priority; import javafx.scene.layout.VBox; +import javafx.util.Duration; import org.jackhuang.hmcl.task.*; import org.jackhuang.hmcl.ui.FXUtils; +import org.jackhuang.hmcl.util.RandomTip; import org.jackhuang.hmcl.util.TaskCancellationAction; import org.jetbrains.annotations.NotNull; @@ -48,6 +54,7 @@ public class TaskExecutorDialogPane extends BorderPane { private final Label lblProgress; private final JFXButton btnCancel; private final Label lblBottomTip; + private final Timeline tipTimeline; private final TaskListPane taskListPane; public TaskExecutorDialogPane(@NotNull TaskCancellationAction cancel) { @@ -78,8 +85,10 @@ public class TaskExecutorDialogPane extends BorderPane { lblBottomTip = new Label(getRandomTip()); lblBottomTip.setStyle("-fx-text-fill: rgba(100, 100, 100, 0.9)"); lblBottomTip.setPadding(new Insets(0, 8, 0, 0)); - BorderPane.setAlignment(lblBottomTip, Pos.CENTER); - bottom.setCenter(lblBottomTip); + + HBox centerBox = new HBox(lblBottomTip); + centerBox.setAlignment(Pos.CENTER); + bottom.setCenter(centerBox); btnCancel = new JFXButton(i18n("button.cancel")); bottom.setRight(btnCancel); @@ -112,6 +121,10 @@ public class TaskExecutorDialogPane extends BorderPane { FileDownloadTask.speedEvent.channel(FetchTask.SpeedEvent.class).registerWeak(speedEventHandler); onEscPressed(this, btnCancel::fire); + + tipTimeline = new Timeline(new KeyFrame(Duration.seconds(2), e -> nextTip())); + tipTimeline.setCycleCount(Animation.INDEFINITE); + tipTimeline.play(); } public void setExecutor(TaskExecutor executor) { @@ -128,6 +141,7 @@ public class TaskExecutorDialogPane extends BorderPane { executor.addTaskListener(new TaskListener() { @Override public void onStop(boolean success, TaskExecutor executor) { + tipTimeline.stop(); Platform.runLater(() -> fireEvent(new DialogCloseEvent())); } }); @@ -151,4 +165,10 @@ public class TaskExecutorDialogPane extends BorderPane { runInFX(() -> btnCancel.setDisable(onCancel == null)); } + + private void nextTip() { + String old = lblBottomTip.getText(); + String next = RandomTip.getRandomTip(old); + Platform.runLater(() -> lblBottomTip.setText(next)); + } } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/util/RandomTip.java b/HMCL/src/main/java/org/jackhuang/hmcl/util/RandomTip.java index 900346082..41892faa7 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/util/RandomTip.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/util/RandomTip.java @@ -41,6 +41,14 @@ public class RandomTip { return formatTip(tip); } + public static String getRandomTip(String previous) { + String tip; + do { + tip = tips.get(getRandomTipIndex()); + } while (tips.size() > 1 && tip.equals(previous)); + return formatTip(tip); + } + private static String formatTip(String tip) { StringBuilder formattedTip = new StringBuilder(); int lineLength = 0; @@ -53,9 +61,10 @@ public class RandomTip { charLength = 2; // One Chinese character is considered as two characters } - if (lineLength + charLength > 50) { - // 49 characters per line - formattedTip.append("\n"); + // avoid leaving a single punctuation on the new line + if (lineLength + charLength > 51 && + !(Character.toString(c).matches("\\p{P}") && lineLength + charLength == 52)) { + formattedTip.append('\n'); lineLength = 0; }