99 lines
2.6 KiB
C
99 lines
2.6 KiB
C
|
|
#pragma once
|
|||
|
|
#include "Tool/IntrusiveList.hpp"
|
|||
|
|
#include "EngineFrame/Component/Component.h"
|
|||
|
|
#include "EngineFrame/Component/Sprite.h"
|
|||
|
|
#include "Asset/AnimationStruct.h"
|
|||
|
|
#include <functional>
|
|||
|
|
|
|||
|
|
class Animation : public Component
|
|||
|
|
{
|
|||
|
|
private:
|
|||
|
|
/* data */
|
|||
|
|
public:
|
|||
|
|
Animation(/* args */);
|
|||
|
|
Animation(std::string AniPath);
|
|||
|
|
Animation(std::string AniPath, std::function<std::string(std::string)> AdditionalOptions);
|
|||
|
|
~Animation();
|
|||
|
|
|
|||
|
|
// 显式引入基类的Init方法,避免隐藏
|
|||
|
|
using Component::Init;
|
|||
|
|
|
|||
|
|
void Init(std::string AniPath);
|
|||
|
|
void HandleEvents(SDL_Event *e) override;
|
|||
|
|
void Update(float deltaTime) override;
|
|||
|
|
void Render(float deltaTime) override;
|
|||
|
|
void OnAdded(Actor *actor) override;
|
|||
|
|
void Clear() override;
|
|||
|
|
|
|||
|
|
public:
|
|||
|
|
void FlushFrame(int Index);
|
|||
|
|
void Reset();
|
|||
|
|
AniScriptParser::AniFrame GetCurrentFrameInfo();
|
|||
|
|
void SetFrameIndex(int Index);
|
|||
|
|
void InterpolationLogic();
|
|||
|
|
// TODO SetOutline
|
|||
|
|
// TODO SetDye
|
|||
|
|
// TODO SetCrop
|
|||
|
|
|
|||
|
|
public:
|
|||
|
|
// Ani是否可用
|
|||
|
|
bool IsUsability = true;
|
|||
|
|
// 当前帧数
|
|||
|
|
int CurrentFrameIndex = 0;
|
|||
|
|
// 总帧数
|
|||
|
|
int TotalFrameIndex = 0;
|
|||
|
|
// 当前帧时间
|
|||
|
|
int CurrentIndexT = 0;
|
|||
|
|
// 当前帧
|
|||
|
|
RefPtr<Sprite> CurrentFrame;
|
|||
|
|
// 下帧延迟
|
|||
|
|
int NextFrameDelay = 9999999;
|
|||
|
|
// 染色Flag
|
|||
|
|
bool DyeingFlag = false;
|
|||
|
|
// 插值模式
|
|||
|
|
std::vector<AniScriptParser::AniFrame> InterpolationFlag;
|
|||
|
|
// 关键帧回调
|
|||
|
|
std::function<void(int)> ChangeFrameCallback;
|
|||
|
|
// 结束回调
|
|||
|
|
std::function<void()> EndCallback;
|
|||
|
|
// Ani的标签
|
|||
|
|
std::unordered_map<std::string, AniScriptParser::AniFlag> AnimationFlag;
|
|||
|
|
// 帧对象数组
|
|||
|
|
std::vector<AniScriptParser::AniFrame> FrameArr;
|
|||
|
|
// 图片精灵帧对象
|
|||
|
|
std::vector<RefPtr<Sprite>> SpriteArr;
|
|||
|
|
// Ani类型
|
|||
|
|
std::string Type = "normal";
|
|||
|
|
// Ani路径
|
|||
|
|
std::string AniPath;
|
|||
|
|
// 是否描边
|
|||
|
|
bool IsOutline = false;
|
|||
|
|
// // 描边颜色
|
|||
|
|
// OutlineColor = null;
|
|||
|
|
// // 描边对象List
|
|||
|
|
// OutlineList = null;
|
|||
|
|
// // 当前描边对象
|
|||
|
|
// CurrentOutline = null;
|
|||
|
|
// // 染色颜色
|
|||
|
|
// DyeColor = null;
|
|||
|
|
// // 染色帧List
|
|||
|
|
// DyeFrameList = null;
|
|||
|
|
// // 整体染色
|
|||
|
|
// DyeAllFlag = false;
|
|||
|
|
// // 裁切数据
|
|||
|
|
// CropRect = null;
|
|||
|
|
|
|||
|
|
// 附加选项
|
|||
|
|
std::function<std::string(std::string)> AdditionalOptions;
|
|||
|
|
|
|||
|
|
SDL_Point Pos = {0, 0}; // 位置坐标
|
|||
|
|
SDL_Point Size = {0, 0}; // 大小
|
|||
|
|
int RenderZOrder = 0; // 渲染层级
|
|||
|
|
|
|||
|
|
public:
|
|||
|
|
void SetSize(SDL_Point size);
|
|||
|
|
void SetPos(SDL_Point pos);
|
|||
|
|
SDL_Point GetSize();
|
|||
|
|
SDL_Point GetPos();
|
|||
|
|
};
|