From 05bf984cf615305ee0963789e9f5363e45af8f5d Mon Sep 17 00:00:00 2001 From: Capeling <113705504+Capeling@users.noreply.github.com> Date: Thu, 3 Oct 2024 01:24:00 +0930 Subject: [PATCH] v1.0.3, you're welcome SMJS --- mod.json | 6 +++--- src/main.cpp | 45 ++++++++++++++++++++++++++++++--------------- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/mod.json b/mod.json index 22bdf00..dc943d7 100644 --- a/mod.json +++ b/mod.json @@ -1,15 +1,15 @@ { - "geode": "3.4.0", + "geode": "3.8.1", "gd": { "win": "2.206", "android": "2.206", "mac": "2.206" }, - "version": "v1.0.2", + "version": "v1.0.3", "id": "capeling.hide_main_menu_ui", "name": "Hide Main Menu UI", "developer": "Capeling", - "description": "Adds a button to the main menu that hides the UI!", + "description": "Adds a button that hides the UI!", "resources": { "spritesheets": { "EyeSheet": [ diff --git a/src/main.cpp b/src/main.cpp index f03f282..6c346ee 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,7 +7,6 @@ struct HookMenuLayer : Modify { struct Fields { bool m_isHidden = false; CCMenuItemToggler* m_eyeButton; - CCMenu* m_eyeMenu; }; bool init() { @@ -15,20 +14,19 @@ struct HookMenuLayer : Modify { return false; auto winSize = CCDirector::sharedDirector()->getWinSize(); auto on = CircleButtonSprite::create(CCSprite::createWithSpriteFrameName("eye_open.png"_spr), CircleBaseColor::Green, CircleBaseSize::Small); + auto offEye = CCSprite::createWithSpriteFrameName("eye_closed.png"_spr); offEye->setOpacity(255 / 2.5); - auto off = CircleButtonSprite::create(offEye, CircleBaseColor::Gray, CircleBaseSize::Small); off->setOpacity(255 / 2.5); m_fields->m_eyeButton = CCMenuItemToggler::create(on, off, this, menu_selector(HookMenuLayer::onToggleHide)); - m_fields->m_eyeMenu = CCMenu::create(); - - m_fields->m_eyeMenu->setPosition({winSize.width - 25, winSize.height - 25}); - m_fields->m_eyeMenu->setID("hide-ui-menu"_spr); + m_fields->m_eyeButton->setID("hide-menu-button"_spr); + + auto menu = static_cast(getChildByID("top-right-menu")); - m_fields->m_eyeMenu->addChild(m_fields->m_eyeButton); - addChild(m_fields->m_eyeMenu); + menu->addChild(m_fields->m_eyeButton); + menu->updateLayout(); return true; } @@ -38,17 +36,34 @@ struct HookMenuLayer : Modify { } void updateMenu() { + CCObject* node; + CCMenu* menu = static_cast(getChildByID("top-right-menu")); if(m_fields->m_isHidden) { - for(int i = 0; i < this->getChildrenCount(); i++) { - auto node = static_cast(this->getChildren()->objectAtIndex(i)); + CCARRAY_FOREACH(getChildren(), node) { + auto node2 = static_cast(node); - if(node->getID() != "main-menu-bg" && node->getID() != "hide-ui-menu"_spr) - node->setVisible(false); + if(node2->getID() != "main-menu-bg" && node2->getID() != "top-right-menu") { + node2->setVisible(false); + } + } + CCARRAY_FOREACH(menu->getChildren(), node) { + auto node2 = static_cast(node); + + log::debug("{}", node2->getID()); + + if(node2->getID() != "hide-menu-button"_spr) { + node2->setVisible(false); + } } } else { - for(int i = 0; i < this->getChildrenCount(); i++) { - auto node = static_cast(this->getChildren()->objectAtIndex(i)); - node->setVisible(true); + CCARRAY_FOREACH(getChildren(), node) { + auto node2 = static_cast(node); + node2->setVisible(true); + } + + CCARRAY_FOREACH(menu->getChildren(), node) { + auto node2 = static_cast(node); + node2->setVisible(true); } } }