状态切换
state 和 states 让 图片 与 按钮 依变量换图。红点角标「有未读才显示」、页签「选中的那个换成亮的」、卡片「空的不画」都靠它。它不是一种元素,是写在 image 和 button 上的两个选项。
最小例子
把下面的内容存成 plugins/CloudUI/screens/state_demo.yml:
portrait:
enabled: false
camera:
animation: false
values:
lamp: closed
elements:
chip:
type: image
image: hudlayout/chip_off.png # 平常的图
state: '{lamp}'
states: {open: hudlayout/chip_on.png}
x: 872
y: 440
turn-on:
type: button
image: main/close.png
hover: main/close_hover.png
x: 842
y: 520
hit: [846, 524, 228, 44]
click:
left: ['console: cui set {player} lamp=open']
turn-on-label:
type: text
text: '打开'
size: 20
align: center
x: 960
y: 537
turn-off:
type: button
image: main/close.png
hover: main/close_hover.png
x: 842
y: 590
hit: [846, 594, 228, 44]
click:
left: ['console: cui set {player} lamp=closed']
turn-off-label:
type: text
text: '关上'
size: 20
align: center
x: 960
y: 607
{lamp} 的值是 open 时,图片换成 states 里对应的那张;是别的值时用 image 里平常的图。
在游戏里看到
- 文件放进
plugins/CloudUI/screens/。 - 执行
/cui reload。 - 执行
/cui open state_demo。上面有一个小标签,点「打开」它换成亮的图,点「关上」换回来。
规则
state是一个变量;它的值在states里找到时,改用那张图(''= 不显示);找不到就用image。states的true也对应on、yes;false也对应off、no。- 值是
hidden时不显示;PlaceholderAPI 变量没有被换掉(例如插件没装)时也不显示,不会露出默认图。
| 选项 | 说明 |
|---|---|
state | 一个变量,可以是 {键名} 或 %PlaceholderAPI% |
states | 值: 图片路径 的对照表;图片路径写 '' 表示这个值时不画 |
常用写法
有未读才显示的红点
存成 screens/state_badge.yml:
portrait:
enabled: false
camera:
animation: false
elements:
mail-badge:
type: image
image: main/mail_badge.png
state: '%starmail_has_unread%'
states: {'false': ''}
x: 940
y: 520
变量是 false 时不画,其他值时画 image。没装 PlaceholderAPI 或那个插件时变量不会被换掉,红点也不显示。
选中的页签换图
存成 screens/state_tab.yml:
portrait:
enabled: false
camera:
animation: false
values:
tab_a: active
tab_b: normal
elements:
tab-a:
type: button
image: teleport/tab.png # 270 x 58
hover: teleport/tab_hover.png
state: '{tab_a}'
states: {active: teleport/tab_active.png}
hover-gpu: true
x: 680
y: 500
hit: [680, 500, 270, 58]
click:
left: ['console: cui set {player} tab_a=active tab_b=normal']
tab-b:
type: button
image: teleport/tab.png
hover: teleport/tab_hover.png
state: '{tab_b}'
states: {active: teleport/tab_active.png}
hover-gpu: true
x: 970
y: 500
hit: [970, 500, 270, 58]
click:
left: ['console: cui set {player} tab_a=normal tab_b=active']
这两个按钮有 state 但永远不会是 hidden,所以加 hover-gpu: true,悬停没有延迟。
空的格子不画
存成 screens/state_empty.yml:
portrait:
enabled: false
camera:
animation: false
elements:
rows:
type: grid
x: 540
y: 330
rows: 3
step: [0, 140]
cell:
card:
type: button
image: teleport/row.png
hit: [0, 0, 840, 132]
state: '{state}'
states: {empty: ''}
click:
left: ['message: <gray>第 {index} 行']
打开后三行都在。执行 /cui set 你的名字 rows.1.state=empty,中间那一行消失,也点不到了。把值设成 hidden 效果一样,而且不用在 states 里另外写。
常见问题
states 里的 false、true 要不要加引号。 加。照上面例子写成 {'false': ''},意思最清楚。true 同时对应 on、yes,false 同时对应 off、no,变量给哪一种都认得。
插件没装时,角标应该不显示却显示了。 检查 state 是不是写成了 PlaceholderAPI 的 %变量%。只有「没被换掉的 %变量%」会自动隐藏;{键名} 没有值时会当成普通的值,在 states 里找不到就画 image。
文字能不能用 state。 不能,state 只有图片和按钮有。文字用 visible 控制显示,进度条和二维码把 value 设成 hidden,见 文字、进度条、二维码。