]> git.lizzy.rs Git - worldedit.git/commitdiff
Add param2 button to WorldEdit GUI
authorNathan Salapat <rendertracer@gmail.com>
Fri, 23 Jul 2021 21:34:13 +0000 (16:34 -0500)
committerGitHub <noreply@github.com>
Fri, 23 Jul 2021 21:34:13 +0000 (23:34 +0200)
worldedit_gui/functionality.lua

index 2efbf9aead8e3fdf547d02d81515499ddab9bc8e..6279d8a8c5bbe0d5e0966e6590b6f7928fdb3039 100644 (file)
@@ -11,6 +11,7 @@ local gui_count2 = {} --mapping of player names to a quantity (arbitrary strings
 local gui_count3 = {} --mapping of player names to a quantity (arbitrary strings may also appear as values)\r
 local gui_angle = {} --mapping of player names to an angle (one of 90, 180, 270, representing the angle in degrees clockwise)\r
 local gui_filename = {} --mapping of player names to file names\r
+local gui_param2 = {} --mapping of player names to param2 values\r
 \r
 --set default values\r
 setmetatable(gui_nodename1, {__index = function() return "Cobblestone" end})\r
@@ -25,6 +26,7 @@ setmetatable(gui_count2,     {__index = function() return "6" end})
 setmetatable(gui_count3,     {__index = function() return "4" end})\r
 setmetatable(gui_angle,     {__index = function() return 90 end})\r
 setmetatable(gui_filename,  {__index = function() return "building" end})\r
+setmetatable(gui_param2,    {__index = function() return "0" end})\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
@@ -904,3 +906,31 @@ worldedit.register_gui_function("worldedit_gui_clearobjects", {
                execute_worldedit_command("clearobjects", name, "")\r
        end,\r
 })\r
+\r
+worldedit.register_gui_function("worldedit_gui_param2", {\r
+       name = "Set Param2",\r
+       privs = we_privs("param2"),\r
+       get_formspec = function(name)\r
+               local value = gui_param2[name] or "0"\r
+               return "size[6.5,3]" .. worldedit.get_formspec_header("worldedit_gui_param2") ..\r
+                       "textarea[0.5,1;5,2;;;Some values may break the node!]"..\r
+                       string.format("field[0.5,2.5;2,0.8;worldedit_gui_param2_value;New Param2;%s]", minetest.formspec_escape(value)) ..\r
+                       "field_close_on_enter[worldedit_gui_param2_value;false]" ..\r
+                       "button_exit[3.5,2.5;3,0.8;worldedit_gui_param2_submit;Set Param2]"\r
+       end,\r
+})\r
+\r
+worldedit.register_gui_handler("worldedit_gui_param2", function(name, fields)\r
+       local cg = {\r
+               worldedit_gui_param2_value = gui_param2,\r
+       }\r
+       local ret = handle_changes(name, "worldedit_gui_param2", fields, cg)\r
+       if fields.worldedit_gui_param2_submit then\r
+               copy_changes(name, fields, cg)\r
+               worldedit.show_page(name, "worldedit_gui_param2")\r
+\r
+               execute_worldedit_command("param2", name, gui_param2[name])\r
+               return true\r
+       end\r
+       return ret\r
+end)\r