2018-02-13 22:31:44 +01:00
|
|
|
local S = skins.S
|
2017-02-09 23:06:25 +01:00
|
|
|
|
|
|
|
unified_inventory.register_page("skins", {
|
|
|
|
get_formspec = function(player)
|
2017-06-15 15:10:59 +02:00
|
|
|
local skin = skins.get_player_skin(player)
|
2018-02-13 22:31:44 +01:00
|
|
|
local formspec = "background[0.06,0.99;7.92,7.52;ui_misc_form.png]"..skins.get_skin_info_formspec(skin)..
|
2018-02-14 00:28:09 +01:00
|
|
|
"button[.75,3;6.5,.5;skins_page;"..S("Change").."]"
|
2017-02-09 23:06:25 +01:00
|
|
|
return {formspec=formspec}
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
unified_inventory.register_button("skins", {
|
|
|
|
type = "image",
|
|
|
|
image = "skins_button.png",
|
|
|
|
})
|
|
|
|
|
2018-02-14 00:28:09 +01:00
|
|
|
local function get_formspec(player)
|
|
|
|
-- unified inventory is stateless, but skins pager needs some context usage to be more flexible
|
|
|
|
local context = minetest.deserialize(player:get_attribute('skinsdb_unified_inventory_context')) or {}
|
|
|
|
context = skins.rebuild_formspec_context(player, context)
|
|
|
|
local formspec = "background[0.06,0.99;7.92,7.52;ui_misc_form.png]"..
|
|
|
|
skins.get_skin_selection_formspec(context, -0.2)
|
|
|
|
player:set_attribute('skinsdb_unified_inventory_context', minetest.serialize(context))
|
|
|
|
return formspec
|
2017-06-15 17:18:51 +02:00
|
|
|
end
|
2017-06-15 15:10:59 +02:00
|
|
|
|
2018-02-14 00:28:09 +01:00
|
|
|
unified_inventory.register_page("skins_page", {
|
|
|
|
get_formspec = function(player)
|
|
|
|
return {formspec=get_formspec(player)}
|
2017-02-09 23:06:25 +01:00
|
|
|
end
|
2018-02-14 00:28:09 +01:00
|
|
|
})
|
2017-06-15 17:18:51 +02:00
|
|
|
|
2017-02-09 23:06:25 +01:00
|
|
|
-- click button handlers
|
|
|
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|
|
|
if fields.skins then
|
2018-02-14 00:28:09 +01:00
|
|
|
player:set_attribute('skinsdb_unified_inventory_context',"") --reset context
|
2017-02-09 23:06:25 +01:00
|
|
|
unified_inventory.set_inventory_formspec(player, "craft")
|
|
|
|
return
|
|
|
|
end
|
2018-02-14 00:28:09 +01:00
|
|
|
|
2018-02-14 01:39:05 +01:00
|
|
|
if formname ~= "" then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2018-02-14 00:28:09 +01:00
|
|
|
local context -- read context only if skins related action
|
2017-02-09 23:06:25 +01:00
|
|
|
for field, _ in pairs(fields) do
|
2018-02-14 00:28:09 +01:00
|
|
|
if field:sub(1,5) == "skins" then
|
|
|
|
context = minetest.deserialize(player:get_attribute('skinsdb_unified_inventory_context')) or {}
|
|
|
|
break
|
2017-02-09 23:06:25 +01:00
|
|
|
end
|
|
|
|
end
|
2018-02-14 00:28:09 +01:00
|
|
|
if not context then
|
2017-02-09 23:06:25 +01:00
|
|
|
return
|
|
|
|
end
|
2018-02-14 00:28:09 +01:00
|
|
|
|
|
|
|
local action = skins.on_skin_selection_receive_fields(player, context, fields)
|
|
|
|
if action == 'set' then
|
|
|
|
player:set_attribute('skinsdb_unified_inventory_context',"") --reset context
|
|
|
|
unified_inventory.set_inventory_formspec(player, "skins")
|
|
|
|
elseif action == 'page' then
|
|
|
|
player:set_attribute('skinsdb_unified_inventory_context', minetest.serialize(context))
|
|
|
|
unified_inventory.set_inventory_formspec(player, "skins_page")
|
|
|
|
end
|
2017-02-09 23:06:25 +01:00
|
|
|
end)
|