diff --git a/loader/include/Geode/ui/Button.hpp b/loader/include/Geode/ui/Button.hpp index e778ed9ce..b2eebcfa7 100644 --- a/loader/include/Geode/ui/Button.hpp +++ b/loader/include/Geode/ui/Button.hpp @@ -62,6 +62,11 @@ namespace geode { */ cocos2d::CCNode* getDisplayNode(); + /** + * Set the Display Node, will change the current one to this + */ + void setDisplayNode(CCNode* node); + /** * Set an animation type, which dictates how the button moves or scales * or if it even has an animation at all diff --git a/loader/src/ui/nodes/Button.cpp b/loader/src/ui/nodes/Button.cpp index 29918bd45..eedc6ba9e 100644 --- a/loader/src/ui/nodes/Button.cpp +++ b/loader/src/ui/nodes/Button.cpp @@ -157,6 +157,17 @@ CCNode* Button::getDisplayNode() { return m_impl->m_displayNode; } +void Button::setDisplayNode(CCNode* node) { + m_impl->m_displayNode->removeFromParent(); + + m_impl->m_displayNode = node; + + setContentSize(m_impl->m_displayNode->getScaledContentSize()); + m_impl->m_displayNode->setPosition(getContentSize() * m_impl->m_displayNode->getAnchorPoint()); + + addChild(m_impl->m_displayNode); +} + CCActionInterval* Button::clickActionForType() { switch (m_impl->m_animationType) { case AnimationType::None: { @@ -232,8 +243,6 @@ void Button::setDefaults() { m_impl->m_defaults->setContentSize(getContentSize()); - m_impl->m_defaults->setZOrder(getZOrder()); - m_impl->m_defaults->setOpacity(getOpacity()); m_impl->m_defaults->setColor(getColor()); } @@ -261,8 +270,6 @@ void Button::resetDefaults() { setContentSize(m_impl->m_defaults->getContentSize()); - setZOrder(m_impl->m_defaults->getZOrder()); - setOpacity(m_impl->m_defaults->getOpacity()); setColor(m_impl->m_defaults->getColor()); }