functionality.lua 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937
  1. --saved state for each player
  2. local gui_nodename1 = {} --mapping of player names to node names
  3. local gui_nodename2 = {} --mapping of player names to node names
  4. local gui_axis1 = {} --mapping of player names to axes (one of 1, 2, 3, or 4, representing the axes in the `axis_indices` table below)
  5. local gui_axis2 = {} --mapping of player names to axes (one of 1, 2, 3, or 4, representing the axes in the `axis_indices` table below)
  6. local gui_distance1 = {} --mapping of player names to a distance (arbitrary strings may also appear as values)
  7. local gui_distance2 = {} --mapping of player names to a distance (arbitrary strings may also appear as values)
  8. local gui_distance3 = {} --mapping of player names to a distance (arbitrary strings may also appear as values)
  9. local gui_count1 = {} --mapping of player names to a quantity (arbitrary strings may also appear as values)
  10. local gui_count2 = {} --mapping of player names to a quantity (arbitrary strings may also appear as values)
  11. local gui_count3 = {} --mapping of player names to a quantity (arbitrary strings may also appear as values)
  12. local gui_angle = {} --mapping of player names to an angle (one of 90, 180, 270, representing the angle in degrees clockwise)
  13. local gui_filename = {} --mapping of player names to file names
  14. local gui_param2 = {} --mapping of player names to param2 values
  15. --set default values
  16. setmetatable(gui_nodename1, {__index = function() return "Cobblestone" end})
  17. setmetatable(gui_nodename2, {__index = function() return "Stone" end})
  18. setmetatable(gui_axis1, {__index = function() return 4 end})
  19. setmetatable(gui_axis2, {__index = function() return 1 end})
  20. setmetatable(gui_distance1, {__index = function() return "10" end})
  21. setmetatable(gui_distance2, {__index = function() return "5" end})
  22. setmetatable(gui_distance3, {__index = function() return "2" end})
  23. setmetatable(gui_count1, {__index = function() return "3" end})
  24. setmetatable(gui_count2, {__index = function() return "6" end})
  25. setmetatable(gui_count3, {__index = function() return "4" end})
  26. setmetatable(gui_angle, {__index = function() return 90 end})
  27. setmetatable(gui_filename, {__index = function() return "building" end})
  28. setmetatable(gui_param2, {__index = function() return "0" end})
  29. local axis_indices = {["X axis"]=1, ["Y axis"]=2, ["Z axis"]=3, ["Look direction"]=4}
  30. local axis_values = {"x", "y", "z", "?"}
  31. setmetatable(axis_indices, {__index = function () return 4 end})
  32. setmetatable(axis_values, {__index = function () return "?" end})
  33. local angle_indices = {["90 degrees"]=1, ["180 degrees"]=2, ["270 degrees"]=3}
  34. local angle_values = {90, 180, 270}
  35. setmetatable(angle_indices, {__index = function () return 1 end})
  36. setmetatable(angle_values, {__index = function () return 90 end})
  37. -- given multiple sets of privileges, produces a single set of privs that would have the same effect as requiring all of them at the same time
  38. local combine_privs = function(...)
  39. local result = {}
  40. for i, privs in ipairs({...}) do
  41. for name, value in pairs(privs) do
  42. if result[name] ~= nil and result[name] ~= value then --the priv must be both true and false, which can never happen
  43. return {__fake_priv_that_nobody_has__=true} --privilege table that can never be satisfied
  44. end
  45. result[name] = value
  46. end
  47. end
  48. return result
  49. end
  50. -- display node (or unknown_node image otherwise) at specified pos in formspec
  51. local formspec_node = function(pos, nodename)
  52. local ndef = nodename and minetest.registered_nodes[nodename]
  53. if nodename and ndef then
  54. return string.format("item_image[%s;1,1;%s]", pos, nodename) ..
  55. string.format("tooltip[%s;1,1;%s]", pos, minetest.formspec_escape(ndef.description))
  56. else
  57. return string.format("image[%s;1,1;worldedit_gui_unknown.png]", pos)
  58. end
  59. end
  60. -- two further priv helpers
  61. local function we_privs(command)
  62. return worldedit.registered_commands[command].privs
  63. end
  64. local function combine_we_privs(list)
  65. local args = {}
  66. for _, t in ipairs(list) do
  67. table.insert(args, we_privs(t))
  68. end
  69. return combine_privs(unpack(args))
  70. end
  71. -- functions that handle value changing & page reshowing (without submitting)
  72. local function copy_changes(name, fields, def)
  73. for field, into in pairs(def) do
  74. if into ~= true and fields[field] then
  75. local value = tostring(fields[field])
  76. if into == gui_axis1 or into == gui_axis2 then
  77. into[name] = axis_indices[value]
  78. elseif into == gui_angle then
  79. into[name] = angle_indices[value]
  80. else
  81. into[name] = value
  82. end
  83. end
  84. end
  85. end
  86. local function handle_changes(name, identifier, fields, def)
  87. local any = false
  88. for field, into in pairs(def) do
  89. if fields.key_enter_field == field then
  90. any = true
  91. end
  92. -- first condition: buttons (value not saved)
  93. -- others: dropdowns which will be sent when their value changes
  94. if into == true or into == gui_axis1 or into == gui_axis2 or into == gui_angle then
  95. if fields[field] then
  96. any = true
  97. end
  98. end
  99. end
  100. if not any then
  101. return false
  102. end
  103. any = false
  104. for field, into in pairs(def) do
  105. if into ~= true and fields[field] then
  106. local value = tostring(fields[field])
  107. if into == gui_axis1 or into == gui_axis2 then
  108. into[name] = axis_indices[value]
  109. elseif into == gui_angle then
  110. into[name] = angle_indices[value]
  111. else
  112. into[name] = value
  113. end
  114. if into == gui_nodename1 or into == gui_nodename2 then
  115. any = true
  116. end
  117. end
  118. end
  119. -- Only nodename fields change based on the value, so only re-show the page if necessary
  120. if any then
  121. worldedit.show_page(name, identifier)
  122. end
  123. return true
  124. end
  125. -- This has the same behaviour as the player invoking the chat command
  126. local function execute_worldedit_command(command_name, player_name, params)
  127. local chatcmd = minetest.registered_chatcommands["/" .. command_name]
  128. assert(chatcmd, "unknown command: " .. command_name)
  129. local _, msg = chatcmd.func(player_name, params)
  130. if msg then
  131. worldedit.player_notify(player_name, msg)
  132. end
  133. end
  134. worldedit.register_gui_function("worldedit_gui_about", {
  135. name = "About",
  136. privs = {interact=true},
  137. on_select = function(name)
  138. execute_worldedit_command("about", name, "")
  139. end,
  140. })
  141. worldedit.register_gui_function("worldedit_gui_inspect", {
  142. name = "Toggle Inspect",
  143. privs = we_privs("inspect"),
  144. on_select = function(name)
  145. execute_worldedit_command("inspect", name,
  146. worldedit.inspect[name] and "disable" or "enable")
  147. end,
  148. })
  149. worldedit.register_gui_function("worldedit_gui_region", {
  150. name = "Get/Set Region",
  151. privs = combine_we_privs({"p", "pos1", "pos2", "reset", "mark", "unmark", "volume", "fixedpos"}),
  152. get_formspec = function(name)
  153. local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
  154. return "size[9,7]" .. worldedit.get_formspec_header("worldedit_gui_region") ..
  155. "button_exit[0,1;3,0.8;worldedit_gui_p_get;Get Positions]" ..
  156. "button_exit[3,1;3,0.8;worldedit_gui_p_set1;Choose Position 1]" ..
  157. "button_exit[6,1;3,0.8;worldedit_gui_p_set2;Choose Position 2]" ..
  158. "button_exit[0,2;3,0.8;worldedit_gui_pos1;Position 1 Here]" ..
  159. "button_exit[3,2;3,0.8;worldedit_gui_pos2;Position 2 Here]" ..
  160. "button_exit[6,2;3,0.8;worldedit_gui_reset;Reset Region]" ..
  161. "button_exit[0,3;3,0.8;worldedit_gui_mark;Mark Region]" ..
  162. "button_exit[3,3;3,0.8;worldedit_gui_unmark;Unmark Region]" ..
  163. "button_exit[6,3;3,0.8;worldedit_gui_volume;Region Volume]" ..
  164. "label[0,4.7;Position 1]" ..
  165. string.format("field[2,5;1.5,0.8;worldedit_gui_fixedpos_pos1x;X ;%s]", pos1 and pos1.x or "") ..
  166. string.format("field[3.5,5;1.5,0.8;worldedit_gui_fixedpos_pos1y;Y ;%s]", pos1 and pos1.y or "") ..
  167. string.format("field[5,5;1.5,0.8;worldedit_gui_fixedpos_pos1z;Z ;%s]", pos1 and pos1.z or "") ..
  168. "button_exit[6.5,4.68;2.5,0.8;worldedit_gui_fixedpos_pos1_submit;Set Position 1]" ..
  169. "label[0,6.2;Position 2]" ..
  170. string.format("field[2,6.5;1.5,0.8;worldedit_gui_fixedpos_pos2x;X ;%s]", pos2 and pos2.x or "") ..
  171. string.format("field[3.5,6.5;1.5,0.8;worldedit_gui_fixedpos_pos2y;Y ;%s]", pos2 and pos2.y or "") ..
  172. string.format("field[5,6.5;1.5,0.8;worldedit_gui_fixedpos_pos2z;Z ;%s]", pos2 and pos2.z or "") ..
  173. "button_exit[6.5,6.18;2.5,0.8;worldedit_gui_fixedpos_pos2_submit;Set Position 2]"
  174. end,
  175. })
  176. worldedit.register_gui_handler("worldedit_gui_region", function(name, fields)
  177. if fields.worldedit_gui_p_get then
  178. execute_worldedit_command("p", name, "get")
  179. return true
  180. elseif fields.worldedit_gui_p_set1 then
  181. execute_worldedit_command("p", name, "set1")
  182. return true
  183. elseif fields.worldedit_gui_p_set2 then
  184. execute_worldedit_command("p", name, "set2")
  185. return true
  186. elseif fields.worldedit_gui_pos1 then
  187. execute_worldedit_command("pos1", name, "")
  188. worldedit.show_page(name, "worldedit_gui_region")
  189. return true
  190. elseif fields.worldedit_gui_pos2 then
  191. execute_worldedit_command("pos2", name, "")
  192. worldedit.show_page(name, "worldedit_gui_region")
  193. return true
  194. elseif fields.worldedit_gui_reset then
  195. execute_worldedit_command("reset", name, "")
  196. worldedit.show_page(name, "worldedit_gui_region")
  197. return true
  198. elseif fields.worldedit_gui_mark then
  199. execute_worldedit_command("mark", name, "")
  200. worldedit.show_page(name, "worldedit_gui_region")
  201. return true
  202. elseif fields.worldedit_gui_unmark then
  203. execute_worldedit_command("unmark", name, "")
  204. worldedit.show_page(name, "worldedit_gui_region")
  205. return true
  206. elseif fields.worldedit_gui_volume then
  207. execute_worldedit_command("volume", name, "")
  208. worldedit.show_page(name, "worldedit_gui_region")
  209. return true
  210. elseif fields.worldedit_gui_fixedpos_pos1_submit then
  211. execute_worldedit_command("fixedpos", name, ("set1 %s %s %s"):format(
  212. tostring(fields.worldedit_gui_fixedpos_pos1x),
  213. tostring(fields.worldedit_gui_fixedpos_pos1y),
  214. tostring(fields.worldedit_gui_fixedpos_pos1z)))
  215. worldedit.show_page(name, "worldedit_gui_region")
  216. return true
  217. elseif fields.worldedit_gui_fixedpos_pos2_submit then
  218. execute_worldedit_command("fixedpos", name, ("set2 %s %s %s"):format(
  219. tostring(fields.worldedit_gui_fixedpos_pos2x),
  220. tostring(fields.worldedit_gui_fixedpos_pos2y),
  221. tostring(fields.worldedit_gui_fixedpos_pos2z)))
  222. worldedit.show_page(name, "worldedit_gui_region")
  223. return true
  224. end
  225. return false
  226. end)
  227. worldedit.register_gui_function("worldedit_gui_set", {
  228. name = "Set Nodes",
  229. privs = we_privs("set"),
  230. get_formspec = function(name)
  231. local node = gui_nodename1[name]
  232. local nodename = worldedit.normalize_nodename(node)
  233. return "size[6.5,3]" .. worldedit.get_formspec_header("worldedit_gui_set") ..
  234. string.format("field[0.5,1.5;4,0.8;worldedit_gui_set_node;Name;%s]", minetest.formspec_escape(node)) ..
  235. "field_close_on_enter[worldedit_gui_set_node;false]" ..
  236. "button[4,1.18;1.5,0.8;worldedit_gui_set_search;Search]" ..
  237. formspec_node("5.5,1.1", nodename) ..
  238. "button_exit[0,2.5;3,0.8;worldedit_gui_set_submit;Set Nodes]"
  239. end,
  240. })
  241. worldedit.register_gui_handler("worldedit_gui_set", function(name, fields)
  242. local cg = {
  243. worldedit_gui_set_search = true,
  244. worldedit_gui_set_node = gui_nodename1,
  245. }
  246. local ret = handle_changes(name, "worldedit_gui_set", fields, cg)
  247. if fields.worldedit_gui_set_submit then
  248. copy_changes(name, fields, cg)
  249. worldedit.show_page(name, "worldedit_gui_set")
  250. local n = worldedit.normalize_nodename(gui_nodename1[name])
  251. if n then
  252. execute_worldedit_command("set", name, n)
  253. end
  254. return true
  255. end
  256. return ret
  257. end)
  258. worldedit.register_gui_function("worldedit_gui_replace", {
  259. name = "Replace Nodes",
  260. privs = combine_we_privs({"replace", "replaceinverse"}),
  261. get_formspec = function(name)
  262. local search, replace = gui_nodename1[name], gui_nodename2[name]
  263. local search_nodename, replace_nodename = worldedit.normalize_nodename(search), worldedit.normalize_nodename(replace)
  264. return "size[6.5,4]" .. worldedit.get_formspec_header("worldedit_gui_replace") ..
  265. string.format("field[0.5,1.5;4,0.8;worldedit_gui_replace_search;Name;%s]", minetest.formspec_escape(search)) ..
  266. "field_close_on_enter[worldedit_gui_replace_search;false]" ..
  267. "button[4,1.18;1.5,0.8;worldedit_gui_replace_search_search;Search]" ..
  268. formspec_node("5.5,1.1", search_nodename) ..
  269. string.format("field[0.5,2.5;4,0.8;worldedit_gui_replace_replace;Name;%s]", minetest.formspec_escape(replace)) ..
  270. "field_close_on_enter[worldedit_gui_replace_replace;false]" ..
  271. "button[4,2.18;1.5,0.8;worldedit_gui_replace_replace_search;Search]" ..
  272. formspec_node("5.5,2.1", replace_nodename) ..
  273. "button_exit[0,3.5;3,0.8;worldedit_gui_replace_submit;Replace Nodes]" ..
  274. "button_exit[3.5,3.5;3,0.8;worldedit_gui_replace_submit_inverse;Replace Inverse]"
  275. end,
  276. })
  277. worldedit.register_gui_handler("worldedit_gui_replace", function(name, fields)
  278. local cg = {
  279. worldedit_gui_replace_search_search = true,
  280. worldedit_gui_replace_replace_search = true,
  281. worldedit_gui_replace_search = gui_nodename1,
  282. worldedit_gui_replace_replace = gui_nodename2,
  283. }
  284. local ret = handle_changes(name, "worldedit_gui_replace", fields, cg)
  285. if fields.worldedit_gui_replace_submit or fields.worldedit_gui_replace_submit_inverse then
  286. copy_changes(name, fields, cg)
  287. worldedit.show_page(name, "worldedit_gui_replace")
  288. local submit = "replace"
  289. if fields.worldedit_gui_replace_submit_inverse then
  290. submit = "replaceinverse"
  291. end
  292. local n1 = worldedit.normalize_nodename(gui_nodename1[name])
  293. local n2 = worldedit.normalize_nodename(gui_nodename2[name])
  294. if n1 and n2 then
  295. execute_worldedit_command(submit, name, n1 .. " " .. n2)
  296. end
  297. return true
  298. end
  299. return ret
  300. end)
  301. worldedit.register_gui_function("worldedit_gui_sphere_dome", {
  302. name = "Sphere/Dome",
  303. privs = combine_we_privs({"hollowsphere", "sphere", "hollowdome", "dome"}),
  304. get_formspec = function(name)
  305. local node, radius = gui_nodename1[name], gui_distance2[name]
  306. local nodename = worldedit.normalize_nodename(node)
  307. return "size[6.5,5]" .. worldedit.get_formspec_header("worldedit_gui_sphere_dome") ..
  308. string.format("field[0.5,1.5;4,0.8;worldedit_gui_sphere_dome_node;Name;%s]", minetest.formspec_escape(node)) ..
  309. "field_close_on_enter[worldedit_gui_sphere_dome_node;false]" ..
  310. "button[4,1.18;1.5,0.8;worldedit_gui_sphere_dome_search;Search]" ..
  311. formspec_node("5.5,1.1", nodename) ..
  312. string.format("field[0.5,2.5;4,0.8;worldedit_gui_sphere_dome_radius;Radius;%s]", minetest.formspec_escape(radius)) ..
  313. "field_close_on_enter[worldedit_gui_sphere_dome_radius;false]" ..
  314. "button_exit[0,3.5;3,0.8;worldedit_gui_sphere_dome_submit_hollow;Hollow Sphere]" ..
  315. "button_exit[3.5,3.5;3,0.8;worldedit_gui_sphere_dome_submit_solid;Solid Sphere]" ..
  316. "button_exit[0,4.5;3,0.8;worldedit_gui_sphere_dome_submit_hollow_dome;Hollow Dome]" ..
  317. "button_exit[3.5,4.5;3,0.8;worldedit_gui_sphere_dome_submit_solid_dome;Solid Dome]"
  318. end,
  319. })
  320. worldedit.register_gui_handler("worldedit_gui_sphere_dome", function(name, fields)
  321. local cg = {
  322. worldedit_gui_sphere_dome_search = true,
  323. worldedit_gui_sphere_dome_node = gui_nodename1,
  324. worldedit_gui_sphere_dome_radius = gui_distance2,
  325. }
  326. local ret = handle_changes(name, "worldedit_gui_sphere_dome", fields, cg)
  327. if fields.worldedit_gui_sphere_dome_submit_hollow or fields.worldedit_gui_sphere_dome_submit_solid
  328. or fields.worldedit_gui_sphere_dome_submit_hollow_dome or fields.worldedit_gui_sphere_dome_submit_solid_dome then
  329. copy_changes(name, fields, cg)
  330. worldedit.show_page(name, "worldedit_gui_sphere_dome")
  331. local submit = "hollowsphere"
  332. if fields.worldedit_gui_sphere_dome_submit_solid then
  333. submit = "sphere"
  334. elseif fields.worldedit_gui_sphere_dome_submit_hollow_dome then
  335. submit = "hollowdome"
  336. elseif fields.worldedit_gui_sphere_dome_submit_solid_dome then
  337. submit = "dome"
  338. end
  339. local n = worldedit.normalize_nodename(gui_nodename1[name])
  340. if n then
  341. execute_worldedit_command(submit, name,
  342. gui_distance2[name] .. " " .. n)
  343. end
  344. return true
  345. end
  346. return ret
  347. end)
  348. worldedit.register_gui_function("worldedit_gui_cylinder", {
  349. name = "Cylinder",
  350. privs = combine_we_privs({"hollowcylinder", "cylinder"}),
  351. get_formspec = function(name)
  352. local node, axis, length = gui_nodename1[name], gui_axis1[name], gui_distance1[name]
  353. local radius1, radius2 = gui_distance2[name], gui_distance3[name]
  354. local nodename = worldedit.normalize_nodename(node)
  355. return "size[6.5,6]" .. worldedit.get_formspec_header("worldedit_gui_cylinder") ..
  356. string.format("field[0.5,1.5;4,0.8;worldedit_gui_cylinder_node;Name;%s]", minetest.formspec_escape(node)) ..
  357. "field_close_on_enter[worldedit_gui_cylinder_node;false]" ..
  358. "button[4,1.18;1.5,0.8;worldedit_gui_cylinder_search;Search]" ..
  359. formspec_node("5.5,1.1", nodename) ..
  360. string.format("field[0.5,2.5;4,0.8;worldedit_gui_cylinder_length;Length;%s]", minetest.formspec_escape(length)) ..
  361. string.format("dropdown[4,2.18;2.5;worldedit_gui_cylinder_axis;X axis,Y axis,Z axis,Look direction;%d]", axis) ..
  362. string.format("field[0.5,3.5;2,0.8;worldedit_gui_cylinder_radius1;Base Radius;%s]", minetest.formspec_escape(radius1)) ..
  363. string.format("field[2.5,3.5;2,0.8;worldedit_gui_cylinder_radius2;Top Radius;%s]", minetest.formspec_escape(radius2)) ..
  364. "field_close_on_enter[worldedit_gui_cylinder_length;false]" ..
  365. "field_close_on_enter[worldedit_gui_cylinder_radius1;false]" ..
  366. "field_close_on_enter[worldedit_gui_cylinder_radius2;false]" ..
  367. "label[0.25,4;Equal base and top radius creates a cylinder,\n"..
  368. "zero top radius creates a cone.\nConsult documentation for more information.]"..
  369. "button_exit[0,5.5;3,0.8;worldedit_gui_cylinder_submit_hollow;Hollow Cylinder]" ..
  370. "button_exit[3.5,5.5;3,0.8;worldedit_gui_cylinder_submit_solid;Solid Cylinder]"
  371. end,
  372. })
  373. worldedit.register_gui_handler("worldedit_gui_cylinder", function(name, fields)
  374. local cg = {
  375. worldedit_gui_cylinder_search = true,
  376. worldedit_gui_cylinder_node = gui_nodename1,
  377. worldedit_gui_cylinder_axis = gui_axis1,
  378. worldedit_gui_cylinder_length = gui_distance1,
  379. worldedit_gui_cylinder_radius1 = gui_distance2,
  380. worldedit_gui_cylinder_radius2 = gui_distance3,
  381. }
  382. local ret = handle_changes(name, "worldedit_gui_cylinder", fields, cg)
  383. if fields.worldedit_gui_cylinder_submit_hollow or fields.worldedit_gui_cylinder_submit_solid then
  384. copy_changes(name, fields, cg)
  385. worldedit.show_page(name, "worldedit_gui_cylinder")
  386. local submit = "hollowcylinder"
  387. if fields.worldedit_gui_cylinder_submit_solid then
  388. submit = "cylinder"
  389. end
  390. local n = worldedit.normalize_nodename(gui_nodename1[name])
  391. if n then
  392. local args = string.format("%s %s %s %s %s", axis_values[gui_axis1[name]], gui_distance1[name], gui_distance2[name], gui_distance3[name], n)
  393. execute_worldedit_command(submit, name, args)
  394. end
  395. return true
  396. end
  397. return ret
  398. end)
  399. worldedit.register_gui_function("worldedit_gui_pyramid", {
  400. name = "Pyramid",
  401. privs = we_privs("pyramid"),
  402. get_formspec = function(name)
  403. local node, axis, length = gui_nodename1[name], gui_axis1[name], gui_distance1[name]
  404. local nodename = worldedit.normalize_nodename(node)
  405. return "size[6.5,4]" .. worldedit.get_formspec_header("worldedit_gui_pyramid") ..
  406. string.format("field[0.5,1.5;4,0.8;worldedit_gui_pyramid_node;Name;%s]", minetest.formspec_escape(node)) ..
  407. "field_close_on_enter[worldedit_gui_pyramid_node;false]" ..
  408. "button[4,1.18;1.5,0.8;worldedit_gui_pyramid_search;Search]" ..
  409. formspec_node("5.5,1.1", nodename) ..
  410. string.format("field[0.5,2.5;4,0.8;worldedit_gui_pyramid_length;Length;%s]", minetest.formspec_escape(length)) ..
  411. string.format("dropdown[4,2.18;2.5;worldedit_gui_pyramid_axis;X axis,Y axis,Z axis,Look direction;%d]", axis) ..
  412. "field_close_on_enter[worldedit_gui_pyramid_length;false]" ..
  413. "button_exit[0,3.5;3,0.8;worldedit_gui_pyramid_submit_hollow;Hollow Pyramid]" ..
  414. "button_exit[3.5,3.5;3,0.8;worldedit_gui_pyramid_submit_solid;Solid Pyramid]"
  415. end,
  416. })
  417. worldedit.register_gui_handler("worldedit_gui_pyramid", function(name, fields)
  418. local cg = {
  419. worldedit_gui_pyramid_search = true,
  420. worldedit_gui_pyramid_node = gui_nodename1,
  421. worldedit_gui_pyramid_axis = gui_axis1,
  422. worldedit_gui_pyramid_length = gui_distance1,
  423. }
  424. local ret = handle_changes(name, "worldedit_gui_pyramid", fields, cg)
  425. if fields.worldedit_gui_pyramid_submit_solid or fields.worldedit_gui_pyramid_submit_hollow then
  426. copy_changes(name, fields, cg)
  427. worldedit.show_page(name, "worldedit_gui_pyramid")
  428. local submit = "pyramid"
  429. if fields.worldedit_gui_pyramid_submit_hollow then
  430. submit = "hollowpyramid"
  431. end
  432. local n = worldedit.normalize_nodename(gui_nodename1[name])
  433. if n then
  434. execute_worldedit_command(submit, name,
  435. string.format("%s %s %s", axis_values[gui_axis1[name]],
  436. gui_distance1[name], n))
  437. end
  438. return true
  439. end
  440. return ret
  441. end)
  442. worldedit.register_gui_function("worldedit_gui_spiral", {
  443. name = "Spiral",
  444. privs = we_privs("spiral"),
  445. get_formspec = function(name)
  446. local node, length, height, space = gui_nodename1[name], gui_distance1[name], gui_distance2[name], gui_distance3[name]
  447. local nodename = worldedit.normalize_nodename(node)
  448. return "size[6.5,6]" .. worldedit.get_formspec_header("worldedit_gui_spiral") ..
  449. string.format("field[0.5,1.5;4,0.8;worldedit_gui_spiral_node;Name;%s]", minetest.formspec_escape(node)) ..
  450. "field_close_on_enter[worldedit_gui_spiral_node;false]" ..
  451. "button[4,1.18;1.5,0.8;worldedit_gui_spiral_search;Search]" ..
  452. formspec_node("5.5,1.1", nodename) ..
  453. string.format("field[0.5,2.5;4,0.8;worldedit_gui_spiral_length;Side Length;%s]", minetest.formspec_escape(length)) ..
  454. string.format("field[0.5,3.5;4,0.8;worldedit_gui_spiral_height;Height;%s]", minetest.formspec_escape(height)) ..
  455. string.format("field[0.5,4.5;4,0.8;worldedit_gui_spiral_space;Wall Spacing;%s]", minetest.formspec_escape(space)) ..
  456. "field_close_on_enter[worldedit_gui_spiral_length;false]" ..
  457. "field_close_on_enter[worldedit_gui_spiral_height;false]" ..
  458. "field_close_on_enter[worldedit_gui_spiral_space;false]" ..
  459. "button_exit[0,5.5;3,0.8;worldedit_gui_spiral_submit;Spiral]"
  460. end,
  461. })
  462. worldedit.register_gui_handler("worldedit_gui_spiral", function(name, fields)
  463. local cg = {
  464. worldedit_gui_spiral_search = true,
  465. worldedit_gui_spiral_node = gui_nodename1,
  466. worldedit_gui_spiral_length = gui_distance1,
  467. worldedit_gui_spiral_height = gui_distance2,
  468. worldedit_gui_spiral_space = gui_distance3,
  469. }
  470. local ret = handle_changes(name, "worldedit_gui_spiral", fields, cg)
  471. if fields.worldedit_gui_spiral_submit then
  472. copy_changes(name, fields, cg)
  473. worldedit.show_page(name, "worldedit_gui_spiral")
  474. local n = worldedit.normalize_nodename(gui_nodename1[name])
  475. if n then
  476. execute_worldedit_command("spiral", name,
  477. string.format("%s %s %s %s", gui_distance1[name],
  478. gui_distance2[name], gui_distance3[name], n))
  479. end
  480. return true
  481. end
  482. return ret
  483. end)
  484. worldedit.register_gui_function("worldedit_gui_copy_move", {
  485. name = "Copy/Move",
  486. privs = combine_we_privs({"copy", "move"}),
  487. get_formspec = function(name)
  488. local axis = gui_axis1[name] or 4
  489. local amount = gui_distance1[name] or "10"
  490. return "size[6.5,3]" .. worldedit.get_formspec_header("worldedit_gui_copy_move") ..
  491. string.format("field[0.5,1.5;4,0.8;worldedit_gui_copy_move_amount;Amount;%s]", minetest.formspec_escape(amount)) ..
  492. string.format("dropdown[4,1.18;2.5;worldedit_gui_copy_move_axis;X axis,Y axis,Z axis,Look direction;%d]", axis) ..
  493. "field_close_on_enter[worldedit_gui_copy_move_amount;false]" ..
  494. "button_exit[0,2.5;3,0.8;worldedit_gui_copy_move_copy;Copy Region]" ..
  495. "button_exit[3.5,2.5;3,0.8;worldedit_gui_copy_move_move;Move Region]"
  496. end,
  497. })
  498. worldedit.register_gui_handler("worldedit_gui_copy_move", function(name, fields)
  499. local cg = {
  500. worldedit_gui_copy_move_amount = gui_distance1,
  501. worldedit_gui_copy_move_axis = gui_axis1,
  502. }
  503. local ret = handle_changes(name, "worldedit_gui_spiral", fields, cg)
  504. if fields.worldedit_gui_copy_move_copy or fields.worldedit_gui_copy_move_move then
  505. copy_changes(name, fields, cg)
  506. worldedit.show_page(name, "worldedit_gui_copy_move")
  507. local submit = "copy"
  508. if fields.worldedit_gui_copy_move_move then
  509. submit = "move"
  510. end
  511. execute_worldedit_command(submit, name,
  512. axis_values[gui_axis1[name]] .. " " .. gui_distance1[name])
  513. return true
  514. end
  515. return ret
  516. end)
  517. worldedit.register_gui_function("worldedit_gui_stack", {
  518. name = "Stack",
  519. privs = we_privs("stack"),
  520. get_formspec = function(name)
  521. local axis, count = gui_axis1[name], gui_count1[name]
  522. return "size[6.5,3]" .. worldedit.get_formspec_header("worldedit_gui_stack") ..
  523. string.format("field[0.5,1.5;4,0.8;worldedit_gui_stack_count;Count;%s]", minetest.formspec_escape(count)) ..
  524. string.format("dropdown[4,1.18;2.5;worldedit_gui_stack_axis;X axis,Y axis,Z axis,Look direction;%d]", axis) ..
  525. "field_close_on_enter[worldedit_gui_stack_count;false]" ..
  526. "button_exit[0,2.5;3,0.8;worldedit_gui_stack_submit;Stack]"
  527. end,
  528. })
  529. worldedit.register_gui_handler("worldedit_gui_stack", function(name, fields)
  530. local cg = {
  531. worldedit_gui_stack_axis = gui_axis1,
  532. worldedit_gui_stack_count = gui_count1,
  533. }
  534. local ret = handle_changes(name, "worldedit_gui_stack", fields, cg)
  535. if fields.worldedit_gui_stack_submit then
  536. copy_changes(name, fields, cg)
  537. worldedit.show_page(name, "worldedit_gui_stack")
  538. execute_worldedit_command("stack", name,
  539. axis_values[gui_axis1[name]] .. " " .. gui_count1[name])
  540. return true
  541. end
  542. return ret
  543. end)
  544. worldedit.register_gui_function("worldedit_gui_stretch", {
  545. name = "Stretch",
  546. privs = we_privs("stretch"),
  547. get_formspec = function(name)
  548. local stretchx, stretchy, stretchz = gui_count1[name], gui_count2[name], gui_count3[name]
  549. return "size[5,5]" .. worldedit.get_formspec_header("worldedit_gui_stretch") ..
  550. string.format("field[0.5,1.5;4,0.8;worldedit_gui_stretch_x;Stretch X;%s]", minetest.formspec_escape(stretchx)) ..
  551. string.format("field[0.5,2.5;4,0.8;worldedit_gui_stretch_y;Stretch Y;%s]", minetest.formspec_escape(stretchy)) ..
  552. string.format("field[0.5,3.5;4,0.8;worldedit_gui_stretch_z;Stretch Z;%s]", minetest.formspec_escape(stretchz)) ..
  553. "field_close_on_enter[worldedit_gui_stretch_x;false]" ..
  554. "field_close_on_enter[worldedit_gui_stretch_y;false]" ..
  555. "field_close_on_enter[worldedit_gui_stretch_z;false]" ..
  556. "button_exit[0,4.5;3,0.8;worldedit_gui_stretch_submit;Stretch]"
  557. end,
  558. })
  559. worldedit.register_gui_handler("worldedit_gui_stretch", function(name, fields)
  560. local cg = {
  561. worldedit_gui_stretch_x = gui_count1,
  562. worldedit_gui_stretch_y = gui_count2,
  563. worldedit_gui_stretch_z = gui_count3,
  564. }
  565. local ret = handle_changes(name, "worldedit_gui_stretch", fields, cg)
  566. if fields.worldedit_gui_stretch_submit then
  567. copy_changes(name, fields, cg)
  568. worldedit.show_page(name, "worldedit_gui_stretch")
  569. execute_worldedit_command("stretch", name, string.format("%s %s %s",
  570. gui_count1[name], gui_count2[name], gui_count3[name]))
  571. return true
  572. end
  573. return ret
  574. end)
  575. worldedit.register_gui_function("worldedit_gui_transpose", {
  576. name = "Transpose",
  577. privs = we_privs("transpose"),
  578. get_formspec = function(name)
  579. local axis1, axis2 = gui_axis1[name], gui_axis2[name]
  580. return "size[5.5,3]" .. worldedit.get_formspec_header("worldedit_gui_transpose") ..
  581. string.format("dropdown[0,1;2.5;worldedit_gui_transpose_axis1;X axis,Y axis,Z axis,Look direction;%d]", axis1) ..
  582. string.format("dropdown[3,1;2.5;worldedit_gui_transpose_axis2;X axis,Y axis,Z axis,Look direction;%d]", axis2) ..
  583. "button_exit[0,2.5;3,0.8;worldedit_gui_transpose_submit;Transpose]"
  584. end,
  585. })
  586. worldedit.register_gui_handler("worldedit_gui_transpose", function(name, fields)
  587. local cg = {
  588. worldedit_gui_transpose_axis1 = gui_axis1,
  589. worldedit_gui_transpose_axis2 = gui_axis2,
  590. }
  591. local ret = handle_changes(name, "worldedit_gui_transpose", fields, cg)
  592. if fields.worldedit_gui_transpose_submit then
  593. copy_changes(name, fields, cg)
  594. execute_worldedit_command("transpose", name,
  595. axis_values[gui_axis1[name]] .. " " .. axis_values[gui_axis2[name]])
  596. return true
  597. end
  598. return ret
  599. end)
  600. worldedit.register_gui_function("worldedit_gui_flip", {
  601. name = "Flip",
  602. privs = we_privs("flip"),
  603. get_formspec = function(name)
  604. local axis = gui_axis1[name]
  605. return "size[5,3]" .. worldedit.get_formspec_header("worldedit_gui_flip") ..
  606. string.format("dropdown[0,1;2.5;worldedit_gui_flip_axis;X axis,Y axis,Z axis,Look direction;%d]", axis) ..
  607. "button_exit[0,2.5;3,0.8;worldedit_gui_flip_submit;Flip]"
  608. end,
  609. })
  610. worldedit.register_gui_handler("worldedit_gui_flip", function(name, fields)
  611. local cg = {
  612. worldedit_gui_flip_axis = gui_axis1
  613. }
  614. local ret = handle_changes(name, "worldedit_gui_flip", fields, cg)
  615. if fields.worldedit_gui_flip_submit then
  616. copy_changes(name, fields, cg)
  617. worldedit.show_page(name, "worldedit_gui_flip")
  618. execute_worldedit_command("flip", name, axis_values[gui_axis1[name]])
  619. return true
  620. end
  621. return ret
  622. end)
  623. worldedit.register_gui_function("worldedit_gui_rotate", {
  624. name = "Rotate",
  625. privs = we_privs("rotate"),
  626. get_formspec = function(name)
  627. local axis, angle = gui_axis1[name], gui_angle[name]
  628. return "size[5.5,3]" .. worldedit.get_formspec_header("worldedit_gui_rotate") ..
  629. string.format("dropdown[0,1;2.5;worldedit_gui_rotate_angle;90 degrees,180 degrees,270 degrees;%s]", angle) ..
  630. string.format("dropdown[3,1;2.5;worldedit_gui_rotate_axis;X axis,Y axis,Z axis,Look direction;%d]", axis) ..
  631. "button_exit[0,2.5;3,0.8;worldedit_gui_rotate_submit;Rotate]"
  632. end,
  633. })
  634. worldedit.register_gui_handler("worldedit_gui_rotate", function(name, fields)
  635. local cg = {
  636. worldedit_gui_rotate_axis = gui_axis1,
  637. worldedit_gui_rotate_angle = gui_angle,
  638. }
  639. local ret = handle_changes(name, "worldedit_gui_rotate", fields, cg)
  640. if fields.worldedit_gui_rotate_submit then
  641. copy_changes(name, fields, cg)
  642. worldedit.show_page(name, "worldedit_gui_rotate")
  643. execute_worldedit_command("rotate", name,
  644. axis_values[gui_axis1[name]] .. " " .. angle_values[gui_angle[name]])
  645. return true
  646. end
  647. return ret
  648. end)
  649. worldedit.register_gui_function("worldedit_gui_orient", {
  650. name = "Orient",
  651. privs = we_privs("orient"),
  652. get_formspec = function(name)
  653. local angle = gui_angle[name]
  654. return "size[5,3]" .. worldedit.get_formspec_header("worldedit_gui_orient") ..
  655. string.format("dropdown[0,1;2.5;worldedit_gui_orient_angle;90 degrees,180 degrees,270 degrees;%s]", angle) ..
  656. "button_exit[0,2.5;3,0.8;worldedit_gui_orient_submit;Orient]"
  657. end,
  658. })
  659. worldedit.register_gui_handler("worldedit_gui_orient", function(name, fields)
  660. local cg = {
  661. worldedit_gui_orient_angle = gui_angle,
  662. }
  663. local ret = handle_changes(name, "worldedit_gui_orient", fields, cg)
  664. if fields.worldedit_gui_orient_submit then
  665. copy_changes(name, fields, cg)
  666. worldedit.show_page(name, "worldedit_gui_orient")
  667. execute_worldedit_command("orient", name,
  668. tostring(angle_values[gui_angle[name]]))
  669. return true
  670. end
  671. return ret
  672. end)
  673. worldedit.register_gui_function("worldedit_gui_fixlight", {
  674. name = "Fix Lighting",
  675. privs = we_privs("fixlight"),
  676. on_select = function(name)
  677. execute_worldedit_command("fixlight", name, "")
  678. end,
  679. })
  680. worldedit.register_gui_function("worldedit_gui_hide", {
  681. name = "Hide Region",
  682. privs = we_privs("hide"),
  683. on_select = function(name)
  684. execute_worldedit_command("hide", name, "")
  685. end,
  686. })
  687. worldedit.register_gui_function("worldedit_gui_suppress", {
  688. name = "Suppress Nodes",
  689. privs = we_privs("suppress"),
  690. get_formspec = function(name)
  691. local node = gui_nodename1[name]
  692. local nodename = worldedit.normalize_nodename(node)
  693. return "size[6.5,3]" .. worldedit.get_formspec_header("worldedit_gui_suppress") ..
  694. string.format("field[0.5,1.5;4,0.8;worldedit_gui_suppress_node;Name;%s]", minetest.formspec_escape(node)) ..
  695. "field_close_on_enter[worldedit_gui_suppress_node;false]" ..
  696. "button[4,1.18;1.5,0.8;worldedit_gui_suppress_search;Search]" ..
  697. formspec_node("5.5,1.1", nodename) ..
  698. "button_exit[0,2.5;3,0.8;worldedit_gui_suppress_submit;Suppress Nodes]"
  699. end,
  700. })
  701. worldedit.register_gui_handler("worldedit_gui_suppress", function(name, fields)
  702. local cg = {
  703. worldedit_gui_suppress_search = true,
  704. worldedit_gui_suppress_node = gui_nodename1,
  705. }
  706. local ret = handle_changes(name, "worldedit_gui_suppress", fields, cg)
  707. if fields.worldedit_gui_suppress_submit then
  708. copy_changes(name, fields, cg)
  709. worldedit.show_page(name, "worldedit_gui_suppress")
  710. local n = worldedit.normalize_nodename(gui_nodename1[name])
  711. if n then
  712. execute_worldedit_command("suppress", name, n)
  713. end
  714. return true
  715. end
  716. return ret
  717. end)
  718. worldedit.register_gui_function("worldedit_gui_highlight", {
  719. name = "Highlight Nodes",
  720. privs = we_privs("highlight"),
  721. get_formspec = function(name)
  722. local node = gui_nodename1[name]
  723. local nodename = worldedit.normalize_nodename(node)
  724. return "size[6.5,3]" .. worldedit.get_formspec_header("worldedit_gui_highlight") ..
  725. string.format("field[0.5,1.5;4,0.8;worldedit_gui_highlight_node;Name;%s]", minetest.formspec_escape(node)) ..
  726. "field_close_on_enter[worldedit_gui_highlight_node;false]" ..
  727. "button[4,1.18;1.5,0.8;worldedit_gui_highlight_search;Search]" ..
  728. formspec_node("5.5,1.1", nodename) ..
  729. "button_exit[0,2.5;3,0.8;worldedit_gui_highlight_submit;Highlight Nodes]"
  730. end,
  731. })
  732. worldedit.register_gui_handler("worldedit_gui_highlight", function(name, fields)
  733. local cg = {
  734. worldedit_gui_highlight_search = true,
  735. worldedit_gui_highlight_node = gui_nodename1,
  736. }
  737. local ret = handle_changes(name, "worldedit_gui_highlight", fields, cg)
  738. if fields.worldedit_gui_highlight_submit then
  739. copy_changes(name, fields, cg)
  740. worldedit.show_page(name, "worldedit_gui_highlight")
  741. local n = worldedit.normalize_nodename(gui_nodename1[name])
  742. if n then
  743. execute_worldedit_command("highlight", name, n)
  744. end
  745. return true
  746. end
  747. return ret
  748. end)
  749. worldedit.register_gui_function("worldedit_gui_restore", {
  750. name = "Restore Region",
  751. privs = we_privs("restore"),
  752. on_select = function(name)
  753. execute_worldedit_command("restore", name, "")
  754. end,
  755. })
  756. worldedit.register_gui_function("worldedit_gui_save_load", {
  757. name = "Save/Load",
  758. privs = combine_we_privs({"save", "allocate", "load"}),
  759. get_formspec = function(name)
  760. local filename = gui_filename[name]
  761. return "size[6,4]" .. worldedit.get_formspec_header("worldedit_gui_save_load") ..
  762. string.format("field[0.5,1.5;4,0.8;worldedit_gui_save_filename;Filename;%s]", minetest.formspec_escape(filename)) ..
  763. "field_close_on_enter[worldedit_gui_save_filename;false]" ..
  764. "button_exit[0,2.5;3,0.8;worldedit_gui_save_load_submit_save;Save]" ..
  765. "button_exit[3,2.5;3,0.8;worldedit_gui_save_load_submit_allocate;Allocate]" ..
  766. "button_exit[0,3.5;3,0.8;worldedit_gui_save_load_submit_load;Load]"
  767. end,
  768. })
  769. worldedit.register_gui_handler("worldedit_gui_save_load", function(name, fields)
  770. if fields.worldedit_gui_save_load_submit_save or fields.worldedit_gui_save_load_submit_allocate or fields.worldedit_gui_save_load_submit_load then
  771. gui_filename[name] = tostring(fields.worldedit_gui_save_filename)
  772. worldedit.show_page(name, "worldedit_gui_save_load")
  773. if fields.worldedit_gui_save_load_submit_save then
  774. execute_worldedit_command("save", name, gui_filename[name])
  775. elseif fields.worldedit_gui_save_load_submit_allocate then
  776. execute_worldedit_command("allocate", name, gui_filename[name])
  777. else --fields.worldedit_gui_save_load_submit_load
  778. execute_worldedit_command("load", name, gui_filename[name])
  779. end
  780. return true
  781. end
  782. return false
  783. end)
  784. worldedit.register_gui_function("worldedit_gui_cube", {
  785. name = "Cube",
  786. privs = combine_we_privs({"hollowcube", "cube"}),
  787. get_formspec = function(name)
  788. local width, height, length = gui_distance1[name], gui_distance2[name], gui_distance3[name]
  789. local node = gui_nodename1[name]
  790. local nodename = worldedit.normalize_nodename(node)
  791. return "size[6.5,4]" .. worldedit.get_formspec_header("worldedit_gui_cube") ..
  792. string.format("field[0.5,1.5;4,0.8;worldedit_gui_cube_node;Name;%s]", minetest.formspec_escape(node)) ..
  793. "field_close_on_enter[worldedit_gui_cube_node;false]" ..
  794. "button[4,1.18;1.5,0.8;worldedit_gui_cube_search;Search]" ..
  795. formspec_node("5.5,1.1", nodename) ..
  796. string.format("field[0.5,2.5;1,0.8;worldedit_gui_cube_width;Width;%s]", minetest.formspec_escape(width)) ..
  797. string.format("field[1.5,2.5;1,0.8;worldedit_gui_cube_height;Height;%s]", minetest.formspec_escape(height)) ..
  798. string.format("field[2.5,2.5;1,0.8;worldedit_gui_cube_length;Length;%s]", minetest.formspec_escape(length)) ..
  799. "field_close_on_enter[worldedit_gui_cube_width;false]" ..
  800. "field_close_on_enter[worldedit_gui_cube_height;false]" ..
  801. "field_close_on_enter[worldedit_gui_cube_length;false]" ..
  802. "button_exit[0,3.5;3,0.8;worldedit_gui_cube_submit_hollow;Hollow Cuboid]" ..
  803. "button_exit[3.5,3.5;3,0.8;worldedit_gui_cube_submit_solid;Solid Cuboid]"
  804. end,
  805. })
  806. worldedit.register_gui_handler("worldedit_gui_cube", function(name, fields)
  807. local cg = {
  808. worldedit_gui_cube_search = true,
  809. worldedit_gui_cube_node = gui_nodename1,
  810. worldedit_gui_cube_width = gui_distance1,
  811. worldedit_gui_cube_height = gui_distance2,
  812. worldedit_gui_cube_length = gui_distance3,
  813. }
  814. local ret = handle_changes(name, "worldedit_gui_cube", fields, cg)
  815. if fields.worldedit_gui_cube_submit_hollow or fields.worldedit_gui_cube_submit_solid then
  816. copy_changes(name, fields, cg)
  817. worldedit.show_page(name, "worldedit_gui_cube")
  818. local submit = "hollowcube"
  819. if fields.worldedit_gui_cube_submit_solid then
  820. submit = "cube"
  821. end
  822. local n = worldedit.normalize_nodename(gui_nodename1[name])
  823. if n then
  824. local args = string.format("%s %s %s %s", gui_distance1[name], gui_distance2[name], gui_distance3[name], n)
  825. execute_worldedit_command(submit, name, args)
  826. end
  827. return true
  828. end
  829. return ret
  830. end)
  831. worldedit.register_gui_function("worldedit_gui_clearobjects", {
  832. name = "Clear Objects",
  833. privs = we_privs("clearobjects"),
  834. on_select = function(name)
  835. execute_worldedit_command("clearobjects", name, "")
  836. end,
  837. })
  838. worldedit.register_gui_function("worldedit_gui_param2", {
  839. name = "Set Param2",
  840. privs = we_privs("param2"),
  841. get_formspec = function(name)
  842. local value = gui_param2[name] or "0"
  843. return "size[6.5,3]" .. worldedit.get_formspec_header("worldedit_gui_param2") ..
  844. "textarea[0.5,1;5,2;;;Some values may break the node!]"..
  845. string.format("field[0.5,2.5;2,0.8;worldedit_gui_param2_value;New Param2;%s]", minetest.formspec_escape(value)) ..
  846. "field_close_on_enter[worldedit_gui_param2_value;false]" ..
  847. "button_exit[3.5,2.5;3,0.8;worldedit_gui_param2_submit;Set Param2]"
  848. end,
  849. })
  850. worldedit.register_gui_handler("worldedit_gui_param2", function(name, fields)
  851. local cg = {
  852. worldedit_gui_param2_value = gui_param2,
  853. }
  854. local ret = handle_changes(name, "worldedit_gui_param2", fields, cg)
  855. if fields.worldedit_gui_param2_submit then
  856. copy_changes(name, fields, cg)
  857. worldedit.show_page(name, "worldedit_gui_param2")
  858. execute_worldedit_command("param2", name, gui_param2[name])
  859. return true
  860. end
  861. return ret
  862. end)