-
Notifications
You must be signed in to change notification settings - Fork 777
feat: 实现启动界面的“小提示”文字 2.0 #4383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: 实现启动界面的“小提示”文字 2.0 #4383
Conversation
可以增加自定义功能吗 |
可以 |
There was a problem hiding this 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 耦合提示的个数。
|
} | ||
|
||
private static int getRandomTipIndex() { | ||
return ThreadLocalRandom.current().nextInt(tips.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
应当自行设计带有“保底”伪随机生成逻辑
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
应当自行设计带有“保底”伪随机生成逻辑
让我思考一下(大脑过载
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
应当自行设计带有“保底”伪随机生成逻辑
我大概是想复杂了
请使用 |
了解 |
放到一个文件里的话,后期做更多语言的 i18n 支持就会比较麻烦,还是每个语言独立文件比较合适。 现在不着急改,我们在研究 #4373,做完之后本地化一些资源文件会更轻松。 |
现在你可以使用 举个例子:如果当前语言环境为
|
那我在I18N这些properties文件的同级目录创建一个launch_tips文件夹,里面专门放置翻译文件吧 |
希望可以在设置提供开关,因为可能会有人不喜欢这个提示 |
|
||
onEscPressed(this, btnCancel::fire); | ||
|
||
tipTimeline = new Timeline(new KeyFrame(Duration.seconds(2), e -> nextTip())); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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--) { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里 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.
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(); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么需要限制最大宽度?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
因为会非常非常长,导致文字和下载计数怼在一起,不好看
用户手动放大HMCL界面后启动面板的大小并不会改变,因此这里的使用应当是安全的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那你应当设置 padding,而不是硬编码一个 width 进去。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那你应当设置 padding,而不是硬编码一个 width 进去。
好的
删除了原有的换行算法,优化“小提示”布局,使下载速度计数与之对齐。

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