Handle image_button{,_exit} parameters like the MT engine

This commit is contained in:
luk3yx 2022-04-29 16:49:42 +12:00
parent 7ec3236a18
commit eef2860b4b
4 changed files with 138 additions and 15 deletions

View File

@ -43,18 +43,20 @@ a[36] = {{a[4], a[3], a[21], a[35]}}
a[37] = {"default", "string"}
a[38] = {a[4], a[3], a[21], a[35], a[37]}
a[39] = {{a[4], a[35]}}
a[40] = {a[4], a[3], a[19], a[21], a[35]}
a[41] = {{{"listelems", "string"}, "..."}}
a[42] = {"selected_idx", "number"}
a[43] = {"transparent", "boolean"}
a[44] = {{{"captions", "string"}, "..."}}
a[45] = {"current_tab", "string"}
a[46] = {"draw_border", "boolean"}
a[47] = {{{"items", "string"}, "..."}}
a[48] = {"index_event", "boolean"}
a[49] = {{"opts", "table"}, "..."}
a[50] = {{a[49]}}
a[51] = {{"props", "table"}, "..."}
a[52] = {a[21]}
a[53] = {{{{{"selectors", "string"}, "..."}}, a[51]}, {a[52], a[51]}}
return {["formspec_version"] = {{{"version", "number"}}}, ["size"] = {{a[3]}, {{a[1], a[2], {"fixed_size", "boolean"}}}}, ["position"] = a[5], ["anchor"] = a[5], ["padding"] = a[5], ["no_prepend"] = a[7], ["real_coordinates"] = {{{"bool", "boolean"}}}, ["container"] = a[5], ["container_end"] = a[7], ["scroll_container"] = {{a[4], a[3], a[8], a[9], {"scroll_factor", "number"}}, {a[4], a[3], a[8], a[9]}}, ["scroll_container_end"] = a[7], ["list"] = {{a[10], a[11], a[4], a[3], {"starting_item_index", "number"}}, {a[10], a[11], a[4], a[3]}}, ["listring"] = {{a[10], a[11]}, a[6]}, ["listcolors"] = {{a[12], a[13], a[14], {"tooltip_bgcolor", "string"}, {"tooltip_fontcolor", "string"}}, {a[12], a[13], a[14]}, {a[12], a[13]}}, ["tooltip"] = {{a[4], a[3], a[15], a[16], a[17]}, {a[4], a[3], a[15], a[16]}, {a[18], a[15], a[16], a[17]}, {a[4], a[3], a[15]}, {a[18], a[15], a[16]}, {a[18], a[15]}}, ["image"] = {a[20]}, ["animated_image"] = {{a[4], a[3], a[21], a[19], a[22], a[23], {"frame_start", "number"}}, {a[4], a[3], a[21], a[19], a[22], a[23]}}, ["model"] = {{a[4], a[3], a[21], a[24], a[25], a[26], a[27], a[28], a[29], {"animation_speed", "number"}}, {a[4], a[3], a[21], a[24], a[25], a[26], a[27], a[28], a[29]}, {a[4], a[3], a[21], a[24], a[25], a[26], a[27], a[28]}, {a[4], a[3], a[21], a[24], a[25], a[26], a[27]}, {a[4], a[3], a[21], a[24], a[25], a[26]}, {a[4], a[3], a[21], a[24], a[25]}}, ["item_image"] = {{a[4], a[3], a[30]}}, ["bgcolor"] = {{a[16], a[31], {"fbgcolor", "string"}}, {a[16], a[31]}, {a[16]}}, ["background"] = {{a[4], a[3], a[19], a[32]}, a[20]}, ["background9"] = {{a[4], a[3], a[19], a[32], {a[33], a[34], {"middle_x2", "number"}, {"middle_y2", "number"}}}, {a[4], a[3], a[19], a[32], {a[33], a[34]}}, {a[4], a[3], a[19], a[32], {a[33]}}}, ["pwdfield"] = a[36], ["field"] = {a[38], {a[21], a[35], a[37]}}, ["field_close_on_enter"] = {{a[21], {"close_on_enter", "boolean"}}}, ["textarea"] = {a[38]}, ["label"] = a[39], ["hypertext"] = {{a[4], a[3], a[21], {"text", "string"}}}, ["vertlabel"] = a[39], ["button"] = a[36], ["image_button"] = {{a[4], a[3], a[19], a[21], a[35], {"noclip", "boolean"}, {"drawborder", "boolean"}, {"pressed_texture_name", "string"}}, a[40]}, ["item_image_button"] = {{a[4], a[3], a[30], a[21], a[35]}}, ["button_exit"] = a[36], ["image_button_exit"] = {a[40]}, ["textlist"] = {{a[4], a[3], a[21], a[41], a[42], a[43]}, {a[4], a[3], a[21], a[41], a[42]}, {a[4], a[3], a[21], a[41]}}, ["tabheader"] = {{a[4], a[2], a[21], a[44], a[45], a[43], a[46]}, {a[4], a[3], a[21], a[44], a[45], a[43], a[46]}, {a[4], a[21], a[44], a[45], a[43], a[46]}, {a[4], a[2], a[21], a[44], a[45], a[43]}, {a[4], a[3], a[21], a[44], a[45], a[43]}, {a[4], a[21], a[44], a[45], a[43]}, {a[4], a[2], a[21], a[44], a[45]}, {a[4], a[3], a[21], a[44], a[45]}, {a[4], a[21], a[44], a[45]}}, ["box"] = {{a[4], a[3], {"color", "string"}}}, ["dropdown"] = {{a[4], a[3], a[21], a[47], a[42], a[48]}, {a[4], a[1], a[21], a[47], a[42], a[48]}, {a[4], a[3], a[21], a[47], a[42]}, {a[4], a[1], a[21], a[47], a[42]}}, ["checkbox"] = {{a[4], a[21], a[35], {"selected", "boolean"}}, {a[4], a[21], a[35]}}, ["scrollbar"] = {{a[4], a[3], a[9], a[21], {"value", "number"}}}, ["scrollbaroptions"] = a[50], ["table"] = {{a[4], a[3], a[21], {{{"cells", "string"}, "..."}}, a[42]}}, ["tableoptions"] = a[50], ["tablecolumns"] = {{{{{"type", "string"}, a[49]}, "..."}}}, ["style"] = a[53], ["style_type"] = a[53], ["set_focus"] = {{a[21], {"force", "boolean"}}, a[52]}}
a[40] = {"noclip", "boolean"}
a[41] = {"drawborder", "boolean"}
a[42] = {{a[4], a[3], a[19], a[21], a[35], a[40], a[41], {"pressed_texture_name", "string"}}, {a[4], a[3], a[19], a[21], a[35], a[40], a[41]}, {a[4], a[3], a[19], a[21], a[35]}}
a[43] = {{{"listelems", "string"}, "..."}}
a[44] = {"selected_idx", "number"}
a[45] = {"transparent", "boolean"}
a[46] = {{{"captions", "string"}, "..."}}
a[47] = {"current_tab", "string"}
a[48] = {"draw_border", "boolean"}
a[49] = {{{"items", "string"}, "..."}}
a[50] = {"index_event", "boolean"}
a[51] = {{"opts", "table"}, "..."}
a[52] = {{a[51]}}
a[53] = {{"props", "table"}, "..."}
a[54] = {a[21]}
a[55] = {{{{{"selectors", "string"}, "..."}}, a[53]}, {a[54], a[53]}}
return {["formspec_version"] = {{{"version", "number"}}}, ["size"] = {{a[3]}, {{a[1], a[2], {"fixed_size", "boolean"}}}}, ["position"] = a[5], ["anchor"] = a[5], ["padding"] = a[5], ["no_prepend"] = a[7], ["real_coordinates"] = {{{"bool", "boolean"}}}, ["container"] = a[5], ["container_end"] = a[7], ["scroll_container"] = {{a[4], a[3], a[8], a[9], {"scroll_factor", "number"}}, {a[4], a[3], a[8], a[9]}}, ["scroll_container_end"] = a[7], ["list"] = {{a[10], a[11], a[4], a[3], {"starting_item_index", "number"}}, {a[10], a[11], a[4], a[3]}}, ["listring"] = {{a[10], a[11]}, a[6]}, ["listcolors"] = {{a[12], a[13], a[14], {"tooltip_bgcolor", "string"}, {"tooltip_fontcolor", "string"}}, {a[12], a[13], a[14]}, {a[12], a[13]}}, ["tooltip"] = {{a[4], a[3], a[15], a[16], a[17]}, {a[4], a[3], a[15], a[16]}, {a[18], a[15], a[16], a[17]}, {a[4], a[3], a[15]}, {a[18], a[15], a[16]}, {a[18], a[15]}}, ["image"] = {a[20]}, ["animated_image"] = {{a[4], a[3], a[21], a[19], a[22], a[23], {"frame_start", "number"}}, {a[4], a[3], a[21], a[19], a[22], a[23]}}, ["model"] = {{a[4], a[3], a[21], a[24], a[25], a[26], a[27], a[28], a[29], {"animation_speed", "number"}}, {a[4], a[3], a[21], a[24], a[25], a[26], a[27], a[28], a[29]}, {a[4], a[3], a[21], a[24], a[25], a[26], a[27], a[28]}, {a[4], a[3], a[21], a[24], a[25], a[26], a[27]}, {a[4], a[3], a[21], a[24], a[25], a[26]}, {a[4], a[3], a[21], a[24], a[25]}}, ["item_image"] = {{a[4], a[3], a[30]}}, ["bgcolor"] = {{a[16], a[31], {"fbgcolor", "string"}}, {a[16], a[31]}, {a[16]}}, ["background"] = {{a[4], a[3], a[19], a[32]}, a[20]}, ["background9"] = {{a[4], a[3], a[19], a[32], {a[33], a[34], {"middle_x2", "number"}, {"middle_y2", "number"}}}, {a[4], a[3], a[19], a[32], {a[33], a[34]}}, {a[4], a[3], a[19], a[32], {a[33]}}}, ["pwdfield"] = a[36], ["field"] = {a[38], {a[21], a[35], a[37]}}, ["field_close_on_enter"] = {{a[21], {"close_on_enter", "boolean"}}}, ["textarea"] = {a[38]}, ["label"] = a[39], ["hypertext"] = {{a[4], a[3], a[21], {"text", "string"}}}, ["vertlabel"] = a[39], ["button"] = a[36], ["image_button"] = a[42], ["item_image_button"] = {{a[4], a[3], a[30], a[21], a[35]}}, ["button_exit"] = a[36], ["image_button_exit"] = a[42], ["textlist"] = {{a[4], a[3], a[21], a[43], a[44], a[45]}, {a[4], a[3], a[21], a[43], a[44]}, {a[4], a[3], a[21], a[43]}}, ["tabheader"] = {{a[4], a[2], a[21], a[46], a[47], a[45], a[48]}, {a[4], a[3], a[21], a[46], a[47], a[45], a[48]}, {a[4], a[21], a[46], a[47], a[45], a[48]}, {a[4], a[2], a[21], a[46], a[47], a[45]}, {a[4], a[3], a[21], a[46], a[47], a[45]}, {a[4], a[21], a[46], a[47], a[45]}, {a[4], a[2], a[21], a[46], a[47]}, {a[4], a[3], a[21], a[46], a[47]}, {a[4], a[21], a[46], a[47]}}, ["box"] = {{a[4], a[3], {"color", "string"}}}, ["dropdown"] = {{a[4], a[3], a[21], a[49], a[44], a[50]}, {a[4], a[1], a[21], a[49], a[44], a[50]}, {a[4], a[3], a[21], a[49], a[44]}, {a[4], a[1], a[21], a[49], a[44]}}, ["checkbox"] = {{a[4], a[21], a[35], {"selected", "boolean"}}, {a[4], a[21], a[35]}}, ["scrollbar"] = {{a[4], a[3], a[9], a[21], {"value", "number"}}}, ["scrollbaroptions"] = a[52], ["table"] = {{a[4], a[3], a[21], {{{"cells", "string"}, "..."}}, a[44]}}, ["tableoptions"] = a[52], ["tablecolumns"] = {{{{{"type", "string"}, a[51]}, "..."}}}, ["style"] = a[55], ["style_type"] = a[55], ["set_focus"] = {{a[21], {"force", "boolean"}}, a[54]}}

