修改
子控件属性修改
下面这种方法我们可以使用斜杠区分子控件,这样就不需要使用 controls 去修改某个子控件了。同时去除一些不必要修改的属性:
原文件
1
2
3
4
5
6
7
8
9
"test": { "controls": [ { "test": { "controls": [{"test": {"type": "label","text": "hello world"}}] } } ]}
接下来,我们只需要修改 text 属性的内容就可以这样做:
新文件
1
2
3
"test/test/test": { "text": "test"}
引用修改
一般修改引用只需要在控件名后方"@xxx.xxx"或"@xxx"。另外,如果没有修改引用的需要,可以去除引用。这样不会对原来的引用影响。
RP/ui/start_screen.json
1
"start_screen": {}
最值得注意的是,修改引用后并且没有任何属性的情况下,会对当前控件重置并仅使用引用控件的属性。
RP/ui/start_screen.json
1
2
// 这样就会闪退"start_screen@common.empty_panel": {}
数组修改
我们总是需要对其他资源包的 controls 进行增加控件或者删除控件。但是为了修改,我们就需要使用到
modifications 仅用于修改低于当前资源包排序的资源包,一般我们只对 vanilla 进行处理。
(资源包排序为:世界资源包 > 全局资源 > 游戏安装包资源包 > treatment,其中他们还可以细分为许多部分,游戏安装包资源包排序又能分为 vanilla版本包 > vanilla > vanilla_base。)
每个控件中 modifications 属性可以同时执行多个修改操作,不过,当目标不存在时、未知的修改操作会报错。
数组对象属性 | 属性名 | 值 | 描述 |
---|---|---|---|
array_name | 数组键名 | 字符串 | 定义要修改的目标数组。 |
operation | 修改操作 | 字符串:列举 | 执行的修改操作。列举的值详见下方内容。 该属性是必要的! |
where | 执行操作的对象 | 对象 | 执行操作的对象,可模糊(指使用目标对象中的某个属性。控件无法模糊,必须是完整控件)选中某个对象。 |
value | 执行操作后的值 | 数组 或 对象 | 执行操作后的值。 单个对象时使用对象,多个对象时使用数组。 |
target | 被操作的对象 | 对象 | 被操作的对象。 |
接下来我们将展示几种修改操作:
插入
insert_front 插入到数组的开始处。示例
1
2
3
4
5
6
7
8
9
10
11
12
13
"modifications": [ // value 目标插入到数组开始处 { "array_name": "controls", "operation": "insert_front", "value": {"test":{}} }, { "array_name": "bindings", "operation": "insert_front", "value": {"binding_name":"#is_insert"} }]
示例
1
2
3
4
5
6
7
8
9
10
11
12
13
"modifications": [ // value 目标插入到数组结尾处 { "array_name": "controls", "operation": "insert_back", "value": {"test":{}} }, { "array_name": "controls", "operation": "insert_back", "where": {"binding_name":"#is_insert"} }]
示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
"modifications": [ // value 目标插入到 test2 控件前方 { "control_name": "test2", "operation": "insert_before", "value": {"test":{}} }, // value 目标插入到 where 目标前方 { "array_name": "bindings", "where": {"binding_name":"#test"}, "operation": "insert_before", "value": {"binding_name":"#is_insert"} }]
示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
"modifications": [ // value 目标插入到 test2 控件后方 { "control_name": "test2", "operation": "insert_after", "value": {"test":{}} }, // value 目标插入到 where 目标后方 { "array_name": "bindings", "where": {"binding_name":"#test"}, "operation": "insert_after", "value": {"binding_name":"#is_insert"} }]
删除
remove 移除目标对象。示例
1
2
3
4
5
6
7
8
9
10
11
12
13
"modifications": [ // 删除目标控件 { "control_name": "test", "operation": "remove" }, // 删除目标绑定 { "array_name": "bindings", "where": {"binding_name":"#test"}, "operation": "remove" }]
替换
replace 替换目标对象。示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
"modifications": [ // 控件替换为 value 目标 { "control_name": "test", "operation": "replace", "value": {"replace":{}} }, // where 目标替换为 value 目标 { "array_name": "bindings", "where": {"binding_name":"#test"}, "operation": "replace", "value": {"binding_name":"#is_replace"} }]
交换
swap 交换目标对象。示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
"modifications": [ // 控件与目标交换 { "control_name": "test", "operation": "swap", "target": {"replace":{}} }, // where 目标与目标交换 { "array_name": "bindings", "where": {"binding_name":"#test"}, "operation": "swap", "target": {"binding_name":"#is_replace"} }]
移动
move_front 移动目标对象到数组开始处。示例
1
2
3
4
5
6
7
8
9
10
11
12
13
"modifications": [ // value 目标移动到数组开始处 { "array_name": "controls", "operation": "move_front", "value": {"replace":{}} }, { "array_name": "bindings", "operation": "move_front", "where": {"binding_name":"#is_move"} }]
示例
1
2
3
4
5
6
7
8
9
10
11
12
13
"modifications": [ // value 目标移动到数组结尾处 { "array_name": "controls", "operation": "move_back", "value": {"replace":{}} }, { "array_name": "bindings", "operation": "move_back", "where": {"binding_name":"#is_move"} }]
示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
"modifications": [ // value 目标移动到控件前方 { "control_name": "test2", "operation": "move_before", "value": {"test":{}} }, // value 目标移动到 where 目标前方 { "array_name": "bindings", "where": {"binding_name":"#test"}, "operation": "move_before", "value": {"binding_name":"#is_move"} }]
示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
"modifications": [ // value 目标移动到控件后方 { "control_name": "test2", "operation": "move_after", "value": {"test":{}} }, // value 目标移动到 where 目标后方 { "array_name": "bindings", "where": {"binding_name":"#test"}, "operation": "move_after", "value": {"binding_name":"#is_move"} }]