diff --git a/config.lua b/config.lua index 6430dc5..02a8654 100644 --- a/config.lua +++ b/config.lua @@ -37,6 +37,16 @@ yl_speak_up.mesh_data["mobs_character.b3d"] = { can_show_wielded_items = false, -- textures are applied directly 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"] = { -- 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, -- call textures2skin in order to convert the textures (wielded items) 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"] = { texture_index = 1, diff --git a/fs_fashion.lua b/fs_fashion.lua index b27f04e..437f170 100644 --- a/fs_fashion.lua +++ b/fs_fashion.lua @@ -38,6 +38,7 @@ yl_speak_up.get_mob_type = function(pname) end + -- this makes use of the "model" option of formspecs yl_speak_up.skin_preview_3d = function(mesh, textures, where_front, where_back) local tstr = "" @@ -49,7 +50,7 @@ yl_speak_up.skin_preview_3d = function(mesh, textures, where_front, where_back) 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;;]".. + return "model["..where_front..";skin_show_front;"..mesh..";"..tstr..";0,180;false;true;;]"..--"0,300;9]".. -- ;]".. backside end @@ -342,6 +343,20 @@ yl_speak_up.input_fashion = function(player, formname, fields) textures[texture_index] = new_skin yl_speak_up.mesh_update_textures(pname, textures) 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 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, @@ -540,8 +555,39 @@ yl_speak_up.get_fs_fashion = function(pname) "tooltip[set_skin_normal;Select a skin from the list.]", preview, -- 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, "") formspec = {} local h = -0.8 diff --git a/functions.lua b/functions.lua index 3758ece..215dd39 100644 --- a/functions.lua +++ b/functions.lua @@ -613,6 +613,12 @@ function yl_speak_up.talk(self, clicker) dialog.trades = {} 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}) end diff --git a/interface_mobs_api.lua b/interface_mobs_api.lua index 3e42b0b..8660f24 100644 --- a/interface_mobs_api.lua +++ b/interface_mobs_api.lua @@ -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]}}) 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 local i_text = "" if self.yl_speak_up.npc_name then