1
0
Fork 0

Add fancy GUI to select skin

This commit is contained in:
Wuzzy 2019-03-05 13:50:35 +01:00
parent 9a54383a23
commit c84656f85a
7 changed files with 100 additions and 23 deletions

View File

@ -324,8 +324,11 @@ mcl_inventory.set_creative_formspec = function(player, start_i, pagenum, inv_siz
-- help button -- help button
"image_button[9,2;1,1;doc_button_icon_lores.png;__mcl_doc;]".. "image_button[9,2;1,1;doc_button_icon_lores.png;__mcl_doc;]"..
"tooltip[__mcl_doc;Help]".. "tooltip[__mcl_doc;Help]"..
-- skins button
"image_button[9,3;1,1;mcl_skins_button.png;__mcl_skins;]"..
"tooltip[__mcl_skins;Select player skin]"..
-- achievements button -- achievements button
"image_button[9,3;1,1;mcl_achievements_button.png;__mcl_achievements;]".. "image_button[9,4;1,1;mcl_achievements_button.png;__mcl_achievements;]"..
"tooltip[__mcl_achievements;Achievements]" "tooltip[__mcl_achievements;Achievements]"
-- For shortcuts -- For shortcuts

View File

@ -105,6 +105,9 @@ local function set_inventory(player, armor_change_only)
-- help button -- help button
"image_button[8,3;1,1;doc_button_icon_lores.png;__mcl_doc;]".. "image_button[8,3;1,1;doc_button_icon_lores.png;__mcl_doc;]"..
"tooltip[__mcl_doc;Help]".. "tooltip[__mcl_doc;Help]"..
-- skins button
"image_button[3,3;1,1;mcl_skins_button.png;__mcl_skins;]"..
"tooltip[__mcl_skins;Select player skin]"..
-- achievements button -- achievements button
"image_button[7,3;1,1;mcl_achievements_button.png;__mcl_achievements;]".. "image_button[7,3;1,1;mcl_achievements_button.png;__mcl_achievements;]"..
"tooltip[__mcl_achievements;Achievements]".. "tooltip[__mcl_achievements;Achievements]"..

View File

@ -12,26 +12,26 @@ local S, NS = dofile(mcl_skins.modpath .. "/intllib.lua")
-- load skin list and metadata -- load skin list and metadata
local id, f, data, skin = 1 local id, f, data, skin = 0
mcl_skins.list[0] = "character"
while true do while true do
skin = "character_" .. id if id == 0 then
skin = "character"
else
skin = "character_" .. id
-- does skin file exist ? -- does skin file exist ?
f = io.open(mcl_skins.modpath .. "/textures/" .. skin .. ".png") f = io.open(mcl_skins.modpath .. "/textures/" .. skin .. ".png")
-- escape loop if not found and remove last entry -- escape loop if not found
if not f then if not f then
mcl_skins.list[id] = nil break
id = id - 1 end
break f:close()
end end
f:close() mcl_skins.list[id] = skin
table.insert(mcl_skins.list, skin)
-- does metadata exist for that skin file ? -- does metadata exist for that skin file ?
f = io.open(mcl_skins.modpath .. "/meta/" .. skin .. ".txt") f = io.open(mcl_skins.modpath .. "/meta/" .. skin .. ".txt")
@ -47,8 +47,10 @@ while true do
author = data and data.author or "", author = data and data.author or "",
} }
if id > 0 then
mcl_skins.skin_count = mcl_skins.skin_count + 1
end
id = id + 1 id = id + 1
mcl_skins.skin_count = mcl_skins.skin_count + 1
end end
mcl_skins.set_player_skin = function(player, skin_id) mcl_skins.set_player_skin = function(player, skin_id)
@ -124,11 +126,15 @@ end
-- command to set player skin (usually for custom skins) -- command to set player skin (usually for custom skins)
minetest.register_chatcommand("setskin", { minetest.register_chatcommand("setskin", {
params = "[<player>] <skin number>", params = "[<player>] [<skin number>]",
description = S("Select player skin of yourself or another player"), description = S("Select player skin of yourself or another player"),
privs = {}, privs = {},
func = function(name, param) func = function(name, param)
if param == "" and name ~= "" then
mcl_skins.show_formspec(name)
return true
end
local playername, skin_id = string.match(param, "([^ ]+) (%d+)") local playername, skin_id = string.match(param, "([^ ]+) (%d+)")
if not playername or not skin_id then if not playername or not skin_id then
skin_id = string.match(param, "(%d+)") skin_id = string.match(param, "(%d+)")
@ -156,17 +162,84 @@ minetest.register_chatcommand("setskin", {
if not ok then if not ok then
return false, S("Invalid skin number! Valid numbers: 0 to @1", mcl_skins.skin_count) return false, S("Invalid skin number! Valid numbers: 0 to @1", mcl_skins.skin_count)
end end
local skinfile = "Skin #"..skin_id local skinfile = "#"..skin_id
local your_msg = S("Your skin has been set to: @1", skinfile) local meta = mcl_skins.meta[mcl_skins.skins[playername]]
local your_msg = S("Your skin has been set to: @1 (@2)", meta.name, skinfile)
if name == playername then if name == playername then
return true, your_msg return true, your_msg
else else
minetest.chat_send_player(playername, your_msg) minetest.chat_send_player(playername, your_msg)
return true, S("Skin of @1 set to: @2", playername, skinfile) return true, S("Skin of @1 set to: @2 (@3)", playername, meta.name, skinfile)
end end
end, end,
}) })
minetest.register_on_player_receive_fields(function(player, formname, fields)
if fields.__mcl_skins then
mcl_skins.show_formspec(player:get_player_name())
end
end)
mcl_skins.show_formspec = function(playername)
local formspec = "size[7,8.5]"
formspec = formspec .. "label[2,2;" .. minetest.formspec_escape(S("Select player skin:")) .. "]"
.. "textlist[0,2.5;6.8,6;skins_set;"
local meta
local selected = 1
for i = 0, mcl_skins.skin_count do
local label = S("@1 (@2)", mcl_skins.meta[mcl_skins.list[i] ].name, "#"..i)
formspec = formspec .. minetest.formspec_escape(label)
if mcl_skins.skins[playername] == mcl_skins.list[i] then
selected = i + 1
meta = mcl_skins.meta[mcl_skins.list[i]]
end
if i < #mcl_skins.list then
formspec = formspec ..","
end
end
formspec = formspec .. ";" .. selected .. ";false]"
formspec = formspec .. "image[0,0;1.35,2.7;" .. mcl_skins.previews[playername] .. ".png]"
if meta then
if meta.name then
formspec = formspec .. "label[2,0.5;" .. minetest.formspec_escape(S("Name: @1", meta.name)) .. "]"
end
end
minetest.show_formspec(playername, "mcl_skins:skin_select", formspec)
end
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname == "mcl_skins:skin_select" then
local name = player:get_player_name()
local event = minetest.explode_textlist_event(fields["skins_set"])
if event.type == "CHG" or event.type == "DCL" then
local skin_id = math.min(event.index - 1, mcl_skins.skin_count)
if not mcl_skins.list[skin_id] then
return -- Do not update wrong skin number
end
mcl_skins.set_player_skin(player, skin_id)
mcl_skins.show_formspec(name)
end
end
end)
minetest.log("action", "[mcl_skins] Mod initialized with "..mcl_skins.skin_count.." custom skin(s)") minetest.log("action", "[mcl_skins] Mod initialized with "..mcl_skins.skin_count.." custom skin(s)")

View File

@ -1,3 +1,2 @@
name = "Steve", name = "Steve",
author = "(Texture pack author)", author = "%TEXTURE_PACK_AUTHOR%",
description = "The default male skin.",

View File

@ -1,3 +1,2 @@
name = "Alex", name = "Alex",
author = "(Texture pack author)", author = "%TEXTURE_PACK_AUTHOR%",
description = "The default female skin.",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB