Skip to content

Commit 8670152

Browse files
committed
final touches (todo: onEnter for touch prio)
1 parent d6ccfd7 commit 8670152

7 files changed

Lines changed: 87 additions & 52 deletions

File tree

src/nodes/ScrollLayerExt.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,15 @@ ScrollLayerExt* ScrollLayerExt::create(CCSize const& size, bool scroll, bool ver
213213
return ScrollLayerExt::create({ 0, 0, size.width, size.height }, scroll, vertical);
214214
}
215215

216+
static int less(const CCObject* p1, const CCObject* p2)
217+
{
218+
return ((CCTouchHandler*)p1)->getPriority() < ((CCTouchHandler*)p2)->getPriority();
219+
}
220+
static void rearrangeHandlers(CCArray *pArray)
221+
{
222+
std::sort(pArray->data->arr, pArray->data->arr + pArray->data->num, less);
223+
}
224+
216225
void ScrollLayerExt::fixTouchPrio() {
217226
auto oldThis = this;
218227
//this->retain();
@@ -221,7 +230,16 @@ void ScrollLayerExt::fixTouchPrio() {
221230
Loader::get()->queueInMainThread([this, handler, delegate, oldThis]() {
222231
if (oldThis != nullptr && handler != nullptr && delegate != nullptr) {
223232
if (auto dispatcher = CCTouchDispatcher::get()) {
224-
dispatcher->setPriority(handler->m_nPriority - 2, delegate);
233+
//dispatcher->setPriority(handler->m_nPriority - 2, delegate);
234+
int nPriority = handler->m_nPriority - 2;
235+
auto handler = dispatcher->findHandler(delegate);
236+
if (!handler) return;
237+
auto currPrio = handler->getPriority();
238+
if (currPrio != nPriority) {
239+
handler->setPriority(nPriority);
240+
rearrangeHandlers(dispatcher->m_pTargetedHandlers);
241+
rearrangeHandlers(dispatcher->m_pStandardHandlers);
242+
}
225243
}
226244
}
227245
});

src/ui/ObjectWorkshop.cpp

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ bool ObjectWorkshop::init(bool authenticated) {
7272

7373
Build<CCSprite>::createSpriteName("GJ_profileButton_001.png").scale(0.7f).intoMenuItem([this]() {
7474
if (!m_user.authenticated) return FLAlertLayer::create("Error", "You cannot view your profile as you are <cy>not authenticated!</c>", "OK")->show();
75-
onClickUser(m_user.account_id);
75+
onClickUser(-1);
7676
}).parentAtPos(m_buttonMenu, (m_leftSide) ? Anchor::TopLeft : Anchor::TopRight, {(m_leftSide) ? 23.f : -27.f, -26});
7777

7878
if (authenticated) {
@@ -85,7 +85,7 @@ bool ObjectWorkshop::init(bool authenticated) {
8585
).store(m_categoryButtonsTop).parentAtPos(m_buttonMenu, (m_leftSide) ? Anchor::TopLeft : Anchor::TopRight, {(m_leftSide) ? 24.f : -27.f, -45});
8686
createCategoryBtn("GJ_downloadBtn_001.png", true, 10, true); // [My Recently Downloaded Objects] [10]
8787
createCategoryBtn("gj_heartOn_001.png", true, 1, true); // [My Favorited Objects] [1]
88-
createCategoryBtn("rankIcon_1_001.png", true, 9, true); // [Leaderboard] (Creator Points, Downloads, etc) [??]
88+
createCategoryBtn("rankIcon_1_001.png", true, 900, true); // [Leaderboard] (Creator Points, Downloads, etc) [??]
8989
}
9090

9191
Build<CCMenu>::create().anchorPoint({0.5, 1}).contentSize({30, 135}).layout(
@@ -120,8 +120,10 @@ bool ObjectWorkshop::init(bool authenticated) {
120120
if (auto item = typeinfo_cast<CCMenuItemSpriteExtra*>(m_categoryButtons->getChildByID(fmt::format("category-{}"_spr, currentMenuIndexGD)))) {
121121
static_cast<CategoryButton*>(item->getChildren()->objectAtIndex(0))->setIndicatorState(true);
122122
}
123-
if (auto item = typeinfo_cast<CCMenuItemSpriteExtra*>(m_categoryButtonsTop->getChildByID(fmt::format("category-{}"_spr, currentMenuIndexGD)))) {
124-
static_cast<CategoryButton*>(item->getChildren()->objectAtIndex(0))->setIndicatorState(true);
123+
if (m_categoryButtonsTop) {
124+
if (auto item = typeinfo_cast<CCMenuItemSpriteExtra*>(m_categoryButtonsTop->getChildByID(fmt::format("category-{}"_spr, currentMenuIndexGD)))) {
125+
static_cast<CategoryButton*>(item->getChildren()->objectAtIndex(0))->setIndicatorState(true);
126+
}
125127
}
126128
Build<ButtonSprite>::create(
127129
CCSprite::createWithSpriteFrameName("GJ_filterIcon_001.png"),
@@ -156,14 +158,18 @@ bool ObjectWorkshop::init(bool authenticated) {
156158
isSearching = false;
157159
onBackBtn(nullptr);
158160
if (newID != currentMenuIndexGD) {
159-
if (auto oldItem = typeinfo_cast<CCMenuItemSpriteExtra*>(m_categoryButtonsTop->getChildByID(fmt::format("category-{}"_spr, currentMenuIndexGD)))) {
160-
static_cast<CategoryButton*>(oldItem->getChildren()->objectAtIndex(0))->setIndicatorState(false);
161+
if (m_categoryButtonsTop) {
162+
if (auto oldItem = typeinfo_cast<CCMenuItemSpriteExtra*>(m_categoryButtonsTop->getChildByID(fmt::format("category-{}"_spr, currentMenuIndexGD)))) {
163+
static_cast<CategoryButton*>(oldItem->getChildren()->objectAtIndex(0))->setIndicatorState(false);
164+
}
161165
}
162166
if (auto oldItem = typeinfo_cast<CCMenuItemSpriteExtra*>(m_categoryButtons->getChildByID(fmt::format("category-{}"_spr, currentMenuIndexGD)))) {
163167
static_cast<CategoryButton*>(oldItem->getChildren()->objectAtIndex(0))->setIndicatorState(false);
164168
}
165-
if (auto newItem = typeinfo_cast<CCMenuItemSpriteExtra*>(m_categoryButtonsTop->getChildByID(fmt::format("category-{}"_spr, newID)))) {
166-
static_cast<CategoryButton*>(newItem->getChildren()->objectAtIndex(0))->setIndicatorState(true);
169+
if (m_categoryButtonsTop) {
170+
if (auto newItem = typeinfo_cast<CCMenuItemSpriteExtra*>(m_categoryButtonsTop->getChildByID(fmt::format("category-{}"_spr, newID)))) {
171+
static_cast<CategoryButton*>(newItem->getChildren()->objectAtIndex(0))->setIndicatorState(true);
172+
}
167173
}
168174
currentMenuIndexGD = newID;
169175
}
@@ -335,17 +341,25 @@ bool ObjectWorkshop::init(bool authenticated) {
335341

336342
void ObjectWorkshop::onSideButton(CCObject* pSender) {
337343
isSearching = false;
338-
m_currentPage = 1;
339-
m_pageInput->setString("1");
340-
onBackBtn(pSender);
341344
auto item = static_cast<CCMenuItemSpriteExtra*>(pSender);
342345
auto idStr = item->getID().view();
343346
//idStr.remove_prefix(idStr.length() - 1);
344347
idStr.remove_prefix(fmt::format("category-"_spr).length());
345-
int id = numFromString<int>(idStr).unwrapOrDefault();;
348+
int id = numFromString<int>(idStr).unwrapOrDefault();
349+
350+
if (id == 900) {
351+
FLAlertLayer::create("Coming soon!", "<cy>Leaderboards</c> are not currently implemented yet!", "OK")->show();
352+
return;
353+
}
354+
355+
m_currentPage = 1;
356+
m_pageInput->setString("1");
357+
onBackBtn(pSender);
346358
if (id != currentMenuIndexGD) {
347-
if (auto oldItem = typeinfo_cast<CCMenuItemSpriteExtra*>(m_categoryButtonsTop->getChildByID(fmt::format("category-{}"_spr, currentMenuIndexGD)))) {
348-
static_cast<CategoryButton*>(oldItem->getChildren()->objectAtIndex(0))->setIndicatorState(false);
359+
if (m_categoryButtonsTop) {
360+
if (auto oldItem = typeinfo_cast<CCMenuItemSpriteExtra*>(m_categoryButtonsTop->getChildByID(fmt::format("category-{}"_spr, currentMenuIndexGD)))) {
361+
static_cast<CategoryButton*>(oldItem->getChildren()->objectAtIndex(0))->setIndicatorState(false);
362+
}
349363
}
350364
if (auto oldItem = typeinfo_cast<CCMenuItemSpriteExtra*>(m_categoryButtons->getChildByID(fmt::format("category-{}"_spr, currentMenuIndexGD)))) {
351365
static_cast<CategoryButton*>(oldItem->getChildren()->objectAtIndex(0))->setIndicatorState(false);
@@ -593,7 +607,7 @@ void ObjectWorkshop::handleRequest1(web::WebResponse value) {
593607
}
594608
m_scrollLayer->setTouchEnabled(true);
595609
m_amountItems = array.size();
596-
if ((currentMenuIndexGD != 0 && currentMenuIndexGD != -1)) {
610+
if ((currentMenuIndexGD != 0 || (currentMenuIndexGD == -1 && m_currentUserID == -1))) {
597611
if (m_amountItems > 6) {
598612
categoryItems->setContentSize({
599613
categoryItems->getContentWidth(),
@@ -658,7 +672,7 @@ void ObjectWorkshop::handleRequest1(web::WebResponse value) {
658672
this->handleRequest2(std::move(res));
659673
}
660674
);
661-
} else if (currentMenuIndexGD == -1) {
675+
} else if (currentMenuIndexGD == -1 && m_currentUserID != -1) {
662676
auto o_user = jsonRes.get("user");
663677
UserData user;
664678
myUploadsMenu->removeAllChildrenWithCleanup(true);
@@ -954,7 +968,7 @@ void ObjectWorkshop::load() {
954968
auto searchReq = [this](std::string url, bool get = true) {
955969
web::WebRequest request = web::WebRequest();
956970
request.userAgent(USER_AGENT);
957-
if (currentMenuIndexGD != -1 && !get) {
971+
if (!get) {
958972
auto myjson = matjson::Value();
959973
myjson.set("token", m_token);
960974
request.header("Content-Type", "application/json");
@@ -1012,7 +1026,11 @@ void ObjectWorkshop::load() {
10121026
} else if (currentMenuIndexGD == 8) { // reports
10131027
searchReq(fmt::format("{}/objects/reports?page={}", HOST_URL, m_currentPage), false);
10141028
} else if (currentMenuIndexGD == -1) { // a user
1015-
searchReq(fmt::format("{}/user/{}?page={}", HOST_URL, m_currentUserID, m_currentPage));
1029+
if (m_currentUserID == -1) {
1030+
searchReq(fmt::format("{}/user/@me/objects?page={}&limit=false", HOST_URL, m_currentPage), false);
1031+
} else {
1032+
searchReq(fmt::format("{}/user/{}?page={}", HOST_URL, m_currentUserID, m_currentPage));
1033+
}
10161034
}
10171035
} else {
10181036
FLAlertLayer::create("Error", "You aren't <cy>authenticated!</c>", "OK")->show();
@@ -1044,7 +1062,7 @@ void ObjectWorkshop::createCategoryBtn(const char* string, bool isSpriteFrame, i
10441062
menu_selector(ObjectWorkshop::onSideButton)
10451063
);
10461064
btn->setID(fmt::format("category-{}"_spr, menuIndex));
1047-
if (top) {
1065+
if (top && m_categoryButtonsTop) {
10481066
m_categoryButtonsTop->addChild(btn);
10491067
m_categoryButtonsTop->updateLayout();
10501068
} else {
@@ -1055,8 +1073,10 @@ void ObjectWorkshop::createCategoryBtn(const char* string, bool isSpriteFrame, i
10551073
}
10561074

10571075
void ObjectWorkshop::onClickUser(int accountID) {
1058-
if (auto oldItem = typeinfo_cast<CCMenuItemSpriteExtra*>(m_categoryButtonsTop->getChildByID(fmt::format("category-{}"_spr, currentMenuIndexGD)))) {
1059-
static_cast<CategoryButton*>(oldItem->getChildren()->objectAtIndex(0))->setIndicatorState(false);
1076+
if (m_categoryButtonsTop) {
1077+
if (auto oldItem = typeinfo_cast<CCMenuItemSpriteExtra*>(m_categoryButtonsTop->getChildByID(fmt::format("category-{}"_spr, currentMenuIndexGD)))) {
1078+
static_cast<CategoryButton*>(oldItem->getChildren()->objectAtIndex(0))->setIndicatorState(false);
1079+
}
10601080
}
10611081
if (auto oldItem = typeinfo_cast<CCMenuItemSpriteExtra*>(m_categoryButtons->getChildByID(fmt::format("category-{}"_spr, currentMenuIndexGD)))) {
10621082
static_cast<CategoryButton*>(oldItem->getChildren()->objectAtIndex(0))->setIndicatorState(false);

src/ui/auth/AuthMenu.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ void AuthMenu::onDashAuth(CCObject*) {
7272
true
7373
);
7474
#else
75-
FLAlertLayer::create("Error", "Unfortunately, RobTop's servers <cr>IP banned my server</c>, meaning this method <cr>is not available</c>.", "OK")->show();
75+
//FLAlertLayer::create("Error", "Unfortunately, RobTop's servers <cr>IP banned my server</c>, meaning this method <cr>is not available</c>.", "OK")->show();
76+
FLAlertLayer::create("Error", "Unfortunately, this method <cr>is not available</c> because I have not ported it to 2.208 yet, please use Argon instead.", "OK")->show();
7677
#endif
7778
}
7879

src/ui/popups/ObjUploadPopup.cpp

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "../../utils.hpp"
44
#include "FiltersPopup.hpp"
55
#include "Geode/ui/Popup.hpp"
6+
#include "../auth/AuthLoadLayer.hpp"
67

78
extern std::unordered_set<std::string> g_availableTags;
89

@@ -226,12 +227,14 @@ bool ObjUploadPopup::init(UserData user) {
226227
}
227228

228229
void ObjUploadPopup::showUpload() {
229-
auto popup = UploadActionPopup::create(this, "Uploading...");
230-
popup->show();
231-
if (m_previewBG->getData().empty() || m_objName == nullptr || m_objDesc == nullptr) return popup->showFailMessage("something must have gone very wrong\nfor this to happen.");
232-
if (m_filterTags.size() == 0) return popup->showFailMessage("You must <cy>set a tag</c>!\nClick on the grey filter button!");
233-
if (m_filterTags.size() > 5) return popup->showFailMessage("You cannot set more than <cy>5 tags</c>!");
234-
if (m_objName != nullptr && m_objName->getString().empty()) return popup->showFailMessage("You must enter an\n<cy>object name</c>!");
230+
//auto popup = UploadActionPopup::create(this, "Uploading...");
231+
//popup->show();
232+
if (m_previewBG->getData().empty() || m_objName == nullptr || m_objDesc == nullptr) return FLAlertLayer::create("Error", "something must have gone very wrong\nfor this to happen.", "OK")->show();
233+
if (m_filterTags.size() == 0) return FLAlertLayer::create("Error", "You must <cy>set a tag</c>!\nClick on the grey filter button!", "OK")->show();
234+
if (m_filterTags.size() > 5) return FLAlertLayer::create("Error", "You cannot set more than <cy>5 tags</c>!", "OK")->show();
235+
if (m_objName != nullptr && m_objName->getString().empty()) return FLAlertLayer::create("Error", "You must enter an\n<cy>object name</c>!", "OK")->show();
236+
auto loadLayer = AuthLoadLayer::create();
237+
loadLayer->show();
235238
ObjectData obj = {
236239
0,
237240
m_objName->getString(),
@@ -262,28 +265,23 @@ void ObjUploadPopup::showUpload() {
262265
req.bodyJSON(myjson);
263266
m_listener.spawn(
264267
req.post(fmt::format("{}/objects/upload", HOST_URL)),
265-
[this, popup](web::WebResponse value) {
266-
if (popup) {
267-
popup->m_delegate = nullptr;
268-
if (popup->getParent()) {
269-
popup->closePopup();
270-
}
271-
}
268+
[this, loadLayer](web::WebResponse value) {
269+
loadLayer->finished();
272270
std::string errContent;
273271
auto jsonRes = value.json().unwrapOrDefault();
274272
if (!jsonRes.isObject()) {
275-
geode::log::error("Response isn't object.");
273+
geode::log::error("Response isn't object. Got this instead: {}", jsonRes.dump());
276274
errContent = "An unknown error occured.";
277275
}
278276
auto isError = jsonRes.get("error");
279277
if (isError.isOk()) {
280278
errContent = isError.unwrap().asString().unwrapOrDefault();
281-
}
282-
if (!value.ok()) {
279+
} else if (!value.ok()) {
283280
errContent = "An unknown error occured.";
284281
}
285-
if (errContent.empty()) {
282+
if (!errContent.empty()) {
286283
FLAlertLayer::create("Error", errContent.c_str(), "OK")->show();
284+
m_buttonMenu->setEnabled(true);
287285
} else {
288286
geode::createQuickPopup("Success!", "Your object is now <cy>pending for review</c>! You can view your pending objects by tapping on your profile icon.", "OK", nullptr, [this](FLAlertLayer *, bool) {
289287
this->onClose(nullptr);

src/ui/popups/ObjUploadPopup.hpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <Geode/ui/Popup.hpp>
33
using namespace geode::prelude;
44
#include "../ObjectWorkshop.hpp"
5-
class ObjUploadPopup : public geode::Popup, public UploadPopupDelegate {
5+
class ObjUploadPopup : public geode::Popup {
66
protected:
77
std::string m_token;
88
async::TaskHolder<geode::utils::web::WebResponse> m_listener;
@@ -36,15 +36,6 @@ class ObjUploadPopup : public geode::Popup, public UploadPopupDelegate {
3636
void onSelectPickPage(CCObject*);
3737
void onObjectDetailsPage(CCObject*);
3838

39-
void onClosePopup(UploadActionPopup* popup) override {
40-
m_listener.cancel();
41-
if (popup) {
42-
popup->m_delegate = nullptr;
43-
if (popup->getParent()) {
44-
popup->closePopup();
45-
}
46-
}
47-
}
4839
public:
4940
static ObjUploadPopup* create(UserData user) {
5041
auto ret = new ObjUploadPopup();

src/ui/popups/ObjectPopup.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ bool ObjectPopup::init(ObjectData objectData, UserData user) {
134134
}).parent(menu);
135135
}
136136
}
137+
if (m_user.account_id == objectData.authorAccId) {
138+
if (m_object.status == ObjectStatus::PENDING_DELETION) {
139+
Build<CCSprite>::createSpriteName("GJ_reportBtn_001.png").scale(0.5f).color(0,255,0).intoMenuItem([this]() {
140+
ReportPopup::create(m_object, ReportActionType::Appeal)->show();
141+
}).parent(menu);
142+
}
143+
}
137144
}).parentAtPos(node, Anchor::Center).updateLayout();
138145
}).parentAtPos(m_mainLayer, Anchor::Left, {17, 40});
139146

src/ui/popups/ReportPopup.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ bool ReportPopup::init(ObjectData obj, ReportActionType type) {
9393
m_reportInput->setMaxCharCount(500);
9494
}
9595
m_reportInput->setCommonFilter(CommonFilter::Any);
96-
m_reportInput->setVisible(false);
96+
m_reportInput->setVisible(type == ReportActionType::Appeal);
9797
m_mainLayer->addChildAtPosition(m_reportInput, Anchor::Center, {0, 20});
9898

9999
std::string btnTitle = "Report";
@@ -157,7 +157,7 @@ void ReportPopup::onReportBtn(CCObject*) {
157157
} else {
158158
std::string desc = "Are you sure you want to <cy>report this object</c>?\n\nPlease make sure this object <cr>violates the guidelines</c> before reporting. Any misuse of this button will result in <cr>a ban</c>";
159159
if (m_type != ReportActionType::Report) {
160-
desc = "Are you sure you want to <cg>appeal this object</c>?\n\nYou will receive a punishment if the object still violates guidelines if you submit an appeal."
160+
desc = "Are you sure you want to <cg>appeal this object</c>?\n\nYou will receive a punishment if the object still violates guidelines if you submit an appeal.";
161161
}
162162
geode::createQuickPopup(
163163
"Warning",

0 commit comments

Comments
 (0)