MCBBS Wiki欢迎您共同参与编辑!在参与编辑之前请先阅读Wiki方针

如果在编辑的过程中遇到了什么问题,可以去讨论板提问。

为了您能够无阻碍地参与编辑 未验证/绑定过邮箱的用户,请尽快绑定/验证

MCBBS Wiki GitHub群组已上线!

您可以在回声洞中发表吐槽!

服务器状态监控。点击进入

本站由MCBBS用户自行搭建,与MCBBS及东银河系漫游指南(北京)科技有限公司没有从属关系。点此了解 MCBBS Wiki 不是什么>>

FancyMenu Wiki/自定义菜单背景:修订间差异

跳到导航 跳到搜索
第587行: 第587行:
</syntaxhighlight>
</syntaxhighlight>
====MenuBackgroundType Class====
====MenuBackgroundType Class====
创建一个MenuBackgroundType的新子类并给它取合适的名字。
创建一个<code>MenuBackgroundType</code>的新子类并给它取合适的名字。
接下来我会将我的示例背景类型类命名为ExampleMenuBackgroundTypeWithInputString。
 
接下来我会将我的示例背景类型类命名为<code>ExampleMenuBackgroundTypeWithInputString</code>。
 
在这个类中有一些特别的点你需要留意。
在这个类中有一些特别的点你需要留意。
构造方法(Constructor)
=====构造方法(Constructor)=====
这里的构造方法用于设置你背景类型唯一的标识符。
这里的构造方法用于设置你背景类型唯一的标识符。
<syntaxhighlight lang="java">
public ExampleMenuBackgroundTypeWithInputString() {
public ExampleMenuBackgroundTypeWithInputString() {
     //This identifier needs to be UNIQUE! It is not possible to register multiple types with the same identifier.
     //This identifier needs to be UNIQUE! It is not possible to register multiple types with the same identifier.
第597行: 第600行:
     super("example_type_input_string");
     super("example_type_input_string");
}
}
复制代码
</syntaxhighlight>
 
=====loadBackgrounds()=====
loadBackgrounds()
在输入字符串模式下,此方法未被使用,因为在此模式下,<code>MenuBackground</code>实例会被即时创建。
在输入字符串模式下,此方法未被使用,因为在此模式下,MenuBackground实例会被即时创建。
<syntaxhighlight lang="java">
@Override
@Override
     public void loadBackgrounds() {
     public void loadBackgrounds() {
第606行: 第609行:
     //这里什么都没有是因为背景实例是通过createInstanceFromInputString()即时创建的。
     //这里什么都没有是因为背景实例是通过createInstanceFromInputString()即时创建的。
}
}
复制代码
</syntaxhighlight>
=====getDisplayName()=====
调用此方法获取背景类型名。


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.
//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.
//显示名字的空间很挤,你的类型名字简短点吧,在描述里详细说明就好。
//显示名字的空间很挤,你的类型名字简短点吧,在描述里详细说明就好。
第617行: 第621行:
     return "Example Type w/ Input";
     return "Example Type w/ Input";
}
}
复制代码
</syntaxhighlight>
=====getDescription()=====
获取背景类型的描述。


getDescription()
获取背景类型的描述。
在布局编辑器的背景选项中显示。
在布局编辑器的背景选项中显示。
<syntaxhighlight lang="java">
//Gets displayed when hovering over the type switcher in the background options menu in the layout editor.
//Gets displayed when hovering over the type switcher in the background options menu in the layout editor.
//在布局编辑器的背景选项菜单中悬停在类型切换器上时显示。
//在布局编辑器的背景选项菜单中悬停在类型切换器上时显示。
第635行: 第640行:
     return l;
     return l;
}
}
复制代码
</syntaxhighlight>
 
