Jordan Irwin 2021-04-22 02:21:25 -07:00
parent 05c30105a9
commit 6a54d5fb31
8 changed files with 76 additions and 55 deletions

View File

@ -93,7 +93,7 @@ The game includes the mods from the default [minetest_game](https://github.com/m
* [hbsprint][] ([LGPL][lic.lgpl2.1]) -- version: [f566d0f Git][ver.hbsprint] *2021-02-18* ([patched][patch.hbsprint])
* player/visuals/
* [invisibility][] ([MIT][lic.invisibility]) -- version: [65c0823 Git][ver.invisibility] *2021-01-21* ([patched][patch.invisibility])
* [wardrobe][] ([MIT][lic.wardrobe]) -- version: [1.2][ver.wardrobe] *2021-04-20*
* [wardrobe][] ([MIT][lic.wardrobe]) -- version: [1.3][ver.wardrobe] *2021-04-22*
* protection/
* [pvp_areas][] ([LGPL][lic.lgpl2.1]) -- version: [6e4d66d Git][ver.pvp_areas] *2018-07-26*
* [simple_protection][] ([CC0][lic.cc0]) -- version: [3630fe9 Git][ver.simple_protection] *2021-04-07* ([patched][patch.simple_protection])
@ -538,7 +538,7 @@ The game includes the mods from the default [minetest_game](https://github.com/m
[ver.unifieddyes]: https://gitlab.com/VanessaE/unifieddyes/tags/2021-03-26-1
[ver.waffles]: https://github.com/GreenXenith/waffles/tree/15bcdce
[ver.walking_light]: https://github.com/petermaloney/walking_light/tree/766ef0f
[ver.wardrobe]: https://github.com/AntumMT/mod-wardrobe/releases/tag/v1.2
[ver.wardrobe]: https://github.com/AntumMT/mod-wardrobe/releases/tag/v1.3
[ver.whitelist]: https://github.com/AntumMT/mod-whitelist/tree/b813b19
[ver.windmill]: https://github.com/Sokomine/windmill/tree/47b029d
[ver.workbench]: https://github.com/minetest-mods/workbench/tree/bd14f59

View File

@ -128,3 +128,9 @@ Version 1.2
* Skins can be registered individually from within mod code.
* Number of displayed skins can be set in server configuration file.
* Keep default skin as first item.
Version 1.3
* Released 2021-04-22
* Formspec doesn't close & re-open when changing page (fixes cursor being centered).
* "prev" & "next" buttons cycle back to last & first page respectively.

View File

@ -0,0 +1,46 @@
wardrobe.formspec_name = "wardrobe_wardrobeSkinForm"
function wardrobe.show_formspec(player, page)
local playerName = player:get_player_name();
if not playerName or playerName == "" then return; end
local page_count = math.ceil(wardrobe.skin_count / wardrobe.skins_per_page)
local page_prev = page-1
local page_next = page+1
if page_prev < 1 then
page_prev = page_count
elseif page_next > page_count then
page_next = 1
end
local n = wardrobe.skin_count
if n <= 0 then return end
local nPages = math.ceil(n / wardrobe.skins_per_page)
if not page or page > nPages then page = 1 end
local s = 1 + wardrobe.skins_per_page*(page-1) -- first skin index for page
local e = math.min(s+wardrobe.skins_per_page-1, n) -- last skin index for page
local skins = {}
for i = s, e do
local skin = wardrobe.skins[i];
local skinName = core.formspec_escape(wardrobe.skinNames[skin]);
table.insert(skins, {skin, skinName})
end
local formspec = "size[5,10]"
.. "label[0,0;Change Into:]"
.. "label[1.8,0.5;Page " .. tostring(page) .. " / " .. tostring(page_count) .. "]"
for idx, s in ipairs(skins) do
formspec = formspec
.. "button_exit[0," .. idx ..";5,1;s:" .. s[1] .. ";" .. s[2] .. "]"
end
formspec = formspec
.. "button[0,9;1,1;n:p" .. tostring(page_prev) .. ";prev]"
.. "button[4,9;1,1;n:p" .. tostring(page_next) .. ";next]"
core.show_formspec(playerName, wardrobe.formspec_name, formspec)
end

View File

@ -9,6 +9,7 @@ wardrobe.skin_files = {wardrobe.path.."/skins.txt", world_path.."/skins.txt"};
wardrobe.playerSkins = {}
dofile(wardrobe.path.."/settings.lua")
dofile(wardrobe.path.."/formspec.lua")
local initSkin, changeSkin, updateSkin = dofile(wardrobe.path.."/skinMethods.lua");
dofile(wardrobe.path.."/storage.lua");
dofile(wardrobe.path.."/wardrobe.lua");

View File

@ -1,4 +1,4 @@
name = wardrobe
description = A wardrobe that can be used to register & set new skins for players.
version = 1.2
version = 1.3
depends = default, player_api, wool

View File

@ -1 +1 @@
character.png: Default Skin
character.png: Sam (default)

View File

@ -1,6 +1,7 @@
wardrobe.skins = {}
wardrobe.skinNames = {}
wardrobe.skin_count = 0
local function removePrefix(str, prefix)
@ -149,6 +150,8 @@ end
function wardrobe.registerSkin(k, v)
table.insert(wardrobe.skins, k)
wardrobe.skinNames[k] = v
wardrobe.skin_count = wardrobe.skin_count+1
end
--- Loads skin names from skin files, storing the result in wardrobe.skins and
@ -185,6 +188,7 @@ function wardrobe.loadSkins(skin_files)
-- overwrite registered skins
wardrobe.skins = skins;
wardrobe.skinNames = skinNames;
wardrobe.skin_count = #wardrobe.skins
wardrobe.sortNames()
end
@ -224,10 +228,6 @@ function wardrobe.registerSkinFiles(skin_files)
-- add to registered skins
for _, sk in ipairs(skins) do
--[[
table.insert(wardrobe.skins, sk)
wardrobe.skinNames[sk] = skinNames[sk]
]]
wardrobe.registerSkin(sk, skinNames[sk])
end

View File

@ -1,41 +1,7 @@
local FORM_NAME = "wardrobe_wardrobeSkinForm";
local function showForm(player, page)
local playerName = player:get_player_name();
if not playerName or playerName == "" then return; end
local n = #wardrobe.skins;
if n <= 0 then return; end
local nPages = math.ceil(n/wardrobe.skins_per_page);
if not page or page > nPages then page = 1; end
local s = 1 + wardrobe.skins_per_page*(page-1);
local e = math.min(s+wardrobe.skins_per_page-1, n);
local fs = "size[5,10]";
fs = fs.."label[0,0;Change Into:]";
for i = s, e do
local slot = i-s+1;
local skin = wardrobe.skins[i];
local skinName = core.formspec_escape(wardrobe.skinNames[skin]);
fs = fs.."button_exit[0,"..slot..";5,1;s:"..skin..";"..skinName.."]";
end
fs = fs.."label[2,9;Page "..page.."/"..nPages.."]";
if page > 1 then
fs = fs.."button_exit[0,9;1,1;n:p"..(page-1)..";prev]";
end
if page < nPages then
fs = fs.."button_exit[4,9;1,1;n:p"..(page+1)..";next]";
end
core.show_formspec(playerName, FORM_NAME, fs);
end
core.register_on_player_receive_fields(
function(player, formName, fields)
if formName ~= FORM_NAME then return; end
if formName ~= wardrobe.formspec_name then return; end
local playerName = player:get_player_name();
if not playerName or playerName == "" then return; end
@ -46,7 +12,7 @@ core.register_on_player_receive_fields(
local value = string.sub(fieldName, 3);
if action == "n" then
showForm(player, tonumber(string.sub(value, 2)));
wardrobe.show_formspec(player, tonumber(string.sub(value, 2)));
return;
elseif action == "s" then
wardrobe.changePlayerSkin(playerName, value);
@ -63,25 +29,27 @@ core.register_node(
description = "Wardrobe",
paramtype2 = "facedir",
tiles = {
"wardrobe_wardrobe_topbottom.png",
"wardrobe_wardrobe_topbottom.png",
"wardrobe_wardrobe_sides.png",
"wardrobe_wardrobe_sides.png",
"wardrobe_wardrobe_sides.png",
"wardrobe_wardrobe_front.png"
},
"wardrobe_wardrobe_topbottom.png",
"wardrobe_wardrobe_topbottom.png",
"wardrobe_wardrobe_sides.png",
"wardrobe_wardrobe_sides.png",
"wardrobe_wardrobe_sides.png",
"wardrobe_wardrobe_front.png"
},
inventory_image = "wardrobe_wardrobe_front.png",
sounds = default.node_sound_wood_defaults(),
groups = { choppy = 3, oddly_breakable_by_hand = 2, flammable = 3 },
on_rightclick = function(pos, node, player, itemstack, pointedThing)
showForm(player, 1);
wardrobe.show_formspec(player, 1);
end
});
core.register_craft(
{
output = "wardrobe:wardrobe",
recipe = { { "group:wood", "group:stick", "group:wood" },
{ "group:wood", "group:wool", "group:wood" },
{ "group:wood", "group:wool", "group:wood" } }
recipe = {
{ "group:wood", "group:stick", "group:wood" },
{ "group:wood", "group:wool", "group:wood" },
{ "group:wood", "group:wool", "group:wood" },
}
});