formspec.lua 19 KB

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