issue #2087: [dispatcher] Changes event priority. The lower value is, the higher priority will be gotten.

This commit is contained in:
James Chen 2013-09-16 15:45:56 +08:00
parent 7921b45090
commit 60645a6702
1 changed files with 15 additions and 3 deletions

View File

@ -30,6 +30,9 @@
#include <algorithm>
#define DUMP_LISTENER_ITEM_PRIORITY_INFO 0
namespace
{
@ -55,7 +58,6 @@ private:
NS_CC_BEGIN
EventDispatcher::EventDispatcher()
: _inDispatch(0)
, _listeners(nullptr)
@ -497,10 +499,11 @@ void EventDispatcher::sortAllEventListenerItemsForType(const std::string &eventT
// After sort: priority < 0, = 0, scene graph, > 0
std::sort(listenerList->begin(), listenerList->end(), [](const EventListenerItem* item1, const EventListenerItem* item2) {
// item1 and item2 are both using fixed priority.
if (nullptr == item1->node && nullptr == item2->node)
{
return item1->fixedPriority > item2->fixedPriority;
return item1->fixedPriority < item2->fixedPriority;
}
// item1 and item2 are both using scene graph based priority.
else if (nullptr != item1->node && nullptr != item2->node)
@ -513,7 +516,7 @@ void EventDispatcher::sortAllEventListenerItemsForType(const std::string &eventT
}
else if (nullptr == item1->node && nullptr != item2->node)
{
return item1->fixedPriority < 0;
return item1->fixedPriority <= 0;
}
else
{
@ -521,6 +524,15 @@ void EventDispatcher::sortAllEventListenerItemsForType(const std::string &eventT
return false;
}
});
#if DUMP_LISTENER_ITEM_PRIORITY_INFO
log("-----------------------------------");
for (auto& item : *listenerList)
{
log("listener item priority: node (%p), fixed (%d)", item->node, item->fixedPriority);
}
#endif
}
std::vector<EventDispatcher::EventListenerItem*>* EventDispatcher::getListenerItemsForType(const std::string &eventType)