TriggerMng.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /****************************************************************************
  2. Copyright (c) 2013-2017 Chukong Technologies Inc.
  3. http://www.cocos2d-x.org
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. ****************************************************************************/
  20. #ifndef __TRIGGERMNG_H__
  21. #define __TRIGGERMNG_H__
  22. #include "editor-support/cocostudio/CocoStudio.h"
  23. namespace cocos2d {
  24. class EventDispatcher;
  25. class EventListener;
  26. }
  27. namespace cocostudio {
  28. class TriggerObj;
  29. class CC_STUDIO_DLL ArmatureMovementDispatcher : public cocos2d::Ref
  30. {
  31. public:
  32. ArmatureMovementDispatcher(void);
  33. ~ArmatureMovementDispatcher(void);
  34. public:
  35. void addAnimationEventCallBack(cocos2d::Ref*pTarget, SEL_MovementEventCallFunc mecf);
  36. void removeAnnimationEventCallBack(cocos2d::Ref*pTarget, SEL_MovementEventCallFunc mecf);
  37. void animationEvent(Armature *armature, MovementEventType movementType, const std::string& movementID);
  38. private:
  39. std::unordered_map<cocos2d::Ref*, SEL_MovementEventCallFunc> *_mapEventAnimation;
  40. };
  41. class CC_STUDIO_DLL TriggerMng
  42. {
  43. public:
  44. TriggerMng(void);
  45. virtual ~TriggerMng(void);
  46. public:
  47. static TriggerMng* getInstance();
  48. static void destroyInstance();
  49. static const char* triggerMngVersion();
  50. public:
  51. void parse(const rapidjson::Value &root);
  52. void parse(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
  53. void removeAll(void);
  54. cocos2d::Vector<TriggerObj*>* get(unsigned int event) const;
  55. TriggerObj* getTriggerObj(unsigned int id) const;
  56. bool removeTriggerObj(TriggerObj *Obj);
  57. bool removeTriggerObj(unsigned int id);
  58. bool isEmpty(void) const;
  59. void addArmatureMovementCallBack(Armature *pAr, cocos2d::Ref *pTarget, SEL_MovementEventCallFunc mecf);
  60. void removeArmatureMovementCallBack(Armature *pAr, cocos2d::Ref *pTarget, SEL_MovementEventCallFunc mecf);
  61. void removeArmatureAllMovementCallBack(Armature *pAr);
  62. void removeAllArmatureMovementCallBack();
  63. void dispatchEvent(cocos2d::EventCustom* tEvent);
  64. void removeEventListener(cocos2d::EventListener* listener);
  65. void addEventListenerWithFixedPriority(cocos2d::EventListener* listener, int fixedPriority);
  66. private:
  67. void buildJson(rapidjson::Document &document, cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
  68. private:
  69. static TriggerMng *_sharedTriggerMng;
  70. std::unordered_map<unsigned int, TriggerObj*> _triggerObjs;
  71. std::unordered_map<Armature*, ArmatureMovementDispatcher*> *_movementDispatches;
  72. cocos2d::EventDispatcher* _eventDispatcher; ///< event dispatcher used to dispatch all kinds of events
  73. };
  74. }
  75. #endif