View File

@ -178,6 +178,15 @@ image_button:
- [noclip, boolean]
- [drawborder, boolean]
- [pressed_texture_name, string]
- - - [x, number]
- [y, number]
- - [w, number]
- [h, number]
- [texture_name, string]
- [name, string]
- [label, string]
- [noclip, boolean]
- [drawborder, boolean]
- - - [x, number]
- [y, number]
- - [w, number]
@ -186,6 +195,25 @@ image_button:
- [name, string]
- [label, string]
image_button_exit:
- - - [x, number]
- [y, number]
- - [w, number]
- [h, number]
- [texture_name, string]
- [name, string]
- [label, string]
- [noclip, boolean]
- [drawborder, boolean]
- [pressed_texture_name, string]
- - - [x, number]
- [y, number]
- - [w, number]
- [h, number]
- [texture_name, string]
- [name, string]
- [label, string]
- [noclip, boolean]
- [drawborder, boolean]
- - - [x, number]
- [y, number]
- - [w, number]

View File

@ -170,6 +170,23 @@ def _model_hook(params):
for i in range(5, len(params) + 1):
yield params[:i]
# Parse image_button/image_button_exit like the source code does
# image_button_exit[] can have the extra parameters as well and
# pressed_texture_name is optional if noclip and drawborder are specified.
@hook('image_button')
@hook('image_button_exit')
def _image_button_hook(params):
if len(params) != 5:
assert len(params) == 8
return
yield params
params.append(('noclip', 'boolean'))
params.append(('drawborder', 'boolean'))
yield params
params.append(('pressed_texture_name', 'string'))
yield params
_param_re = re.compile(r'^\* `([^`]+)`(?: and `([^`]+)`)?:? ')
def _raw_parse(data):
# Get everything from the elements heading to the end of the next heading

