1
0
Fork 0

mcl_skins: PR feedback

This commit is contained in:
parent 26f033932e
commit f1d17e2c69
6 changed files with 111 additions and 96 deletions

View File

@ -98,7 +98,19 @@ function mcl_player.player_set_model(player, model_name)
damage_texture_modifier = "^[colorize:red:130", damage_texture_modifier = "^[colorize:red:130",
}) })
update_player_textures(player) update_player_textures(player)
mcl_player.player_set_animation(player, "stand")
local new_anim = "stand"
local model_animations = models[model_name].animations
local old_anim = player_anim[name]
if model_animations and old_anim and model_animations[old_anim] then
new_anim = old_anim
end
mcl_player.player_set_animation(player, new_anim)
else
player:set_properties({
textures = { "player.png", "player_back.png", },
visual = "upright_sprite",
})
end end
end end

View File

@ -31,11 +31,11 @@ Coloring only works for "base", "bottom, "top", and "hair".
`preview_rotation` `preview_rotation`
A table containing properties x and y. x and y represent the x and y rotation of the item preview. A table containing properties x and y. x and y represent the x and y rotation of the item preview.
`alex` `template2`
If set to true the item will be default for female character. If set to true the item will be default for female template.
`steve` `template1`
If set to true the item will be default for male character. If set to true the item will be default for male template.
`rank` `rank`
This property is used to change the application order of the skin item when applied to a player. This property is used to change the application order of the skin item when applied to a player.
@ -60,10 +60,17 @@ headwear: 80
Lower ranks are applied to the player first and can thus be covered by higher rank items. Lower ranks are applied to the player first and can thus be covered by higher rank items.
### `mcl_skins.show_formspec(player)` ### `mcl_skins.show_formspec(player, active_tab, page_num)`
Show the skin configuration screen. Show the skin configuration screen.
`player` is a player ObjectRef. `player` is a player ObjectRef.
`active_tab` is the tab that will be displayed. This parameter is optional.
Can be one of: "arm", "base", "footwear", "eye", "mouth", "bottom", "top", "hair", "headwear"
`page_num` The page number to display of there are multiple pages of items.
This parameter is optional. Must be a number. If it is not a valid page number the closest page number will be shown.
### `mcl_skins.get_skin_list()` ### `mcl_skins.get_skin_list()`
This function is used by mods that want a list of skins to register nodes that use the player skin as a texture. This function is used by mods that want a list of skins to register nodes that use the player skin as a texture.
Returns an array of tables containing information about each skin. Returns an array of tables containing information about each skin.

View File

