From 3d08b568ad1da1e3259a66cb91fd1039781c75cb Mon Sep 17 00:00:00 2001 From: Vanessa Ezekowitz Date: Tue, 26 Sep 2017 00:11:57 -0400 Subject: update castles modpack, boost_cart, homedecor, currency, farming redo, framed glass, gloopblocks, mesecons, moreblocks, pipeworks, signs_lib, technic, unified mesecons, and worldedit created a new tag for this release (this will be standard procedure from now on) --- worldedit_gui/functionality.lua | 82 +++++++++++------- worldedit_gui/init.lua | 94 ++++----------------- .../textures/inventory_plus_worldedit_gui.png | Bin 25175 -> 21724 bytes 3 files changed, 69 insertions(+), 107 deletions(-) (limited to 'worldedit_gui') diff --git a/worldedit_gui/functionality.lua b/worldedit_gui/functionality.lua index 17a8a79..912fd59 100644 --- a/worldedit_gui/functionality.lua +++ b/worldedit_gui/functionality.lua @@ -1,6 +1,6 @@ --saved state for each player -local gui_nodename1 = {} --mapping of player names to node names (arbitrary strings may also appear as values) -local gui_nodename2 = {} --mapping of player names to node names (arbitrary strings may also appear as values) +local gui_nodename1 = {} --mapping of player names to node names +local gui_nodename2 = {} --mapping of player names to node names 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) 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) local gui_distance1 = {} --mapping of player names to a distance (arbitrary strings may also appear as values) @@ -10,9 +10,7 @@ local gui_count1 = {} --mapping of player names to a quantity (arbitrary strings local gui_count2 = {} --mapping of player names to a quantity (arbitrary strings may also appear as values) local gui_count3 = {} --mapping of player names to a quantity (arbitrary strings may also appear as values) local gui_angle = {} --mapping of player names to an angle (one of 90, 180, 270, representing the angle in degrees clockwise) -local gui_filename = {} --mapping of player names to file names (arbitrary strings may also appear as values) -local gui_formspec = {} --mapping of player names to formspecs -local gui_code = {} --mapping of player names to formspecs +local gui_filename = {} --mapping of player names to file names --set default values setmetatable(gui_nodename1, {__index = function() return "Cobblestone" end}) @@ -27,8 +25,6 @@ setmetatable(gui_count2, {__index = function() return "6" end}) setmetatable(gui_count3, {__index = function() return "4" end}) setmetatable(gui_angle, {__index = function() return 90 end}) setmetatable(gui_filename, {__index = function() return "building" end}) -setmetatable(gui_formspec, {__index = function() return "size[5,5]\nlabel[0,0;Hello, world!]" end}) -setmetatable(gui_code, {__index = function() return "minetest.chat_send_player(\"singleplayer\", \"Hello, world!\")" end}) local axis_indices = {["X axis"]=1, ["Y axis"]=2, ["Z axis"]=3, ["Look direction"]=4} local axis_values = {"x", "y", "z", "?"} @@ -292,17 +288,21 @@ worldedit.register_gui_function("worldedit_gui_cylinder", { name = "Cylinder", privs = combine_we_privs({"hollowcylinder", "cylinder"}), get_formspec = function(name) - local node, axis, length, radius = gui_nodename1[name], gui_axis1[name], gui_distance1[name], gui_distance2[name] + local node, axis, length = gui_nodename1[name], gui_axis1[name], gui_distance1[name] + local radius1, radius2 = gui_distance2[name], gui_distance3[name] local nodename = worldedit.normalize_nodename(node) - return "size[6.5,5]" .. worldedit.get_formspec_header("worldedit_gui_cylinder") .. + return "size[6.5,6]" .. worldedit.get_formspec_header("worldedit_gui_cylinder") .. string.format("field[0.5,1.5;4,0.8;worldedit_gui_cylinder_node;Name;%s]", minetest.formspec_escape(node)) .. "button[4,1.18;1.5,0.8;worldedit_gui_cylinder_search;Search]" .. formspec_node("5.5,1.1", nodename) .. string.format("field[0.5,2.5;4,0.8;worldedit_gui_cylinder_length;Length;%s]", minetest.formspec_escape(length)) .. string.format("dropdown[4,2.18;2.5;worldedit_gui_cylinder_axis;X axis,Y axis,Z axis,Look direction;%d]", axis) .. - string.format("field[0.5,3.5;4,0.8;worldedit_gui_cylinder_radius;Radius;%s]", minetest.formspec_escape(radius)) .. - "button_exit[0,4.5;3,0.8;worldedit_gui_cylinder_submit_hollow;Hollow Cylinder]" .. - "button_exit[3.5,4.5;3,0.8;worldedit_gui_cylinder_submit_solid;Solid Cylinder]" + string.format("field[0.5,3.5;2,0.8;worldedit_gui_cylinder_radius1;Base Radius;%s]", minetest.formspec_escape(radius1)) .. + string.format("field[2.5,3.5;2,0.8;worldedit_gui_cylinder_radius2;Top Radius;%s]", minetest.formspec_escape(radius2)) .. + "label[0.25,4;Equal base and top radius creates a cylinder,\n".. + "zero top radius creates a cone.\nConsult documentation for more information.]".. + "button_exit[0,5.5;3,0.8;worldedit_gui_cylinder_submit_hollow;Hollow Cylinder]" .. + "button_exit[3.5,5.5;3,0.8;worldedit_gui_cylinder_submit_solid;Solid Cylinder]" end, }) @@ -312,7 +312,8 @@ worldedit.register_gui_handler("worldedit_gui_cylinder", function(name, fields) gui_nodename1[name] = tostring(fields.worldedit_gui_cylinder_node) gui_axis1[name] = axis_indices[fields.worldedit_gui_cylinder_axis] gui_distance1[name] = tostring(fields.worldedit_gui_cylinder_length) - gui_distance2[name] = tostring(fields.worldedit_gui_cylinder_radius) + gui_distance2[name] = tostring(fields.worldedit_gui_cylinder_radius1) + gui_distance3[name] = tostring(fields.worldedit_gui_cylinder_radius2) worldedit.show_page(name, "worldedit_gui_cylinder") local submit = nil @@ -324,7 +325,8 @@ worldedit.register_gui_handler("worldedit_gui_cylinder", function(name, fields) if submit then local n = worldedit.normalize_nodename(gui_nodename1[name]) if n then - minetest.chatcommands["/"..submit].func(name, string.format("%s %s %s %s", axis_values[gui_axis1[name]], gui_distance1[name], gui_distance2[name], n)) + local args = string.format("%s %s %s %s %s", axis_values[gui_axis1[name]], gui_distance1[name], gui_distance2[name], gui_distance3[name], n) + minetest.chatcommands["/"..submit].func(name, args) end end return true @@ -733,26 +735,46 @@ worldedit.register_gui_handler("worldedit_gui_save_load", function(name, fields) return false end) -worldedit.register_gui_function("worldedit_gui_lua", { - name = "Run Lua", - privs = we_privs("lua"), +worldedit.register_gui_function("worldedit_gui_cube", { + name = "Cuboid", -- technically the command is misnamed, I know... + privs = combine_we_privs({"hollowcube", "cube"}), get_formspec = function(name) - local code = gui_code[name] - return "size[8,6.5]" .. worldedit.get_formspec_header("worldedit_gui_lua") .. - string.format("textarea[0.5,1;7.5,5.5;worldedit_gui_lua_code;Lua Code;%s]", minetest.formspec_escape(code)) .. - "button_exit[0,6;3,0.8;worldedit_gui_lua_run;Run Lua]" .. - "button_exit[5,6;3,0.8;worldedit_gui_lua_transform;Lua Transform]" + local width, height, length = gui_distance1[name], gui_distance2[name], gui_distance3[name] + local node = gui_nodename1[name] + local nodename = worldedit.normalize_nodename(node) + return "size[6.5,4]" .. worldedit.get_formspec_header("worldedit_gui_cube") .. + string.format("field[0.5,1.5;4,0.8;worldedit_gui_cube_node;Name;%s]", minetest.formspec_escape(node)) .. + "button[4,1.18;1.5,0.8;worldedit_gui_cube_search;Search]" .. + formspec_node("5.5,1.1", nodename) .. + string.format("field[0.5,2.5;1,0.8;worldedit_gui_cube_width;Width;%s]", minetest.formspec_escape(width)) .. + string.format("field[1.5,2.5;1,0.8;worldedit_gui_cube_height;Height;%s]", minetest.formspec_escape(height)) .. + string.format("field[2.5,2.5;1,0.8;worldedit_gui_cube_length;Length;%s]", minetest.formspec_escape(length)) .. + "button_exit[0,3.5;3,0.8;worldedit_gui_cube_submit_hollow;Hollow Cuboid]" .. + "button_exit[3.5,3.5;3,0.8;worldedit_gui_cube_submit_solid;Solid Cuboid]" end, }) -worldedit.register_gui_handler("worldedit_gui_lua", function(name, fields) - if fields.worldedit_gui_lua_run or fields.worldedit_gui_lua_transform then - gui_code[name] = fields.worldedit_gui_lua_code - worldedit.show_page(name, "worldedit_gui_lua") - if fields.worldedit_gui_lua_run then - minetest.chatcommands["/lua"].func(name, gui_code[name]) - else --fields.worldedit_gui_lua_transform - minetest.chatcommands["/luatransform"].func(name, gui_code[name]) +worldedit.register_gui_handler("worldedit_gui_cube", function(name, fields) + if fields.worldedit_gui_cube_search + or fields.worldedit_gui_cube_submit_hollow or fields.worldedit_gui_cube_submit_solid then + gui_nodename1[name] = tostring(fields.worldedit_gui_cube_node) + gui_distance1[name] = tostring(fields.worldedit_gui_cube_width) + gui_distance2[name] = tostring(fields.worldedit_gui_cube_height) + gui_distance3[name] = tostring(fields.worldedit_gui_cube_length) + worldedit.show_page(name, "worldedit_gui_cube") + + local submit = nil + if fields.worldedit_gui_cube_submit_hollow then + submit = "hollowcube" + elseif fields.worldedit_gui_cube_submit_solid then + submit = "cube" + end + if submit then + local n = worldedit.normalize_nodename(gui_nodename1[name]) + if n then + local args = string.format("%s %s %s %s", gui_distance1[name], gui_distance2[name], gui_distance3[name], n) + minetest.chatcommands["/"..submit].func(name, args) + end end return true end diff --git a/worldedit_gui/init.lua b/worldedit_gui/init.lua index dafd7c2..137a057 100644 --- a/worldedit_gui/init.lua +++ b/worldedit_gui/init.lua @@ -145,13 +145,21 @@ elseif rawget(_G, "sfinv") then --sfinv installed (part of minetest_game since 0 end }) + --compatibility with pre-0.4.16 sfinv + local set_page = sfinv.set_page or function(player, name) + --assumptions: src pg has no leave callback, dst pg has no enter callback + local ctx = {page=name} + sfinv.contexts[player:get_player_name()] = ctx + sfinv.set_player_inventory_formspec(player, ctx) + end + --show the form when the button is pressed and hide it when done minetest.register_on_player_receive_fields(function(player, formname, fields) if fields.worldedit_gui then --main page worldedit.show_page(player:get_player_name(), "worldedit_gui") return true elseif fields.worldedit_gui_exit then --return to original page - sfinv.set_page(player, "sfinv:crafting") + set_page(player, "sfinv:crafting") return true end return false @@ -163,82 +171,14 @@ elseif rawget(_G, "sfinv") then --sfinv installed (part of minetest_game since 0 player:set_inventory_formspec(get_formspec(name, page)) end end -else --fallback button - -- FIXME: this is a huge clusterfuck and the back button is broken - local player_formspecs = {} - - local update_main_formspec = function(name) - local formspec = player_formspecs[name] - if not formspec then - return - end - local player = minetest.get_player_by_name(name) - if not player then --this is in case the player signs off while the media is loading - return - end - if (minetest.check_player_privs(name, {creative=true}) or - minetest.setting_getbool("creative_mode")) and - creative then --creative is active, add button to modified formspec - local creative_formspec = player:get_inventory_formspec() - local tab_id = tonumber(creative_formspec:match("tabheader%[.-;(%d+)%;")) - - if tab_id == 1 then - formspec = creative_formspec .. - "image_button[0,1;1,1;inventory_plus_worldedit_gui.png;worldedit_gui;]" - elseif not tab_id then - formspec = creative_formspec .. - "image_button[6,0;1,1;inventory_plus_worldedit_gui.png;worldedit_gui;]" - else - return - end - else - formspec = formspec .. "image_button[0,0;1,1;inventory_plus_worldedit_gui.png;worldedit_gui;]" - end - player:set_inventory_formspec(formspec) - end - - minetest.register_on_joinplayer(function(player) - local name = player:get_player_name() - minetest.after(1, function() - if minetest.get_player_by_name(name) then --ensure the player is still signed in - player_formspecs[name] = player:get_inventory_formspec() - minetest.after(0.01, function() - update_main_formspec(name) - end) - end - end) - end) - - minetest.register_on_leaveplayer(function(player) - player_formspecs[player:get_player_name()] = nil - end) - - local gui_player_formspecs = {} - minetest.register_on_player_receive_fields(function(player, formname, fields) - local name = player:get_player_name() - if fields.worldedit_gui then --main page - gui_player_formspecs[name] = player:get_inventory_formspec() - worldedit.show_page(name, "worldedit_gui") - return true - elseif fields.worldedit_gui_exit then --return to original page - if gui_player_formspecs[name] then - player:set_inventory_formspec(gui_player_formspecs[name]) - end - return true - else --deal with creative_inventory setting the formspec on every single message - minetest.after(0.01,function() - update_main_formspec(name) - end) - return false --continue processing in creative inventory - end - end) - - worldedit.show_page = function(name, page) - local player = minetest.get_player_by_name(name) - if player then - player:set_inventory_formspec(get_formspec(name, page)) - end - end +else + error( + "worldedit_gui requires a supported \"gui management\" mod to be installed\n".. + "To use the GUI you need to either\n".. + "* Use minetest_game (at least 0.4.15) or a subgame with compatible sfinv\n".. + "* Install Unified Inventory or Inventory++\n".. + "If you do not want to use worldedit_gui, disable it by editing world.mt or from the Main Menu" + ) end worldedit.register_gui_function("worldedit_gui", { diff --git a/worldedit_gui/textures/inventory_plus_worldedit_gui.png b/worldedit_gui/textures/inventory_plus_worldedit_gui.png index fbc1abc..ff9404b 100644 Binary files a/worldedit_gui/textures/inventory_plus_worldedit_gui.png and b/worldedit_gui/textures/inventory_plus_worldedit_gui.png differ -- cgit v1.2.3