2015-05-01 14:51:52 +02:00
|
|
|
|
2017-01-31 06:34:41 +01:00
|
|
|
local S = homedecor_i18n.gettext
|
|
|
|
|
2015-05-01 14:51:52 +02:00
|
|
|
local wd_cbox = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = { -0.5, -0.5, -0.5, 0.5, 1.5, 0.5 }
|
|
|
|
}
|
|
|
|
|
2018-04-27 21:55:49 +02:00
|
|
|
-- cache set_textures function (fallback to old version)
|
|
|
|
-- default.player_set_textures is deprecated and will be removed in future
|
|
|
|
local set_player_textures =
|
2018-04-27 22:39:23 +02:00
|
|
|
minetest.get_modpath("player_api") and player_api.set_textures
|
2018-04-27 21:55:49 +02:00
|
|
|
or default.player_set_textures
|
|
|
|
|
2018-04-27 22:39:23 +02:00
|
|
|
local armor_mod_path = minetest.get_modpath("3d_armor")
|
|
|
|
local skins = {"male1", "male2", "male3", "male4", "male5"}
|
2018-04-28 01:26:39 +02:00
|
|
|
local skin_updates = {} -- skin update queue
|
2018-04-27 22:39:23 +02:00
|
|
|
|
|
|
|
local function set_player_skin(player, skin)
|
2018-04-28 01:04:12 +02:00
|
|
|
minetest.log("verbose",
|
|
|
|
S("player @1 sets skin to @2", player:get_player_name(), skin) ..
|
|
|
|
(armor_mod_path and ' [armor]' or '')
|
|
|
|
)
|
2018-04-27 22:39:23 +02:00
|
|
|
if armor_mod_path then -- if 3D_armor's installed, let it set the skin
|
|
|
|
armor.textures[player:get_player_name()].skin = skin
|
|
|
|
armor:update_player_visuals(player)
|
|
|
|
else
|
|
|
|
set_player_textures(player, { skin })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-05-01 14:51:52 +02:00
|
|
|
homedecor.register("wardrobe", {
|
|
|
|
mesh = "homedecor_bedroom_wardrobe.obj",
|
|
|
|
tiles = {
|
2015-05-04 03:18:35 +02:00
|
|
|
homedecor.plain_wood,
|
2015-05-01 14:51:52 +02:00
|
|
|
"homedecor_wardrobe_drawers.png",
|
|
|
|
"homedecor_wardrobe_doors.png"
|
|
|
|
},
|
|
|
|
inventory_image = "homedecor_wardrobe_inv.png",
|
2017-01-31 06:34:41 +01:00
|
|
|
description = S("Wardrobe"),
|
2015-05-01 14:51:52 +02:00
|
|
|
groups = {snappy=3},
|
|
|
|
selection_box = wd_cbox,
|
|
|
|
collision_box = wd_cbox,
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
2015-09-08 09:50:02 +02:00
|
|
|
expand = { top="placeholder" },
|
2015-05-14 12:25:11 +02:00
|
|
|
on_rotate = screwdriver.rotate_simple,
|
2017-01-31 06:34:41 +01:00
|
|
|
infotext = S("Wardrobe"),
|
2015-08-19 18:03:05 +02:00
|
|
|
inventory = {
|
|
|
|
size = 10
|
|
|
|
},
|
2015-05-01 14:51:52 +02:00
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
-- textures made by the Minetest community (mostly Calinou and Jordach)
|
2015-05-01 18:13:10 +02:00
|
|
|
local clothes_strings = ""
|
|
|
|
for i = 1,5 do
|
|
|
|
clothes_strings = clothes_strings..
|
2015-05-07 20:28:12 +02:00
|
|
|
"image_button_exit["..(i-1)..".5,0;1.1,2;homedecor_clothes_"..skins[i].."_preview.png;"..skins[i]..";]"..
|
|
|
|
"image_button_exit["..(i-1)..".5,2;1.1,2;homedecor_clothes_fe"..skins[i].."_preview.png;fe"..skins[i]..";]"
|
2015-05-01 18:13:10 +02:00
|
|
|
end
|
2015-05-01 14:51:52 +02:00
|
|
|
meta:set_string("formspec", "size[5.5,8.5]"..default.gui_bg..default.gui_bg_img..default.gui_slots..
|
2017-01-31 06:34:41 +01:00
|
|
|
"vertlabel[0,0.5;"..minetest.formspec_escape(S("Clothes")).."]"..
|
2015-05-01 18:13:10 +02:00
|
|
|
clothes_strings..
|
2017-01-31 06:34:41 +01:00
|
|
|
"vertlabel[0,5.2;"..minetest.formspec_escape(S("Storage")).."]"..
|
2015-05-01 14:51:52 +02:00
|
|
|
"list[current_name;main;0.5,4.5;5,2;]"..
|
2016-08-27 21:10:43 +02:00
|
|
|
"list[current_player;main;0.5,6.8;5,2;]" ..
|
|
|
|
"listring[]")
|
2015-05-01 14:51:52 +02:00
|
|
|
end,
|
|
|
|
on_receive_fields = function(pos, formname, fields, sender)
|
2015-05-01 18:13:10 +02:00
|
|
|
for i = 1,5 do
|
|
|
|
if fields[skins[i]] then
|
2018-04-27 22:39:23 +02:00
|
|
|
set_player_skin(sender, "homedecor_clothes_"..skins[i]..".png")
|
2018-04-28 01:04:12 +02:00
|
|
|
sender:set_attribute("homedecor:player_skin", "homedecor_clothes_"..skins[i]..".png")
|
2015-05-01 18:13:10 +02:00
|
|
|
break
|
|
|
|
elseif fields["fe"..skins[i]] then
|
2018-04-27 22:39:23 +02:00
|
|
|
set_player_skin(sender, "homedecor_clothes_fe"..skins[i]..".png")
|
2018-04-28 01:04:12 +02:00
|
|
|
sender:set_attribute("homedecor:player_skin", "homedecor_clothes_fe"..skins[i]..".png")
|
2015-05-01 18:13:10 +02:00
|
|
|
break
|
|
|
|
end
|
2015-05-01 14:51:52 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_alias("homedecor:wardrobe_bottom", "homedecor:wardrobe")
|
|
|
|
minetest.register_alias("homedecor:wardrobe_top", "air")
|
2018-04-28 01:04:12 +02:00
|
|
|
|
|
|
|
minetest.register_on_joinplayer(function(player)
|
|
|
|
local skin = player:get_attribute("homedecor:player_skin")
|
|
|
|
if skin ~= nil then
|
|
|
|
-- setting player skin on connect has no effect, so queue skin change for next game step
|
|
|
|
table.insert(skin_updates, {player, skin})
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_globalstep(function(dtime)
|
|
|
|
-- if skin update queue is filled
|
|
|
|
if #skin_updates > 0 then
|
|
|
|
-- update player skins
|
|
|
|
for _,u in pairs(skin_updates) do
|
|
|
|
set_player_skin(u[1], u[2])
|
|
|
|
end
|
|
|
|
skin_updates = {} -- empty queue
|
|
|
|
end
|
|
|
|
end)
|