跳到主要内容

箱子选单和云界面互转

这一篇做两件方向相反的事:

  • 别的插件用箱子当选单,把它变成云界面画面。这叫箱子界面转接,用画面文件里的 proxy:。
  • 有些玩家看不到云界面(基岩版、拒绝资源包、自己输入了 /cui classic),云界面会把画面变成箱子给他们。这叫箱子备援,想自己排箱子里的格子,用画面文件里的 chest:。

两件事互不相干,可以只做其中一件。

一、把别的插件的箱子选单变成云界面​

第 1 步:先看示范​

管理员在游戏里输入 /cui proxydemo。云界面会开一个普通的箱子选单,然后马上把它接手成画面:物品排成整齐的卡片,鼠标停上去有名称和说明,可以点、可以翻页。接下来要做的就是同样的东西,只是换成你自己的插件。

第 2 步:记下原选单的三样资料​

用原本的方式打开你要转接的那个插件选单,记下:

  1. 标题:箱子上方那行字,颜色不用管。例如「每日商店 - 第 1 页」。
  2. 行数:箱子有几行,1 到 6。
  3. 控制按钮在第几格:上一页、关闭、下一页。

格号从左上角的 0 开始,往右加 1,每行 9 格:

第 1 行: 0 1 2 3 4 5 6 7 8
第 2 行: 9 10 11 12 13 14 15 16 17
第 3 行:18 19 20 21 22 23 24 25 26
第 4 行:27 28 29 30 31 32 33 34 35
第 5 行:36 37 38 39 40 41 42 43 44
第 6 行:45 46 47 48 49 50 51 52 53

第 3 步:写转接画面​

在 plugins/CloudUI/screens/ 新建 tut_shop_proxy.yml,把下面整份贴进去。然后只改最上面的 proxy::title 换成你记下的标题,buttons 换成你记下的格号。

proxy:
match:
title: ['每日商店*']
grid: items
layout: compact
slots: 0-44
skip: ['*_STAINED_GLASS_PANE', 'GLASS_PANE']
buttons:
prev: 45
close: 49
next: 53
portrait:
enabled: false
camera:
open-ticks: 16
close-ticks: 12
switch-ticks: 8
tooltip:
frame: proxy/tooltip.png
border: 24
width: 380
padding: 20
font: text
title-size: 22
size: 16
title-height: 36
line-height: 24
color: '#E2EEF4'
transition:
slide-x: 0
slide-y: 40
out-ticks: 3
in-ticks: 6
family: tut_shop_proxy
elements:
backdrop:
type: image
image: proxy/backdrop.png
x: 0
y: 0
resolution: 0.25
fit: cover
title:
type: text
text: '{title}'
font: title
size: 40
color: '#F2F5FA'
align: center
x: 960
y: 96
items:
type: grid
x: 350
y: 220
columns: 7
rows: 4
step: [176, 123]
stagger: cell
motion: {x: 0, y: 24, delay: 1}
cell:
frame:
type: image
image: main/tile_s.png
state: '{state}'
icon:
type: item
item: '{icon}'
x: 58
y: 14
size: 48
amount:
type: text
text: '{amount}'
font: text
size: 14
color: '#F2F5FA'
align: right
x: 150
y: 10
name:
type: text
text: '{name}'
font: text
size: 16
color: '#E2EEF4'
align: center
x: 82
y: 76
hit:
type: button
hover: main/tile_s_hover.png
state: '{state}'
hit: [0, 0, 164, 111]
click:
left: ['custom: slot']
right: ['custom: slot']
shift-left: ['custom: slot shift']
prev:
type: button
image: teleport/btn_go.png
hover: teleport/btn_go_hover.png
state: '{button.prev.state}'
x: 600
y: 740
hit: [600, 740, 170, 54]
click:
left: ['custom: button prev']
prev-label:
type: text
text: '上一页'
font: title
size: 18
color: '#E2EEF4'
align: center
visible: '{button.prev.state}'
x: 685
y: 759
next:
type: button
image: teleport/btn_go.png
hover: teleport/btn_go_hover.png
state: '{button.next.state}'
x: 1150
y: 740
hit: [1150, 740, 170, 54]
click:
left: ['custom: button next']
next-label:
type: text
text: '下一页'
font: title
size: 18
color: '#E2EEF4'
align: center
visible: '{button.next.state}'
x: 1235
y: 759
close:
type: button
image: main/close.png
hover: main/close_hover.png
x: 842
y: 830
hit: [842, 830, 236, 52]
click:
left: ['custom: button close']
close-label:
type: text
text: '关闭'
font: title
size: 24
color: '#E2EEF4'
align: center
x: 960
y: 845

