wardrobe/wardrobe.lua

98 lines
2.8 KiB
Lua

local FORM_NAME = "wardrobe_wardrobeSkinForm";
local SKINS_PER_PAGE = 8;
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/SKINS_PER_PAGE);
if not page or page > nPages then page = 1; end
local s = 1 + SKINS_PER_PAGE*(page-1);
local e = math.min(s+SKINS_PER_PAGE-1, n);
local fs = "size[5,11]";
fs = fs.."label[0,0;Change Into:]";
for i = s, e do
local slot = i-s+1;
local skin = wardrobe.skins[i];
local skinName = minetest.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
fs = fs.."button_exit[0,10;5,1;c:c;clear]";
minetest.show_formspec(playerName, FORM_NAME, fs);
end
minetest.register_on_player_receive_fields(
function(player, formName, fields)
if formName ~= FORM_NAME then return; end
local playerName = player:get_player_name();
if not playerName or playerName == "" then return; end
for fieldName in pairs(fields) do
if #fieldName > 2 then
local action = string.sub(fieldName, 1, 1);
local value = string.sub(fieldName, 3);
if action == "n" then
showForm(player, tonumber(string.sub(value, 2)));
return;
elseif action == "s" then
wardrobe.changePlayerSkin(playerName, value);
return;
elseif action == "c" then
wardrobe.changePlayerSkin(playerName, nil);
return;
end
end
end
end);
scbox = {
type = "fixed",
fixed = { -0.5, -0.5, -0.5, 0.5, 1.5, 0.5 }
}
minetest.register_node("wardrobe:wardrobe", {
description = "Wardrobe",
drawtype = "mesh",
mesh = "wardrobe.obj",
sunlight_propagates = true,
paramtype = 'light',
paramtype2 = "facedir",
wield_scale = {x=0.6, y=0.6, z=0.6},
selection_box = scbox,
collision_box = scbox,
tiles = {
"wardrobe_base.png",
"wardrobe_drawers.png",
"wardrobe_doors.png"
},
inventory_image = "wardrobe_inv.png",
groups = {cracky=1,choppy=1,snappy=1},
on_rightclick = function(pos, node, player, itemstack, pointedThing)
showForm(player, 1);
end
})
minetest.register_craft(
{
output = "wardrobe:wardrobe",
recipe = { { "group:wood", "group:stick", "group:wood" },
{ "group:wood", "group:wool", "group:wood" },
{ "group:wood", "group:wool", "group:wood" } }
});