update default logo to just N/A + move featured to a star icon next to the title rather than glow since we can't enforce mod logo shape

This commit is contained in:
HJfod 2024-02-28 21:33:58 +02:00
parent c7d64beb7a
commit eed99d16c5
4 changed files with 33 additions and 45 deletions

View file

@ -40,5 +40,5 @@ namespace geode {
* logo is initially a loading circle, with the actual sprite downloaded
* asynchronously
*/
GEODE_DLL cocos2d::CCNode* createServerModLogo(std::string const& id, bool featured);
GEODE_DLL cocos2d::CCNode* createServerModLogo(std::string const& id);
}

View file

@ -69,10 +69,9 @@ class ModLogoSprite : public CCNode {
protected:
std::string m_modID;
CCNode* m_sprite = nullptr;
CCNode* m_featuredSprite = nullptr;
EventListener<PromiseEventFilter<ByteVector, server::ServerError>> m_listener;
bool init(std::string const& id, bool fetch, bool featured) {
bool init(std::string const& id, bool fetch) {
if (!CCNode::init())
return false;
@ -82,13 +81,6 @@ protected:
m_modID = id;
m_listener.bind(this, &ModLogoSprite::onFetch);
if (featured) {
m_featuredSprite = CCSprite::createWithSpriteFrameName("logo-glow.png"_spr);
limitNodeSize(m_featuredSprite, m_obContentSize * 1.15f, 99.f, .1f);
m_featuredSprite->setZOrder(-1);
this->addChildAtPosition(m_featuredSprite, Anchor::Center);
}
// Load from Resources
if (!fetch) {
this->setSprite(id == "geode.loader" ?
@ -104,10 +96,6 @@ protected:
m_listener.setFilter(server::getModLogo(id).listen());
}
if (m_featuredSprite) {
m_featuredSprite->setVisible(!fetch);
}
return true;
}
@ -118,21 +106,13 @@ protected:
}
// Fallback to default logo if the sprite is null
if (!sprite) {
sprite = CCSprite::createWithSpriteFrameName("no-logo.png"_spr);
}
// Fallback to lobotomy if Geode sprites are missing
if (!sprite) {
sprite = CCSprite::createWithSpriteFrameName("difficulty_02_btn_001.png");
sprite = CCLabelBMFont::create("N/A", "bigFont.fnt");
static_cast<CCLabelBMFont*>(sprite)->setOpacity(90);
}
// Set sprite and scale it to node size
m_sprite = sprite;
limitNodeSize(m_sprite, m_obContentSize, 99.f, .05f);
this->addChildAtPosition(m_sprite, Anchor::Center);
// Featured sprite is initially invisible if fetched from server
if (m_featuredSprite) {
m_featuredSprite->setVisible(true);
}
}
void onFetch(PromiseEvent<ByteVector, server::ServerError>* event) {
@ -151,9 +131,9 @@ protected:
}
public:
static ModLogoSprite* create(std::string const& id, bool fetch = false, bool featured = false) {
static ModLogoSprite* create(std::string const& id, bool fetch = false) {
auto ret = new ModLogoSprite();
if (ret && ret->init(id, fetch, featured)) {
if (ret && ret->init(id, fetch)) {
ret->autorelease();
return ret;
}
@ -170,22 +150,6 @@ CCNode* geode::createModLogo(Mod* mod) {
return ModLogoSprite::create(mod->getID());
}
CCNode* geode::createServerModLogo(std::string const& id, bool featured) {
return ModLogoSprite::create(id, true, featured);
CCNode* geode::createServerModLogo(std::string const& id) {
return ModLogoSprite::create(id, true);
}
// CCNode* geode::createIndexItemLogo(IndexItemHandle item) {
// auto logoPath = ghc::filesystem::absolute(item->getRootPath() / "logo.png");
// CCNode* spr = CCSprite::create(logoPath.string().c_str());
// if (!spr) {
// spr = createDefaultLogo();
// }
// if (item->isFeatured()) {
// auto logoGlow = CCSprite::createWithSpriteFrameName("logo-glow.png"_spr);
// spr->setScaleX(logoGlow->getContentWidth() / spr->getContentWidth());
// spr->setScaleY(logoGlow->getContentHeight() / spr->getContentHeight());
// logoGlow->addChildAtPosition(spr, Anchor::Center);
// spr = logoGlow;
// }
// return spr;
// }

View file

@ -120,9 +120,30 @@ bool ServerModItem::init(server::ServerModMetadata const& metadata) {
if (!BaseModItem::init())
return false;
if (metadata.featured) {
m_checkmark = CCScale9Sprite::createWithSpriteFrameName("GJ_colorBtn_001.png");
m_checkmark->setContentSize({ 50, 38 });
m_checkmark->setColor({ 255, 255, 120 });
m_checkmark->setOpacity(45);
auto tick = CCSprite::createWithSpriteFrameName("GJ_starsIcon_001.png");
m_checkmark->addChildAtPosition(tick, Anchor::Center);
this->addChild(m_checkmark);
}
return true;
}
void ServerModItem::updateSize(float width, bool big) {
BaseModItem::updateSize(width, big);
if (m_checkmark) {
auto size = m_title->getScaledContentSize();
limitNodeSize(m_checkmark, ccp(100, size.height), 1.f, .1f);
m_checkmark->setPosition(m_title->getPosition() + ccp(size.width + 10, 0));
}
}
ServerModItem* ServerModItem::create(server::ServerModMetadata const& metadata) {
auto ret = new ServerModItem();
if (ret && ret->init(metadata)) {
@ -138,7 +159,7 @@ ModMetadata ServerModItem::getMetadata() const {
}
CCNode* ServerModItem::createModLogo() const {
return createServerModLogo(m_metadata.id, m_metadata.featured);
return createServerModLogo(m_metadata.id);
}
bool ServerModItem::wantsRestart() const {

View file

@ -47,6 +47,7 @@ public:
class ServerModItem : public BaseModItem {
protected:
server::ServerModMetadata m_metadata;
CCScale9Sprite* m_checkmark = nullptr;
bool init(server::ServerModMetadata const& metadata);
@ -59,4 +60,6 @@ public:
ModMetadata getMetadata() const override;
CCNode* createModLogo() const override;
bool wantsRestart() const override;
void updateSize(float width, bool big) override;
};