123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435 |
- /****************************************************************************
- Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
-
- 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 _CCB_CCBREADER_H_
- #define _CCB_CCBREADER_H_
- #include <set>
- #include <string>
- #include <vector>
- #include "2d/CCNode.h"
- #include "base/CCData.h"
- #include "base/CCMap.h"
- #include "editor-support/cocosbuilder/CCBSequence.h"
- #include "extensions/GUI/CCControlExtension/CCControl.h"
- #include "editor-support/cocosbuilder/CCBAnimationManager.h"
- #if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
- #ifdef ABSOLUTE
- #undef ABSOLUTE
- #endif
- #endif
- #define CCB_STATIC_NEW_AUTORELEASE_OBJECT_METHOD(T, METHOD) static T * METHOD() { \
- T * ptr = new (std::nothrow) 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 (std::nothrow) T(); \
- if(ptr != NULL && ptr->init()) { \
- ptr->autorelease(); \
- return ptr; \
- } \
- CC_SAFE_DELETE(ptr); \
- return NULL; \
- }
- #define CCB_VERSION 5
- namespace cocosbuilder {
- /**
- * @addtogroup cocosbuilder
- * @{
- */
- class CCBFile : public cocos2d::Node
- {
- private:
- cocos2d::Node *_CCBFileNode;
-
- public:
- CCBFile();
-
- static CCBFile* create();
-
- cocos2d::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 CC_DLL CCBReader : public cocos2d::Ref
- {
- 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
- };
-
- enum class FloatType {
- _0 = 0,
- _1,
- MINUS1,
- _05,
- INTEGER,
- FULL
- };
-
- enum class PlatformType {
- ALL = 0,
- IOS,
- MAC
- };
-
- enum class TargetType {
- NONE = 0,
- DOCUMENT_ROOT = 1,
- OWNER = 2,
- };
-
- enum class PositionType
- {
- RELATIVE_BOTTOM_LEFT,
- RELATIVE_TOP_LEFT,
- RELATIVE_TOP_RIGHT,
- RELATIVE_BOTTOM_RIGHT,
- PERCENT,
- MULTIPLY_RESOLUTION,
- };
-
- enum class SizeType
- {
- ABSOLUTE,
- PERCENT,
- RELATIVE_CONTAINER,
- HORIZONTAL_PERCENT,
- VERTICAL_PERCENT,
- MULTIPLY_RESOLUTION,
- };
-
- enum class ScaleType
- {
- ABSOLUTE,
- MULTIPLY_RESOLUTION
- };
- /**
- * @js NA
- * @lua NA
- */
- CCBReader(NodeLoaderLibrary *pNodeLoaderLibrary, CCBMemberVariableAssigner *pCCBMemberVariableAssigner = NULL, CCBSelectorResolver *pCCBSelectorResolver = NULL, NodeLoaderListener *pNodeLoaderListener = NULL);
- /**
- * @js NA
- * @lua NA
- */
- CCBReader(CCBReader *ccbReader);
- /**
- * @js NA
- * @lua NA
- */
- virtual ~CCBReader();
- /**
- * @js NA
- * @lua NA
- */
- CCBReader();
-
- void setCCBRootPath(const char* ccbRootPath);
- const std::string& getCCBRootPath() const;
- cocos2d::Node* readNodeGraphFromFile(const char *pCCBFileName);
- cocos2d::Node* readNodeGraphFromFile(const char *pCCBFileName, cocos2d::Ref *pOwner);
- cocos2d::Node* readNodeGraphFromFile(const char *pCCBFileName, cocos2d::Ref *pOwner, const cocos2d::Size &parentSize);
- /**
- * @js NA
- * @lua NA
- */
- cocos2d::Node* readNodeGraphFromData(std::shared_ptr<cocos2d::Data> data, cocos2d::Ref *pOwner, const cocos2d::Size &parentSize);
-
- /**
- @lua NA
- */
- cocos2d::Scene* createSceneWithNodeGraphFromFile(const char *pCCBFileName);
- /**
- @lua NA
- */
- cocos2d::Scene* createSceneWithNodeGraphFromFile(const char *pCCBFileName, cocos2d::Ref *pOwner);
- /**
- @lua NA
- */
- cocos2d::Scene* createSceneWithNodeGraphFromFile(const char *pCCBFileName, cocos2d::Ref *pOwner, const cocos2d::Size &parentSize);
-
- /**
- * @js NA
- * @lua NA
- */
- CCBMemberVariableAssigner* getCCBMemberVariableAssigner();
- /**
- * @js NA
- * @lua NA
- */
- CCBSelectorResolver* getCCBSelectorResolver();
-
- /**
- * @js getActionManager
- * @lua getActionManager
- */
- CCBAnimationManager* getAnimationManager();
- /**
- * @js setActionManager
- * @lua setActionManager
- */
- void setAnimationManager(CCBAnimationManager *pAnimationManager);
-
- /** Used in NodeLoader::parseProperties()
- * @js NA
- * @lua NA
- */
- std::set<std::string>* getAnimatedProperties();
- /**
- * @js NA
- * @lua NA
- */
- std::set<std::string>& getLoadedSpriteSheet();
- /**
- * @js NA
- * @lua NA
- */
- cocos2d::Ref* getOwner();
- /* Utility methods.
- * @js NA
- * @lua NA
- */
- static std::string lastPathComponent(const char* pString);
- /**
- * @js NA
- * @lua NA
- */
- static std::string deletePathExtension(const char* pString);
- /**
- * @js NA
- * @lua NA
- */
- static std::string toLowerCase(const char* pString);
- /**
- * @js NA
- * @lua NA
- */
- static bool endsWith(const char* pString, const char* pEnding);
- /* Parse methods.
- * @js NA
- * @lua NA
- */
- int readInt(bool pSigned);
- /**
- * @js NA
- * @lua NA
- */
- unsigned char readByte();
- /**
- * @js NA
- * @lua NA
- */
- bool readBool();
- std::string readUTF8();
- /**
- * @js NA
- * @lua NA
- */
- float readFloat();
- /**
- * @js NA
- * @lua NA
- */
- std::string readCachedString();
- /**
- * @js NA
- * @lua NA
- */
- bool isJSControlled();
-
- bool readCallbackKeyframesForSeq(CCBSequence* seq);
- bool readSoundKeyframesForSeq(CCBSequence* seq);
-
- cocos2d::ValueVector getOwnerCallbackNames();
- cocos2d::Vector<cocos2d::Node*>& getOwnerCallbackNodes();
- cocos2d::ValueVector& getOwnerCallbackControlEvents();
-
- cocos2d::ValueVector getOwnerOutletNames();
- cocos2d::Vector<cocos2d::Node*>& getOwnerOutletNodes();
- cocos2d::Vector<cocos2d::Node*>& getNodesWithAnimationManagers();
- cocos2d::Vector<CCBAnimationManager*>& getAnimationManagersForNodes();
-
- typedef cocos2d::Map<cocos2d::Node*, CCBAnimationManager*> CCBAnimationManagerMap;
- typedef std::shared_ptr<CCBAnimationManagerMap> CCBAnimationManagerMapPtr;
-
- /**
- * @js NA
- * @lua NA
- */
- CCBAnimationManagerMapPtr getAnimationManagers();
- /**
- * @js NA
- * @lua NA
- */
- void setAnimationManagers(CCBAnimationManagerMapPtr x);
- /**
- * @js NA
- * @lua NA
- */
- void addOwnerCallbackName(const std::string& name);
- /**
- * @js NA
- * @lua NA
- */
- void addOwnerCallbackNode(cocos2d::Node *node);
- void addOwnerCallbackControlEvents(cocos2d::extension::Control::EventType type);
- /**
- * @js NA
- * @lua NA
- */
- void addDocumentCallbackName(const std::string& name);
- /**
- * @js NA
- * @lua NA
- */
- void addDocumentCallbackNode(cocos2d::Node *node);
- void addDocumentCallbackControlEvents(cocos2d::extension::Control::EventType eventType);
- /**
- * @js NA
- * @lua NA
- */
- static float getResolutionScale();
- static void setResolutionScale(float scale);
- /**
- * @js NA
- * @lua NA
- */
- cocos2d::Node* readFileWithCleanUp(bool bCleanUp, CCBAnimationManagerMapPtr am);
-
- void addOwnerOutletName(std::string name);
- void addOwnerOutletNode(cocos2d::Node *node);
- private:
- void cleanUpNodeGraph(cocos2d::Node *pNode);
- bool readSequences();
- CCBKeyframe* readKeyframe(PropertyType type);
-
- bool readHeader();
- bool readStringCache();
- //void readStringCacheEntry();
- cocos2d::Node* readNodeGraph();
- cocos2d::Node* readNodeGraph(cocos2d::Node * pParent);
- bool getBit();
- void alignBits();
- bool init();
-
- friend class NodeLoader;
- private:
- std::shared_ptr<cocos2d::Data> _data;
- unsigned char *_bytes;
- int _currentByte;
- int _currentBit;
-
- std::vector<std::string> _stringCache;
- std::set<std::string> _loadedSpriteSheets;
-
- cocos2d::Ref *_owner;
-
- CCBAnimationManager* _animationManager; //retain
- CCBAnimationManagerMapPtr _animationManagers;
-
- std::set<std::string> *_animatedProps;
-
- NodeLoaderLibrary *_nodeLoaderLibrary;
- NodeLoaderListener *_nodeLoaderListener;
- CCBMemberVariableAssigner *_CCBMemberVariableAssigner;
- CCBSelectorResolver *_CCBSelectorResolver;
-
- std::vector<std::string> _ownerOutletNames;
- cocos2d::Vector<cocos2d::Node*> _ownerOutletNodes;
- cocos2d::Vector<cocos2d::Node*> _nodesWithAnimationManagers;
- cocos2d::Vector<CCBAnimationManager*> _animationManagersForNodes;
-
- std::vector<std::string> _ownerCallbackNames;
- cocos2d::Vector<cocos2d::Node*> _ownerCallbackNodes;
- cocos2d::ValueVector _ownerOwnerCallbackControlEvents;
- std::string _CCBRootPath;
-
- bool _jsControlled;
- };
- // end of effects group
- /// @}
- }
- #endif
|