2012-06-14 05:19:13 +08:00
|
|
|
#ifndef _CCB_CCBREADER_H_
|
|
|
|
#define _CCB_CCBREADER_H_
|
2012-05-03 11:58:53 +08:00
|
|
|
|
|
|
|
#include "cocos2d.h"
|
2012-07-20 14:05:52 +08:00
|
|
|
#include "ExtensionMacros.h"
|
2012-09-17 14:27:17 +08:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2013-03-15 08:43:56 +08:00
|
|
|
#include "CCBSequence.h"
|
|
|
|
|
2012-05-03 14:43:27 +08:00
|
|
|
|
2012-06-15 05:23:53 +08:00
|
|
|
#define CCB_STATIC_NEW_AUTORELEASE_OBJECT_METHOD(T, METHOD) static T * METHOD() { \
|
2012-06-15 09:16:54 +08:00
|
|
|
T * ptr = new T(); \
|
|
|
|
if(ptr != NULL) { \
|
|
|
|
ptr->autorelease(); \
|
|
|
|
return ptr; \
|
|
|
|
} \
|
|
|
|
CC_SAFE_DELETE(ptr); \
|
|
|
|
return NULL; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CCB_STATIC_NEW_AUTORELEASE_OBJECT_WITH_INIT_METHOD(T, METHOD) static T * METHOD() { \
|
|
|
|
T * ptr = new T(); \
|
|
|
|
if(ptr != NULL && ptr->init()) { \
|
|
|
|
ptr->autorelease(); \
|
|
|
|
return ptr; \
|
|
|
|
} \
|
|
|
|
CC_SAFE_DELETE(ptr); \
|
|
|
|
return NULL; \
|
2012-06-14 05:19:13 +08:00
|
|
|
}
|
|
|
|
|
2013-03-15 08:43:56 +08:00
|
|
|
#define kCCBVersion 5
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
enum {
|
|
|
|
kCCBPropTypePosition = 0,
|
|
|
|
kCCBPropTypeSize,
|
|
|
|
kCCBPropTypePoint,
|
|
|
|
kCCBPropTypePointLock,
|
|
|
|
kCCBPropTypeScaleLock,
|
|
|
|
kCCBPropTypeDegrees,
|
|
|
|
kCCBPropTypeInteger,
|
|
|
|
kCCBPropTypeFloat,
|
|
|
|
kCCBPropTypeFloatVar,
|
|
|
|
kCCBPropTypeCheck,
|
|
|
|
kCCBPropTypeSpriteFrame,
|
|
|
|
kCCBPropTypeTexture,
|
|
|
|
kCCBPropTypeByte,
|
|
|
|
kCCBPropTypeColor3,
|
|
|
|
kCCBPropTypeColor4FVar,
|
|
|
|
kCCBPropTypeFlip,
|
|
|
|
kCCBPropTypeBlendmode,
|
|
|
|
kCCBPropTypeFntFile,
|
|
|
|
kCCBPropTypeText,
|
|
|
|
kCCBPropTypeFontTTF,
|
|
|
|
kCCBPropTypeIntegerLabeled,
|
|
|
|
kCCBPropTypeBlock,
|
|
|
|
kCCBPropTypeAnimation,
|
|
|
|
kCCBPropTypeCCBFile,
|
|
|
|
kCCBPropTypeString,
|
|
|
|
kCCBPropTypeBlockCCControl,
|
2013-03-15 08:43:56 +08:00
|
|
|
kCCBPropTypeFloatScale,
|
|
|
|
kCCBPropTypeFloatXY
|
2012-09-17 14:27:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
kCCBFloat0 = 0,
|
|
|
|
kCCBFloat1,
|
|
|
|
kCCBFloatMinus1,
|
|
|
|
kCCBFloat05,
|
|
|
|
kCCBFloatInteger,
|
|
|
|
kCCBFloatFull
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
kCCBPlatformAll = 0,
|
|
|
|
kCCBPlatformIOS,
|
|
|
|
kCCBPlatformMac
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
kCCBTargetTypeNone = 0,
|
|
|
|
kCCBTargetTypeDocumentRoot = 1,
|
|
|
|
kCCBTargetTypeOwner = 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
kCCBKeyframeEasingInstant,
|
|
|
|
|
|
|
|
kCCBKeyframeEasingLinear,
|
|
|
|
|
|
|
|
kCCBKeyframeEasingCubicIn,
|
|
|
|
kCCBKeyframeEasingCubicOut,
|
|
|
|
kCCBKeyframeEasingCubicInOut,
|
|
|
|
|
|
|
|
kCCBKeyframeEasingElasticIn,
|
|
|
|
kCCBKeyframeEasingElasticOut,
|
|
|
|
kCCBKeyframeEasingElasticInOut,
|
|
|
|
|
|
|
|
kCCBKeyframeEasingBounceIn,
|
|
|
|
kCCBKeyframeEasingBounceOut,
|
|
|
|
kCCBKeyframeEasingBounceInOut,
|
|
|
|
|
|
|
|
kCCBKeyframeEasingBackIn,
|
|
|
|
kCCBKeyframeEasingBackOut,
|
|
|
|
kCCBKeyframeEasingBackInOut,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
kCCBPositionTypeRelativeBottomLeft,
|
|
|
|
kCCBPositionTypeRelativeTopLeft,
|
|
|
|
kCCBPositionTypeRelativeTopRight,
|
|
|
|
kCCBPositionTypeRelativeBottomRight,
|
|
|
|
kCCBPositionTypePercent,
|
|
|
|
kCCBPositionTypeMultiplyResolution,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
kCCBSizeTypeAbsolute,
|
|
|
|
kCCBSizeTypePercent,
|
|
|
|
kCCBSizeTypeRelativeContainer,
|
|
|
|
kCCBSizeTypeHorizontalPercent,
|
|
|
|
kCCBSizeTypeVerticalPercent,
|
|
|
|
kCCBSizeTypeMultiplyResolution,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
kCCBScaleTypeAbsolute,
|
|
|
|
kCCBScaleTypeMultiplyResolution
|
|
|
|
};
|
2012-06-12 01:43:07 +08:00
|
|
|
|
2012-09-24 11:47:33 +08:00
|
|
|
|
2012-05-07 17:05:17 +08:00
|
|
|
NS_CC_EXT_BEGIN
|
2012-05-03 11:58:53 +08:00
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup cocosbuilder
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
class CCBFile : public CCNode
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CCNode *mCCBFileNode;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CCBFile();
|
|
|
|
|
|
|
|
static CCBFile* create();
|
|
|
|
|
|
|
|
CCNode* getCCBFileNode();
|
|
|
|
void setCCBFileNode(CCNode *pNode); // retain
|
|
|
|
};
|
|
|
|
|
2012-06-14 05:19:13 +08:00
|
|
|
/* Forward declaration. */
|
|
|
|
class CCNodeLoader;
|
|
|
|
class CCNodeLoaderLibrary;
|
|
|
|
class CCNodeLoaderListener;
|
|
|
|
class CCBMemberVariableAssigner;
|
|
|
|
class CCBSelectorResolver;
|
2012-09-17 14:27:17 +08:00
|
|
|
class CCBAnimationManager;
|
|
|
|
class CCBKeyframe;
|
2012-06-14 05:19:13 +08:00
|
|
|
|
2012-05-07 18:14:15 +08:00
|
|
|
/**
|
2012-06-14 05:19:13 +08:00
|
|
|
* @brief Parse CCBI file which is generated by CocosBuilder
|
2012-05-07 18:14:15 +08:00
|
|
|
*/
|
2012-09-17 14:27:17 +08:00
|
|
|
class CCBReader : public CCObject
|
|
|
|
{
|
|
|
|
private:
|
2012-11-02 08:52:07 +08:00
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
CCData *mData;
|
|
|
|
unsigned char *mBytes;
|
|
|
|
int mCurrentByte;
|
|
|
|
int mCurrentBit;
|
|
|
|
|
2012-11-26 21:51:05 +08:00
|
|
|
std::vector<std::string> mStringCache;
|
2012-09-17 14:27:17 +08:00
|
|
|
std::set<std::string> mLoadedSpriteSheets;
|
|
|
|
|
|
|
|
CCObject *mOwner;
|
|
|
|
|
2012-11-26 21:51:05 +08:00
|
|
|
CCBAnimationManager *mActionManager; //retain
|
|
|
|
CCDictionary* mActionManagers;
|
2012-11-01 02:06:56 +08:00
|
|
|
|
2012-09-18 17:04:10 +08:00
|
|
|
std::set<std::string> *mAnimatedProps;
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
CCNodeLoaderLibrary *mCCNodeLoaderLibrary;
|
|
|
|
CCNodeLoaderListener *mCCNodeLoaderListener;
|
|
|
|
CCBMemberVariableAssigner *mCCBMemberVariableAssigner;
|
2012-11-02 08:52:07 +08:00
|
|
|
CCBSelectorResolver *mCCBSelectorResolver;
|
|
|
|
|
2012-11-26 21:51:05 +08:00
|
|
|
std::vector<std::string> mOwnerOutletNames;
|
2012-11-02 08:52:07 +08:00
|
|
|
CCArray* mOwnerOutletNodes;
|
|
|
|
CCArray* mNodesWithAnimationManagers;
|
2012-11-26 21:51:05 +08:00
|
|
|
CCArray* mAnimationManagersForNodes;
|
2012-11-02 08:52:07 +08:00
|
|
|
|
2012-11-26 21:51:05 +08:00
|
|
|
std::vector<std::string> mOwnerCallbackNames;
|
2012-11-02 08:52:07 +08:00
|
|
|
CCArray* mOwnerCallbackNodes;
|
2012-12-03 18:27:50 +08:00
|
|
|
std::string mCCBRootPath;
|
2013-03-03 10:32:09 +08:00
|
|
|
bool hasScriptingOwner;
|
2012-11-26 21:51:05 +08:00
|
|
|
bool init();
|
2012-09-17 14:27:17 +08:00
|
|
|
public:
|
2013-03-15 08:43:56 +08:00
|
|
|
|
|
|
|
bool jsControlled;
|
2012-09-17 14:27:17 +08:00
|
|
|
CCBReader(CCNodeLoaderLibrary *pCCNodeLoaderLibrary, CCBMemberVariableAssigner *pCCBMemberVariableAssigner = NULL, CCBSelectorResolver *pCCBSelectorResolver = NULL, CCNodeLoaderListener *pCCNodeLoaderListener = NULL);
|
|
|
|
CCBReader(CCBReader *pCCBReader);
|
|
|
|
virtual ~CCBReader();
|
|
|
|
CCBReader();
|
2012-11-26 21:51:05 +08:00
|
|
|
|
2012-12-03 18:27:50 +08:00
|
|
|
void setCCBRootPath(const char* pCCBRootPath);
|
|
|
|
const std::string& getCCBRootPath() const;
|
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
CCNode* readNodeGraphFromFile(const char *pCCBFileName);
|
|
|
|
CCNode* readNodeGraphFromFile(const char *pCCBFileName, CCObject *pOwner);
|
|
|
|
CCNode* readNodeGraphFromFile(const char *pCCBFileName, CCObject *pOwner, const CCSize &parentSize);
|
|
|
|
|
|
|
|
CCNode* readNodeGraphFromData(CCData *pData, CCObject *pOwner, const CCSize &parentSize);
|
2012-11-26 21:51:05 +08:00
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
CCScene* createSceneWithNodeGraphFromFile(const char *pCCBFileName);
|
|
|
|
CCScene* createSceneWithNodeGraphFromFile(const char *pCCBFileName, CCObject *pOwner);
|
|
|
|
CCScene* createSceneWithNodeGraphFromFile(const char *pCCBFileName, CCObject *pOwner, const CCSize &parentSize);
|
|
|
|
|
|
|
|
CCBMemberVariableAssigner* getCCBMemberVariableAssigner();
|
|
|
|
CCBSelectorResolver* getCCBSelectorResolver();
|
|
|
|
|
|
|
|
CCBAnimationManager* getAnimationManager();
|
|
|
|
void setAnimationManager(CCBAnimationManager *pAnimationManager);
|
|
|
|
|
|
|
|
// Used in CCNodeLoader::parseProperties()
|
2012-09-18 17:04:10 +08:00
|
|
|
std::set<std::string>* getAnimatedProperties();
|
2012-09-17 14:27:17 +08:00
|
|
|
std::set<std::string>& getLoadedSpriteSheet();
|
|
|
|
CCObject* getOwner();
|
|
|
|
|
|
|
|
/* Utility methods. */
|
2012-11-26 21:51:05 +08:00
|
|
|
static std::string lastPathComponent(const char* pString);
|
|
|
|
static std::string deletePathExtension(const char* pString);
|
|
|
|
static std::string toLowerCase(const char* pCCString);
|
|
|
|
static bool endsWith(const char* pString, const char* pEnding);
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
/* Parse methods. */
|
|
|
|
int readInt(bool pSigned);
|
|
|
|
unsigned char readByte();
|
|
|
|
bool readBool();
|
2012-11-26 21:51:05 +08:00
|
|
|
std::string readUTF8();
|
2012-09-17 14:27:17 +08:00
|
|
|
float readFloat();
|
2012-11-26 21:51:05 +08:00
|
|
|
std::string readCachedString();
|
2012-11-01 02:06:56 +08:00
|
|
|
bool isJSControlled();
|
|
|
|
|
|
|
|
|
2013-03-15 08:43:56 +08:00
|
|
|
bool readCallbackKeyframesForSeq(CCBSequence* seq);
|
|
|
|
bool readSoundKeyframesForSeq(CCBSequence* seq);
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-11-26 21:51:05 +08:00
|
|
|
CCArray* getOwnerCallbackNames();
|
|
|
|
CCArray* getOwnerCallbackNodes();
|
2012-11-01 02:06:56 +08:00
|
|
|
CCArray* getOwnerOutletNames();
|
|
|
|
CCArray* getOwnerOutletNodes();
|
|
|
|
CCArray* getNodesWithAnimationManagers();
|
2012-11-02 08:52:07 +08:00
|
|
|
CCArray* getAnimationManagersForNodes();
|
|
|
|
|
2012-11-26 21:51:05 +08:00
|
|
|
CCDictionary* getAnimationManagers();
|
2013-01-21 14:40:29 +08:00
|
|
|
void setAnimationManagers(CCDictionary* x); // weak reference
|
2012-11-01 02:06:56 +08:00
|
|
|
|
|
|
|
void addOwnerCallbackName(std::string name);
|
|
|
|
void addOwnerCallbackNode(CCNode *node);
|
|
|
|
|
|
|
|
void addDocumentCallbackName(std::string name);
|
|
|
|
void addDocumentCallbackNode(CCNode *node);
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
static float getResolutionScale();
|
2013-04-23 10:34:16 +08:00
|
|
|
static void setResolutionScale(float scale);
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2012-11-26 21:51:05 +08:00
|
|
|
CCNode* readFileWithCleanUp(bool bCleanUp, CCDictionary* am);
|
2013-06-05 15:17:00 +08:00
|
|
|
|
|
|
|
void addOwnerOutletName(std::string name);
|
|
|
|
void addOwnerOutletNode(CCNode *node);
|
2012-09-19 08:38:33 +08:00
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
private:
|
|
|
|
void cleanUpNodeGraph(CCNode *pNode);
|
|
|
|
bool readSequences();
|
|
|
|
CCBKeyframe* readKeyframe(int type);
|
|
|
|
|
|
|
|
bool readHeader();
|
|
|
|
bool readStringCache();
|
2012-11-26 21:51:05 +08:00
|
|
|
//void readStringCacheEntry();
|
2012-09-17 14:27:17 +08:00
|
|
|
CCNode* readNodeGraph();
|
|
|
|
CCNode* readNodeGraph(CCNode * pParent);
|
|
|
|
|
|
|
|
bool getBit();
|
|
|
|
void alignBits();
|
2012-09-19 08:38:33 +08:00
|
|
|
|
2012-11-26 21:51:05 +08:00
|
|
|
friend class CCNodeLoader;
|
2012-06-14 05:19:13 +08:00
|
|
|
};
|
2012-05-03 11:58:53 +08:00
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
// end of effects group
|
|
|
|
/// @}
|
|
|
|
|
2012-05-07 17:05:17 +08:00
|
|
|
NS_CC_EXT_END
|
2012-05-03 14:43:27 +08:00
|
|
|
|
2012-09-19 08:38:33 +08:00
|
|
|
#endif
|