Skip to content

Commit 6221a1e

Browse files
committed
add featured toggle
1 parent 4981158 commit 6221a1e

6 files changed

Lines changed: 35 additions & 28 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ endif()
3535
add_subdirectory($ENV{GEODE_SDK} ${CMAKE_CURRENT_BINARY_DIR}/geode)
3636

3737
#CPMAddPackage("gh:FireMario211/dashauth#main")
38-
CPMAddPackage("gh:GlobedGD/argon@1.4.1")
38+
CPMAddPackage("gh:GlobedGD/argon@1.4.5")
3939
CPMAddPackage("gh:camila314/uibuilder#main") # i love it
4040
target_link_libraries(${PROJECT_NAME} argon UIBuilder)
4141

src/ui/ObjectWorkshop.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ bool ObjectWorkshop::init(bool authenticated) {
132132
"GJ_button_04.png",
133133
false
134134
).scale(.4f).intoMenuItem([this]() {
135-
FiltersPopup::create(g_availableTags, m_filterTags, m_user.role, currentMenuIndexGD == 7, [this](std::unordered_set<std::string> selectedTags, bool pending, bool reports) {
135+
FiltersPopup::create(g_availableTags, m_filterTags, m_selectedFeatured, m_user.role, currentMenuIndexGD == 7, [this](std::unordered_set<std::string> selectedTags, bool featured, bool pending, bool reports) {
136136
bool regenCate = false;
137137
int newID = 0;
138138
if (pending && currentMenuIndexGD != 7) {
@@ -146,6 +146,10 @@ bool ObjectWorkshop::init(bool authenticated) {
146146
m_filterTags = selectedTags;
147147
regenCate = true;
148148
}
149+
if (featured != m_selectedFeatured) {
150+
m_selectedFeatured = featured;
151+
regenCate = true;
152+
}
149153
if (regenCate || newID > 0) {
150154
if (newID > 0) {
151155
isSearching = false;
@@ -1012,15 +1016,16 @@ void ObjectWorkshop::load() {
10121016
}
10131017
} else {
10141018
if (m_filterTags.empty()) {
1015-
searchReq(fmt::format("{}/objects?page={}&category={}&limit={}", HOST_URL, m_currentPage, Utils::intToCategory(currentMenuIndexGD), RESULT_LIMIT));
1019+
searchReq(fmt::format("{}/objects?page={}&category={}&featured={}&limit={}", HOST_URL, m_currentPage, Utils::intToCategory(currentMenuIndexGD), m_selectedFeatured ? "true" : "false", RESULT_LIMIT));
10161020
} else {
10171021
searchReq(
10181022
fmt::format(
1019-
"{}/objects?page={}&category={}&tags={}&limit={}",
1023+
"{}/objects?page={}&category={}&tags={}&featured={}&limit={}",
10201024
HOST_URL,
10211025
m_currentPage,
10221026
Utils::intToCategory(currentMenuIndexGD),
10231027
Utils::url_encode(fmt::format("{}",fmt::join(m_filterTags, ","))),
1028+
m_selectedFeatured ? "true" : "false",
10241029
RESULT_LIMIT
10251030
)
10261031
);
@@ -1308,7 +1313,7 @@ void ObjectWorkshop::onPendingBtn(CCObject*) {
13081313
}
13091314

13101315
void ObjectWorkshop::onUploadFilterBtn(CCObject*) {
1311-
FiltersPopup::create(g_availableTags, m_filterTags, 0, true, [this](std::unordered_set<std::string> selectedTags, bool, bool) {
1316+
FiltersPopup::create(g_availableTags, m_filterTags, true, 0, true, [this](std::unordered_set<std::string> selectedTags, bool, bool, bool) {
13121317
m_filterTags = selectedTags;
13131318
})->show();
13141319
}

src/ui/ObjectWorkshop.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ class ObjectWorkshop : public geode::Popup, public TextInputDelegate {
158158
void onDownloadBtn(CCObject*);
159159

160160
std::unordered_set<std::string> m_filterTags;
161+
bool m_selectedFeatured;
161162
void onUpload(CCObject*);
162163
void onUploadFilterBtn(CCObject*);
163164
void onRulesBtn(CCObject*) {

src/ui/popups/EditPopup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ bool EditPopup::init(ObjectData obj, std::unordered_set<std::string> availableTa
4141
);
4242
filterSpr->setScale(0.75F);
4343
auto filterBtn = CCMenuItemExt::createSpriteExtra(filterSpr, [this](CCObject*) {
44-
FiltersPopup::create(m_availableTags, m_object.tags, 0, true, [this](std::unordered_set<std::string> selectedTags, bool, bool) {
44+
FiltersPopup::create(m_availableTags, m_object.tags, true, 0, true, [this](std::unordered_set<std::string> selectedTags, bool, bool, bool) {
4545
m_object.tags = selectedTags;
4646
})->show();
4747
});

src/ui/popups/FiltersPopup.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
#include "../../utils.hpp"
33

44
// TODO: add "Reports" and maybe a star icon to indicate featured?
5-
bool FiltersPopup::init(std::unordered_set<std::string> tags, std::unordered_set<std::string> selectedTags, int role, bool uploading, std::function<void(std::unordered_set<std::string>, bool, bool)> callback) {
5+
bool FiltersPopup::init(std::unordered_set<std::string> tags, std::unordered_set<std::string> selectedTags, bool selectedFeatured, int role, bool uploading, std::function<void(std::unordered_set<std::string>, bool, bool, bool)> callback) {
66
if (!Popup::init(350.f, 170.f)) return false;
77
m_callback = callback;
88
m_selectedTags = selectedTags;
99

10-
this->setTitle((uploading) ? "Set Tags" : "Search Filters");
10+
this->setTitle((uploading && role == 0) ? "Set Tags" : "Search Filters");
1111

1212
// loader/src/ui/mods/popups/FiltersPopup.cpp
1313
auto tagsContainer = CCNode::create();
@@ -39,15 +39,20 @@ bool FiltersPopup::init(std::unordered_set<std::string> tags, std::unordered_set
3939

4040
auto tagsTitle = CCLabelBMFont::create("Tags", "bigFont.fnt");
4141
tagsTitleMenu->addChild(tagsTitle);
42-
4342
tagsTitleMenu->addChild(SpacerNode::create());
44-
45-
auto resetSpr = CCSprite::createWithSpriteFrameName("GJ_trashBtn_001.png");
46-
auto resetBtn = CCMenuItemSpriteExtra::create(
47-
resetSpr, this, menu_selector(FiltersPopup::onResetBtn)
48-
);
49-
tagsTitleMenu->addChild(resetBtn);
50-
43+
if (!uploading) {
44+
Build<CCMenuItemToggler>::createToggle(
45+
Build<CCSprite>::createSpriteName("GJ_starsIcon_001.png").scale(1.25f).collect(),
46+
Build<CCSprite>::createSpriteName("GJ_starsIcon_gray_001.png").scale(1.25f).collect(),
47+
[this](CCMenuItemToggler* toggler){
48+
m_selectedFeatured = toggler->isOn();
49+
}
50+
).parent(tagsTitleMenu).toggle(!selectedFeatured);
51+
}
52+
Build<CCSprite>::createSpriteName("GJ_trashBtn_001.png").intoMenuItem([this]() {
53+
m_selectedTags.clear();
54+
this->updateTags();
55+
}).parent(tagsTitleMenu);
5156
tagsTitleMenu->setLayout(
5257
RowLayout::create()
5358
->setDefaultScaleLimits(.1f, .4f)
@@ -146,20 +151,16 @@ void FiltersPopup::onSelectTag(CCObject* sender) {
146151
}
147152
this->updateTags();
148153
}
149-
void FiltersPopup::onResetBtn(CCObject*) {
150-
m_selectedTags.clear();
151-
this->updateTags();
152-
}
153154

154155
void FiltersPopup::onClose(CCObject* sender) {
155156
if (m_pendingBtn) {
156157
if (m_reportsBtn) {
157-
m_callback(m_selectedTags, m_pendingBtn->isToggled(), m_reportsBtn->isToggled());
158+
m_callback(m_selectedTags, m_selectedFeatured, m_pendingBtn->isToggled(), m_reportsBtn->isToggled());
158159
} else {
159-
m_callback(m_selectedTags, m_pendingBtn->isToggled(), false);
160+
m_callback(m_selectedTags, m_selectedFeatured, m_pendingBtn->isToggled(), false);
160161
}
161162
} else {
162-
m_callback(m_selectedTags, false, false);
163+
m_callback(m_selectedTags, m_selectedFeatured, false, false);
163164
}
164165
Popup::onClose(sender);
165166
}

src/ui/popups/FiltersPopup.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ class FiltersPopup : public geode::Popup {
1010
CCMenuItemToggler* m_reportsBtn;
1111
CCMenu* m_tagsMenu;
1212
std::unordered_set<std::string> m_selectedTags;
13-
std::function<void(std::unordered_set<std::string>, bool, bool)> m_callback;
13+
bool m_selectedFeatured;
14+
std::function<void(std::unordered_set<std::string>, bool, bool, bool)> m_callback;
1415

15-
bool init(std::unordered_set<std::string> tags, std::unordered_set<std::string> selectedTags, int role, bool uploading, std::function<void(std::unordered_set<std::string>, bool, bool)> callback);
16-
void onResetBtn(CCObject*);
16+
bool init(std::unordered_set<std::string> tags, std::unordered_set<std::string> selectedTags, bool selectedFeatured, int role, bool uploading, std::function<void(std::unordered_set<std::string>, bool, bool, bool)> callback);
1717
void onSelectTag(CCObject*);
1818
void updateTags();
1919
virtual void onClose(CCObject* sender) override;
2020
public:
2121
static CCNode* createTags(std::unordered_set<std::string> tags, CCSize contentSize = {105, 27}, CCPoint anchorPoint = {0, 0.5}, AxisAlignment alignment = AxisAlignment::Start);
22-
static FiltersPopup* create(std::unordered_set<std::string> tags, std::unordered_set<std::string> selectedTags, int role, bool uploading, std::function<void(std::unordered_set<std::string>, bool, bool)> callback) {
22+
static FiltersPopup* create(std::unordered_set<std::string> tags, std::unordered_set<std::string> selectedTags, bool selectedFeatured, int role, bool uploading, std::function<void(std::unordered_set<std::string>, bool, bool, bool)> callback) {
2323
auto ret = new FiltersPopup();
24-
if (ret->init(tags, selectedTags, role, uploading, callback)) {
24+
if (ret->init(tags, selectedTags, selectedFeatured, role, uploading, callback)) {
2525
ret->autorelease();
2626
return ret;
2727
}

0 commit comments

Comments
 (0)