Skip to content

Commit

Permalink
Added search user on More Leaderboards
Browse files Browse the repository at this point in the history
  • Loading branch information
Jouca committed Jun 20, 2024
1 parent affdfe2 commit 63b8267
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/BrownAlertDelegate.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "BrownAlertDelegate.hpp"

bool BrownAlertDelegate::init(float _w, float _h, const char* _spr, const char* _title) {
auto winSize = cocos2d::CCDirector::sharedDirector()->getWinSize();
auto director = cocos2d::CCDirector::sharedDirector();
auto winSize = director->getWinSize();
this->m_pLrSize = cocos2d::CCSize { _w, _h };

if (!this->initWithColor({ 0, 0, 0, 105 })) return false;
Expand Down Expand Up @@ -49,6 +50,9 @@ bool BrownAlertDelegate::init(float _w, float _h, const char* _spr, const char*
this->setKeypadEnabled(true);
this->setTouchEnabled(true);

m_mainLayer->setTouchPriority(director->getTouchDispatcher()->getTargetPrio());
director->getTouchDispatcher()->registerForcePrio(this, 2);

return true;
}

Expand Down
78 changes: 75 additions & 3 deletions src/MoreLeaderboards/MoreLeaderboards.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <Geode/ui/GeodeUI.hpp>

StatsListType MoreLeaderboards::g_tab = StatsListType::Stars;
std::string MoreLeaderboards::username = "";
int MoreLeaderboards::scroll_int = 0;
static int page = 0;
static int start_count = 0;
static int end_count = 0;
Expand Down Expand Up @@ -36,10 +38,10 @@ std::vector<std::string> MoreLeaderboards::getWords(std::string s, std::string d
class SearchUserLBLayer : public BrownAlertDelegate {
protected:
MoreLeaderboards* m_layer;
InputNode* input_username = InputNode::create(200.0F, "Username", "bigFont.fnt", "", 20);

virtual void setup() {
auto winSize = cocos2d::CCDirector::sharedDirector()->getWinSize();
InputNode* input_username = InputNode::create(200.0F, "Username", "bigFont.fnt", "", 20);
input_username->setPositionY(10);
this->m_buttonMenu->addChild(input_username);
auto validate_spr = ButtonSprite::create("Search", 60, true, "bigFont.fnt", "GJ_button_01.png", 30, .5F);
Expand All @@ -54,14 +56,33 @@ class SearchUserLBLayer : public BrownAlertDelegate {
-35
});
this->m_buttonMenu->addChild(validate_btn, 1);

if (MoreLeaderboards::username != "") {
input_username->setString(MoreLeaderboards::username);

auto delete_spr = CCSprite::createWithSpriteFrameName("GJ_deleteBtn_001.png");
delete_spr->setScale(.45f);
auto delete_btn = CCMenuItemSpriteExtra::create(
delete_spr,
this,
menu_selector(SearchUserLBLayer::onRemoveUsername)
);
delete_btn->setPosition({
113,
11
});
this->m_buttonMenu->addChild(delete_btn, 1);
}

this->m_mainLayer->addChild(this->m_buttonMenu);
setTouchEnabled(true);
this->setTouchEnabled(true);
}
cocos2d::CCSize m_sScrLayerSize;
void onClose(cocos2d::CCObject* pSender) {
BrownAlertDelegate::onClose(pSender);
}
void onValidate(cocos2d::CCObject*);
void onRemoveUsername(cocos2d::CCObject*);
float m_fWidth = s_defWidth;
float m_fHeight = s_defHeight;
public:
Expand All @@ -82,13 +103,26 @@ class SearchUserLBLayer : public BrownAlertDelegate {
void SearchUserLBLayer::onValidate(CCObject* pSender) {
if (this->m_layer->loading) return;

MoreLeaderboards::username = input_username->getString();

this->m_layer->changeTabPage();

this->m_layer->onTab(nullptr);

BrownAlertDelegate::onClose(pSender);
}

void SearchUserLBLayer::onRemoveUsername(CCObject* pSender) {
MoreLeaderboards::username = "";
MoreLeaderboards::scroll_int = 0;
input_username->setString("");

this->m_layer->changeTabPage();
this->m_layer->onTab(nullptr);

BrownAlertDelegate::onClose(pSender);
}

CCDictionary* MoreLeaderboards::responseToDict(const std::string& response){
auto dict = CCDictionary::create();
std::stringstream responseStream(response);
Expand Down Expand Up @@ -343,6 +377,8 @@ bool MoreLeaderboards::init(std::string type) {
void MoreLeaderboards::backButton(cocos2d::CCObject*) {
MoreLeaderboards::data_response_moreLB = "";
MoreLeaderboards::g_tab = StatsListType::Stars;
MoreLeaderboards::username = "";
MoreLeaderboards::scroll_int = 0;
cocos2d::CCDirector::sharedDirector()->popSceneWithTransition(0.5F, cocos2d::PopTransition::kPopTransitionFade);
};

Expand Down Expand Up @@ -546,6 +582,22 @@ void MoreLeaderboards::startLoadingMore() {
this->release();
return;
}
if (data == "-2" || data.length() < 2) {
fadeLoadingCircle();
FLAlertLayer::create(nullptr,
"Error",
"User not found : " + MoreLeaderboards::username,
"OK",
nullptr,
200.0F
)->show();

MoreLeaderboards::scroll_int = 0;
this->release();

loadTabPageButtons();
return;
}

handle_request_more(data);
fadeLoadingCircle();
Expand All @@ -556,7 +608,7 @@ void MoreLeaderboards::startLoadingMore() {

RUNNING_REQUESTS.emplace(
"@loaderMoreLeaderboardCheck",
request.param("type", type).param("page", page).param("country", country_id).get("https://clarifygdps.com/gdutils/moreleaderboards.php").map(
request.param("type", type).param("page", page).param("country", country_id).param("username", username).get("https://clarifygdps.com/gdutils/moreleaderboards.php").map(
[expect = std::move(expect), then = std::move(then)](web::WebResponse* response) {
if (response->ok()) {
then(response->string().value());
Expand Down Expand Up @@ -624,6 +676,11 @@ void MoreLeaderboards::handle_request_more(std::string const& data) {
total_count = std::stoi(page_test);
} else if (id == 3) {
page = std::stoi(page_test);
} else if (id == 4) {
log::debug("test {}", std::stoi(page_test));
if (std::stoi(page_test) != 0) {
MoreLeaderboards::scroll_int = std::stoi(page_test);
}
}

id++;
Expand All @@ -645,6 +702,12 @@ void MoreLeaderboards::loadPageMore() {
listLayer->setPosition(winSize / 2 - listLayer->getScaledContentSize() / 2 - CCPoint(0,5));

addChild(listLayer);

if (MoreLeaderboards::scroll_int != 0) {
log::debug("scrolling by {}", MoreLeaderboards::scroll_int);
listLayer->m_listView->m_tableView->scrollLayer(-99999999);
listLayer->m_listView->m_tableView->scrollLayer(MoreLeaderboards::scroll_int);
}
}

void MoreLeaderboards::onSearch(CCObject*) {
Expand Down Expand Up @@ -775,6 +838,9 @@ void MoreLeaderboards::onTabPageRight(CCObject* pSender) {
}

void MoreLeaderboards::changeTabPage() {
if (m_search != nullptr) m_search->removeFromParentAndCleanup(true);
m_search = nullptr;

if (m_tab1 != nullptr) m_tab1->removeFromParentAndCleanup(true);
if (m_tab2 != nullptr) m_tab2->removeFromParentAndCleanup(true);
if (m_tab3 != nullptr) m_tab3->removeFromParentAndCleanup(true);
Expand Down Expand Up @@ -973,6 +1039,9 @@ void MoreLeaderboards::changeTabPage() {
void MoreLeaderboards::onPageLeft(CCObject* pSender) {
if (loading) return;

MoreLeaderboards::username = "";
MoreLeaderboards::scroll_int = 0;

loading = true;

loading_circle = LoadingCircle::create();
Expand All @@ -998,6 +1067,9 @@ void MoreLeaderboards::onPageLeft(CCObject* pSender) {
void MoreLeaderboards::onPageRight(CCObject* pSender) {
if (loading) return;

MoreLeaderboards::username = "";
MoreLeaderboards::scroll_int = 0;

loading = true;

loading_circle = LoadingCircle::create();
Expand Down
4 changes: 3 additions & 1 deletion src/MoreLeaderboards/MoreLeaderboards.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class MoreLeaderboards : public CCLayer {
CCMenuItemToggler* m_tab6;
int tab_page = 0;

CCMenuItemSpriteExtra* m_search = nullptr;
CCMenuItemSpriteExtra* m_search;

#ifndef GEODE_IS_IOS
CCClippingNode* m_tabsGradientNode = nullptr;
Expand All @@ -79,6 +79,8 @@ class MoreLeaderboards : public CCLayer {
public:
static std::string data_response_moreLB;
static StatsListType g_tab;
static std::string username;
static int scroll_int;
bool loading = false;

void onMoreLeaderboards(CCObject*);
Expand Down

0 comments on commit 63b8267

Please sign in to comment.