2022-10-14 14:04:59 -04:00
|
|
|
#include <InternalLoader.hpp>
|
2022-10-30 14:56:36 -04:00
|
|
|
#include <array>
|
2022-08-01 11:18:03 -04:00
|
|
|
|
|
|
|
USE_GEODE_NAMESPACE();
|
|
|
|
|
2022-10-30 14:56:36 -04:00
|
|
|
#include <Geode/modify/LoadingLayer.hpp>
|
2022-11-28 11:32:25 -05:00
|
|
|
#include <fmt/format.h>
|
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-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();
|
|
|
|
|
|
|
|
auto label = CCLabelBMFont::create(
|
2022-11-28 11:32:25 -05:00
|
|
|
fmt::format("Geode: Loaded {} mods", count).c_str(),
|
2022-08-01 11:18:03 -04:00
|
|
|
"goldFont.fnt"
|
|
|
|
);
|
|
|
|
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-10-14 14:04:59 -04:00
|
|
|
// verify loader resources
|
2022-11-09 13:03:53 -05:00
|
|
|
if (!InternalLoader::get()->verifyLoaderResources(std::bind(
|
|
|
|
&CustomLoadingLayer::updateResourcesProgress, this, std::placeholders::_1,
|
|
|
|
std::placeholders::_2, std::placeholders::_3
|
|
|
|
))) {
|
2022-10-15 11:35:13 -04:00
|
|
|
// auto bg = CCScale9Sprite::create(
|
|
|
|
// "square02b_001.png", { 0.0f, 0.0f, 80.0f, 80.0f }
|
|
|
|
// );
|
|
|
|
// bg->setScale(.6f);
|
|
|
|
// bg->setColor({ 0, 0, 0 });
|
|
|
|
// bg->setOpacity(150);
|
|
|
|
// bg->setPosition(winSize / 2);
|
|
|
|
// this->addChild(bg);
|
2022-10-14 14:04:59 -04:00
|
|
|
|
2022-10-15 11:35:13 -04:00
|
|
|
// m_fields->m_updatingResourcesBG = bg;
|
2022-10-14 14:04:59 -04:00
|
|
|
|
2022-10-15 11:35:13 -04:00
|
|
|
// auto label = CCLabelBMFont::create("", "goldFont.fnt");
|
|
|
|
// label->setScale(1.1f);
|
|
|
|
// bg->addChild(label);
|
2022-10-14 14:04:59 -04:00
|
|
|
|
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());
|
|
|
|
// m_fields->m_updatingResources->setString(text.c_str());
|
|
|
|
// m_fields->m_updatingResourcesBG->setContentSize({
|
|
|
|
// m_fields->m_updatingResources->getScaledContentSize().width + 30.f,
|
|
|
|
// 50.f
|
|
|
|
// });
|
|
|
|
// m_fields->m_updatingResources->setPosition(
|
|
|
|
// m_fields->m_updatingResourcesBG->getContentSize() / 2
|
|
|
|
// );
|
2022-10-14 14:04:59 -04:00
|
|
|
}
|
|
|
|
|
2022-11-09 13:03:53 -05:00
|
|
|
void updateResourcesProgress(UpdateStatus status, std::string const& info, uint8_t progress) {
|
2022-10-14 14:04:59 -04:00
|
|
|
switch (status) {
|
|
|
|
case UpdateStatus::Progress: {
|
2022-11-09 13:03:53 -05:00
|
|
|
this->setUpdateText("Downloading Resources: " + std::to_string(progress) + "%");
|
2022-10-14 14:04:59 -04:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case UpdateStatus::Finished: {
|
|
|
|
this->setUpdateText("Resources Downloaded");
|
2022-10-15 11:35:13 -04:00
|
|
|
m_fields->m_updatingResources = false;
|
2022-10-14 14:04:59 -04:00
|
|
|
this->loadAssets();
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case UpdateStatus::Failed: {
|
|
|
|
InternalLoader::platformMessageBox(
|
|
|
|
"Error updating resources",
|
2022-11-09 13:03:53 -05:00
|
|
|
"Unable to update Geode resources: " + info +
|
|
|
|
".\n"
|
|
|
|
"The game will be loaded as normal, but please be aware "
|
|
|
|
"that it may very likely crash."
|
2022-10-14 14:04:59 -04:00
|
|
|
);
|
|
|
|
this->setUpdateText("Resource Download Failed");
|
2022-10-15 11:35:13 -04:00
|
|
|
m_fields->m_updatingResources = false;
|
2022-10-14 14:04:59 -04:00
|
|
|
this->loadAssets();
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
};
|