Skip to content

Commit

Permalink
this will bresk compiling btw
Browse files Browse the repository at this point in the history
Signed-off-by: Erymanthus[#5074] | (u/)RayDeeUx <[email protected]>
  • Loading branch information
RayDeeUx committed Aug 15, 2024
1 parent aa0cd50 commit 4556872
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 50 deletions.
15 changes: 15 additions & 0 deletions mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@
"type": "bool",
"default": true
},
"customPrefix": {
"name": "Notification Prefix",
"description": "Set your prefix for the \"Now Playing\" notification here.\n\n<cyTo disable the prefix, set it to </c><cc>\"[Empty]\"</c><cy>.</c>",
"type": "string",
"default": "Now Playing",
"one-of": [
"Now Playing",
"Current Song",
"Looping",
"Song",
"Music",
"Playing",
"[Empty]"
]
},
"notificationTime": {
"name": "Notification Time",
"type": "float",
Expand Down
38 changes: 38 additions & 0 deletions src/CCDirector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "Utils.hpp"
#include <Geode/modify/CCDirector.hpp>

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();
}
};
12 changes: 6 additions & 6 deletions src/GameManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
};
19 changes: 11 additions & 8 deletions src/MenuLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class $modify(MenuLoopMLHook, MenuLayer) {
struct Fields {
SongManager &songManager = SongManager::get();
};

bool init() {
if (!MenuLayer::init())
return false;
Expand All @@ -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<std::string>("customPrefix");
if (!prefix.empty())
notifString = fmt::format("{}: ", prefix);

if (Utils::getBool("useCustomSongs")) {
notifString = notifString.append(songFileName.string());
Expand Down Expand Up @@ -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)
);
Expand All @@ -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();
}
};
56 changes: 28 additions & 28 deletions src/OptionsLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
};
16 changes: 8 additions & 8 deletions src/PlayLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
};
19 changes: 19 additions & 0 deletions src/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,25 @@ bool Utils::getBool(std::string setting) {
return geode::Mod::get()->getSettingValue<bool>(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<double>("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() {
Expand Down
2 changes: 2 additions & 0 deletions src/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};

0 comments on commit 4556872

Please sign in to comment.