mirror of
https://github.com/geode-sdk/geode.git
synced 2025-04-12 21:14:41 -04:00
add geode::cocos::reloadTextures utility
This commit is contained in:
parent
a33bb71eda
commit
ec8da8da87
3 changed files with 43 additions and 1 deletions
|
@ -67,7 +67,9 @@ class AppDelegate : cocos2d::CCApplication {
|
|||
virtual void applicationWillResignActive() = mac 0x3aab50, win 0x3cf20;
|
||||
virtual void trySaveGame() = mac 0x3aaf10, win 0x3d5e0, ios 0x1a28f0;
|
||||
virtual void willSwitchToScene(cocos2d::CCScene*) = mac 0x3aaf40, win 0x3d690;
|
||||
static AppDelegate* get() = mac 0x3aab10;
|
||||
static AppDelegate* get() {
|
||||
return static_cast<AppDelegate*>(cocos2d::CCApplication::sharedApplication());
|
||||
}
|
||||
bool musicTest() = win 0x3d580;
|
||||
void pauseGame() = mac 0x3aab60, win 0x3d3e0;
|
||||
void resumeSound() = win 0x3d4d0;
|
||||
|
|
|
@ -131,6 +131,17 @@ namespace geode::cocos {
|
|||
*/
|
||||
GEODE_DLL cocos2d::CCScene* switchToScene(cocos2d::CCLayer* layer);
|
||||
|
||||
using CreateLayerFunc = cocos2d::CCLayer*(*)();
|
||||
|
||||
/**
|
||||
* Reload textures, overwriting the scene to return to after the loading
|
||||
* screen is finished
|
||||
* @param returnTo A function that returns a new layer. After loading is
|
||||
* finished, the game switches to the given layer instead of MenuLayer.
|
||||
* Leave nullptr to enable default behaviour
|
||||
*/
|
||||
GEODE_DLL void reloadTextures(CreateLayerFunc returnTo = nullptr);
|
||||
|
||||
/**
|
||||
* Rescale node to fit inside given size
|
||||
* @param node Node to rescale
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <Geode/utils/cocos.hpp>
|
||||
#include <Geode/utils/operators.hpp>
|
||||
#include <Geode/utils/WackyGeodeMacros.hpp>
|
||||
#include <Geode/modify/LoadingLayer.hpp>
|
||||
|
||||
USE_GEODE_NAMESPACE();
|
||||
|
||||
|
@ -108,3 +109,31 @@ CCScene* geode::cocos::switchToScene(CCLayer* layer) {
|
|||
));
|
||||
return scene;
|
||||
}
|
||||
|
||||
static CreateLayerFunc LOADING_FINISHED_SCENE = nullptr;
|
||||
|
||||
void geode::cocos::reloadTextures(CreateLayerFunc returnTo) {
|
||||
LOADING_FINISHED_SCENE = returnTo;
|
||||
GameManager::get()->reloadAll(false, false, true);
|
||||
}
|
||||
|
||||
class $modify(LoadingLayer) {
|
||||
void loadingFinished() {
|
||||
// Default behaviour
|
||||
if (!LOADING_FINISHED_SCENE) {
|
||||
return LoadingLayer::loadingFinished();
|
||||
}
|
||||
// Create custom layer
|
||||
auto layer = LOADING_FINISHED_SCENE();
|
||||
// If failed, default behaviour
|
||||
if (!layer) {
|
||||
return LoadingLayer::loadingFinished();
|
||||
}
|
||||
auto scene = CCScene::create();
|
||||
scene->addChild(layer);
|
||||
AppDelegate::get()->m_runningScene = scene;
|
||||
CCDirector::get()->replaceScene(scene);
|
||||
// Don't overwrite behaviour next time
|
||||
LOADING_FINISHED_SCENE = nullptr;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue