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"
|
2013-08-12 11:18:07 +08:00
|
|
|
#include "GUI/CCControlExtension/CCControl.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-07-27 21:44:49 +08:00
|
|
|
#define CCB_VERSION 5
|
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
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
class CCBFile : public Node
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
private:
|
2013-07-27 22:31:57 +08:00
|
|
|
Node *_CCBFileNode;
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
CCBFile();
|
|
|
|
|
|
|
|
static CCBFile* create();
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Node* getCCBFileNode();
|
|
|
|
void setCCBFileNode(Node *pNode); // retain
|
2012-09-17 14:27:17 +08:00
|
|
|
};
|
|
|
|
|
2012-06-14 05:19:13 +08:00
|
|
|
/* Forward declaration. */
|
2013-06-20 14:15:53 +08:00
|
|
|
class NodeLoader;
|
|
|
|
class NodeLoaderLibrary;
|
|
|
|
class NodeLoaderListener;
|
2012-06-14 05:19:13 +08:00
|
|
|
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
|
|
|
*/
|
2013-06-20 14:15:53 +08:00
|
|
|
class CCBReader : public Object
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
public:
|
|
|
|
enum class PropertyType {
|
|
|
|
POSITION = 0,
|
|
|
|
SIZE,
|
|
|
|
POINT,
|
|
|
|
POINT_LOCK,
|
|
|
|
SCALE_LOCK,
|
|
|
|
DEGREES,
|
|
|
|
INTEGER,
|
|
|
|
FLOAT,
|
|
|
|
FLOAT_VAR,
|
|
|
|
CHECK,
|
|
|
|
SPRITEFRAME,
|
|
|
|
TEXTURE,
|
|
|
|
BYTE,
|
|
|
|
COLOR3,
|
|
|
|
COLOR4F_VAR,
|
|
|
|
FLIP,
|
|
|
|
BLEND_MODE,
|
|
|
|
FNT_FILE,
|
|
|
|
TEXT,
|
|
|
|
FONT_TTF,
|
|
|
|
INTEGER_LABELED,
|
|
|
|
BLOCK,
|
|
|
|
ANIMATION,
|
|
|
|
CCB_FILE,
|
|
|
|
STRING,
|
|
|
|
BLOCK_CONTROL,
|
|
|
|
FLOAT_SCALE,
|
|
|
|
FLOAT_XY
|
|
|
|
};
|
2012-11-02 08:52:07 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
enum class FloatType {
|
|
|
|
_0 = 0,
|
|
|
|
_1,
|
|
|
|
MINUS1,
|
|
|
|
_05,
|
|
|
|
INTEGER,
|
|
|
|
FULL
|
|
|
|
};
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
enum class PlatformType {
|
|
|
|
ALL = 0,
|
|
|
|
IOS,
|
|
|
|
MAC
|
|
|
|
};
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
enum class TargetType {
|
|
|
|
NONE = 0,
|
|
|
|
DOCUMENT_ROOT = 1,
|
|
|
|
OWNER = 2,
|
|
|
|
};
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
enum class PositionType
|
|
|
|
{
|
|
|
|
RELATIVE_BOTTOM_LEFT,
|
|
|
|
RELATIVE_TOP_LEFT,
|
|
|
|
RELATIVE_TOP_RIGHT,
|
|
|
|
RELATIVE_BOTTOM_RIGHT,
|
|
|
|
PERCENT,
|
|
|
|
MULTIPLY_RESOLUTION,
|
|
|
|
};
|
2012-11-02 08:52:07 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
enum class SizeType
|
|
|
|
{
|
|
|
|
ABSOLUTE,
|
|
|
|
PERCENT,
|
|
|
|
RELATIVE_CONTAINER,
|
|
|
|
HORIZONTAL_PERCENT,
|
|
|
|
VERTICAL_PERCENT,
|
|
|
|
MULTIPLY_RESOLUTION,
|
|
|
|
};
|
2012-11-02 08:52:07 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
enum class ScaleType
|
|
|
|
{
|
|
|
|
ABSOLUTE,
|
|
|
|
MULTIPLY_RESOLUTION
|
|
|
|
};
|
2013-03-15 08:43:56 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
CCBReader(NodeLoaderLibrary *pNodeLoaderLibrary, CCBMemberVariableAssigner *pCCBMemberVariableAssigner = NULL, CCBSelectorResolver *pCCBSelectorResolver = NULL, NodeLoaderListener *pNodeLoaderListener = NULL);
|
2013-07-27 21:44:49 +08:00
|
|
|
CCBReader(CCBReader *ccbReader);
|
2012-09-17 14:27:17 +08:00
|
|
|
virtual ~CCBReader();
|
|
|
|
CCBReader();
|
2012-11-26 21:51:05 +08:00
|
|
|
|
2013-07-27 22:31:57 +08:00
|
|
|
void setCCBRootPath(const char* ccbRootPath);
|
2012-12-03 18:27:50 +08:00
|
|
|
const std::string& getCCBRootPath() const;
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Node* readNodeGraphFromFile(const char *pCCBFileName);
|
|
|
|
Node* readNodeGraphFromFile(const char *pCCBFileName, Object *pOwner);
|
|
|
|
Node* readNodeGraphFromFile(const char *pCCBFileName, Object *pOwner, const Size &parentSize);
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Node* readNodeGraphFromData(Data *pData, Object *pOwner, const Size &parentSize);
|
2012-11-26 21:51:05 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Scene* createSceneWithNodeGraphFromFile(const char *pCCBFileName);
|
|
|
|
Scene* createSceneWithNodeGraphFromFile(const char *pCCBFileName, Object *pOwner);
|
|
|
|
Scene* createSceneWithNodeGraphFromFile(const char *pCCBFileName, Object *pOwner, const Size &parentSize);
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
CCBMemberVariableAssigner* getCCBMemberVariableAssigner();
|
|
|
|
CCBSelectorResolver* getCCBSelectorResolver();
|
|
|
|
|
|
|
|
CCBAnimationManager* getAnimationManager();
|
|
|
|
void setAnimationManager(CCBAnimationManager *pAnimationManager);
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
// Used in NodeLoader::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();
|
2013-06-20 14:15:53 +08:00
|
|
|
Object* getOwner();
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
/* Utility methods. */
|
2012-11-26 21:51:05 +08:00
|
|
|
static std::string lastPathComponent(const char* pString);
|
|
|
|
static std::string deletePathExtension(const char* pString);
|
2013-06-20 14:15:53 +08:00
|
|
|
static std::string toLowerCase(const char* pString);
|
2012-11-26 21:51:05 +08:00
|
|
|
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);
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Array* getOwnerCallbackNames();
|
|
|
|
Array* getOwnerCallbackNodes();
|
2013-08-12 11:18:07 +08:00
|
|
|
Array* getOwnerCallbackControlEvents();
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Array* getOwnerOutletNames();
|
|
|
|
Array* getOwnerOutletNodes();
|
|
|
|
Array* getNodesWithAnimationManagers();
|
|
|
|
Array* getAnimationManagersForNodes();
|
2013-08-12 11:18:07 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Dictionary* getAnimationManagers();
|
|
|
|
void setAnimationManagers(Dictionary* x); // weak reference
|
2012-11-01 02:06:56 +08:00
|
|
|
|
2013-08-12 11:18:07 +08:00
|
|
|
void addOwnerCallbackName(const std::string& name);
|
2013-06-20 14:15:53 +08:00
|
|
|
void addOwnerCallbackNode(Node *node);
|
2013-08-12 11:18:07 +08:00
|
|
|
void addOwnerCallbackControlEvents(Control::EventType type);
|
2012-11-01 02:06:56 +08:00
|
|
|
|
2013-08-12 11:18:07 +08:00
|
|
|
void addDocumentCallbackName(const std::string& name);
|
2013-06-20 14:15:53 +08:00
|
|
|
void addDocumentCallbackNode(Node *node);
|
2013-08-12 11:18:07 +08:00
|
|
|
void addDocumentCallbackControlEvents(Control::EventType eventType);
|
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
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Node* readFileWithCleanUp(bool bCleanUp, Dictionary* am);
|
2013-06-05 15:17:00 +08:00
|
|
|
|
|
|
|
void addOwnerOutletName(std::string name);
|
2013-06-20 14:15:53 +08:00
|
|
|
void addOwnerOutletNode(Node *node);
|
2012-09-19 08:38:33 +08:00
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
private:
|
2013-06-20 14:15:53 +08:00
|
|
|
void cleanUpNodeGraph(Node *pNode);
|
2012-09-17 14:27:17 +08:00
|
|
|
bool readSequences();
|
2013-07-27 21:44:49 +08:00
|
|
|
CCBKeyframe* readKeyframe(PropertyType type);
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
bool readHeader();
|
|
|
|
bool readStringCache();
|
2012-11-26 21:51:05 +08:00
|
|
|
//void readStringCacheEntry();
|
2013-06-20 14:15:53 +08:00
|
|
|
Node* readNodeGraph();
|
|
|
|
Node* readNodeGraph(Node * pParent);
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
bool getBit();
|
|
|
|
void alignBits();
|
2012-09-19 08:38:33 +08:00
|
|
|
|
2013-08-12 11:18:07 +08:00
|
|
|
bool init();
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
friend class NodeLoader;
|
2013-07-27 21:44:49 +08:00
|
|
|
|
|
|
|
private:
|
2013-07-27 22:31:57 +08:00
|
|
|
Data *_data;
|
|
|
|
unsigned char *_bytes;
|
|
|
|
int _currentByte;
|
|
|
|
int _currentBit;
|
2013-07-27 21:44:49 +08:00
|
|
|
|
2013-07-27 22:31:57 +08:00
|
|
|
std::vector<std::string> _stringCache;
|
|
|
|
std::set<std::string> _loadedSpriteSheets;
|
2013-07-27 21:44:49 +08:00
|
|
|
|
2013-07-27 22:31:57 +08:00
|
|
|
Object *_owner;
|
2013-07-27 21:44:49 +08:00
|
|
|
|
2013-07-27 22:31:57 +08:00
|
|
|
CCBAnimationManager *_actionManager; //retain
|
|
|
|
Dictionary* _actionManagers;
|
2013-07-27 21:44:49 +08:00
|
|
|
|
2013-07-27 22:31:57 +08:00
|
|
|
std::set<std::string> *_animatedProps;
|
2013-07-27 21:44:49 +08:00
|
|
|
|
2013-07-27 22:31:57 +08:00
|
|
|
NodeLoaderLibrary *_nodeLoaderLibrary;
|
|
|
|
NodeLoaderListener *_nodeLoaderListener;
|
|
|
|
CCBMemberVariableAssigner *_CCBMemberVariableAssigner;
|
|
|
|
CCBSelectorResolver *_CCBSelectorResolver;
|
2013-07-27 21:44:49 +08:00
|
|
|
|
2013-07-27 22:31:57 +08:00
|
|
|
std::vector<std::string> _ownerOutletNames;
|
|
|
|
Array* _ownerOutletNodes;
|
|
|
|
Array* _nodesWithAnimationManagers;
|
|
|
|
Array* _animationManagersForNodes;
|
2013-07-27 21:44:49 +08:00
|
|
|
|
2013-07-27 22:31:57 +08:00
|
|
|
std::vector<std::string> _ownerCallbackNames;
|
|
|
|
Array* _ownerCallbackNodes;
|
2013-08-12 11:18:07 +08:00
|
|
|
Array* _ownerOwnerCallbackControlEvents;
|
2013-07-27 22:31:57 +08:00
|
|
|
std::string _CCBRootPath;
|
2013-07-27 21:44:49 +08:00
|
|
|
|
|
|
|
bool _jsControlled;
|
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
|