diff --git a/loader/include/Geode/UI.hpp b/loader/include/Geode/UI.hpp index 54edc0236..6318b3e6a 100644 --- a/loader/include/Geode/UI.hpp +++ b/loader/include/Geode/UI.hpp @@ -17,7 +17,7 @@ #include "ui/MDTextArea.hpp" #include "ui/Notification.hpp" #include "ui/Popup.hpp" -#include "ui/SceneManager.hpp" +#include "ui/OverlayManager.hpp" #include "ui/Scrollbar.hpp" #include "ui/ScrollLayer.hpp" #include "ui/SelectList.hpp" diff --git a/loader/include/Geode/ui/Notification.hpp b/loader/include/Geode/ui/Notification.hpp index ce79bd922..e59f86ba5 100644 --- a/loader/include/Geode/ui/Notification.hpp +++ b/loader/include/Geode/ui/Notification.hpp @@ -1,6 +1,6 @@ #pragma once -#include "SceneManager.hpp" +#include "OverlayManager.hpp" #include #include #include diff --git a/loader/include/Geode/ui/OverlayManager.hpp b/loader/include/Geode/ui/OverlayManager.hpp new file mode 100644 index 000000000..688d893b1 --- /dev/null +++ b/loader/include/Geode/ui/OverlayManager.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include "../DefaultInclude.hpp" + +#include +#include + +namespace geode { + class GEODE_DLL OverlayManager final : public cocos2d::CCNode { + public: + static OverlayManager* get(); + }; +} diff --git a/loader/include/Geode/ui/SceneManager.hpp b/loader/include/Geode/ui/SceneManager.hpp deleted file mode 100644 index 2c57c564d..000000000 --- a/loader/include/Geode/ui/SceneManager.hpp +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -#include "../DefaultInclude.hpp" - -#include -#include -#include -#include - -namespace geode { - struct SceneSwitch; - - class GEODE_DLL SceneManager final { - protected: - std::vector> m_persistedNodes; - cocos2d::CCScene* m_lastScene = nullptr; - - virtual ~SceneManager(); - - void willSwitchToScene(cocos2d::CCScene* scene); - - friend struct SceneSwitch; - - public: - static SceneManager* get(); - - /** - * Adds a node to the list of persisted nodes, which are kept across scene changes. - * @param node The node to keep across scenes. - */ - void keepAcrossScenes(cocos2d::CCNode* node); - - /** - * Removes a node from the list of persisted nodes. - * @param node The node to forget. - */ - void forget(cocos2d::CCNode* node); - - /** - * Gets a span of the persisted nodes. To add new nodes to the list, use keepAcrossScenes. - */ - std::span const> getPersistedNodes(); - }; -} diff --git a/loader/src/hooks/persist.cpp b/loader/src/hooks/persist.cpp index 87a5b885e..602041e0f 100644 --- a/loader/src/hooks/persist.cpp +++ b/loader/src/hooks/persist.cpp @@ -1,5 +1,6 @@ -#include +#include #include +#include using namespace geode::prelude; @@ -11,26 +12,19 @@ using namespace geode::prelude; namespace geode { -#ifdef GEODE_IS_WINDOWS -struct SceneSwitch : Modify { +struct DrawOverlay : Modify { GEODE_FORWARD_COMPAT_DISABLE_HOOKS("persist disabled") - void willSwitchToScene(CCScene* scene) { - AppDelegate::willSwitchToScene(scene); - SceneManager::get()->willSwitchToScene(scene); + static void onModify(auto& self) { + if (auto res = self.setHookPriorityPost("cocos2d::CCEGLView::swapBuffers", Priority::First); !res) { + geode::log::warn("Failed to set hook priority: {}", res.unwrapErr()); + } } -}; - -#else -struct SceneSwitch : Modify { - GEODE_FORWARD_COMPAT_DISABLE_HOOKS("persist disabled") - void willSwitchToScene(CCScene* scene) { - AchievementNotifier::willSwitchToScene(scene); - SceneManager::get()->willSwitchToScene(scene); + void swapBuffers() { + OverlayManager::get()->visit(); + CCEGLView::swapBuffers(); } }; -#endif - struct SceneSwitch2 : Modify { GEODE_FORWARD_COMPAT_DISABLE_HOOKS("persist disabled") // CCDirector does not call willSwitchToScene in these 2 instances, @@ -54,4 +48,5 @@ struct SceneSwitch2 : Modify { } }; -} \ No newline at end of file + +} diff --git a/loader/src/ui/nodes/Notification.cpp b/loader/src/ui/nodes/Notification.cpp index 2b4afbd88..c6ec63574 100644 --- a/loader/src/ui/nodes/Notification.cpp +++ b/loader/src/ui/nodes/Notification.cpp @@ -59,7 +59,7 @@ void Notification::showNextNotification() { s_queue = CCArray::create(); s_queue->retain(); } - SceneManager::get()->forget(this); + OverlayManager::get()->removeChild(this); // remove self from front of queue s_queue->removeFirstObject(); if (auto obj = s_queue->firstObject()) { @@ -180,7 +180,7 @@ void Notification::show() { this->setPosition(winSize.width / 2, winSize.height / 4); this->setZOrder(CCScene::get()->getChildrenCount() > 0 ? CCScene::get()->getHighestChildZ() + 2 : 10); } - SceneManager::get()->keepAcrossScenes(this); + OverlayManager::get()->addChild(this); m_showing = true; } this->runAction(CCSequence::create( diff --git a/loader/src/ui/nodes/OverlayManager.cpp b/loader/src/ui/nodes/OverlayManager.cpp new file mode 100644 index 000000000..bb7c84b86 --- /dev/null +++ b/loader/src/ui/nodes/OverlayManager.cpp @@ -0,0 +1,14 @@ +#include +#include +#include + +using namespace geode::prelude; + +OverlayManager* OverlayManager::get() { + static OverlayManager* inst = nullptr; + if (!inst) { + inst = new OverlayManager(); + inst->onEnter(); + } + return inst; +} \ No newline at end of file diff --git a/loader/src/ui/nodes/SceneManager.cpp b/loader/src/ui/nodes/SceneManager.cpp deleted file mode 100644 index eeaf14500..000000000 --- a/loader/src/ui/nodes/SceneManager.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -#include - -using namespace geode::prelude; - -SceneManager* SceneManager::get() { - static SceneManager* inst = nullptr; - if (!inst) { - inst = new SceneManager(); - } - return inst; -} - -SceneManager::~SceneManager() {} - -void SceneManager::keepAcrossScenes(CCNode* node) { - if (ranges::contains(m_persistedNodes, node)) { - return; - } - m_persistedNodes.push_back(node); - if (m_lastScene) { - node->removeFromParentAndCleanup(false); - m_lastScene->addChild(node); - } -} - -void SceneManager::forget(CCNode* node) { - std::erase(m_persistedNodes, node); -} - -std::span const> SceneManager::getPersistedNodes() { - return m_persistedNodes; -} - -void SceneManager::willSwitchToScene(CCScene* scene) { - for (auto& node : m_persistedNodes) { - // no cleanup in order to keep actions running - node->removeFromParentAndCleanup(false); - if(scene) scene->addChild(node); - } - m_lastScene = scene; -}