mirror of https://github.com/axmolengine/axmol.git
issue #2087: [dispatcher] Changes event priority. The lower value is, the higher priority will be gotten.
This commit is contained in:
parent
7921b45090
commit
60645a6702
|
@ -30,6 +30,9 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
|
||||||
|
#define DUMP_LISTENER_ITEM_PRIORITY_INFO 0
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -55,7 +58,6 @@ private:
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
|
||||||
EventDispatcher::EventDispatcher()
|
EventDispatcher::EventDispatcher()
|
||||||
: _inDispatch(0)
|
: _inDispatch(0)
|
||||||
, _listeners(nullptr)
|
, _listeners(nullptr)
|
||||||
|
@ -497,10 +499,11 @@ void EventDispatcher::sortAllEventListenerItemsForType(const std::string &eventT
|
||||||
|
|
||||||
// After sort: priority < 0, = 0, scene graph, > 0
|
// After sort: priority < 0, = 0, scene graph, > 0
|
||||||
std::sort(listenerList->begin(), listenerList->end(), [](const EventListenerItem* item1, const EventListenerItem* item2) {
|
std::sort(listenerList->begin(), listenerList->end(), [](const EventListenerItem* item1, const EventListenerItem* item2) {
|
||||||
|
|
||||||
// item1 and item2 are both using fixed priority.
|
// item1 and item2 are both using fixed priority.
|
||||||
if (nullptr == item1->node && nullptr == item2->node)
|
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.
|
// item1 and item2 are both using scene graph based priority.
|
||||||
else if (nullptr != item1->node && nullptr != item2->node)
|
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)
|
else if (nullptr == item1->node && nullptr != item2->node)
|
||||||
{
|
{
|
||||||
return item1->fixedPriority < 0;
|
return item1->fixedPriority <= 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -521,6 +524,15 @@ void EventDispatcher::sortAllEventListenerItemsForType(const std::string &eventT
|
||||||
return false;
|
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)
|
std::vector<EventDispatcher::EventListenerItem*>* EventDispatcher::getListenerItemsForType(const std::string &eventType)
|
||||||
|
|
Loading…
Reference in New Issue