diff --git a/loader/src/ui/mods/GeodeStyle.cpp b/loader/src/ui/mods/GeodeStyle.cpp new file mode 100644 index 00000000..ddad2672 --- /dev/null +++ b/loader/src/ui/mods/GeodeStyle.cpp @@ -0,0 +1,49 @@ +#include "GeodeStyle.hpp" +#include + +bool GeodeButtonSprite::init(CCSprite* top, bool* state) { + if (!CCSprite::initWithFile("GE_button_05.png"_spr)) + return false; + + m_stateSrc = state; + + limitNodeSize(top, m_obContentSize * .65f, 2.f, .1f); + this->addChildAtPosition(top, Anchor::Center); + + // Only schedule update if there is a need to do so + if (state) { + this->scheduleUpdate(); + } + + return true; +} + +void GeodeButtonSprite::update(float dt) { + CCSprite::update(dt); + if (m_stateSrc && m_state != *m_stateSrc) { + m_state = *m_stateSrc; + this->setTexture(CCTextureCache::get()->addImage( + (m_state ? "GJ_button_02.png" : "GE_button_05.png"_spr), true + )); + } +} + +GeodeButtonSprite* GeodeButtonSprite::create(const char* top, bool* state) { + auto ret = new GeodeButtonSprite(); + if (ret && ret->init(CCSprite::create(top), state)) { + ret->autorelease(); + return ret; + } + CC_SAFE_DELETE(ret); + return nullptr; +} + +GeodeButtonSprite* GeodeButtonSprite::createWithSpriteFrameName(const char* top, bool* state) { + auto ret = new GeodeButtonSprite(); + if (ret && ret->init(CCSprite::createWithSpriteFrameName(top), state)) { + ret->autorelease(); + return ret; + } + CC_SAFE_DELETE(ret); + return nullptr; +} diff --git a/loader/src/ui/mods/GeodeStyle.hpp b/loader/src/ui/mods/GeodeStyle.hpp new file mode 100644 index 00000000..b9158f0b --- /dev/null +++ b/loader/src/ui/mods/GeodeStyle.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include + +using namespace geode::prelude; + +class GeodeButtonSprite : public CCSprite { +protected: + bool* m_stateSrc = nullptr; + bool m_state = false; + + bool init(CCSprite* top, bool* state); + + void update(float dt) override; + +public: + static GeodeButtonSprite* create(const char* top, bool* state = nullptr); + static GeodeButtonSprite* createWithSpriteFrameName(const char* top, bool* state = nullptr); +}; diff --git a/loader/src/ui/mods/ModItem.cpp b/loader/src/ui/mods/ModItem.cpp index bc962785..6142c760 100644 --- a/loader/src/ui/mods/ModItem.cpp +++ b/loader/src/ui/mods/ModItem.cpp @@ -14,20 +14,25 @@ bool BaseModItem::init() { m_title->setAnchorPoint({ .0f, .5f }); this->addChild(m_title); - auto by = "By " + ModMetadata::formatDeveloperDisplayString(meta.getDevelopers()); - auto developersBtn = CCMenuItemSpriteExtra::create( - CCLabelBMFont::create(by.c_str(), "goldFont.fnt"), - this, nullptr - ); m_developers = CCMenu::create(); m_developers->ignoreAnchorPointForPosition(false); - m_developers->setContentSize(developersBtn->getScaledContentSize()); - m_developers->addChildAtPosition(developersBtn, Anchor::Center); m_developers->setAnchorPoint({ .0f, .5f }); + m_developers->setLayout( + RowLayout::create() + ->setAxisAlignment(AxisAlignment::Start) + ); this->addChild(m_developers); m_viewMenu = CCMenu::create(); m_viewMenu->setAnchorPoint({ 1.f, .5f }); + m_viewMenu->setScale(.55f); + + auto viewBtn = CCMenuItemSpriteExtra::create( + ButtonSprite::create("View", "bigFont.fnt", "GE_button_05.png"_spr, .8f), + this, nullptr + ); + m_viewMenu->addChild(viewBtn); + m_viewMenu->setLayout( RowLayout::create() ->setAxisReverse(true) @@ -41,24 +46,19 @@ bool BaseModItem::init() { } void BaseModItem::updateState() { - m_viewMenu->removeAllChildren(); + m_developers->removeAllChildren(); if (this->wantsRestart()) { - auto restartSpr = ButtonSprite::create("Restart", "bigFont.fnt", "GE_button_02.png"_spr, .8f); - restartSpr->setScale(.55f); - auto restartBtn = CCMenuItemSpriteExtra::create( - restartSpr, this, nullptr - ); - m_viewMenu->addChild(restartBtn); + m_developers->addChild(ButtonSprite::create("Restart Required", "goldFont.fnt", "black-square"_spr, .8f)); } else { - auto viewSpr = ButtonSprite::create("View", "bigFont.fnt", "GE_button_05.png"_spr, .8f); - viewSpr->setScale(.55f); - auto viewBtn = CCMenuItemSpriteExtra::create( - viewSpr, this, nullptr + auto by = "By " + ModMetadata::formatDeveloperDisplayString(this->getMetadata().getDevelopers()); + auto developersBtn = CCMenuItemSpriteExtra::create( + CCLabelBMFont::create(by.c_str(), "goldFont.fnt"), + this, nullptr ); - m_viewMenu->addChild(viewBtn); + m_developers->addChild(developersBtn); } - m_viewMenu->updateLayout(); + m_developers->updateLayout(); } void BaseModItem::updateSize(float width, bool big) { @@ -74,8 +74,12 @@ void BaseModItem::updateSize(float width, bool big) { }; m_title->setPosition(m_obContentSize.height + 10, m_obContentSize.height * .7f); limitNodeSize(m_title, titleSpace, 1.f, .1f); + + // Only limit developer size by height since we're setting the content width manually + limitNodeSize(m_developers, ccp(9999, titleSpace.height * .8f), 1.f, .1f); m_developers->setPosition(m_obContentSize.height + 10, m_obContentSize.height * .3f); - limitNodeSize(m_developers, titleSpace, .4f, .1f); + m_developers->setContentWidth(titleSpace.width / m_developers->getScale()); + m_developers->updateLayout(); m_viewMenu->setContentWidth(m_obContentSize.width / 2 - 20); m_viewMenu->updateLayout(); diff --git a/loader/src/ui/mods/ModList.cpp b/loader/src/ui/mods/ModList.cpp index c0ed0555..b66d18ef 100644 --- a/loader/src/ui/mods/ModList.cpp +++ b/loader/src/ui/mods/ModList.cpp @@ -1,6 +1,7 @@ #include "ModList.hpp" #include #include "TagsPopup.hpp" +#include "GeodeStyle.hpp" bool ModList::init(ModListSource* src, CCSize const& size) { if (!CCNode::init()) @@ -71,21 +72,15 @@ bool ModList::init(ModListSource* src, CCSize const& size) { // todo: sort button - m_filterBtnSpr = CCSprite::create("GE_button_05.png"_spr); - auto filterBtnTop = CCSprite::createWithSpriteFrameName("GJ_filterIcon_001.png"); - limitNodeSize(filterBtnTop, m_filterBtnSpr->getContentSize() * .65f, 2.f, .1f); - m_filterBtnSpr->addChildAtPosition(filterBtnTop, Anchor::Center); auto filterBtn = CCMenuItemSpriteExtra::create( - m_filterBtnSpr, this, menu_selector(ModList::onFilters) + GeodeButtonSprite::createWithSpriteFrameName("GJ_filterIcon_001.png"), + this, menu_selector(ModList::onFilters) ); searchFiltersMenu->addChild(filterBtn); - auto clearFiltersBtnSpr = CCSprite::create("GE_button_05.png"_spr); - auto clearFiltersBtnTop = CCSprite::createWithSpriteFrameName("GJ_deleteIcon_001.png"); - limitNodeSize(clearFiltersBtnTop, clearFiltersBtnSpr->getContentSize() * .65f, 2.f, .1f); - clearFiltersBtnSpr->addChildAtPosition(clearFiltersBtnTop, Anchor::Center); auto clearFiltersBtn = CCMenuItemSpriteExtra::create( - clearFiltersBtnSpr, this, menu_selector(ModList::onClearFilters) + GeodeButtonSprite::createWithSpriteFrameName("GJ_deleteIcon_001.png"), + this, menu_selector(ModList::onClearFilters) ); searchFiltersMenu->addChild(clearFiltersBtn); diff --git a/loader/src/ui/mods/ModList.hpp b/loader/src/ui/mods/ModList.hpp index 5b4cec82..3689704a 100644 --- a/loader/src/ui/mods/ModList.hpp +++ b/loader/src/ui/mods/ModList.hpp @@ -33,7 +33,6 @@ protected: CCMenuItemSpriteExtra* m_pagePrevBtn; CCMenuItemSpriteExtra* m_pageNextBtn; Ref m_searchMenu; - CCSprite* m_filterBtnSpr; TextInput* m_searchInput; ModListPageUpdated m_pageUpdated = nullptr; bool m_bigSize = false; diff --git a/loader/src/ui/mods/ModsLayer.cpp b/loader/src/ui/mods/ModsLayer.cpp index ff89427c..31bbf4fd 100644 --- a/loader/src/ui/mods/ModsLayer.cpp +++ b/loader/src/ui/mods/ModsLayer.cpp @@ -2,6 +2,7 @@ #include "SwelvyBG.hpp" #include #include +#include "GeodeStyle.hpp" bool ModsLayer::init() { if (!CCLayer::init()) @@ -137,21 +138,15 @@ bool ModsLayer::init() { listActionsMenu->setAnchorPoint({ 1, 0 }); listActionsMenu->setScale(.65f); - m_bigSizeBtnSpr = CCSprite::create("GE_button_05.png"_spr); - auto bigSizeBtnTop = CCSprite::createWithSpriteFrameName("GJ_smallModeIcon_001.png"); - limitNodeSize(bigSizeBtnTop, m_bigSizeBtnSpr->getContentSize() * .65f, 2.f, .1f); - m_bigSizeBtnSpr->addChildAtPosition(bigSizeBtnTop, Anchor::Center); auto bigSizeBtn = CCMenuItemSpriteExtra::create( - m_bigSizeBtnSpr, this, menu_selector(ModsLayer::onBigView) + GeodeButtonSprite::createWithSpriteFrameName("GJ_smallModeIcon_001.png", &m_bigView), + this, menu_selector(ModsLayer::onBigView) ); listActionsMenu->addChild(bigSizeBtn); - m_searchBtnSpr = CCSprite::create("GE_button_05.png"_spr); - auto searchBtnTop = CCSprite::createWithSpriteFrameName("search.png"_spr); - limitNodeSize(searchBtnTop, m_searchBtnSpr->getContentSize() * .65f, 2.f, .1f); - m_searchBtnSpr->addChildAtPosition(searchBtnTop, Anchor::Center); auto searchBtn = CCMenuItemSpriteExtra::create( - m_searchBtnSpr, this, menu_selector(ModsLayer::onSearch) + GeodeButtonSprite::createWithSpriteFrameName("search.png"_spr, &m_showSearch), + this, menu_selector(ModsLayer::onSearch) ); listActionsMenu->addChild(searchBtn); @@ -285,29 +280,18 @@ void ModsLayer::onGoToPage(CCObject*) { void ModsLayer::onBigView(CCObject*) { m_bigView = !m_bigView; - // Make sure to avoid a crash if (m_currentSource) { m_lists.at(m_currentSource)->updateSize(m_bigView); } - - // Update the background on the size button - m_bigSizeBtnSpr->setTexture(CCTextureCache::get()->addImage( - (m_bigView ? "GJ_button_02.png" : "GE_button_05.png"_spr), true - )); } void ModsLayer::onSearch(CCObject*) { m_showSearch = !m_showSearch; - // Make sure to avoid a crash if (m_currentSource) { m_lists.at(m_currentSource)->activateSearch(m_showSearch); } - // Update the background on the search button - m_searchBtnSpr->setTexture(CCTextureCache::get()->addImage( - (m_showSearch ? "GJ_button_02.png" : "GE_button_05.png"_spr), true - )); } ModsLayer* ModsLayer::create() { diff --git a/loader/src/ui/mods/ModsLayer.hpp b/loader/src/ui/mods/ModsLayer.hpp index fd071093..b35d017f 100644 --- a/loader/src/ui/mods/ModsLayer.hpp +++ b/loader/src/ui/mods/ModsLayer.hpp @@ -15,8 +15,6 @@ protected: std::vector m_tabs; ModListSource* m_currentSource = nullptr; std::unordered_map> m_lists; - CCSprite* m_bigSizeBtnSpr; - CCSprite* m_searchBtnSpr; CCMenu* m_pageMenu; CCLabelBMFont* m_pageLabel; CCMenuItemSpriteExtra* m_goToPageBtn;