summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Weber <web.alexander@web.de>2018-02-14 01:39:05 +0100
committersofar <sofar+github@foo-projects.org>2018-02-19 11:18:18 -0800
commit4704e17dd2a833ebdd8e8f7081e11b05b6cdae4a (patch)
treee9f166d5be0c97bbd433e754e42eb7a6e7e3b049
parent23afa1d1aa49d0e5855350772162000b53438357 (diff)
added /skinsdb ui
-rw-r--r--chatcommands.lua44
-rw-r--r--unified_inventory_page.lua4
2 files changed, 43 insertions, 5 deletions
diff --git a/chatcommands.lua b/chatcommands.lua
index 0be274b..22fe044 100644
--- a/chatcommands.lua
+++ b/chatcommands.lua
@@ -1,5 +1,16 @@
+local function show_selection_formspec(player, context)
+ skins.rebuild_formspec_context(player, context)
+ local name = player:get_player_name()
+ local skin = skins.get_player_skin(player)
+ local formspec = "size[8,8]"..skins.get_skin_info_formspec(skin)
+ formspec = formspec..skins.get_skin_selection_formspec(context, 3.5)
+ player:set_attribute('skinsdb_context', minetest.serialize(context))
+ minetest.show_formspec(name, 'skinsdb_show_ui', formspec)
+end
+
+
minetest.register_chatcommand("skinsdb", {
- params = "[set] <skin key> | show [<skin key>] | list | list private | list public",
+ params = "[set] <skin key> | show [<skin key>] | list | list private | list public | [ui]",
description = "Set, show or list player's skin",
func = function(name, param)
local player = minetest.get_player_by_name(name)
@@ -12,7 +23,7 @@ minetest.register_chatcommand("skinsdb", {
for word in param:gmatch("([^ ]+)") do
if not command then
-- first word
- if word == 'set' or word == 'list' or word == 'show' then
+ if word == 'set' or word == 'list' or word == 'show' or word == 'ui' then
command = word
elseif skins.get(word) then
command = 'set'
@@ -28,7 +39,7 @@ minetest.register_chatcommand("skinsdb", {
end
end
if not command then
- return false, "see /help skinsdb for supported parameters"
+ command = "ui"
end
if command == "set" then
@@ -59,6 +70,7 @@ minetest.register_chatcommand("skinsdb", {
minetest.chat_send_player(name, info)
end
elseif command == "show" then
+ local skin
if parameter then
skin = skins.get(parameter)
else
@@ -69,8 +81,30 @@ minetest.register_chatcommand("skinsdb", {
end
local formspec = "size[8,3]"..skins.get_skin_info_formspec(skin)
minetest.show_formspec(name, 'skinsdb_show_skin', formspec)
+ elseif command == "ui" then
+ local context = minetest.deserialize(player:get_attribute('skinsdb_context')) or {}
+ show_selection_formspec(player, context)
end
-
-
end,
})
+
+
+minetest.register_on_player_receive_fields(function(player, formname, fields)
+ if formname ~= "skinsdb_show_ui" then
+ return
+ end
+
+ local context = minetest.deserialize(player:get_attribute('skinsdb_context'))
+ if not context then
+ return
+ end
+
+ local action = skins.on_skin_selection_receive_fields(player, context, fields)
+ if action == 'set' then
+ player:set_attribute('skinsdb_context',"")
+ minetest.close_formspec(player:get_player_name(), formname)
+ elseif action == 'page' then
+ player:set_attribute('skinsdb_context', minetest.serialize(context))
+ show_selection_formspec(player, context)
+ end
+end)
diff --git a/unified_inventory_page.lua b/unified_inventory_page.lua
index 332e3cb..91f4e57 100644
--- a/unified_inventory_page.lua
+++ b/unified_inventory_page.lua
@@ -38,6 +38,10 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
return
end
+ if formname ~= "" then
+ return
+ end
+
local context -- read context only if skins related action
for field, _ in pairs(fields) do
if field:sub(1,5) == "skins" then