From 2825654361c4de53c052effdf545dee289167dd8 Mon Sep 17 00:00:00 2001 From: HJfod <60038575+HJfod@users.noreply.github.com> Date: Thu, 22 Feb 2024 23:56:20 +0200 Subject: [PATCH] make top sprite offset settable in BasedButtonSprite --- loader/include/Geode/ui/BasedButtonSprite.hpp | 7 ++++++- loader/src/ui/nodes/BasedButtonSprite.cpp | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/loader/include/Geode/ui/BasedButtonSprite.hpp b/loader/include/Geode/ui/BasedButtonSprite.hpp index 8925a414..4900836f 100644 --- a/loader/include/Geode/ui/BasedButtonSprite.hpp +++ b/loader/include/Geode/ui/BasedButtonSprite.hpp @@ -148,6 +148,7 @@ namespace geode { int m_size; int m_color; cocos2d::CCNode* m_onTop = nullptr; + cocos2d::CCPoint m_topOffset = CCPointZero; bool init(cocos2d::CCNode* ontop, BaseType type, int size, int color); bool initWithSprite( @@ -157,7 +158,6 @@ namespace geode { const char* sprName, float sprScale, BaseType type, int size, int color ); - cocos2d::CCPoint getTopOffset() const; virtual cocos2d::CCSize getMaxTopSize() const; virtual ~BasedButtonSprite(); @@ -180,6 +180,11 @@ namespace geode { cocos2d::CCNode* ontop, BaseType type, int size, int color ); + /** + * Set an offset to the top sprite + */ + void setTopOffset(CCPoint const& offset); + cocos2d::CCNode* getTopNode() const; }; diff --git a/loader/src/ui/nodes/BasedButtonSprite.cpp b/loader/src/ui/nodes/BasedButtonSprite.cpp index f41e4c3a..49256387 100644 --- a/loader/src/ui/nodes/BasedButtonSprite.cpp +++ b/loader/src/ui/nodes/BasedButtonSprite.cpp @@ -190,7 +190,7 @@ bool BasedButtonSprite::init(CCNode* ontop, BaseType type, int size, int color) if (ontop) { m_onTop = ontop; - m_onTop->setPosition(this->getContentSize() / 2 + this->getTopOffset()); + m_onTop->setPosition(this->getContentSize() / 2 + m_topOffset); limitNodeSize(m_onTop, this->getMaxTopSize(), m_onTop->getScale(), .1f); this->addChild(m_onTop); } @@ -202,8 +202,8 @@ CCSize BasedButtonSprite::getMaxTopSize() const { return m_obContentSize - CCSize(18.f, 18.f); } -CCPoint BasedButtonSprite::getTopOffset() const { - return { 0, 0 }; +void BasedButtonSprite::setTopOffset(CCPoint const& offset) { + m_topOffset = offset; } bool BasedButtonSprite::initWithSprite(