// // Redream的QCoreLayer加载类 // #ifndef RUQCoreLayer_h #define RUQCoreLayer_h #include "cocos2d.h" #include "extensions/cocos-ext.h" #include "rparticle/RParticleSystem.h" #include "Redream.h" #include "RUDefine.h" #include USING_NS_CC; USING_NS_CC_EXT; using namespace std; NS_RU_BEGIN class QCoreBtn; class QCoreLayerDelegate : public Ref ,public redream::REDAnimationManagerDelegate{ public: virtual void completedAnimationSequenceNamed(const char *name, int seqId,int tag) override; virtual void registerCompletedAniCallBack(std::function callback); protected: std::function _completedAniCallBack = nullptr; }; typedef std::unordered_map M_SNODE; class QCoreLayer :public Layer ,public redream::REDSelectorResolver ,public redream::REDMemberVariableAssigner ,public redream::NodeLoaderListener { public: static QCoreLayer* Layer(const string& file,bool batchReader=false); static redream::NodeLoaderLibrary* sharedLibrary(); static QCoreLayer* LayerBatchReader(string file,unordered_set plistSt); static QCoreLayer* LayerBatchReader(string file,unordered_set plistSt,unordered_set repleacPlistSt); static void registerNodeLoaderLibrary(tuple nodeLoaderArr); static QCoreLayer* loadFromRED(string pREDFileName,Ref* owner = nullptr); static int _count; RED_STATIC_NEW_AUTORELEASE_OBJECT_WITH_INIT_METHOD(QCoreLayer, create); QCoreLayer(); ~QCoreLayer(); virtual void onExit() override; std::function setCbOnExit(std::function cb); virtual cocos2d::SEL_MenuHandler onResolveREDCCMenuItemSelector(cocos2d::Ref * pTarget, const char * pSelectorName) override; virtual cocos2d::extension::Control::Handler onResolveREDCCControlSelector(cocos2d::Ref * pTarget, const char * pSelectorName) override; virtual cocos2d::SEL_CallFuncN onResolveREDCCCallFuncSelector(cocos2d::Ref * pTarget, const char* pSelectorName) override ; virtual bool onAssignREDMemberVariable(cocos2d::Ref * pTarget, const char * pMemberVariableName, cocos2d::Node * node) override; virtual bool onAssignREDCustomProperty(cocos2d::Ref* target, const char* memberVariableName, const cocos2d::Value& value) override; virtual void onNodeLoaded(cocos2d::Node * node, redream::NodeLoader * nodeLoader) override; virtual void registerCompletedAniCallBack(std::function callback); virtual void setAnimManager(redream::REDReader::REDAnimationManagerMapPtr map); redream::REDAnimationManager* getAnimManager(){return _mAnimCtrl;} virtual bool isValidAnim(std::string animName); // 是否合法的动画名 virtual float getAnimTime(std::string animName); virtual void playAnim(std::string animName, const std::function &cbFinishAnim = nullptr, const std::string cbScheduleKey = ""); virtual void playAnimAndRemoveSelf(std::string animName); virtual void setAnimationSpeed(float tRate); Spawn* getNodeAniByName(std::string timeLineName, std::string nodeName,const Vec2& orginPos); void changeToOtherParent(Node* newParent); void setCcbiName(const string&); bool setCBSpriteName(string spriteName,string spriteFrameName); Value getCustomeProperty(const char* name); bool hasChileByName(std::string name); Node* getByName(std::string name); Sprite* getSprite(std::string name); Label* getLabel(std::string name); ParticleSystemQuad* getParticle(std::string name); ZMLCCParticleSystemQuad* getZMLCCParticle(std::string name); RRP::RParticleSystem* getRParticle(std::string name); QCoreLayer* getCoreLayer(std::string name); QCoreBtn* getCoreBtn(std::string name); void updateAnimSpeed(float speed); void SmartScaleHeightNode(Node* layer, cocos2d::Size designSize); template inline T* getCcbVarByName(const char* name){ auto iter = _mapChilden.find(std::string(name)); //CCAssert(iter != _mapChilden.end(), "ccb无这个变量???"); if(iter!=_mapChilden.end()){ return (T*)iter->second; }else{ log("ccb无这个变量%s",name); return nullptr; } } protected: map> _timelineCallbacks; map _timelineCallbackListeners; void onTimeLineCallback(Node*){} public: void setTimelineCallback(string selectorName,function func){ _timelineCallbacks[selectorName] = func ; } protected: redream::REDAnimationManager* _mAnimCtrl = nullptr; M_SNODE _mapChilden; std::map _customProperties; QCoreLayerDelegate* _aniDelegate = nullptr; std::function _cbOnExit = nullptr; string _ccbName; }; class QCoreLayerLoader : public redream::LayerLoader { public: RED_STATIC_NEW_AUTORELEASE_OBJECT_METHOD(QCoreLayerLoader, loader); protected: RED_VIRTUAL_NEW_AUTORELEASE_CREATECCNODE_METHOD(QCoreLayer); }; NS_RU_END #endif /* defined(RUQCoreLayer_h) */