ReboltRedManager.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. //
  2. // ReboltRedManager.h
  3. // empty2dx-desktop
  4. //
  5. // Created by zhu on 2022/8/3.
  6. //
  7. #ifndef ReboltRedManager_h
  8. #define ReboltRedManager_h
  9. #include <set>
  10. #include <string>
  11. #include <vector>
  12. #include "cocos2d.h"
  13. #include "ReboltRunDelegate.hpp"
  14. #include "behaviac/RedBehaviacTree.h"
  15. #include "extensions/cocos-ext.h"
  16. #include "../REDAnimationManager.h"
  17. #include "AsyncWaiterContainer.hpp"
  18. #include "NotifyDevelopmentWaiter.hpp"
  19. namespace redream {
  20. typedef enum ReboltRedManagerEBTStatus {
  21. ReboltRedManagerBT_INVALID,
  22. ReboltRedManagerBT_SUCCESS,
  23. ReboltRedManagerBT_FAILURE,
  24. ReboltRedManagerBT_RUNNING,
  25. } ReboltRedManagerEBTStatus;
  26. typedef struct RootRedManger{
  27. std::string selfPath = "";
  28. ReboltRedManager* rootRedManger;
  29. } RootReboltManger;
  30. class NotifyDevelopmentDelegate
  31. {
  32. public:
  33. virtual void onNotifyDevelopment(ReboltRedManager* reboltRedManager, NotifyDevelopmentWaiter* waiter, std::string notify, std::string param, bool reboltIsWait, Node* outNode) = 0;
  34. };
  35. class ReboltRedManager: public cocos2d::Ref, public AsyncWaiterContainer
  36. {
  37. public:
  38. ReboltRedManager();
  39. virtual ~ReboltRedManager();
  40. void update(float dt);
  41. red::RedBehaviacTree* createBehaviacTree(std::string treeName, const std::map<std::string, bool>& boolMap, const std::map<std::string, std::string>& stringMap);
  42. /// 获取red文件对应的根节点指针
  43. cocos2d::Node* getRootNode();
  44. std::vector<RootReboltManger> getRootRedMangers(){return _rootRedMangers;}
  45. bool onAssignREDReboltRedManagerReboltPath(cocos2d::Ref* target, const char* reboltPath, ReboltRedManager* pReboltRedManager);
  46. /// 解析protobuf过程中的回调接口,提供给manger进行绑定和处理逻辑
  47. /// - Parameters:
  48. /// - target: ReboltRedManager的指针,用来判断是否是自己
  49. /// - reboltName: 解析中节点的reboltName
  50. /// - reboltId: 解析中节点的reboltId
  51. /// - pNode: 正在解析中的节点
  52. virtual bool onAssignREDReboltRedManagerReboltName(cocos2d::Ref* target, const char* reboltName, const char* reboltId, cocos2d::Node* pNode);
  53. void parseTreeMapAndStartUpdate();
  54. void setREDAnimationManager(REDAnimationManager* pREDAnimationManager);
  55. REDAnimationManager* getREDAnimationManager();
  56. void setTreeTypeNameMap(std::map<std::string, std::map<std::string, std::string>> treeTypeNameMap){_treeTypeNameMap = treeTypeNameMap;}
  57. std::map<std::string, std::map<std::string, std::string>> getTreeTypeNameMap(){return _treeTypeNameMap;}
  58. void setRootRedMangers(std::vector<RootReboltManger> rrmv){_rootRedMangers = rrmv;}
  59. void setFunParam(std::map<std::string, std::map<std::string, std::vector<std::string>>> funParam){_funParam = funParam;}
  60. void setReboltRunDelegate(ReboltRunDelegate* reboltRunDelegate){_reboltRunDelegate = reboltRunDelegate;}
  61. void setNotifyDevelopmentDelegate(NotifyDevelopmentDelegate* ndd){_notifyDevelopmentDelegate = ndd;};
  62. NotifyDevelopmentDelegate* getNotifyDevelopmentDelegate(){return _notifyDevelopmentDelegate;}
  63. void setNotifyDevelopmentDelegate4AllChildren(NotifyDevelopmentDelegate* ndd);
  64. void setGlobalDataVar(std::string key, std::string content);
  65. void setCoderDataVar(std::string key, std::string content);
  66. /// 播放场景的行为树
  67. /// @param treeName 行为树Id
  68. std::string runBehaviacTree(const std::string& treeName, const std::map<std::string, bool>& boolMap, const std::map<std::string, std::string>& stringMap);
  69. /// 设置red文件对应的根节点指针
  70. /// - Parameter pRootNode: 根节点指针
  71. void setRootNode(cocos2d::Node* pRootNode);
  72. std::string runBehaviacWhitFunName(std::string name, std::map<std::string, bool> boolMap = {}, std::map<std::string, std::string> stringMap = {});
  73. void runAnimFile(cocos2d::Node* node, std::string animPath, cocos2d::Vec2 startPos, cocos2d::Vec2 endPos, const std::function<void()> &func, ReboltErrorInfo& errorInfo);
  74. private:
  75. void onButtonClick(cocos2d::Ref * sender, cocos2d::extension::Control::EventType pControlEvent);
  76. void runBehaviacWhitButtonClick(std::string btnName);
  77. void runBehaviacWhitMsg(ValueMap& msg);
  78. void onTreeRunEnd(int endType, std::string treeName);
  79. void onSubTreeRunEnd(int endType, std::string redPath, std::string treeName);
  80. ReboltRunDelegate* getReboltRunDelegate(){return _reboltRunDelegate;}
  81. friend class red::RedBehaviacTree;
  82. friend class WaitableStateBase;
  83. public:
  84. //解析过程中的接口
  85. REDAnimationManager* getSubREDAnimationManager(std::string redPath);
  86. /// 设置reboltId
  87. /// - Parameter rId: reboltId
  88. void setReboltId(const std::string rId);
  89. std::string getReboltId();
  90. /// 添加行为树的实例化对象
  91. /// - Parameters:
  92. /// - tree: 行为树对象指针
  93. /// - treeName: 行为树的名字,目前的命名规则是行为树的ID+自增长的行为树序号
  94. void addBehaviacTree(red::RedBehaviacTree* tree, std::string treeName);
  95. /// 删除缓存的行为树对象
  96. /// - Parameter treeName: 行为树的名字
  97. void removeBehaviacTree(std::string treeName);
  98. /// 直接全部重新设置数组
  99. /// - Parameters:
  100. /// - dataName: 数组的名字
  101. /// - vec: 数组的内容
  102. void setList(std::string dataName,std::vector<std::string> vec);
  103. private:
  104. //胶水代码接口
  105. float getCustomFloat(std::string key, ReboltErrorInfo& errorInfo);
  106. float getCoderFloat(std::string key, ReboltErrorInfo& errorInfo);
  107. float getGlobalFloat(std::string key, ReboltErrorInfo& errorInfo);
  108. std::string getCustomString(std::string key, ReboltErrorInfo& errorInfo);
  109. std::string getCoderString(std::string key, ReboltErrorInfo& errorInfo);
  110. std::string getGlobalString(std::string key, ReboltErrorInfo& errorInfo);
  111. vector<std::string>& getGlobalVector(std::string key);
  112. void setCustomDataVar(std::string key, std::string content);
  113. void messageSend(std::string messageName, std::string messageValue);
  114. void showNode(std::string nodeName, ReboltErrorInfo& errorInfo);
  115. void playTimeLine(std::string actionId, ReboltErrorInfo& errorInfo);
  116. void stopTimeLine(ReboltErrorInfo& errorInfo);
  117. void setLabelTitle(std::string labelName, std::string content, ReboltErrorInfo& errorInfo);
  118. void redProgressBar(std::string barName, float percentage, ReboltErrorInfo& errorInfo);
  119. float getNodeGlobalPostionX(std::string nodeName, ReboltErrorInfo& errorInfo);
  120. float getNodeGlobalPostionY(std::string nodeName, ReboltErrorInfo& errorInfo);
  121. void listVarAdd(std::string dataName, std::string content);
  122. float listVarCount(std::string dataName);
  123. void listVarDeleteAll(std::string dataName);
  124. void listVarDeleteOne(std::string dataName, int index, ReboltErrorInfo& errorInfo);
  125. float listVarFindValueID(std::string dataName, std::string content, ReboltErrorInfo& errorInfo);
  126. bool listVarHasValue(std::string dataName, std::string content);
  127. std::string listVarIndexValue(std::string dataName, int index, ReboltErrorInfo& errorInfo);
  128. void listVarInsertBefore(std::string dataName, int index, std::string content, ReboltErrorInfo& errorInfo);
  129. void listVarReplace(std::string dataName, int index, std::string content, ReboltErrorInfo& errorInfo);
  130. //AD
  131. bool rewardVideoIsLoad(std::string adName);
  132. // 控制子节点的内容
  133. void playSubredTimeLine(std::string redPath, std::string actionName, ReboltErrorInfo& errorInfo);
  134. void stopSubredTimeLine(std::string redPath, ReboltErrorInfo& errorInfo);
  135. void subredProgressBar(std::string redPath, std::string barName, float percentage, ReboltErrorInfo& errorInfo);
  136. float getSubredNodeGlobalPostionX(std::string redPath, std::string nodeName, ReboltErrorInfo& errorInfo);
  137. float getSubredNodeGlobalPostionY(std::string redPath, std::string nodeName, ReboltErrorInfo& errorInfo);
  138. void setSubredLabelTitle(std::string redPath, std::string labelName, std::string content, ReboltErrorInfo& errorInfo);
  139. // 控制Sprite的填充内容
  140. void setSpriteImage(std::string nodeId, std::string imagePath, ReboltErrorInfo& errorInfo);
  141. void setSpritePlist(std::string nodeId, std::string plistPath, std::string frameName, ReboltErrorInfo& errorInfo);
  142. void setSubredSpriteImage(std::string redPath, std::string nodeId, std::string imagePath, ReboltErrorInfo& errorInfo);
  143. void setSubredSpritePlist(std::string redPath, std::string nodeId, std::string plistPath, std::string frameName, ReboltErrorInfo& errorInfo);
  144. //播放动画文件
  145. void nodeSetAnimAction(std::string nodeId, std::string animPath, cocos2d::Vec2 startPos, cocos2d::Vec2 endPos, ReboltErrorInfo& errorInfo);
  146. //播放wwsie声音文件
  147. void playWiseSound(std::string& bnkPath, std::string& eventName, ReboltErrorInfo& errorInfo);
  148. private:
  149. //!<时间线Id,播放状态>
  150. std::map<std::string, ReboltRedManagerEBTStatus> _animFileStatusMap; //!<时间线Id,播放状态>
  151. std::map<std::string, cocos2d::Node*> _nodeMap; //!<reboltId,节点指针>
  152. map<cocos2d::Ref*, std::string> _buttonNameMap; //!<button指针,reboltId>
  153. cocos2d::Map<std::string, ReboltRedManager*> _pathRedMangerMap; //!<路径,子ReboltRedManager>
  154. //!
  155. std::map<std::string, std::map<std::string, std::string>> _treeTypeNameMap; //! <树类型,<树的名字,树的文件名>>
  156. std::map<std::string, red::RedBehaviacTree*> _behaviacTreeMap; //! 行为树的实例化对象存在这里面
  157. std::vector<std::string> _waitDelTreeNameVec;
  158. std::map<std::string, red::RedBehaviacTree*> _waitAddTreeMap;
  159. std::map<std::string, std::map<std::string, std::vector<std::string>>> _funParam; //! <函数ID,<参数数据类型,[数名列表]>>
  160. std::string _reboltId;
  161. std::vector<RootReboltManger> _rootRedMangers;
  162. map<std::string, std::string> _customVarStringMap;
  163. map<std::string, std::string> _coderVarStringMap;
  164. map<std::string, std::vector<std::string>> _localStringVectorMap; //!<数组名称,[string]>
  165. REDAnimationManager* _redAnimationManager;
  166. cocos2d::Node* _rootNode;
  167. EventListenerCustom* _eventListener;
  168. int _treeIndex; //!自增长的树索引
  169. int _animIndex; //!自增长的时间线索引
  170. std::vector<std::string> _fileSearchPaths;
  171. private:
  172. /// 处理Control的读取逻辑
  173. void onResolveREDControlRebolt(cocos2d::Ref* target, const char* reboltName, const char* reboltId, cocos2d::Node* pNode);
  174. int getTreeIndex();
  175. int getAnimIndex();
  176. void playOneTimeLine(std::string actionId, int tag);
  177. cocos2d::Node* getNodeByKey(std::string key, ReboltErrorInfo& errorInfo);
  178. cocos2d::Node* getSubredNodeByKey(std::string redPath, std::string key, ReboltErrorInfo& errorInfo);
  179. cocos2d::extension::Control* getControlByKey(std::string key, ReboltErrorInfo& errorInfo);
  180. cocos2d::extension::Control* getSubredControlByKey(std::string redPath, std::string key, ReboltErrorInfo& errorInfo);
  181. void updateTreeWithName(std::string redPath, std::string treeName, std::string subTreeName);
  182. private:
  183. NotifyDevelopmentDelegate* _notifyDevelopmentDelegate;
  184. ReboltRunDelegate* _reboltRunDelegate;
  185. private:
  186. ReboltRedManager* getReboltRedManagerByPath(std::string path, ReboltErrorInfo& errorInfo);
  187. std::string getAnimFileKey(std::string nodeId, std::string animPath);
  188. private:
  189. void onClickSubRedButton(cocos2d::Ref * sender, cocos2d::extension::Control::EventType pControlEvent, std::string redPath, std::string clickName);
  190. };
  191. };
  192. #endif /* ReboltRedManager_hpp */