Skip to content

Commit

Permalink
Fix EditorPauseLayer :P (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alphalaneous authored Jun 21, 2024
1 parent 0e5eaa6 commit 8582366
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 54 deletions.
2 changes: 1 addition & 1 deletion mod.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"geode": "3.0.0-beta.2",
"geode": "3.0.0-beta.3",
"gd": {
"win": "2.206",
"android": "2.206",
Expand Down
96 changes: 43 additions & 53 deletions src/EditorPauseLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CCMenuItemSpriteExtra*>(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) {
Expand Down Expand Up @@ -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<CCNode*>(menu->getChildren())) {
if(CCMenuItemToggler* toggler = typeinfo_cast<CCMenuItemToggler*>(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<CCSprite>(off, 0);
CCSprite* onSpr = getChildOfType<CCSprite>(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",
Expand Down Expand Up @@ -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(
Expand All @@ -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;
Expand Down

0 comments on commit 8582366

Please sign in to comment.