推
This commit is contained in:
@@ -22,21 +22,20 @@ void Chr_Animation::CreateSkinmationBySlot(std::string actionName, std::string s
|
||||
if (slotName == "skin_avatar")
|
||||
{
|
||||
// 如果穿戴了皮肤时装 读取variation
|
||||
RefPtr<Equipment> Equip = ((CharacterObject *)m_Parent)->_EquipmentManager->GetEquip(slotName);
|
||||
RefPtr<Equipment> Equip = ((CharacterObject *)GetParent())->_EquipmentManager->GetEquip(slotName);
|
||||
if (Equip)
|
||||
{
|
||||
Animation::ReplaceData Data(0, 0);
|
||||
|
||||
for (auto &Variation : Equip->JobAni[this->chr_parent->Job])
|
||||
{
|
||||
Data.Param1 = Variation.ImgFormat[0];
|
||||
Data.Param2 = Variation.ImgFormat[1];
|
||||
// 构造好Ani以后 统一设置为不可见 然后放入ActionAnis表
|
||||
// 构造Ani
|
||||
RefPtr<Animation> Ani = new Animation(path, FormatImgPath, Data);
|
||||
Ani->SetVisible(false);
|
||||
|
||||
Ani->SetRenderZOrder(Variation.Layer);
|
||||
this->AddChild(Ani);
|
||||
ActionAnis[actionName].push_back(Ani);
|
||||
Ani->SetZOrder(Variation.Layer);
|
||||
// 将构造好的Ani 添加进AniMap
|
||||
ActionAnis[actionName]->AddAnimation(Ani);
|
||||
|
||||
// 构造一下阴影对象 //TODO
|
||||
// RefPtr<Animation> ShadowAni = new Animation(path, FormatImgPath, Data);
|
||||
@@ -49,10 +48,9 @@ void Chr_Animation::CreateSkinmationBySlot(std::string actionName, std::string s
|
||||
}
|
||||
else
|
||||
{
|
||||
RefPtr<Equipment> Equip = ((CharacterObject *)m_Parent)->_EquipmentManager->GetEquip(slotName);
|
||||
RefPtr<Equipment> Equip = ((CharacterObject *)GetParent())->_EquipmentManager->GetEquip(slotName);
|
||||
if (Equip)
|
||||
{
|
||||
// SDL_Log("CreateSkinmationBySlot %s", slotName.c_str());
|
||||
Animation::ReplaceData Data(0, 0);
|
||||
for (auto &Variation : Equip->JobAni[this->chr_parent->Job])
|
||||
{
|
||||
@@ -64,12 +62,11 @@ void Chr_Animation::CreateSkinmationBySlot(std::string actionName, std::string s
|
||||
// 组装动画路径
|
||||
std::string AniPath = EquipPath + Variation.AnimationGroup + path.substr(path.find_last_of("/"), path.length());
|
||||
|
||||
// 构造好Ani以后 统一设置为不可见 然后放入ActionAnis表
|
||||
// 构造Ani
|
||||
RefPtr<Animation> Ani = new Animation(AniPath, FormatImgPath, Data);
|
||||
Ani->SetVisible(false);
|
||||
Ani->SetRenderZOrder(Variation.Layer);
|
||||
this->AddChild(Ani);
|
||||
ActionAnis[actionName].push_back(Ani);
|
||||
Ani->SetZOrder(Variation.Layer);
|
||||
// 将构造好的Ani 添加进AniMap
|
||||
ActionAnis[actionName]->AddAnimation(Ani);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,24 +74,30 @@ void Chr_Animation::CreateSkinmationBySlot(std::string actionName, std::string s
|
||||
|
||||
void Chr_Animation::Init(CharacterObject *parent)
|
||||
{
|
||||
// 调用RenderBase类的初始化 才能挂上标签
|
||||
RenderBase::Init();
|
||||
parent->AddChild(this);
|
||||
chr_parent = parent;
|
||||
GlobalCharacterScript::CharacterConfig Config = Global_Game::GetInstance().CharacterConfigs[parent->Job];
|
||||
|
||||
|
||||
// 遍历所有动作Ani路径
|
||||
for (const auto &pair : Config.animationPath)
|
||||
{
|
||||
std::string ActionName = pair.first;
|
||||
std::string Path = std::string("character/" + Config.jobTag + "/" + Tool_toLowerCase(pair.second));
|
||||
|
||||
//以动作为Key构造AniMap
|
||||
ActionAnis[ActionName] = new AnimationMap();
|
||||
ActionAnis[ActionName]->SetVisible(false);
|
||||
|
||||
// 遍历所有时装部位构造Ani
|
||||
for (auto &AvatarPartPair : AvatarPart)
|
||||
{
|
||||
std::string AvatarPartName = AvatarPartPair.first;
|
||||
CreateSkinmationBySlot(ActionName, AvatarPartName, Path);
|
||||
}
|
||||
|
||||
// 将所有时装部位的Ani添加到动作AniMap以后完成构造
|
||||
ActionAnis[ActionName]->CompleteConstruction();
|
||||
this->AddChild(ActionAnis[ActionName]);
|
||||
}
|
||||
// 设置初始动作
|
||||
SetAction("rest");
|
||||
@@ -103,18 +106,9 @@ void Chr_Animation::Init(CharacterObject *parent)
|
||||
void Chr_Animation::SetAction(std::string actionName)
|
||||
{
|
||||
// 先将原动作的Ani设置为不可见
|
||||
for (auto Ani : ActionAnis[CurrentActionTag])
|
||||
{
|
||||
Ani->Reset();
|
||||
Ani->SetVisible(false);
|
||||
}
|
||||
ActionAnis[CurrentActionTag]->Reset();
|
||||
ActionAnis[CurrentActionTag]->SetVisible(false);
|
||||
// 再将新动作的Ani设置为可见
|
||||
for (auto Ani : ActionAnis[actionName])
|
||||
{
|
||||
Ani->SetVisible(true);
|
||||
}
|
||||
ActionAnis[actionName]->SetVisible(true);
|
||||
CurrentActionTag = actionName;
|
||||
|
||||
// 设置阴影的动作
|
||||
if(chr_parent->_Shadow)chr_parent->_Shadow->SetAction(actionName);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
#pragma once
|
||||
#include "EngineFrame/Component/Animation.h"
|
||||
#include "EngineFrame/Base/Actor.h"
|
||||
#include "EngineFrame/Component/AnimationMap.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
class CharacterObject;
|
||||
class Chr_Animation : public RenderBase
|
||||
class Chr_Animation : public Actor
|
||||
{
|
||||
// 动作动画集合
|
||||
using ActionAniList = std::map<std::string, std::vector<RefPtr<Animation>>>;
|
||||
using ActionAniList = std::map<std::string, RefPtr<AnimationMap>>;
|
||||
|
||||
public:
|
||||
inline static const std::unordered_map<std::string, std::string>
|
||||
|
||||
@@ -28,7 +28,6 @@ float Chr_Controller::ConvertAxisValue(Sint16 rawValue)
|
||||
|
||||
void Chr_Controller::Init(CharacterObject *pCharacter)
|
||||
{
|
||||
addTag(Tag::HANDEL_EVENT);
|
||||
m_pCharacter = pCharacter;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
#include "EngineFrame/Base/BaseNode.h"
|
||||
#include "EngineFrame/Base/Node.h"
|
||||
#include "Tool/Common.h"
|
||||
class CharacterObject;
|
||||
class Chr_Controller : public BaseNode
|
||||
class Chr_Controller : public Node
|
||||
{
|
||||
private:
|
||||
CharacterObject *m_pCharacter = nullptr;
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
#include "Chr_Shadow.h"
|
||||
#include "Global/Global_Game.h"
|
||||
#include "Actor/Object/CharacterObject.h"
|
||||
#include "Asset/Character/Chr_Equipment.h"
|
||||
|
||||
void Chr_Shadow::Init(CharacterObject *parent)
|
||||
{
|
||||
// 调用RenderBase类的初始化 才能挂上标签
|
||||
RenderBase::Init();
|
||||
chr_parent = parent;
|
||||
SetRenderZOrder(1000000);
|
||||
SetPos(parent->GetPos());
|
||||
}
|
||||
|
||||
void Chr_Shadow::SetAction(std::string actionName)
|
||||
{
|
||||
// 先将原动作的Ani设置为不可见
|
||||
for (auto Ani : ActionAnis[CurrentActionTag])
|
||||
{
|
||||
Ani->Reset();
|
||||
Ani->SetVisible(false);
|
||||
}
|
||||
// 再将新动作的Ani设置为可见
|
||||
for (auto Ani : ActionAnis[actionName])
|
||||
{
|
||||
Ani->SetVisible(true);
|
||||
}
|
||||
CurrentActionTag = actionName;
|
||||
}
|
||||
|
||||
void Chr_Shadow::SetDirection(int dir)
|
||||
{
|
||||
Vec2 sc = GetScale();
|
||||
// 朝右
|
||||
if (dir == 0)
|
||||
{
|
||||
SetScale(Vec2({SDL_fabsf(sc.x), sc.y}));
|
||||
}
|
||||
// 朝左
|
||||
else if (dir == 1)
|
||||
{
|
||||
SetScale(Vec2({-SDL_fabsf(sc.x), sc.y}));
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
#pragma once
|
||||
#include "EngineFrame/Component/Animation.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
class CharacterObject;
|
||||
class Chr_Shadow : public RenderBase
|
||||
{
|
||||
// 动作动画集合
|
||||
using ActionAniList = std::map<std::string, std::vector<RefPtr<Animation>>>;
|
||||
|
||||
private:
|
||||
/* data */
|
||||
public:
|
||||
// 父对象
|
||||
CharacterObject *chr_parent;
|
||||
// 时装部位对应的动作动画集合
|
||||
ActionAniList ActionAnis;
|
||||
// 当前动作Tag
|
||||
std::string CurrentActionTag = "waiting";
|
||||
|
||||
// 初始化时
|
||||
void Init(CharacterObject *parent);
|
||||
// 设置动作
|
||||
void SetAction(std::string actionName);
|
||||
|
||||
// 设置方向
|
||||
void SetDirection(int dir);
|
||||
};
|
||||
@@ -5,7 +5,6 @@
|
||||
void Chr_StateMachine::Init(CharacterObject *parent)
|
||||
{
|
||||
chr_Parent = parent;
|
||||
addTag(Tag::UPDATE);
|
||||
parent->AddChild(this);
|
||||
}
|
||||
void Chr_StateMachine::ChangeState(int state)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
#include "Global/Global_Enum.h"
|
||||
#include "EngineFrame/Base/Actor.h"
|
||||
#include "EngineFrame/Base/Node.h"
|
||||
class CharacterObject;
|
||||
class Chr_StateMachine : public Actor
|
||||
class Chr_StateMachine : public Node
|
||||
{
|
||||
private:
|
||||
// 父对象
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
void Mon_Animation::Init(MonsterObject *parent)
|
||||
{
|
||||
// 调用RenderBase类的初始化 才能挂上标签
|
||||
RenderBase::Init();
|
||||
parent->AddChild(this);
|
||||
mon_parent = parent;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
class MonsterObject;
|
||||
class Mon_Animation : public RenderBase
|
||||
class Mon_Animation : public Actor
|
||||
{
|
||||
// 动作动画集合
|
||||
using ActionAniList = std::map<std::string, RefPtr<Animation>>;
|
||||
|
||||
@@ -78,7 +78,7 @@ static SQInteger SQR_GetZOrder(HSQUIRRELVM v)
|
||||
SQUserPointer A_obj;
|
||||
sq_getuserpointer(v, 2, &A_obj);
|
||||
Actor *Aobj = (Actor *)A_obj;
|
||||
sq_pushinteger(v, Aobj->GetRenderZOrder());
|
||||
sq_pushinteger(v, Aobj->GetZOrder());
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ static SQInteger SQR_SetZOrder(HSQUIRRELVM v)
|
||||
SQInteger Value;
|
||||
sq_getinteger(v, 3, &Value);
|
||||
Actor *Aobj = (Actor *)A_obj;
|
||||
Aobj->SetRenderZOrder(Value);
|
||||
Aobj->SetZOrder(Value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ static SQInteger SQR_GetPos(HSQUIRRELVM v)
|
||||
SQUserPointer A_obj;
|
||||
sq_getuserpointer(v, 2, &A_obj);
|
||||
Actor *Aobj = (Actor *)A_obj;
|
||||
Vec2 Pos = Aobj->GetPos();
|
||||
glm::vec2 Pos = Aobj->GetPosition();
|
||||
|
||||
sq_newtable(v);
|
||||
sq_pushstring(v, _SC("x"), -1);
|
||||
@@ -117,7 +117,7 @@ static SQInteger SQR_SetPos(HSQUIRRELVM v)
|
||||
|
||||
if (sq_gettop(v) == 3)
|
||||
{
|
||||
Vec2 Pos;
|
||||
glm::vec2 Pos;
|
||||
sq_pushnull(v); // null iterator
|
||||
while (SQ_SUCCEEDED(sq_next(v, 3)))
|
||||
{
|
||||
@@ -139,7 +139,7 @@ static SQInteger SQR_SetPos(HSQUIRRELVM v)
|
||||
sq_pop(v, 1);
|
||||
|
||||
Actor *Aobj = (Actor *)A_obj;
|
||||
Aobj->SetPos(Pos);
|
||||
Aobj->SetPosition(Pos);
|
||||
}
|
||||
else if (sq_gettop(v) == 4)
|
||||
{
|
||||
@@ -147,7 +147,7 @@ static SQInteger SQR_SetPos(HSQUIRRELVM v)
|
||||
sq_getfloat(v, 3, &X);
|
||||
sq_getfloat(v, 4, &Y);
|
||||
Actor *Aobj = (Actor *)A_obj;
|
||||
Aobj->SetPos(Vec2(X, Y));
|
||||
Aobj->SetPosition(glm::vec2(X, Y));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -157,7 +157,7 @@ static SQInteger SQR_GetWorldPos(HSQUIRRELVM v)
|
||||
SQUserPointer A_obj;
|
||||
sq_getuserpointer(v, 2, &A_obj);
|
||||
Actor *Aobj = (Actor *)A_obj;
|
||||
Vec2 Pos = Aobj->GetWorldPos();
|
||||
glm::vec2 Pos = Aobj->ConvertToWorld(glm::vec2(0, 0));
|
||||
|
||||
sq_newtable(v);
|
||||
sq_pushstring(v, _SC("x"), -1);
|
||||
@@ -175,7 +175,7 @@ static SQInteger SQR_GetAlpha(HSQUIRRELVM v)
|
||||
sq_getuserpointer(v, 2, &A_obj);
|
||||
Actor *Aobj = (Actor *)A_obj;
|
||||
|
||||
sq_pushfloat(v, Aobj->GetAlpha());
|
||||
sq_pushfloat(v, Aobj->GetOpacity());
|
||||
return 1;
|
||||
}
|
||||
static SQInteger SQR_SetAlpha(HSQUIRRELVM v)
|
||||
@@ -185,7 +185,7 @@ static SQInteger SQR_SetAlpha(HSQUIRRELVM v)
|
||||
SQFloat Value;
|
||||
sq_getfloat(v, 3, &Value);
|
||||
Actor *Aobj = (Actor *)A_obj;
|
||||
Aobj->SetAlpha(Value);
|
||||
Aobj->SetOpacity(Value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ static SQInteger SQR_GetScale(HSQUIRRELVM v)
|
||||
SQUserPointer A_obj;
|
||||
sq_getuserpointer(v, 2, &A_obj);
|
||||
Actor *Aobj = (Actor *)A_obj;
|
||||
Vec2 Pos = Aobj->GetScale();
|
||||
glm::vec2 Pos = Aobj->GetScale();
|
||||
sq_newtable(v);
|
||||
sq_pushstring(v, _SC("x"), -1);
|
||||
sq_pushfloat(v, Pos.x);
|
||||
@@ -212,7 +212,7 @@ static SQInteger SQR_SetScale(HSQUIRRELVM v)
|
||||
|
||||
if (sq_gettop(v) == 3)
|
||||
{
|
||||
Vec2 Pos;
|
||||
glm::vec2 Pos;
|
||||
sq_pushnull(v); // null iterator
|
||||
while (SQ_SUCCEEDED(sq_next(v, 3)))
|
||||
{
|
||||
@@ -242,7 +242,7 @@ static SQInteger SQR_SetScale(HSQUIRRELVM v)
|
||||
sq_getfloat(v, 3, &X);
|
||||
sq_getfloat(v, 4, &Y);
|
||||
Actor *Aobj = (Actor *)A_obj;
|
||||
Aobj->SetScale(Vec2(X, Y));
|
||||
Aobj->SetScale(X, Y);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -342,7 +342,7 @@ static SQInteger SQR_GetVisible(HSQUIRRELVM v)
|
||||
SQUserPointer A_obj;
|
||||
sq_getuserpointer(v, 2, &A_obj);
|
||||
Actor *Aobj = (Actor *)A_obj;
|
||||
sq_pushbool(v, Aobj->GetVisible());
|
||||
sq_pushbool(v, Aobj->IsVisible());
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -391,7 +391,7 @@ static SQInteger SQR_Canvas_DrawImg(HSQUIRRELVM v)
|
||||
sq_getinteger(v, 4, &Idx);
|
||||
sq_GetVec2(v, 5, &Pos);
|
||||
Canvas *Aobj = (Canvas *)A_obj;
|
||||
Aobj->DrawImg(ImgPath, Idx, Pos);
|
||||
// Aobj->DrawImg(ImgPath, Idx, Pos);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -406,7 +406,7 @@ static SQInteger SQR_Canvas_DrawImgRect(HSQUIRRELVM v)
|
||||
sq_getinteger(v, 4, &Idx);
|
||||
sq_GetFRect(v, 5, &Rect);
|
||||
Canvas *Aobj = (Canvas *)A_obj;
|
||||
Aobj->DrawImg(ImgPath, Idx, Rect);
|
||||
// Aobj->DrawImg(ImgPath, Idx, Rect);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user