forked from Sokomine/yl_speak_up
rewrote fasion_extended formspec
This commit is contained in:
parent
533c382ee4
commit
e062eec580
@ -51,6 +51,8 @@ yl_speak_up.mesh_data["skinsdb_3d_armor_character_5.b3d"] = {
|
||||
-- diffrent mob types may want to wear diffrent skins - even if they share the
|
||||
-- same model/mesh
|
||||
yl_speak_up.mob_skins = {}
|
||||
-- some models support capes
|
||||
yl_speak_up.mob_capes = {}
|
||||
|
||||
-- mobs_redo usually uses 64 x 32 textures:
|
||||
yl_speak_up.mob_skins["mobs_npc:npc"] = {
|
||||
@ -64,6 +66,9 @@ yl_speak_up.mob_skins["mobs_npc:trader"] = {
|
||||
-- this here uses 64 x 64 textures:
|
||||
yl_speak_up.mob_skins["yl_speak_up:human"] = {
|
||||
"yl_speak_up_main_default.png", "some_skin.png", "2022_06_28_the-lonley-lumberjack-20494635.png"}
|
||||
-- which capes can an NPC wear?
|
||||
yl_speak_up.mob_capes["yl_speak_up:human"] = {
|
||||
"yl_npc_cape_default.png"}
|
||||
|
||||
|
||||
-- some mobs (in particular from mobs_redo) can switch between follow (their owner),
|
||||
|
162
fs_fashion.lua
162
fs_fashion.lua
@ -39,31 +39,27 @@ end
|
||||
|
||||
|
||||
-- this makes use of the "model" option of formspecs
|
||||
yl_speak_up.skin_preview_3d = function(mesh, textures)
|
||||
yl_speak_up.skin_preview_3d = function(mesh, textures, where_front, where_back)
|
||||
local tstr = ""
|
||||
for i, t in ipairs(textures) do
|
||||
tstr = tstr..minetest.formspec_escape(t)..","
|
||||
end
|
||||
return "container[0.5,0.5]"..
|
||||
"model[2,1;6,12;skin_animation_front;"..mesh..";"..tstr..";0,180;false;true;;]"..
|
||||
"model[8,1;6,12;skin_animation_back;"..mesh..";"..tstr..";0,0;false;true;;]"..
|
||||
"container_end[]"
|
||||
local backside = ""
|
||||
if(where_back) then
|
||||
backside = ""..
|
||||
"model["..where_back..";skin_show_back;"..mesh..";"..tstr..";0,0;false;true;;]"
|
||||
end
|
||||
return "model["..where_front..";skin_show_front;"..mesh..";"..tstr..";0,180;false;true;;]"..
|
||||
backside
|
||||
end
|
||||
|
||||
|
||||
-- this is a suitable version for most models/meshes that use normal player skins
|
||||
-- (i.e. mobs_redo) with skins in either 64 x 32 or 64 x 64 MC skin format
|
||||
yl_speak_up.skin_preview_normal = function(skin)
|
||||
return "image[3,0.7;2,2;[combine:8x8:-8,-8="..skin.."]"..
|
||||
"image[2.85,0.55;2.3,2.3;[combine:8x8:-40,-8="..skin.."]".. -- head, beard
|
||||
"image[3,2.75;2,3;[combine:8x12:-20,-20="..skin..":-20,-36="..skin.."]".. -- body
|
||||
"image[3,5.75;1,3;[combine:4x12:-4,-20="..skin..":-4,-36="..skin.."]".. -- left leg + ov
|
||||
"image[4,5.75;1,3;[combine:4x12:-4,-20="..skin.."^[transformFX]".. -- right leg
|
||||
"image[4,5.75;1,3;[combine:4x12:-20,-52="..skin..":-4,-52="..skin.."]".. -- right leg ov
|
||||
"image[2.0,2.75;1,3;[combine:4x12:-44,-20="..skin..":-44,-36="..skin.."]".. -- left hand
|
||||
"image[5.0,2.75;1,3;[combine:4x12:-44,-20="..skin.."^[transformFX]".. -- right hand
|
||||
"image[5.0,2.75;1,3;[combine:4x12:-36,-52="..skin..":-52,-52="..skin.."]".. -- right hand ov
|
||||
|
||||
yl_speak_up.skin_preview_normal = function(skin, with_backside)
|
||||
local backside = ""
|
||||
if(with_backside) then
|
||||
backside = ""..
|
||||
"image[8,0.7;2,2;[combine:8x8:-24,-8="..skin.."]".. -- back head
|
||||
"image[7.85,0.55;2.3,2.3;[combine:8x8:-56,-8="..skin.."]".. -- head, beard
|
||||
"image[8,2.75;2,3;[combine:8x12:-32,-20="..skin..":-32,-36="..skin.."]".. -- body back
|
||||
@ -73,9 +69,19 @@ yl_speak_up.skin_preview_normal = function(skin)
|
||||
"image[9,5.75;1,3;[combine:4x12:-12,-36="..skin.."]".. -- right leg back ov
|
||||
"image[7,2.75;1,3;[combine:4x12:-52,-20="..skin..":-40,-52="..skin..":-60,-52="..skin.."]".. -- l. hand back ov
|
||||
"image[10,2.75;1,3;[combine:4x12:-52,-20="..skin.."^[transformFX]".. -- right hand back
|
||||
"image[10,2.75;1,3;[combine:4x12:-52,-20="..skin..":-52,-36="..skin.."]".. -- left hand back
|
||||
"image[10,2.75;1,3;[combine:4x12:-52,-20="..skin..":-52,-36="..skin.."]" -- left hand back
|
||||
end
|
||||
return "image[3,0.7;2,2;[combine:8x8:-8,-8="..skin.."]"..
|
||||
"image[2.85,0.55;2.3,2.3;[combine:8x8:-40,-8="..skin.."]".. -- head, beard
|
||||
"image[3,2.75;2,3;[combine:8x12:-20,-20="..skin..":-20,-36="..skin.."]".. -- body
|
||||
"image[3,5.75;1,3;[combine:4x12:-4,-20="..skin..":-4,-36="..skin.."]".. -- left leg + ov
|
||||
"image[4,5.75;1,3;[combine:4x12:-4,-20="..skin.."^[transformFX]".. -- right leg
|
||||
"image[4,5.75;1,3;[combine:4x12:-20,-52="..skin..":-4,-52="..skin.."]".. -- right leg ov
|
||||
"image[2.0,2.75;1,3;[combine:4x12:-44,-20="..skin..":-44,-36="..skin.."]".. -- left hand
|
||||
"image[5.0,2.75;1,3;[combine:4x12:-44,-20="..skin.."^[transformFX]".. -- right hand
|
||||
"image[5.0,2.75;1,3;[combine:4x12:-36,-52="..skin..":-52,-52="..skin.."]".. -- right hand ov
|
||||
backside
|
||||
|
||||
""
|
||||
--local legs_back = "[combine:4x12:-12,-20="..skins.skins[name]..".png"
|
||||
end
|
||||
|
||||
@ -255,7 +261,7 @@ end
|
||||
|
||||
|
||||
-- TODO: link that somehow for NPC that support it
|
||||
yl_speak_up.get_fs_fashion_extended = function(pname)
|
||||
yl_speak_up.get_fs_fashion_extended_orig = function(pname)
|
||||
local textures = yl_speak_up.speak_to[pname].textures
|
||||
|
||||
local maintable, mainlist, mainindex = get_npc_skins(textures[2])
|
||||
@ -326,6 +332,100 @@ yl_speak_up.get_fs_fashion_extended = function(pname)
|
||||
end
|
||||
|
||||
|
||||
yl_speak_up.get_fs_fashion_extended = function(pname)
|
||||
-- which texture from the textures list are we talking about?
|
||||
-- this depends on the model!
|
||||
local mesh = yl_speak_up.get_mesh(pname)
|
||||
local texture_index = yl_speak_up.mesh_data[mesh].texture_index
|
||||
if(not(texture_index)) then
|
||||
texture_index = 1
|
||||
end
|
||||
|
||||
local textures = yl_speak_up.speak_to[pname].textures
|
||||
local skin = (textures[texture_index] or "")
|
||||
|
||||
-- which skins are available? this depends on mob_type
|
||||
local mob_type = yl_speak_up.get_mob_type(pname)
|
||||
local skins = yl_speak_up.mob_skins[mob_type] or {skin}
|
||||
local capes = yl_speak_up.mob_capes[mob_type] or {}
|
||||
local cape = "" -- TODO
|
||||
|
||||
-- is this player editing this particular NPC? then rename the button
|
||||
if(not(yl_speak_up.edit_mode[pname])
|
||||
or yl_speak_up.edit_mode[pname] ~= yl_speak_up.speak_to[pname].n_id) then
|
||||
return "label[Error. Not in Edit mode!]"
|
||||
end
|
||||
|
||||
local cape_list = table.concat(capes, ",")
|
||||
local cape_index = table.indexof(capes, cape)
|
||||
if(cape_index == -1) then
|
||||
cape_index = ""
|
||||
end
|
||||
|
||||
local tmp_textures = textures
|
||||
if(texture_index ~= 1) then
|
||||
tmp_textures = textures2skin(textures)
|
||||
end
|
||||
local preview = yl_speak_up.skin_preview_3d(mesh, tmp_textures, "4.7,0.5;5,10", nil)
|
||||
|
||||
-- local preview = create_preview(textures[2])
|
||||
|
||||
local button_cancel = "Cancel"
|
||||
-- is this player editing this particular NPC? then rename the button
|
||||
if( yl_speak_up.edit_mode[pname]
|
||||
and yl_speak_up.edit_mode[pname] == yl_speak_up.speak_to[pname].n_id) then
|
||||
button_cancel = "Back"
|
||||
end
|
||||
local formspec = {
|
||||
"size[13.4,15]",
|
||||
"label[0.3,0.2;Skin: ",
|
||||
minetest.formspec_escape(skin),
|
||||
"]",
|
||||
"label[4.6,0.65;",
|
||||
yl_speak_up.speak_to[pname].n_id,
|
||||
"]",
|
||||
"label[6,0.65;",
|
||||
(yl_speak_up.speak_to[pname].n_npc or "- nameless -"),
|
||||
"]",
|
||||
"dropdown[9.1,0.2;4,0.75;set_cape;",
|
||||
cape_list, ";", cape_index, "]",
|
||||
"label[0.3,4.2;Left:]",
|
||||
"label[9.1,4.2;Right:]",
|
||||
"field_close_on_enter[set_sword;false]",
|
||||
"field_close_on_enter[set_shield;false]",
|
||||
"image[9.1,1;4,2;",
|
||||
textures[1] or "",
|
||||
"]", -- Cape
|
||||
"image[0.3,4.2;4,4;",
|
||||
textures[4] or "",
|
||||
"]", -- Sword
|
||||
"image[9.1,4.2;4,4;",
|
||||
textures[3] or "",
|
||||
"]", --textures[3],"]", -- Shield
|
||||
"tooltip[0.3,4.2;4,4;This is: ",
|
||||
minetest.formspec_escape(textures[4]),
|
||||
"]",
|
||||
"tooltip[9.1,4.2;4,4;This is: ",
|
||||
minetest.formspec_escape(textures[3]),
|
||||
"]",
|
||||
preview or "",
|
||||
"button[0.3,8.4;3,0.75;button_cancel;"..button_cancel.."]",
|
||||
"button[10.1,8.4;3,0.75;button_save;Save]",
|
||||
"list[current_player;main;1.8,10;8,4;]",
|
||||
-- set wielded items
|
||||
"label[0.3,9.7;Wield\nleft:]",
|
||||
"label[12.0,9.7;Wield\nright:]",
|
||||
"list[detached:yl_speak_up_player_"..tostring(pname)..";wield;0.3,10.5;1,1;]",
|
||||
"list[detached:yl_speak_up_player_"..tostring(pname)..";wield;12.0,10.5;1,1;1]",
|
||||
"button[0.3,11.7;1,0.6;button_wield_left;Set]",
|
||||
"button[12.0,11.7;1,0.6;button_wield_right;Set]",
|
||||
"tooltip[button_wield_left;Set and store what your NPC shall wield in its left hand.]",
|
||||
"tooltip[button_wield_right;Set and store what your NPC shall wield in its right hand.]",
|
||||
}
|
||||
return table.concat(formspec, "")
|
||||
end
|
||||
|
||||
|
||||
yl_speak_up.fashion_wield_give_items_back = function(player, pname)
|
||||
-- move the item back to the player's inventory (if possible)
|
||||
local trade_inv = minetest.get_inventory({type="detached", name="yl_speak_up_player_"..pname})
|
||||
@ -474,7 +574,8 @@ yl_speak_up.input_fashion_extended = function(player, formname, fields)
|
||||
end
|
||||
|
||||
-- catch ESC as well
|
||||
if(not(fields) or (fields.quit or fields.button_cancel or fields.button_exit)) then
|
||||
if(not(fields)
|
||||
or (fields.quit or fields.button_cancel or fields.button_exit or fields.button_save)) then
|
||||
yl_speak_up.fashion_wield_give_items_back(player, pname)
|
||||
yl_speak_up.show_fs(player, "fashion")
|
||||
return
|
||||
@ -511,19 +612,6 @@ yl_speak_up.input_fashion_extended = function(player, formname, fields)
|
||||
end
|
||||
end
|
||||
|
||||
-- only change the skin if there really is a diffrent new one selected
|
||||
elseif(fields.set_skin and fields.set_skin ~= textures[2]) then
|
||||
-- only set the skin if it is part of the list of allowed skins
|
||||
local maintable, mainlist, mainindex = get_npc_skins(textures[2])
|
||||
for _, v in pairs(maintable) do
|
||||
if(v == fields.set_skin) then
|
||||
textures[2] = fields.set_skin
|
||||
yl_speak_up.log_change(pname, n_id,
|
||||
"(fashion) skin changed to "..tostring(fields.set_skin)..".")
|
||||
-- we have found it
|
||||
break
|
||||
end
|
||||
end
|
||||
elseif fields.button_save then
|
||||
local obj = yl_speak_up.speak_to[pname].obj
|
||||
if obj ~= nil and obj:get_luaentity() ~= nil then
|
||||
@ -535,6 +623,10 @@ yl_speak_up.input_fashion_extended = function(player, formname, fields)
|
||||
end
|
||||
yl_speak_up.fashion_wield_give_items_back(player, pname)
|
||||
end
|
||||
if(fields.button_wield_left or fields.button_wield_right or fields.set_cape) then
|
||||
yl_speak_up.show_fs(player, "fashion_extended")
|
||||
return
|
||||
end
|
||||
yl_speak_up.show_fs(player, "fashion")
|
||||
end
|
||||
|
||||
@ -635,9 +727,9 @@ yl_speak_up.get_fs_fashion = function(pname)
|
||||
|
||||
local tmp_textures = textures
|
||||
if(texture_index ~= 1) then
|
||||
textures = textures2skin(textures)
|
||||
tmp_textures = textures2skin(textures)
|
||||
end
|
||||
local preview = yl_speak_up.skin_preview_3d(mesh, textures)
|
||||
local preview = yl_speak_up.skin_preview_3d(mesh, tmp_textures, "2,1;6,12", "8,1;6,12")
|
||||
-- local preview = yl_speak_up.mesh_data[mesh].skin_preview(skin)
|
||||
|
||||
local formspec = {
|
||||
|
Loading…
Reference in New Issue
Block a user