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