]> git.lizzy.rs Git - worldedit.git/blob - worldedit_gui/functionality.lua
1efed10e27450277227dcf434446a3b43651276e
[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 worldedit.register_gui_function("worldedit_gui_about", {\r
136         name = "About",\r
137         privs = {interact=true},\r
138         on_select = function(name)\r
139                 minetest.chatcommands["/about"].func(name, "")\r
140         end,\r
141 })\r
142 \r
143 worldedit.register_gui_function("worldedit_gui_inspect", {\r
144         name = "Toggle Inspect",\r
145         privs = we_privs("inspect"),\r
146         on_select = function(name)\r
147                 minetest.chatcommands["/inspect"].func(name, worldedit.inspect[name] and "disable" or "enable")\r
148         end,\r
149 })\r
150 \r
151 worldedit.register_gui_function("worldedit_gui_region", {\r
152         name = "Get/Set Region",\r
153         privs = combine_we_privs({"p", "pos1", "pos2", "reset", "mark", "unmark", "volume", "fixedpos"}),\r
154         get_formspec = function(name)\r
155                 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
156                 return "size[9,7]" .. worldedit.get_formspec_header("worldedit_gui_region") ..\r
157                         "button_exit[0,1;3,0.8;worldedit_gui_p_get;Get Positions]" ..\r
158                         "button_exit[3,1;3,0.8;worldedit_gui_p_set1;Choose Position 1]" ..\r
159                         "button_exit[6,1;3,0.8;worldedit_gui_p_set2;Choose Position 2]" ..\r
160                         "button_exit[0,2;3,0.8;worldedit_gui_pos1;Position 1 Here]" ..\r
161                         "button_exit[3,2;3,0.8;worldedit_gui_pos2;Position 2 Here]" ..\r
162                         "button_exit[6,2;3,0.8;worldedit_gui_reset;Reset Region]" ..\r
163                         "button_exit[0,3;3,0.8;worldedit_gui_mark;Mark Region]" ..\r
164                         "button_exit[3,3;3,0.8;worldedit_gui_unmark;Unmark Region]" ..\r
165                         "button_exit[6,3;3,0.8;worldedit_gui_volume;Region Volume]" ..\r
166                         "label[0,4.7;Position 1]" ..\r
167                         string.format("field[2,5;1.5,0.8;worldedit_gui_fixedpos_pos1x;X ;%s]", pos1 and pos1.x or "") ..\r
168                         string.format("field[3.5,5;1.5,0.8;worldedit_gui_fixedpos_pos1y;Y ;%s]", pos1 and pos1.y or "") ..\r
169                         string.format("field[5,5;1.5,0.8;worldedit_gui_fixedpos_pos1z;Z ;%s]", pos1 and pos1.z or "") ..\r
170                         "button_exit[6.5,4.68;2.5,0.8;worldedit_gui_fixedpos_pos1_submit;Set Position 1]" ..\r
171                         "label[0,6.2;Position 2]" ..\r
172                         string.format("field[2,6.5;1.5,0.8;worldedit_gui_fixedpos_pos2x;X ;%s]", pos2 and pos2.x or "") ..\r
173                         string.format("field[3.5,6.5;1.5,0.8;worldedit_gui_fixedpos_pos2y;Y ;%s]", pos2 and pos2.y or "") ..\r
174                         string.format("field[5,6.5;1.5,0.8;worldedit_gui_fixedpos_pos2z;Z ;%s]", pos2 and pos2.z or "") ..\r
175                         "button_exit[6.5,6.18;2.5,0.8;worldedit_gui_fixedpos_pos2_submit;Set Position 2]"\r
176         end,\r
177 })\r
178 \r
179 worldedit.register_gui_handler("worldedit_gui_region", function(name, fields)\r
180         if fields.worldedit_gui_p_get then\r
181                 minetest.chatcommands["/p"].func(name, "get")\r
182                 return true\r
183         elseif fields.worldedit_gui_p_set1 then\r
184                 minetest.chatcommands["/p"].func(name, "set1")\r
185                 return true\r
186         elseif fields.worldedit_gui_p_set2 then\r
187                 minetest.chatcommands["/p"].func(name, "set2")\r
188                 return true\r
189         elseif fields.worldedit_gui_pos1 then\r
190                 minetest.chatcommands["/pos1"].func(name, "")\r
191                 worldedit.show_page(name, "worldedit_gui_region")\r
192                 return true\r
193         elseif fields.worldedit_gui_pos2 then\r
194                 minetest.chatcommands["/pos2"].func(name, "")\r
195                 worldedit.show_page(name, "worldedit_gui_region")\r
196                 return true\r
197         elseif fields.worldedit_gui_reset then\r
198                 minetest.chatcommands["/reset"].func(name, "")\r
199                 worldedit.show_page(name, "worldedit_gui_region")\r
200                 return true\r
201         elseif fields.worldedit_gui_mark then\r
202                 minetest.chatcommands["/mark"].func(name, "")\r
203                 worldedit.show_page(name, "worldedit_gui_region")\r
204                 return true\r
205         elseif fields.worldedit_gui_unmark then\r
206                 minetest.chatcommands["/unmark"].func(name, "")\r
207                 worldedit.show_page(name, "worldedit_gui_region")\r
208                 return true\r
209         elseif fields.worldedit_gui_volume then\r
210                 minetest.chatcommands["/volume"].func(name, "")\r
211                 worldedit.show_page(name, "worldedit_gui_region")\r
212                 return true\r
213         elseif fields.worldedit_gui_fixedpos_pos1_submit then\r
214                 minetest.chatcommands["/fixedpos"].func(name, string.format("set1 %s %s %s",\r
215                         tostring(fields.worldedit_gui_fixedpos_pos1x),\r
216                         tostring(fields.worldedit_gui_fixedpos_pos1y),\r
217                         tostring(fields.worldedit_gui_fixedpos_pos1z)))\r
218                 worldedit.show_page(name, "worldedit_gui_region")\r
219                 return true\r
220         elseif fields.worldedit_gui_fixedpos_pos2_submit then\r
221                 minetest.chatcommands["/fixedpos"].func(name, string.format("set2 %s %s %s",\r
222                         tostring(fields.worldedit_gui_fixedpos_pos2x),\r
223                         tostring(fields.worldedit_gui_fixedpos_pos2y),\r
224                         tostring(fields.worldedit_gui_fixedpos_pos2z)))\r
225                 worldedit.show_page(name, "worldedit_gui_region")\r
226                 return true\r
227         end\r
228         return false\r
229 end)\r
230 \r
231 worldedit.register_gui_function("worldedit_gui_set", {\r
232         name = "Set Nodes",\r
233         privs = we_privs("set"),\r
234         get_formspec = function(name)\r
235                 local node = gui_nodename1[name]\r
236                 local nodename = worldedit.normalize_nodename(node)\r
237                 return "size[6.5,3]" .. worldedit.get_formspec_header("worldedit_gui_set") ..\r
238                         string.format("field[0.5,1.5;4,0.8;worldedit_gui_set_node;Name;%s]", minetest.formspec_escape(node)) ..\r
239                         "field_close_on_enter[worldedit_gui_set_node;false]" ..\r
240                         "button[4,1.18;1.5,0.8;worldedit_gui_set_search;Search]" ..\r
241                         formspec_node("5.5,1.1", nodename) ..\r
242                         "button_exit[0,2.5;3,0.8;worldedit_gui_set_submit;Set Nodes]"\r
243         end,\r
244 })\r
245 \r
246 worldedit.register_gui_handler("worldedit_gui_set", function(name, fields)\r
247         local cg = {\r
248                 worldedit_gui_set_search = true,\r
249                 worldedit_gui_set_node = gui_nodename1,\r
250         }\r
251         local ret = handle_changes(name, "worldedit_gui_set", fields, cg)\r
252         if fields.worldedit_gui_set_submit then\r
253                 copy_changes(name, fields, cg)\r
254                 worldedit.show_page(name, "worldedit_gui_set")\r
255 \r
256                 local n = worldedit.normalize_nodename(gui_nodename1[name])\r
257                 if n then\r
258                         minetest.chatcommands["/set"].func(name, n)\r
259                 end\r
260                 return true\r
261         end\r
262         return ret\r
263 end)\r
264 \r
265 worldedit.register_gui_function("worldedit_gui_replace", {\r
266         name = "Replace Nodes",\r
267         privs = combine_we_privs({"replace", "replaceinverse"}),\r
268         get_formspec = function(name)\r
269                 local search, replace = gui_nodename1[name], gui_nodename2[name]\r
270                 local search_nodename, replace_nodename = worldedit.normalize_nodename(search), worldedit.normalize_nodename(replace)\r
271                 return "size[6.5,4]" .. worldedit.get_formspec_header("worldedit_gui_replace") ..\r
272                         string.format("field[0.5,1.5;4,0.8;worldedit_gui_replace_search;Name;%s]", minetest.formspec_escape(search)) ..\r
273                         "field_close_on_enter[worldedit_gui_replace_search;false]" ..\r
274                         "button[4,1.18;1.5,0.8;worldedit_gui_replace_search_search;Search]" ..\r
275                         formspec_node("5.5,1.1", search_nodename) ..\r
276                         string.format("field[0.5,2.5;4,0.8;worldedit_gui_replace_replace;Name;%s]", minetest.formspec_escape(replace)) ..\r
277                         "field_close_on_enter[worldedit_gui_replace_replace;false]" ..\r
278                         "button[4,2.18;1.5,0.8;worldedit_gui_replace_replace_search;Search]" ..\r
279                         formspec_node("5.5,2.1", replace_nodename) ..\r
280                         "button_exit[0,3.5;3,0.8;worldedit_gui_replace_submit;Replace Nodes]" ..\r
281                         "button_exit[3.5,3.5;3,0.8;worldedit_gui_replace_submit_inverse;Replace Inverse]"\r
282         end,\r
283 })\r
284 \r
285 worldedit.register_gui_handler("worldedit_gui_replace", function(name, fields)\r
286         local cg = {\r
287                 worldedit_gui_replace_search_search = true,\r
288                 worldedit_gui_replace_replace_search = true,\r
289                 worldedit_gui_replace_search = gui_nodename1,\r
290                 worldedit_gui_replace_replace = gui_nodename2,\r
291         }\r
292         local ret = handle_changes(name, "worldedit_gui_replace", fields, cg)\r
293         if fields.worldedit_gui_replace_submit or fields.worldedit_gui_replace_submit_inverse then\r
294                 copy_changes(name, fields, cg)\r
295                 worldedit.show_page(name, "worldedit_gui_replace")\r
296 \r
297                 local submit = "replace"\r
298                 if fields.worldedit_gui_replace_submit_inverse then\r
299                         submit = "replaceinverse"\r
300                 end\r
301                 local n1 = worldedit.normalize_nodename(gui_nodename1[name])\r
302                 local n2 = worldedit.normalize_nodename(gui_nodename2[name])\r
303                 if n1 and n2 then\r
304                         minetest.chatcommands["/"..submit].func(name, string.format("%s %s", n1, n2))\r
305                 end\r
306                 return true\r
307         end\r
308         return ret\r
309 end)\r
310 \r
311 worldedit.register_gui_function("worldedit_gui_sphere_dome", {\r
312         name = "Sphere/Dome",\r
313         privs = combine_we_privs({"hollowsphere", "sphere", "hollowdome", "dome"}),\r
314         get_formspec = function(name)\r
315                 local node, radius = gui_nodename1[name], gui_distance2[name]\r
316                 local nodename = worldedit.normalize_nodename(node)\r
317                 return "size[6.5,5]" .. worldedit.get_formspec_header("worldedit_gui_sphere_dome") ..\r
318                         string.format("field[0.5,1.5;4,0.8;worldedit_gui_sphere_dome_node;Name;%s]", minetest.formspec_escape(node)) ..\r
319                         "field_close_on_enter[worldedit_gui_sphere_dome_node;false]" ..\r
320                         "button[4,1.18;1.5,0.8;worldedit_gui_sphere_dome_search;Search]" ..\r
321                         formspec_node("5.5,1.1", nodename) ..\r
322                         string.format("field[0.5,2.5;4,0.8;worldedit_gui_sphere_dome_radius;Radius;%s]", minetest.formspec_escape(radius)) ..\r
323                         "field_close_on_enter[worldedit_gui_sphere_dome_radius;false]" ..\r
324                         "button_exit[0,3.5;3,0.8;worldedit_gui_sphere_dome_submit_hollow;Hollow Sphere]" ..\r
325                         "button_exit[3.5,3.5;3,0.8;worldedit_gui_sphere_dome_submit_solid;Solid Sphere]" ..\r
326                         "button_exit[0,4.5;3,0.8;worldedit_gui_sphere_dome_submit_hollow_dome;Hollow Dome]" ..\r
327                         "button_exit[3.5,4.5;3,0.8;worldedit_gui_sphere_dome_submit_solid_dome;Solid Dome]"\r
328         end,\r
329 })\r
330 \r
331 worldedit.register_gui_handler("worldedit_gui_sphere_dome", function(name, fields)\r
332         local cg = {\r
333                 worldedit_gui_sphere_dome_search = true,\r
334                 worldedit_gui_sphere_dome_node = gui_nodename1,\r
335                 worldedit_gui_sphere_dome_radius = gui_distance2,\r
336         }\r
337         local ret = handle_changes(name, "worldedit_gui_sphere_dome", fields, cg)\r
338         if fields.worldedit_gui_sphere_dome_submit_hollow or fields.worldedit_gui_sphere_dome_submit_solid\r
339         or fields.worldedit_gui_sphere_dome_submit_hollow_dome or fields.worldedit_gui_sphere_dome_submit_solid_dome then\r
340                 copy_changes(name, fields, cg)\r
341                 worldedit.show_page(name, "worldedit_gui_sphere_dome")\r
342 \r
343                 local submit = "hollowsphere"\r
344                 if fields.worldedit_gui_sphere_dome_submit_solid then\r
345                         submit = "sphere"\r
346                 elseif fields.worldedit_gui_sphere_dome_submit_hollow_dome then\r
347                         submit = "hollowdome"\r
348                 elseif fields.worldedit_gui_sphere_dome_submit_solid_dome then\r
349                         submit = "dome"\r
350                 end\r
351                 local n = worldedit.normalize_nodename(gui_nodename1[name])\r
352                 if n then\r
353                         minetest.chatcommands["/"..submit].func(name, string.format("%s %s", gui_distance2[name], n))\r
354                 end\r
355                 return true\r
356         end\r
357         return ret\r
358 end)\r
359 \r
360 worldedit.register_gui_function("worldedit_gui_cylinder", {\r
361         name = "Cylinder",\r
362         privs = combine_we_privs({"hollowcylinder", "cylinder"}),\r
363         get_formspec = function(name)\r
364                 local node, axis, length = gui_nodename1[name], gui_axis1[name], gui_distance1[name]\r
365                 local radius1, radius2 = gui_distance2[name], gui_distance3[name]\r
366                 local nodename = worldedit.normalize_nodename(node)\r
367                 return "size[6.5,6]" .. worldedit.get_formspec_header("worldedit_gui_cylinder") ..\r
368                         string.format("field[0.5,1.5;4,0.8;worldedit_gui_cylinder_node;Name;%s]", minetest.formspec_escape(node)) ..\r
369                         "field_close_on_enter[worldedit_gui_cylinder_node;false]" ..\r
370                         "button[4,1.18;1.5,0.8;worldedit_gui_cylinder_search;Search]" ..\r
371                         formspec_node("5.5,1.1", nodename) ..\r
372                         string.format("field[0.5,2.5;4,0.8;worldedit_gui_cylinder_length;Length;%s]", minetest.formspec_escape(length)) ..\r
373                         string.format("dropdown[4,2.18;2.5;worldedit_gui_cylinder_axis;X axis,Y axis,Z axis,Look direction;%d]", axis) ..\r
374                         string.format("field[0.5,3.5;2,0.8;worldedit_gui_cylinder_radius1;Base Radius;%s]", minetest.formspec_escape(radius1)) ..\r
375                         string.format("field[2.5,3.5;2,0.8;worldedit_gui_cylinder_radius2;Top Radius;%s]", minetest.formspec_escape(radius2)) ..\r
376                         "field_close_on_enter[worldedit_gui_cylinder_length;false]" ..\r
377                         "field_close_on_enter[worldedit_gui_cylinder_radius1;false]" ..\r
378                         "field_close_on_enter[worldedit_gui_cylinder_radius2;false]" ..\r
379                         "label[0.25,4;Equal base and top radius creates a cylinder,\n"..\r
380                                 "zero top radius creates a cone.\nConsult documentation for more information.]"..\r
381                         "button_exit[0,5.5;3,0.8;worldedit_gui_cylinder_submit_hollow;Hollow Cylinder]" ..\r
382                         "button_exit[3.5,5.5;3,0.8;worldedit_gui_cylinder_submit_solid;Solid Cylinder]"\r
383         end,\r
384 })\r
385 \r
386 worldedit.register_gui_handler("worldedit_gui_cylinder", function(name, fields)\r
387         local cg = {\r
388                 worldedit_gui_cylinder_search = true,\r
389                 worldedit_gui_cylinder_node = gui_nodename1,\r
390                 worldedit_gui_cylinder_axis = gui_axis1,\r
391                 worldedit_gui_cylinder_length = gui_distance1,\r
392                 worldedit_gui_cylinder_radius1 = gui_distance2,\r
393                 worldedit_gui_cylinder_radius2 = gui_distance3,\r
394         }\r
395         local ret = handle_changes(name, "worldedit_gui_cylinder", fields, cg)\r
396         if fields.worldedit_gui_cylinder_submit_hollow or fields.worldedit_gui_cylinder_submit_solid then\r
397                 copy_changes(name, fields, cg)\r
398                 worldedit.show_page(name, "worldedit_gui_cylinder")\r
399 \r
400                 local submit = "hollowcylinder"\r
401                 if fields.worldedit_gui_cylinder_submit_solid then\r
402                         submit = "cylinder"\r
403                 end\r
404                 local n = worldedit.normalize_nodename(gui_nodename1[name])\r
405                 if n then\r
406                         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
407                         minetest.chatcommands["/"..submit].func(name, args)\r
408                 end\r
409                 return true\r
410         end\r
411         return ret\r
412 end)\r
413 \r
414 worldedit.register_gui_function("worldedit_gui_pyramid", {\r
415         name = "Pyramid",\r
416         privs = we_privs("pyramid"),\r
417         get_formspec = function(name)\r
418                 local node, axis, length = gui_nodename1[name], gui_axis1[name], gui_distance1[name]\r
419                 local nodename = worldedit.normalize_nodename(node)\r
420                 return "size[6.5,4]" .. worldedit.get_formspec_header("worldedit_gui_pyramid") ..\r
421                         string.format("field[0.5,1.5;4,0.8;worldedit_gui_pyramid_node;Name;%s]", minetest.formspec_escape(node)) ..\r
422                         "field_close_on_enter[worldedit_gui_pyramid_node;false]" ..\r
423                         "button[4,1.18;1.5,0.8;worldedit_gui_pyramid_search;Search]" ..\r
424                         formspec_node("5.5,1.1", nodename) ..\r
425                         string.format("field[0.5,2.5;4,0.8;worldedit_gui_pyramid_length;Length;%s]", minetest.formspec_escape(length)) ..\r
426                         string.format("dropdown[4,2.18;2.5;worldedit_gui_pyramid_axis;X axis,Y axis,Z axis,Look direction;%d]", axis) ..\r
427                         "field_close_on_enter[worldedit_gui_pyramid_length;false]" ..\r
428                         "button_exit[0,3.5;3,0.8;worldedit_gui_pyramid_submit_hollow;Hollow Pyramid]" ..\r
429                         "button_exit[3.5,3.5;3,0.8;worldedit_gui_pyramid_submit_solid;Solid Pyramid]"\r
430         end,\r
431 })\r
432 \r
433 worldedit.register_gui_handler("worldedit_gui_pyramid", function(name, fields)\r
434         local cg = {\r
435                 worldedit_gui_pyramid_search = true,\r
436                 worldedit_gui_pyramid_node = gui_nodename1,\r
437                 worldedit_gui_pyramid_axis = gui_axis1,\r
438                 worldedit_gui_pyramid_length = gui_distance1,\r
439         }\r
440         local ret = handle_changes(name, "worldedit_gui_pyramid", fields, cg)\r
441         if fields.worldedit_gui_pyramid_submit_solid or fields.worldedit_gui_pyramid_submit_hollow then\r
442                 copy_changes(name, fields, cg)\r
443                 worldedit.show_page(name, "worldedit_gui_pyramid")\r
444 \r
445                 local submit = "pyramid"\r
446                 if fields.worldedit_gui_pyramid_submit_hollow then\r
447                         submit = "hollowpyramid"\r
448                 end\r
449                 local n = worldedit.normalize_nodename(gui_nodename1[name])\r
450                 if n then\r
451                         minetest.chatcommands["/"..submit].func(name, string.format("%s %s %s", axis_values[gui_axis1[name]], gui_distance1[name], n))\r
452                 end\r
453                 return true\r
454         end\r
455         return ret\r
456 end)\r
457 \r
458 worldedit.register_gui_function("worldedit_gui_spiral", {\r
459         name = "Spiral",\r
460         privs = we_privs("spiral"),\r
461         get_formspec = function(name)\r
462                 local node, length, height, space = gui_nodename1[name], gui_distance1[name], gui_distance2[name], gui_distance3[name]\r
463                 local nodename = worldedit.normalize_nodename(node)\r
464                 return "size[6.5,6]" .. worldedit.get_formspec_header("worldedit_gui_spiral") ..\r
465                         string.format("field[0.5,1.5;4,0.8;worldedit_gui_spiral_node;Name;%s]", minetest.formspec_escape(node)) ..\r
466                         "field_close_on_enter[worldedit_gui_spiral_node;false]" ..\r
467                         "button[4,1.18;1.5,0.8;worldedit_gui_spiral_search;Search]" ..\r
468                         formspec_node("5.5,1.1", nodename) ..\r
469                         string.format("field[0.5,2.5;4,0.8;worldedit_gui_spiral_length;Side Length;%s]", minetest.formspec_escape(length)) ..\r
470                         string.format("field[0.5,3.5;4,0.8;worldedit_gui_spiral_height;Height;%s]", minetest.formspec_escape(height)) ..\r
471                         string.format("field[0.5,4.5;4,0.8;worldedit_gui_spiral_space;Wall Spacing;%s]", minetest.formspec_escape(space)) ..\r
472                         "field_close_on_enter[worldedit_gui_spiral_length;false]" ..\r
473                         "field_close_on_enter[worldedit_gui_spiral_height;false]" ..\r
474                         "field_close_on_enter[worldedit_gui_spiral_space;false]" ..\r
475                         "button_exit[0,5.5;3,0.8;worldedit_gui_spiral_submit;Spiral]"\r
476         end,\r
477 })\r
478 \r
479 worldedit.register_gui_handler("worldedit_gui_spiral", function(name, fields)\r
480         local cg = {\r
481                 worldedit_gui_spiral_search = true,\r
482                 worldedit_gui_spiral_node = gui_nodename1,\r
483                 worldedit_gui_spiral_length = gui_distance1,\r
484                 worldedit_gui_spiral_height = gui_distance2,\r
485                 worldedit_gui_spiral_space = gui_distance3,\r
486         }\r
487         local ret = handle_changes(name, "worldedit_gui_spiral", fields, cg)\r
488         if fields.worldedit_gui_spiral_submit then\r
489                 copy_changes(name, fields, cg)\r
490                 worldedit.show_page(name, "worldedit_gui_spiral")\r
491 \r
492                 local n = worldedit.normalize_nodename(gui_nodename1[name])\r
493                 if n then\r
494                         minetest.chatcommands["/spiral"].func(name, string.format("%s %s %s %s", gui_distance1[name], gui_distance2[name], gui_distance3[name], n))\r
495                 end\r
496                 return true\r
497         end\r
498         return ret\r
499 end)\r
500 \r
501 worldedit.register_gui_function("worldedit_gui_copy_move", {\r
502         name = "Copy/Move",\r
503         privs = combine_we_privs({"copy", "move"}),\r
504         get_formspec = function(name)\r
505                 local axis = gui_axis1[name] or 4\r
506                 local amount = gui_distance1[name] or "10"\r
507                 return "size[6.5,3]" .. worldedit.get_formspec_header("worldedit_gui_copy_move") ..\r
508                         string.format("field[0.5,1.5;4,0.8;worldedit_gui_copy_move_amount;Amount;%s]", minetest.formspec_escape(amount)) ..\r
509                         string.format("dropdown[4,1.18;2.5;worldedit_gui_copy_move_axis;X axis,Y axis,Z axis,Look direction;%d]", axis) ..\r
510                         "field_close_on_enter[worldedit_gui_copy_move_amount;false]" ..\r
511                         "button_exit[0,2.5;3,0.8;worldedit_gui_copy_move_copy;Copy Region]" ..\r
512                         "button_exit[3.5,2.5;3,0.8;worldedit_gui_copy_move_move;Move Region]"\r
513         end,\r
514 })\r
515 \r
516 worldedit.register_gui_handler("worldedit_gui_copy_move", function(name, fields)\r
517         local cg = {\r
518                 worldedit_gui_copy_move_amount = gui_distance1,\r
519                 worldedit_gui_copy_move_axis = gui_axis1,\r
520         }\r
521         local ret = handle_changes(name, "worldedit_gui_spiral", fields, cg)\r
522         if fields.worldedit_gui_copy_move_copy or fields.worldedit_gui_copy_move_move then\r
523                 copy_changes(name, fields, cg)\r
524                 worldedit.show_page(name, "worldedit_gui_copy_move")\r
525 \r
526                 local submit = "copy"\r
527                 if fields.worldedit_gui_copy_move_move then\r
528                         submit = "move"\r
529                 end\r
530                 minetest.chatcommands["/"..submit].func(name, string.format("%s %s", axis_values[gui_axis1[name]], gui_distance1[name]))\r
531                 return true\r
532         end\r
533         return ret\r
534 end)\r
535 \r
536 worldedit.register_gui_function("worldedit_gui_stack", {\r
537         name = "Stack",\r
538         privs = we_privs("stack"),\r
539         get_formspec = function(name)\r
540                 local axis, count = gui_axis1[name], gui_count1[name]\r
541                 return "size[6.5,3]" .. worldedit.get_formspec_header("worldedit_gui_stack") ..\r
542                         string.format("field[0.5,1.5;4,0.8;worldedit_gui_stack_count;Count;%s]", minetest.formspec_escape(count)) ..\r
543                         string.format("dropdown[4,1.18;2.5;worldedit_gui_stack_axis;X axis,Y axis,Z axis,Look direction;%d]", axis) ..\r
544                         "field_close_on_enter[worldedit_gui_stack_count;false]" ..\r
545                         "button_exit[0,2.5;3,0.8;worldedit_gui_stack_submit;Stack]"\r
546         end,\r
547 })\r
548 \r
549 worldedit.register_gui_handler("worldedit_gui_stack", function(name, fields)\r
550         local cg = {\r
551                 worldedit_gui_stack_axis = gui_axis1,\r
552                 worldedit_gui_stack_count = gui_count1,\r
553         }\r
554         local ret = handle_changes(name, "worldedit_gui_stack", fields, cg)\r
555         if fields.worldedit_gui_stack_submit then\r
556                 copy_changes(name, fields, cg)\r
557                 worldedit.show_page(name, "worldedit_gui_stack")\r
558 \r
559                 minetest.chatcommands["/stack"].func(name, string.format("%s %s", axis_values[gui_axis1[name]], gui_count1[name]))\r
560                 return true\r
561         end\r
562         return ret\r
563 end)\r
564 \r
565 worldedit.register_gui_function("worldedit_gui_stretch", {\r
566         name = "Stretch",\r
567         privs = we_privs("stretch"),\r
568         get_formspec = function(name)\r
569                 local stretchx, stretchy, stretchz = gui_count1[name], gui_count2[name], gui_count3[name]\r
570                 return "size[5,5]" .. worldedit.get_formspec_header("worldedit_gui_stretch") ..\r
571                         string.format("field[0.5,1.5;4,0.8;worldedit_gui_stretch_x;Stretch X;%s]", minetest.formspec_escape(stretchx)) ..\r
572                         string.format("field[0.5,2.5;4,0.8;worldedit_gui_stretch_y;Stretch Y;%s]", minetest.formspec_escape(stretchy)) ..\r
573                         string.format("field[0.5,3.5;4,0.8;worldedit_gui_stretch_z;Stretch Z;%s]", minetest.formspec_escape(stretchz)) ..\r
574                         "field_close_on_enter[worldedit_gui_stretch_x;false]" ..\r
575                         "field_close_on_enter[worldedit_gui_stretch_y;false]" ..\r
576                         "field_close_on_enter[worldedit_gui_stretch_z;false]" ..\r
577                         "button_exit[0,4.5;3,0.8;worldedit_gui_stretch_submit;Stretch]"\r
578         end,\r
579 })\r
580 \r
581 worldedit.register_gui_handler("worldedit_gui_stretch", function(name, fields)\r
582         local cg = {\r
583                 worldedit_gui_stretch_x = gui_count1,\r
584                 worldedit_gui_stretch_y = gui_count2,\r
585                 worldedit_gui_stretch_z = gui_count3,\r
586         }\r
587         local ret = handle_changes(name, "worldedit_gui_stretch", fields, cg)\r
588         if fields.worldedit_gui_stretch_submit then\r
589                 copy_changes(name, fields, cg)\r
590                 worldedit.show_page(name, "worldedit_gui_stretch")\r
591 \r
592                 minetest.chatcommands["/stretch"].func(name, string.format("%s %s %s", gui_count1[name], gui_count2[name], gui_count3[name]))\r
593                 return true\r
594         end\r
595         return ret\r
596 end)\r
597 \r
598 worldedit.register_gui_function("worldedit_gui_transpose", {\r
599         name = "Transpose",\r
600         privs = we_privs("transpose"),\r
601         get_formspec = function(name)\r
602                 local axis1, axis2 = gui_axis1[name], gui_axis2[name]\r
603                 return "size[5.5,3]" .. worldedit.get_formspec_header("worldedit_gui_transpose") ..\r
604                         string.format("dropdown[0,1;2.5;worldedit_gui_transpose_axis1;X axis,Y axis,Z axis,Look direction;%d]", axis1) ..\r
605                         string.format("dropdown[3,1;2.5;worldedit_gui_transpose_axis2;X axis,Y axis,Z axis,Look direction;%d]", axis2) ..\r
606                         "button_exit[0,2.5;3,0.8;worldedit_gui_transpose_submit;Transpose]"\r
607         end,\r
608 })\r
609 \r
610 worldedit.register_gui_handler("worldedit_gui_transpose", function(name, fields)\r
611         local cg = {\r
612                 worldedit_gui_transpose_axis1 = gui_axis1,\r
613                 worldedit_gui_transpose_axis2 = gui_axis2,\r
614         }\r
615         local ret = handle_changes(name, "worldedit_gui_transpose", fields, cg)\r
616         if fields.worldedit_gui_transpose_submit then\r
617                 copy_changes(name, fields, cg)\r
618 \r
619                 minetest.chatcommands["/transpose"].func(name, string.format("%s %s", axis_values[gui_axis1[name]], axis_values[gui_axis2[name]]))\r
620                 return true\r
621         end\r
622         return ret\r
623 end)\r
624 \r
625 worldedit.register_gui_function("worldedit_gui_flip", {\r
626         name = "Flip",\r
627         privs = we_privs("flip"),\r
628         get_formspec = function(name)\r
629                 local axis = gui_axis1[name]\r
630                 return "size[5,3]" .. worldedit.get_formspec_header("worldedit_gui_flip") ..\r
631                         string.format("dropdown[0,1;2.5;worldedit_gui_flip_axis;X axis,Y axis,Z axis,Look direction;%d]", axis) ..\r
632                         "button_exit[0,2.5;3,0.8;worldedit_gui_flip_submit;Flip]"\r
633         end,\r
634 })\r
635 \r
636 worldedit.register_gui_handler("worldedit_gui_flip", function(name, fields)\r
637         local cg = {\r
638                 worldedit_gui_flip_axis = gui_axis1\r
639         }\r
640         local ret = handle_changes(name, "worldedit_gui_flip", fields, cg)\r
641         if fields.worldedit_gui_flip_submit then\r
642                 copy_changes(name, fields, cg)\r
643                 worldedit.show_page(name, "worldedit_gui_flip")\r
644 \r
645                 minetest.chatcommands["/flip"].func(name, axis_values[gui_axis1[name]])\r
646                 return true\r
647         end\r
648         return ret\r
649 end)\r
650 \r
651 worldedit.register_gui_function("worldedit_gui_rotate", {\r
652         name = "Rotate",\r
653         privs = we_privs("rotate"),\r
654         get_formspec = function(name)\r
655                 local axis, angle = gui_axis1[name], gui_angle[name]\r
656                 return "size[5.5,3]" .. worldedit.get_formspec_header("worldedit_gui_rotate") ..\r
657                         string.format("dropdown[0,1;2.5;worldedit_gui_rotate_angle;90 degrees,180 degrees,270 degrees;%s]", angle) ..\r
658                         string.format("dropdown[3,1;2.5;worldedit_gui_rotate_axis;X axis,Y axis,Z axis,Look direction;%d]", axis) ..\r
659                         "button_exit[0,2.5;3,0.8;worldedit_gui_rotate_submit;Rotate]"\r
660         end,\r
661 })\r
662 \r
663 worldedit.register_gui_handler("worldedit_gui_rotate", function(name, fields)\r
664         local cg = {\r
665                 worldedit_gui_rotate_axis = gui_axis1,\r
666                 worldedit_gui_rotate_angle = gui_angle,\r
667         }\r
668         local ret = handle_changes(name, "worldedit_gui_rotate", fields, cg)\r
669         if fields.worldedit_gui_rotate_submit then\r
670                 copy_changes(name, fields, cg)\r
671                 worldedit.show_page(name, "worldedit_gui_rotate")\r
672 \r
673                 minetest.chatcommands["/rotate"].func(name, string.format("%s %s", axis_values[gui_axis1[name]], angle_values[gui_angle[name]]))\r
674                 return true\r
675         end\r
676         return ret\r
677 end)\r
678 \r
679 worldedit.register_gui_function("worldedit_gui_orient", {\r
680         name = "Orient",\r
681         privs = we_privs("orient"),\r
682         get_formspec = function(name)\r
683                 local angle = gui_angle[name]\r
684                 return "size[5,3]" .. worldedit.get_formspec_header("worldedit_gui_orient") ..\r
685                         string.format("dropdown[0,1;2.5;worldedit_gui_orient_angle;90 degrees,180 degrees,270 degrees;%s]", angle) ..\r
686                         "button_exit[0,2.5;3,0.8;worldedit_gui_orient_submit;Orient]"\r
687         end,\r
688 })\r
689 \r
690 worldedit.register_gui_handler("worldedit_gui_orient", function(name, fields)\r
691         local cg = {\r
692                 worldedit_gui_orient_angle = gui_angle,\r
693         }\r
694         local ret = handle_changes(name, "worldedit_gui_orient", fields, cg)\r
695         if fields.worldedit_gui_orient_submit then\r
696                 copy_changes(name, fields, cg)\r
697                 worldedit.show_page(name, "worldedit_gui_orient")\r
698 \r
699                 minetest.chatcommands["/orient"].func(name, tostring(angle_values[gui_angle[name]]))\r
700                 return true\r
701         end\r
702         return ret\r
703 end)\r
704 \r
705 worldedit.register_gui_function("worldedit_gui_fixlight", {\r
706         name = "Fix Lighting",\r
707         privs = we_privs("fixlight"),\r
708         on_select = function(name)\r
709                 minetest.chatcommands["/fixlight"].func(name, "")\r
710         end,\r
711 })\r
712 \r
713 worldedit.register_gui_function("worldedit_gui_hide", {\r
714         name = "Hide Region",\r
715         privs = we_privs("hide"),\r
716         on_select = function(name)\r
717                 minetest.chatcommands["/hide"].func(name, "")\r
718         end,\r
719 })\r
720 \r
721 worldedit.register_gui_function("worldedit_gui_suppress", {\r
722         name = "Suppress Nodes",\r
723         privs = we_privs("suppress"),\r
724         get_formspec = function(name)\r
725                 local node = gui_nodename1[name]\r
726                 local nodename = worldedit.normalize_nodename(node)\r
727                 return "size[6.5,3]" .. worldedit.get_formspec_header("worldedit_gui_suppress") ..\r
728                         string.format("field[0.5,1.5;4,0.8;worldedit_gui_suppress_node;Name;%s]", minetest.formspec_escape(node)) ..\r
729                         "field_close_on_enter[worldedit_gui_suppress_node;false]" ..\r
730                         "button[4,1.18;1.5,0.8;worldedit_gui_suppress_search;Search]" ..\r
731                         formspec_node("5.5,1.1", nodename) ..\r
732                         "button_exit[0,2.5;3,0.8;worldedit_gui_suppress_submit;Suppress Nodes]"\r
733         end,\r
734 })\r
735 \r
736 worldedit.register_gui_handler("worldedit_gui_suppress", function(name, fields)\r
737         local cg = {\r
738                 worldedit_gui_suppress_search = true,\r
739                 worldedit_gui_suppress_node = gui_nodename1,\r
740         }\r
741         local ret = handle_changes(name, "worldedit_gui_suppress", fields, cg)\r
742         if fields.worldedit_gui_suppress_submit then\r
743                 copy_changes(name, fields, cg)\r
744                 worldedit.show_page(name, "worldedit_gui_suppress")\r
745 \r
746                 local n = worldedit.normalize_nodename(gui_nodename1[name])\r
747                 if n then\r
748                         minetest.chatcommands["/suppress"].func(name, n)\r
749                 end\r
750                 return true\r
751         end\r
752         return ret\r
753 end)\r
754 \r
755 worldedit.register_gui_function("worldedit_gui_highlight", {\r
756         name = "Highlight Nodes",\r
757         privs = we_privs("highlight"),\r
758         get_formspec = function(name)\r
759                 local node = gui_nodename1[name]\r
760                 local nodename = worldedit.normalize_nodename(node)\r
761                 return "size[6.5,3]" .. worldedit.get_formspec_header("worldedit_gui_highlight") ..\r
762                         string.format("field[0.5,1.5;4,0.8;worldedit_gui_highlight_node;Name;%s]", minetest.formspec_escape(node)) ..\r
763                         "field_close_on_enter[worldedit_gui_highlight_node;false]" ..\r
764                         "button[4,1.18;1.5,0.8;worldedit_gui_highlight_search;Search]" ..\r
765                         formspec_node("5.5,1.1", nodename) ..\r
766                         "button_exit[0,2.5;3,0.8;worldedit_gui_highlight_submit;Highlight Nodes]"\r
767         end,\r
768 })\r
769 \r
770 worldedit.register_gui_handler("worldedit_gui_highlight", function(name, fields)\r
771         local cg = {\r
772                 worldedit_gui_highlight_search = true,\r
773                 worldedit_gui_highlight_node = gui_nodename1,\r
774         }\r
775         local ret = handle_changes(name, "worldedit_gui_highlight", fields, cg)\r
776         if fields.worldedit_gui_highlight_submit then\r
777                 copy_changes(name, fields, cg)\r
778                 worldedit.show_page(name, "worldedit_gui_highlight")\r
779 \r
780                 local n = worldedit.normalize_nodename(gui_nodename1[name])\r
781                 if n then\r
782                         minetest.chatcommands["/highlight"].func(name, n)\r
783                 end\r
784                 return true\r
785         end\r
786         return ret\r
787 end)\r
788 \r
789 worldedit.register_gui_function("worldedit_gui_restore", {\r
790         name = "Restore Region",\r
791         privs = we_privs("restore"),\r
792         on_select = function(name)\r
793                 minetest.chatcommands["/restore"].func(name, "")\r
794         end,\r
795 })\r
796 \r
797 worldedit.register_gui_function("worldedit_gui_save_load", {\r
798         name = "Save/Load",\r
799         privs = combine_we_privs({"save", "allocate", "load"}),\r
800         get_formspec = function(name)\r
801                 local filename = gui_filename[name]\r
802                 return "size[6,4]" .. worldedit.get_formspec_header("worldedit_gui_save_load") ..\r
803                         string.format("field[0.5,1.5;4,0.8;worldedit_gui_save_filename;Filename;%s]", minetest.formspec_escape(filename)) ..\r
804                         "field_close_on_enter[worldedit_gui_save_filename;false]" ..\r
805                         "button_exit[0,2.5;3,0.8;worldedit_gui_save_load_submit_save;Save]" ..\r
806                         "button_exit[3,2.5;3,0.8;worldedit_gui_save_load_submit_allocate;Allocate]" ..\r
807                         "button_exit[0,3.5;3,0.8;worldedit_gui_save_load_submit_load;Load]"\r
808         end,\r
809 })\r
810 \r
811 worldedit.register_gui_handler("worldedit_gui_save_load", function(name, fields)\r
812         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
813                 gui_filename[name] = tostring(fields.worldedit_gui_save_filename)\r
814                 worldedit.show_page(name, "worldedit_gui_save_load")\r
815 \r
816                 if fields.worldedit_gui_save_load_submit_save then\r
817                         minetest.chatcommands["/save"].func(name, gui_filename[name])\r
818                 elseif fields.worldedit_gui_save_load_submit_allocate then\r
819                         minetest.chatcommands["/allocate"].func(name, gui_filename[name])\r
820                 else --fields.worldedit_gui_save_load_submit_load\r
821                         minetest.chatcommands["/load"].func(name, gui_filename[name])\r
822                 end\r
823                 return true\r
824         end\r
825         return false\r
826 end)\r
827 \r
828 worldedit.register_gui_function("worldedit_gui_cube", {\r
829         name = "Cube",\r
830         privs = combine_we_privs({"hollowcube", "cube"}),\r
831         get_formspec = function(name)\r
832                 local width, height, length = gui_distance1[name], gui_distance2[name], gui_distance3[name]\r
833                 local node = gui_nodename1[name]\r
834                 local nodename = worldedit.normalize_nodename(node)\r
835                 return "size[6.5,4]" .. worldedit.get_formspec_header("worldedit_gui_cube") ..\r
836                         string.format("field[0.5,1.5;4,0.8;worldedit_gui_cube_node;Name;%s]", minetest.formspec_escape(node)) ..\r
837                         "field_close_on_enter[worldedit_gui_cube_node;false]" ..\r
838                         "button[4,1.18;1.5,0.8;worldedit_gui_cube_search;Search]" ..\r
839                         formspec_node("5.5,1.1", nodename) ..\r
840                         string.format("field[0.5,2.5;1,0.8;worldedit_gui_cube_width;Width;%s]", minetest.formspec_escape(width)) ..\r
841                         string.format("field[1.5,2.5;1,0.8;worldedit_gui_cube_height;Height;%s]", minetest.formspec_escape(height)) ..\r
842                         string.format("field[2.5,2.5;1,0.8;worldedit_gui_cube_length;Length;%s]", minetest.formspec_escape(length)) ..\r
843                         "field_close_on_enter[worldedit_gui_cube_width;false]" ..\r
844                         "field_close_on_enter[worldedit_gui_cube_height;false]" ..\r
845                         "field_close_on_enter[worldedit_gui_cube_length;false]" ..\r
846                         "button_exit[0,3.5;3,0.8;worldedit_gui_cube_submit_hollow;Hollow Cuboid]" ..\r
847                         "button_exit[3.5,3.5;3,0.8;worldedit_gui_cube_submit_solid;Solid Cuboid]"\r
848         end,\r
849 })\r
850 \r
851 worldedit.register_gui_handler("worldedit_gui_cube", function(name, fields)\r
852         local cg = {\r
853                 worldedit_gui_cube_search = true,\r
854                 worldedit_gui_cube_node = gui_nodename1,\r
855                 worldedit_gui_cube_width = gui_distance1,\r
856                 worldedit_gui_cube_height = gui_distance2,\r
857                 worldedit_gui_cube_length = gui_distance3,\r
858         }\r
859         local ret = handle_changes(name, "worldedit_gui_cube", fields, cg)\r
860         if fields.worldedit_gui_cube_submit_hollow or fields.worldedit_gui_cube_submit_solid then\r
861                 copy_changes(name, fields, cg)\r
862                 worldedit.show_page(name, "worldedit_gui_cube")\r
863 \r
864                 local submit = "hollowcube"\r
865                 if fields.worldedit_gui_cube_submit_solid then\r
866                         submit = "cube"\r
867                 end\r
868                 local n = worldedit.normalize_nodename(gui_nodename1[name])\r
869                 if n then\r
870                         local args = string.format("%s %s %s %s", gui_distance1[name], gui_distance2[name], gui_distance3[name], n)\r
871                         minetest.chatcommands["/"..submit].func(name, args)\r
872                 end\r
873                 return true\r
874         end\r
875         return ret\r
876 end)\r
877 \r
878 worldedit.register_gui_function("worldedit_gui_clearobjects", {\r
879         name = "Clear Objects",\r
880         privs = we_privs("clearobjects"),\r
881         on_select = function(name)\r
882                 minetest.chatcommands["/clearobjects"].func(name, "")\r
883         end,\r
884 })\r