|
| 1 | +#include "an_shield_popup.hpp" |
| 2 | +#include "../managers/auto_nong_manager.hpp" |
| 3 | +#include "Geode/utils/web.hpp" |
| 4 | + |
| 5 | +std::optional<int> ANShieldPopup::m_cachedCount; |
| 6 | + |
| 7 | +bool ANShieldPopup::setup() { |
| 8 | + this->setTitle("Help Required"); |
| 9 | + |
| 10 | + auto inputParent = CCNode::create(); |
| 11 | + m_inputParent = inputParent; |
| 12 | + inputParent->setContentSize({250.f, 100.f}); |
| 13 | + inputParent->setAnchorPoint({0.5f, 1.0f}); |
| 14 | + inputParent->setPosition(m_mainLayer->getContentSize().width / 2, |
| 15 | + m_mainLayer->getContentSize().height - 40.f); |
| 16 | + |
| 17 | + setString("many"); |
| 18 | + |
| 19 | + auto discordSpr = CCSprite::createWithSpriteFrameName("gj_discordIcon_001.png"); |
| 20 | + auto discordBtn = CCMenuItemSpriteExtra::create( |
| 21 | + discordSpr, this, menu_selector(ANShieldPopup::onDiscord)); |
| 22 | + auto discordMenu = CCMenu::create(); |
| 23 | + discordMenu->setID("discord-menu"); |
| 24 | + discordMenu->setPosition(250.f/2.f, 0.f); |
| 25 | + discordMenu->addChild(discordBtn); |
| 26 | + inputParent->addChild(discordMenu); |
| 27 | + |
| 28 | + m_mainLayer->addChild(inputParent); |
| 29 | + |
| 30 | + if (m_cachedCount.has_value()) { |
| 31 | + setString(std::to_string(m_cachedCount.value())); |
| 32 | + } else { |
| 33 | + auto req = web::WebRequest().header("User-Agent", "Auto-Nong").get("https://api.github.com/search/issues?q=repo:flafydev/auto-nong-indexes+is:issue+is:open"); |
| 34 | + m_countListener.bind([this](web::WebTask::Event *event) { |
| 35 | + auto res = event->getValue(); |
| 36 | + if (res && res->ok()) { |
| 37 | + auto json = res->json(); |
| 38 | + auto count = json->as_object()["total_count"].as_int(); |
| 39 | + m_cachedCount = count; |
| 40 | + setString(std::to_string(count)); |
| 41 | + } |
| 42 | + }); |
| 43 | + m_countListener.setFilter(req); |
| 44 | + } |
| 45 | + |
| 46 | + return true; |
| 47 | +} |
| 48 | + |
| 49 | +void ANShieldPopup::onDiscord(CCObject *) { |
| 50 | + web::openLinkInBrowser("https://discord.gg/twuZ3X35yM"); |
| 51 | +} |
| 52 | + |
| 53 | +void ANShieldPopup::setString(std::string count) { |
| 54 | + if (m_label) { |
| 55 | + m_label->removeFromParent(); |
| 56 | + } |
| 57 | + |
| 58 | + // Recreating because setString behaves weirdly (didn't test with TextArea tho) |
| 59 | + auto text = TextArea::create(("Auto Nong currently has <cr>" + count + "</c> NONG songs submitted by players for review.\nWe are looking for volunteers to assist with approving/rejecting the submissions.").c_str(), |
| 60 | + "chatFont.fnt", 1.f, 250.f, {0.5f, 0.5f}, 20.f, false); |
| 61 | + |
| 62 | + // text->setAnchorPoint({0.0f, 1.0f}); |
| 63 | + text->setPosition({250.f/2.f, 100.f/2.f+10.f}); |
| 64 | + // text->setContentWidth(250.f); |
| 65 | + m_label = text; |
| 66 | + m_inputParent->addChild(text); |
| 67 | +} |
0 commit comments