From c84656f85a672e5ed77cc51d7603f3815c545714 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 5 Mar 2019 13:50:35 +0100 Subject: [PATCH] Add fancy GUI to select skin --- mods/HUD/mcl_inventory/creative.lua | 5 +- mods/HUD/mcl_inventory/init.lua | 3 + mods/PLAYER/mcl_skins/init.lua | 109 +++++++++++++++--- mods/PLAYER/mcl_skins/meta/character.txt | 3 +- mods/PLAYER/mcl_skins/meta/character_1.txt | 3 +- .../textures/inventory_plus_skins.png | Bin 2182 -> 0 bytes .../mcl_skins/textures/mcl_skins_button.png | Bin 0 -> 2010 bytes 7 files changed, 100 insertions(+), 23 deletions(-) delete mode 100644 mods/PLAYER/mcl_skins/textures/inventory_plus_skins.png create mode 100644 mods/PLAYER/mcl_skins/textures/mcl_skins_button.png diff --git a/mods/HUD/mcl_inventory/creative.lua b/mods/HUD/mcl_inventory/creative.lua index d9ad2e94..fcc8efdd 100644 --- a/mods/HUD/mcl_inventory/creative.lua +++ b/mods/HUD/mcl_inventory/creative.lua @@ -324,8 +324,11 @@ mcl_inventory.set_creative_formspec = function(player, start_i, pagenum, inv_siz -- help button "image_button[9,2;1,1;doc_button_icon_lores.png;__mcl_doc;]".. "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 - "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]" -- For shortcuts diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index 415c3075..05f61aac 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -105,6 +105,9 @@ local function set_inventory(player, armor_change_only) -- help button "image_button[8,3;1,1;doc_button_icon_lores.png;__mcl_doc;]".. "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 "image_button[7,3;1,1;mcl_achievements_button.png;__mcl_achievements;]".. "tooltip[__mcl_achievements;Achievements]".. diff --git a/mods/PLAYER/mcl_skins/init.lua b/mods/PLAYER/mcl_skins/init.lua index c24ce4a4..8fe76db3 100644 --- a/mods/PLAYER/mcl_skins/init.lua +++ b/mods/PLAYER/mcl_skins/init.lua @@ -12,26 +12,26 @@ local S, NS = dofile(mcl_skins.modpath .. "/intllib.lua") -- load skin list and metadata -local id, f, data, skin = 1 - -mcl_skins.list[0] = "character" +local id, f, data, skin = 0 while true do - skin = "character_" .. id + if id == 0 then + skin = "character" + else + skin = "character_" .. id - -- does skin file exist ? - f = io.open(mcl_skins.modpath .. "/textures/" .. skin .. ".png") + -- does skin file exist ? + f = io.open(mcl_skins.modpath .. "/textures/" .. skin .. ".png") - -- escape loop if not found and remove last entry - if not f then - mcl_skins.list[id] = nil - id = id - 1 - break + -- escape loop if not found + if not f then + break + end + f:close() end - f:close() - table.insert(mcl_skins.list, skin) + mcl_skins.list[id] = skin -- does metadata exist for that skin file ? f = io.open(mcl_skins.modpath .. "/meta/" .. skin .. ".txt") @@ -47,8 +47,10 @@ while true do author = data and data.author or "", } + if id > 0 then + mcl_skins.skin_count = mcl_skins.skin_count + 1 + end id = id + 1 - mcl_skins.skin_count = mcl_skins.skin_count + 1 end mcl_skins.set_player_skin = function(player, skin_id) @@ -124,11 +126,15 @@ end -- command to set player skin (usually for custom skins) minetest.register_chatcommand("setskin", { - params = "[] ", + params = "[] []", description = S("Select player skin of yourself or another player"), privs = {}, 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+)") if not playername or not skin_id then skin_id = string.match(param, "(%d+)") @@ -156,17 +162,84 @@ minetest.register_chatcommand("setskin", { if not ok then return false, S("Invalid skin number! Valid numbers: 0 to @1", mcl_skins.skin_count) 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 return true, your_msg else 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, }) +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)") + diff --git a/mods/PLAYER/mcl_skins/meta/character.txt b/mods/PLAYER/mcl_skins/meta/character.txt index 5a07db19..00061a65 100644 --- a/mods/PLAYER/mcl_skins/meta/character.txt +++ b/mods/PLAYER/mcl_skins/meta/character.txt @@ -1,3 +1,2 @@ name = "Steve", -author = "(Texture pack author)", -description = "The default male skin.", +author = "%TEXTURE_PACK_AUTHOR%", diff --git a/mods/PLAYER/mcl_skins/meta/character_1.txt b/mods/PLAYER/mcl_skins/meta/character_1.txt index ec438955..f96b13f6 100644 --- a/mods/PLAYER/mcl_skins/meta/character_1.txt +++ b/mods/PLAYER/mcl_skins/meta/character_1.txt @@ -1,3 +1,2 @@ name = "Alex", -author = "(Texture pack author)", -description = "The default female skin.", +author = "%TEXTURE_PACK_AUTHOR%", diff --git a/mods/PLAYER/mcl_skins/textures/inventory_plus_skins.png b/mods/PLAYER/mcl_skins/textures/inventory_plus_skins.png deleted file mode 100644 index 7cc97759cd8c906632a0ff2712b647c23abc2278..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2182 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4kiW$h6xih%orHh?5jc|N`ey06$*;-(=u~X z6-p`#QWa7wGSe6sDsHU}kKDwp&hzKFh$U0f^}>kNMa?qyyq9{Wr|9qC+Ba>{QZr0&+m7<*3nnr#V<54%WVJB zHu09`zMFq-d#lsm&ieV3HGKBl&(Aq`Z*_~zKJ_Zg!$C_j_R7{N#qE8(0l$oO9-jK) zcISDq;kqW(G6S;%X@{@!8d@&ct8rn0SNF3_>(Um9J0+59i|_tS*0!@Q`#VACo9pS+ z3&uVA35%Oe_gC&rUTCa8|EHDc85<5;*@KdaNBU3K82y|6x@^lezgVT{yfp&TZ(H^n zm=*sP-|N7kd(=d(=6veBPsi*8Umr}cF%Z|;a7#@uYKeQ^&%>MD_h&S3++?c3U&_#7 zQ0`*zOklt+d1fiMtA$5A=TL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