FancyMenu Wiki/自定义Visibility Requirements:修订间差异

(创建页面,内容为“== 关于 == 通过在拓展模组中调用 FancyMenu API,即可自定义Visibility Requirements用于布局中的元素。 重要:Visibility RequirementsAPI只在FancyMenu v2.6.3+有效。 == 准备开发环境 == 请参阅 准备工作区。 == 添加Visibility Requirements == Visibility Requirements使用<code>VisibilityRequirement</code>类。 你需要为每一个VisibilityRequirement Requirements 创建一个子…”)
 
 
(未显示1个用户的4个中间版本)
=== 不同类型的Requirements ===
VisibilityRequirements可以用于两种不同的模式。
 
第一种是不使用任何值来检查是否满足 Requirements ,第二种是使用一个值。
 
如果 Requirements 使用值,那么用户在给一个元素设置 Requirements 时就需要输入这个值。
=== 不使用值来创建 Requirements ===
创建一个<code>VisibilityRequirement</code>的新子类并取一个合适的名字。
 
接下来我会将我的示例类命名为ExampleVisibilityRequirement。
接下来我会将我的示例类命名为<code>ExampleVisibilityRequirement</code>。
 
同时有一些特殊的点需要特别留意一下。
==== 构造方法(Constructor) ====
在构造方法中给你的 Requirements 定义唯一标识符。
<syntaxhighlight lang="java">
public ExampleVisibilityRequirement() {
//The identifier needs to be unique! It's not possible to register multiple requirements with the same identifier!
super("example_requirement_no_value");
}
</syntaxhighlight>
复制代码
==== hasValue() ====
 
hasValue()
这个方法用于返回 Requirements 是否需要值。
 
因为我们不想给这个 Requirements 使用值,所以返回false。
因为我们不想给这个 Requirements 使用值,所以返回<code>false</code>。
<syntaxhighlight lang="java">
@Override
public boolean hasValue() {
return false;
}
</syntaxhighlight>
复制代码
==== isRequirementMet() ====
 
isRequirementMet()
这是你的 Requirements 的最重要的方法。
 
这里用于返回是否满足在此要求中检查的条件。
 
这个方法以 Requirements 的值为参数,但因为这个 Requirements 没有值,所以参数为空。
<syntaxhighlight lang="java">
//Here you return if the requirement is met (using the given requirement value if the requirement has one).
//在这里返回是否满足 Requirements (如果 Requirements 有值则返回 Requirements 的值)
 
}
</syntaxhighlight>
复制代码
==== getDisplayName() ====
 
getDisplayName()
这个方法返回 Requirements 的显示名。
 
这个显示名会在布局编辑器的Visibility Requirements选项显示。
<syntaxhighlight lang="java">
//This is the display name of the requirement.
//这个是 Requirements 的显示名。
return "Example Requirement [No Value]";
}
</syntaxhighlight>
复制代码
==== getDescription() ====
 
getDescription()
返回 Requirements 的描述。
 
当把鼠标悬停在切换 Requirements 按钮上时,该描述会作为工具提示显示。
<syntaxhighlight lang="java">
//This is the description of the requirement.
//这里是 Requirements 的描述
return l;
}
</syntaxhighlight>
复制代码
==== getValueDisplayName() ====
 
getValueDisplayName()
这个方法返回值的显示名。
 
因为咱的 Requirements 不用值,返回空即可。
<syntaxhighlight lang="java">
//Since this requirement has no value, just return NULL here.
//因为 Requirements 没有值,只需要在这里返回null。
return null;
}
</syntaxhighlight>
复制代码
==== getValuePreset() ====
 
getValuePreset()
返回自动设置到值输入文本字段的内容。
 
这个 Requirements 没有值输入字段,所以我们返回null。
这个 Requirements 没有值输入字段,所以我们返回<code>null</code>。
<syntaxhighlight lang="java">
//No value, so just return NULL.
//没有值,返回null。
return null;
}
</syntaxhighlight>
复制代码
==== getValueInputFieldFilter() ====
 
getValueInputFieldFilter()
该方法返回一个字符过滤器,该过滤器用来检查用户可以在数值输入文本字段中允许输入的字符。
 
妹纸,回null。
没值,回null。
<syntaxhighlight lang="java">
//You know the drill. No value = return NULL.
//没值 = 返回null(毁灭吧,我累了 *发动地鸣)
return null;
}
</syntaxhighlight>
2.2.9. Full Example Class
==== 完整示例 ====
This is a full working VisibilityRequirement example.
这个是完整的VisibilityRequirement样例。
<syntaxhighlight lang="java">
package de.keksuccino.fancymenu.api.visibilityrequirements.example;
 
 
}
</syntaxhighlight>
复制代码
==== 注册Visibility Requirement ====
 
注册Visibility Requirement
到这你几乎完成了。(译者:我也是 *冰箱里拿一瓶啤酒)
 
现在你只需要在游戏加载时将你的VisibilityRequirement注册到VisibilityRequirementRegistry。
现在你只需要在游戏加载时将你的<code>VisibilityRequirement</code>注册到<code>VisibilityRequirementRegistry</code>。
<syntaxhighlight lang="java">
package de.keksuccino.fancymenu;
 
 
}
</syntaxhighlight>
复制代码
 
=== 创建带值的Requirement ===
创建<code>VisibilityRequirement</code>的新子类并取一个合适的名字。
 
接下来我将我的演示类命名为<code>ExampleVisibilityRequirementWithValue</code>
 
有一些重要的点需要留意
 
==== 构造函数(Constructor) ====
构造函数用标识符独一无二
<syntaxhighlight lang="java">
public ExampleVisibilityRequirementWithValue() {
//The identifier needs to be unique! It's not possible to register multiple requirements with the same identifier!
super("example_requirement_with_value");
}
</syntaxhighlight>
复制代码
==== hasValue() ====
 
hasValue()
这个方法用于返回 Requirements 是否需要值。
 
因为我们想给这个 Requirements 使用值,所以返回true。
<syntaxhighlight lang="java">
@Override
public boolean hasValue() {
return true;
}
</syntaxhighlight>
复制代码
 
==== isRequirementMet() ====
这是你的 Requirements 的最重要的方法。
 
这里用于返回是否满足在此要求中检查的条件。
 
这个方法有 Requirements 的值作为参数,所以你可以使用它检查是否满足 Requirements 。
<syntaxhighlight lang="java">
//Here you return if the requirement is met (using the given requirement value if the requirement has one).
//在这里返回是否满足 Requirements (如果 Requirements 有值则返回 Requirements 的值)
 
}
</syntaxhighlight>
复制代码
 
==== getDisplayName() ====
此方法返回 Requirements 显示名。
 
这个显示名会在布局编辑器的Visibility Requirements选项显示。
<syntaxhighlight lang="java">
//This is the display name of the requirement.
//这个是 Requirements 的显示名。
return "Example Requirement [With Value]";
}
</syntaxhighlight>
复制代码
 
==== getDescription() ====
返回 Requirements 的描述。
 
当把鼠标悬停在切换 Requirements 按钮上时,该描述会作为工具提示显示。
<syntaxhighlight lang="java">
//This is the description of the requirement.
//这里是 Requirements 的描述
return l;
}
</syntaxhighlight>
复制代码
==== getValueDisplayName() ====
 
getValueDisplayName()
这个方法返回值的显示名。
<syntaxhighlight lang="java">
//This is the display name of the VALUE of the requirement.
//这是 Requirements 的值的显示名。
return "Example Value Name";
}
</syntaxhighlight>
复制代码
==== getValuePreset() ====
如果没有真实的值,则返回自动设置到输入文本字段的内容。
 
getValuePreset()
如果没有真实的值,则返回自动设置到输入文本字段的内容。
最好给用户展示真实值的样例。
<syntaxhighlight lang="java">
//This is the content that will be automatically set to the value input field when there is no value already.
//在已经没有值的情况下将自动设置到值输入栏的内容。
return "cool value preset";
}
</syntaxhighlight>
复制代码
==== getValueInputFieldFilter() ====
 
getValueInputFieldFilter()
该方法返回一个字符过滤器,该过滤器被用来检查用户可以在数值输入文本字段中允许输入的字符。
 
如果你想允许所有字符,那直接返回null。
如果你想允许所有字符,那直接返回<code>null</code>。
<syntaxhighlight lang="java">
//The character filter of the value input field. Return NULL if you want to allow all characters.
//值输入字段字符过滤器,返回null允许所有字符。
return null;
}
</syntaxhighlight>
2.3.9. Full Example Class
====完整示例====
This is a full working VisibilityRequirement example.
这是完整的VisibilityRequirement示例。
 
<syntaxhighlight lang="java">
package de.keksuccino.fancymenu.api.visibilityrequirements.example;
 
 
}
</syntaxhighlight>
复制代码
==== 注册Visibility Requirement ====
你弟任务!完成啦!啊哈哈哈哈哈哈哈哈哈哈哈哈!
 
<code>VisibilityRequirement</code>:<code>VisibilityRequirementRegistry</code>先生,Java陛下,我们在天堂(游戏加载)见!
注册Visibility Requirement
<syntaxhighlight lang="java">
你弟任务!完成啦!啊哈哈哈哈哈哈哈哈哈哈哈哈
VisibilityRequirement:VisibilityRequirementRegistry先生,Java陛下,我们在天堂(游戏加载)见!
package de.keksuccino.fancymenu;
 
 
}
</syntaxhighlight>
复制代码
[[分类:FancyMenu]]
178

个编辑