formspec.lua 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. local color = core.colorize
  2. -- \208\176 is a cyrillic small a
  3. local unsafe_url = core.formspec_escape("https://u:p@wikipedi\208\176.org:1233/heIIoll?a=b#c")
  4. local clip_fs = [[
  5. style_type[label,button,image_button,item_image_button,
  6. tabheader,scrollbar,table,animated_image
  7. ,field,textarea,checkbox,dropdown;noclip=%c]
  8. label[0,0;A clipping test]
  9. button_url[0,1;3,0.8;clip_button;A clipping test;]] .. unsafe_url .. [[]
  10. image_button[0,2;3,0.8;testformspec_button_image.png;clip_image_button;A clipping test]
  11. item_image_button[0,3;3,0.8;testformspec:item;clip_item_image_button;A clipping test]
  12. tabheader[0,4.7;3,0.63;clip_tabheader;Clip,Test,Text,Tabs;1;false;false]
  13. field[0,5;3,0.8;clip_field;Title;]
  14. textarea[0,6;3,1;clip_textarea;Title;]
  15. checkbox[0,7.5;clip_checkbox;This is a test;true]
  16. dropdown[0,8;3,0.8;clip_dropdown;Select An Item,One,Two,Three,Four,Five;1]
  17. scrollbar[0,9;3,0.8;horizontal;clip_scrollbar;3]
  18. tablecolumns[text;text]
  19. table[0,10;3,1;clip_table;one,two,three,four;1]
  20. animated_image[-0.5,11;4.5,1;clip_animated_image;testformspec_animation.png;4;100]
  21. ]]
  22. local tabheaders_fs = [[
  23. tabheader[0,0;10,0.63;tabs_opaque;Opaque,Without,Border;1;false;false]
  24. tabheader[0,1;10,0.63;tabs_opaque_border;Opaque,With,Border;1;false;true]
  25. tabheader[0,2;10,0.63;tabs_transparent;Transparent,Without,Border;1;true;false]
  26. tabheader[0,3;10,0.63;tabs_transparent_border;Transparent,With,Border;1;true;true]
  27. tabheader[0,4;tabs_default;Default,Tabs;1]
  28. tabheader[0,6;10,0.5;tabs_size1;Height=0.5;1;false;false]
  29. tabheader[2,6;10,0.75;tabs_size1;Height=0.75;1;false;false]
  30. tabheader[4,6;10,1;tabs_size2;Height=1;1;false;false]
  31. tabheader[6,6;10,1.25;tabs_size2;Height=1.25;1;false;false]
  32. tabheader[8,6;10,1.5;tabs_size2;Height=1.5;1;false;false]
  33. ]]
  34. local inv_style_fs = [[
  35. style_type[list;noclip=true]
  36. list[current_player;main;-0.75,0.75;2,2]
  37. real_coordinates[false]
  38. list[current_player;main;1.5,0;3,2]
  39. real_coordinates[true]
  40. real_coordinates[false]
  41. style_type[list;size=1.1;spacing=0.1]
  42. list[current_player;main;5,0;3,2]
  43. real_coordinates[true]
  44. style_type[list;size=.001;spacing=0]
  45. list[current_player;main;7,3.5;8,4]
  46. box[3,3.5;1,1;#000000]
  47. box[5,3.5;1,1;#000000]
  48. box[4,4.5;1,1;#000000]
  49. box[3,5.5;1,1;#000000]
  50. box[5,5.5;1,1;#000000]
  51. style_type[list;spacing=.25,.125;size=.75,.875]
  52. list[current_player;main;3,3.5;3,3]
  53. style_type[list;spacing=0;size=1.1]
  54. list[current_player;main;.5,7;8,4]
  55. ]]
  56. -- Some textures from textures/base/pack and Devtest, with many different sizes
  57. -- and aspect ratios.
  58. local image_column = "image,0=logo.png,1=crack_anylength.png^[invert:rgb,2=checkbox_16.png," ..
  59. "3=checkbox_32.png,4=checkbox_64.png,5=default_lava.png," ..
  60. "6=progress_bar.png,7=progress_bar_bg.png"
  61. local words = {
  62. "esciunt", "repudiandae", "repellat", "voluptatem", "autem", "vitae", "et",
  63. "minima", "quasi", "facere", "nihil", "ea", "nemo", "rem", "non", "eos",
  64. "laudantium", "eveniet", "veritatis",
  65. }
  66. local reseed = math.random(2^31-1)
  67. math.randomseed(1337)
  68. local table_content = {}
  69. for i = 1, 100 do
  70. table.insert(table_content, words[math.random(#words)])
  71. table.insert(table_content, words[math.random(#words)])
  72. table.insert(table_content, words[math.random(#words)])
  73. table.insert(table_content, math.random(0, 7))
  74. table.insert(table_content, math.random(0, 7))
  75. table.insert(table_content, math.random(0, 7))
  76. table.insert(table_content, words[math.random(#words)])
  77. end
  78. math.randomseed(reseed)
  79. local table_fs = table.concat({
  80. "tablecolumns[text,align=left;text,align=right;text,align=center;",
  81. image_column, ",align=left;",
  82. image_column, ",align=right;",
  83. image_column, ",align=center;text,align=right]",
  84. "table[0,0;17,12;the_table;", table.concat(table_content, ","), ";1]"
  85. })
  86. local hypertext_basic = [[A hypertext element
  87. <bigger>Normal test</bigger>
  88. This is a normal text.
  89. <bigger><mono>style</mono> test</bigger>
  90. <style color="#FFFF00">Yellow text.</style> <style color='#FF0000'>Red text.</style>
  91. <style size="24">Size 24.</style> <style size=16>Size 16</style>. <style size=12>Size 12.</style>
  92. <style font="normal">Normal font.</style> <style font=mono>Mono font.</style>
  93. <bigger>Tag test</bigger>
  94. <normal>normal</normal>
  95. <mono>mono</mono>
  96. <b>bold</b>
  97. <i>italic</i>
  98. <u>underlined</u>
  99. <big>big</big>
  100. <bigger>bigger</bigger>
  101. <left>left</left>
  102. <center>center</center>
  103. <right>right</right>
  104. <justify>justify. Here comes a blind text: Lorem testum dolor sit amet consecutor celeron fiftifahivus e shadoninia e smalus jokus anrus relsocutoti rubenwardus. Erasputinus hara holisti dominus wusi. Grumarinsti erltusmuate ol fortitusti fla flo, blani burki e sfani fahif. Ultae ratii, e megus gigae don anonimus. Grinus dimondus krockus e nore. Endus finalus nowus comus endus o blindus tekstus.</justify>
  105. <bigger>Custom tag test</bigger>
  106. <tag name=t_green color=green>
  107. <tag name="t_hover" hovercolor=yellow>
  108. <tag name="t_size" size=24>
  109. <tag name="t_mono" font=mono>
  110. <tag name="t_multi" color=green font=mono size=24>
  111. <t_green>color=green</t_green>
  112. Action: <action name="color"><t_green>color=green</t_green></action>
  113. Action: <action name="hovercolor"><t_hover>hovercolor=yellow</t_hover></action>
  114. Action URL: <action name="open" url="https://example.com/?a=b#c">open URL</action>
  115. <t_size>size=24</t_size>
  116. <t_mono>font=mono</t_mono>
  117. <t_multi>color=green font=mono size=24</t_multi>
  118. <bigger><mono>action</mono> test</bigger>
  119. <action name="action_test">action</action>
  120. <bigger><mono>img</mono> test</bigger>
  121. Normal:
  122. <img name=testformspec_item.png>
  123. <mono>width=48 height=48</mono>:
  124. <img name=testformspec_item.png width=48 height=48>
  125. <mono>float=left</mono>:
  126. <img name=testformspec_item.png float=left>
  127. <mono>float=right</mono>:
  128. <img name=testformspec_item.png float=right>
  129. <bigger><mono>item</mono> test</bigger>
  130. Normal:
  131. <item name=testformspec:node>
  132. <mono>width=48 height=48</mono>
  133. <item name=testformspec:node width=48 height=48>
  134. <mono>angle=30,0,0</mono>:
  135. <item name=testformspec:node angle=30,0,0>
  136. <mono>angle=0,30,0</mono>:
  137. <item name=testformspec:node angle=0,30,0>
  138. <mono>angle=0,0,30</mono>:
  139. <item name=testformspec:node angle=0,0,30>
  140. <mono>rotate=yes</mono>:
  141. <item name=testformspec:node rotate=yes>
  142. <mono>rotate=100,0,0</mono>:
  143. <item name=testformspec:node rotate=100,0,0>
  144. <mono>rotate=0,100,0</mono>:
  145. <item name=testformspec:node rotate=0,100,0>
  146. <mono>rotate=0,0,100</mono>:
  147. <item name=testformspec:node rotate=0,0,100>
  148. <mono>rotate=50,75,100</mono>:
  149. <item name=testformspec:node rotate=50,75,100>
  150. <mono>angle=-30,-45,90 rotate=100,150,-50</mono>:
  151. <item name=testformspec:node angle=-30,-45,90 rotate=100,150,-50>]]
  152. local hypertext_global = [[
  153. <global background=gray margin=20 valign=bottom halign=right color=pink hovercolor=purple size=12 font=mono>
  154. This is a test of the global tag. The parameters are:
  155. background=gray margin=20 valign=bottom halign=right color=pink hovercolor=purple size=12 font=mono
  156. <action name=global>action</action>]]
  157. local hypertext_fs = "hypertext[0,0;11,9;hypertext;"..core.formspec_escape(hypertext_basic).."]"..
  158. "hypertext[0,9.5;11,2.5;hypertext;"..core.formspec_escape(hypertext_global).."]"
  159. local style_fs = [[
  160. style[one_btn1;bgcolor=red;textcolor=yellow;bgcolor_hovered=orange;
  161. bgcolor_pressed=purple]
  162. button_url_exit[0,0;2.5,0.8;one_btn1;Button;]] .. unsafe_url .. [[]
  163. style[one_btn2;border=false;textcolor=cyan] ]]..
  164. "button[0,1.05;2.5,0.8;one_btn2;Text " .. color("#FF0", "Yellow") .. [[]
  165. style[one_btn3;bgimg=testformspec_button_image.png;bgimg_hovered=testformspec_hovered.png;
  166. bgimg_pressed=testformspec_pressed.png]
  167. button[0,2.1;1,1;one_btn3;Border]
  168. style[one_btn4;bgimg=testformspec_button_image.png;bgimg_hovered=testformspec_hovered.png;
  169. bgimg_pressed=testformspec_pressed.png;border=false]
  170. button[1.25,2.1;1,1;one_btn4;NoBor]
  171. style[one_btn5;bgimg=testformspec_button_image.png;bgimg_hovered=testformspec_hovered.png;
  172. bgimg_pressed=testformspec_pressed.png;border=false;alpha=false]
  173. button[0,3.35;1,1;one_btn5;Alph]
  174. style[one_btn6;border=true]
  175. image_button[0,4.6;1,1;testformspec_button_image.png;one_btn6;Border]
  176. style[one_btn7;border=false]
  177. image_button[1.25,4.6;1,1;testformspec_button_image.png;one_btn7;NoBor]
  178. style[one_btn8;border=false]
  179. image_button[0,5.85;1,1;testformspec_button_image.png;one_btn8;Border;false;true;testformspec_pressed.png]
  180. style[one_btn9;border=true]
  181. image_button[1.25,5.85;1,1;testformspec_button_image.png;one_btn9;NoBor;false;false;testformspec_pressed.png]
  182. style[one_btn10;alpha=false]
  183. image_button[0,7.1;1,1;testformspec_button_image.png;one_btn10;NoAlpha]
  184. style[one_btn11;alpha=true]
  185. image_button[1.25,7.1;1,1;testformspec_button_image.png;one_btn11;Alpha]
  186. style[one_btn12;border=true]
  187. item_image_button[0,8.35;1,1;testformspec:item;one_btn12;Border]
  188. style[one_btn13;border=false]
  189. item_image_button[1.25,8.35;1,1;testformspec:item;one_btn13;NoBor]
  190. style[one_btn14;border=false;bgimg=testformspec_bg.png;fgimg=testformspec_button_image.png]
  191. style[one_btn14:hovered;bgimg=testformspec_bg_hovered.png;fgimg=testformspec_hovered.png;textcolor=yellow]
  192. style[one_btn14:pressed;bgimg=testformspec_bg_pressed.png;fgimg=testformspec_pressed.png;textcolor=blue]
  193. style[one_btn14:hovered+pressed;textcolor=purple]
  194. style[one_btn14:focused;textcolor=red]
  195. image_button[0,9.6;1,1;testformspec_button_image.png;one_btn14;Bg]
  196. style[one_btn15;border=false;bgcolor=#1cc;bgimg=testformspec_bg.png;bgimg_hovered=testformspec_bg_hovered.png;bgimg_pressed=testformspec_bg_pressed.png]
  197. item_image_button[1.25,9.6;1,1;testformspec:item;one_btn15;Bg]
  198. style[one_btn16;border=false;bgimg=testformspec_bg_9slice.png;bgimg_middle=4,6;padding=5,7;fgimg=testformspec_bg.png;fgimg_middle=1]
  199. style[one_btn16:hovered;bgimg=testformspec_bg_9slice_hovered.png;fgimg=testformspec_bg_hovered.png]
  200. style[one_btn16:pressed;bgimg=testformspec_bg_9slice_pressed.png;fgimg=testformspec_bg_pressed.png]
  201. style[one_btn16:focused;bgimg=testformspec_bg_9slice_focused.png;fgimg=testformspec_bg_focused.png]
  202. image_button[2.5,9.6;2,1;;one_btn16;9-Slice Bg]
  203. container[2.75,0]
  204. style[one_tb1;textcolor=Yellow]
  205. tabheader[0,3;2.5,0.63;one_tb1;Yellow,Text,Tabs;1;false;false]
  206. style[one_f1;textcolor=yellow]
  207. field[0,4.25;2.5,0.8;one_f1;Field One;Yellow Text]
  208. style[one_f2;border=false;textcolor=cyan]
  209. field[0,5.75;2.5,0.8;one_f2;Field Two;Borderless Cyan Text]
  210. style[one_f3;textcolor=yellow]
  211. textarea[0,7.025;2.5,0.8;one_f3;Label;]] ..
  212. core.formspec_escape("Yellow Text\nLine two") .. [[ ]
  213. style[one_f4;border=false;textcolor=cyan]
  214. textarea[0,8.324999999999999;2.5,0.8;one_f4;Label;]] ..
  215. core.formspec_escape("Borderless Cyan Text\nLine two") .. [[ ]
  216. container_end[]
  217. ]]
  218. local scroll_fs =
  219. "button[8.5,1;4,1;outside;Outside of container]"..
  220. "box[1,1;8,6;#00aa]"..
  221. "scroll_container[1,1;8,6;scrbar;vertical]"..
  222. "button[0,1;1,1;lorem;Lorem]"..
  223. "animated_image[0,1;4.5,1;clip_animated_image;testformspec_animation.png;4;100]" ..
  224. "button[0,10;1,1;ipsum;Ipsum]"..
  225. "pwdfield[2,2;1,1;lorem2;Lorem]"..
  226. "list[current_player;main;4,4;1,5;]"..
  227. "box[2,5;3,2;#ffff00]"..
  228. "image[1,10;3,2;testformspec_item.png]"..
  229. "image[3,1;testformspec_item.png]"..
  230. "item_image[2,6;3,2;testformspec:node]"..
  231. "label[2,15;bla Bli\nfoo bar]"..
  232. "item_image_button[2,3;1,1;testformspec:node;itemimagebutton;ItemImageButton]"..
  233. "tooltip[0,11;3,2;Buz;#f00;#000]"..
  234. "box[0,11;3,2;#00ff00]"..
  235. "hypertext[3,13;3,3;;" .. hypertext_basic .. "]" ..
  236. "hypertext[3,17;3,3;;Hypertext with no scrollbar\\; the scroll container should scroll.]" ..
  237. "textarea[3,21;3,1;textarea;;More scroll within scroll]" ..
  238. "container[0,18]"..
  239. "box[1,2;3,2;#0a0a]"..
  240. "scroll_container[1,2;3,2;scrbar2;horizontal;0.06]"..
  241. "button[0,0;6,1;butnest;Nest]"..
  242. "label[10,0.5;nest]"..
  243. "scroll_container_end[]"..
  244. "scrollbar[1,0;3.5,0.3;horizontal;scrbar2;0]"..
  245. "container_end[]"..
  246. "dropdown[0,6;2;hmdrpdwn;apple,bulb;1]"..
  247. "image_button[0,4;2,2;testformspec_button_image.png;imagebutton;bbbbtt;false;true;testformspec_pressed.png]"..
  248. "box[1,22.5;4,1;#a00a]"..
  249. "scroll_container_end[]"..
  250. "scrollbaroptions[max=170]".. -- lowest seen pos is: 0.1*170+6=23 (factor*max+height)
  251. "scrollbar[7.5,0;0.3,4;vertical;scrbar;0]"..
  252. "scrollbar[8,0;0.3,4;vertical;scrbarhmmm;0]"..
  253. "dropdown[0,6;2;hmdrpdwnnn;Outside,of,container;1]"..
  254. "scroll_container[0,8;10,4;scrbar420;vertical;0.1;2]"..
  255. "button[0.5,0.5;10,1;;Container with padding=2]"..
  256. "list[current_player;main;0,5;8,4;]"..
  257. "scroll_container_end[]"..
  258. "scrollbar[10.1,8;0.5,4;vertical;scrbar420;0]"..
  259. -- Buttons for scale comparison
  260. "button[11,8;1,1;;0]"..
  261. "button[11,9;1,1;;1]"..
  262. "button[11,10;1,1;;2]"..
  263. "button[11,11;1,1;;3]"..
  264. "button[11,12;1,1;;4]"
  265. --style_type[label;textcolor=green]
  266. --label[0,0;Green]
  267. --style_type[label;textcolor=blue]
  268. --label[0,1;Blue]
  269. --style_type[label;textcolor=;border=true]
  270. --label[1.2,0;Border]
  271. --style_type[label;border=true;bgcolor=red]
  272. --label[1.2,1;Background]
  273. --style_type[label;border=;bgcolor=]
  274. --label[0.75,2;Reset]
  275. local window = {
  276. sizex = 12,
  277. sizey = 13,
  278. positionx = 0.5,
  279. positiony = 0.5,
  280. anchorx = 0.5,
  281. anchory = 0.5,
  282. paddingx = 0.05,
  283. paddingy = 0.05
  284. }
  285. local pages = {
  286. -- Real Coordinates
  287. [[
  288. formspec_version[3]
  289. size[12,13]
  290. image_button[0,0;1,1;logo.png;rc_image_button_1x1;1x1]
  291. image_button[1,0;2,2;logo.png;rc_image_button_2x2;2x2]
  292. button[0,2;1,1;rc_button_1x1;1x1]
  293. button[1,2;2,2;rc_button_2x2;2x2]
  294. item_image[0,4;1,1;air]
  295. item_image[1,4;2,2;air]
  296. item_image_button[0,6;1,1;testformspec:node;rc_item_image_button_1x1;1x1]
  297. item_image_button[1,6;2,2;testformspec:node;rc_item_image_button_2x2;2x2]
  298. field[3,.5;3,.5;rc_field;Field;text]
  299. pwdfield[6,.5;3,1;rc_pwdfield;Password Field]
  300. field[3,1;3,1;;Read-Only Field;text]
  301. textarea[3,2;3,.5;rc_textarea_small;Textarea;text]
  302. textarea[6,2;3,2;rc_textarea_big;Textarea;text\nmore text]
  303. textarea[3,3;3,1;;Read-Only Textarea;text\nmore text]
  304. textlist[3,4;3,2;rc_textlist;Textlist,Perfect Coordinates;1;false]
  305. tableoptions[highlight=#ABCDEF75;background=#00000055;border=false]
  306. table[6,4;3,2;rc_table;Table,Cool Stuff,Foo,Bar;2]
  307. dropdown[3,6;3,1;rc_dropdown_small;This,is,a,dropdown;1]
  308. dropdown[6,6;3,2;rc_dropdown_big;I,am,a,bigger,dropdown;5]
  309. image[0,8;3,2;ignore.png]
  310. box[3,7;3,1;#00A3FF]
  311. checkbox[3,8;rc_checkbox_1;Check me!;false]
  312. checkbox[3,9;rc_checkbox_2;Uncheck me now!;true]
  313. scrollbar[0,11.5;11.5,.5;horizontal;rc_scrollbar_horizontal;500]
  314. scrollbar[11.5,0;.5,11.5;vertical;rc_scrollbar_vertical;0]
  315. list[current_player;main;6,8;3,2;1]
  316. button[9,0;2.5,1;rc_empty_button_1;]
  317. button[9,1;2.5,1;rc_empty_button_2;]
  318. button[9,2;2.5,1;rc_empty_button_3;] ]]..
  319. "label[9,0.5;This is a label.\nLine\nLine\nLine\nEnd]"..
  320. [[button[9,3;1,1;rc_empty_button_4;]
  321. vertlabel[9,4;VERT]
  322. label[10,3;HORIZ]
  323. tabheader[8,0;6,0.65;rc_tabheader;Tab 1,Tab 2,Tab 3,Secrets;1;false;false]
  324. ]],
  325. -- Style
  326. "formspec_version[3]size[12,13]" ..
  327. ("label[0.375,0.375;Styled - %s %s]"):format(
  328. color("#F00", "red text"),
  329. color("#77FF00CC", "green text")) ..
  330. "label[6.375,0.375;Unstyled]" ..
  331. "box[0,0.75;12,0.1;#999]" ..
  332. "box[6,0.85;0.1,11.15;#999]" ..
  333. "container[0.375,1.225]" ..
  334. style_fs ..
  335. "container_end[]container[6.375,1.225]" ..
  336. style_fs:gsub("one_", "two_"):gsub("style%[[^%]]+%]", ""):gsub("style_type%[[^%]]+%]", "") ..
  337. "container_end[]",
  338. -- Noclip
  339. "formspec_version[3]size[12,13]" ..
  340. "label[0.1,0.5;Clip]" ..
  341. "container[-2.5,1]" .. clip_fs:gsub("%%c", "false") .. "container_end[]" ..
  342. "label[11,0.5;Noclip]" ..
  343. "container[11.5,1]" .. clip_fs:gsub("%%c", "true") .. "container_end[]",
  344. -- Table
  345. "size[18,13]real_coordinates[true]" ..
  346. "container[0.5,0.5]" .. table_fs.. "container_end[]",
  347. -- Hypertext
  348. "size[12,13]real_coordinates[true]" ..
  349. "container[0.5,0.5]" .. hypertext_fs .. "container_end[]",
  350. -- Tabheaders
  351. "size[12,13]real_coordinates[true]" ..
  352. "container[0.5,1.5]" .. tabheaders_fs .. "container_end[]",
  353. -- Inv
  354. "size[12,13]real_coordinates[true]" .. inv_style_fs,
  355. -- Window
  356. function()
  357. return "formspec_version[3]" ..
  358. string.format("size[%s,%s]position[%s,%s]anchor[%s,%s]padding[%s,%s]",
  359. window.sizex, window.sizey, window.positionx, window.positiony,
  360. window.anchorx, window.anchory, window.paddingx, window.paddingy) ..
  361. string.format("field[0.5,0.5;2.5,0.5;sizex;X Size;%s]field[3.5,0.5;2.5,0.5;sizey;Y Size;%s]" ..
  362. "field[0.5,1.5;2.5,0.5;positionx;X Position;%s]field[3.5,1.5;2.5,0.5;positiony;Y Position;%s]" ..
  363. "field[0.5,2.5;2.5,0.5;anchorx;X Anchor;%s]field[3.5,2.5;2.5,0.5;anchory;Y Anchor;%s]" ..
  364. "field[0.5,3.5;2.5,0.5;paddingx;X Padding;%s]field[3.5,3.5;2.5,0.5;paddingy;Y Padding;%s]" ..
  365. "button[2,4.5;2.5,0.5;submit_window;Submit]",
  366. window.sizex, window.sizey, window.positionx, window.positiony,
  367. window.anchorx, window.anchory, window.paddingx, window.paddingy) ..
  368. "field_close_on_enter[sizex;false]field_close_on_enter[sizey;false]" ..
  369. "field_close_on_enter[positionx;false]field_close_on_enter[positiony;false]" ..
  370. "field_close_on_enter[anchorx;false]field_close_on_enter[anchory;false]" ..
  371. "field_close_on_enter[paddingx;false]field_close_on_enter[paddingy;false]"
  372. end,
  373. -- Animation
  374. [[
  375. formspec_version[6]
  376. size[12,13]
  377. animated_image[0.5,0.5;1,1;;testformspec_animation.png;4;100]
  378. animated_image[0.5,1.75;1,1;;testformspec_animation.jpg;4;100]
  379. animated_image[1.75,0.5;1,1;;testformspec_animation.png;100;100]
  380. animated_image[3,0.5;1,1;ani_img_1;testformspec_animation.png;4;1000]
  381. image[0.5,3;1,1;testformspec_bg.png;1]
  382. animated_image[0.5,4.25;1,1;;[combine:16x48:0,0=testformspec_bg.png:0,16=testformspec_bg_hovered.png:0,32=testformspec_bg_pressed.png;3;250;1;1]
  383. image[0.5,5.5;2,1;testformspec_9slice.png;16,0,-16,-16]
  384. animated_image[2.75,5.5;1.5,0.5;;[combine:300x140:0,0=testformspec_9slice.png:0,70=(testformspec_9slice.png^[transformFX);2;500;1;16,0,-16,-16]
  385. button[4.25,0.5;1,1;ani_btn_1;Current
  386. Number]
  387. animated_image[3,1.75;1,1;ani_img_2;testformspec_animation.png;4;1000;2]
  388. button[4.25,1.75;1,1;ani_btn_2;Current
  389. Number]
  390. animated_image[3,3;1,1;;testformspec_animation.png;4;0]
  391. animated_image[3,4.25;1,1;;testformspec_animation.png;4;0;3]
  392. animated_image[5.5,0.5;5,2;;testformspec_animation.png;4;100]
  393. animated_image[5.5,2.75;5,2;;testformspec_animation.jpg;4;100]
  394. ]],
  395. -- Model
  396. [[
  397. formspec_version[3]
  398. size[12,13]
  399. style[m1;bgcolor=black]
  400. style[m2;bgcolor=black]
  401. label[5,1;all defaults]
  402. label[5,5.1;angle = 0, 180
  403. continuous = false
  404. mouse control = false
  405. frame loop range = 0,30]
  406. label[5,9.2;continuous = true
  407. mouse control = true]
  408. model[0.5,0.1;4,4;m1;testformspec_character.b3d;testformspec_character.png]
  409. model[0.5,4.2;4,4;m2;testformspec_character.b3d;testformspec_character.png;0,180;false;false;0,30]
  410. model[0.5,8.3;4,4;m3;testformspec_chest.obj;default_chest_top.png,default_chest_top.png,default_chest_side.png,default_chest_side.png,default_chest_front.png,default_chest_inside.png;30,1;true;true]
  411. ]],
  412. -- Scroll containers
  413. "formspec_version[7]size[12,13]" ..
  414. scroll_fs,
  415. -- Sound
  416. [[
  417. formspec_version[3]
  418. size[12,13]
  419. style[snd_btn;sound=soundstuff_mono]
  420. style[snd_ibtn;sound=soundstuff_mono]
  421. style[snd_drp;sound=soundstuff_mono]
  422. style[snd_chk;sound=soundstuff_mono]
  423. style[snd_tab;sound=soundstuff_mono]
  424. button[0.5,0.5;2,1;snd_btn;Sound]
  425. image_button[0.5,2;2,1;testformspec_item.png;snd_ibtn;Sound]
  426. dropdown[0.5,4;4;snd_drp;Sound,Two,Three;]
  427. checkbox[0.5,5.5.5;snd_chk;Sound;]
  428. tabheader[0.5,7;8,0.65;snd_tab;Soundtab1,Soundtab2,Soundtab3;1;false;false]
  429. ]],
  430. -- Background
  431. [[
  432. formspec_version[3]
  433. size[12,13]
  434. box[0,0;12,13;#f0f1]
  435. background[0,0;0,0;testformspec_bg.png;true]
  436. box[3.9,2.9;6.2,4.2;#d00f]
  437. scroll_container[4,3;6,4;scrbar;vertical]
  438. background9[1,0.5;0,0;testformspec_bg_9slice.png;true;4,6]
  439. label[0,0.2;Backgrounds are not be applied to scroll containers,]
  440. label[0,0.5;but to the whole form.]
  441. scroll_container_end[]
  442. scrollbar[3.5,3;0.3,4;vertical;scrbar;0]
  443. container[2,11]
  444. box[-0.1,0.5;3.2,1;#fff5]
  445. background[0,0;2,3;testformspec_bg.png;false]
  446. background9[1,0;2,3;testformspec_bg_9slice.png;false;4,6]
  447. container_end[]
  448. ]],
  449. -- Unsized
  450. [[
  451. formspec_version[3]
  452. background9[0,0;0,0;testformspec_bg_9slice.png;true;4,6]
  453. background[1,1;0,0;testformspec_bg.png;true]
  454. ]],
  455. }
  456. local page_id = 2
  457. local function show_test_formspec(pname)
  458. local page = pages[page_id]
  459. if type(page) == "function" then
  460. page = page()
  461. end
  462. local fs = page .. "tabheader[0,0;11,0.65;maintabs;Real Coord,Styles,Noclip,Table,Hypertext,Tabs,Invs,Window,Anim,Model,ScrollC,Sound,Background,Unsized;" .. page_id .. ";false;false]"
  463. core.show_formspec(pname, "testformspec:formspec", fs)
  464. end
  465. core.register_on_player_receive_fields(function(player, formname, fields)
  466. if formname ~= "testformspec:formspec" then
  467. return false
  468. end
  469. if fields.maintabs then
  470. page_id = tonumber(fields.maintabs)
  471. show_test_formspec(player:get_player_name())
  472. return true
  473. end
  474. if fields.ani_img_1 and fields.ani_btn_1 then
  475. core.chat_send_player(player:get_player_name(), "ani_img_1 = " .. tostring(fields.ani_img_1))
  476. return true
  477. elseif fields.ani_img_2 and fields.ani_btn_2 then
  478. core.chat_send_player(player:get_player_name(), "ani_img_2 = " .. tostring(fields.ani_img_2))
  479. return true
  480. end
  481. if fields.hypertext then
  482. core.chat_send_player(player:get_player_name(), "Hypertext action received: " .. tostring(fields.hypertext))
  483. return true
  484. end
  485. for name, value in pairs(fields) do
  486. if window[name] then
  487. print(name, window[name])
  488. local num_val = tonumber(value) or 0
  489. if name == "sizex" and num_val < 4 then
  490. num_val = 6.5
  491. elseif name == "sizey" and num_val < 5 then
  492. num_val = 5.5
  493. end
  494. window[name] = num_val
  495. print(name, window[name])
  496. end
  497. end
  498. if fields.submit_window then
  499. show_test_formspec(player:get_player_name())
  500. end
  501. end)
  502. core.register_chatcommand("test_formspec", {
  503. params = "",
  504. description = "Open the test formspec",
  505. func = function(name)
  506. if not core.get_player_by_name(name) then
  507. return false, "You need to be online!"
  508. end
  509. show_test_formspec(name)
  510. return true
  511. end,
  512. })