proxy: 里每一行的意思:

键说明
match.title原选单的标题。不分大小写、不看颜色,* 代表任意文字,可以写好几个。'每日商店*' 能对上「每日商店」和「每日商店 - 第 2 页」
match.rows选填。写了就只接这个行数的箱子
grid物品排进画面上哪个格子元素,这里是下面的 items
layoutcompact 是有东西的格子依序排进来,空格略过;exact 是画面第 N 格放箱子第 N 格
slots哪些格子算物品。0-44 是前五行,最下面一行留给控制按钮
skip哪些物品不显示,一般是当装饰的玻璃板
buttons给位置固定的按钮取名字,写成「名字: 格号」

画面上的 custom: slot 是「点这一格对应的箱子格」,custom: button close 是「点 buttons 里叫 close 的那一格」。点击会原样交回原插件,扣钱、给东西、翻页都照它自己的规则。

原插件的选单没有上一页、下一页的话,把 buttons 里的 prev、next 两行,和下面 prev、prev-label、next、next-label 四个元素删掉。

第 4 步:重新载入,打开原选单​

/cui reload,然后用原本的方式打开那个插件的选单(指令、点 NPC 都行)。看到的应该是云界面画面:上方是原选单的标题,中间 7 栏 4 行的卡片是箱子里的物品,鼠标停上去显示物品的名称和说明。

还是普通箱子的话,先看本页最下面的常见问题。

二、给看不到云界面的玩家排箱子版面​

基岩版玩家、拒绝了资源包的玩家、输入过 /cui classic 的玩家,打开任何云界面画面时看到的都是箱子:画面上每个有点击动作的按钮变成一格物品。这是自动的,不用设定。自动排出来不好看时,用 chest: 自己排。

第 1 步:做一个有三个按钮的小选单​

新建 plugins/CloudUI/screens/tut_chest_menu.yml:

portrait:
enabled: false
camera:
animation: false
elements:
title:
type: text
text: '服务器选单'
font: title
size: 40
color: '#F2F5FA'
align: center
x: 960
y: 300
warp:
type: button
image: main/tile_s.png
hover: main/tile_s_hover.png
x: 700
y: 420
hit: [700, 420, 164, 111]
click:
left: ['message: <gray>传送:在 screens/tut_chest_menu.yml 换成你的指令']
tooltip: ['传送', '回到主城']
warp-icon:
type: item
item: 'vanilla:ENDER_PEARL'
x: 758
y: 434
size: 48
warp-name:
type: text
text: '传送'
font: text
size: 16
color: '#E2EEF4'
align: center
x: 782
y: 496
shop:
type: button
image: main/tile_s.png
hover: main/tile_s_hover.png
x: 878
y: 420
hit: [878, 420, 164, 111]
click:
left: ['message: <gray>商店:在 screens/tut_chest_menu.yml 换成你的指令']
shop-icon:
type: item
item: 'vanilla:EMERALD'
x: 936
y: 434
size: 48
shop-name:
type: text
text: '商店'
font: text
size: 16
color: '#E2EEF4'
align: center
x: 960
y: 496
daily:
type: button
image: main/tile_s.png
hover: main/tile_s_hover.png
x: 1056
y: 420
hit: [1056, 420, 164, 111]
click:
left: ['message: <gray>签到:在 screens/tut_chest_menu.yml 换成你的指令']
daily-icon:
type: item
item: 'vanilla:CLOCK'
x: 1114
y: 434
size: 48
daily-name:
type: text
text: '签到'
font: text
size: 16
color: '#E2EEF4'
align: center
x: 1138
y: 496
close:
type: button
image: main/close.png
hover: main/close_hover.png
x: 842
y: 580
hit: [842, 580, 236, 52]
click:
left: ['close']
close-name:
type: text
text: '关闭'
font: text
size: 20
color: '#E2EEF4'
align: center
x: 960
y: 597

