3,462
个编辑
MCBBS Wiki欢迎您共同参与编辑!在参与编辑之前请先阅读Wiki方针。
如果在编辑的过程中遇到了什么问题,可以去讨论板提问。
为了您能够无阻碍地参与编辑 未验证/绑定过邮箱的用户,请尽快绑定/验证。
MCBBS Wiki GitHub群组已上线!
您可以在回声洞中发表吐槽!
服务器状态监控。点击进入
本站由MCBBS用户自行搭建,与MCBBS及东银河系漫游指南(北京)科技有限公司没有从属关系。点此了解 MCBBS Wiki 不是什么>>
(创建页面,内容为“== 关于 == 你可以使用FancyMenu编写你自己的自定义背景拓展模组,而且你可以在布局中使用它们。 重要:Menu Background API只在FancyMenu v2.6.2+可用! == 准备开发环境 == 请参阅 准备工作区。 == 添加菜单背景 == 每一个菜单背景都系要两个类。 第一个是<code>MenuBackgroundType</code>。 这个是你的背景类型(比如已经存在的动画,或是全景…”) |
小 (// Edit via Wikiplus) |
||
(未显示同一用户的3个中间版本) | |||
=== 创建字符串模式背景 ===
输入字符串模式下的<code>MenuBackgroundTypes</code>从一个输入字符串中快速创建<code>MenuBackground</code>实例。
这些实例并不会想普通模式会被储存下来,而是每次布局被加载时新的实例也会被创建。
==== MenuBackground Class ====
创建一个<code>MenuBackground</code>的新子类并取一个合适的名字
接下来我会给我的示例类起名为<code>ExampleMenuBackgroundForInputString</code>。
这里有一些需要特别注意的事项。
=====构造方法(Constructor)=====
和普通模式不一样,你不需要为你的背景整一个唯一的标识符,因为它们并不会被储存下来。在输入字符串模式下,你为<code>MenuBackground</code>实例使用什么标识符基本上并不重要。
当然,这里仍然可以在构造上设置变量。
<syntaxhighlight lang="java">
public ExampleMenuBackgroundForInputString(@Nonnull MenuBackgroundType type, String imagePath) {
//Identifiers aren't really used for backgrounds that don't get registered to a type (because the type uses the input string),
}
</syntaxhighlight>
=====onOpenMenu()=====
这个方法对于输入字符串模式的背景没用,因为在每一次加载菜单时总会创建新的实例,所以这没啥可重置的。
<syntaxhighlight lang="java">
@Override
public void onOpenMenu() {
//所以在使用输入字符串模式时你不需要重置。
}
</syntaxhighlight>
=====render()=====
调用此方法来渲染你的菜单背景实例。
应该指我解释一下在这里做什么,对吧?
<syntaxhighlight lang="java">
//Here you will render the background instance.
//在这里你可以渲染背景实例。
}
</syntaxhighlight>
=====完整样例类=====
完整
<syntaxhighlight lang="java">
package de.keksuccino.fancymenu.api.background.example.with_input_string;
}
}
</syntaxhighlight>
====MenuBackgroundType Class====
创建一个<code>MenuBackgroundType</code>的新子类并给它取合适的名字。
接下来我会将我的示例背景类型类命名为<code>ExampleMenuBackgroundTypeWithInputString</code>。
在这个类中有一些特别的点你需要留意。
=====构造方法(Constructor)=====
这里的构造方法用于设置你背景类型唯一的标识符。
<syntaxhighlight lang="java">
public ExampleMenuBackgroundTypeWithInputString() {
//This identifier needs to be UNIQUE! It is not possible to register multiple types with the same identifier.
super("example_type_input_string");
}
</syntaxhighlight>
=====loadBackgrounds()=====
在输入字符串模式下,此方法未被使用,因为在此模式下,<code>MenuBackground</code>实例会被即时创建。
<syntaxhighlight lang="java">
@Override
public void loadBackgrounds() {
//这里什么都没有是因为背景实例是通过createInstanceFromInputString()即时创建的。
}
</syntaxhighlight>
=====getDisplayName()=====
调用此方法获取背景类型名。
名称显示在布局编辑器的背景选项中。
<syntaxhighlight lang="java">
//You don't really have much space for the display name, so try to choose a short one ond explain the type further in the description.
//显示名字的空间很挤,你的类型名字简短点吧,在描述里详细说明就好。
return "Example Type w/ Input";
}
</syntaxhighlight>
=====getDescription()=====
获取背景类型的描述。
在布局编辑器的背景选项中显示。
<syntaxhighlight lang="java">
//Gets displayed when hovering over the type switcher in the background options menu in the layout editor.
//在布局编辑器的背景选项菜单中悬停在类型切换器上时显示。
return l;
}
</syntaxhighlight>
=====needsInputString()=====
这是最重要的方法,因为你得在这选择背景类型模式。
在这里,我们返回
返回<code>false</code>会将背景类型设置为普通模式。
<syntaxhighlight lang="java">
@Override
public boolean needsInputString() {
return true;
}
</syntaxhighlight>
=====createInstanceFromInputString()=====
当处于输入字符串模式时,每次需要一个新的<code>MenuBackground</code>实例时都会调用这个方法。
它基本是菜单背景工厂。
这个方法有给定的输入字符串作为参数,所以你可以用它来创建新的实例。
<syntaxhighlight lang="java">
//In input string mode, this will get called whenever a new background instance is needed.
//在输入字符串模式下,每当需要一个新的背景实例时,它都会被调用。
return new ExampleMenuBackgroundForInputString(this, inputString);
}
</syntaxhighlight>
=====onInputStringButtonPress()=====
这里,你可以指定当用户在布局编辑器的后台选项中点击输入字符串按钮时会发生什么。
在这基本没啥限制,除了让猴子写代码,想干啥干啥,只要你可以在最后正确地将新背景设置成编辑器实例。
<syntaxhighlight lang="java">
//This gets called when the input string button in the background options is pressed by the user.
//这个方法当用户按下背景选项上的输入字符串按钮后会被调用。
}
</syntaxhighlight>
=====inputStringButtonLabel()=====
返回布局编辑器的背景选项中的输入字符串按钮的标签。
<syntaxhighlight lang="java">
//The button label of the input string button in the background options.
//背景选项中输入字符串按钮的按钮标签。
return "Choose File";
}
</syntaxhighlight>
=====inputStringButtonTooltip()=====
返回布局编辑器的背景选项中输入字符串按钮的工具提示。
<syntaxhighlight lang="java">
//A tooltip that gets displayed when hovering over the input string button in the background options menu of the layout editor.
//当悬停在布局编辑器的背景选项菜单的输入字符串按钮上时,会显示工具提示。
return l;
}
</syntaxhighlight>
=====完整示例=====
下面是完整的MenuBackgroundType样例.
<syntaxhighlight lang="java">
package de.keksuccino.fancymenu.api.background.example.with_input_string;
}
</syntaxhighlight>
====注册菜单背景====
你就快完成了
现在你只需要在游戏加载时把你的<code>MenuBackgroundType</code>注册到<code>MenuBackgroundTypeRegistry</code>.
<syntaxhighlight lang="java">
package de.keksuccino.fancymenu;
}
</syntaxhighlight>
[[分类:FancyMenu]]
|