Skip to content

Commit 77397f6

Browse files
authored
优化离线账户中包含非 ASCII 字符时的提示 (#3853)
1 parent c9ba789 commit 77397f6

4 files changed

Lines changed: 30 additions & 10 deletions

File tree

HMCL/src/main/java/org/jackhuang/hmcl/ui/account/CreateAccountPane.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
import com.jfoenix.controls.*;
2121
import com.jfoenix.validation.base.ValidatorBase;
22+
import javafx.animation.KeyFrame;
23+
import javafx.animation.KeyValue;
24+
import javafx.animation.Timeline;
2225
import javafx.application.Platform;
2326
import javafx.beans.NamedArg;
2427
import javafx.beans.binding.BooleanBinding;
@@ -36,6 +39,7 @@
3639
import javafx.scene.control.TextInputControl;
3740
import javafx.scene.layout.*;
3841

42+
import javafx.util.Duration;
3943
import org.jackhuang.hmcl.Metadata;
4044
import org.jackhuang.hmcl.auth.AccountFactory;
4145
import org.jackhuang.hmcl.auth.CharacterSelector;
@@ -264,16 +268,33 @@ private void onAccept() {
264268
};
265269

266270
if (factory instanceof OfflineAccountFactory && username != null && !USERNAME_CHECKER_PATTERN.matcher(username).matches()) {
267-
Controllers.confirm(
271+
JFXButton btnYes = new JFXButton(i18n("button.ok"));
272+
btnYes.getStyleClass().add("dialog-error");
273+
btnYes.setOnAction(e -> doCreate.run());
274+
btnYes.setDisable(true);
275+
276+
int countdown = 10;
277+
KeyFrame[] keyFrames = new KeyFrame[countdown + 1];
278+
for (int i = 0; i < countdown; i++) {
279+
keyFrames[i] = new KeyFrame(Duration.seconds(i),
280+
new KeyValue(btnYes.textProperty(), i18n("button.ok.countdown", countdown - i)));
281+
}
282+
keyFrames[countdown] = new KeyFrame(Duration.seconds(countdown),
283+
new KeyValue(btnYes.textProperty(), i18n("button.ok")),
284+
new KeyValue(btnYes.disableProperty(), false));
285+
286+
Timeline timeline = new Timeline(keyFrames);
287+
Controllers.confirmAction(
268288
i18n("account.methods.offline.name.invalid"), i18n("message.warning"),
269289
MessageDialogPane.MessageType.WARNING,
270-
doCreate,
290+
btnYes,
271291
() -> {
272-
lblErrorMessage.setText(i18n("account.methods.offline.name.invalid.tip"));
292+
timeline.stop();
273293
body.setDisable(false);
274294
spinner.hideSpinner();
275295
}
276296
);
297+
timeline.play();
277298
} else {
278299
doCreate.run();
279300
}

HMCL/src/main/resources/assets/lang/I18N.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,12 @@ account.methods.microsoft.snapshot=You are using an unofficial build of HMCL. Pl
124124
account.methods.microsoft.snapshot.website=Official Website
125125
account.methods.offline=Offline
126126
account.methods.offline.name.special_characters=Using only English letters, numbers, and underscores is recommended
127-
account.methods.offline.name.invalid.tip=It is recommended to use only English letters, numbers and underscores for the username, and the length should not exceed 16 characters.
128127
account.methods.offline.name.invalid=It is recommended to use only English letters, numbers and underscores for the username, and the length should not exceed 16 characters.\n\
129128
\n\
130129
\ · Legitimate: HuangYu, huang_Yu, Huang_Yu_123;\n\
131130
\ · Illegal: Huang Yu, Huang-Yu_%%%, Huang_Yu_hello_world_hello_world.\n\
132131
\n\
133-
If you believe there is a corresponding mod or plugin on the server side to remove this restriction, you can ignore this warning.
132+
Using the illegal username will prevent you from joining most servers and may conflict with some mods, causing the game to crash.
134133
account.methods.offline.uuid=UUID
135134
account.methods.offline.uuid.hint=UUID is a unique identifier for Minecraft players, and each launcher may generate UUIDs differently. Changing it to the one generated by other launchers allows you to keep your items in your offline account inventory.\n\
136135
\n\
@@ -181,6 +180,7 @@ button.install=Install
181180
button.export=Export
182181
button.no=No
183182
button.ok=OK
183+
button.ok.countdown=OK (%d)
184184
button.refresh=Refresh
185185
button.remove=Remove
186186
button.remove.confirm=Are you sure you want to permanently remove it? This action cannot be undone!

HMCL/src/main/resources/assets/lang/I18N_zh.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,12 @@ account.methods.microsoft.snapshot=你正在使用第三方提供的 HMCL,請
130130
account.methods.microsoft.snapshot.website=官方網站
131131
account.methods.offline=離線模式
132132
account.methods.offline.name.special_characters=建議使用英文字母、數字以及底線命名
133-
account.methods.offline.name.invalid.tip=遊戲使用者名稱建議僅使用英文字母、數字及底線,且長度不超過 16 個字元。
134133
account.methods.offline.name.invalid=遊戲使用者名稱建議僅使用英文字母、數字及底線,且長度不超過 16 個字元。\n\
135134
\n\
136135
\ · 一些有效的使用者名稱:HuangYu、huang_Yu、Huang_Yu_123;\n\
137136
\ · 一些無效的使用者名稱:黃魚,Huang Yu、Huang-Yu_%%%、Huang_Yu_hello_world_hello_world。\n\
138137
\n\
139-
如果你相信伺服器端有相應的模組或插件來解除此限制,你可以忽略本警告
138+
使用非法使用者名稱會導致你無法加入大部分伺服器,並可能與部分模組衝突而使遊戲崩潰
140139
account.methods.offline.uuid=UUID
141140
account.methods.offline.uuid.hint=UUID 是 Minecraft 玩家的唯一標識符,每個啟動器生成 UUID 的方式可能不同。\n透過修改 UUID 選項至原啟動器所生成的 UUID,你可以保證在切換啟動器後,遊戲還能將你的遊戲角色識別為給定 UUID 所對應的角色,從而保留原來角色的背包物品。\nUUID 選項為進階選項,除非你知道你在做什麼,否則你不需要調整該選項。
142141
account.methods.offline.uuid.malformed=格式錯誤
@@ -184,6 +183,7 @@ button.install=安裝
184183
button.export=匯出
185184
button.no=
186185
button.ok=確定
186+
button.ok.countdown=確定 (%d)
187187
button.refresh=重新整理
188188
button.remove=刪除
189189
button.remove.confirm=你確認要刪除嗎?該操作無法復原!

HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,12 @@ account.methods.microsoft.snapshot=你正在使用第三方提供的 HMCL,请
138138
account.methods.microsoft.snapshot.website=官方网站
139139
account.methods.offline=离线模式
140140
account.methods.offline.name.special_characters=建议使用英文字符、数字以及下划线命名
141-
account.methods.offline.name.invalid.tip=游戏用户名建议仅使用英文字母、数字及下划线,且长度不超过 16 个字符。
142141
account.methods.offline.name.invalid=游戏用户名建议仅使用英文字母、数字及下划线,且长度不超过 16 个字符。\n\
143142
\n\
144143
\ · 一些合法用户名:HuangYu、huang_Yu、Huang_Yu_123;\n\
145144
\ · 一些非法用户名:黄鱼、Huang Yu、Huang-Yu_%%%、Huang_Yu_hello_world_hello_world。\n\
146145
\n\
147-
如果你相信服务端有相应模组或插件解除此限制,可以忽略本警告。\n\
148-
如遇到问题,你可以点击右上角帮助按钮进行求助。
146+
使用非法用户名会导致你无法加入大部分服务器,并可能与部分模组冲突而使游戏崩溃。
149147
account.methods.offline.uuid=UUID
150148
account.methods.offline.uuid.hint=UUID 是 Minecraft 玩家的唯一标识符,每个启动器生成 UUID 的方式可能不同。通过将 UUID 修改为原启动器所生成的 UUID,你可以保证在切换启动器后,游戏还能将你的游戏角色识别为给定 UUID 所对应的角色,从而保留原角色的背包物品。UUID 选项为高级选项,除非你知道你在做什么,否则你不需要调整该选项。
151149
account.methods.offline.uuid.malformed=格式错误
@@ -193,6 +191,7 @@ button.install=安装
193191
button.export=导出
194192
button.no=
195193
button.ok=确定
194+
button.ok.countdown=确定 (%d)
196195
button.refresh=刷新
197196
button.remove=删除
198197
button.remove.confirm=你确定要删除吗?此操作无法撤销!

0 commit comments

Comments
 (0)