added animation setting to edit skin menu

This commit is contained in:
Sokomine 2023-06-15 06:05:54 +02:00
parent 22ce6fb623
commit 70d81c2bd7
4 changed files with 79 additions and 2 deletions

View File

@ -37,6 +37,16 @@ yl_speak_up.mesh_data["mobs_character.b3d"] = {
can_show_wielded_items = false, can_show_wielded_items = false,
-- textures are applied directly -- textures are applied directly
textures_to_skin = false, textures_to_skin = false,
animation = {
-- {x = start_frame, y = end_frame, collisionbox}
stand_still = {x = 0, y = 0, collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3}},
stand = {x = 0, y = 79, collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3}},
sit = {x = 81, y = 160, collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.0, 0.3}},
lay = {x = 162, y = 166, collisionbox = {-0.6, 0.0, -0.6, 0.6, 0.3, 0.6}},
walk = {x = 168, y = 187, collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3}},
mine = {x = 189, y = 198, collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3}},
walk_mine = {x = 200, y = 219, collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3}},
},
} }
yl_speak_up.mesh_data["skinsdb_3d_armor_character_5.b3d"] = { yl_speak_up.mesh_data["skinsdb_3d_armor_character_5.b3d"] = {
-- the second texture is the skin -- the second texture is the skin
@ -45,6 +55,17 @@ yl_speak_up.mesh_data["skinsdb_3d_armor_character_5.b3d"] = {
can_show_wielded_items = true, can_show_wielded_items = true,
-- call textures2skin in order to convert the textures (wielded items) -- call textures2skin in order to convert the textures (wielded items)
textures_to_skin = true, textures_to_skin = true,
animation = {
-- {x = start_frame, y = end_frame, collisionbox}
stand_still = {x = 0, y = 0, collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3}},
stand = {x = 0, y = 79, collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3}},
sit = {x = 81, y = 160, collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.0, 0.3}},
lay = {x = 162, y = 166, collisionbox = {-0.6, 0.0, -0.6, 0.6, 0.3, 0.6}},
walk = {x = 168, y = 187, collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3}},
mine = {x = 189, y = 198, collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3}},
walk_mine = {x = 200, y = 219, collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3}},
},
} }
yl_speak_up.mesh_data["mobs_sheep.b3d"] = { yl_speak_up.mesh_data["mobs_sheep.b3d"] = {
texture_index = 1, texture_index = 1,

View File

@ -38,6 +38,7 @@ yl_speak_up.get_mob_type = function(pname)
end end
-- this makes use of the "model" option of formspecs -- this makes use of the "model" option of formspecs
yl_speak_up.skin_preview_3d = function(mesh, textures, where_front, where_back) yl_speak_up.skin_preview_3d = function(mesh, textures, where_front, where_back)
local tstr = "" local tstr = ""
@ -49,7 +50,7 @@ yl_speak_up.skin_preview_3d = function(mesh, textures, where_front, where_back)
backside = "".. backside = ""..
"model["..where_back..";skin_show_back;"..mesh..";"..tstr..";0,0;false;true;;]" "model["..where_back..";skin_show_back;"..mesh..";"..tstr..";0,0;false;true;;]"
end end
return "model["..where_front..";skin_show_front;"..mesh..";"..tstr..";0,180;false;true;;]".. return "model["..where_front..";skin_show_front;"..mesh..";"..tstr..";0,180;false;true;;]"..--"0,300;9]".. -- ;]"..
backside backside
end end
@ -342,6 +343,20 @@ yl_speak_up.input_fashion = function(player, formname, fields)
textures[texture_index] = new_skin textures[texture_index] = new_skin
yl_speak_up.mesh_update_textures(pname, textures) yl_speak_up.mesh_update_textures(pname, textures)
end end
if(fields.set_animation
and yl_speak_up.mesh_data[mesh]
and yl_speak_up.mesh_data[mesh].animation
and yl_speak_up.mesh_data[mesh].animation[fields.set_animation]
and yl_speak_up.speak_to[pname]
and yl_speak_up.speak_to[pname].obj) then
local obj = yl_speak_up.speak_to[pname].obj
obj:set_animation(yl_speak_up.mesh_data[mesh].animation[fields.set_animation])
-- store the animation so that it can be restored on reload
local entity = obj:get_luaentity()
if(entity) then
entity.yl_speak_up.animation = yl_speak_up.mesh_data[mesh].animation[fields.set_animation]
end
end
if(fields.button_old_skin or fields.button_store_new_skin) then if(fields.button_old_skin or fields.button_store_new_skin) then
yl_speak_up.speak_to[pname].old_texture = nil yl_speak_up.speak_to[pname].old_texture = nil
yl_speak_up.show_fs(player, "talk", {n_id = yl_speak_up.speak_to[pname].n_id, yl_speak_up.show_fs(player, "talk", {n_id = yl_speak_up.speak_to[pname].n_id,
@ -540,8 +555,39 @@ yl_speak_up.get_fs_fashion = function(pname)
"tooltip[set_skin_normal;Select a skin from the list.]", "tooltip[set_skin_normal;Select a skin from the list.]",
preview, preview,
-- we add a special button for setting the skin in the player answer/reply window -- we add a special button for setting the skin in the player answer/reply window
"container_end[]",
} }
if(yl_speak_up.mesh_data[mesh].animation
and yl_speak_up.speak_to[pname]
and yl_speak_up.speak_to[pname].obj) then
local anim_list = {}
for k, v in pairs(yl_speak_up.mesh_data[mesh].animation) do
table.insert(anim_list, k)
end
table.sort(anim_list)
-- which animation is the NPC currently running?
local obj = yl_speak_up.speak_to[pname].obj
local curr_anim = obj:get_animation(pname)
local anim = ""
-- does the current animation match any stored one?
for k, v in pairs(yl_speak_up.mesh_data[mesh].animation) do
if(v.x and v.y and curr_anim and curr_anim.x and curr_anim.y
and v.x == curr_anim.x and v.y == curr_anim.y) then
anim = k
end
end
local anim_index = table.indexof(anim_list, anim)
if(anim_index == -1) then
anim_index = "1"
end
table.insert(formspec, "label[0.75,16.4;Do the following animation:]")
table.insert(formspec, "dropdown[0.75,16.9;16.25,1.5;set_animation;")
table.insert(formspec, table.concat(anim_list, ','))
table.insert(formspec, ";")
table.insert(formspec, tostring(anim_index) or "")
table.insert(formspec, "]")
end
table.insert(formspec, "container_end[]")
local left_window = table.concat(formspec, "") local left_window = table.concat(formspec, "")
formspec = {} formspec = {}
local h = -0.8 local h = -0.8

View File

@ -613,6 +613,12 @@ function yl_speak_up.talk(self, clicker)
dialog.trades = {} dialog.trades = {}
end end
-- some NPC may have reset the animation; at least set it to the desired
-- value whenever we talk to the NPC
if self.yl_speak_up and self.yl_speak_up.animation then
self.object:set_animation(self.yl_speak_up.animation)
end
yl_speak_up.show_fs(clicker, "talk", {n_id = n_id}) yl_speak_up.show_fs(clicker, "talk", {n_id = n_id})
end end

View File

@ -78,6 +78,10 @@ function yl_speak_up.after_activate(self, staticdata, def, dtime)
self.object:set_properties({textures = {tex[1], tex[2], tex[3], tex[4]}}) self.object:set_properties({textures = {tex[1], tex[2], tex[3], tex[4]}})
end end
if self.yl_speak_up and self.yl_speak_up.animation then
self.object:set_animation(self.yl_speak_up.animation)
end
if yl_speak_up.infotext then if yl_speak_up.infotext then
local i_text = "" local i_text = ""
if self.yl_speak_up.npc_name then if self.yl_speak_up.npc_name then