Skip to content

Commit e5ef561

Browse files
committed
feat: Add shield popup
1 parent 3bf09fb commit e5ef561

File tree

8 files changed

+117
-4
lines changed

8 files changed

+117
-4
lines changed

.github/workflows/multi-platform.yml

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ jobs:
3838
- name: Build the mod
3939
uses: geode-sdk/build-geode-mod@main
4040
with:
41-
sdk: '3.0.0-beta.5'
4241
combine: true
4342
target: ${{ matrix.config.target }}
4443

mod.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"geode": "3.0.0-beta.5",
2+
"geode": "3.1.1",
33
"gd": {
44
"win": "2.206",
55
"android": "2.206"
@@ -9,6 +9,10 @@
99
"name": "Auto Nong",
1010
"developer": "Flafy",
1111
"description": "Automatically download NONG songs for levels",
12+
"links": {
13+
"community": "https://discord.gg/twuZ3X35yM",
14+
"source": "https://github.com/flafydev/auto-nong"
15+
},
1216
"repository": "https://github.com/flafydev/auto-nong",
1317
"tags": [
1418
"music",
@@ -26,6 +30,7 @@
2630
"resources": {
2731
"sprites": [
2832
"resources/addIcon.png",
33+
"resources/mod_btn.png",
2934
"resources/logo_regular.png",
3035
"resources/logo_grayscaled.png"
3136
]

resources/mod_btn.png

16.3 KB
Loading

src/managers/auto_nong_manager.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,8 @@ std::optional<std::string> AutoNongManager::generatePublishUrl(const ANSong &son
506506

507507
return fmt::format("https://github.com/FlafyDev/auto-nong-indexes/issues/"
508508
"new?template=add-nong-song.yml&title={}&song-name={}&artist-name={}&"
509-
"youtube-link={}&song-id={}&extra={}",
510-
title, song.m_name, song.m_artist, ytSong->m_ytId, songId, extraEncoded);
509+
"youtube-link={}&start-offset={}&song-id={}&extra={}",
510+
title, song.m_name, song.m_artist, ytSong->m_ytId, ytSong->m_startOffsetMS, songId, extraEncoded);
511511
}
512512
return std::nullopt;
513513
}

src/ui/an_dropdown_layer.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "an_dropdown_layer.hpp"
22
#include "../managers/auto_nong_manager.hpp"
33
#include "an_add_local_popup.hpp"
4+
#include "an_shield_popup.hpp"
45
#include "an_song_cell.hpp"
56

67
bool ANDropdownLayer::setup(int songId, CustomSongWidget *parent, int popupNumber, int totalPopups,
@@ -32,11 +33,19 @@ bool ANDropdownLayer::setup(int songId, CustomSongWidget *parent, int popupNumbe
3233
addNongBtn->setPosition(contentSize.width - 26.f, 28.f);
3334
addNongBtn->setID("add-nong-btn");
3435

36+
auto modBtnSpr = CCSprite::create("mod_btn.png"_spr);
37+
modBtnSpr->setScale(.8f);
38+
auto modBtn =
39+
CCMenuItemSpriteExtra::create(modBtnSpr, this, menu_selector(ANDropdownLayer::onShield));
40+
modBtn->setPosition(contentSize.width - 26.f, 70.f);
41+
modBtn->setID("mod-btn");
42+
3543
menu = CCMenu::create();
3644
menu->setAnchorPoint(ccp(0, 0));
3745
menu->setPosition(ccp(0, 0));
3846
menu->setID("button-menu2");
3947
menu->addChild(addNongBtn);
48+
menu->addChild(modBtn);
4049
menu->setZOrder(2);
4150
m_mainLayer->addChild(menu);
4251

@@ -148,3 +157,7 @@ void ANDropdownLayer::updateCellsButtonsState() {
148157
cell->setButtonsState();
149158
}
150159
}
160+
161+
void ANDropdownLayer::onShield(CCObject*) {
162+
ANShieldPopup::create()->show();
163+
}

src/ui/an_dropdown_layer.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ class ANDropdownLayer : public Popup<int, CustomSongWidget *, int, int, bool> {
4141
void updateCells();
4242
void onOpenOptions(CCObject *);
4343
void updateCellsButtonsState();
44+
void onShield(CCObject *);
4445
};

src/ui/an_shield_popup.cpp

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
}

src/ui/an_shield_popup.hpp

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#pragma once
2+
3+
#include "../includes/geode.hpp"
4+
5+
class ANShieldPopup : public Popup<> {
6+
protected:
7+
static std::optional<int> m_cachedCount;
8+
9+
EventListener<web::WebTask> m_countListener;
10+
TextArea *m_label = nullptr;
11+
CCNode* m_inputParent = nullptr;
12+
13+
bool setup() override;
14+
void onDiscord(CCObject *);
15+
void setString(std::string count);
16+
public:
17+
static ANShieldPopup *create() {
18+
auto ret = new ANShieldPopup;
19+
if (ret && ret->initAnchored(320.f, 192.f)) {
20+
ret->autorelease();
21+
return ret;
22+
}
23+
24+
CC_SAFE_DELETE(ret);
25+
return nullptr;
26+
}
27+
};
28+

0 commit comments

Comments
 (0)