// // ReboltRedManager.h // empty2dx-desktop // // Created by zhu on 2022/8/3. // #ifndef ReboltRedManager_h #define ReboltRedManager_h #include #include #include #include "cocos2d.h" #include "ReboltRunDelegate.hpp" #include "behaviac/RedBehaviacTree.h" #include "extensions/cocos-ext.h" #include "../REDAnimationManager.h" #include "AsyncWaiterContainer.hpp" #include "NotifyDevelopmentWaiter.hpp" namespace redream { typedef enum ReboltRedManagerEBTStatus { ReboltRedManagerBT_INVALID, ReboltRedManagerBT_SUCCESS, ReboltRedManagerBT_FAILURE, ReboltRedManagerBT_RUNNING, } ReboltRedManagerEBTStatus; typedef struct RootRedManger{ std::string selfPath = ""; ReboltRedManager* rootRedManger; } RootReboltManger; class NotifyDevelopmentDelegate { public: virtual void onNotifyDevelopment(ReboltRedManager* reboltRedManager, NotifyDevelopmentWaiter* waiter, std::string notify, std::string param, bool reboltIsWait, Node* outNode) = 0; }; class ReboltRedManager: public cocos2d::Ref, public AsyncWaiterContainer { public: ReboltRedManager(); virtual ~ReboltRedManager(); void update(float dt); red::RedBehaviacTree* createBehaviacTree(std::string treeName, const std::map& boolMap, const std::map& stringMap); /// 获取red文件对应的根节点指针 cocos2d::Node* getRootNode(); std::vector getRootRedMangers(){return _rootRedMangers;} bool onAssignREDReboltRedManagerReboltPath(cocos2d::Ref* target, const char* reboltPath, ReboltRedManager* pReboltRedManager); /// 解析protobuf过程中的回调接口,提供给manger进行绑定和处理逻辑 /// - Parameters: /// - target: ReboltRedManager的指针,用来判断是否是自己 /// - reboltName: 解析中节点的reboltName /// - reboltId: 解析中节点的reboltId /// - pNode: 正在解析中的节点 virtual bool onAssignREDReboltRedManagerReboltName(cocos2d::Ref* target, const char* reboltName, const char* reboltId, cocos2d::Node* pNode); void parseTreeMapAndStartUpdate(); void setREDAnimationManager(REDAnimationManager* pREDAnimationManager); REDAnimationManager* getREDAnimationManager(); void setTreeTypeNameMap(std::map> treeTypeNameMap){_treeTypeNameMap = treeTypeNameMap;} std::map> getTreeTypeNameMap(){return _treeTypeNameMap;} void setRootRedMangers(std::vector rrmv){_rootRedMangers = rrmv;} void setFunParam(std::map>> funParam){_funParam = funParam;} void setReboltRunDelegate(ReboltRunDelegate* reboltRunDelegate){_reboltRunDelegate = reboltRunDelegate;} void setNotifyDevelopmentDelegate(NotifyDevelopmentDelegate* ndd){_notifyDevelopmentDelegate = ndd;}; NotifyDevelopmentDelegate* getNotifyDevelopmentDelegate(){return _notifyDevelopmentDelegate;} void setNotifyDevelopmentDelegate4AllChildren(NotifyDevelopmentDelegate* ndd); void setGlobalDataVar(std::string key, std::string content); void setCoderDataVar(std::string key, std::string content); /// 播放场景的行为树 /// @param treeName 行为树Id std::string runBehaviacTree(const std::string& treeName, const std::map& boolMap, const std::map& stringMap); /// 设置red文件对应的根节点指针 /// - Parameter pRootNode: 根节点指针 void setRootNode(cocos2d::Node* pRootNode); std::string runBehaviacWhitFunName(std::string name, std::map boolMap = {}, std::map stringMap = {}); void runAnimFile(cocos2d::Node* node, std::string animPath, cocos2d::Vec2 startPos, cocos2d::Vec2 endPos, const std::function &func, ReboltErrorInfo& errorInfo); private: void onButtonClick(cocos2d::Ref * sender, cocos2d::extension::Control::EventType pControlEvent); void runBehaviacWhitButtonClick(std::string btnName); void runBehaviacWhitMsg(ValueMap& msg); void onTreeRunEnd(int endType, std::string treeName); void onSubTreeRunEnd(int endType, std::string redPath, std::string treeName); ReboltRunDelegate* getReboltRunDelegate(){return _reboltRunDelegate;} friend class red::RedBehaviacTree; friend class WaitableStateBase; public: //解析过程中的接口 REDAnimationManager* getSubREDAnimationManager(std::string redPath); /// 设置reboltId /// - Parameter rId: reboltId void setReboltId(const std::string rId); std::string getReboltId(); /// 添加行为树的实例化对象 /// - Parameters: /// - tree: 行为树对象指针 /// - treeName: 行为树的名字,目前的命名规则是行为树的ID+自增长的行为树序号 void addBehaviacTree(red::RedBehaviacTree* tree, std::string treeName); /// 删除缓存的行为树对象 /// - Parameter treeName: 行为树的名字 void removeBehaviacTree(std::string treeName); /// 直接全部重新设置数组 /// - Parameters: /// - dataName: 数组的名字 /// - vec: 数组的内容 void setList(std::string dataName,std::vector vec); private: //胶水代码接口 float getCustomFloat(std::string key, ReboltErrorInfo& errorInfo); float getCoderFloat(std::string key, ReboltErrorInfo& errorInfo); float getGlobalFloat(std::string key, ReboltErrorInfo& errorInfo); std::string getCustomString(std::string key, ReboltErrorInfo& errorInfo); std::string getCoderString(std::string key, ReboltErrorInfo& errorInfo); std::string getGlobalString(std::string key, ReboltErrorInfo& errorInfo); vector& getGlobalVector(std::string key); void setCustomDataVar(std::string key, std::string content); void messageSend(std::string messageName, std::string messageValue); void showNode(std::string nodeName, ReboltErrorInfo& errorInfo); void playTimeLine(std::string actionId, ReboltErrorInfo& errorInfo); void stopTimeLine(ReboltErrorInfo& errorInfo); void setLabelTitle(std::string labelName, std::string content, ReboltErrorInfo& errorInfo); void redProgressBar(std::string barName, float percentage, ReboltErrorInfo& errorInfo); float getNodeGlobalPostionX(std::string nodeName, ReboltErrorInfo& errorInfo); float getNodeGlobalPostionY(std::string nodeName, ReboltErrorInfo& errorInfo); void listVarAdd(std::string dataName, std::string content); float listVarCount(std::string dataName); void listVarDeleteAll(std::string dataName); void listVarDeleteOne(std::string dataName, int index, ReboltErrorInfo& errorInfo); float listVarFindValueID(std::string dataName, std::string content, ReboltErrorInfo& errorInfo); bool listVarHasValue(std::string dataName, std::string content); std::string listVarIndexValue(std::string dataName, int index, ReboltErrorInfo& errorInfo); void listVarInsertBefore(std::string dataName, int index, std::string content, ReboltErrorInfo& errorInfo); void listVarReplace(std::string dataName, int index, std::string content, ReboltErrorInfo& errorInfo); //AD bool rewardVideoIsLoad(std::string adName); // 控制子节点的内容 void playSubredTimeLine(std::string redPath, std::string actionName, ReboltErrorInfo& errorInfo); void stopSubredTimeLine(std::string redPath, ReboltErrorInfo& errorInfo); void subredProgressBar(std::string redPath, std::string barName, float percentage, ReboltErrorInfo& errorInfo); float getSubredNodeGlobalPostionX(std::string redPath, std::string nodeName, ReboltErrorInfo& errorInfo); float getSubredNodeGlobalPostionY(std::string redPath, std::string nodeName, ReboltErrorInfo& errorInfo); void setSubredLabelTitle(std::string redPath, std::string labelName, std::string content, ReboltErrorInfo& errorInfo); // 控制Sprite的填充内容 void setSpriteImage(std::string nodeId, std::string imagePath, ReboltErrorInfo& errorInfo); void setSpritePlist(std::string nodeId, std::string plistPath, std::string frameName, ReboltErrorInfo& errorInfo); void setSubredSpriteImage(std::string redPath, std::string nodeId, std::string imagePath, ReboltErrorInfo& errorInfo); void setSubredSpritePlist(std::string redPath, std::string nodeId, std::string plistPath, std::string frameName, ReboltErrorInfo& errorInfo); //播放动画文件 void nodeSetAnimAction(std::string nodeId, std::string animPath, cocos2d::Vec2 startPos, cocos2d::Vec2 endPos, ReboltErrorInfo& errorInfo); //播放wwsie声音文件 void playWiseSound(std::string& bnkPath, std::string& eventName, ReboltErrorInfo& errorInfo); private: //!<时间线Id,播放状态> std::map _animFileStatusMap; //!<时间线Id,播放状态> std::map _nodeMap; //! map _buttonNameMap; //! cocos2d::Map _pathRedMangerMap; //!<路径,子ReboltRedManager> //! std::map> _treeTypeNameMap; //! <树类型,<树的名字,树的文件名>> std::map _behaviacTreeMap; //! 行为树的实例化对象存在这里面 std::vector _waitDelTreeNameVec; std::map _waitAddTreeMap; std::map>> _funParam; //! <函数ID,<参数数据类型,[数名列表]>> std::string _reboltId; std::vector _rootRedMangers; map _customVarStringMap; map _coderVarStringMap; map> _localStringVectorMap; //!<数组名称,[string]> REDAnimationManager* _redAnimationManager; cocos2d::Node* _rootNode; EventListenerCustom* _eventListener; int _treeIndex; //!自增长的树索引 int _animIndex; //!自增长的时间线索引 private: /// 处理Control的读取逻辑 void onResolveREDControlRebolt(cocos2d::Ref* target, const char* reboltName, const char* reboltId, cocos2d::Node* pNode); int getTreeIndex(); int getAnimIndex(); void playOneTimeLine(std::string actionId, int tag); cocos2d::Node* getNodeByKey(std::string key, ReboltErrorInfo& errorInfo); cocos2d::Node* getSubredNodeByKey(std::string redPath, std::string key, ReboltErrorInfo& errorInfo); cocos2d::extension::Control* getControlByKey(std::string key, ReboltErrorInfo& errorInfo); cocos2d::extension::Control* getSubredControlByKey(std::string redPath, std::string key, ReboltErrorInfo& errorInfo); void updateTreeWithName(std::string redPath, std::string treeName, std::string subTreeName); private: NotifyDevelopmentDelegate* _notifyDevelopmentDelegate; ReboltRunDelegate* _reboltRunDelegate; private: ReboltRedManager* getReboltRedManagerByPath(std::string path, ReboltErrorInfo& errorInfo); std::string getAnimFileKey(std::string nodeId, std::string animPath); private: void onClickSubRedButton(cocos2d::Ref * sender, cocos2d::extension::Control::EventType pControlEvent, std::string redPath, std::string clickName); }; }; #endif /* ReboltRedManager_hpp */