add CCNode::insertBefore and CCNode::insertAfter

This commit is contained in:
HJfod 2023-02-11 21:13:22 +02:00
parent 3f64b98cf1
commit eb10eca6e5
2 changed files with 38 additions and 4 deletions

View file

@ -761,7 +761,7 @@ public:
* Returns a tag that is used to identify the node easily.
*
* You can set tags to node then identify them easily.
* @code
* @example
* #define TAG_PLAYER 1
* #define TAG_MONSTER 2
* #define TAG_BOSS 3
@ -786,9 +786,7 @@ public:
* break;
* }
* }
* @endcode
*
* @return A interger that identifies the node.
* @returns A interger that identifies the node.
*/
RT_REMOVE( virtual int getTag() const; )
/**
@ -883,6 +881,26 @@ public:
*/
GEODE_DLL CCNode* getChildByIDRecursive(std::string const& id);
/**
* Add a child before a specified existing child
* @param child The node to add. The node may not be a child of another
* node already
* @param before The child the node is added before of. If this is null or
* not a child of this node, the new child will be placed at the end of the
* child list
*/
GEODE_DLL void insertBefore(CCNode* child, CCNode* before);
/**
* Add a child after an specified existing child
* @param child The node to add. The node may not be a child of another
* node already
* @param after The child the node is added after of. If this is null or
* not a child of this node, the new child will be placed at the end of the
* child list
*/
GEODE_DLL void insertAfter(CCNode* child, CCNode* after);
/**
* Set an attribute on a node. Attributes are a system added by Geode,
* where a node may have any sort of extra data associated with it. Used

View file

@ -14,6 +14,22 @@ void CCNode::swapChildIndices(CCNode* first, CCNode* second) {
std::swap(first->m_uOrderOfArrival, second->m_uOrderOfArrival);
}
void CCNode::insertBefore(CCNode* child, CCNode* before) {
this->addChild(child);
if (m_pChildren->containsObject(before)) {
child->setZOrder(before->getZOrder());
child->setOrderOfArrival(before->getOrderOfArrival() - 1);
}
}
void CCNode::insertAfter(CCNode* child, CCNode* after) {
this->addChild(child);
if (m_pChildren->containsObject(after)) {
child->setZOrder(after->getZOrder());
child->setOrderOfArrival(after->getOrderOfArrival() + 1);
}
}
CCArray* Layout::getNodesToPosition(CCNode* on) {
auto filtered = CCArray::create();
for (auto& child : CCArrayExt<CCNode>(on->getChildren())) {