summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2017-03-11 12:47:30 +0100
committersfan5 <sfan5@live.de>2017-03-11 12:47:30 +0100
commit610cd9981dbb2649308172936a1c5f626581a4c5 (patch)
tree5856490524f44356340123263a1cd34340102c48
parentc0f3bb695865c46738bee71efafd80851d83f81e (diff)
Use sfinv if possible, fixes #124 with recent minetest versions
-rw-r--r--worldedit_gui/depends.txt3
-rw-r--r--worldedit_gui/init.lua30
2 files changed, 32 insertions, 1 deletions
diff --git a/worldedit_gui/depends.txt b/worldedit_gui/depends.txt
index d603ac9..2558dce 100644
--- a/worldedit_gui/depends.txt
+++ b/worldedit_gui/depends.txt
@@ -2,4 +2,5 @@ worldedit
worldedit_commands
unified_inventory?
inventory_plus?
-creative? \ No newline at end of file
+sfinv?
+creative?
diff --git a/worldedit_gui/init.lua b/worldedit_gui/init.lua
index 57fd9a8..0a770c6 100644
--- a/worldedit_gui/init.lua
+++ b/worldedit_gui/init.lua
@@ -131,7 +131,37 @@ elseif rawget(_G, "inventory_plus") then --inventory++ installed
inventory_plus.set_inventory_formspec(player, get_formspec(name, page))
end
end
+elseif rawget(_G, "sfinv") then --sfinv installed (part of minetest_game since 0.4.15)
+ assert(sfinv.enabled)
+ local orig_get = sfinv.pages["sfinv:crafting"].get
+ sfinv.override_page("sfinv:crafting", {
+ get = function(self, player, context)
+ local can_worldedit = minetest.check_player_privs(player, {worldedit=true})
+ local fs = orig_get(self, player, context)
+ return fs .. (can_worldedit and "image_button[0,0;1,1;inventory_plus_worldedit_gui.png;worldedit_gui;]" or "")
+ 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")
+ return true
+ end
+ return false
+ 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 --fallback button
+ -- FIXME: this is a huge clusterfuck and the back button is broken
local player_formspecs = {}
local update_main_formspec = function(name)