mirror of
https://github.com/minetest-mods/skinsdb.git
synced 2025-01-22 13:50:27 +01:00
consolidate redundant skinsinfo formspec code
This commit is contained in:
parent
51b6cf2e3a
commit
5498faa88a
25
formspecs.lua
Normal file
25
formspecs.lua
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
local S = skins.S
|
||||||
|
|
||||||
|
-- Show skin info
|
||||||
|
function skins.get_skin_info_formspec(skin)
|
||||||
|
local texture = skin:get_texture()
|
||||||
|
local m_name = skin:get_meta_string("name")
|
||||||
|
local m_author = skin:get_meta_string("author")
|
||||||
|
local m_license = skin:get_meta_string("license")
|
||||||
|
-- overview page
|
||||||
|
local formspec = "image[0,.75;1,2;"..skin:get_preview().."]"
|
||||||
|
if texture then
|
||||||
|
formspec = formspec.."label[6,.5;"..S("Raw texture")..":]"
|
||||||
|
.."image[6,1;2,1;"..skin:get_texture().."]"
|
||||||
|
end
|
||||||
|
if m_name ~= "" then
|
||||||
|
formspec = formspec.."label[2,.5;"..S("Name")..": "..minetest.formspec_escape(m_name).."]"
|
||||||
|
end
|
||||||
|
if m_author ~= "" then
|
||||||
|
formspec = formspec.."label[2,1;"..S("Author")..": "..minetest.formspec_escape(m_author).."]"
|
||||||
|
end
|
||||||
|
if m_license ~= "" then
|
||||||
|
formspec = formspec.."label[2,1.5;"..S("License")..": "..minetest.formspec_escape(m_license).."]"
|
||||||
|
end
|
||||||
|
return formspec
|
||||||
|
end
|
9
init.lua
9
init.lua
@ -9,9 +9,18 @@ skins = {}
|
|||||||
skins.modpath = minetest.get_modpath(minetest.get_current_modname())
|
skins.modpath = minetest.get_modpath(minetest.get_current_modname())
|
||||||
skins.default = "character"
|
skins.default = "character"
|
||||||
|
|
||||||
|
local S
|
||||||
|
if minetest.get_modpath("intllib") then
|
||||||
|
skins.S = intllib.Getter()
|
||||||
|
else
|
||||||
|
skins.S = function(s) return s end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
dofile(skins.modpath.."/skin_meta_api.lua")
|
dofile(skins.modpath.."/skin_meta_api.lua")
|
||||||
dofile(skins.modpath.."/api.lua")
|
dofile(skins.modpath.."/api.lua")
|
||||||
dofile(skins.modpath.."/skinlist.lua")
|
dofile(skins.modpath.."/skinlist.lua")
|
||||||
|
dofile(skins.modpath.."/formspecs.lua")
|
||||||
dofile(skins.modpath.."/chatcommands.lua")
|
dofile(skins.modpath.."/chatcommands.lua")
|
||||||
-- Unified inventory page/integration
|
-- Unified inventory page/integration
|
||||||
if minetest.get_modpath("unified_inventory") then
|
if minetest.get_modpath("unified_inventory") then
|
||||||
|
@ -1,33 +1,10 @@
|
|||||||
local S
|
local S = skins.S
|
||||||
if minetest.get_modpath("intllib") then
|
|
||||||
S = intllib.Getter()
|
|
||||||
else
|
|
||||||
S = function(s) return s end
|
|
||||||
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()
|
||||||
local skin = skins.get_player_skin(player)
|
local skin = skins.get_player_skin(player)
|
||||||
local texture = skin:get_texture()
|
local formspec = skins.get_skin_info_formspec(skin)
|
||||||
local m_name = skin:get_meta_string("name")
|
|
||||||
local m_author = skin:get_meta_string("author")
|
|
||||||
local m_license = skin:get_meta_string("license")
|
|
||||||
-- overview page
|
|
||||||
local formspec = "image[0,.75;1,2;"..skin:get_preview().."]"
|
|
||||||
if texture then
|
|
||||||
formspec = formspec.."label[6,.5;"..S("Raw texture")..":]"
|
|
||||||
.."image[6,1;2,1;"..skin:get_texture().."]"
|
|
||||||
end
|
|
||||||
if m_name ~= "" then
|
|
||||||
formspec = formspec.."label[2,.5;"..S("Name")..": "..minetest.formspec_escape(m_name).."]"
|
|
||||||
end
|
|
||||||
if m_author ~= "" then
|
|
||||||
formspec = formspec.."label[2,1;"..S("Author")..": "..minetest.formspec_escape(m_author).."]"
|
|
||||||
end
|
|
||||||
if m_license ~= "" then
|
|
||||||
formspec = formspec.."label[2,1.5;"..S("License")..": "..minetest.formspec_escape(m_license).."]"
|
|
||||||
end
|
|
||||||
|
|
||||||
local page = 1
|
local page = 1
|
||||||
if context.skins_page then
|
if context.skins_page then
|
||||||
|
@ -1,38 +1,14 @@
|
|||||||
local S
|
local S = skins.S
|
||||||
if minetest.get_modpath("intllib") then
|
|
||||||
S = intllib.Getter()
|
|
||||||
else
|
|
||||||
S = function(s) return s end
|
|
||||||
end
|
|
||||||
|
|
||||||
local dropdown_values = {}
|
local dropdown_values = {}
|
||||||
local skins_reftab = {}
|
local skins_reftab = {}
|
||||||
local skins_list = skins.get_skinlist_for_player() --public only
|
local skins_list = skins.get_skinlist_for_player() --public only
|
||||||
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 skin = skins.get_player_skin(player)
|
local skin = skins.get_player_skin(player)
|
||||||
local texture = skin:get_texture()
|
|
||||||
local m_name = skin:get_meta_string("name")
|
|
||||||
local m_author = skin:get_meta_string("author")
|
|
||||||
local m_license = skin:get_meta_string("license")
|
|
||||||
local formspec = "background[0.06,0.99;7.92,7.52;ui_misc_form.png]".."image[0,.75;1,2;"..skin:get_preview().."]"
|
|
||||||
if texture then
|
|
||||||
formspec=formspec.."label[6,.5;"..S("Raw texture")..":]"
|
|
||||||
.."image[6,1;2,1;"..texture.."]"
|
|
||||||
end
|
|
||||||
if m_name ~= "" then
|
|
||||||
formspec = formspec.."label[2,.5;"..S("Name")..": "..minetest.formspec_escape(m_name).."]"
|
|
||||||
end
|
|
||||||
if m_author ~= "" then
|
|
||||||
formspec = formspec.."label[2,1;"..S("Author")..": "..minetest.formspec_escape(m_author).."]"
|
|
||||||
end
|
|
||||||
if m_license ~= "" then
|
|
||||||
formspec = formspec.."label[2,1.5;"..S("License")..": "..minetest.formspec_escape(m_license).."]"
|
|
||||||
end
|
|
||||||
|
|
||||||
local page = skin:get_meta("inv_page") or 1
|
local page = skin:get_meta("inv_page") or 1
|
||||||
formspec = formspec .. "button[.75,3;6.5,.5;skins_page$"..page..";"..S("Change").."]"
|
local formspec = "background[0.06,0.99;7.92,7.52;ui_misc_form.png]"..skins.get_skin_info_formspec(skin)..
|
||||||
|
"button[.75,3;6.5,.5;skins_page$"..page..";"..S("Change").."]"
|
||||||
return {formspec=formspec}
|
return {formspec=formspec}
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user