/cui reload,/cui open tut_chest_menu,先确认云界面画面是好的:一行标题、三个带图标的按钮、一个关闭按钮。

第 2 步:切到箱子模式看自动排的样子​

输入 /cui classic,提示已改用箱子选单。再 /cui open tut_chest_menu,这次打开的是箱子:

  • 三个按钮变成末影珍珠、绿宝石、时钟三个物品,名字是按钮上最大的那段字。
  • 「传送」的说明里有「回到主城」,来自按钮的 tooltip。
  • 关闭按钮变成屏障,因为它的第一个动作是 close。
  • 箱子标题是「服务器选单」,取的是画面上不在按钮里的最大一段字。

第 3 步:加 chest 自己排​

在文件最外层(和 elements: 同一层)加一段:

chest:
rows: 3
title: '<dark_aqua>服务器选单'
fill: minecraft:gray_stained_glass_pane
buttons:
- id: warp
slot: 11
item: minecraft:compass
name: '<aqua>传送'
lore: ['<gray>点一下回到主城']
- id: shop
slot: 13
- id: daily
slot: 15
- id: close
slot: 22

/cui reload 后再 /cui open tut_chest_menu。箱子变成三行,空格填满灰色玻璃板,三个按钮在第二行的 11、13、15,关闭在第三行正中的 22。「传送」换成了指南针,名字和说明也换成 chest: 里写的。

键说明
rows箱子行数,1 到 6。不写就自动
title箱子标题,可以用 MiniMessage 颜色和变量。不写就取画面上最大的字
fill空格填什么物品。填进去的物品没有名字,点了没反应
buttons列表,每一项的 id 是按钮在 elements: 里的名字
slot放第几格,从 0 数起
item换成别的物品。不写就用按钮上画的物品
name / lore物品名称和说明。lore 写了会整个换掉原本的说明
hide写 true 就不放进箱子

没列在 buttons 里的按钮照自动的方式放进剩下的空格。

看完记得再输入一次 /cui classic 换回云界面。这个设定是记在玩家身上的,重进服务器也还在。

这个画面不要箱子版​

整页是一张图、放进箱子没有意义的画面,在最外层写:

chest: false

箱子模式的玩家打开它时什么都不会出现。

常见问题​

打开原插件的选单还是普通箱子​

依序检查:match.title 有没有对上(标题后面会变的部分用 *);写了 match.rows 但行数不一样;改完没有 /cui reload;你自己是不是还在 /cui classic 的箱子模式。另外有些插件的选单不是真的箱子,而是直接发封包给客户端,服务器看不到,这种转接不了。

后台提示「画面 … 的箱子版面:…」​

chest: 里有地方写错了。写错不会让画面打不开,只是那一部分改回自动。常见的几种:行数不是 1 到 6、格子超出箱子大小、两个按钮写了同一格、item 写的物品找不到、id 写了画面里没有的按钮。同一句只提示一次,照提示改完 /cui reload。

某个按钮没出现在箱子里​

只有带点击动作的按钮会进箱子。另外按钮的 state 是 hidden 或 false、玩家没有按钮的 permission 时,也不会放进去。

物品点了没反应​

转接画面里,格子按钮的 click 要写 custom: slot。原插件只认右键或 Shift 点击的话,对应加上 right、shift-left。

相关页面​

  • 箱子界面转接:proxy: 的全部设定、能用的变量和动作
  • 箱子备援:哪些玩家会用箱子、自动转换的规则、chest: 的全部写法
  • 背包投影:要在画面上拖放物品(仓库、末影箱)看这页
  • 格子:grid 元素
  • 指令:/cui classic、/cui proxydemo
0:000:00