feat: 实现启动界面的“小提示”文字 2.0 - #4383
Conversation
|
可以增加自定义功能吗 |
可以 |
|
| } | ||
|
|
||
| private static int getRandomTipIndex() { | ||
| return ThreadLocalRandom.current().nextInt(tips.size()); |
请使用 |
了解 |
放到一个文件里的话,后期做更多语言的 i18n 支持就会比较麻烦,还是每个语言独立文件比较合适。 现在不着急改,我们在研究 #4373,做完之后本地化一些资源文件会更轻松。 |
|
现在你可以使用 举个例子:如果当前语言环境为
|
那我在I18N这些properties文件的同级目录创建一个launch_tips文件夹,里面专门放置翻译文件吧 |
|
希望可以在设置提供开关,因为可能会有人不喜欢这个提示 |
|
|
||
| onEscPressed(this, btnCancel::fire); | ||
|
|
||
| tipTimeline = new Timeline(new KeyFrame(Duration.seconds(2), e -> nextTip())); |
| return formatTip(tip); | ||
| } | ||
|
|
||
| private static String formatTip(String tip) { |
There was a problem hiding this comment.
我不太理解为什么你依然在使用手动换行。JavaFX 的 TextFlow 控件可以非常方便的实现显示多行文本,可考虑迁移到 TextFlow
| } | ||
|
|
||
| private void shuffle() { | ||
| for (int i = indices.size() - 1; i > 0; i--) { |
There was a problem hiding this comment.
java.util.Collections#shuffle(java.util.List<?>)
|
|
||
| public final class RandomTip { | ||
|
|
||
| private static final List<String> tips; |
There was a problem hiding this comment.
这里的数据结构完全可以修改为:
`
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())); |
There was a problem hiding this comment.
这里 e -> nextTip 隐式捕获了 this。在 JavaFX 上,这是否会导致潜在的内存泄漏?
| private final Text bottomTipText; | ||
| private final TextFlow tfwBottomTip; | ||
| private final Timeline tipTimeline; | ||
| private static final List<String> tips; |
There was a problem hiding this comment.
你可以就地打乱 tips,而不需要保存一份原本的,每次从原本顺序打乱。
| private final Timeline tipTimeline; | ||
| private static final List<String> tips; | ||
| private static final List<String> shuffledTips; | ||
| private static final Random random = new Random(); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
因为会非常非常长,导致文字和下载计数怼在一起,不好看
用户手动放大HMCL界面后启动面板的大小并不会改变,因此这里的使用应当是安全的
There was a problem hiding this comment.
那你应当设置 padding,而不是硬编码一个 width 进去。
There was a problem hiding this comment.
那你应当设置 padding,而不是硬编码一个 width 进去。
好的

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

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