added player skin selector in the inventory

This commit is contained in:
kaadmy 2016-02-02 12:53:45 -08:00
parent a19a117968
commit 0d5dcbd4d1
12 changed files with 47 additions and 0 deletions

View File

@ -180,6 +180,9 @@ end
if minetest.get_modpath("achievements") ~= nil then
form_core = form_core .. default.ui.tab(-0.9, 2.84, "tab_achievements", "ui_icon_achievements.png", "Achievements")
end
if minetest.get_modpath("player_skins") ~= nil then
form_core = form_core .. default.ui.tab(-0.9, 3.62, "tab_player_skins", "ui_icon_player_skins.png", "Player Skins")
end
form_core = form_core .. "background[0,0;8.5,9;ui_formspec_bg_tall.png]"
default.ui.register_page("core", form_core)
default.ui.register_page("core_2part", form_core .. "background[0,0;8.5,4.5;ui_formspec_bg_short.png]")
@ -241,6 +244,8 @@ function default.ui.receive_fields(player, form_name, fields)
minetest.show_formspec(name, "core_armor", default.ui.get_page("core_armor"))
elseif minetest.get_modpath("achievements") ~= nil and fields.tab_achievements then
minetest.show_formspec(name, "core_achievements", achievements.get_formspec(name))
elseif minetest.get_modpath("player_skins") ~= nil and fields.tab_player_skins then
minetest.show_formspec(name, "core_player_skins", player_skins.get_formspec(name))
end
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 289 B

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 287 B

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 B

Binary file not shown.

View File

@ -6,6 +6,7 @@
player_skins = {}
player_skins.skin_names = {"male", "female"}
if minetest.setting_get("player_skins_names") then
player_skins.skin_names = util.split(minetest.setting_get("player_skins_names"), ",")
end
@ -113,6 +114,47 @@ local function get_chatparams()
return s .. "]"
end
function player_skins.get_formspec(playername)
local form = default.ui.get_page("core")
form = form .. "image[4,0;0.5,10.05;ui_vertical_divider.png]"
for i, name in ipairs(player_skins.skin_names) do
x = 0.25
y = i - 0.5
if i > 8 then
x = 4.5
y = y - 8
end
form = form .. default.ui.button(x, y, 2, 1, "skin_select_" .. name, player_skins.skin_names[i])
form = form .. "image[" .. (x + 2.25) .. "," .. y.. ";1,1;player_skins_icon_" .. name .. ".png]"
if player_skins.skins[playername] == name then
form = form .. "image[" .. (x + 3.25) .. "," .. (y + 0.25).. ";0.5,0.5;ui_checkmark.png]"
end
end
return form
end
default.ui.register_page("core_player_skins", form)
minetest.register_on_player_receive_fields(
function(player, form_name, fields)
local name = player:get_player_name()
for fieldname, val in pairs(fields) do
local skinname = string.match(fieldname, "skin_select_(.*)")
if skinname ~= nil then
player_skins.set_skin(name, skinname)
minetest.show_formspec(name, "core_player_skins", player_skins.get_formspec(name))
end
end
end)
minetest.register_privilege("player_skin", "Can change player skin")
minetest.register_chatcommand(
"player_skin",

Binary file not shown.

After

Width:  |  Height:  |  Size: 320 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 335 B

Binary file not shown.