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