2022-12-01 15:42:49 -05:00
|
|
|
|
2022-10-30 14:56:36 -04:00
|
|
|
#include <Geode/modify/LoadingLayer.hpp>
|
2022-12-07 14:21:50 -05:00
|
|
|
#include <Geode/utils/cocos.hpp>
|
2022-12-10 11:30:14 -05:00
|
|
|
#include <array>
|
|
|
|
#include <fmt/format.h>
|
2022-12-14 06:50:46 -05:00
|
|
|
#include <loader/LoaderImpl.hpp>
|
2022-11-09 13:03:53 -05:00
|
|
|
|
2022-12-01 15:42:49 -05:00
|
|
|
USE_GEODE_NAMESPACE();
|
|
|
|
|
2022-11-09 13:03:53 -05:00
|
|
|
struct CustomLoadingLayer : Modify<CustomLoadingLayer, LoadingLayer> {
|
2022-10-15 11:35:13 -04:00
|
|
|
bool m_updatingResources;
|
2022-10-14 14:04:59 -04:00
|
|
|
|
2022-10-15 11:35:13 -04:00
|
|
|
CustomLoadingLayer() : m_updatingResources(false) {}
|
2022-10-14 14:04:59 -04:00
|
|
|
|
2022-08-01 11:18:03 -04:00
|
|
|
bool init(bool fromReload) {
|
2022-12-12 06:46:00 -05:00
|
|
|
Loader::get()->waitForModsToBeLoaded();
|
|
|
|
|
2022-11-09 13:03:53 -05:00
|
|
|
if (!LoadingLayer::init(fromReload)) return false;
|
2022-08-01 11:18:03 -04:00
|
|
|
|
|
|
|
auto winSize = CCDirector::sharedDirector()->getWinSize();
|
|
|
|
|
|
|
|
auto count = Loader::get()->getAllMods().size();
|
|
|
|
|
2022-12-17 12:08:01 -05:00
|
|
|
auto label = CCLabelBMFont::create(
|
|
|
|
fmt::format("Geode: Loaded {} mods", count).c_str(),
|
|
|
|
"goldFont.fnt"
|
|
|
|
);
|
2022-08-01 11:18:03 -04:00
|
|
|
label->setPosition(winSize.width / 2, 30.f);
|
|
|
|
label->setScale(.45f);
|
2022-10-14 14:04:59 -04:00
|
|
|
label->setID("geode-loaded-info");
|
2022-08-01 11:18:03 -04:00
|
|
|
this->addChild(label);
|
|
|
|
|
2022-12-17 12:08:01 -05:00
|
|
|
// fields have unpredictable destructors
|
2022-12-07 14:21:50 -05:00
|
|
|
this->addChild(EventListenerNode<ResourceDownloadFilter>::create(
|
2022-12-07 05:35:50 -05:00
|
|
|
this, &CustomLoadingLayer::updateResourcesProgress
|
2022-12-07 14:21:50 -05:00
|
|
|
));
|
2022-10-14 14:04:59 -04:00
|
|
|
|
2022-12-01 15:42:49 -05:00
|
|
|
// verify loader resources
|
2022-12-14 06:50:46 -05:00
|
|
|
if (!LoaderImpl::get()->verifyLoaderResources()) {
|
2022-10-15 11:35:13 -04:00
|
|
|
m_fields->m_updatingResources = true;
|
2022-10-14 14:04:59 -04:00
|
|
|
this->setUpdateText("Downloading Resources");
|
|
|
|
}
|
|
|
|
|
2022-08-01 11:18:03 -04:00
|
|
|
return true;
|
|
|
|
}
|
2022-10-14 14:04:59 -04:00
|
|
|
|
|
|
|
void setUpdateText(std::string const& text) {
|
2022-10-15 11:35:13 -04:00
|
|
|
m_textArea->setString(text.c_str());
|
2022-10-14 14:04:59 -04:00
|
|
|
}
|
|
|
|
|
2022-12-01 15:42:49 -05:00
|
|
|
void updateResourcesProgress(ResourceDownloadEvent* event) {
|
2022-12-06 14:22:03 -05:00
|
|
|
std::visit(makeVisitor {
|
|
|
|
[&](UpdateProgress const& progress) {
|
|
|
|
this->setUpdateText(fmt::format(
|
|
|
|
"Downloading Resources: {}%", progress.first
|
|
|
|
));
|
|
|
|
},
|
|
|
|
[&](UpdateFinished) {
|
|
|
|
this->setUpdateText("Resources Downloaded");
|
|
|
|
m_fields->m_updatingResources = false;
|
|
|
|
this->loadAssets();
|
|
|
|
},
|
2022-12-09 05:53:49 -05:00
|
|
|
[&](UpdateFailed const& error) {
|
2022-12-14 06:50:46 -05:00
|
|
|
LoaderImpl::get()->platformMessageBox(
|
2022-12-06 14:22:03 -05:00
|
|
|
"Error updating resources",
|
|
|
|
error + ".\n"
|
2022-12-17 12:08:01 -05:00
|
|
|
"You will have to install resources manually by downloading resources.zip "
|
|
|
|
"from the latest release on GitHub: "
|
|
|
|
"https://github.com/geode-sdk/geode/releases/latest.\n"
|
2022-12-06 14:22:03 -05:00
|
|
|
"The game will be loaded as normal, but please be aware "
|
2022-12-17 12:08:01 -05:00
|
|
|
"that it is very likely to crash. "
|
2022-12-06 14:22:03 -05:00
|
|
|
);
|
|
|
|
this->setUpdateText("Resource Download Failed");
|
|
|
|
m_fields->m_updatingResources = false;
|
|
|
|
this->loadAssets();
|
|
|
|
}
|
|
|
|
}, event->status);
|
2022-10-14 14:04:59 -04:00
|
|
|
}
|
|
|
|
|
2022-11-09 13:03:53 -05:00
|
|
|
void loadAssets() {
|
|
|
|
if (m_fields->m_updatingResources) {
|
2022-10-14 14:04:59 -04:00
|
|
|
return;
|
2022-11-09 13:03:53 -05:00
|
|
|
}
|
|
|
|
LoadingLayer::loadAssets();
|
|
|
|
}
|
2022-08-01 11:18:03 -04:00
|
|
|
};
|