123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- //
- // 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 <unordered_set>
- 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<void(string name)> callback);
- protected:
- std::function<void(string name)> _completedAniCallBack = nullptr;
- };
- typedef std::unordered_map<std::string,Node*> 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<string> plistSt);
- static QCoreLayer* LayerBatchReader(string file,unordered_set<string> plistSt,unordered_set<string> repleacPlistSt);
- static void registerNodeLoaderLibrary(tuple<const char *, redream::NodeLoader *> 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<void(const string&, QCoreLayer*)> setCbOnExit(std::function<void(const string&, QCoreLayer*)> 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<void(string name)> 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<void(float)> &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 <class T>
- 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<string,function<void()>> _timelineCallbacks;
- map<string,EventListenerCustom*> _timelineCallbackListeners;
- void onTimeLineCallback(Node*){}
- public:
- void setTimelineCallback(string selectorName,function<void()> func){
- _timelineCallbacks[selectorName] = func ;
- }
-
- protected:
- redream::REDAnimationManager* _mAnimCtrl = nullptr;
- M_SNODE _mapChilden;
- std::map<std::string, Value> _customProperties;
- QCoreLayerDelegate* _aniDelegate = nullptr;
- std::function<void(const string&, QCoreLayer*)> _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) */
|