Add support for 9-slice images and animated images
This commit is contained in:
parent
eef2860b4b
commit
a42f688274
78
elements.lua
78
elements.lua
@ -23,40 +23,44 @@ a[16] = {"bgcolor", "string"}
|
||||
a[17] = {"fontcolor", "string"}
|
||||
a[18] = {"gui_element_name", "string"}
|
||||
a[19] = {"texture_name", "string"}
|
||||
a[20] = {a[4], a[3], a[19]}
|
||||
a[21] = {"name", "string"}
|
||||
a[22] = {"frame_count", "number"}
|
||||
a[23] = {"frame_duration", "number"}
|
||||
a[24] = {"mesh", "string"}
|
||||
a[25] = {{{"textures", "string"}, "..."}}
|
||||
a[26] = {{"rotation_x", "number"}, {"rotation_y", "number"}}
|
||||
a[27] = {"continuous", "boolean"}
|
||||
a[28] = {"mouse_control", "boolean"}
|
||||
a[29] = {{"frame_loop_begin", "number"}, {"frame_loop_end", "number"}}
|
||||
a[30] = {"item_name", "string"}
|
||||
a[31] = {"fullscreen", "fullscreen"}
|
||||
a[32] = {"auto_clip", "boolean"}
|
||||
a[33] = {"middle_x", "number"}
|
||||
a[34] = {"middle_y", "number"}
|
||||
a[35] = {"label", "string"}
|
||||
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] = {"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]}}
|
||||
a[20] = {"middle_x", "number"}
|
||||
a[21] = {"middle_y", "number"}
|
||||
a[22] = {a[20], a[21], {"middle_x2", "number"}, {"middle_y2", "number"}}
|
||||
a[23] = {a[20], a[21]}
|
||||
a[24] = {a[20]}
|
||||
a[25] = {a[4], a[3], a[19]}
|
||||
a[26] = {"name", "string"}
|
||||
a[27] = {"frame_count", "number"}
|
||||
a[28] = {"frame_duration", "number"}
|
||||
a[29] = {"frame_start", "number"}
|
||||
a[30] = {"mesh", "string"}
|
||||
a[31] = {{{"textures", "string"}, "..."}}
|
||||
a[32] = {{"rotation_x", "number"}, {"rotation_y", "number"}}
|
||||
a[33] = {"continuous", "boolean"}
|
||||
a[34] = {"mouse_control", "boolean"}
|
||||
a[35] = {{"frame_loop_begin", "number"}, {"frame_loop_end", "number"}}
|
||||
a[36] = {"item_name", "string"}
|
||||
a[37] = {"fullscreen", "fullscreen"}
|
||||
a[38] = {"auto_clip", "boolean"}
|
||||
a[39] = {"label", "string"}
|
||||
a[40] = {{a[4], a[3], a[26], a[39]}}
|
||||
a[41] = {"default", "string"}
|
||||
a[42] = {a[4], a[3], a[26], a[39], a[41]}
|
||||
a[43] = {{a[4], a[39]}}
|
||||
a[44] = {"noclip", "boolean"}
|
||||
a[45] = {"drawborder", "boolean"}
|
||||
a[46] = {{a[4], a[3], a[19], a[26], a[39], a[44], a[45], {"pressed_texture_name", "string"}}, {a[4], a[3], a[19], a[26], a[39], a[44], a[45]}, {a[4], a[3], a[19], a[26], a[39]}}
|
||||
a[47] = {{{"listelems", "string"}, "..."}}
|
||||
a[48] = {"selected_idx", "number"}
|
||||
a[49] = {"transparent", "boolean"}
|
||||
a[50] = {{{"captions", "string"}, "..."}}
|
||||
a[51] = {"current_tab", "string"}
|
||||
a[52] = {"draw_border", "boolean"}
|
||||
a[53] = {{{"items", "string"}, "..."}}
|
||||
a[54] = {"index_event", "boolean"}
|
||||
a[55] = {{"opts", "table"}, "..."}
|
||||
a[56] = {{a[55]}}
|
||||
a[57] = {{"props", "table"}, "..."}
|
||||
a[58] = {a[26]}
|
||||
a[59] = {{{{{"selectors", "string"}, "..."}}, a[57]}, {a[58], a[57]}}
|
||||
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[4], a[3], a[19], a[22]}, {a[4], a[3], a[19], a[23]}, {a[4], a[3], a[19], a[24]}, a[25]}, ["animated_image"] = {{a[4], a[3], a[26], a[19], a[27], a[28], a[29], a[22]}, {a[4], a[3], a[26], a[19], a[27], a[28], a[29], a[23]}, {a[4], a[3], a[26], a[19], a[27], a[28], a[29], a[24]}, {a[4], a[3], a[26], a[19], a[27], a[28], a[29]}, {a[4], a[3], a[26], a[19], a[27], a[28]}}, ["model"] = {{a[4], a[3], a[26], a[30], a[31], a[32], a[33], a[34], a[35], {"animation_speed", "number"}}, {a[4], a[3], a[26], a[30], a[31], a[32], a[33], a[34], a[35]}, {a[4], a[3], a[26], a[30], a[31], a[32], a[33], a[34]}, {a[4], a[3], a[26], a[30], a[31], a[32], a[33]}, {a[4], a[3], a[26], a[30], a[31], a[32]}, {a[4], a[3], a[26], a[30], a[31]}}, ["item_image"] = {{a[4], a[3], a[36]}}, ["bgcolor"] = {{a[16], a[37], {"fbgcolor", "string"}}, {a[16], a[37]}, {a[16]}}, ["background"] = {{a[4], a[3], a[19], a[38]}, a[25]}, ["background9"] = {{a[4], a[3], a[19], a[38], a[22]}, {a[4], a[3], a[19], a[38], a[23]}, {a[4], a[3], a[19], a[38], a[24]}}, ["pwdfield"] = a[40], ["field"] = {a[42], {a[26], a[39], a[41]}}, ["field_close_on_enter"] = {{a[26], {"close_on_enter", "boolean"}}}, ["textarea"] = {a[42]}, ["label"] = a[43], ["hypertext"] = {{a[4], a[3], a[26], {"text", "string"}}}, ["vertlabel"] = a[43], ["button"] = a[40], ["image_button"] = a[46], ["item_image_button"] = {{a[4], a[3], a[36], a[26], a[39]}}, ["button_exit"] = a[40], ["image_button_exit"] = a[46], ["textlist"] = {{a[4], a[3], a[26], a[47], a[48], a[49]}, {a[4], a[3], a[26], a[47], a[48]}, {a[4], a[3], a[26], a[47]}}, ["tabheader"] = {{a[4], a[2], a[26], a[50], a[51], a[49], a[52]}, {a[4], a[3], a[26], a[50], a[51], a[49], a[52]}, {a[4], a[26], a[50], a[51], a[49], a[52]}, {a[4], a[2], a[26], a[50], a[51], a[49]}, {a[4], a[3], a[26], a[50], a[51], a[49]}, {a[4], a[26], a[50], a[51], a[49]}, {a[4], a[2], a[26], a[50], a[51]}, {a[4], a[3], a[26], a[50], a[51]}, {a[4], a[26], a[50], a[51]}}, ["box"] = {{a[4], a[3], {"color", "string"}}}, ["dropdown"] = {{a[4], a[3], a[26], a[53], a[48], a[54]}, {a[4], a[1], a[26], a[53], a[48], a[54]}, {a[4], a[3], a[26], a[53], a[48]}, {a[4], a[1], a[26], a[53], a[48]}}, ["checkbox"] = {{a[4], a[26], a[39], {"selected", "boolean"}}, {a[4], a[26], a[39]}}, ["scrollbar"] = {{a[4], a[3], a[9], a[26], {"value", "number"}}}, ["scrollbaroptions"] = a[56], ["table"] = {{a[4], a[3], a[26], {{{"cells", "string"}, "..."}}, a[48]}}, ["tableoptions"] = a[56], ["tablecolumns"] = {{{{{"type", "string"}, a[55]}, "..."}}}, ["style"] = a[59], ["style_type"] = a[59], ["set_focus"] = {{a[26], {"force", "boolean"}}, a[58]}}
|
||||
|
@ -8,6 +8,40 @@ anchor:
|
||||
- - - [x, number]
|
||||
- [y, number]
|
||||
animated_image:
|
||||
- - - [x, number]
|
||||
- [y, number]
|
||||
- - [w, number]
|
||||
- [h, number]
|
||||
- [name, string]
|
||||
- [texture_name, string]
|
||||
- [frame_count, number]
|
||||
- [frame_duration, number]
|
||||
- [frame_start, number]
|
||||
- - [middle_x, number]
|
||||
- [middle_y, number]
|
||||
- [middle_x2, number]
|
||||
- [middle_y2, number]
|
||||
- - - [x, number]
|
||||
- [y, number]
|
||||
- - [w, number]
|
||||
- [h, number]
|
||||
- [name, string]
|
||||
- [texture_name, string]
|
||||
- [frame_count, number]
|
||||
- [frame_duration, number]
|
||||
- [frame_start, number]
|
||||
- - [middle_x, number]
|
||||
- [middle_y, number]
|
||||
- - - [x, number]
|
||||
- [y, number]
|
||||
- - [w, number]
|
||||
- [h, number]
|
||||
- [name, string]
|
||||
- [texture_name, string]
|
||||
- [frame_count, number]
|
||||
- [frame_duration, number]
|
||||
- [frame_start, number]
|
||||
- - [middle_x, number]
|
||||
- - - [x, number]
|
||||
- [y, number]
|
||||
- - [w, number]
|
||||
@ -162,6 +196,28 @@ hypertext:
|
||||
- [name, string]
|
||||
- [text, string]
|
||||
image:
|
||||
- - - [x, number]
|
||||
- [y, number]
|
||||
- - [w, number]
|
||||
- [h, number]
|
||||
- [texture_name, string]
|
||||
- - [middle_x, number]
|
||||
- [middle_y, number]
|
||||
- [middle_x2, number]
|
||||
- [middle_y2, number]
|
||||
- - - [x, number]
|
||||
- [y, number]
|
||||
- - [w, number]
|
||||
- [h, number]
|
||||
- [texture_name, string]
|
||||
- - [middle_x, number]
|
||||
- [middle_y, number]
|
||||
- - - [x, number]
|
||||
- [y, number]
|
||||
- - [w, number]
|
||||
- [h, number]
|
||||
- [texture_name, string]
|
||||
- - [middle_x, number]
|
||||
- - - [x, number]
|
||||
- [y, number]
|
||||
- - [w, number]
|
||||
|
@ -84,10 +84,15 @@ def hook(name, *, passive=False):
|
||||
return func
|
||||
return add_hook
|
||||
|
||||
# Fix background9
|
||||
# Fix 9-slice co-ordinates
|
||||
@hook('background9')
|
||||
@hook('image', passive=True)
|
||||
@hook('animated_image', passive=True)
|
||||
def _background9_hook(params):
|
||||
assert params[-1] == ('middle', 'string')
|
||||
if params[-1] != ('middle', 'string'):
|
||||
assert ('middle', 'string') not in params
|
||||
return
|
||||
|
||||
params[-1] = param = []
|
||||
param.append(('middle_x', 'number'))
|
||||
yield params
|
||||
@ -96,6 +101,7 @@ def _background9_hook(params):
|
||||
param.append(('middle_x2', 'number'))
|
||||
param.append(('middle_y2', 'number'))
|
||||
yield params
|
||||
del params[-1]
|
||||
|
||||
# Fix bgcolor
|
||||
@hook('bgcolor')
|
||||
|
34
tests.lua
34
tests.lua
@ -111,6 +111,9 @@ local fs = [[
|
||||
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]
|
||||
image[1,2;3,4;air.png;5]
|
||||
image[1,2;3,4;air.png;5,6]
|
||||
image[1,2;3,4;air.png;5,6,7,8]
|
||||
]]
|
||||
fs = ('\n' .. fs):gsub('\n[ \n]*', '')
|
||||
|
||||
@ -377,6 +380,37 @@ test_parse_unparse(fs, {
|
||||
drawborder = false,
|
||||
pressed_texture_name = "img2.png",
|
||||
},
|
||||
{
|
||||
type = "image",
|
||||
x = 1,
|
||||
y = 2,
|
||||
w = 3,
|
||||
h = 4,
|
||||
texture_name = "air.png",
|
||||
middle_x = 5,
|
||||
},
|
||||
{
|
||||
type = "image",
|
||||
x = 1,
|
||||
y = 2,
|
||||
w = 3,
|
||||
h = 4,
|
||||
texture_name = "air.png",
|
||||
middle_x = 5,
|
||||
middle_y = 6,
|
||||
},
|
||||
{
|
||||
type = "image",
|
||||
x = 1,
|
||||
y = 2,
|
||||
w = 3,
|
||||
h = 4,
|
||||
texture_name = "air.png",
|
||||
middle_x = 5,
|
||||
middle_y = 6,
|
||||
middle_x2 = 7,
|
||||
middle_y2 = 8,
|
||||
},
|
||||
})
|
||||
|
||||
local function remove_trailing_params(elem_s, elem, ...)
|
||||
|
Loading…
Reference in New Issue
Block a user