From 94ca81035bebdef22d79c991f16716a3eaa9d518 Mon Sep 17 00:00:00 2001 From: Glavo Date: Sat, 18 Oct 2025 22:18:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=99=B6=E7=93=A6=E8=81=94?= =?UTF-8?q?=E6=9C=BA=E7=9A=84=E5=A4=8D=E5=88=B6=E9=82=80=E8=AF=B7=E7=A0=81?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=20(#4687)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/jackhuang/hmcl/ui/FXUtils.java | 8 +++-- .../terracotta/TerracottaControllerPage.java | 34 +++++++------------ .../resources/assets/lang/I18N.properties | 1 + .../resources/assets/lang/I18N_zh.properties | 1 + .../assets/lang/I18N_zh_CN.properties | 1 + 5 files changed, 21 insertions(+), 24 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java index 6c7e58bfd..b2385f3f5 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java @@ -1411,12 +1411,16 @@ public final class FXUtils { } public static void copyText(String text) { + copyText(text, i18n("message.copied")); + } + + public static void copyText(String text, @Nullable String toastMessage) { ClipboardContent content = new ClipboardContent(); content.putString(text); Clipboard.getSystemClipboard().setContent(content); - if (!Controllers.isStopped()) { - Controllers.showToast(i18n("message.copied")); + if (toastMessage != null && !Controllers.isStopped()) { + Controllers.showToast(toastMessage); } } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/terracotta/TerracottaControllerPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/terracotta/TerracottaControllerPage.java index efb753f67..d96988a00 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/terracotta/TerracottaControllerPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/terracotta/TerracottaControllerPage.java @@ -34,11 +34,8 @@ import javafx.scene.Cursor; import javafx.scene.Node; import javafx.scene.control.Label; import javafx.scene.control.ScrollPane; -import javafx.scene.control.TextField; import javafx.scene.image.Image; import javafx.scene.image.ImageView; -import javafx.scene.input.Clipboard; -import javafx.scene.input.ClipboardContent; import javafx.scene.layout.HBox; import javafx.scene.layout.Priority; import javafx.scene.layout.StackPane; @@ -342,6 +339,7 @@ public class TerracottaControllerPage extends StackPane { return; } else { String cs = hostOK.getCode(); + copyCode(cs); statusProperty.set(i18n("terracotta.status.host_ok")); progressProperty.set(1); @@ -350,36 +348,24 @@ public class TerracottaControllerPage extends StackPane { code.setAlignment(Pos.CENTER); { Label desc = new Label(i18n("terracotta.status.host_ok.code")); - { - ClipboardContent cp = new ClipboardContent(); - cp.putString(cs); - Clipboard.getSystemClipboard().setContent(cp); - } + desc.setMouseTransparent(true); - // FIXME: The implementation to display Room Code is ambiguous. Consider using a clearer JavaFX Element in the future. - TextField label = new TextField(cs); - label.setEditable(false); - label.setFocusTraversable(false); + Label label = new Label(cs); + label.setMouseTransparent(true); + label.setStyle("-fx-font-size: 24"); label.setAlignment(Pos.CENTER); - label.setStyle("-fx-background-color: transparent; -fx-border-color: transparent;"); VBox.setMargin(label, new Insets(10, 0, 10, 0)); - label.setScaleX(1.8); - label.setScaleY(1.8); - holder.add(FXUtils.onWeakChange(label.selectedTextProperty(), string -> { - if (string != null && !string.isEmpty() && !cs.equals(string)) { - label.selectAll(); - } - })); code.getChildren().setAll(desc, label); } - FXUtils.onClicked(code, () -> FXUtils.copyText(cs)); + code.setCursor(Cursor.HAND); + FXUtils.onClicked(code, () -> copyCode(cs)); LineButton copy = LineButton.of(); copy.setLeftIcon(SVG.CONTENT_COPY); copy.setTitle(i18n("terracotta.status.host_ok.code.copy")); copy.setSubtitle(i18n("terracotta.status.host_ok.code.desc")); - FXUtils.onClicked(copy, () -> FXUtils.copyText(cs)); + FXUtils.onClicked(copy, () -> copyCode(cs)); LineButton back = LineButton.of(); back.setLeftIcon(SVG.ARROW_BACK); @@ -601,6 +587,10 @@ public class TerracottaControllerPage extends StackPane { return locals; } + private void copyCode(String code) { + FXUtils.copyText(code, i18n("terracotta.status.host_ok.code.copy.toast")); + } + private static final class LineButton extends RipplerContainer { private final WeakListenerHolder holder = new WeakListenerHolder(); diff --git a/HMCL/src/main/resources/assets/lang/I18N.properties b/HMCL/src/main/resources/assets/lang/I18N.properties index 823a2eeb2..b59ab34f7 100644 --- a/HMCL/src/main/resources/assets/lang/I18N.properties +++ b/HMCL/src/main/resources/assets/lang/I18N.properties @@ -1460,6 +1460,7 @@ terracotta.status.host_starting.back=This will stop creating the room. terracotta.status.host_ok=Room created terracotta.status.host_ok.code=Invitation code (Copied) terracotta.status.host_ok.code.copy=Copy invitation code +terracotta.status.host_ok.code.copy.toast=Invitation code has been copied to clipboard terracotta.status.host_ok.code.desc=Please remind your friends to select Guest mode in HMCL - Multiplayer or PCL CE and enter this invitation code. terracotta.status.host_ok.back=This will also close the room, other guests will leave and cannot rejoin. terracotta.status.guest_starting=Joining room diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh.properties b/HMCL/src/main/resources/assets/lang/I18N_zh.properties index 96eeab477..c97225c87 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh.properties @@ -1248,6 +1248,7 @@ terracotta.status.host_starting.back=這將會取消建立房間。 terracotta.status.host_ok=已建立房間 terracotta.status.host_ok.code=邀請碼 (已自動複製到剪貼簿) terracotta.status.host_ok.code.copy=複製邀請碼 +terracotta.status.host_ok.code.copy.toast=已將邀請碼複製到剪貼簿 terracotta.status.host_ok.code.desc=請提醒您的朋友在 HMCL 或 PCL CE 多人遊戲功能中選擇房客模式,並輸入該邀請碼。 terracotta.status.host_ok.back=這將同時徹底關閉房間,其他房客將退出並不再能重新加入該房間。 terracotta.status.guest_starting=正在加入房間 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 9596687c6..f05ee9608 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties @@ -1258,6 +1258,7 @@ terracotta.status.host_starting.back=这将会取消创建房间。 terracotta.status.host_ok=已启动房间 terracotta.status.host_ok.code=邀请码 (已自动复制到剪贴板) terracotta.status.host_ok.code.copy=复制邀请码 +terracotta.status.host_ok.code.copy.toast=已将邀请码复制到剪贴板 terracotta.status.host_ok.code.desc=请提醒您的朋友在 HMCL 或 PCL CE 多人联机功能中选择房客模式,并输入该邀请码。 terracotta.status.host_ok.back=这将同时彻底关闭房间,其他房客将退出并不再能重新加入该房间。 terracotta.status.guest_starting=正在加入房间