CCDatas.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. /****************************************************************************
  2. Copyright (c) 2013-2017 Chukong Technologies Inc.
  3. http://www.cocos2d-x.org
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. ****************************************************************************/
  20. #ifndef __CCARMATURE_DATAS_H__
  21. #define __CCARMATURE_DATAS_H__
  22. #include "base/CCRef.h"
  23. #include "base/ccTypes.h"
  24. #include "base/CCVector.h"
  25. #include "base/CCMap.h"
  26. #include "math/CCAffineTransform.h"
  27. #include "editor-support/cocostudio/CCArmatureDefine.h"
  28. #include "2d/CCTweenFunction.h"
  29. #include "editor-support/cocostudio/CocosStudioExport.h"
  30. #define CC_CREATE_NO_PARAM_NO_INIT(varType)\
  31. public: \
  32. static inline varType *create(void){ \
  33. varType *var = new (std::nothrow) varType();\
  34. if (var)\
  35. {\
  36. var->autorelease();\
  37. return var;\
  38. }\
  39. CC_SAFE_DELETE(var);\
  40. return nullptr;\
  41. }
  42. #define CC_CREATE_NO_PARAM(varType)\
  43. public: \
  44. static inline varType *create(void){ \
  45. varType *var = new (std::nothrow) varType();\
  46. if (var && var->init())\
  47. {\
  48. var->autorelease();\
  49. return var;\
  50. }\
  51. CC_SAFE_DELETE(var);\
  52. return nullptr;\
  53. }
  54. namespace cocostudio {
  55. /**
  56. * The base node include a lot of attributes.
  57. * @js NA
  58. * @lua NA
  59. */
  60. class CC_STUDIO_DLL BaseData : public cocos2d::Ref
  61. {
  62. public:
  63. CC_CREATE_NO_PARAM_NO_INIT(BaseData)
  64. public:
  65. /**
  66. * @js ctor
  67. */
  68. BaseData();
  69. /**
  70. * @js NA
  71. * @lua NA
  72. */
  73. ~BaseData(void);
  74. /*
  75. * Copy data from node
  76. * @param node A BaseData to copy data
  77. */
  78. virtual void copy(const BaseData *node);
  79. /*
  80. * Calculate two BaseData's between value(to - from) and set to self
  81. *
  82. * @param from from BaseData
  83. * @param to to BaseData
  84. */
  85. virtual void subtract(BaseData *from, BaseData *to, bool limit);
  86. virtual void setColor(const cocos2d::Color4B &color);
  87. virtual cocos2d::Color4B getColor();
  88. public:
  89. float x; //! position x attribute
  90. float y; //! position y attribute
  91. int zOrder; //! zorder attribute, used to order the Bone's depth order
  92. /**
  93. * x y skewX skewY scaleX scaleY used to calculate transform matrix
  94. * skewX, skewY can have rotation effect
  95. * To get more matrix information, you can have a look at this paper : http://www.senocular.com/flash/tutorials/transformmatrix/
  96. */
  97. float skewX;
  98. float skewY;
  99. float scaleX;
  100. float scaleY;
  101. float tweenRotate; //! SkewX, SkewY, and TweenRotate effect the rotation
  102. bool isUseColorInfo; //! Whether or not this frame have the color changed Info
  103. int a, r, g, b;
  104. };
  105. /**
  106. * DisplayType distinguish which type your display is.
  107. */
  108. enum DisplayType
  109. {
  110. CS_DISPLAY_SPRITE, //! display is a single Sprite
  111. CS_DISPLAY_ARMATURE, //! display is a Armature
  112. CS_DISPLAY_PARTICLE, //! display is a CCParticle.
  113. CS_DISPLAY_MAX
  114. };
  115. /**
  116. * @js NA
  117. * @lua NA
  118. */
  119. class CC_STUDIO_DLL DisplayData : public cocos2d::Ref
  120. {
  121. public:
  122. CC_CREATE_NO_PARAM_NO_INIT(DisplayData)
  123. static std::string changeDisplayToTexture(const std::string& displayName);
  124. public:
  125. /**
  126. * @js ctor
  127. */
  128. DisplayData();
  129. /**
  130. * @js NA
  131. * @lua NA
  132. */
  133. virtual ~DisplayData(void) {}
  134. virtual void copy(DisplayData *displayData);
  135. DisplayType displayType; //! mark which type your display is
  136. std::string displayName;
  137. };
  138. /**
  139. * @js NA
  140. * @lua NA
  141. */
  142. class CC_STUDIO_DLL SpriteDisplayData : public DisplayData
  143. {
  144. public:
  145. CC_CREATE_NO_PARAM_NO_INIT(SpriteDisplayData)
  146. public:
  147. /**
  148. * @js ctor
  149. */
  150. SpriteDisplayData();
  151. /**
  152. * @js NA
  153. * @lua NA
  154. */
  155. virtual ~SpriteDisplayData() {};
  156. void copy(DisplayData *displayData);
  157. public:
  158. BaseData skinData;
  159. };
  160. /**
  161. * @js NA
  162. * @lua NA
  163. */
  164. class CC_STUDIO_DLL ArmatureDisplayData : public DisplayData
  165. {
  166. public:
  167. CC_CREATE_NO_PARAM_NO_INIT(ArmatureDisplayData)
  168. public:
  169. /**
  170. * @js ctor
  171. */
  172. ArmatureDisplayData();
  173. /**
  174. * @js NA
  175. * @lua NA
  176. */
  177. virtual ~ArmatureDisplayData() {}
  178. };
  179. /**
  180. * @js NA
  181. * @lua NA
  182. */
  183. class CC_STUDIO_DLL ParticleDisplayData : public DisplayData
  184. {
  185. public:
  186. CC_CREATE_NO_PARAM_NO_INIT(ParticleDisplayData)
  187. public:
  188. /**
  189. * @js ctor
  190. */
  191. ParticleDisplayData();
  192. /**
  193. * @js NA
  194. * @lua NA
  195. */
  196. virtual ~ParticleDisplayData() {};
  197. };
  198. /**
  199. * BoneData used to init a Bone.
  200. * BoneData keeps a DisplayData list, a Bone can have many display to change.
  201. * The display information saved in the DisplayData
  202. * @js NA
  203. * @lua NA
  204. */
  205. class CC_STUDIO_DLL BoneData : public BaseData
  206. {
  207. public:
  208. CC_CREATE_NO_PARAM(BoneData)
  209. public:
  210. /**
  211. * @js ctor
  212. */
  213. BoneData(void);
  214. /**
  215. * @js NA
  216. * @lua NA
  217. */
  218. ~BoneData(void);
  219. virtual bool init();
  220. void addDisplayData(DisplayData *displayData);
  221. DisplayData *getDisplayData(int index);
  222. public:
  223. std::string name; //! the bone's name
  224. std::string parentName; //! the bone parent's name
  225. cocos2d::Vector<DisplayData*> displayDataList; //! save DisplayData informations for the Bone
  226. cocos2d::AffineTransform boneDataTransform;
  227. };
  228. /**
  229. * ArmatureData saved the Armature name and Bonedata needed for the CCBones in this Armature
  230. * When we create a Armature, we need to get each Bone's BoneData as it's init information.
  231. * So we can get a BoneData from the Dictionary saved in the ArmatureData.
  232. * @js NA
  233. * @lua NA
  234. */
  235. class CC_STUDIO_DLL ArmatureData : public cocos2d::Ref
  236. {
  237. public:
  238. CC_CREATE_NO_PARAM(ArmatureData)
  239. public:
  240. /**
  241. * @js ctor
  242. */
  243. ArmatureData();
  244. /**
  245. * @js NA
  246. * @lua NA
  247. */
  248. ~ArmatureData();
  249. bool init();
  250. void addBoneData(BoneData *boneData);
  251. BoneData *getBoneData(const std::string& boneName);
  252. public:
  253. std::string name;
  254. cocos2d::Map<std::string, BoneData*> boneDataDic;
  255. float dataVersion;
  256. };
  257. enum BlendType
  258. {
  259. BLEND_NORMAL,
  260. BLEND_LAYER,
  261. BLEND_DARKEN,
  262. BLEND_MULTIPLY,
  263. BLEND_LIGHTEN,
  264. BLEND_SCREEN,
  265. BLEND_OVERLAY,
  266. BLEND_HARD_LIGHT,
  267. BLEND_ADD,
  268. BLEND_SUBSTRACT,
  269. BLEND_DIFFERENCE,
  270. BLEND_INVERT,
  271. BLEND_ALPHA,
  272. BLEND_ERASE
  273. };
  274. /**
  275. * @js NA
  276. * @lua NA
  277. */
  278. class CC_STUDIO_DLL FrameData : public BaseData
  279. {
  280. public:
  281. CC_CREATE_NO_PARAM_NO_INIT(FrameData)
  282. public:
  283. /**
  284. * @js ctor
  285. */
  286. FrameData();
  287. /**
  288. * @js NA
  289. * @lua NA
  290. */
  291. ~FrameData();
  292. virtual void copy(const BaseData *baseData);
  293. public:
  294. int frameID;
  295. int duration; //! The frame will last duration frames
  296. cocos2d::tweenfunc::TweenType tweenEasing; //! Every frame's tween easing effect
  297. int easingParamNumber;
  298. float *easingParams;
  299. bool isTween; //! Whether it's a tween key frame
  300. /**
  301. * The current display index when change to this frame.
  302. * If value is -1, then display will not be shown.
  303. */
  304. int displayIndex;
  305. cocos2d::BlendFunc blendFunc;
  306. std::string strEvent;
  307. /**
  308. * strMovement, strEvent, strSound, strSoundEffect do not support yet
  309. */
  310. std::string strMovement;
  311. std::string strSound;
  312. std::string strSoundEffect;
  313. };
  314. /**
  315. * @js NA
  316. * @lua NA
  317. */
  318. class CC_STUDIO_DLL MovementBoneData : public cocos2d::Ref
  319. {
  320. public:
  321. CC_CREATE_NO_PARAM(MovementBoneData)
  322. public:
  323. /**
  324. * @js ctor
  325. */
  326. MovementBoneData();
  327. /**
  328. * @js NA
  329. * @lua NA
  330. */
  331. ~MovementBoneData(void);
  332. virtual bool init();
  333. void addFrameData(FrameData *frameData);
  334. FrameData *getFrameData(int index);
  335. public:
  336. float delay; //! movement delay percent, this value can produce a delay effect
  337. float scale; //! scale this movement
  338. float duration; //! this Bone in this movement will last m_iDuration frames
  339. std::string name; //! bone name
  340. cocos2d::Vector<FrameData*> frameList;
  341. };
  342. /**
  343. * @js NA
  344. * @lua NA
  345. */
  346. class CC_STUDIO_DLL MovementData : public cocos2d::Ref
  347. {
  348. public:
  349. CC_CREATE_NO_PARAM_NO_INIT(MovementData)
  350. public:
  351. /**
  352. * @js ctor
  353. */
  354. MovementData(void);
  355. /**
  356. * @js NA
  357. * @lua NA
  358. */
  359. ~MovementData(void);
  360. void addMovementBoneData(MovementBoneData *movBoneData);
  361. MovementBoneData *getMovementBoneData(const std::string& boneName);
  362. public:
  363. std::string name;
  364. int duration; //! the frames this movement will last
  365. float scale; //! scale this movement
  366. /**
  367. * Change to this movement will last durationTo frames. Use this effect can avoid too suddenly changing.
  368. *
  369. * Example : current movement is "stand", we want to change to "run", then we fill durationTo frames before
  370. * change to "run" instead of changing to "run" directly.
  371. */
  372. int durationTo;
  373. /*
  374. * This is different from duration, durationTween contain tween effect.
  375. * duration is the raw time that the animation will last, it's the same with the time you edit in the Action Editor.
  376. * durationTween is the actual time you want this animation last.
  377. * 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
  378. */
  379. int durationTween;
  380. bool loop; //! whether the movement was looped
  381. /**
  382. * Which tween easing effect the movement use
  383. * TWEEN_EASING_MAX : use the value from MovementData get from flash design panel
  384. */
  385. cocos2d::tweenfunc::TweenType tweenEasing;
  386. /**
  387. * @brief save movement bone data
  388. * @key const std::string&
  389. * @value MovementBoneData *
  390. */
  391. cocos2d::Map<std::string, MovementBoneData*> movBoneDataDic;
  392. };
  393. /**
  394. * AnimationData include all movement information for the Armature
  395. * The struct is AnimationData -> MovementData -> MovementBoneData -> FrameData
  396. * -> MovementFrameData
  397. * @js NA
  398. * @lua NA
  399. */
  400. class CC_STUDIO_DLL AnimationData : public cocos2d::Ref
  401. {
  402. public:
  403. CC_CREATE_NO_PARAM_NO_INIT(AnimationData)
  404. public:
  405. /**
  406. * @js ctor
  407. */
  408. AnimationData(void);
  409. /**
  410. * @js NA
  411. * @lua NA
  412. */
  413. ~AnimationData(void);
  414. void addMovement(MovementData *movData);
  415. MovementData *getMovement(const std::string& movementName);
  416. ssize_t getMovementCount();
  417. public:
  418. std::string name;
  419. cocos2d::Map<std::string, MovementData*> movementDataDic;
  420. std::vector<std::string> movementNames;
  421. };
  422. /*
  423. * ContourData include a contour vertex information
  424. * @js NA
  425. * @lua NA
  426. */
  427. class CC_STUDIO_DLL ContourData : public cocos2d::Ref
  428. {
  429. public:
  430. CC_CREATE_NO_PARAM(ContourData)
  431. public:
  432. /**
  433. * @js ctor
  434. */
  435. ContourData();
  436. /**
  437. * @js NA
  438. * @lua NA
  439. */
  440. ~ContourData(void);
  441. virtual bool init();
  442. virtual void addVertex(cocos2d::Vec2 &vertex);
  443. public:
  444. std::vector<cocos2d::Vec2> vertexList; //! Save contour vertex info, vertex saved in a Vec2
  445. };
  446. /*
  447. * TextureData include a texture's information
  448. * @js NA
  449. * @lua NA
  450. */
  451. class CC_STUDIO_DLL TextureData : public cocos2d::Ref
  452. {
  453. public:
  454. CC_CREATE_NO_PARAM(TextureData)
  455. public:
  456. /**
  457. * @js ctor
  458. */
  459. TextureData();
  460. /**
  461. * @js NA
  462. * @lua NA
  463. */
  464. ~TextureData(void);
  465. virtual bool init();
  466. void addContourData(ContourData *contourData);
  467. ContourData *getContourData(int index);
  468. public:
  469. float height; //! The texture's width, height
  470. float width;
  471. float pivotX; //! The texture's anchor point
  472. float pivotY;
  473. std::string name; //! The texture's name
  474. cocos2d::Vector<ContourData*> contourDataList;
  475. };
  476. }
  477. #endif /*__CCARMATURE_DATAS_H__*/