-
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
Open
hmr-BH
wants to merge
17
commits into
HMCL-dev:main
Choose a base branch
from
hmr-BH:tips
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: 实现启动界面的“小提示”文字 2.0 #4383
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
95458af
feat: 实现启动界面的“小提示”内容
hmr-BH 4d8e756
修改占位的默认值的格式
hmr-BH b70ca5d
优化英文翻译的标点符号的使用
hmr-BH b7d538c
每隔两秒更换”小提示“。优化换行算法
hmr-BH 864f38f
带有”保底“机制的随机”小贴士“生成算法
hmr-BH 9595378
修改随机类命名
hmr-BH b727b67
删除旧的方法封装
hmr-BH 74ed377
对齐启动面板底部组件
hmr-BH fc82cfc
按照新版规范添加翻译文件占位
hmr-BH 5ceb561
重构并优化代码逻辑
hmr-BH 59a4d04
将i18n文本迁移到json文件
hmr-BH 3ace3a2
Update LaunchTipLabel.java
hmr-BH d060af8
Merge branch 'HMCL-dev:main' into tips
hmr-BH 1f48055
修复不一致的命名
hmr-BH 7701948
让用户可以自主选择是否在启动时显示小提示
hmr-BH 806c474
延长每一个小提示展示的时长到3s
hmr-BH e1650ce
Update LaunchTipLabel.java
hmr-BH File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/LaunchTipLabel.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
* Hello Minecraft! Launcher | ||
* Copyright (C) 2021 huangyuhui <[email protected]> and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package org.jackhuang.hmcl.ui.construct; | ||
|
||
import javafx.animation.Animation; | ||
import javafx.animation.KeyFrame; | ||
import javafx.animation.Timeline; | ||
import javafx.application.Platform; | ||
import javafx.geometry.Insets; | ||
import javafx.geometry.Pos; | ||
import javafx.scene.layout.HBox; | ||
import javafx.scene.text.Text; | ||
import javafx.scene.text.TextAlignment; | ||
import javafx.scene.text.TextFlow; | ||
import javafx.util.Duration; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.JsonSyntaxException; | ||
import com.google.gson.annotations.SerializedName; | ||
|
||
import org.jackhuang.hmcl.util.i18n.I18n; | ||
|
||
|
||
public class LaunchTipLabel extends HBox { | ||
private final Text bottomTipText; | ||
private final TextFlow tfwBottomTip; | ||
private final Timeline tipTimeline; | ||
private static final List<String> tips; | ||
private static int index = 0; | ||
private static final int nextTipDelay = 3; | ||
|
||
static { | ||
tips = loadTipsFromJson(); | ||
Collections.shuffle(tips, ThreadLocalRandom.current()); | ||
} | ||
|
||
public LaunchTipLabel() { | ||
setAlignment(Pos.CENTER); | ||
|
||
tfwBottomTip = new TextFlow(); | ||
tfwBottomTip.setTextAlignment(TextAlignment.CENTER); | ||
tfwBottomTip.setStyle("-fx-text-fill: rgba(100, 100, 100, 0.9)"); | ||
tfwBottomTip.setPadding(new Insets(0, 50, 0, 50)); | ||
|
||
bottomTipText = new Text(getRandomTip()); | ||
tfwBottomTip.getChildren().add(bottomTipText); | ||
|
||
getChildren().add(tfwBottomTip); | ||
|
||
tipTimeline = new Timeline(new KeyFrame(Duration.seconds(nextTipDelay), e -> nextTip())); | ||
tipTimeline.setCycleCount(Animation.INDEFINITE); | ||
tipTimeline.play(); | ||
} | ||
|
||
private void nextTip() { | ||
String next = getRandomTip(); | ||
Platform.runLater(() -> bottomTipText.setText(next)); | ||
} | ||
|
||
private static String getRandomTip() { | ||
if (index >= tips.size()){ | ||
Collections.shuffle(tips, ThreadLocalRandom.current()); | ||
index = 0; | ||
} | ||
return tips.get(index++); | ||
} | ||
private static List<String> loadTipsFromJson() { | ||
List<String> result = new ArrayList<>(); | ||
String resourceName = "assets.lang.launch_tips.tips"; | ||
|
||
try { | ||
java.net.URL url = I18n.getBuiltinResource(resourceName, "json"); | ||
if (url != null) { | ||
Gson gson = new Gson(); | ||
try (InputStream inputStream = url.openStream(); | ||
InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) { | ||
LaunchTipsData data = gson.fromJson(reader, LaunchTipsData.class); | ||
if (data != null && data.tips != null) { | ||
result.addAll(data.tips); | ||
} | ||
} | ||
} | ||
} catch (IOException | JsonSyntaxException ignored) { | ||
// ignored | ||
} | ||
|
||
if (result.isEmpty()) { | ||
result.add("Welcome to HMCL!"); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
|
||
private static class LaunchTipsData { | ||
@SerializedName("tips") | ||
private List<String> tips; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
HMCL/src/main/resources/assets/lang/launch_tips/tips_en.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"tips": [ | ||
"HMCL was originally made by huanghongxun; more contributors later joined.", | ||
"Minecraft’s first version launched in 2009 as a simple prototype.", | ||
"Every horse in Minecraft has a random unique speed.", | ||
"Name a Vindicator \"Johnny\" to make it very aggressive.", | ||
"HMCL’s dev community is active (new features often added); follow GitHub discussions.", | ||
"HMCL works on Windows, MacOS and Linux.", | ||
"HMCL devs share progress/plans on Bilibili and GitHub.", | ||
"Iron Golems give Poppies to Copper Golems, which then wear them.", | ||
"Endermen lose teleport if trapped in a minecart or cobweb.", | ||
"Creepers started as a pig glitch in the game.", | ||
"Skip sleep for 3 in-game days? Be careful on day 4’s night.", | ||
"1/256 chance to get 4 chicks from one egg.", | ||
"Golden Pickaxe has low durability but high good enchant chance.", | ||
"Ocelots and Iron Golems take no fall damage—they can’t die from falling.", | ||
"Falling on hay bales reduces fall damage.", | ||
"Early Minecraft let you mine coal ore with bare hands.", | ||
"Chests turn into gift box textures at Christmas.", | ||
"Cats sit on beds, chests and furnaces automatically.", | ||
"Endermen are the only mobs spawning naturally in all 3 Minecraft dimensions.", | ||
"Banners sway in the Overworld, not in the Nether/End.", | ||
"Minecraft’s \"tick\" = 0.05s; 1 in-game day = 24,000 ticks (20 mins).", | ||
"Tropical Fish: 2 sizes, 6 patterns each, 15 base/pattern colors—2,700 total types.", | ||
"Name a sheep \"jeb_\" to make it rainbow-colored.", | ||
"Skeletons have 21% left-hand bow use (based on real human data).", | ||
"Skeletons attack from any angle—turning away won’t stop them.", | ||
"Test horse speed: Two riders, leashed together, pull opposite—loser’s horse is slower.", | ||
"Hit squids’ heads, not tentacles—tentacles take no damage.", | ||
"Adult turtles avoid undead unless the undead hated them as babies.", | ||
"Jungle Temples always use 1,185 cobblestone or mossy cobblestone.", | ||
"Enchant shields with Unbreaking/Mending via anvil, not enchantment table." | ||
] | ||
} |
34 changes: 34 additions & 0 deletions
34
HMCL/src/main/resources/assets/lang/launch_tips/tips_zh.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"tips": [ | ||
"HMCL 最初由 huanghongxun 開發,後來有越來越多的貢獻者加入其中。", | ||
"Minecraft 的第一個版本在 2009 年發布,當時它還只是一個簡單的原型。", | ||
"在 Minecraft 中,每一匹馬的速度都不同,這些屬性是隨機生成的。", | ||
"將衛道士命名為「Johnny」會讓牠變得非常暴躁。", | ||
"HMCL 的開發者社群相當活躍,時常會有新功能與改進推出。您可以在 GitHub 上追蹤相關討論。", | ||
"HMCL 支援多平台,包括 Windows、MacOS 與 Linux。", | ||
"HMCL 的開發者經常在 B站 和 GitHub 社群中分享開發進度與規劃。", | ||
"鐵傀會將罌粟贈送給附近的銅傀,接受贈送的銅傀會把罌粟戴在頭上。", | ||
"末影人若被困在礦車中或沾到蜘蛛網,牠的瞬移技能就會消失。", | ||
"苦力怕的原型是一隻豬,因遊戲錯誤而誕生。", | ||
"如果您在遊戲中連續三天不睡覺,第四天晚上最好多加小心。", | ||
"用雞蛋一次砸出 4 隻小雞的機率是 256 分之一。", | ||
"雖然金鎬的耐久度很低,但附魔出好屬性的機率相當高。", | ||
"豹貓和鐵傀不會摔死,因為牠們沒有摔落傷害。", | ||
"摔落在乾草上可以減少摔落傷害。", | ||
"在早期的《我的世界》中,煤礦可以空手挖掘。", | ||
"聖誕節期間,箱子會變成禮物箱的材質。", | ||
"貓會自己坐到床、箱子、熔爐上。", | ||
"末影人是原版 Minecraft 中唯一一種能在三個世界自然生成的生物。", | ||
"旗幟在主世界會輕微晃動,但在下界和末地則不會。", | ||
"Minecraft 的基本時間單位是「刻」,1刻=0.05秒,一天=24000刻=20分鐘。", | ||
"熱帶魚有 2 種體型,每種體型有 6 種花紋,底色與花紋顏色各 15 種,因此總共共有 2700 種。", | ||
"將羊命名為「jeb_」會讓牠變成一道彩虹。", | ||
"骷髏有 21% 的機率用左手拿弓。據說這個機率是依據現實世界中人類的真實數據設定的。", | ||
"骷髏攻擊沒有角度限制,別以為背對著骷髏,牠就攻擊不到您。", | ||
"比較馬的速度:讓兩人各騎一匹馬,用拴繩相連後朝相反方向拉。哪個人的馬被拉動,那匹馬的速度就比較慢。", | ||
"攻擊魷魚的觸手時,牠們不會受到傷害,最好的方法是攻擊牠們的頭部。", | ||
"成年海龜不會受到亡靈的攻擊……除非牠碰到幼年時就對牠抱有敵意的亡靈。", | ||
"叢林神廟一定是由 1185 個原石或苔石組成的。", | ||
"盾牌可以用鐵砧附魔「耐久」和「經驗修補」,但無法用附魔台進行附魔。" | ||
] | ||
} |
34 changes: 34 additions & 0 deletions
34
HMCL/src/main/resources/assets/lang/launch_tips/tips_zh_CN.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"tips": [ | ||
"HMCL 最初由 huanghongxun 开发,后来有越来越多的贡献者加入了其中。", | ||
"Minecraft 的第一个版本是在 2009 年发布的,当时它只是一个简单的原型。", | ||
"在 Minecraft 中,每匹马都有不同的速度。这些属性是随机生成的。", | ||
"给卫道士命名为“Johnny”会让他变得很暴躁。", | ||
"HMCL 的开发者社区非常活跃,经常会有新的功能和改进。您可以在 GitHub 上关注相关讨论。", | ||
"HMCL支持多平台,包括 Windows、MacOS 和 Linux。", | ||
"HMCL 的开发者经常会在 B站 和 GitHub 社区中分享开发进度和计划。", | ||
"铁傀会将虞美人赠予附近的铜傀,接受的铜傀会将其戴到头上。", | ||
"末影人如果被困在矿车中或粘到蜘蛛网,它的瞬移技能会消失。", | ||
"苦力怕的原型是一只猪,因游戏错误而诞生。", | ||
"如果你在游戏里连续三天不睡觉,第四天晚上最好小心点。", | ||
"鸡蛋一次性砸出 4 只小鸡的几率是 256 分之一。", | ||
"虽然金镐的耐久度很低,但是附魔出好属性的几率很高。", | ||
"豹猫和铁傀是不会摔死的,因为它们没有摔落伤害。", | ||
"摔落在干草上可以减少摔落伤害。", | ||
"在早期的我的世界中,煤矿可以空手撸。", | ||
"在圣诞节的时候,箱子会变成礼物箱的材质。", | ||
"猫会自己坐到床、箱子、熔炉上。", | ||
"末影人是原版 Minecraft 中唯一一种在三个世界都自然生成的生物。", | ||
"旗帜在主世界会轻微晃动,而在下界和末地不会。", | ||
"Minecraft 的基本时间单位是刻,1刻=0.05秒,一天 = 24000刻 = 20分钟。", | ||
"热带鱼有 2 种体型,每种体型有6种花纹,底色与花纹颜色各15种,所以共有 2700 种。", | ||
"给羊命名为“jeb_”会使其变成一道彩虹。", | ||
"骷髅有 21% 的概率使用左手拿弓。据说,这个概率是依据现实世界人类真实的数据设定的。", | ||
"骷攻击没有角度的,不要以为背对着骷髅,它就攻击不到你。", | ||
"比较马的速度: 让两人各骑一匹马,用拴绳相连,朝反方向拉。谁的马被拉动,谁的马就更快。", | ||
"你攻击鱿鱼的触手时,它们不会受到伤害。最好的方法是攻击头部。", | ||
"成年的海龟不会受到亡灵的攻击...除非它碰到幼年时就对它起了敌意的亡灵。", | ||
"丛林神庙总是会由 1185 个原石或苔石组成。", | ||
"盾牌可以用铁砧附魔耐久和经验修补,但没法用附魔台。" | ||
] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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,而不需要保存一份原本的,每次从原本顺序打乱。