@ -1,5 +1,6 @@
local S = minetest.get_translator("mcl_skins") local S = minetest.get_translator("mcl_skins")
local color_to_string = minetest.colorspec_to_colorstring local color_to_string = minetest.colorspec_to_colorstring
local EDIT_SKIN_KEY = -1 -- The key used for edit skin in the mcl_skins.simple_skins table
mcl_skins = { mcl_skins = {
simple_skins = {}, simple_skins = {},
@ -19,8 +20,8 @@ mcl_skins = {
headwear = S("Headwears"), headwear = S("Headwears"),
skin = S("Skins"), skin = S("Skins"),
}, },
steve = {}, -- Stores skin values for Steve skin template1 = {}, -- Stores edit skin values for template1
alex = {}, -- Stores skin values for Alex skin template2 = {}, -- Stores edit skin values for template2
base = {}, -- List of base textures base = {}, -- List of base textures
-- Base color is separate to keep the number of junk nodes registered in check -- Base color is separate to keep the number of junk nodes registered in check
@ -59,12 +60,12 @@ mcl_skins = {
function mcl_skins.register_item(item) function mcl_skins.register_item(item)
assert(mcl_skins[item.type], "Skin item type " .. item.type .. " does not exist.") assert(mcl_skins[item.type], "Skin item type " .. item.type .. " does not exist.")
local texture = item.texture or "blank.png" local texture = item.texture or "blank.png"
if item.steve then if item.template1 then
mcl_skins.steve[item.type] = texture mcl_skins.template1[item.type] = texture
end end
if item.alex then if item.template2 then
mcl_skins.alex[item.type] = texture mcl_skins.template2[item.type] = texture
end end
table.insert(mcl_skins[item.type], texture) table.insert(mcl_skins[item.type], texture)
@ -96,7 +97,13 @@ end
minetest.register_chatcommand("skin", { minetest.register_chatcommand("skin", {
description = S("Open skin configuration screen."), description = S("Open skin configuration screen."),
privs = {}, privs = {},
func = function(name, param) mcl_skins.show_formspec(minetest.get_player_by_name(name)) end func = function(name, param)
local player = minetest.get_player_by_name(name)
local formspec_data = mcl_skins.player_formspecs[player]
local active_tab = formspec_data.active_tab
local page_num = formspec_data.page_num
mcl_skins.show_formspec(player, active_tab, page_num)
end
}) })
function mcl_skins.compile_skin(skin) function mcl_skins.compile_skin(skin)
@ -165,9 +172,9 @@ minetest.register_on_joinplayer(function(player)
mcl_skins.player_skins[player] = skin mcl_skins.player_skins[player] = skin
else else
if math.random() > 0.5 then if math.random() > 0.5 then
skin = table.copy(mcl_skins.steve) skin = table.copy(mcl_skins.template1)
else else
skin = table.copy(mcl_skins.alex) skin = table.copy(mcl_skins.template2)
end end
mcl_skins.player_skins[player] = skin mcl_skins.player_skins[player] = skin
end end
@ -193,11 +200,24 @@ minetest.register_on_leaveplayer(function(player)
mcl_skins.player_formspecs[player] = nil mcl_skins.player_formspecs[player] = nil
end) end)
function mcl_skins.show_formspec(player) local function calculate_page_count(tab)
if tab == "skin" then
return math.ceil((#mcl_skins.simple_skins + 2) / 8)
elseif mcl_skins[tab] then
return math.ceil(#mcl_skins[tab] / 16)
end
return 1
end
function mcl_skins.show_formspec(player, active_tab, page_num)
local formspec_data = mcl_skins.player_formspecs[player] local formspec_data = mcl_skins.player_formspecs[player]
local skin = mcl_skins.player_skins[player] local skin = mcl_skins.player_skins[player]
local active_tab = formspec_data.active_tab formspec_data.active_tab = active_tab
local page_num = formspec_data.page_num
local page_count = calculate_page_count(active_tab)
if page_num < 1 then page_num = 1 end
if page_num > page_count then page_num = page_count end
formspec_data.page_num = page_num
local formspec = "formspec_version[3]size[14.2,11]" local formspec = "formspec_version[3]size[14.2,11]"
@ -238,12 +258,12 @@ function mcl_skins.show_formspec(player)
local skin = table.copy(skin) local skin = table.copy(skin)
local simple_skins_id = skin.simple_skins_id local simple_skins_id = skin.simple_skins_id
skin.simple_skins_id = nil skin.simple_skins_id = nil
mcl_skins.simple_skins[-1] = { mcl_skins.simple_skins[EDIT_SKIN_KEY] = {
slim_arms = skin.slim_arms, slim_arms = skin.slim_arms,
texture = mcl_skins.compile_skin(skin), texture = mcl_skins.compile_skin(skin),
} }
simple_skins_id = simple_skins_id or simple_skins_id = simple_skins_id or
mcl_skins.simple_skins[-1].texture mcl_skins.simple_skins[EDIT_SKIN_KEY].texture
for i = page_start, page_end do for i = page_start, page_end do
local skin = mcl_skins.simple_skins[i] local skin = mcl_skins.simple_skins[i]
@ -269,22 +289,22 @@ function mcl_skins.show_formspec(player)
"button[" .. x .. "," .. y .. ";1.5,3;" .. i .. ";]" "button[" .. x .. "," .. y .. ";1.5,3;" .. i .. ";]"
end end
if page_start == -1 then if page_start == EDIT_SKIN_KEY then
formspec = formspec .. "image[4.85,1;0.8,0.8;mcl_skins_button.png]" formspec = formspec .. "image[4.85,1;0.8,0.8;mcl_skins_button.png]"
end end
elseif active_tab == "template" then elseif active_tab == "template" then
formspec = formspec .. formspec = formspec ..
"model[5,2;2,3;player_mesh;mcl_armor_character.b3d;" .. "model[5,2;2,3;player_mesh;mcl_armor_character.b3d;" ..
mcl_skins.compile_skin(mcl_skins.steve) .. mcl_skins.compile_skin(mcl_skins.template1) ..
",blank.png,blank.png;0,180;false;true;0,0]" .. ",blank.png,blank.png;0,180;false;true;0,0]" ..
"button[5,5.2;2,0.8;steve;" .. S("Select") .. "]" .. "button[5,5.2;2,0.8;template1;" .. S("Select") .. "]" ..
"model[7.5,2;2,3;player_mesh;mcl_armor_character_female.b3d;" .. "model[7.5,2;2,3;player_mesh;mcl_armor_character_female.b3d;" ..
mcl_skins.compile_skin(mcl_skins.alex) .. mcl_skins.compile_skin(mcl_skins.template2) ..
",blank.png,blank.png;0,180;false;true;0,0]" .. ",blank.png,blank.png;0,180;false;true;0,0]" ..
"button[7.5,5.2;2,0.8;alex;" .. S("Select") .. "]" "button[7.5,5.2;2,0.8;template2;" .. S("Select") .. "]"
elseif mcl_skins[active_tab] then elseif mcl_skins[active_tab] then
formspec = formspec .. formspec = formspec ..
@ -400,13 +420,6 @@ function mcl_skins.show_formspec(player)
end end
end end
local page_count = 1
if mcl_skins[active_tab] then
page_count = math.ceil(#mcl_skins[active_tab] / 16)
elseif active_tab == "skin" then
page_count = math.ceil((#mcl_skins.simple_skins + 2) / 8)
end
if page_num > 1 then if page_num > 1 then
formspec = formspec .. formspec = formspec ..
"image_button[4.5,6.7;1,1;mcl_skins_arrow.png^[transformFX;previous_page;]" "image_button[4.5,6.7;1,1;mcl_skins_arrow.png^[transformFX;previous_page;]"
@ -427,16 +440,17 @@ function mcl_skins.show_formspec(player)
end end
minetest.register_on_player_receive_fields(function(player, formname, fields) minetest.register_on_player_receive_fields(function(player, formname, fields)
local formspec_data = mcl_skins.player_formspecs[player]
local active_tab = formspec_data.active_tab
local page_num = formspec_data.page_num
if fields.__mcl_skins then if fields.__mcl_skins then
mcl_skins.show_formspec(player) mcl_skins.show_formspec(player, active_tab, page_num)
return false return false
end end
if formname ~= "mcl_skins:skins" then return false end if formname ~= "mcl_skins:skins" then return false end
local formspec_data = mcl_skins.player_formspecs[player]
local active_tab = formspec_data.active_tab
-- Cancel formspec resend after scrollbar move -- Cancel formspec resend after scrollbar move
if formspec_data.form_send_job then if formspec_data.form_send_job then
formspec_data.form_send_job:cancel() formspec_data.form_send_job:cancel()
@ -448,23 +462,21 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
return true return true
end end
if fields.alex then if fields.template2 then
mcl_skins.player_skins[player] = table.copy(mcl_skins.alex) mcl_skins.player_skins[player] = table.copy(mcl_skins.template2)
mcl_skins.update_player_skin(player) mcl_skins.update_player_skin(player)
mcl_skins.show_formspec(player) mcl_skins.show_formspec(player, active_tab, page_num)
return true return true
elseif fields.steve then elseif fields.template1 then
mcl_skins.player_skins[player] = table.copy(mcl_skins.steve) mcl_skins.player_skins[player] = table.copy(mcl_skins.template1)
mcl_skins.update_player_skin(player) mcl_skins.update_player_skin(player)
mcl_skins.show_formspec(player) mcl_skins.show_formspec(player, active_tab, page_num)
return true return true
end end
for i, tab in pairs(mcl_skins.tab_names) do for i, tab in pairs(mcl_skins.tab_names) do
if fields[tab] then if fields[tab] then
formspec_data.active_tab = tab mcl_skins.show_formspec(player, tab, 1)
formspec_data.page_num = 1
mcl_skins.show_formspec(player)
return true return true
end end
end end
@ -473,28 +485,12 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if not skin then return true end if not skin then return true end
if fields.next_page then if fields.next_page then
local page_num = formspec_data.page_num
page_num = page_num + 1 page_num = page_num + 1
mcl_skins.show_formspec(player, active_tab, page_num)
local page_count
if active_tab == "skin" then
page_count = math.ceil((#mcl_skins.simple_skins + 2) / 8)
else
page_count = math.ceil(#mcl_skins[active_tab] / 16)
end
if page_num > page_count then
page_num = page_count
end
formspec_data.page_num = page_num
mcl_skins.show_formspec(player)
return true return true
elseif fields.previous_page then elseif fields.previous_page then
local page_num = formspec_data.page_num
page_num = page_num - 1 page_num = page_num - 1
if page_num < 1 then page_num = 1 end mcl_skins.show_formspec(player, active_tab, page_num)
formspec_data.page_num = page_num
mcl_skins.show_formspec(player)
return true return true
end end
@ -505,7 +501,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
skin.slim_arms = true skin.slim_arms = true
end end
mcl_skins.update_player_skin(player) mcl_skins.update_player_skin(player)
mcl_skins.show_formspec(player) mcl_skins.show_formspec(player, active_tab, page_num)
return true return true
end end
@ -530,7 +526,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if player and player:is_player() then if player and player:is_player() then
skin[active_tab .. "_color"] = color skin[active_tab .. "_color"] = color
mcl_skins.update_player_skin(player) mcl_skins.update_player_skin(player)
mcl_skins.show_formspec(player) mcl_skins.show_formspec(player, active_tab, page_num)
formspec_data.form_send_job = nil formspec_data.form_send_job = nil
end end
end) end)
@ -549,14 +545,14 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if field and active_tab == "skin" then if field and active_tab == "skin" then
local index = tonumber(field) local index = tonumber(field)
index = index and math.floor(index) or 0 index = index and math.floor(index) or 0
mcl_skins.simple_skins[-1].texture = nil mcl_skins.simple_skins[EDIT_SKIN_KEY].texture = nil
if if
#mcl_skins.simple_skins > 0 and #mcl_skins.simple_skins > 0 and
index >= -1 and index <= #mcl_skins.simple_skins index >= EDIT_SKIN_KEY and index <= #mcl_skins.simple_skins
then then
skin.simple_skins_id = mcl_skins.simple_skins[index].texture skin.simple_skins_id = mcl_skins.simple_skins[index].texture
mcl_skins.update_player_skin(player) mcl_skins.update_player_skin(player)
mcl_skins.show_formspec(player) mcl_skins.show_formspec(player, active_tab, page_num)
end end
return true return true
end end
@ -568,7 +564,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
then then
skin[active_tab] = field skin[active_tab] = field
mcl_skins.update_player_skin(player) mcl_skins.update_player_skin(player)
mcl_skins.show_formspec(player) mcl_skins.show_formspec(player, active_tab, page_num)
return true return true
end end
@ -579,7 +575,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if color and color >= 0 and color <= 0xffffffff then if color and color >= 0 and color <= 0xffffffff then
skin[active_tab .. "_color"] = color skin[active_tab .. "_color"] = color
mcl_skins.update_player_skin(player) mcl_skins.update_player_skin(player)
mcl_skins.show_formspec(player) mcl_skins.show_formspec(player, active_tab, page_num)
return true return true
end end
end end
@ -599,17 +595,17 @@ local function init()
for _, item in pairs(json) do for _, item in pairs(json) do
mcl_skins.register_item(item) mcl_skins.register_item(item)
end end
mcl_skins.steve.base_color = mcl_skins.base_color[2] mcl_skins.template1.base_color = mcl_skins.base_color[2]
mcl_skins.steve.hair_color = 0xff5d473b mcl_skins.template1.hair_color = 0xff5d473b
mcl_skins.steve.top_color = 0xff993535 mcl_skins.template1.top_color = 0xff993535
mcl_skins.steve.bottom_color = 0xff644939 mcl_skins.template1.bottom_color = 0xff644939
mcl_skins.steve.slim_arms = false mcl_skins.template1.slim_arms = false
mcl_skins.alex.base_color = mcl_skins.base_color[1] mcl_skins.template2.base_color = mcl_skins.base_color[1]
mcl_skins.alex.hair_color = 0xff715d57 mcl_skins.template2.hair_color = 0xff715d57
mcl_skins.alex.top_color = 0xff346840 mcl_skins.template2.top_color = 0xff346840
mcl_skins.alex.bottom_color = 0xff383532 mcl_skins.template2.bottom_color = 0xff383532
mcl_skins.alex.slim_arms = true mcl_skins.template2.slim_arms = true
mcl_skins.register_simple_skin({ mcl_skins.register_simple_skin({
index = 0, index = 0,

View File

@ -2,8 +2,8 @@
{ {
"type": "footwear", "type": "footwear",
"texture": "mcl_skins_footwear_1.png", "texture": "mcl_skins_footwear_1.png",
"steve": true, "template1": true,
"alex": true, "template2": true,
"rank": 55 "rank": 55
}, },
{ {
@ -20,12 +20,12 @@
{ {
"type": "eye", "type": "eye",
"texture": "mcl_skins_eye_1.png", "texture": "mcl_skins_eye_1.png",
"alex": true "template2": true
}, },
{ {
"type": "eye", "type": "eye",
"texture": "mcl_skins_eye_2.png", "texture": "mcl_skins_eye_2.png",
"steve": true "template1": true
}, },
{ {
"type": "eye", "type": "eye",
@ -50,7 +50,7 @@
{ {
"type": "mouth", "type": "mouth",
"texture": "mcl_skins_mouth_1.png", "texture": "mcl_skins_mouth_1.png",
"steve": true "template1": true
}, },
{ {
"type": "mouth", "type": "mouth",
@ -78,19 +78,19 @@
}, },
{ {
"type": "mouth", "type": "mouth",
"alex": true "template1": true
}, },
{ {
"type": "hair", "type": "hair",
"texture": "mcl_skins_hair_1.png", "texture": "mcl_skins_hair_1.png",
"mask": "mcl_skins_hair_1_mask.png", "mask": "mcl_skins_hair_1_mask.png",
"alex": true "template2": true
}, },
{ {
"type": "hair", "type": "hair",
"texture": "mcl_skins_hair_2.png", "texture": "mcl_skins_hair_2.png",
"mask": "mcl_skins_hair_2_mask.png", "mask": "mcl_skins_hair_2_mask.png",
"steve": true "template1": true
}, },
{ {
"type": "hair", "type": "hair",
@ -147,7 +147,7 @@
{ {
"type": "headwear", "type": "headwear",
"texture": "mcl_skins_headwear_2.png", "texture": "mcl_skins_headwear_2.png",
"alex": true "template2": true
}, },
{ {
"type": "headwear", "type": "headwear",
@ -175,14 +175,14 @@
}, },
{ {
"type": "headwear", "type": "headwear",
"steve": true "template1": true
}, },
{ {
"type": "bottom", "type": "bottom",
"texture": "mcl_skins_bottom_1.png", "texture": "mcl_skins_bottom_1.png",
"mask": "mcl_skins_bottom_1_mask.png", "mask": "mcl_skins_bottom_1_mask.png",
"steve": true, "template1": true,
"alex": true "template2": true
}, },
{ {
"type": "bottom", "type": "bottom",
@ -209,8 +209,8 @@
"type": "top", "type": "top",
"texture": "mcl_skins_top_1.png", "texture": "mcl_skins_top_1.png",
"mask": "mcl_skins_top_1_mask.png", "mask": "mcl_skins_top_1_mask.png",
"steve": true, "template1": true,
"alex": true "template2": true
}, },
{ {
"type": "top", "type": "top",
@ -261,7 +261,7 @@
"type": "base", "type": "base",
"texture": "mcl_skins_base_1.png", "texture": "mcl_skins_base_1.png",
"mask": "mcl_skins_base_1_mask.png", "mask": "mcl_skins_base_1_mask.png",
"steve": true, "template1": true,
"alex": true "template2": true
} }
] ]

BIN
textures/player.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 419 B

BIN
textures/player_back.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 307 B