View File

@ -105,6 +105,12 @@ local fs = [[
tablecolumns[text;image;color,option=value;tree]
list[test;test2;1,2;3,4;5]
list[test6;test7;8,9;10,11]
image_button[1,2;3,4;img.png;name;label]
image_button[1,2;3,4;img.png;name;label;false;true]
image_button[1,2;3,4;img.png;name;label;true;false;img2.png]
image_button_exit[1,2;3,4;img.png;name;label]
image_button_exit[1,2;3,4;img.png;name;label;false;true]
image_button_exit[1,2;3,4;img.png;name;label;true;false;img2.png]
]]
fs = ('\n' .. fs):gsub('\n[ \n]*', '')
@ -301,6 +307,76 @@ test_parse_unparse(fs, {
w = 10,
h = 11,
},
{
type = "image_button",
x = 1,
y = 2,
w = 3,
h = 4,
texture_name = "img.png",
name = "name",
label = "label",
},
{
type = "image_button",
x = 1,
y = 2,
w = 3,
h = 4,
texture_name = "img.png",
name = "name",
label = "label",
noclip = false,
drawborder = true,
},
{
type = "image_button",
x = 1,
y = 2,
w = 3,
h = 4,
texture_name = "img.png",
name = "name",
label = "label",
noclip = true,
drawborder = false,
pressed_texture_name = "img2.png",
},
{
type = "image_button_exit",
x = 1,
y = 2,
w = 3,
h = 4,
texture_name = "img.png",
name = "name",
label = "label",
},
{
type = "image_button_exit",
x = 1,
y = 2,
w = 3,
h = 4,
texture_name = "img.png",
name = "name",
label = "label",
noclip = false,
drawborder = true,
},
{
type = "image_button_exit",
x = 1,
y = 2,
w = 3,
h = 4,
texture_name = "img.png",
name = "name",
label = "label",
noclip = true,
drawborder = false,
pressed_texture_name = "img2.png",
},
})
local function remove_trailing_params(elem_s, elem, ...)