diff --git a/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id b/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id index 5c639da189..96a90bbb01 100644 --- a/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -8b8a994b2fdf6fd8ef65f714619ce35ff1ca09cf \ No newline at end of file +63ebe9b06aa15d229d0546427ccdae5cde18b857 \ No newline at end of file diff --git a/cocos2dx/Android.mk b/cocos2dx/Android.mk index 0033dd4975..230586e108 100644 --- a/cocos2dx/Android.mk +++ b/cocos2dx/Android.mk @@ -47,6 +47,8 @@ effects/CCGrabber.cpp \ effects/CCGrid.cpp \ event_dispatcher/CCAccelerationEvent.cpp \ event_dispatcher/CCAccelerationEventListener.cpp \ +event_dispatcher/CCCustomEvent.cpp \ +event_dispatcher/CCCustomEventListener.cpp \ event_dispatcher/CCEvent.cpp \ event_dispatcher/CCEventDispatcher.cpp \ event_dispatcher/CCEventListener.cpp \ diff --git a/cocos2dx/base_nodes/CCNode.cpp b/cocos2dx/base_nodes/CCNode.cpp index 5310d0312a..2bf360daaf 100644 --- a/cocos2dx/base_nodes/CCNode.cpp +++ b/cocos2dx/base_nodes/CCNode.cpp @@ -1323,7 +1323,7 @@ void Node::setDirtyForAllEventListeners() for (auto& listener : _eventlisteners) { - dispatcher->setDirtyForEventType(listener->type, true); + dispatcher->setDirtyForEventType(listener->_type, true); } } diff --git a/cocos2dx/event_dispatcher/CCAccelerationEventListener.h b/cocos2dx/event_dispatcher/CCAccelerationEventListener.h index b107cbfc76..d5a3b85eaf 100644 --- a/cocos2dx/event_dispatcher/CCAccelerationEventListener.h +++ b/cocos2dx/event_dispatcher/CCAccelerationEventListener.h @@ -34,12 +34,13 @@ class AccelerationEventListener : public EventListener { public: static AccelerationEventListener* create(std::function callback); - virtual AccelerationEventListener* clone() override; - ~AccelerationEventListener(); + + /// Overrides + virtual AccelerationEventListener* clone() override; + virtual bool checkAvaiable() override; private: AccelerationEventListener(); - virtual bool checkAvaiable() override; bool init(std::function callback); std::function onAccelerationEvent; diff --git a/cocos2dx/event_dispatcher/CCCustomEvent.cpp b/cocos2dx/event_dispatcher/CCCustomEvent.cpp new file mode 100644 index 0000000000..460b9b96f6 --- /dev/null +++ b/cocos2dx/event_dispatcher/CCCustomEvent.cpp @@ -0,0 +1,35 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "CCCustomEvent.h" + +NS_CC_BEGIN + +CustomEvent::CustomEvent(const std::string& eventName) +: Event(eventName) +, _userData(nullptr) +{ +} + +NS_CC_END diff --git a/cocos2dx/event_dispatcher/CCCustomEvent.h b/cocos2dx/event_dispatcher/CCCustomEvent.h new file mode 100644 index 0000000000..f1255bffc8 --- /dev/null +++ b/cocos2dx/event_dispatcher/CCCustomEvent.h @@ -0,0 +1,50 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#ifndef __cocos2d_libs__CCCustomEvent__ +#define __cocos2d_libs__CCCustomEvent__ + +#include "CCEvent.h" + +NS_CC_BEGIN + +class CustomEvent : public Event +{ +public: + /** Constructor */ + CustomEvent(const std::string& eventName); + + /** Set user data */ + inline void setUserData(void* data) { _userData = data; }; + + /** Get user data */ + inline void* getUserData() const { return _userData; }; + +protected: + void* _userData; ///< User data +}; + +NS_CC_END + +#endif /* defined(__cocos2d_libs__CCCustomEvent__) */ diff --git a/cocos2dx/event_dispatcher/CCCustomEventListener.cpp b/cocos2dx/event_dispatcher/CCCustomEventListener.cpp new file mode 100644 index 0000000000..d575a71591 --- /dev/null +++ b/cocos2dx/event_dispatcher/CCCustomEventListener.cpp @@ -0,0 +1,93 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "CCCustomEventListener.h" +#include "CCCustomEvent.h" + +NS_CC_BEGIN + +CustomEventListener::CustomEventListener() +: _onCustomEvent(nullptr) +{ +} + +CustomEventListener* CustomEventListener::create(const std::string& eventName, std::function callback) +{ + CustomEventListener* ret = new CustomEventListener(); + if (ret && ret->init(eventName, callback)) + { + ret->autorelease(); + } + else + { + CC_SAFE_DELETE(ret); + } + return ret; +} + +bool CustomEventListener::init(const std::string& eventName, std::functioncallback) +{ + bool ret = false; + + _onCustomEvent = callback; + + auto listener = [this](Event* event){ + if (_onCustomEvent != nullptr) + { + _onCustomEvent(static_cast(event)); + } + }; + + if (EventListener::init(eventName, listener)) + { + ret = true; + } + return ret; +} + +CustomEventListener* CustomEventListener::clone() +{ + CustomEventListener* ret = new CustomEventListener(); + if (ret && ret->init(_type, _onCustomEvent)) + { + ret->autorelease(); + } + else + { + CC_SAFE_DELETE(ret); + } + return ret; +} + +bool CustomEventListener::checkAvaiable() +{ + bool ret = false; + if (EventListener::checkAvaiable() && _onCustomEvent != nullptr) + { + ret = true; + } + return ret; +} + +NS_CC_END diff --git a/cocos2dx/event_dispatcher/CCCustomEventListener.h b/cocos2dx/event_dispatcher/CCCustomEventListener.h new file mode 100644 index 0000000000..4e5785ad0e --- /dev/null +++ b/cocos2dx/event_dispatcher/CCCustomEventListener.h @@ -0,0 +1,77 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#ifndef __cocos2d_libs__CCCustomEventListener__ +#define __cocos2d_libs__CCCustomEventListener__ + +#include "CCEventListener.h" + +NS_CC_BEGIN + +class CustomEvent; + +/** + * Usage: + * auto dispatcher = EventDispatcher::getInstance(); + * Adds a listener: + * + * auto callback = [](CustomEvent* event){ do_some_thing(); }; + * auto listener = CustomEventListener::create(callback); + * dispatcher->addEventListenerWithSceneGraphPriority(listener, one_node); + * + * Dispatchs a custom event: + * + * Event event("your_event_type"); + * dispatcher->dispatchEvent(&event); + * + * Removes a listener + * + * dispatcher->removeListener(listener); + */ +class CustomEventListener : public EventListener +{ +public: + /** Creates an event listener with type and callback. + * @param eventType The type of the event. + * @param callback The callback function when the specified event was emitted. + */ + static CustomEventListener* create(const std::string& eventName, std::function callback); + + /// Overrides + virtual bool checkAvaiable() override; + virtual CustomEventListener* clone() override; + +protected: + /** Constructor */ + CustomEventListener(); + + /** Initializes event with type and callback function */ + bool init(const std::string& eventName, std::function callback); + + std::function _onCustomEvent; +}; + +NS_CC_END + +#endif /* defined(__cocos2d_libs__CCCustomEventListener__) */ diff --git a/cocos2dx/event_dispatcher/CCEvent.cpp b/cocos2dx/event_dispatcher/CCEvent.cpp index 9dbe5030ca..1dc9294d83 100644 --- a/cocos2dx/event_dispatcher/CCEvent.cpp +++ b/cocos2dx/event_dispatcher/CCEvent.cpp @@ -30,7 +30,6 @@ Event::Event(const std::string& type) : _type(type) , _isStopped(false) , _currentTarget(nullptr) -, _userData(nullptr) { } diff --git a/cocos2dx/event_dispatcher/CCEvent.h b/cocos2dx/event_dispatcher/CCEvent.h index fb31f7e6e0..b9a2abb734 100644 --- a/cocos2dx/event_dispatcher/CCEvent.h +++ b/cocos2dx/event_dispatcher/CCEvent.h @@ -40,10 +40,10 @@ class Node; */ class Event { -public: +protected: /** Constructor */ Event(const std::string& type); - +public: /** Destructor */ virtual ~Event(); @@ -63,12 +63,6 @@ public: */ inline Node* getCurrentTarget() { return _currentTarget; }; - /** Set user data */ - inline void setUserData(void* data) { _userData = data; }; - - /** Get user data */ - inline void* getUserData() const { return _userData; }; - protected: /** Sets current target */ inline void setCurrentTarget(Node* target) { _currentTarget = target; }; @@ -76,7 +70,6 @@ protected: std::string _type; ///< Event type bool _isStopped; ///< whether the event has been stopped. Node* _currentTarget; ///< Current target - void* _userData; ///< User data friend class EventDispatcher; }; diff --git a/cocos2dx/event_dispatcher/CCEventDispatcher.cpp b/cocos2dx/event_dispatcher/CCEventDispatcher.cpp index 84b848ebe1..39504ce6fc 100644 --- a/cocos2dx/event_dispatcher/CCEventDispatcher.cpp +++ b/cocos2dx/event_dispatcher/CCEventDispatcher.cpp @@ -98,12 +98,12 @@ void EventDispatcher::addEventListenerWithItem(EventListenerItem* item) { std::vector* listenerList = nullptr; - auto iter = _listeners.find(item->listener->type); + auto iter = _listeners.find(item->listener->_type); if (iter == _listeners.end()) { listenerList = new std::vector(); listenerList->reserve(100); - _listeners.insert(std::make_pair(item->listener->type, listenerList)); + _listeners.insert(std::make_pair(item->listener->_type, listenerList)); } else { @@ -112,7 +112,7 @@ void EventDispatcher::addEventListenerWithItem(EventListenerItem* item) listenerList->insert(listenerList->begin(), item); - setDirtyForEventType(item->listener->type, true); + setDirtyForEventType(item->listener->_type, true); } else { @@ -196,7 +196,7 @@ void EventDispatcher::removeEventListener(EventListener* listener) iter = _listeners.erase(iter); CC_SAFE_DELETE(list); - _priorityDirtyFlagMap.erase(listener->type); + _priorityDirtyFlagMap.erase(listener->_type); } else { @@ -225,7 +225,7 @@ void EventDispatcher::setPriority(EventListener* listener, int fixedPriority) if (item->fixedPriority != fixedPriority) { item->fixedPriority = fixedPriority; - setDirtyForEventType(listener->type, true); + setDirtyForEventType(listener->_type, true); } return; } @@ -272,7 +272,7 @@ void EventDispatcher::dispatchEvent(Event* event, bool forceSortListeners) CCASSERT(item, "listener item is invalid."); event->setCurrentTarget(item->node); - item->listener->onEvent(event); + item->listener->_onEvent(event); if (event->isStopped()) break; @@ -515,12 +515,12 @@ void EventDispatcher::updateListenerItems() for (auto& item : _toAddedListeners) { - auto itr = _listeners.find(item->listener->type); + auto itr = _listeners.find(item->listener->_type); if (itr == _listeners.end()) { listenerList = new std::vector(); listenerList->reserve(100); - _listeners.insert(std::make_pair(item->listener->type, listenerList)); + _listeners.insert(std::make_pair(item->listener->_type, listenerList)); } else { @@ -529,7 +529,7 @@ void EventDispatcher::updateListenerItems() listenerList->push_back(item); - setDirtyForEventType(item->listener->type, true); + setDirtyForEventType(item->listener->_type, true); } _toAddedListeners.clear(); } diff --git a/cocos2dx/event_dispatcher/CCEventListener.cpp b/cocos2dx/event_dispatcher/CCEventListener.cpp index 15e54c462b..ce3c787883 100644 --- a/cocos2dx/event_dispatcher/CCEventListener.cpp +++ b/cocos2dx/event_dispatcher/CCEventListener.cpp @@ -27,20 +27,6 @@ NS_CC_BEGIN -EventListener* EventListener::create(const std::string& eventType, std::function callback) -{ - EventListener* ret = new EventListener(); - if (ret && ret->init(eventType, callback)) - { - ret->autorelease(); - } - else - { - CC_SAFE_DELETE(ret); - } - return ret; -} - EventListener::EventListener() {} @@ -49,10 +35,10 @@ EventListener::~EventListener() CCLOGINFO("In the destructor of EventListener. %p", this); } -bool EventListener::init(const std::string& t, std::functioncallback) +bool EventListener::init(const std::string& t, std::function callback) { - onEvent = callback; - type = t; + _onEvent = callback; + _type = t; _isRegistered = false; return true; @@ -60,21 +46,7 @@ bool EventListener::init(const std::string& t, std::functioncallba bool EventListener::checkAvaiable() { - return (onEvent != nullptr); -} - -EventListener* EventListener::clone() -{ - EventListener* ret = new EventListener(); - if (ret && ret->init(type, onEvent)) - { - ret->autorelease(); - } - else - { - CC_SAFE_DELETE(ret); - } - return ret; + return (_onEvent != nullptr); } NS_CC_END diff --git a/cocos2dx/event_dispatcher/CCEventListener.h b/cocos2dx/event_dispatcher/CCEventListener.h index 10e9210f4b..156d644f17 100644 --- a/cocos2dx/event_dispatcher/CCEventListener.h +++ b/cocos2dx/event_dispatcher/CCEventListener.h @@ -39,33 +39,10 @@ class Event; /** * The base class of event listener. * If you need custom listener which with different callback, you need to inherit this class. - * For instance, you could refer to AccelerationEventListener, KeyboardEventListener or TouchEventListener. - * Usage: - * auto dispatcher = EventDispatcher::getInstance(); - * Adds a listener: - * - * auto callback = [](Event* event){ do_some_thing(); }; - * auto listener = EventListener::create("your_event_type", callback); - * dispatcher->addEventListenerWithSceneGraphPriority(listener, one_node); - * - * Dispatchs a custom event: - * - * Event event("your_event_type"); - * dispatcher->dispatchEvent(&event); - * - * Removes a listener - * - * dispatcher->removeListener(listener); + * For instance, you could refer to AccelerationEventListener, KeyboardEventListener or TouchEventListener, CustomEventListener. */ class EventListener : public Object -{ -public: - /** Creates an event listener with type and callback. - * @param eventType The type of the event. - * @param callback The callback function when the specified event was emitted. - */ - static EventListener* create(const std::string& eventType, std::function callback); - +{ protected: /** Constructor */ EventListener(); @@ -77,13 +54,13 @@ public: virtual ~EventListener(); /** Checks whether the listener is available. */ - virtual bool checkAvaiable(); + virtual bool checkAvaiable() = 0; /** Clones the listener, its subclasses have to override this method. */ - virtual EventListener* clone(); + virtual EventListener* clone() = 0; protected: - std::function onEvent; /// Event callback function - std::string type; /// Event type + std::function _onEvent; /// Event callback function + std::string _type; /// Event type bool _isRegistered; /// Whether the listener has been added to dispatcher. friend class EventDispatcher; diff --git a/cocos2dx/event_dispatcher/CCKeyboardEventListener.h b/cocos2dx/event_dispatcher/CCKeyboardEventListener.h index 64467a1c31..18feb6a908 100644 --- a/cocos2dx/event_dispatcher/CCKeyboardEventListener.h +++ b/cocos2dx/event_dispatcher/CCKeyboardEventListener.h @@ -37,15 +37,16 @@ class KeyboardEventListener : public EventListener { public: static KeyboardEventListener* create(); + + /// Overrides virtual KeyboardEventListener* clone() override; + virtual bool checkAvaiable() override; std::function onKeyPressed; std::function onKeyReleased; private: KeyboardEventListener(); bool init(); - - virtual bool checkAvaiable() override; }; NS_CC_END diff --git a/cocos2dx/event_dispatcher/CCTouchEventListener.h b/cocos2dx/event_dispatcher/CCTouchEventListener.h index 2d16f9aa95..87bdded343 100644 --- a/cocos2dx/event_dispatcher/CCTouchEventListener.h +++ b/cocos2dx/event_dispatcher/CCTouchEventListener.h @@ -37,15 +37,17 @@ class TouchEventListener : public EventListener { public: static TouchEventListener* create(Touch::DispatchMode mode); + + /// Overrides virtual TouchEventListener* clone() override; + virtual bool checkAvaiable() override; + + virtual ~TouchEventListener(); private: TouchEventListener(); bool init(Touch::DispatchMode mode); - virtual ~TouchEventListener(); - virtual bool checkAvaiable() override; - public: std::function onTouchBegan; std::function onTouchMoved; diff --git a/cocos2dx/include/cocos2d.h b/cocos2dx/include/cocos2d.h index 2abb121ad7..713303d2c7 100644 --- a/cocos2dx/include/cocos2d.h +++ b/cocos2dx/include/cocos2d.h @@ -268,6 +268,8 @@ THE SOFTWARE. #include "event_dispatcher/CCKeyboardEvent.h" #include "event_dispatcher/CCAccelerationEvent.h" #include "event_dispatcher/CCAccelerationEventListener.h" +#include "event_dispatcher/CCCustomEvent.h" +#include "event_dispatcher/CCCustomEventListener.h" // root #include "CCCamera.h" diff --git a/cocos2dx/proj.emscripten/Makefile b/cocos2dx/proj.emscripten/Makefile index 4a6613cd44..2961cc0cd1 100644 --- a/cocos2dx/proj.emscripten/Makefile +++ b/cocos2dx/proj.emscripten/Makefile @@ -55,6 +55,8 @@ SOURCES = ../actions/CCAction.cpp \ ../event_dispatcher/CCTouch.cpp \ ../event_dispatcher/CCTouchEvent.cpp \ ../event_dispatcher/CCTouchEventListener.cpp \ +../event_dispatcher/CCCustomEvent.cpp \ +../event_dispatcher/CCCustomEventListener.cpp \ ../label_nodes/CCFont.cpp \ ../label_nodes/CCFontAtlas.cpp \ ../label_nodes/CCFontAtlasCache.cpp \ diff --git a/cocos2dx/proj.linux/Makefile b/cocos2dx/proj.linux/Makefile index c063e48a34..9da1bd8226 100644 --- a/cocos2dx/proj.linux/Makefile +++ b/cocos2dx/proj.linux/Makefile @@ -49,6 +49,8 @@ SOURCES = ../actions/CCAction.cpp \ ../event_dispatcher/CCTouch.cpp \ ../event_dispatcher/CCTouchEvent.cpp \ ../event_dispatcher/CCTouchEventListener.cpp \ +../event_dispatcher/CCCustomEvent.cpp \ +../event_dispatcher/CCCustomEventListener.cpp \ ../draw_nodes/CCDrawingPrimitives.cpp \ ../draw_nodes/CCDrawNode.cpp \ ../effects/CCGrabber.cpp \ diff --git a/cocos2dx/proj.nacl/Makefile b/cocos2dx/proj.nacl/Makefile index 1a04da1f1d..77fba1a66e 100644 --- a/cocos2dx/proj.nacl/Makefile +++ b/cocos2dx/proj.nacl/Makefile @@ -44,6 +44,8 @@ SOURCES = ../actions/CCAction.cpp \ ../event_dispatcher/CCTouch.cpp \ ../event_dispatcher/CCTouchEvent.cpp \ ../event_dispatcher/CCTouchEventListener.cpp \ +../event_dispatcher/CCCustomEvent.cpp \ +../event_dispatcher/CCCustomEventListener.cpp \ ../label_nodes/CCLabelAtlas.cpp \ ../label_nodes/CCLabelBMFont.cpp \ ../label_nodes/CCLabelTTF.cpp \ diff --git a/cocos2dx/proj.qt5/cocos2dx.pro b/cocos2dx/proj.qt5/cocos2dx.pro index 53dfdcfe8f..b849d745ba 100644 --- a/cocos2dx/proj.qt5/cocos2dx.pro +++ b/cocos2dx/proj.qt5/cocos2dx.pro @@ -50,6 +50,8 @@ SOURCES += ../actions/CCAction.cpp \ ../event_dispatcher/CCTouch.cpp \ ../event_dispatcher/CCTouchEvent.cpp \ ../event_dispatcher/CCTouchEventListener.cpp \ +../event_dispatcher/CCCustomEvent.cpp \ +../event_dispatcher/CCCustomEventListener.cpp \ ../label_nodes/CCLabelAtlas.cpp \ ../label_nodes/CCLabelBMFont.cpp \ ../label_nodes/CCLabelTTF.cpp \ diff --git a/extensions/Android.mk b/extensions/Android.mk index 2cc83d8669..cbd8d39ebd 100644 --- a/extensions/Android.mk +++ b/extensions/Android.mk @@ -31,6 +31,11 @@ CCBReader/CCParticleSystemQuadLoader.cpp \ CCBReader/CCScale9SpriteLoader.cpp \ CCBReader/CCScrollViewLoader.cpp \ CCBReader/CCSpriteLoader.cpp \ +CocoStudio/Action/CCActionFrame.cpp \ +CocoStudio/Action/CCActionFrameEasing.cpp \ +CocoStudio/Action/CCActionManagerEx.cpp \ +CocoStudio/Action/CCActionNode.cpp \ +CocoStudio/Action/CCActionObject.cpp \ CocoStudio/Armature/CCArmature.cpp \ CocoStudio/Armature/CCBone.cpp \ CocoStudio/Armature/animation/CCArmatureAnimation.cpp \ @@ -85,11 +90,6 @@ CocoStudio/Json/lib_json/json_value.cpp \ CocoStudio/Json/lib_json/json_writer.cpp \ CocoStudio/Reader/CCSGUIReader.cpp \ CocoStudio/Reader/CCSSceneReader.cpp \ -CocoStudio/Action/CCActionFrame.cpp \ -CocoStudio/Action/CCActionFrameEasing.cpp \ -CocoStudio/Action/CCActionManagerEx.cpp \ -CocoStudio/Action/CCActionNode.cpp \ -CocoStudio/Action/CCActionObject.cpp \ GUI/CCControlExtension/CCControl.cpp \ GUI/CCControlExtension/CCControlButton.cpp \ GUI/CCControlExtension/CCControlColourPicker.cpp \ diff --git a/samples/Cpp/TestCpp/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp b/samples/Cpp/TestCpp/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp index 8b22f3d6f5..5097429e3a 100644 --- a/samples/Cpp/TestCpp/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp +++ b/samples/Cpp/TestCpp/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp @@ -398,7 +398,7 @@ void CustomEventTest::onEnter() statusLabel->setPosition(origin + Point(size.width/2, size.height-90)); addChild(statusLabel); - _listener = EventListener::create("game_custom_event", [=](Event* event){ + _listener = CustomEventListener::create("game_custom_event", [=](CustomEvent* event){ std::string str("Custom event received, "); char* buf = static_cast(event->getUserData()); str += buf; @@ -414,7 +414,7 @@ void CustomEventTest::onEnter() ++count; char* buf = new char[10]; sprintf(buf, "%d", count); - Event event("game_custom_event"); + CustomEvent event("game_custom_event"); event.setUserData(buf); dispatcher->dispatchEvent(&event); }); diff --git a/samples/Cpp/TestCpp/Classes/NewEventDispatcherTest/NewEventDispatcherTest.h b/samples/Cpp/TestCpp/Classes/NewEventDispatcherTest/NewEventDispatcherTest.h index ff23ac330b..3677fdff96 100644 --- a/samples/Cpp/TestCpp/Classes/NewEventDispatcherTest/NewEventDispatcherTest.h +++ b/samples/Cpp/TestCpp/Classes/NewEventDispatcherTest/NewEventDispatcherTest.h @@ -63,7 +63,7 @@ public: virtual std::string title() override; virtual std::string subtitle() override; private: - EventListener* _listener; + CustomEventListener* _listener; }; class LabelKeyboardEventTest : public EventDispatcherTestDemo