RUQCoreLayer.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //
  2. // Redream的QCoreLayer加载类
  3. //
  4. #ifndef RUQCoreLayer_h
  5. #define RUQCoreLayer_h
  6. #include "cocos2d.h"
  7. #include "extensions/cocos-ext.h"
  8. #include "rparticle/RParticleSystem.h"
  9. #include "Redream.h"
  10. #include "RUDefine.h"
  11. #include <unordered_set>
  12. USING_NS_CC;
  13. USING_NS_CC_EXT;
  14. using namespace std;
  15. NS_RU_BEGIN
  16. class QCoreBtn;
  17. class QCoreLayerDelegate
  18. : public Ref
  19. ,public redream::REDAnimationManagerDelegate{
  20. public:
  21. virtual void completedAnimationSequenceNamed(const char *name, int seqId,int tag) override;
  22. virtual void registerCompletedAniCallBack(std::function<void(string name)> callback);
  23. protected:
  24. std::function<void(string name)> _completedAniCallBack = nullptr;
  25. };
  26. typedef std::unordered_map<std::string,Node*> M_SNODE;
  27. class QCoreLayer
  28. :public Layer
  29. ,public redream::REDSelectorResolver
  30. ,public redream::REDMemberVariableAssigner
  31. ,public redream::NodeLoaderListener
  32. {
  33. public:
  34. static QCoreLayer* Layer(const string& file,bool batchReader=false);
  35. static redream::NodeLoaderLibrary* sharedLibrary();
  36. static QCoreLayer* LayerBatchReader(string file,unordered_set<string> plistSt);
  37. static QCoreLayer* LayerBatchReader(string file,unordered_set<string> plistSt,unordered_set<string> repleacPlistSt);
  38. static void registerNodeLoaderLibrary(tuple<const char *, redream::NodeLoader *> nodeLoaderArr);
  39. static QCoreLayer* loadFromRED(string pREDFileName,Ref* owner = nullptr);
  40. static int _count;
  41. RED_STATIC_NEW_AUTORELEASE_OBJECT_WITH_INIT_METHOD(QCoreLayer, create);
  42. QCoreLayer();
  43. ~QCoreLayer();
  44. virtual void onExit() override;
  45. std::function<void(const string&, QCoreLayer*)> setCbOnExit(std::function<void(const string&, QCoreLayer*)> cb);
  46. virtual cocos2d::SEL_MenuHandler onResolveREDCCMenuItemSelector(cocos2d::Ref * pTarget, const char * pSelectorName) override;
  47. virtual cocos2d::extension::Control::Handler onResolveREDCCControlSelector(cocos2d::Ref * pTarget, const char * pSelectorName) override;
  48. virtual cocos2d::SEL_CallFuncN onResolveREDCCCallFuncSelector(cocos2d::Ref * pTarget, const char* pSelectorName) override ;
  49. virtual bool onAssignREDMemberVariable(cocos2d::Ref * pTarget, const char * pMemberVariableName, cocos2d::Node * node) override;
  50. virtual bool onAssignREDCustomProperty(cocos2d::Ref* target, const char* memberVariableName, const cocos2d::Value& value) override;
  51. virtual void onNodeLoaded(cocos2d::Node * node, redream::NodeLoader * nodeLoader) override;
  52. virtual void registerCompletedAniCallBack(std::function<void(string name)> callback);
  53. virtual void setAnimManager(redream::REDReader::REDAnimationManagerMapPtr map);
  54. redream::REDAnimationManager* getAnimManager(){return _mAnimCtrl;}
  55. virtual bool isValidAnim(std::string animName); // 是否合法的动画名
  56. virtual float getAnimTime(std::string animName);
  57. virtual void playAnim(std::string animName, const std::function<void(float)> &cbFinishAnim = nullptr, const std::string cbScheduleKey = "");
  58. virtual void playAnimAndRemoveSelf(std::string animName);
  59. virtual void setAnimationSpeed(float tRate);
  60. Spawn* getNodeAniByName(std::string timeLineName, std::string nodeName,const Vec2& orginPos);
  61. void changeToOtherParent(Node* newParent);
  62. void setCcbiName(const string&);
  63. bool setCBSpriteName(string spriteName,string spriteFrameName);
  64. Value getCustomeProperty(const char* name);
  65. bool hasChileByName(std::string name);
  66. Node* getByName(std::string name);
  67. Sprite* getSprite(std::string name);
  68. Label* getLabel(std::string name);
  69. ParticleSystemQuad* getParticle(std::string name);
  70. ZMLCCParticleSystemQuad* getZMLCCParticle(std::string name);
  71. RRP::RParticleSystem* getRParticle(std::string name);
  72. QCoreLayer* getCoreLayer(std::string name);
  73. QCoreBtn* getCoreBtn(std::string name);
  74. void updateAnimSpeed(float speed);
  75. void SmartScaleHeightNode(Node* layer, cocos2d::Size designSize);
  76. template <class T>
  77. inline T* getCcbVarByName(const char* name){
  78. auto iter = _mapChilden.find(std::string(name));
  79. //CCAssert(iter != _mapChilden.end(), "ccb无这个变量???");
  80. if(iter!=_mapChilden.end()){
  81. return (T*)iter->second;
  82. }else{
  83. log("ccb无这个变量%s",name);
  84. return nullptr;
  85. }
  86. }
  87. protected:
  88. map<string,function<void()>> _timelineCallbacks;
  89. map<string,EventListenerCustom*> _timelineCallbackListeners;
  90. void onTimeLineCallback(Node*){}
  91. public:
  92. void setTimelineCallback(string selectorName,function<void()> func){
  93. _timelineCallbacks[selectorName] = func ;
  94. }
  95. protected:
  96. redream::REDAnimationManager* _mAnimCtrl = nullptr;
  97. M_SNODE _mapChilden;
  98. std::map<std::string, Value> _customProperties;
  99. QCoreLayerDelegate* _aniDelegate = nullptr;
  100. std::function<void(const string&, QCoreLayer*)> _cbOnExit = nullptr;
  101. string _ccbName;
  102. };
  103. class QCoreLayerLoader : public redream::LayerLoader {
  104. public:
  105. RED_STATIC_NEW_AUTORELEASE_OBJECT_METHOD(QCoreLayerLoader, loader);
  106. protected:
  107. RED_VIRTUAL_NEW_AUTORELEASE_CREATECCNODE_METHOD(QCoreLayer);
  108. };
  109. NS_RU_END
  110. #endif /* defined(RUQCoreLayer_h) */