diff --git a/mod.json b/mod.json index c7eaae6..8ccd47b 100644 --- a/mod.json +++ b/mod.json @@ -1,10 +1,10 @@ { - "geode": "4.7.0", + "geode": "5.0.0-beta.3", "gd": { - "win": "2.2074", - "mac": "2.2074", - "ios": "2.2074", - "android": "2.2074" + "win": "2.2081", + "mac": "2.2081", + "ios": "2.2081", + "android": "2.2081" }, "id": "dulak.wraith-help", "name": "Wraith Helper", diff --git a/src/main.cpp b/src/main.cpp index e5c4766..f18cbfc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,12 +4,11 @@ #include #include - using namespace geode::prelude; -class MyPopup : public geode::Popup<> { +class MyPopup : public geode::Popup { protected: - EventListener m_listener; + async::TaskHolder m_listener; size_t m_currentPage = 0; static constexpr size_t kPerPage = 5; CCMenu* m_contentMenu = nullptr; @@ -20,13 +19,15 @@ class MyPopup : public geode::Popup<> { CCLabelBMFont* m_titleLabel = nullptr; CCLabelBMFont* m_codeLabel = nullptr; std::map > codes = {}; - std::vector m_keys; - bool setup() override { + std::vector m_keys; + + bool init() { + if (!Popup::init(320.f, 260.f)) return false; this->setTitle("Wraith helper"); - m_contentMenu = CCMenu::create(); - m_contentMenu->setContentSize({ m_size.width - 4.f, 140.f }); + m_contentMenu = CCMenu::create(); + m_contentMenu->setContentSize({ m_size.width - 4.f, 140.f }); m_contentMenu->ignoreAnchorPointForPosition(false); m_contentMenu->setAnchorPoint({ 0.5f, 0.5f }); m_contentMenu->setPosition({ m_size.width / 2, m_size.height / 2 - 10.f }); @@ -37,6 +38,7 @@ class MyPopup : public geode::Popup<> { updatePageUI(); return true; } + void updatePageUI() { auto totalItems = m_keys.size(); if (totalItems == 0) { @@ -54,7 +56,7 @@ class MyPopup : public geode::Popup<> { size_t start = m_currentPage * kPerPage; size_t end = std::min(start + kPerPage, totalItems); - float containerW = m_contentMenu ? m_contentMenu->getContentSize().width : (m_size.width - 4.f); + float containerW = m_contentMenu ? m_contentMenu->getContentSize().width : (m_size.width - 4.f); float yTop = (m_contentMenu ? m_contentMenu->getContentSize().height : 140.f) + 20.f; float lineH = 28.f; @@ -119,6 +121,7 @@ class MyPopup : public geode::Popup<> { updateProgressDisplay(); } + void rebuildIndex() { m_keys.clear(); m_keys.reserve(codes.size()); @@ -131,11 +134,14 @@ class MyPopup : public geode::Popup<> { auto const& codeB = std::get<1>(tb); if (codeA != codeB) return codeA < codeB; return a < b; - }); + } + ); } + size_t totalPages() const { return (m_keys.size() + kPerPage - 1) / kPerPage; } + void onInfo(CCObject* sender) { auto button = static_cast(sender); int index = button ? button->getTag() : -1; @@ -145,10 +151,24 @@ class MyPopup : public geode::Popup<> { auto const& reward = std::get<0>(tup); FLAlertLayer::create("Code Info", reward.c_str(), "OK")->show(); } + void downloadCodes() { - m_listener.bind([this](web::WebTask::Event* e) { - if (auto* res = e->getValue()) { - auto body = res->string().unwrapOr(""); + auto req = web::WebRequest(); + bool codesSecret = Mod::get()->getSettingValue("secret"); + bool soggy = Mod::get()->getSettingValue("soggy"); + std::string url; + if (codesSecret) { + url = "https://raw.githubusercontent.com/dulakgg/codes/main/secretcodes.json"; + } else if (soggy) { + url = "https://raw.githubusercontent.com/dulakgg/codes/main/soggycodes.json"; + } else { + url = "https://raw.githubusercontent.com/dulakgg/codes/main/codes.json"; + } + + m_listener.spawn( + req.get(url), + [this](web::WebResponse res) { + auto body = res.string().unwrapOr(""); auto parsed = matjson::parse(body); if (!parsed) { log::error("JSON failed (interesting reset your dns pls)): {}", parsed.unwrapErr()); @@ -171,18 +191,7 @@ class MyPopup : public geode::Popup<> { updatePageUI(); updateProgressDisplay(); } - }); - - auto req = web::WebRequest(); - bool codesSecret = Mod::get()->getSettingValue("secret"); - bool soggy = Mod::get()->getSettingValue("soggy"); - if (codesSecret) { - m_listener.setFilter(req.get("https://raw.githubusercontent.com/dulakgg/codes/main/secretcodes.json")); - } else if (soggy) { - m_listener.setFilter(req.get("https://raw.githubusercontent.com/dulakgg/codes/main/soggycodes.json")); - } else { - m_listener.setFilter(req.get("https://raw.githubusercontent.com/dulakgg/codes/main/codes.json")); - } + ); } void setupPaginationControls() { auto paginationMenu = CCMenu::create(); @@ -283,7 +292,8 @@ class MyPopup : public geode::Popup<> { public: static MyPopup* create() { auto ret = new MyPopup(); - if (ret->initAnchored(320.f, 260.f, "GJ_square07.png")) { + ret->m_bgSprite = NineSlice::create("GJ_square07.png"); + if (ret->init()) { ret->autorelease(); return ret; }