mirror of https://github.com/axmolengine/axmol.git
302 lines
7.3 KiB
C++
302 lines
7.3 KiB
C++
#ifndef _CCB_CCBREADER_H_
|
|
#define _CCB_CCBREADER_H_
|
|
|
|
#include "cocos2d.h"
|
|
#include "ExtensionMacros.h"
|
|
#include <string>
|
|
#include <vector>
|
|
#include "CCBSequence.h"
|
|
|
|
|
|
#define CCB_STATIC_NEW_AUTORELEASE_OBJECT_METHOD(T, METHOD) static T * METHOD() { \
|
|
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; \
|
|
}
|
|
|
|
#define kCCBVersion 5
|
|
|
|
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,
|
|
kCCBPropTypeBlockControl,
|
|
kCCBPropTypeFloatScale,
|
|
kCCBPropTypeFloatXY
|
|
};
|
|
|
|
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
|
|
};
|
|
|
|
|
|
NS_CC_EXT_BEGIN
|
|
|
|
/**
|
|
* @addtogroup cocosbuilder
|
|
* @{
|
|
*/
|
|
|
|
class CCBFile : public Node
|
|
{
|
|
private:
|
|
Node *mCCBFileNode;
|
|
|
|
public:
|
|
CCBFile();
|
|
|
|
static CCBFile* create();
|
|
|
|
Node* getCCBFileNode();
|
|
void setCCBFileNode(Node *pNode); // retain
|
|
};
|
|
|
|
/* Forward declaration. */
|
|
class NodeLoader;
|
|
class NodeLoaderLibrary;
|
|
class NodeLoaderListener;
|
|
class CCBMemberVariableAssigner;
|
|
class CCBSelectorResolver;
|
|
class CCBAnimationManager;
|
|
class CCBKeyframe;
|
|
|
|
/**
|
|
* @brief Parse CCBI file which is generated by CocosBuilder
|
|
*/
|
|
class CCBReader : public Object
|
|
{
|
|
private:
|
|
|
|
Data *mData;
|
|
unsigned char *mBytes;
|
|
int mCurrentByte;
|
|
int mCurrentBit;
|
|
|
|
std::vector<std::string> mStringCache;
|
|
std::set<std::string> mLoadedSpriteSheets;
|
|
|
|
Object *mOwner;
|
|
|
|
CCBAnimationManager *mActionManager; //retain
|
|
Dictionary* mActionManagers;
|
|
|
|
std::set<std::string> *mAnimatedProps;
|
|
|
|
NodeLoaderLibrary *mNodeLoaderLibrary;
|
|
NodeLoaderListener *mNodeLoaderListener;
|
|
CCBMemberVariableAssigner *mCCBMemberVariableAssigner;
|
|
CCBSelectorResolver *mCCBSelectorResolver;
|
|
|
|
std::vector<std::string> mOwnerOutletNames;
|
|
Array* mOwnerOutletNodes;
|
|
Array* mNodesWithAnimationManagers;
|
|
Array* mAnimationManagersForNodes;
|
|
|
|
std::vector<std::string> mOwnerCallbackNames;
|
|
Array* mOwnerCallbackNodes;
|
|
std::string mCCBRootPath;
|
|
bool hasScriptingOwner;
|
|
bool init();
|
|
public:
|
|
|
|
bool jsControlled;
|
|
CCBReader(NodeLoaderLibrary *pNodeLoaderLibrary, CCBMemberVariableAssigner *pCCBMemberVariableAssigner = NULL, CCBSelectorResolver *pCCBSelectorResolver = NULL, NodeLoaderListener *pNodeLoaderListener = NULL);
|
|
CCBReader(CCBReader *pCCBReader);
|
|
virtual ~CCBReader();
|
|
CCBReader();
|
|
|
|
void setCCBRootPath(const char* pCCBRootPath);
|
|
const std::string& getCCBRootPath() const;
|
|
|
|
Node* readNodeGraphFromFile(const char *pCCBFileName);
|
|
Node* readNodeGraphFromFile(const char *pCCBFileName, Object *pOwner);
|
|
Node* readNodeGraphFromFile(const char *pCCBFileName, Object *pOwner, const Size &parentSize);
|
|
|
|
Node* readNodeGraphFromData(Data *pData, Object *pOwner, const Size &parentSize);
|
|
|
|
Scene* createSceneWithNodeGraphFromFile(const char *pCCBFileName);
|
|
Scene* createSceneWithNodeGraphFromFile(const char *pCCBFileName, Object *pOwner);
|
|
Scene* createSceneWithNodeGraphFromFile(const char *pCCBFileName, Object *pOwner, const Size &parentSize);
|
|
|
|
CCBMemberVariableAssigner* getCCBMemberVariableAssigner();
|
|
CCBSelectorResolver* getCCBSelectorResolver();
|
|
|
|
CCBAnimationManager* getAnimationManager();
|
|
void setAnimationManager(CCBAnimationManager *pAnimationManager);
|
|
|
|
// Used in NodeLoader::parseProperties()
|
|
std::set<std::string>* getAnimatedProperties();
|
|
std::set<std::string>& getLoadedSpriteSheet();
|
|
Object* getOwner();
|
|
|
|
/* Utility methods. */
|
|
static std::string lastPathComponent(const char* pString);
|
|
static std::string deletePathExtension(const char* pString);
|
|
static std::string toLowerCase(const char* pString);
|
|
static bool endsWith(const char* pString, const char* pEnding);
|
|
|
|
/* Parse methods. */
|
|
int readInt(bool pSigned);
|
|
unsigned char readByte();
|
|
bool readBool();
|
|
std::string readUTF8();
|
|
float readFloat();
|
|
std::string readCachedString();
|
|
bool isJSControlled();
|
|
|
|
|
|
bool readCallbackKeyframesForSeq(CCBSequence* seq);
|
|
bool readSoundKeyframesForSeq(CCBSequence* seq);
|
|
|
|
|
|
|
|
Array* getOwnerCallbackNames();
|
|
Array* getOwnerCallbackNodes();
|
|
Array* getOwnerOutletNames();
|
|
Array* getOwnerOutletNodes();
|
|
Array* getNodesWithAnimationManagers();
|
|
Array* getAnimationManagersForNodes();
|
|
|
|
Dictionary* getAnimationManagers();
|
|
void setAnimationManagers(Dictionary* x); // weak reference
|
|
|
|
void addOwnerCallbackName(std::string name);
|
|
void addOwnerCallbackNode(Node *node);
|
|
|
|
void addDocumentCallbackName(std::string name);
|
|
void addDocumentCallbackNode(Node *node);
|
|
|
|
static float getResolutionScale();
|
|
static void setResolutionScale(float scale);
|
|
|
|
Node* readFileWithCleanUp(bool bCleanUp, Dictionary* am);
|
|
|
|
void addOwnerOutletName(std::string name);
|
|
void addOwnerOutletNode(Node *node);
|
|
|
|
private:
|
|
void cleanUpNodeGraph(Node *pNode);
|
|
bool readSequences();
|
|
CCBKeyframe* readKeyframe(int type);
|
|
|
|
bool readHeader();
|
|
bool readStringCache();
|
|
//void readStringCacheEntry();
|
|
Node* readNodeGraph();
|
|
Node* readNodeGraph(Node * pParent);
|
|
|
|
bool getBit();
|
|
void alignBits();
|
|
|
|
friend class NodeLoader;
|
|
};
|
|
|
|
// end of effects group
|
|
/// @}
|
|
|
|
NS_CC_EXT_END
|
|
|
|
#endif
|