diff --git a/mod.json b/mod.json index eec05cf..eccf928 100644 --- a/mod.json +++ b/mod.json @@ -35,6 +35,21 @@ "type": "bool", "default": true }, + "customPrefix": { + "name": "Notification Prefix", + "description": "Set your prefix for the \"Now Playing\" notification here.\n\n\"[Empty]\".", + "type": "string", + "default": "Now Playing", + "one-of": [ + "Now Playing", + "Current Song", + "Looping", + "Song", + "Music", + "Playing", + "[Empty]" + ] + }, "notificationTime": { "name": "Notification Time", "type": "float", diff --git a/src/CCDirector.cpp b/src/CCDirector.cpp new file mode 100644 index 0000000..5d27588 --- /dev/null +++ b/src/CCDirector.cpp @@ -0,0 +1,38 @@ +#include "Utils.hpp" +#include + +using namespace geode::prelude; + +class $modify(MenuLoopCCDHook, CCDirector) { + void willSwitchToScene(cocos2d::CCScene* scene) { + CCDirector* director = get(); + CCScene* previousScene = director->getRunningScene(); + + director->willSwitchToScene(scene); + + if (previousScene->getChildByIDRecursive("MenuLayer")) + Utils::removeCurrentNotif(); + } + + bool pushScene(cocos2d::CCScene* scene) { + CCDirector* director = get(); + CCScene* previousScene = director->getRunningScene(); + + bool result = director->pushScene(scene); + + if (previousScene->getChildByIDRecursive("MenuLayer")) + Utils::removeCurrentNotif(); + + return result; + } + + void popSceneWithTransition(float p0, cocos2d::PopTransition p1) { + CCDirector* director = get(); + CCScene* previousScene = director->getRunningScene(); + + director->popSceneWithTransition(p0, p1); + + if (previousScene->getChildByIDRecursive("MenuLayer")) + Utils::removeCurrentNotif(); + } +}; \ No newline at end of file diff --git a/src/GameManager.cpp b/src/GameManager.cpp index f6a101f..781d562 100644 --- a/src/GameManager.cpp +++ b/src/GameManager.cpp @@ -4,10 +4,10 @@ using namespace geode::prelude; class $modify(MenuLoopGMHook, GameManager) { - struct Fields { - SongManager &songManager = SongManager::get(); - }; - gd::string getMenuMusicFile() { - return m_fields->songManager.getCurrentSong(); - } + struct Fields { + SongManager &songManager = SongManager::get(); + }; + gd::string getMenuMusicFile() { + return m_fields->songManager.getCurrentSong(); + } }; \ No newline at end of file diff --git a/src/MenuLayer.cpp b/src/MenuLayer.cpp index 93a0514..3a607ec 100644 --- a/src/MenuLayer.cpp +++ b/src/MenuLayer.cpp @@ -9,6 +9,7 @@ class $modify(MenuLoopMLHook, MenuLayer) { struct Fields { SongManager &songManager = SongManager::get(); }; + bool init() { if (!MenuLayer::init()) return false; @@ -28,7 +29,10 @@ class $modify(MenuLoopMLHook, MenuLayer) { void generateNotifcation() { auto songFileName = std::filesystem::path(m_fields->songManager.getCurrentSong()).filename(); - std::string notifString = "Now playing: "; + std::string notifString; + auto prefix = Mod::get()->getSettingValue("customPrefix"); + if (!prefix.empty()) + notifString = fmt::format("{}: ", prefix); if (Utils::getBool("useCustomSongs")) { notifString = notifString.append(songFileName.string()); @@ -86,9 +90,7 @@ class $modify(MenuLoopMLHook, MenuLayer) { auto menu = getChildByID("right-side-menu"); auto btn = CCMenuItemSpriteExtra::create( - CircleButtonSprite::create( - CCSprite::create("shuffle-btn-sprite.png"_spr) - ), + CircleButtonSprite::create(CCSprite::create("shuffle-btn-sprite.png"_spr)), this, menu_selector(MenuLoopMLHook::onShuffleBtn) ); @@ -99,10 +101,11 @@ class $modify(MenuLoopMLHook, MenuLayer) { } void onShuffleBtn(CCObject *sender) { - if (auto card = getChildByIDRecursive("now-playing"_spr)) { - card->removeMeAndCleanup(); - } + Utils::removeCurrentNotif(); + Utils::setNewSong(); - MenuLoopMLHook::generateNotifcation(); + + if (Utils::getBool("enableNotification")) + MenuLoopMLHook::generateNotifcation(); } }; \ No newline at end of file diff --git a/src/OptionsLayer.cpp b/src/OptionsLayer.cpp index 8b90139..dadd596 100644 --- a/src/OptionsLayer.cpp +++ b/src/OptionsLayer.cpp @@ -3,32 +3,32 @@ using namespace geode::prelude; class $modify(MenuLoopOLHook, OptionsLayer) { - void customSetup() { - OptionsLayer::customSetup(); - - // add the folder btn to the settings layer - auto menu = CCMenu::create(); - - auto btn = CCMenuItemSpriteExtra::create( - CircleButtonSprite::create( - CCSprite::createWithSpriteFrameName("gj_folderBtn_001.png"), - CircleBaseColor::Pink - ), - this, - menu_selector(MenuLoopOLHook::onSongsBtn) - ); - - btn->setPosition({-144.0f, -60.0f}); - btn->m_scaleMultiplier = 1.1f; - btn->setID("songs-button"_spr); - - menu->addChild(btn); - menu->setID("songs-button-menu"_spr); - - m_mainLayer->addChild(menu); - } - - void onSongsBtn(CCObject *sender) { - file::openFolder(Mod::get()->getConfigDir()); - } + void customSetup() { + OptionsLayer::customSetup(); + + // add the folder btn to the settings layer + auto menu = CCMenu::create(); + + auto btn = CCMenuItemSpriteExtra::create( + CircleButtonSprite::create( + CCSprite::createWithSpriteFrameName("gj_folderBtn_001.png"), + CircleBaseColor::Pink + ), + this, + menu_selector(MenuLoopOLHook::onSongsBtn) + ); + + btn->setPosition({-144.0f, -60.0f}); + btn->m_scaleMultiplier = 1.1f; + btn->setID("songs-button"_spr); + + menu->addChild(btn); + menu->setID("songs-button-menu"_spr); + + m_mainLayer->addChild(menu); + } + + void onSongsBtn(CCObject *sender) { + file::openFolder(Mod::get()->getConfigDir()); + } }; \ No newline at end of file diff --git a/src/PlayLayer.cpp b/src/PlayLayer.cpp index b5c8cb9..1c4cc93 100644 --- a/src/PlayLayer.cpp +++ b/src/PlayLayer.cpp @@ -5,13 +5,13 @@ using namespace geode::prelude; class $modify(MenuLoopPLHook, PlayLayer) { - struct Fields { - SongManager &songManager = SongManager::get(); - }; - void onQuit() { - if (Utils::getBool("randomizeWhenExitingLevel")) - m_fields->songManager.pickRandomSong(); + struct Fields { + SongManager &songManager = SongManager::get(); + }; + void onQuit() { + if (Utils::getBool("randomizeWhenExitingLevel")) + m_fields->songManager.pickRandomSong(); - PlayLayer::onQuit(); - } + PlayLayer::onQuit(); + } }; \ No newline at end of file diff --git a/src/Utils.cpp b/src/Utils.cpp index 7d7f045..e3ceac5 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -28,6 +28,25 @@ bool Utils::getBool(std::string setting) { return geode::Mod::get()->getSettingValue(setting); } +// TODO FIX + +void Utils::removeCurrentNotif() { + if (auto card = cocos2d::CCDirector::get()->getRunningScene()->getChildByIDRecursive("now-playing"_spr)) { + cocos2d::CCAction* fadeOutSequence = cocos2d::CCSequence::create( + cocos2d::CCFadeOut::create(geode::Mod::get()->getSettingValue("notificationTime") / 4), + cocos2d::CCDelayTime::create(.125f), + cocos2d::CCCallFunc::create(callfunc_selector(Utils::removeCard)), + nullptr + ); + card->runAction(fadeOutSequence); + } +} + +void Utils::removeCard(cocos2d::CCObject* sender) { + if (auto card = cocos2d::CCDirector::get()->getRunningScene()->getChildByIDRecursive("now-playing"_spr)) + card->removeMeAndCleanup(); +} + #include "SongManager.hpp" void Utils::setNewSong() { diff --git a/src/Utils.hpp b/src/Utils.hpp index 2ec1d2f..cbc87e5 100644 --- a/src/Utils.hpp +++ b/src/Utils.hpp @@ -6,5 +6,7 @@ class Utils { static int stoi(std::string); static bool isSupportedExtension(std::string); static bool getBool(std::string); + static void removeCurrentNotif(); + static void removeCard(cocos2d::CCObject*); static void setNewSong(); }; \ No newline at end of file