=====needsInputString()=====
needsInputString()
这是最重要的方法,因为你得在这选择背景类型模式。
这是最重要的方法,因为你得在这选择背景类型模式。
在这里,我们返回true,因为我们想为咱的背景类型使用输入字符串模式。
在这里,我们返回<code>true</code>,因为我们想为咱的背景类型使用输入字符串模式。
返回false会将背景类型设置为普通模式。
返回<code>false</code>会将背景类型设置为普通模式。
<syntaxhighlight lang="java">
@Override
@Override
public boolean needsInputString() {
public boolean needsInputString() {
第651行: 第656行:
     return true;
     return true;
}
}
复制代码
</syntaxhighlight>
=====createInstanceFromInputString()=====
当处于输入字符串模式时,每次需要一个新的<code>MenuBackground</code>实例时都会调用这个方法。


createInstanceFromInputString()
当处于输入字符串模式时,每次需要一个新的MenuBackground实例时都会调用这个方法。
它基本是菜单背景工厂。
它基本是菜单背景工厂。
这个方法有给定的输入字符串作为参数,所以你可以用它来创建新的实例。
这个方法有给定的输入字符串作为参数,所以你可以用它来创建新的实例。
<syntaxhighlight lang="java">
//In input string mode, this will get called whenever a new background instance is needed.
//In input string mode, this will get called whenever a new background instance is needed.
//在输入字符串模式下,每当需要一个新的背景实例时,它都会被调用。
//在输入字符串模式下,每当需要一个新的背景实例时,它都会被调用。
第669行: 第676行:
     return new ExampleMenuBackgroundForInputString(this, inputString);
     return new ExampleMenuBackgroundForInputString(this, inputString);
}
}
复制代码
</syntaxhighlight>
=====onInputStringButtonPress()=====
这里,你可以指定当用户在布局编辑器的后台选项中点击输入字符串按钮时会发生什么。


onInputStringButtonPress()
这里,你可以指定当用户在布局编辑器的后台选项中点击输入字符串按钮时会发生什么。
在这基本没啥限制,除了让猴子写代码,想干啥干啥,只要你可以在最后正确地将新背景设置成编辑器实例。
在这基本没啥限制,除了让猴子写代码,想干啥干啥,只要你可以在最后正确地将新背景设置成编辑器实例。
<syntaxhighlight lang="java">
//This gets called when the input string button in the background options is pressed by the user.
//This gets called when the input string button in the background options is pressed by the user.
//这个方法当用户按下背景选项上的输入字符串按钮后会被调用。
//这个方法当用户按下背景选项上的输入字符串按钮后会被调用。
第710行: 第718行:


}
}
复制代码
</syntaxhighlight>
 
=====inputStringButtonLabel()=====
inputStringButtonLabel()
返回布局编辑器的背景选项中的输入字符串按钮的标签。
返回布局编辑器的背景选项中的输入字符串按钮的标签。
<syntaxhighlight lang="java">
//The button label of the input string button in the background options.
//The button label of the input string button in the background options.
//背景选项中输入字符串按钮的按钮标签。
//背景选项中输入字符串按钮的按钮标签。
第720行: 第728行:
     return "Choose File";
     return "Choose File";
}
}
复制代码
</syntaxhighlight>
 
=====inputStringButtonTooltip()=====
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.
//A tooltip that gets displayed when hovering over the input string button in the background options menu of the layout editor.
//当悬停在布局编辑器的背景选项菜单的输入字符串按钮上时,会显示工具提示。
//当悬停在布局编辑器的背景选项菜单的输入字符串按钮上时,会显示工具提示。
第733行: 第741行:
     return l;
     return l;
}
}
复制代码
</syntaxhighlight>
 
=====完整示例=====
完整示例
下面是完整的MenuBackgroundType样例.
下面是完整的MenuBackgroundType样例.
<syntaxhighlight lang="java">
package de.keksuccino.fancymenu.api.background.example.with_input_string;
package de.keksuccino.fancymenu.api.background.example.with_input_string;


第867行: 第875行:


}
}
复制代码
</syntaxhighlight>


====注册菜单背景====
====注册菜单背景====
维护员、​界面管理员、​巡查员、​监督员、​小部件编辑者
3,469

个编辑

我们提供服务需要使用Cookie。您使用我们的服务,即表示您同意我们使用Cookie。

导航菜单