From c9991aea81e081c5d021ee5ba83486177ef0b8fb Mon Sep 17 00:00:00 2001 From: geron-cn Date: Tue, 28 Jul 2015 16:31:06 +0800 Subject: [PATCH 1/6] fix bug: BoneNode 's debugdraw can not be controlled by ancestor's visible --- .../cocostudio/ActionTimeline/CCBoneNode.cpp | 7 ++---- .../ActionTimeline/CCSkeletonNode.cpp | 23 +++++++++++++++---- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCBoneNode.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCBoneNode.cpp index 122ff8a37b..f246f5bd35 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCBoneNode.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCBoneNode.cpp @@ -398,12 +398,9 @@ cocos2d::Vector BoneNode::getAllSubBones() const allBones.pushBack(top); boneStack.pop(); auto topchildren = top->getChildBones(); - if (topchildren.size() > 0) + for (const auto& childbone : topchildren) { - for (const auto& childbone : topchildren) - { - boneStack.push(childbone); - } + boneStack.push(childbone); } } return allBones; diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCSkeletonNode.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCSkeletonNode.cpp index a3881ffc82..a95256207c 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCSkeletonNode.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCSkeletonNode.cpp @@ -335,11 +335,26 @@ void SkeletonNode::addSkinGroup(std::string groupName, std::map boneStack; + for (const auto& bone : _childBones) { - auto bone = bonepair.second; - if (bone->isVisible() && bone->isDebugDrawEnabled()) - _subDrawBones.pushBack(bone); + if (bone->isVisible()) + boneStack.push(bone); + } + + while (boneStack.size() > 0) + { + auto top = boneStack.top(); + _subDrawBones.pushBack(top); + boneStack.pop(); + auto topChildren = top->getChildBones(); + for (const auto& childbone : topChildren) + { + if (childbone->isVisible()) + boneStack.push(childbone); + } } _subDrawBonesDirty = false; } From 0275e3b773503cc871bc3c2c513100910a8e7650 Mon Sep 17 00:00:00 2001 From: geron-cn Date: Tue, 28 Jul 2015 17:25:40 +0800 Subject: [PATCH 2/6] fix set visible --- cocos/editor-support/cocostudio/ActionTimeline/CCBoneNode.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCBoneNode.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCBoneNode.cpp index f246f5bd35..153a3092d6 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCBoneNode.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCBoneNode.cpp @@ -563,7 +563,7 @@ void BoneNode::setVisible(bool visible) return; Node::setVisible(visible); - if (_isRackShow) + if (_isRackShow && _rootSkeleton != nullptr) { _rootSkeleton->_subDrawBonesDirty = true; _rootSkeleton->_subDrawBonesOrderDirty = true; From d2de5b1c852229e226c9d50c3f693e880f8e9b56 Mon Sep 17 00:00:00 2001 From: geron-cn Date: Tue, 28 Jul 2015 19:18:58 +0800 Subject: [PATCH 3/6] add test case for bug: #13060 and #13005 --- .../cocostudio/ActionTimeline/CCBoneNode.cpp | 3 +- .../ActionTimelineTestScene.cpp | 56 +++++++++++++++++-- .../ActionTimelineTestScene.h | 4 ++ 3 files changed, 57 insertions(+), 6 deletions(-) diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCBoneNode.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCBoneNode.cpp index 153a3092d6..731f1e312d 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCBoneNode.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCBoneNode.cpp @@ -34,7 +34,7 @@ THE SOFTWARE. NS_TIMELINE_BEGIN BoneNode::BoneNode() -: _isRackShow(true) +: _isRackShow(false) , _rackColor(cocos2d::Color4F::WHITE) , _rackLength(50) , _rackWidth(20) @@ -323,6 +323,7 @@ bool BoneNode::init() _rackLength = 50; _rackWidth = 20; updateVertices(); + updateColor(); setGLProgramState(cocos2d::GLProgramState::getOrCreateWithGLProgramName(cocos2d::GLProgram::SHADER_NAME_POSITION_COLOR_NO_MVP)); return true; } diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioActionTimelineTest/ActionTimelineTestScene.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioActionTimelineTest/ActionTimelineTestScene.cpp index 498613574e..1f0e6405f2 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioActionTimelineTest/ActionTimelineTestScene.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioActionTimelineTest/ActionTimelineTestScene.cpp @@ -343,9 +343,14 @@ void TestActionTimelineSkeleton::onEnter() boneDrawsBtn->setPosition(Vec2(VisibleRect::right().x - 30, VisibleRect::top().y - 30)); boneDrawsBtn->setTitleText("Draw bone"); - boneDrawsBtn->addClickEventListener([skeletonNode](Ref* sender) + _isAllBonesDraw = true; + skeletonNode->setDebugDrawEnabled(_isAllBonesDraw); + setAllSubBonesDebugDraw(skeletonNode, _isAllBonesDraw); + boneDrawsBtn->addClickEventListener([skeletonNode, this](Ref* sender) { - skeletonNode->setDebugDrawEnabled(!skeletonNode->isDebugDrawEnabled()); + _isAllBonesDraw = !_isAllBonesDraw; + skeletonNode->setDebugDrawEnabled(_isAllBonesDraw); + setAllSubBonesDebugDraw(skeletonNode, _isAllBonesDraw); }); @@ -402,9 +407,6 @@ void TestActionTimelineSkeleton::onEnter() debugDrawNode->drawRect(leftbottom, righttop, cocos2d::Color4F::YELLOW); // bone boundingbox - /* // debug draw contentsize - rect = cocos2d::Rect(Vec2(.0f, .0f), weaponHandeBone->getContentSize()); - rect = RectApplyAffineTransform(rect, weaponHandeBone->getNodeToParentAffineTransform());*/ rect = weaponHandeBone->getBoundingBox(); leftbottom.x = rect.getMinX(); leftbottom.y = rect.getMinY(); righttop.x = rect.getMaxX(); righttop.y = rect.getMaxY(); @@ -477,6 +479,41 @@ void TestActionTimelineSkeleton::onEnter() _changedDisplays = false; } }); + + + /*********** test cases for bugs **********/ + // bug: #13060 https://github.com/cocos2d/cocos2d-x/issues/13060 + // bug: bone draw at the other edge when move to outside right edge. + BoneNode* bugtestBoneNode = BoneNode::create(500); + bugtestBoneNode->setRotation(-10); + bugtestBoneNode->retain(); + bugtestBoneNode->setDebugDrawEnabled(true); + bugtestBoneNode->setPosition(Vec2(1500, VisibleRect::top().y - 90)); + auto bug13060Btn = cocos2d::ui::Button::create(); + bug13060Btn->setPosition(Vec2(VisibleRect::right().x - 30, VisibleRect::top().y - 90)); + bug13060Btn->setTitleText("bug #13060"); + addChild(bug13060Btn); + bug13060Btn->addClickEventListener([bugtestBoneNode, skeletonNode](Ref* sender) + { + if (bugtestBoneNode->getParent() == nullptr) + skeletonNode->addChild(bugtestBoneNode); + else + bugtestBoneNode->removeFromParent(); + // bug fixed while bugtestBoneNode not be drawn at the bottom edge + }); + + // bug: #13005 https://github.com/cocos2d/cocos2d-x/issues/#13005 + // bug: BoneNode 's debugdraw can not be controlled by ancestor's visible + auto leftleg = skeletonNode->getBoneNode("Layer26"); + auto bug13005Btn = cocos2d::ui::Button::create(); + addChild(bug13005Btn); + bug13005Btn->setPosition(Vec2(VisibleRect::right().x - 30, VisibleRect::top().y - 105)); + bug13005Btn->setTitleText("bug #13005"); + bug13005Btn->addClickEventListener([leftleg](Ref* sender) + { + leftleg->setVisible(!leftleg->isVisible()); + // bug fixed while leftleg's child hide with leftleg's visible + }); } std::string TestActionTimelineSkeleton::title() const @@ -484,6 +521,15 @@ std::string TestActionTimelineSkeleton::title() const return "Test ActionTimeline Skeleton"; } +void TestActionTimelineSkeleton::setAllSubBonesDebugDraw(SkeletonNode* rootSkeleton, bool isShow) +{ + auto boneMap = rootSkeleton->getAllSubBonesMap(); + for (auto& bonePair : boneMap) + { + bonePair.second->setDebugDrawEnabled(isShow); + } +} + // TestTimelineExtensionData void TestTimelineExtensionData::onEnter() diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioActionTimelineTest/ActionTimelineTestScene.h b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioActionTimelineTest/ActionTimelineTestScene.h index 86cd284047..a64e08000a 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioActionTimelineTest/ActionTimelineTestScene.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioActionTimelineTest/ActionTimelineTestScene.h @@ -125,9 +125,13 @@ public: virtual void onEnter() override; virtual std::string title() const override; + private: + void setAllSubBonesDebugDraw(cocostudio::timeline::SkeletonNode* rootSkeleton, bool isShow); + bool _changedDisplay; bool _changedDisplays; + bool _isAllBonesDraw; }; class TestTimelineExtensionData : public ActionTimelineBaseTest From fa5d70fc0418fa9161b15a5e56dcf0f607229d06 Mon Sep 17 00:00:00 2001 From: geron-cn Date: Tue, 28 Jul 2015 23:49:25 +0800 Subject: [PATCH 4/6] add SkeletonNode Nest test case --- .../cocostudio/ActionTimeline/CCBoneNode.cpp | 13 ++++++++++--- .../cocostudio/ActionTimeline/CCSkeletonNode.cpp | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCBoneNode.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCBoneNode.cpp index 731f1e312d..79f36d0543 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCBoneNode.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCBoneNode.cpp @@ -112,6 +112,10 @@ void BoneNode::removeChild(Node* child, bool cleanup /* = true */) void BoneNode::removeFromBoneList(BoneNode* bone) { _childBones.eraseObject(bone); + auto skeletonNode = dynamic_cast(bone); + if (bone != nullptr) // nested skeleton + return; + bone->_rootSkeleton = nullptr; auto subBones = bone->getAllSubBones(); subBones.pushBack(bone); @@ -424,9 +428,12 @@ cocos2d::Vector BoneNode::getAllSubSkins() const void BoneNode::sortAllChildren() { - Node::sortAllChildren(); - std::sort(_childBones.begin(), _childBones.end(), cocos2d::nodeComparisonLess); - std::sort(_boneSkins.begin(), _boneSkins.end(), cocos2d::nodeComparisonLess); + if (_reorderChildDirty) + { + std::sort(_childBones.begin(), _childBones.end(), cocos2d::nodeComparisonLess); + std::sort(_boneSkins.begin(), _boneSkins.end(), cocos2d::nodeComparisonLess); + Node::sortAllChildren(); + } } SkeletonNode* BoneNode::getRootSkeletonNode() const diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCSkeletonNode.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCSkeletonNode.cpp index a95256207c..f5f78c93ea 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCSkeletonNode.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCSkeletonNode.cpp @@ -340,7 +340,7 @@ void SkeletonNode::updateAllDrawBones() std::stack boneStack; for (const auto& bone : _childBones) { - if (bone->isVisible()) + if (bone->isVisible() && bone->isDebugDrawEnabled()) boneStack.push(bone); } @@ -352,7 +352,7 @@ void SkeletonNode::updateAllDrawBones() auto topChildren = top->getChildBones(); for (const auto& childbone : topChildren) { - if (childbone->isVisible()) + if (childbone->isVisible() && childbone->isDebugDrawEnabled()) boneStack.push(childbone); } } From 7e05538521636edb022914a4f3e2cf6363418e4c Mon Sep 17 00:00:00 2001 From: geron-cn Date: Wed, 29 Jul 2015 10:23:03 +0800 Subject: [PATCH 5/6] ADD SKELETON NEST TEST CASE --- .../ActionTimelineTestScene.cpp | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioActionTimelineTest/ActionTimelineTestScene.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioActionTimelineTest/ActionTimelineTestScene.cpp index 1f0e6405f2..7489509851 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioActionTimelineTest/ActionTimelineTestScene.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioActionTimelineTest/ActionTimelineTestScene.cpp @@ -514,6 +514,39 @@ void TestActionTimelineSkeleton::onEnter() leftleg->setVisible(!leftleg->isVisible()); // bug fixed while leftleg's child hide with leftleg's visible }); + + + /************* Skeleton nest Skeleton test *************/ + auto nestSkeletonBtn = cocos2d::ui::Button::create(); + nestSkeletonBtn->setTitleText("Skeleton Nest"); + nestSkeletonBtn->setPosition(Vec2(VisibleRect::right().x - 40, VisibleRect::top().y - 120)); + addChild(nestSkeletonBtn); + auto nestSkeleton = static_cast(CSLoader::createNode("ActionTimeline/DemoPlayer_skeleton.csb")); + nestSkeleton->retain(); + ActionTimeline* nestSkeletonAction = action->clone(); + nestSkeletonAction->retain(); + nestSkeleton->runAction(nestSkeletonAction); + nestSkeleton->setScale(0.2f); + nestSkeleton->setPosition(150, 300); + nestSkeletonAction->gotoFrameAndPlay(0); + // show debug draws, or comment this for hide bones draws + for (auto& nestbonechild : nestSkeleton->getAllSubBonesMap()) + { + nestbonechild.second->setDebugDrawEnabled(true); + } + + nestSkeletonBtn->addClickEventListener([leftleg, nestSkeleton, nestSkeletonAction](Ref* sender) + { + if (nestSkeleton->getParent() == nullptr) + { + leftleg->addChild(nestSkeleton); + } + else + { + nestSkeleton->removeFromParentAndCleanup(false); + } + // bug fixed while leftleg's child hide with leftleg's visible + }); } std::string TestActionTimelineSkeleton::title() const From 0955b0f9de71ed3a23a390f9c5693098b7006db7 Mon Sep 17 00:00:00 2001 From: geron-cn Date: Thu, 30 Jul 2015 19:28:00 +0800 Subject: [PATCH 6/6] fix comment by pandamicro --- cocos/editor-support/cocostudio/ActionTimeline/CCBoneNode.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCBoneNode.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCBoneNode.cpp index 79f36d0543..fda656e820 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCBoneNode.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCBoneNode.cpp @@ -113,7 +113,7 @@ void BoneNode::removeFromBoneList(BoneNode* bone) { _childBones.eraseObject(bone); auto skeletonNode = dynamic_cast(bone); - if (bone != nullptr) // nested skeleton + if (skeletonNode != nullptr) // nested skeleton return; bone->_rootSkeleton = nullptr;