zh_cn:tutorial:screen
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
zh_cn:tutorial:screen [2023/04/24 08:17] – created solidblock | zh_cn:tutorial:screen [2023/12/18 01:40] (current) – [添加文本] solidblock | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== 添加屏幕 ====== | ====== 添加屏幕 ====== | ||
- | **屏幕**是指的图形用户界面,其类继承了 '' | + | **屏幕**是指的图形用户界面,其类继承了 '' |
你可以使用 mixin 以在现有的屏幕中,加入你的屏幕的链接。但是很多情况下,我们可以实现 Mod Menu 模组中的 '' | 你可以使用 mixin 以在现有的屏幕中,加入你的屏幕的链接。但是很多情况下,我们可以实现 Mod Menu 模组中的 '' | ||
Line 108: | Line 108: | ||
===== 添加复述 ===== | ===== 添加复述 ===== | ||
- | By default, when narration is enabled, the screen title and information of the element you hover or focus on will be narrated. If the screen requires extra narrations (for example it has some texts rendered but not added as a widget), you can override | + | 默认情况下,在复述功能启用时,屏幕的标题以及你鼠标悬浮或选中的元素的信息会被复述。如果屏幕需要额外的复述(例如渲染了一些文本但没有添加为部件),你可以覆盖 |
- | * **Title**: The title of the screen, which is defined in the constructor. When you enter the screen, the title will be automatically narrated. | + | * **Title**:屏幕的标题,会在构造函数中指定。当你进入屏幕时,这个标题会被自动复述。 |
- | * **Position**: Telling you the position of the widget you are focusing on. In vanilla, it is: "//Screen element | + | * **Position**:告诉你当前正在选中的部件的位置。在原版中,是“//屏幕控件,第%s个,共%s个//”。此外,如果是在列表中,还会复述以下内容:“//已选中列表的第%s行,共%s行//”。 |
- | * **Hint**: This refers the tooltip of the element you focus on or hovers on. For example, you may remember about the '' | + | * **Hint**:这个是指的当前选中或悬浮的元素的提示。例如,你可能会记得在上面的代码中创建 |
- | * **Usage**: In vanilla, the usage is: "//Use mouse cursor or Tab button to select element//". | + | * **Usage**:在原版中,用法为“//使用鼠标指针或Tab键选择屏幕控件//”。 |
- | Besides the narration of the screen, you can also customize the narration of the element, by overriding | + | 除了对屏幕的复述之外,你还可以自定义元素的复述,也就是覆盖元素的类的 |
- | In the method of appending narrations, using '' | + | 在添加复述的方法中,使用 |
- | In some cases, you want repetitive narrations, instead of narrating only once. For example, when loading a level, the percentage of loading is narrated repetitively, | + | 在有些类中,你可能需要重复的复述,而不是只复述一次。例如,在加载世界时,加载的百分比会重复复述,告诉用户当前的加载状态。你可以在 |
===== 添加文本 ===== | ===== 添加文本 ===== | ||
- | In '' | + | 在 '' |
<code java> | <code java> | ||
+ | // 对于 1.20 以下版本 | ||
@Override | @Override | ||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { | public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { | ||
super.render(matrices, | super.render(matrices, | ||
- | drawCenteredTextWithShadow(matrices, | + | drawCenteredTextWithShadow(matrices, |
+ | } | ||
+ | |||
+ | // 对于 1.20 及以上的版本 | ||
+ | @Override | ||
+ | public void render(DrawContext context, int mouseX, int mouseY, float delta) { | ||
+ | super.render(context, | ||
+ | context.drawCenteredTextWithShadow(textRenderer, | ||
} | } | ||
</ | </ | ||
- | If you're concerned that the text can be pretty long and may exceed the screen limit, you can use '' | + | 如果你担心文本太长超出了屏幕的边界。你可以使用 |
<code java> | <code java> | ||
- | final MultilineText multilineText = MultilineText.create(textRenderer, | + | final MultilineText multilineText = MultilineText.create(textRenderer, |
+ | |||
+ | // 对于 1.20 以下版本 | ||
multilineText.drawWithShadow(matrices, | multilineText.drawWithShadow(matrices, | ||
+ | // 对于 1.20 及以下的版本 | ||
+ | multilineText.drawWithShadow(context, | ||
</ | </ | ||
- | Another alterative is using '' | + | 另一个选择是使用 |
===== 滚动 ===== | ===== 滚动 ===== | ||
- | The screen does not support scrolling, but you can add widgets that supports scrolling. | + | 屏幕不支持滚动,但是你可以添加支持滚动的部件。''< |
- | + | ||
- | * ''< | + | |
- | * ''< | + | |
+ | * ''< | ||
+ | * ''< | ||
===== 完成之前需要检查的事情 ===== | ===== 完成之前需要检查的事情 ===== | ||
- | After finishing your screen, in order to avoid potential issues, please check: | + | 在完成你的屏幕之后,为避免潜在的问题,请检查: |
- | * whether the screen returns to the last screen (parent screen) when you press "Esc" | + | * 按下 |
- | * whether these classes exist only on client (which means they will not be loaded in the dedicated server) | + | * 这些类是否仅存在于客户端(也就是说在专用服务器上不会加载) |
- | * whether elements are focused in the correct order when you press "Tab" to select them | + | * 按下 |
- | * whether the behaviors are correct when you resize | + | * 重新调整屏幕尺寸时的行为是否正确 |
- | * whether the narrations are correct when you use "Tab" or mouse cursor to select element while narration enabled | + | * 启用了复述功能时,按下 |
zh_cn/tutorial/screen.1682324240.txt.gz · Last modified: 2023/04/24 08:17 by solidblock