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 d9ad2e94e..fcc8efddb 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 415c30757..05f61aac0 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 c24ce4a4c..8fe76db3e 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 5a07db19e..00061a654 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 ec4389550..f96b13f68 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 zcmV;12zmF3P) zaB^>EX>4U6ba`-PAZ2)IW&i+q+O1bvvI8d!{O1%o0%F&3SgUe_96t@xjF)G>N>cHZ z&5Qj?pTL1##Z9sDk(O*YzxrUWn-{yeUpSaNS}%`j zYX1s*d<@7z?d{cWa#ue^9ntOheEgny-)q03j=U2)>9b)SSHshC^y|91Rp;-|Ap?vN z;mS{Oy(rM2N{i-cJ9UH@+;kbObKUu4D?U4R{g4v&MayN-GmI}_qk}cS zdAVbuGcTX{Iu*=32t6Ia8DYea%X~8am+N-4)=pg_TW+inm)kjwFgA1h7rj6TEyXk* ze9vW`^2R<9>%m|=Fc&Pa+9obqq(^S~!?Q=fXoIn`H7E~t0EjSmL@?yRfKB8hC9>JM zOavSY_^F88A?+I&pcvgCv%rn_3FH*F=f;>!r>~1n%#aok5qc zn*k)W+nm`#A-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