cherry-pick BasedButtonSprite changes from new-index-but-better

This commit is contained in:
HJfod 2024-05-16 14:59:46 +03:00
parent f79e87af93
commit edb8e6c721
3 changed files with 26 additions and 10 deletions
loader

View file

@ -28,7 +28,6 @@ namespace geode {
Gray = 2,
Blue = 3,
Cyan = 4,
Geode = 5,
};
GEODE_DLL const char* baseEnumToString(CircleBaseColor);
@ -148,6 +147,8 @@ namespace geode {
int m_size;
int m_color;
cocos2d::CCNode* m_onTop = nullptr;
float m_onTopRelativeScale = 1.f;
cocos2d::CCPoint m_topOffset = cocos2d::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,12 @@ namespace geode {
cocos2d::CCNode* ontop, BaseType type, int size, int color
);
/**
* Set an offset to the top sprite
*/
void setTopOffset(cocos2d::CCPoint const& offset);
void setTopRelativeScale(float scale);
cocos2d::CCNode* getTopNode() const;
};

View file

@ -72,7 +72,7 @@ struct CustomMenuLayer : Modify<CustomMenuLayer, MenuLayer> {
if (!m_fields->m_menuDisabled) {
m_fields->m_geodeButton = CircleButtonSprite::createWithSpriteFrameName(
"geode-logo-outline-gold.png"_spr,
1.0f,
.95f,
CircleBaseColor::Green,
CircleBaseSize::MediumAlt
);

View file

@ -25,7 +25,6 @@ const char* geode::baseEnumToString(CircleBaseColor value) {
case CircleBaseColor::Gray: return "Gray";
case CircleBaseColor::Blue: return "Blue";
case CircleBaseColor::Cyan: return "Cyan";
case CircleBaseColor::Geode: return "Geode";
}
return "Unknown";
}
@ -190,8 +189,9 @@ bool BasedButtonSprite::init(CCNode* ontop, BaseType type, int size, int color)
if (ontop) {
m_onTop = ontop;
m_onTop->setPosition(this->getContentSize() / 2 + this->getTopOffset());
limitNodeSize(m_onTop, this->getMaxTopSize(), m_onTop->getScale(), .1f);
m_onTop->setPosition(this->getContentSize() / 2 + m_topOffset);
limitNodeSize(m_onTop, this->getMaxTopSize(), 999.f, .1f);
m_onTop->setScale(m_onTop->getScale() * m_onTopRelativeScale);
this->addChild(m_onTop);
}
@ -202,8 +202,18 @@ 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;
if (m_onTop) {
m_onTop->setPosition(this->getContentSize() / 2 + offset);
}
}
void BasedButtonSprite::setTopRelativeScale(float scale) {
m_onTopRelativeScale = scale;
if (m_onTop) {
limitNodeSize(m_onTop, this->getMaxTopSize(), 999.f, .1f);
m_onTop->setScale(m_onTop->getScale() * m_onTopRelativeScale);
}
}
bool BasedButtonSprite::initWithSprite(
@ -211,7 +221,7 @@ bool BasedButtonSprite::initWithSprite(
) {
auto spr = CCSprite::create(sprName);
if (!spr) return false;
spr->setScale(sprScale);
m_onTopRelativeScale = sprScale;
return this->init(spr, type, size, color);
}
@ -220,7 +230,7 @@ bool BasedButtonSprite::initWithSpriteFrameName(
) {
auto spr = CCSprite::createWithSpriteFrameName(sprName);
if (!spr) return false;
spr->setScale(sprScale);
m_onTopRelativeScale = sprScale;
return this->init(spr, type, size, color);
}