diff --git a/cocos/2d/CCProtectedNode.cpp b/cocos/2d/CCProtectedNode.cpp index 1af4d714be..6896abcd2a 100644 --- a/cocos/2d/CCProtectedNode.cpp +++ b/cocos/2d/CCProtectedNode.cpp @@ -100,9 +100,8 @@ void ProtectedNode::addProtectedChild(Node *child, int zOrder, int tag) this->insertProtectedChild(child, zOrder); child->setTag(tag); - + child->setGlobalZOrder(_globalZOrder); child->setParent(this); - child->updateOrderOfArrival(); if( _running ) @@ -467,4 +466,11 @@ void ProtectedNode::setCameraMask(unsigned short mask, bool applyChildren) } +void ProtectedNode::setGlobalZOrder(float globalZOrder) +{ + Node::setGlobalZOrder(globalZOrder); + for (auto &child : _protectedChildren) + child->setGlobalZOrder(globalZOrder); +} + NS_CC_END diff --git a/cocos/2d/CCProtectedNode.h b/cocos/2d/CCProtectedNode.h index 466738242a..9a055fef3a 100644 --- a/cocos/2d/CCProtectedNode.h +++ b/cocos/2d/CCProtectedNode.h @@ -181,6 +181,7 @@ public: virtual void disableCascadeColor() override; virtual void disableCascadeOpacity()override; virtual void setCameraMask(unsigned short mask, bool applyChildren = true) override; + virtual void setGlobalZOrder(float globalZOrder) override; CC_CONSTRUCTOR_ACCESS: ProtectedNode(); virtual ~ProtectedNode(); diff --git a/cocos/ui/UILayout.cpp b/cocos/ui/UILayout.cpp index 8cc70c586c..143daf66bc 100644 --- a/cocos/ui/UILayout.cpp +++ b/cocos/ui/UILayout.cpp @@ -125,6 +125,18 @@ void Layout::onExit() _clippingStencil->onExit(); } } + +void Layout::setGlobalZOrder(float globalZOrder) +{ + // _protectedChildren's global z order is set in ProtectedNode::setGlobalZOrder() + + Widget::setGlobalZOrder(globalZOrder); + if (_clippingStencil) + _clippingStencil->setGlobalZOrder(globalZOrder); + + for (auto &child : _children) + child->setGlobalZOrder(globalZOrder); +} Layout* Layout::create() { @@ -166,6 +178,7 @@ void Layout::addChild(Node *child, int zOrder, int tag) if (dynamic_cast(child)) { supplyTheLayoutParameterLackToChild(static_cast(child)); } + child->setGlobalZOrder(_globalZOrder); Widget::addChild(child, zOrder, tag); _doLayoutDirty = true; } @@ -175,6 +188,7 @@ void Layout::addChild(Node* child, int zOrder, const std::string &name) if (dynamic_cast(child)) { supplyTheLayoutParameterLackToChild(static_cast(child)); } + child->setGlobalZOrder(_globalZOrder); Widget::addChild(child, zOrder, name); _doLayoutDirty = true; } @@ -389,6 +403,7 @@ void Layout::setClippingEnabled(bool able) if (able) { _clippingStencil = DrawNode::create(); + _clippingStencil->setGlobalZOrder(_globalZOrder); if (_running) { _clippingStencil->onEnter(); diff --git a/cocos/ui/UILayout.h b/cocos/ui/UILayout.h index 5b4d9aa2c8..e455f8236e 100644 --- a/cocos/ui/UILayout.h +++ b/cocos/ui/UILayout.h @@ -414,6 +414,8 @@ public: */ virtual void onExit() override; + virtual void setGlobalZOrder(float globalZOrder) override; + /** * If a layout is loop focused which means that the focus movement will be inside the layout *@param loop pass true to let the focus movement loop inside the layout diff --git a/cocos/ui/UIScrollView.cpp b/cocos/ui/UIScrollView.cpp index 15fa1d3127..92c7fbbc4e 100644 --- a/cocos/ui/UIScrollView.cpp +++ b/cocos/ui/UIScrollView.cpp @@ -257,11 +257,13 @@ void ScrollView::addChild(Node * child, int localZOrder) void ScrollView::addChild(Node *child, int zOrder, int tag) { + child->setGlobalZOrder(_globalZOrder); _innerContainer->addChild(child, zOrder, tag); } void ScrollView::addChild(Node* child, int zOrder, const std::string &name) { + child->setGlobalZOrder(_globalZOrder); _innerContainer->addChild(child, zOrder, name); } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp index bd76022e95..c9a0203d90 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp @@ -76,6 +76,7 @@ bool UIListViewTest_Vertical::init() _listView->setDirection(ui::ScrollView::Direction::VERTICAL); _listView->setBounceEnabled(true); _listView->setBackGroundImage("cocosui/green_edit.png"); + _listView->setGlobalZOrder(200); _listView->setBackGroundImageScale9Enabled(true); _listView->setContentSize(Size(240, 130)); _listView->setPosition(Vec2((widgetSize - _listView->getContentSize()) / 2.0f)); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp index 0165538d92..51e755f11b 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp @@ -61,6 +61,7 @@ bool UIPageViewTest::init() pageView->setPosition((widgetSize - pageView->getContentSize()) / 2.0f); pageView->removeAllItems(); pageView->setIndicatorEnabled(true); + pageView->setGlobalZOrder(200); int pageCount = 4; for (int i = 0; i < pageCount; ++i) diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp index 0a8b837bc9..11239c9cc0 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp @@ -60,6 +60,7 @@ bool UIScrollViewTest_Vertical::init() scrollView->setScrollBarWidth(4); scrollView->setScrollBarPositionFromCorner(Vec2(2, 2)); scrollView->setScrollBarColor(Color3B::WHITE); + scrollView->setGlobalZOrder(200); _uiLayer->addChild(scrollView); ImageView* imageView = ImageView::create("cocosui/ccicon.png");