#pragma once

#include "CProcessBase.h"
#include "CArmatureAniData.h"
#include "CTween.h"
#include "CBone.h"

class CCArmature;

typedef void (*ON_ANIMATION)(const char* _state, const char* _aniNow, CCArmature *_armature, const char* _frameEventName);

/**
* ſʼ
*/
static const char* START = "start";
/**
* Ž
*/
static const char* COMPLETE = "complete";
/**
* ѭ
*/
static const char* LOOP_COMPLETE = "loopComplete";
/**
* ¼֡
*/
static const char* IN_FRAME = "inFrame";


class CCAnimationEventListener{
public:
	virtual void animationHandler(const char* _aniType, const char* _aniID, const char* _frameID) = 0;
};


/*ΪǼܹTween*/
class CCARmatureAnimation : public CCProcessBase
{
public:
    static CCARmatureAnimation *create();
public:
    CCARmatureAnimation();
    ~CCARmatureAnimation(void);

    virtual bool init();

    /**
    * ɾ
    */
    void remove();
    void pause();
    void resume();
    void stop();
    /**
    * ȡ  ǰ ArmatureAniData
    */
    CCArmatureAniData* getData();
    void setData(CCArmatureAniData* _aniData);
    /**
    * ԹٶȽ
    * @param _scale ֵΪϵ˵ԭĶֵ֡
    * @param _boneName ָĳŵĹIDָĬΪй
    */
    void setAnimationScale(float _scale, const char* _boneName = "");
    /**
    * Ϊ Tween ʵ
    */
    void addTween(CCBone* _bone);
    /**
    * ɾ Tween ʵ
    */
    void removeTween(CCBone* _bone);
    /**
    * ȡ Tween ʵ
    */
    CCTween *getTween(const char* _boneID);
    /**
    * ָ Tween ʵ
    */
    void updateTween(const std::string *_boneID, float dt);
    /**
    * Ŷ
    * @param _to ArmatureAniData  ConnectionData еַ
    * @param _toFrames ɵ _to Ҫѵ֡
    * @param _listFrames _to ų֡
    * @param _loop Ƿѭ
    * @param _ease FrameNodeList ؼĻʽ-1:SineOut0:Line1:SineIn2:SineInOut
    */
    void playTo(void * _to, int _toFrames, int _listFrames = 0, bool _loop = false, int _ease = 0);

    void updateHandler();

    void updateCurrentPrecent();
public:
    /**
    * ¼ص
    */
	CC_SYNTHESIZE(CCAnimationEventListener *, mEventListener, AniEventListener);

protected:
    CCArmatureAniData	*mArmatureAniData;

    CCBoneAniData		*mBoneAniData;
	
private:
	
    // <const char*, CCTween*>
    CCDictionary	*mTweens;
    const char*		mAniIDNow;

};

