axmol/extensions/CCArmature/datas/CCDatas.h

460 lines
12 KiB
C
Raw Normal View History

2013-06-06 12:02:54 +08:00
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCARMATURE_DATAS_H__
#define __CCARMATURE_DATAS_H__
2013-06-06 12:02:54 +08:00
#include "../utils/CCArmatureDefine.h"
#include "../utils/CCTweenFunction.h"
#define CS_CREATE_NO_PARAM_NO_INIT(varType)\
public: \
static inline varType *create(void){ \
varType *var = new varType();\
if (var)\
{\
var->autorelease();\
return var;\
}\
CC_SAFE_DELETE(var);\
return NULL;\
}
#define CS_CREATE_NO_PARAM(varType)\
public: \
static inline varType *create(void){ \
varType *var = new varType();\
if (var && var->init())\
{\
var->autorelease();\
return var;\
}\
CC_SAFE_DELETE(var);\
return NULL;\
}
NS_CC_EXT_BEGIN
2013-06-07 10:52:32 +08:00
2013-06-06 12:02:54 +08:00
/**
* the base node include a lot of attribute.
*/
2013-06-06 16:22:58 +08:00
class CCBaseData : public CCObject
2013-06-06 12:02:54 +08:00
{
public:
2013-06-07 10:52:32 +08:00
CS_CREATE_NO_PARAM_NO_INIT(CCBaseData)
public:
CCBaseData();
~CCBaseData(void);
/*
* Copy datas from node
* @param node A CCBaseData to copy datas
*/
virtual void copy(const CCBaseData *_node);
/*
* Calculate two CCBaseData's between value(_to - _from) and set to self
*
* @param from from CCBaseData
* @param to to CCBaseData
*/
virtual void subtract(CCBaseData *_from, CCBaseData *_to);
public:
2013-06-07 19:48:31 +08:00
float x; //! position x attribute
float y; //! position y attribute
int zOrder; //! zorder attribute, used to order the CCBone's depth order
2013-06-07 10:52:32 +08:00
/**
* x y skewX skewY scaleX scaleY used to calculate transform matrix
* skewX, skewY can have rotation effect
* To get more matrix information, you can have a look at this pape : http://www.senocular.com/flash/tutorials/transformmatrix/
*/
float skewX;
float skewY;
float scaleX;
float scaleY;
float tweenRotate; //! SkewX, SkewY, and TweenRotate effect the rotation
bool isUseColorInfo; //! Whether or not this frame have the color changed Info
int a, r, g, b;
2013-06-06 12:02:54 +08:00
};
2013-06-06 12:02:54 +08:00
/**
* DisplayType distinguish which type you display is.
*/
2013-06-07 10:52:32 +08:00
enum DisplayType
{
CS_DISPLAY_SPRITE, //! display is a single CCSprite
CS_DISPLAY_ARMATURE, //! display is a CCArmature
CS_DISPLAY_PARTICLE, //! display is a CCParticle.
CS_DISPLAY_SHADER, //! display is a shader
2013-06-06 12:02:54 +08:00
2013-06-07 10:52:32 +08:00
CS_DISPLAY_MAX
2013-06-06 12:02:54 +08:00
};
2013-06-06 16:22:58 +08:00
class CCDisplayData : public CCObject
2013-06-06 12:02:54 +08:00
{
public:
2013-06-07 10:52:32 +08:00
CS_CREATE_NO_PARAM_NO_INIT(CCDisplayData)
2013-06-06 12:02:54 +08:00
2013-06-07 10:52:32 +08:00
static const char *changeDisplayToTexture(const char *);
2013-06-06 12:02:54 +08:00
public:
2013-06-07 10:52:32 +08:00
CCDisplayData();
virtual ~CCDisplayData(void);
2013-06-06 12:02:54 +08:00
2013-06-07 10:52:32 +08:00
DisplayType displayType; //! mark which type your display is
2013-06-06 12:02:54 +08:00
};
2013-06-06 16:22:58 +08:00
class CCSpriteDisplayData : public CCDisplayData
2013-06-06 12:02:54 +08:00
{
public:
2013-06-07 10:52:32 +08:00
CS_CREATE_NO_PARAM_NO_INIT(CCSpriteDisplayData)
2013-06-06 12:02:54 +08:00
public:
2013-06-07 10:52:32 +08:00
CCSpriteDisplayData();
virtual ~CCSpriteDisplayData();
2013-06-06 12:02:54 +08:00
2013-06-07 10:52:32 +08:00
inline void setParam(const char *displayName)
{
this->displayName = displayName;
}
void copy(CCSpriteDisplayData *displayData);
2013-06-06 12:02:54 +08:00
public:
2013-06-07 10:52:32 +08:00
/**
* If DisplayType is CS_DISPLAY_SPRITE, then CCBone will use this image name to create a CCSprite from CCSpriteFrameCache.
* It should note that when use this name to create CCSprite from CCSpriteFrameCache, you should use _displayName + ".png", because when use Texture Packer to pack single image file, the name have ".png".
2013-06-07 10:52:32 +08:00
*
* If DisplayType is CS_DISPLAY_ARMATURE, the name is the CCArmature's name. When CCBone init display and type is CS_DISPLAY_ARMATURE,
* then CCBone will create a CCArmature.
*/
std::string displayName;
2013-06-06 12:02:54 +08:00
};
2013-06-06 16:22:58 +08:00
class CCArmatureDisplayData : public CCDisplayData
2013-06-07 10:52:32 +08:00
{
2013-06-06 12:02:54 +08:00
public:
2013-06-07 10:52:32 +08:00
CS_CREATE_NO_PARAM_NO_INIT(CCArmatureDisplayData)
2013-06-06 12:02:54 +08:00
public:
2013-06-07 10:52:32 +08:00
CCArmatureDisplayData();
virtual ~CCArmatureDisplayData();
2013-06-06 12:02:54 +08:00
2013-06-07 10:52:32 +08:00
inline void setParam(const char *displayName)
{
this->displayName = displayName;
}
void copy(CCArmatureDisplayData *displayData);
2013-06-06 12:02:54 +08:00
public:
2013-06-07 10:52:32 +08:00
/**
* If DisplayType is CS_DISPLAY_SPRITE, then CCBone will use this image name to create a CCSprite from CCSpriteFrameCache.
* It should note that when use this name to create CCSprite from CCSpriteFrameCache, you should use _displayName + ".png", because when use Texture Packer to pack single image file, the name have ".png".
2013-06-07 10:52:32 +08:00
*
* If DisplayType is CS_DISPLAY_ARMATURE, the name is the CCArmature's name. When CCBone init display and type is CS_DISPLAY_ARMATURE,
* then CCBone will create a CCArmature.
*/
std::string displayName;
2013-06-06 12:02:54 +08:00
};
2013-06-06 16:22:58 +08:00
class CCParticleDisplayData : public CCDisplayData
2013-06-06 12:02:54 +08:00
{
public:
2013-06-07 10:52:32 +08:00
CS_CREATE_NO_PARAM_NO_INIT(CCParticleDisplayData)
2013-06-06 12:02:54 +08:00
public:
2013-06-07 10:52:32 +08:00
CCParticleDisplayData();
virtual ~CCParticleDisplayData() {};
2013-06-06 12:02:54 +08:00
2013-06-07 10:52:32 +08:00
void setParam(const char *plist)
{
this->plist = plist;
}
2013-06-06 12:02:54 +08:00
2013-06-07 10:52:32 +08:00
void copy(CCParticleDisplayData *displayData);
public:
std::string plist;
2013-06-06 12:02:54 +08:00
};
2013-06-06 16:22:58 +08:00
class CCShaderDisplayData : public CCDisplayData
2013-06-06 12:02:54 +08:00
{
public:
2013-06-07 10:52:32 +08:00
CS_CREATE_NO_PARAM_NO_INIT(CCShaderDisplayData)
2013-06-06 12:02:54 +08:00
public:
2013-06-07 10:52:32 +08:00
CCShaderDisplayData();
virtual ~CCShaderDisplayData() {};
2013-06-06 12:02:54 +08:00
2013-06-07 10:52:32 +08:00
inline void setParam(const char *vert, const char *frag)
{
this->vert = vert;
this->frag = frag;
}
2013-06-06 12:02:54 +08:00
2013-06-07 10:52:32 +08:00
void copy(CCShaderDisplayData *displayData);
2013-06-06 12:02:54 +08:00
public:
2013-06-07 10:52:32 +08:00
std::string vert;
std::string frag;
2013-06-06 12:02:54 +08:00
};
/**
2013-06-06 16:22:58 +08:00
* CCBoneData used to init a CCBone.
* CCBoneData keeps a CCDisplayData list, a CCBone can have many display to change.
* The display information saved in the CCDisplayData
2013-06-06 12:02:54 +08:00
*/
2013-06-06 16:22:58 +08:00
class CCBoneData : public CCBaseData
2013-06-06 12:02:54 +08:00
{
public:
2013-06-07 10:52:32 +08:00
CS_CREATE_NO_PARAM(CCBoneData)
2013-06-06 12:02:54 +08:00
public:
2013-06-07 10:52:32 +08:00
CCBoneData(void);
~CCBoneData(void);
2013-06-06 12:02:54 +08:00
2013-06-07 10:52:32 +08:00
virtual bool init();
2013-06-06 12:02:54 +08:00
2013-06-07 10:52:32 +08:00
void addDisplayData(CCDisplayData *displayData);
CCDisplayData *getDisplayData(int index);
2013-06-06 12:02:54 +08:00
public:
2013-06-07 10:52:32 +08:00
std::string name; //! the bone's name
std::string parentName; //! the bone parent's name
CCArray displayDataList; //! save CCDisplayData informations for the CCBone
2013-06-06 12:02:54 +08:00
};
2013-06-06 12:02:54 +08:00
/**
2013-06-06 16:22:58 +08:00
* CCArmatureData saved the CCArmature name and Bonedatas needed for the Bones in this CCArmature
* When we create a CCArmature, we need to get each CCBone's CCBoneData as it's init information.
* So we can get a CCBoneData from the CCDictionary saved in the CCArmatureData.
2013-06-06 12:02:54 +08:00
*/
2013-06-06 16:22:58 +08:00
class CCArmatureData : public CCObject
2013-06-06 12:02:54 +08:00
{
public:
2013-06-07 10:52:32 +08:00
CS_CREATE_NO_PARAM(CCArmatureData)
2013-06-06 12:02:54 +08:00
public:
2013-06-07 10:52:32 +08:00
CCArmatureData();
~CCArmatureData();
2013-06-06 12:02:54 +08:00
2013-06-07 10:52:32 +08:00
bool init();
void addBoneData(CCBoneData *boneData);
CCBoneData *getBoneData(const char *boneName);
2013-06-06 12:02:54 +08:00
public:
2013-06-07 10:52:32 +08:00
std::string name;
CCDictionary boneDataDic;
CCArray boneList;
2013-06-06 12:02:54 +08:00
};
2013-06-06 16:22:58 +08:00
class CCFrameData : public CCBaseData
2013-06-06 12:02:54 +08:00
{
public:
2013-06-07 10:52:32 +08:00
CS_CREATE_NO_PARAM_NO_INIT(CCFrameData)
2013-06-06 12:02:54 +08:00
public:
2013-06-07 10:52:32 +08:00
CCFrameData();
~CCFrameData();
2013-06-06 12:02:54 +08:00
2013-06-07 10:52:32 +08:00
virtual void copy(CCFrameData *frameData);
2013-06-06 12:02:54 +08:00
public:
int duration; //! The frame will last _duration frames
2013-06-07 10:52:32 +08:00
CCTweenType tweenEasing; //! Every frame's tween easing effect
2013-06-06 12:02:54 +08:00
2013-06-07 10:52:32 +08:00
/**
* The current display index when change to this frame.
* If value is -1, then display will not show.
*/
int displayIndex;
2013-06-06 12:02:54 +08:00
2013-06-07 10:52:32 +08:00
/**
* _movement, _event, _sound, _soundEffect do not support yet
2013-06-07 10:52:32 +08:00
*/
std::string _movement;
std::string _event;
std::string _sound;
std::string _soundEffect;
2013-06-06 12:02:54 +08:00
};
2013-06-06 16:22:58 +08:00
class CCMovementBoneData : public CCObject
2013-06-06 12:02:54 +08:00
{
public:
2013-06-07 10:52:32 +08:00
CS_CREATE_NO_PARAM(CCMovementBoneData)
2013-06-06 12:02:54 +08:00
public:
2013-06-07 10:52:32 +08:00
CCMovementBoneData();
~CCMovementBoneData(void);
2013-06-06 12:02:54 +08:00
2013-06-07 10:52:32 +08:00
virtual bool init();
2013-06-06 12:02:54 +08:00
2013-06-07 10:52:32 +08:00
void addFrameData(CCFrameData *frameData);
CCFrameData *getFrameData(int index);
2013-06-06 12:02:54 +08:00
public:
2013-06-07 10:52:32 +08:00
float delay; //! movement delay percent, this value can produce a delay effect
float scale; //! scale this movement
float duration; //! this CCBone in this movement will last _duration frames
2013-06-07 10:52:32 +08:00
std::string name; //! bone name
2013-06-06 12:02:54 +08:00
2013-06-07 10:52:32 +08:00
CCArray frameList;
2013-06-06 12:02:54 +08:00
};
2013-06-06 16:22:58 +08:00
class CCMovementData : public CCObject
2013-06-06 12:02:54 +08:00
{
public:
2013-06-07 10:52:32 +08:00
CS_CREATE_NO_PARAM_NO_INIT(CCMovementData)
public:
CCMovementData(void);
~CCMovementData(void);
void addMovementBoneData(CCMovementBoneData *movBoneData);
CCMovementBoneData *getMovementBoneData(const char *boneName);
public:
std::string name;
int duration; //! the frames this movement will last
/**
* Change to this movement will last _durationTo frames. Use this effect can avoid too suddenly changing.
2013-06-07 10:52:32 +08:00
*
* Example : current movement is "stand", we want to change to "run", then we fill _durationTo frames before
2013-06-07 10:52:32 +08:00
* change to "run" instead of changing to "run" directly.
*/
int durationTo;
/*
* This is different from _duration, _durationTween contain tween effect.
2013-06-07 10:52:32 +08:00
*
* Example : If we edit 10 frames in the flash, then _duration is 10. When we set _durationTween to 50, the movement will last 50 frames, the extra 40 frames will auto filled with tween effect
2013-06-07 10:52:32 +08:00
*/
int durationTween;
2013-06-07 19:48:31 +08:00
bool loop; //! whether the movement is looped
2013-06-07 10:52:32 +08:00
/**
* Which tween easing effect the movement use
* TWEEN_EASING_MAX : use the value from CCMovementData get from flash design panel
*/
CCTweenType tweenEasing;
/**
* @brief save movment bone datas
* @key std::string
* @value CCMovementBoneData *
*/
CCDictionary movBoneDataDic;
2013-06-06 12:02:54 +08:00
};
2013-06-06 12:02:54 +08:00
/**
2013-06-06 16:22:58 +08:00
* CCAnimationData include all movement infomation for the CCArmature
* The struct is CCAnimationData -> CCMovementData -> CCMovementBoneData -> CCFrameData
2013-06-06 12:02:54 +08:00
* -> MovementFrameData
*/
2013-06-06 16:22:58 +08:00
class CCAnimationData : public CCObject
2013-06-06 12:02:54 +08:00
{
public:
2013-06-07 10:52:32 +08:00
CS_CREATE_NO_PARAM_NO_INIT(CCAnimationData)
2013-06-06 12:02:54 +08:00
public:
2013-06-07 10:52:32 +08:00
CCAnimationData(void);
~CCAnimationData(void);
2013-06-06 12:02:54 +08:00
2013-06-07 10:52:32 +08:00
void release();
void retain();
2013-06-06 12:02:54 +08:00
2013-06-07 10:52:32 +08:00
void addMovement(CCMovementData *movData);
CCMovementData *getMovement(const char *movementName);
int getMovementCount();
2013-06-06 12:02:54 +08:00
public:
2013-06-07 10:52:32 +08:00
std::string name;
CCDictionary movementDataDic;
std::vector<std::string> movementNames;
2013-06-06 12:02:54 +08:00
};
2013-06-06 16:22:58 +08:00
struct CCContourVertex2 : public CCObject
2013-06-06 12:02:54 +08:00
{
2013-06-07 10:52:32 +08:00
CCContourVertex2(float x, float y)
{
this->x = x;
this->y = y;
}
float x;
float y;
2013-06-06 12:02:54 +08:00
};
/*
2013-06-07 10:52:32 +08:00
* CCContourData include a contour vertex information
2013-06-06 12:02:54 +08:00
*/
2013-06-06 16:22:58 +08:00
class CCContourData : public CCObject
2013-06-06 12:02:54 +08:00
{
public:
2013-06-07 10:52:32 +08:00
CS_CREATE_NO_PARAM(CCContourData)
2013-06-06 12:02:54 +08:00
public:
2013-06-07 10:52:32 +08:00
CCContourData();
~CCContourData(void);
2013-06-06 12:02:54 +08:00
2013-06-07 10:52:32 +08:00
virtual bool init();
2013-06-06 12:02:54 +08:00
public:
2013-06-07 10:52:32 +08:00
CCArray vertexList; //! Save contour vertex info, vertex saved in a CCPoint
2013-06-06 12:02:54 +08:00
};
/*
2013-06-07 10:52:32 +08:00
* CCTextureData include a texture's information
2013-06-06 12:02:54 +08:00
*/
2013-06-06 16:22:58 +08:00
class CCTextureData : public CCObject
2013-06-06 12:02:54 +08:00
{
public:
2013-06-07 10:52:32 +08:00
CS_CREATE_NO_PARAM(CCTextureData)
2013-06-06 12:02:54 +08:00
public:
2013-06-07 10:52:32 +08:00
CCTextureData();
~CCTextureData(void);
2013-06-06 12:02:54 +08:00
2013-06-07 10:52:32 +08:00
virtual bool init();
2013-06-06 12:02:54 +08:00
2013-06-07 10:52:32 +08:00
void addContourData(CCContourData *contourData);
CCContourData *getContourData(int index);
2013-06-06 12:02:54 +08:00
public:
2013-06-07 19:48:31 +08:00
float height; //! The texture's width, height
float width;
2013-06-06 12:02:54 +08:00
2013-06-07 10:52:32 +08:00
float pivotX; //! The texture's anchor point
float pivotY;
2013-06-06 12:02:54 +08:00
2013-06-07 19:48:31 +08:00
std::string name; //! The texture's name
2013-06-06 12:02:54 +08:00
2013-06-07 10:52:32 +08:00
CCArray contourDataList;
2013-06-06 12:02:54 +08:00
};
2013-06-06 12:02:54 +08:00
NS_CC_EXT_END
#endif /*__CCARMATURE_DATAS_H__*/