mirror of
https://github.com/minetest-mods/skinsdb.git
synced 2025-01-03 12:50:22 +01:00
added skins.get_skinlist(listname), sfinv prepared for per player skinlist
This commit is contained in:
parent
077312257d
commit
50e6c9e2d0
@ -5,17 +5,6 @@ else
|
|||||||
S = function(s) return s end
|
S = function(s) return s end
|
||||||
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
|
-- generate the current formspec
|
||||||
local function get_formspec(player, context)
|
local function get_formspec(player, context)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
@ -47,7 +36,7 @@ local function get_formspec(player, context)
|
|||||||
end
|
end
|
||||||
|
|
||||||
for i = (page-1)*16+1, page*16 do
|
for i = (page-1)*16+1, page*16 do
|
||||||
local skin = skins.list[i]
|
local skin = context.skins_list[i]
|
||||||
if not skin then
|
if not skin then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@ -67,15 +56,15 @@ local function get_formspec(player, context)
|
|||||||
local page_prev = page - 1
|
local page_prev = page - 1
|
||||||
local page_next = page + 1
|
local page_next = page + 1
|
||||||
if page_prev < 1 then
|
if page_prev < 1 then
|
||||||
page_prev = total_pages
|
page_prev = context.total_pages
|
||||||
end
|
end
|
||||||
if page_next > total_pages then
|
if page_next > context.total_pages then
|
||||||
page_next = 1
|
page_next = 1
|
||||||
end
|
end
|
||||||
local page_list = ""
|
local page_list = ""
|
||||||
dropdown_values = {}
|
dropdown_values = {}
|
||||||
for pg=1, total_pages do
|
for pg=1, context.total_pages do
|
||||||
local pagename = S("Page").." "..pg.."/"..total_pages
|
local pagename = S("Page").." "..pg.."/"..context.total_pages
|
||||||
dropdown_values[pagename] = pg
|
dropdown_values[pagename] = pg
|
||||||
if pg > 1 then page_list = page_list.."," end
|
if pg > 1 then page_list = page_list.."," end
|
||||||
page_list = page_list..pagename
|
page_list = page_list..pagename
|
||||||
@ -91,13 +80,23 @@ end
|
|||||||
sfinv.register_page("skins:overview", {
|
sfinv.register_page("skins:overview", {
|
||||||
title = "Skins",
|
title = "Skins",
|
||||||
get = function(self, player, context)
|
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))
|
return sfinv.make_formspec(player, context, get_formspec(player, context))
|
||||||
end,
|
end,
|
||||||
on_player_receive_fields = function(self, player, context, fields)
|
on_player_receive_fields = function(self, player, context, fields)
|
||||||
for field, _ in pairs(fields) do
|
for field, _ in pairs(fields) do
|
||||||
local current = string.split(field, "$", 2)
|
local current = string.split(field, "$", 2)
|
||||||
if current[1] == "skins_set" then
|
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)
|
sfinv.set_player_inventory_formspec(player)
|
||||||
return
|
return
|
||||||
elseif current[1] == "skins_page" then
|
elseif current[1] == "skins_page" then
|
||||||
|
23
skinlist.lua
23
skinlist.lua
@ -1,7 +1,7 @@
|
|||||||
skins.list = {}
|
|
||||||
|
|
||||||
local skins_dir_list = minetest.get_dir_list(skins.modpath.."/textures")
|
local skins_dir_list = minetest.get_dir_list(skins.modpath.."/textures")
|
||||||
local unsorted_skinslist = {}
|
local unsorted_skinslist = {}
|
||||||
|
local sorted_skinslist
|
||||||
for _, fn in pairs(skins_dir_list) do
|
for _, fn in pairs(skins_dir_list) do
|
||||||
if fn:find("^character_") then
|
if fn:find("^character_") then
|
||||||
nameparts = string.gsub(fn, "[.]", "_"):split("_")
|
nameparts = string.gsub(fn, "[.]", "_"):split("_")
|
||||||
@ -26,7 +26,22 @@ for _, fn in pairs(skins_dir_list) do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
table.sort(unsorted_skinslist, function(a,b) return a:get_meta("_sort_id") < b:get_meta("_sort_id") end)
|
-- get skinlist. listname not full implemented at the time: could be "mod:wardrobe" or "player:bell07" in feature
|
||||||
for _,v in ipairs(unsorted_skinslist) do
|
function skins.get_skinlist(listname)
|
||||||
table.insert(skins.list, v)
|
-- sort on demand
|
||||||
|
if not sorted_skinslist then
|
||||||
|
table.sort(unsorted_skinslist, function(a,b) return a:get_meta("_sort_id") < b:get_meta("_sort_id") end)
|
||||||
|
sorted_skinslist = unsorted_skinslist
|
||||||
|
end
|
||||||
|
if not listname then
|
||||||
|
return sorted_skinslist
|
||||||
|
else
|
||||||
|
local ret = {}
|
||||||
|
for _, skin in ipairs(sorted_skinslist) do
|
||||||
|
if skin:get_meta(listname) then
|
||||||
|
table.insert(ret, skin)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return ret
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -7,7 +7,7 @@ end
|
|||||||
|
|
||||||
local dropdown_values = {}
|
local dropdown_values = {}
|
||||||
local skins_reftab = {}
|
local skins_reftab = {}
|
||||||
|
local skins_list = skins.get_skinlist()
|
||||||
unified_inventory.register_page("skins", {
|
unified_inventory.register_page("skins", {
|
||||||
get_formspec = function(player)
|
get_formspec = function(player)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
@ -44,7 +44,7 @@ unified_inventory.register_button("skins", {
|
|||||||
|
|
||||||
-- Create all of the skin-picker pages.
|
-- Create all of the skin-picker pages.
|
||||||
local total_pages = 1
|
local total_pages = 1
|
||||||
for i, skin in ipairs(skins.list) do
|
for i, skin in ipairs(skins_list) do
|
||||||
local page = math.floor((i-1) / 16)+1
|
local page = math.floor((i-1) / 16)+1
|
||||||
skin:set_meta("inv_page", page)
|
skin:set_meta("inv_page", page)
|
||||||
skin:set_meta("inv_page_index", (i-1)%16+1)
|
skin:set_meta("inv_page_index", (i-1)%16+1)
|
||||||
@ -54,7 +54,7 @@ end
|
|||||||
for page=1, total_pages do
|
for page=1, total_pages do
|
||||||
local formspec = "background[0.06,0.99;7.92,7.52;ui_misc_form.png]"
|
local formspec = "background[0.06,0.99;7.92,7.52;ui_misc_form.png]"
|
||||||
for i = (page-1)*16+1, page*16 do
|
for i = (page-1)*16+1, page*16 do
|
||||||
local skin = skins.list[i]
|
local skin = skins_list[i]
|
||||||
if not skin then
|
if not skin then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@ -108,7 +108,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
for field, _ in pairs(fields) do
|
for field, _ in pairs(fields) do
|
||||||
local current = string.split(field, "$", 2)
|
local current = string.split(field, "$", 2)
|
||||||
if current[1] == "skins_set" then
|
if current[1] == "skins_set" then
|
||||||
skins.set_player_skin(player, skins.list[tonumber(current[2])])
|
skins.set_player_skin(player, skins_list[tonumber(current[2])])
|
||||||
unified_inventory.set_inventory_formspec(player, "skins")
|
unified_inventory.set_inventory_formspec(player, "skins")
|
||||||
return
|
return
|
||||||
elseif current[1] == "skins_page" then
|
elseif current[1] == "skins_page" then
|
||||||
|
Loading…
Reference in New Issue
Block a user