SwitchGame/source/EngineFrame/Component/Animation.h

99 lines
2.6 KiB
C
Raw Permalink Normal View History

2025-09-18 15:21:43 +08:00
#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;
2025-09-19 12:18:57 +08:00
void SetIterationPos(VecPos pos) override;
2025-09-18 15:21:43 +08:00
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;
2025-09-19 12:18:57 +08:00
VecPos Pos = {0, 0}; // 位置坐标
VecSize Size = {0, 0}; // 大小
2025-09-18 15:21:43 +08:00
public:
2025-09-19 12:18:57 +08:00
void SetSize(VecSize size);
void SetPos(VecPos pos);
VecSize GetSize();
VecPos GetPos();
2025-09-18 15:21:43 +08:00
};