Skip to content

Conversation

hmr-BH
Copy link

@hmr-BH hmr-BH commented Sep 3, 2025

删除了原有的换行算法,优化“小提示”布局,使下载速度计数与之对齐。
PixPin_2025-09-03_13-47-50

目前实现了繁体中文和英文的翻译(由Kimi翻译)如果有不准确的地方,敬请指出。

@hmr-BH hmr-BH mentioned this pull request Sep 3, 2025
@hmr-BH
Copy link
Author

hmr-BH commented Sep 3, 2025

#3683

@zkitefly
Copy link
Member

zkitefly commented Sep 3, 2025

可以增加自定义功能吗

@hmr-BH
Copy link
Author

hmr-BH commented Sep 3, 2025

可以增加自定义功能吗

可以

@hmr-BH hmr-BH changed the title feat: 实现启动界面的“小提示”内容 2.0 feat: 实现启动界面的“小提示”文字 2.0 Sep 3, 2025
@hmr-BH hmr-BH marked this pull request as draft September 3, 2025 09:09
Copy link
Member

@burningtnt burningtnt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应当使用 JavaFX 在图形化界面上完成文本居中,可尝试实现依一定时间间隔动态变更 tip。此外,请将文本配置放入独立的 JSON 文件中,避免代码和 I18N 耦合提示的个数。

@hmr-BH
Copy link
Author

hmr-BH commented Sep 3, 2025

应当使用 JavaFX 在图形化界面上完成文本居中,可尝试实现依一定时间间隔动态变更 tip。此外,请将文本配置放入独立的 JSON 文件中,避免代码和 I18N 耦合提示的个数。
那么是要为每种语言都创建一个JSON文件吗?还是要怎么做?

}

private static int getRandomTipIndex() {
return ThreadLocalRandom.current().nextInt(tips.size());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应当自行设计带有“保底”伪随机生成逻辑

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应当自行设计带有“保底”伪随机生成逻辑

让我思考一下(大脑过载

Copy link
Author

@hmr-BH hmr-BH Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应当自行设计带有“保底”伪随机生成逻辑

我大概是想复杂了

@burningtnt
Copy link
Member

那么是要为每种语言都创建一个JSON文件吗?还是要怎么做?

请使用 I18N.getLocale().getName() 作为 key,在同一个 json 文件中使用 key -> string[] 数据结构存储小提示

@hmr-BH
Copy link
Author

hmr-BH commented Sep 3, 2025

那么是要为每种语言都创建一个JSON文件吗?还是要怎么做?

请使用 I18N.getLocale().getName() 作为 key,在同一个 json 文件中使用 key -> string[] 数据结构存储小提示

了解

@Glavo
Copy link
Member

Glavo commented Sep 3, 2025

请使用 I18N.getLocale().getName() 作为 key,在同一个 json 文件中使用 key -> string[] 数据结构存储小提示

放到一个文件里的话,后期做更多语言的 i18n 支持就会比较麻烦,还是每个语言独立文件比较合适。

现在不着急改,我们在研究 #4373,做完之后本地化一些资源文件会更轻松。

@Glavo
Copy link
Member

Glavo commented Sep 3, 2025

6ab216d

现在你可以使用 I18n.getLocale().findBuiltinResource("xxx", "json") 来加载内置的本地化资源。

举个例子:如果当前语言环境为 zh-CN,调用 findBuiltinResource("assets.lang.foo", "json") 会尝试从 HMCL 内部依次查找以下资源:

  • assets/lang/foo_zh_Hans_CN.json
  • assets/lang/foo_zh_Hans.json
  • assets/lang/foo_zh_CN.json
  • assets/lang/foo_zh.json
  • assets/lang/foo.json

@hmr-BH
Copy link
Author

hmr-BH commented Sep 3, 2025

6ab216d

现在你可以使用 I18n.getLocale().findBuiltinResource("xxx", "json") 来加载内置的本地化资源。

举个例子:如果当前语言环境为 zh-CN,调用 findBuiltinResource("assets.lang.foo", "json") 会尝试从 HMCL 内部依次查找以下资源:

  • assets/lang/foo_zh_Hans_CN.json
  • assets/lang/foo_zh_Hans.json
  • assets/lang/foo_zh_CN.json
  • assets/lang/foo_zh.json
  • assets/lang/foo.json

明白
PixPin_2025-09-03_22-29-38

那我在I18N这些properties文件的同级目录创建一个launch_tips文件夹,里面专门放置翻译文件吧

@zkitefly
Copy link
Member

zkitefly commented Sep 4, 2025

希望可以在设置提供开关,因为可能会有人不喜欢这个提示


onEscPressed(this, btnCancel::fire);

tipTimeline = new Timeline(new KeyFrame(Duration.seconds(2), e -> nextTip()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我觉得 2 秒太短了,还没看完就跳了

return formatTip(tip);
}

private static String formatTip(String tip) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我不太理解为什么你依然在使用手动换行。JavaFX 的 TextFlow 控件可以非常方便的实现显示多行文本,可考虑迁移到 TextFlow

}

private void shuffle() {
for (int i = indices.size() - 1; i > 0; i--) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

java.util.Collections#shuffle(java.util.List<?>)


public final class RandomTip {

private static final List<String> tips;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的数据结构完全可以修改为:
`

private static final List<String> tips;
private static int index;

在 index 不断自增到 tips.length() 后,使用 Collections.shuffle 打乱 tips,然后重置 index 到 0


getChildren().add(tfwBottomTip);

tipTimeline = new Timeline(new KeyFrame(Duration.seconds(2), e -> nextTip()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里 e -> nextTip 隐式捕获了 this。在 JavaFX 上,这是否会导致潜在的内存泄漏?

@Glavo

private final Text bottomTipText;
private final TextFlow tfwBottomTip;
private final Timeline tipTimeline;
private static final List<String> tips;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你可以就地打乱 tips,而不需要保存一份原本的,每次从原本顺序打乱。

private final Timeline tipTimeline;
private static final List<String> tips;
private static final List<String> shuffledTips;
private static final Random random = new Random();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ThreadLocalRandom::current()

tfwBottomTip.setTextAlignment(TextAlignment.CENTER);
tfwBottomTip.setStyle("-fx-text-fill: rgba(100, 100, 100, 0.9)");
tfwBottomTip.setPadding(new Insets(0, 8, 0, 0));
tfwBottomTip.setMaxWidth(300);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么需要限制最大宽度?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

因为会非常非常长,导致文字和下载计数怼在一起,不好看
用户手动放大HMCL界面后启动面板的大小并不会改变,因此这里的使用应当是安全的

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那你应当设置 padding,而不是硬编码一个 width 进去。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那你应当设置 padding,而不是硬编码一个 width 进去。

好的

@hmr-BH hmr-BH marked this pull request as ready for review September 29, 2025 15:10
@hmr-BH hmr-BH marked this pull request as draft September 29, 2025 15:10
@hmr-BH hmr-BH marked this pull request as ready for review September 29, 2025 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants