123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- //
- // ReboltRedManager.h
- // empty2dx-desktop
- //
- // Created by zhu on 2022/8/3.
- //
- #ifndef ReboltRedManager_h
- #define ReboltRedManager_h
- #include <set>
- #include <string>
- #include <vector>
- #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<std::string, bool>& boolMap, const std::map<std::string, std::string>& stringMap);
-
- /// 获取red文件对应的根节点指针
- cocos2d::Node* getRootNode();
-
- std::vector<RootReboltManger> 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<std::string, std::map<std::string, std::string>> treeTypeNameMap){_treeTypeNameMap = treeTypeNameMap;}
-
- std::map<std::string, std::map<std::string, std::string>> getTreeTypeNameMap(){return _treeTypeNameMap;}
-
- void setRootRedMangers(std::vector<RootReboltManger> rrmv){_rootRedMangers = rrmv;}
-
- void setFunParam(std::map<std::string, std::map<std::string, std::vector<std::string>>> 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<std::string, bool>& boolMap, const std::map<std::string, std::string>& stringMap);
-
- /// 设置red文件对应的根节点指针
- /// - Parameter pRootNode: 根节点指针
- void setRootNode(cocos2d::Node* pRootNode);
-
- std::string runBehaviacWhitFunName(std::string name, std::map<std::string, bool> boolMap = {}, std::map<std::string, std::string> stringMap = {});
-
- void runAnimFile(cocos2d::Node* node, std::string animPath, cocos2d::Vec2 startPos, cocos2d::Vec2 endPos, const std::function<void()> &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<std::string> 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<std::string>& 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<std::string, ReboltRedManagerEBTStatus> _animFileStatusMap; //!<时间线Id,播放状态>
-
- std::map<std::string, cocos2d::Node*> _nodeMap; //!<reboltId,节点指针>
- map<cocos2d::Ref*, std::string> _buttonNameMap; //!<button指针,reboltId>
- cocos2d::Map<std::string, ReboltRedManager*> _pathRedMangerMap; //!<路径,子ReboltRedManager>
- //!
- std::map<std::string, std::map<std::string, std::string>> _treeTypeNameMap; //! <树类型,<树的名字,树的文件名>>
- std::map<std::string, red::RedBehaviacTree*> _behaviacTreeMap; //! 行为树的实例化对象存在这里面
- std::vector<std::string> _waitDelTreeNameVec;
- std::map<std::string, red::RedBehaviacTree*> _waitAddTreeMap;
-
- std::map<std::string, std::map<std::string, std::vector<std::string>>> _funParam; //! <函数ID,<参数数据类型,[数名列表]>>
-
- std::string _reboltId;
- std::vector<RootReboltManger> _rootRedMangers;
-
- map<std::string, std::string> _customVarStringMap;
-
- map<std::string, std::string> _coderVarStringMap;
-
- map<std::string, std::vector<std::string>> _localStringVectorMap; //!<数组名称,[string]>
-
- REDAnimationManager* _redAnimationManager;
-
- cocos2d::Node* _rootNode;
-
- EventListenerCustom* _eventListener;
-
- int _treeIndex; //!自增长的树索引
-
- int _animIndex; //!自增长的时间线索引
-
- std::vector<std::string> _fileSearchPaths;
- 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 */
|