diff --git a/cocos/2d/CCEventCustom.cpp b/cocos/2d/CCEventCustom.cpp index 89e56a3a69..8960b9fd87 100644 --- a/cocos/2d/CCEventCustom.cpp +++ b/cocos/2d/CCEventCustom.cpp @@ -24,14 +24,15 @@ #include "CCEventCustom.h" #include "ccMacros.h" +#include NS_CC_BEGIN -EventCustom::EventCustom(Type type) -: Event(type) +EventCustom::EventCustom(const std::string& eventName) +: Event(std::hash()(eventName)) , _userData(nullptr) { - CCASSERT(type >= TYPE_CUSTOM, "custom type should be greater than TYPE_CUSTOM."); +// CCASSERT(type >= TYPE_CUSTOM, "custom type should be greater than TYPE_CUSTOM."); } NS_CC_END diff --git a/cocos/2d/CCEventCustom.h b/cocos/2d/CCEventCustom.h index 96676cdbfd..c4521e3bbf 100644 --- a/cocos/2d/CCEventCustom.h +++ b/cocos/2d/CCEventCustom.h @@ -33,7 +33,7 @@ class EventCustom : public Event { public: /** Constructor */ - EventCustom(Type type); + EventCustom(const std::string& eventName); /** Set user data */ inline void setUserData(void* data) { _userData = data; }; diff --git a/cocos/2d/CCEventListenerCustom.cpp b/cocos/2d/CCEventListenerCustom.cpp index 3875f61c94..048fede198 100644 --- a/cocos/2d/CCEventListenerCustom.cpp +++ b/cocos/2d/CCEventListenerCustom.cpp @@ -32,10 +32,10 @@ EventListenerCustom::EventListenerCustom() { } -EventListenerCustom* EventListenerCustom::create(Type type, std::function callback) +EventListenerCustom* EventListenerCustom::create(const std::string& eventName, std::function callback) { EventListenerCustom* ret = new EventListenerCustom(); - if (ret && ret->init(type, callback)) + if (ret && ret->init(std::hash()(eventName), callback)) { ret->autorelease(); } @@ -46,7 +46,7 @@ EventListenerCustom* EventListenerCustom::create(Type type, std::functioncallback) +bool EventListenerCustom::init(Type type, std::functioncallback) { bool ret = false; diff --git a/cocos/2d/CCEventListenerCustom.h b/cocos/2d/CCEventListenerCustom.h index 285d257cd3..0bd5bec700 100644 --- a/cocos/2d/CCEventListenerCustom.h +++ b/cocos/2d/CCEventListenerCustom.h @@ -56,7 +56,7 @@ public: * @param eventType The type of the event. * @param callback The callback function when the specified event was emitted. */ - static EventListenerCustom* create(int type, std::function callback); + static EventListenerCustom* create(const std::string& eventName, std::function callback); /// Overrides virtual bool checkAvailable() override; @@ -67,7 +67,7 @@ protected: EventListenerCustom(); /** Initializes event with type and callback function */ - bool init(int type, std::function callback); + bool init(Type type, std::function callback); std::function _onCustomEvent; };