diff --git a/mods/sfinv/api.lua b/mods/sfinv/api.lua index fdb652b..b4bcfa3 100644 --- a/mods/sfinv/api.lua +++ b/mods/sfinv/api.lua @@ -139,6 +139,11 @@ function sfinv.set_page(player, pagename) sfinv.set_player_inventory_formspec(player, context) end +function sfinv.get_page(player) + local context = sfinv.contexts[player:get_player_name()] + return context and context.page or sfinv.get_homepage_name(player) +end + minetest.register_on_joinplayer(function(player) if sfinv.enabled then sfinv.set_player_inventory_formspec(player) diff --git a/mods/sfinv/depends.txt b/mods/sfinv/depends.txt index 4ad96d5..836358d 100644 --- a/mods/sfinv/depends.txt +++ b/mods/sfinv/depends.txt @@ -1 +1,2 @@ default +sethome? \ No newline at end of file diff --git a/mods/sfinv/init.lua b/mods/sfinv/init.lua index f030222..ac8e571 100644 --- a/mods/sfinv/init.lua +++ b/mods/sfinv/init.lua @@ -20,3 +20,59 @@ sfinv.register_page("sfinv:crafting", { ]], true) end }) + +local home = minetest.get_modpath("sethome") or false +local sfinvhome = minetest.get_modpath("sfinv_home") or false + +if home and not sfinvhome then + local get_formspec = function(name) + + local formspec = "size[6,2]" + .. "button_exit[2,2.5;4,1;home_gui_go;" .. "-> Home" .. "]" + .. "button_exit[2,4.5;4,1;home_gui_set;" .. "!! Home <-" .. "]" + -- .. "button_exit[2,6.5;4,1;home_gui_spawn;" .. S("Spawn") .. "]" + + local home = sethome.get(name) + + if home then + formspec = formspec + .. "label[2,1.5;" .. "Home:" .. " " + .. minetest.pos_to_string(vector.round(home)) .. "]" + else + formspec = formspec + .. "label[2,1.5;" .. "Invalid: no home!" .. "]" + end + + return formspec + end + + sfinv.register_page("sfinv:home", { + title = "Home", + get = function(self, player, context) + local name = player:get_player_name() + return sfinv.make_formspec(player, context, get_formspec(name)) + end, + is_in_nav = function(self, player, context) + local name = player:get_player_name() + return minetest.get_player_privs(name).home + end, + on_enter = function(self, player, context) end, + on_leave = function(self, player, context) end, + on_player_receive_fields = function(self, player, context, fields) + local name = player:get_player_name() + if not minetest.get_player_privs(name).home then + return + end + if fields.home_gui_set then + sethome.set(name, player:get_pos()) + sfinv.set_player_inventory_formspec(player) + elseif fields.home_gui_go then + sethome.go(name) + -- elseif fields.home_gui_spawn then + -- player:set_pos(statspawn) + end + end + }) + +end + diff --git a/mods/sfinv/mod.conf b/mods/sfinv/mod.conf new file mode 100644 index 0000000..356c108 --- /dev/null +++ b/mods/sfinv/mod.conf @@ -0,0 +1,4 @@ +name = sfinv +depends = default +optional_depends = sethome +description = Minetest Game mod: sfinv