]> git.lizzy.rs Git - worldedit.git/commitdiff
Implement copy/move in the WorldEdit GUI.
authorUberi <azhang9@gmail.com>
Sun, 15 Dec 2013 21:56:37 +0000 (16:56 -0500)
committerUberi <azhang9@gmail.com>
Sun, 15 Dec 2013 21:56:37 +0000 (16:56 -0500)
worldedit_gui/functionality.lua

index 928fa730d4df7528d75eb4a7d8e3febfb58352d3..29405eac2cd92e676cb1c7c74c3538addde67d54 100644 (file)
@@ -1,10 +1,13 @@
 --saved state for each player\r
-local gui_nodename1 = {}\r
-local gui_nodename2 = {}\r
-local gui_radius = {}\r
-local gui_axis = {}\r
-local gui_length = {}\r
-local gui_formspec = {}\r
+local gui_nodename1 = {} --mapping of player names to node names (arbitrary strings may also appear as values)\r
+local gui_nodename2 = {} --mapping of player names to node names (arbitrary strings may also appear as values)\r
+local gui_radius = {} --mapping of player names to radii (arbitrary strings may also appear as values)\r
+local gui_axis = {} --mapping of player names to axes (one of 1, 2, 3, or 4, representing the axes in the `axis_indices` table below)\r
+local gui_length = {} --mapping of player names to lengths (arbitrary strings may also appear as values)\r
+local gui_formspec = {} --mapping of player names to formspecs (arbitrary strings may also appear as values)\r
+\r
+local axis_indices = {["X axis"]=1, ["Y axis"]=2, ["Z axis"]=3, ["Look direction"]=4}\r
+local axis_values = {"x", "y", "z", "?"}\r
 \r
 local register_gui_chatcommand = function(identifier, name, command, callback)\r
        callback = callback or function(name, command) command(name, "") end\r
@@ -222,9 +225,6 @@ worldedit.register_gui_function("worldedit_gui_cylinder", {
        end,\r
 })\r
 \r
-local axis_indices = {["X axis"]=1, ["Y axis"]=2, ["Z axis"]=3, ["Look direction"]=4}\r
-local axis_values = {"x", "y", "z", "?"}\r
-\r
 worldedit.register_gui_handler("worldedit_gui_cylinder", function(name, fields)\r
        if fields.worldedit_gui_cylinder_search then\r
                gui_nodename1[name] = fields.worldedit_gui_cylinder_node\r
@@ -246,6 +246,34 @@ worldedit.register_gui_handler("worldedit_gui_cylinder", function(name, fields)
        return false\r
 end)\r
 \r
+worldedit.register_gui_function("worldedit_gui_copy_move", {\r
+       name = "Copy/Move", privs = minetest.chatcommands["/move"].privs,\r
+       get_formspec = function(name)\r
+               local axis = gui_axis[name] or 4\r
+               local amount = gui_length[name] or "10"\r
+               return "size[6.5,3]" .. worldedit.get_formspec_header("worldedit_gui_copy_move") ..\r
+                       string.format("field[0.5,1.5;4,0.8;worldedit_gui_copy_move_amount;Amount;%s]", minetest.formspec_escape(amount)) ..\r
+                       string.format("dropdown[4,1.18;2.5;worldedit_gui_copy_move_axis;X axis,Y axis,Z axis,Look direction;%d]", axis) ..\r
+                       "button_exit[0,2.5;3,0.8;worldedit_gui_copy_move_copy;Copy Region]" ..\r
+                       "button_exit[3.5,2.5;3,0.8;worldedit_gui_copy_move_move;Move Region]"\r
+       end,\r
+})\r
+\r
+worldedit.register_gui_handler("worldedit_gui_copy_move", function(name, fields)\r
+       if fields.worldedit_gui_copy_move_copy or fields.worldedit_gui_copy_move_move then\r
+               gui_axis[name] = axis_indices[fields.worldedit_gui_cylinder_axis] or 4\r
+               gui_length[name] = tostring(fields.worldedit_gui_copy_move_amount)\r
+               worldedit.show_page(name, "worldedit_gui_copy_move")\r
+               if fields.worldedit_gui_copy_move_copy then\r
+                       minetest.chatcommands["/copy"].func(name, string.format("%s %s", axis_values[gui_axis[name]], gui_length[name]))\r
+               else --fields.worldedit_gui_copy_move_move\r
+                       minetest.chatcommands["/move"].func(name, string.format("%s %s", axis_values[gui_axis[name]], gui_length[name]))\r
+               end\r
+               return true\r
+       end\r
+       return false\r
+end)\r
+\r
 worldedit.register_gui_function("worldedit_gui_formspec_tester", {\r
        name = "Formspec Tester",\r
        get_formspec = function(name)\r