2022-12-01 22:42:49 +02:00
|
|
|
|
2022-10-30 21:56:36 +03:00
|
|
|
#include <Geode/modify/LoadingLayer.hpp>
|
2022-12-07 21:21:50 +02:00
|
|
|
#include <Geode/utils/cocos.hpp>
|
2022-12-10 19:30:14 +03:00
|
|
|
#include <array>
|
|
|
|
#include <fmt/format.h>
|
2022-12-14 14:50:46 +03:00
|
|
|
#include <loader/LoaderImpl.hpp>
|
2022-11-09 21:03:53 +03:00
|
|
|
|
2023-03-10 11:33:24 -08:00
|
|
|
using namespace geode::prelude;
|
2022-12-01 22:42:49 +02:00
|
|
|
|
2022-11-09 21:03:53 +03:00
|
|
|
struct CustomLoadingLayer : Modify<CustomLoadingLayer, LoadingLayer> {
|
2023-08-09 18:55:14 +03:00
|
|
|
CCLabelBMFont* m_loadedModsLabel;
|
2022-10-15 18:35:13 +03:00
|
|
|
bool m_updatingResources;
|
2022-10-14 21:04:59 +03:00
|
|
|
|
2023-08-09 18:55:14 +03:00
|
|
|
CustomLoadingLayer() : m_loadedModsLabel(nullptr), m_updatingResources(false) {}
|
2022-10-14 21:04:59 +03:00
|
|
|
|
2023-08-16 23:29:51 +03:00
|
|
|
void updateLoadedModsLabel() {
|
2023-08-09 18:55:14 +03:00
|
|
|
auto allMods = Loader::get()->getAllMods();
|
|
|
|
auto count = std::count_if(allMods.begin(), allMods.end(), [&](auto& item) {
|
2023-09-11 14:38:14 +03:00
|
|
|
return item->isEnabled();
|
2023-08-09 18:55:14 +03:00
|
|
|
});
|
|
|
|
auto str = fmt::format("Geode: Loaded {}/{} mods", count, allMods.size());
|
2023-08-16 23:29:51 +03:00
|
|
|
m_fields->m_loadedModsLabel->setCString(str.c_str());
|
2023-08-09 18:55:14 +03:00
|
|
|
}
|
2022-12-12 13:46:00 +02:00
|
|
|
|
2023-08-09 18:55:14 +03:00
|
|
|
bool init(bool fromReload) {
|
2023-01-24 00:13:20 +02:00
|
|
|
CCFileUtils::get()->updatePaths();
|
2022-08-01 18:18:03 +03:00
|
|
|
|
2023-01-24 00:13:20 +02:00
|
|
|
if (!LoadingLayer::init(fromReload)) return false;
|
2023-08-09 18:55:14 +03:00
|
|
|
|
|
|
|
if (fromReload) return true;
|
|
|
|
|
|
|
|
auto winSize = CCDirector::sharedDirector()->getWinSize();
|
|
|
|
|
2023-08-16 23:29:51 +03:00
|
|
|
m_fields->m_loadedModsLabel = CCLabelBMFont::create("Geode: Loaded 0/0 mods", "goldFont.fnt");
|
|
|
|
m_fields->m_loadedModsLabel->setPosition(winSize.width / 2, 30.f);
|
|
|
|
m_fields->m_loadedModsLabel->setScale(.45f);
|
|
|
|
m_fields->m_loadedModsLabel->setID("geode-loaded-info");
|
|
|
|
this->addChild(m_fields->m_loadedModsLabel);
|
2023-08-09 18:55:14 +03:00
|
|
|
this->updateLoadedModsLabel();
|
|
|
|
|
|
|
|
// fields have unpredictable destructors
|
|
|
|
this->addChild(EventListenerNode<ResourceDownloadFilter>::create(
|
|
|
|
this, &CustomLoadingLayer::updateResourcesProgress
|
|
|
|
));
|
|
|
|
|
|
|
|
// verify loader resources
|
|
|
|
if (!LoaderImpl::get()->verifyLoaderResources()) {
|
|
|
|
m_fields->m_updatingResources = true;
|
|
|
|
this->setUpdateText("Downloading Resources");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LoaderImpl::get()->updateSpecialFiles();
|
2022-10-14 21:04:59 +03:00
|
|
|
}
|
|
|
|
|
2022-08-01 18:18:03 +03:00
|
|
|
return true;
|
|
|
|
}
|
2022-10-14 21:04:59 +03:00
|
|
|
|
|
|
|
void setUpdateText(std::string const& text) {
|
2022-10-15 18:35:13 +03:00
|
|
|
m_textArea->setString(text.c_str());
|
2022-10-14 21:04:59 +03:00
|
|
|
}
|
|
|
|
|
2022-12-01 22:42:49 +02:00
|
|
|
void updateResourcesProgress(ResourceDownloadEvent* event) {
|
2022-12-06 21:22:03 +02: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 12:53:49 +02:00
|
|
|
[&](UpdateFailed const& error) {
|
2022-12-14 14:50:46 +03:00
|
|
|
LoaderImpl::get()->platformMessageBox(
|
2022-12-06 21:22:03 +02:00
|
|
|
"Error updating resources",
|
|
|
|
error + ".\n"
|
2022-12-17 19:08:01 +02: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 21:22:03 +02:00
|
|
|
"The game will be loaded as normal, but please be aware "
|
2022-12-17 19:08:01 +02:00
|
|
|
"that it is very likely to crash. "
|
2022-12-06 21:22:03 +02:00
|
|
|
);
|
|
|
|
this->setUpdateText("Resource Download Failed");
|
|
|
|
m_fields->m_updatingResources = false;
|
|
|
|
this->loadAssets();
|
|
|
|
}
|
|
|
|
}, event->status);
|
2022-10-14 21:04:59 +03:00
|
|
|
}
|
|
|
|
|
2022-11-09 21:03:53 +03:00
|
|
|
void loadAssets() {
|
2023-08-09 18:55:14 +03:00
|
|
|
if (Loader::get()->getLoadingState() != Loader::LoadingState::Done) {
|
|
|
|
this->updateLoadedModsLabel();
|
2023-08-19 00:23:20 +03:00
|
|
|
Loader::get()->queueInMainThread([this]() {
|
2023-08-09 18:55:14 +03:00
|
|
|
this->loadAssets();
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2022-11-09 21:03:53 +03:00
|
|
|
if (m_fields->m_updatingResources) {
|
2022-10-14 21:04:59 +03:00
|
|
|
return;
|
2022-11-09 21:03:53 +03:00
|
|
|
}
|
|
|
|
LoadingLayer::loadAssets();
|
|
|
|
}
|
2022-08-01 18:18:03 +03:00
|
|
|
};
|