mirror of https://github.com/axmolengine/axmol.git
Factor in protected nodes when creating global Z node priority map for event dispatcher (#1224)
This commit is contained in:
parent
53a5057867
commit
978648e5a9
|
@ -144,6 +144,8 @@ public:
|
|||
*/
|
||||
virtual void sortAllProtectedChildren();
|
||||
|
||||
const Vector<Node*>& getProtectedChildren() const { return _protectedChildren; }
|
||||
|
||||
/// @} end of Children and Parent
|
||||
|
||||
/**
|
||||
|
|
|
@ -213,45 +213,113 @@ EventDispatcher::~EventDispatcher()
|
|||
|
||||
void EventDispatcher::visitTarget(Node* node, bool isRootNode)
|
||||
{
|
||||
node->sortAllChildren();
|
||||
|
||||
int i = 0;
|
||||
auto& children = node->getChildren();
|
||||
|
||||
auto childrenCount = children.size();
|
||||
|
||||
if (childrenCount > 0)
|
||||
auto* protectedNode = dynamic_cast<ProtectedNode*>(node);
|
||||
if (protectedNode)
|
||||
{
|
||||
Node* child = nullptr;
|
||||
// visit children zOrder < 0
|
||||
for (; i < childrenCount; i++)
|
||||
{
|
||||
child = children.at(i);
|
||||
protectedNode->sortAllProtectedChildren();
|
||||
protectedNode->sortAllChildren();
|
||||
|
||||
if (child && child->getLocalZOrder() < 0)
|
||||
visitTarget(child, false);
|
||||
else
|
||||
break;
|
||||
}
|
||||
const auto& children = protectedNode->getChildren();
|
||||
const auto& protectedChildren = protectedNode->getProtectedChildren();
|
||||
|
||||
if (_nodeListenersMap.find(node) != _nodeListenersMap.end())
|
||||
{
|
||||
_globalZOrderNodeMap[node->getGlobalZOrder()].emplace_back(node);
|
||||
}
|
||||
const auto childrenCount = children.size();
|
||||
const auto protectedChildrenCount = protectedChildren.size();
|
||||
|
||||
for (; i < childrenCount; i++)
|
||||
if (childrenCount > 0 || protectedChildrenCount > 0)
|
||||
{
|
||||
child = children.at(i);
|
||||
if (child)
|
||||
visitTarget(child, false);
|
||||
int childIndex = 0;
|
||||
int protectedChildIndex = 0;
|
||||
Node* child = nullptr;
|
||||
// visit children zOrder < 0
|
||||
for (; childIndex < childrenCount; childIndex++)
|
||||
{
|
||||
child = children.at(childIndex);
|
||||
|
||||
if (child && child->getLocalZOrder() < 0)
|
||||
visitTarget(child, false);
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
for (; protectedChildIndex < protectedChildrenCount; protectedChildIndex++)
|
||||
{
|
||||
child = protectedChildren.at(protectedChildIndex);
|
||||
|
||||
if (child && child->getLocalZOrder() < 0)
|
||||
visitTarget(child, false);
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (_nodeListenersMap.find(node) != _nodeListenersMap.end())
|
||||
{
|
||||
_globalZOrderNodeMap[node->getGlobalZOrder()].emplace_back(node);
|
||||
}
|
||||
|
||||
for (; childIndex < childrenCount; childIndex++)
|
||||
{
|
||||
child = children.at(childIndex);
|
||||
if (child)
|
||||
visitTarget(child, false);
|
||||
}
|
||||
|
||||
for (; protectedChildIndex < protectedChildrenCount; protectedChildIndex++)
|
||||
{
|
||||
child = protectedChildren.at(protectedChildIndex);
|
||||
if (child)
|
||||
visitTarget(child, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_nodeListenersMap.find(node) != _nodeListenersMap.end())
|
||||
{
|
||||
_globalZOrderNodeMap[node->getGlobalZOrder()].emplace_back(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_nodeListenersMap.find(node) != _nodeListenersMap.end())
|
||||
node->sortAllChildren();
|
||||
|
||||
const auto& children = node->getChildren();
|
||||
|
||||
const auto childrenCount = children.size();
|
||||
|
||||
if (childrenCount > 0)
|
||||
{
|
||||
_globalZOrderNodeMap[node->getGlobalZOrder()].emplace_back(node);
|
||||
int i = 0;
|
||||
Node* child = nullptr;
|
||||
// visit children zOrder < 0
|
||||
for (; i < childrenCount; i++)
|
||||
{
|
||||
child = children.at(i);
|
||||
|
||||
if (child && child->getLocalZOrder() < 0)
|
||||
visitTarget(child, false);
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (_nodeListenersMap.find(node) != _nodeListenersMap.end())
|
||||
{
|
||||
_globalZOrderNodeMap[node->getGlobalZOrder()].emplace_back(node);
|
||||
}
|
||||
|
||||
for (; i < childrenCount; i++)
|
||||
{
|
||||
child = children.at(i);
|
||||
if (child)
|
||||
visitTarget(child, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_nodeListenersMap.find(node) != _nodeListenersMap.end())
|
||||
{
|
||||
_globalZOrderNodeMap[node->getGlobalZOrder()].emplace_back(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isRootNode)
|
||||
|
|
|
@ -49,6 +49,15 @@ bool UITabControlTest::init()
|
|||
displayText->setPosition(VisibleRect::bottom() + Vec2(0, 50));
|
||||
_uiLayer->addChild(displayText);
|
||||
|
||||
auto* touchSinkLayer = Layer::create();
|
||||
touchSinkLayer->setContentSize(_uiLayer->getContentSize());
|
||||
_uiLayer->addChild(touchSinkLayer);
|
||||
|
||||
auto listener = EventListenerTouchOneByOne::create();
|
||||
listener->setSwallowTouches(true);
|
||||
listener->onTouchBegan = [](Touch* t, Event* e) { return true; };
|
||||
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, touchSinkLayer);
|
||||
|
||||
auto tab = TabControl::create();
|
||||
tab->setContentSize(Size(200.f, 200.f));
|
||||
tab->setHeaderHeight(20.f);
|
||||
|
@ -88,7 +97,7 @@ bool UITabControlTest::init()
|
|||
|
||||
tab->setSelectTab(2);
|
||||
|
||||
_uiLayer->addChild(tab);
|
||||
touchSinkLayer->addChild(tab);
|
||||
tab->setPosition(Vec2(widgetSize.width * .5f, widgetSize.height * .5f));
|
||||
|
||||
tab->setTabChangedEventListener([displayText](int index, TabControl::EventType evtType) {
|
||||
|
|
Loading…
Reference in New Issue