From 85823665f1b294c5aa0048d5e058a384ae651e68 Mon Sep 17 00:00:00 2001 From: Ashton <38200084+Alphalaneous@users.noreply.github.com> Date: Thu, 20 Jun 2024 20:05:24 -0400 Subject: [PATCH] Fix EditorPauseLayer :P (#95) --- mod.json | 2 +- src/EditorPauseLayer.cpp | 96 ++++++++++++++++++---------------------- 2 files changed, 44 insertions(+), 54 deletions(-) diff --git a/mod.json b/mod.json index 542532d..b0a7c61 100644 --- a/mod.json +++ b/mod.json @@ -1,5 +1,5 @@ { - "geode": "3.0.0-beta.2", + "geode": "3.0.0-beta.3", "gd": { "win": "2.206", "android": "2.206", diff --git a/src/EditorPauseLayer.cpp b/src/EditorPauseLayer.cpp index e6a21a6..700a917 100644 --- a/src/EditorPauseLayer.cpp +++ b/src/EditorPauseLayer.cpp @@ -7,57 +7,19 @@ using namespace geode::node_ids; // special class for this because making it a CCMenuItemToggler would be very UB // (not gonna reinterpret_cast that into the members) -class GuidelinesButton : public CCMenuItemSpriteExtra { -protected: - bool init() override { - auto* spr = CCSprite::createWithSpriteFrameName("GJ_audioOffBtn_001.png"); - #ifdef GEODE_IS_WINDOWS - // thank you windows - // this got inlined into the ::create function, - // so the address we have for CCMenuItemSpriteExtra::init contains the code after calling this, - // so we have to call it ourselves - if (!CCMenuItemSprite::initWithNormalSprite( - spr, nullptr, nullptr, this, nullptr - )) return false; - - // TODO: this function is cursed on windows, only takes 1 arg - #else - if (!CCMenuItemSpriteExtra::init( - spr, - nullptr, - this, nullptr - )) return false; - #endif - - this->updateSprite(); - - return true; - } +class GuidelinesButtonDummy { - void updateSprite() { - this->setNormalImage(CCSprite::createWithSpriteFrameName( +public: + void onClick(CCObject* sender) { + GameManager::get()->m_showSongMarkers ^= 1; + CCMenuItemSpriteExtra* btn = typeinfo_cast(sender); + + btn->setNormalImage(CCSprite::createWithSpriteFrameName( GameManager::get()->m_showSongMarkers ? "GJ_audioOnBtn_001.png" : "GJ_audioOffBtn_001.png" )); } - - void activate() override { - CCMenuItemSpriteExtra::activate(); - GameManager::get()->m_showSongMarkers ^= 1; - this->updateSprite(); - } - -public: - static GuidelinesButton* create() { - auto ret = new GuidelinesButton(); - if (ret && ret->init()) { - ret->autorelease(); - return ret; - } - CC_SAFE_DELETE(ret); - return nullptr; - } }; $register_ids(EditorPauseLayer) { @@ -186,15 +148,37 @@ class GuidelinesButton : public CCMenuItemSpriteExtra { menu->getChildByID("reset-unused-button"), menu->getChildByID("uncheck-portals-button") ); - #ifdef GEODE_IS_DESKTOP - if (auto keysBtn = actionsMenu->getChildByID("keys-button")) { - keysBtn->setLayoutOptions(AxisLayoutOptions::create()->setPrevGap(10.f)); - } - #endif actionsMenu->setContentSize({ 100.f, 290.f }); actionsMenu->setPositionY(155.f); actionsMenu->updateLayout(); + for(CCNode* node : CCArrayExt(menu->getChildren())) { + if(CCMenuItemToggler* toggler = typeinfo_cast(node)) { + + auto off = toggler->m_offButton; + auto on = toggler->m_onButton; + + float maxWidth = (std::max)(off->getContentSize().width, on->getContentSize().width); + float maxHeight = (std::max)(off->getContentSize().height, on->getContentSize().height); + + toggler->setContentSize({maxWidth, maxHeight}); + off->setContentSize({maxWidth, maxHeight}); + on->setContentSize({maxWidth, maxHeight}); + + off->setPosition({maxWidth/2, maxHeight/2}); + on->setPosition({maxWidth/2, maxHeight/2}); + + CCSprite* offSpr = getChildOfType(off, 0); + CCSprite* onSpr = getChildOfType(off, 0); + + off->setPosition({maxWidth/2, maxHeight/2}); + on->setPosition({maxWidth/2, maxHeight/2}); + + offSpr->setPosition({maxWidth/2, maxHeight/2}); + onSpr->setPosition({maxWidth/2, maxHeight/2}); + } + } + auto optionsMenu = detachAndCreateMenu( this, "options-menu", @@ -234,13 +218,13 @@ class GuidelinesButton : public CCMenuItemSpriteExtra { ->setSameLine(true) ->setBreakLine(true) ->setPrevGap(5.f) - ->setScaleLimits(.1f, .5f) + ->setScaleLimits(.1f, .35f) ->setScalePriority(1) ); } } optionsMenu->setContentSize({ 120.f, winSize.height - 60.f }); - optionsMenu->setPosition(70.f, winSize.height / 2 - 25.f + 10.f); + optionsMenu->setPosition(75.f, winSize.height / 2 - 25.f + 10.f); optionsMenu->updateLayout(); auto settingsMenu = detachAndCreateMenu( @@ -259,7 +243,13 @@ class GuidelinesButton : public CCMenuItemSpriteExtra { guidelinesMenu->getChildByID("guidelines-enable-button")->removeFromParent(); guidelinesMenu->getChildByID("guidelines-disable-button")->removeFromParent(); - auto glToggle = GuidelinesButton::create(); + auto* spr = CCSprite::createWithSpriteFrameName("GJ_audioOffBtn_001.png"); + auto glToggle = CCMenuItemSpriteExtra::create(spr, this, menu_selector(GuidelinesButtonDummy::onClick)); + glToggle->setNormalImage(CCSprite::createWithSpriteFrameName( + GameManager::get()->m_showSongMarkers ? + "GJ_audioOnBtn_001.png" : + "GJ_audioOffBtn_001.png" + )); glToggle->setID("guidelines-enable-toggle"); guidelinesMenu->insertBefore(glToggle, nullptr); m_guidelinesOffButton = m_guidelinesOnButton = nullptr;