summaryrefslogtreecommitdiff
path: root/sfinv_page.lua
diff options
context:
space:
mode:
authorAlexander Weber <web.alexander@web.de>2017-06-17 00:23:39 +0200
committerAlexander Weber <web.alexander@web.de>2017-06-17 00:23:39 +0200
commit50e6c9e2d01bbeb04be7fcaf58ff5233125b3ff3 (patch)
tree10af912f96ceccfed7b8b4b33ccd052b2edb4cd1 /sfinv_page.lua
parent077312257de7f3fa5c3b815e5b81b001a26d9f9d (diff)
added skins.get_skinlist(listname), sfinv prepared for per player skinlist
Diffstat (limited to 'sfinv_page.lua')
-rw-r--r--sfinv_page.lua33
1 files changed, 16 insertions, 17 deletions
diff --git a/sfinv_page.lua b/sfinv_page.lua
index 30ec39d..5fcd6e2 100644
--- a/sfinv_page.lua
+++ b/sfinv_page.lua
@@ -5,17 +5,6 @@ else
S = function(s) return s end
end
-local dropdown_values = {}
-
--- collect skins data
-local total_pages = 1
-for i, skin in ipairs(skins.list) do
- local page = math.floor((i-1) / 16)+1
- skin:set_meta("inv_page", page)
- skin:set_meta("inv_page_index", (i-1)%16+1)
- total_pages = page
-end
-
-- generate the current formspec
local function get_formspec(player, context)
local name = player:get_player_name()
@@ -47,7 +36,7 @@ local function get_formspec(player, context)
end
for i = (page-1)*16+1, page*16 do
- local skin = skins.list[i]
+ local skin = context.skins_list[i]
if not skin then
break
end
@@ -67,15 +56,15 @@ local function get_formspec(player, context)
local page_prev = page - 1
local page_next = page + 1
if page_prev < 1 then
- page_prev = total_pages
+ page_prev = context.total_pages
end
- if page_next > total_pages then
+ if page_next > context.total_pages then
page_next = 1
end
local page_list = ""
dropdown_values = {}
- for pg=1, total_pages do
- local pagename = S("Page").." "..pg.."/"..total_pages
+ for pg=1, context.total_pages do
+ local pagename = S("Page").." "..pg.."/"..context.total_pages
dropdown_values[pagename] = pg
if pg > 1 then page_list = page_list.."," end
page_list = page_list..pagename
@@ -91,13 +80,23 @@ end
sfinv.register_page("skins:overview", {
title = "Skins",
get = function(self, player, context)
+ -- collect skins data
+ context.skins_list = skins.get_skinlist()
+ context.total_pages = 1
+ for i, skin in ipairs(context.skins_list ) do
+ local page = math.floor((i-1) / 16)+1
+ skin:set_meta("inv_page", page)
+ skin:set_meta("inv_page_index", (i-1)%16+1)
+ context.total_pages = page
+ end
+ -- generate first formspec
return sfinv.make_formspec(player, context, get_formspec(player, context))
end,
on_player_receive_fields = function(self, player, context, fields)
for field, _ in pairs(fields) do
local current = string.split(field, "$", 2)
if current[1] == "skins_set" then
- skins.set_player_skin(player, skins.list[tonumber(current[2])])
+ skins.set_player_skin(player, context.skins_list[tonumber(current[2])])
sfinv.set_player_inventory_formspec(player)
return
elseif current[1] == "skins_page" then