mirror of https://github.com/axmolengine/axmol.git
issue #3069: Using `std::string` to initialize `EventCustom`. It will be easier for editor parser to emit callback event.
This commit is contained in:
parent
48ce5e39fe
commit
0622434321
|
@ -24,14 +24,15 @@
|
|||
|
||||
#include "CCEventCustom.h"
|
||||
#include "ccMacros.h"
|
||||
#include <functional>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
EventCustom::EventCustom(Type type)
|
||||
: Event(type)
|
||||
EventCustom::EventCustom(const std::string& eventName)
|
||||
: Event(std::hash<std::string>()(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
|
||||
|
|
|
@ -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; };
|
||||
|
|
|
@ -32,10 +32,10 @@ EventListenerCustom::EventListenerCustom()
|
|||
{
|
||||
}
|
||||
|
||||
EventListenerCustom* EventListenerCustom::create(Type type, std::function<void(EventCustom*)> callback)
|
||||
EventListenerCustom* EventListenerCustom::create(const std::string& eventName, std::function<void(EventCustom*)> callback)
|
||||
{
|
||||
EventListenerCustom* ret = new EventListenerCustom();
|
||||
if (ret && ret->init(type, callback))
|
||||
if (ret && ret->init(std::hash<std::string>()(eventName), callback))
|
||||
{
|
||||
ret->autorelease();
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ EventListenerCustom* EventListenerCustom::create(Type type, std::function<void(E
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool EventListenerCustom::init(int type, std::function<void(EventCustom*)>callback)
|
||||
bool EventListenerCustom::init(Type type, std::function<void(EventCustom*)>callback)
|
||||
{
|
||||
bool ret = false;
|
||||
|
||||
|
|
|
@ -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<void(EventCustom*)> callback);
|
||||
static EventListenerCustom* create(const std::string& eventName, std::function<void(EventCustom*)> 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<void(EventCustom*)> callback);
|
||||
bool init(Type type, std::function<void(EventCustom*)> callback);
|
||||
|
||||
std::function<void(EventCustom*)> _onCustomEvent;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue