Skip to content

Commit

Permalink
enable view leaderboard as on mac
Browse files Browse the repository at this point in the history
  • Loading branch information
Cvolton committed Sep 9, 2023
1 parent 8fac185 commit 44faff6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 61 deletions.
2 changes: 1 addition & 1 deletion mod.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"geode": "1.1.1",
"geode": "1.3.0",
"version": "v3.0.3",
"id": "cvolton.betterinfo",
"name": "BetterInfo",
Expand Down
52 changes: 24 additions & 28 deletions src/hooks/ProfilePage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,37 +144,33 @@ class $modify(BIProfilePage, ProfilePage) {
if(a2->m_userID != GameManager::sharedState()->m_playerUserID){
for(unsigned int i = 0; i < layer->getChildrenCount(); i++){
CCNode* node = dynamic_cast<CCNode*>(layer->getChildren()->objectAtIndex(i));
#ifndef GEODE_IS_MACOS
if(node != nullptr && node->getPositionX() == (winSize.width / 2) - 164 && node->getPositionY() == (winSize.height / 2) + 123) node->setVisible(false);
#endif
if(node != nullptr && node->getPositionX() == (winSize.width / 2) - 164 && node->getPositionY() == (winSize.height / 2) + 123) node->setVisible(false);
if(node != nullptr && node->getPositionX() == (winSize.width / 2) && node->getPositionY() == (winSize.height / 2) + 125) node->setVisible(false);
}

#ifndef GEODE_IS_MACOS
auto leaderboardButtonSprite = BetterInfo::createBISprite("BI_blankBtn_001.png");
auto leaderboardSprite = CCSprite::createWithSpriteFrameName(BetterInfo::rankIcon(a2->m_globalRank));
leaderboardSprite->setZOrder(1);
leaderboardSprite->setScale(1 / 0.6f);
if(a2->m_globalRank > 0) {
if(a2->m_globalRank <= 10) leaderboardSprite->setScale(1.1f);
else if(a2->m_globalRank <= 50) leaderboardSprite->setScale(1.25f);
else if(a2->m_globalRank <= 200) leaderboardSprite->setScale(1.3f);
else if(a2->m_globalRank <= 1000) leaderboardSprite->setScale(1 / 0.7f);
}
leaderboardSprite->setPosition({22.5f, 23});
leaderboardButtonSprite->addChild(leaderboardSprite);
leaderboardButtonSprite->setScale( (a2->m_globalRank <= 1000 && a2->m_globalRank > 0) ? 0.7f : 0.6f);
auto leaderboardButton = CCMenuItemSpriteExtra::create(
leaderboardButtonSprite,
this,
menu_selector(BIProfilePage::onProfilePageLeaderboard)
);
leaderboardButton->setID("bi-leaderboard-button");
menu->addChild(leaderboardButton);
leaderboardButton->setPosition({46, -12});
leaderboardButton->setSizeMult(1.2f);
this->m_buttons->addObject(leaderboardButton);
#endif
auto leaderboardButtonSprite = BetterInfo::createBISprite("BI_blankBtn_001.png");
auto leaderboardSprite = CCSprite::createWithSpriteFrameName(BetterInfo::rankIcon(a2->m_globalRank));
leaderboardSprite->setZOrder(1);
leaderboardSprite->setScale(1 / 0.6f);
if(a2->m_globalRank > 0) {
if(a2->m_globalRank <= 10) leaderboardSprite->setScale(1.1f);
else if(a2->m_globalRank <= 50) leaderboardSprite->setScale(1.25f);
else if(a2->m_globalRank <= 200) leaderboardSprite->setScale(1.3f);
else if(a2->m_globalRank <= 1000) leaderboardSprite->setScale(1 / 0.7f);
}
leaderboardSprite->setPosition({22.5f, 23});
leaderboardButtonSprite->addChild(leaderboardSprite);
leaderboardButtonSprite->setScale( (a2->m_globalRank <= 1000 && a2->m_globalRank > 0) ? 0.7f : 0.6f);
auto leaderboardButton = CCMenuItemSpriteExtra::create(
leaderboardButtonSprite,
this,
menu_selector(BIProfilePage::onProfilePageLeaderboard)
);
leaderboardButton->setID("bi-leaderboard-button");
menu->addChild(leaderboardButton);
leaderboardButton->setPosition({46, -12});
leaderboardButton->setSizeMult(1.2f);
this->m_buttons->addObject(leaderboardButton);

auto refreshSprite = CCSprite::createWithSpriteFrameName("GJ_updateBtn_001.png");
auto refreshButton = CCMenuItemSpriteExtra::create(
Expand Down
42 changes: 11 additions & 31 deletions src/managers/BetterInfoOnline.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "BetterInfoOnline.h"
#include "../utils.hpp"
#include <Geode/utils/web.hpp>

bool BetterInfoOnline::init(){
return true;
Expand All @@ -25,37 +26,16 @@ void BetterInfoOnline::loadScores(int accountID, bool force){
return;
}

#ifndef GEODE_IS_MACOS
//only on forced reload or if we dont have cached
CCHttpRequest* request = new CCHttpRequest;
request->setUrl("http://www.boomlings.com/database/getGJScores20.php");
request->setRequestType(CCHttpRequest::HttpRequestType::kHttpPost);
request->setResponseCallback(this, httpresponse_selector(BetterInfoOnline::onScoresFinished));
//TODO: make this slightly more dynamic
auto postData = CCString::createWithFormat("gameVersion=21&binaryVersion=35&gdw=0&accountID=%i&type=relative&secret=Wmfd2893gb7", accountID);
request->setRequestData(
postData->getCString(), strlen(postData->getCString())
);
auto ccInt = CCInteger::create(accountID);
ccInt->retain();
request->setUserData(ccInt);
CCHttpClient::getInstance()->send(request);
//request->release();
#endif
}

void BetterInfoOnline::onScoresFinished(CCHttpClient* client, CCHttpResponse* response){
if(!(response->isSucceed())) return;

gd::vector<char>* responseData = response->getResponseData();
std::string responseString(responseData->begin(), responseData->end());

auto ccInt = (CCInteger*) (response->getHttpRequest()->getUserData());
int accountID = ccInt->getValue();
ccInt->release();
generateScores(responseString, accountID);

sendScores(m_scoreDict[accountID], accountID);
web::AsyncWebRequest()
.userAgent("")
.postRequest()
.postFields(fmt::format("gameVersion=21&binaryVersion=35&gdw=0&accountID={}&type=relative&secret=Wmfd2893gb7", accountID))
.fetch("http://www.boomlings.com/database/getGJScores20.php")
.text()
.then([this, accountID](const std::string& response) {
generateScores(response, accountID);
sendScores(m_scoreDict[accountID], accountID);
});
}

void BetterInfoOnline::generateScores(const std::string& response, int accountID){
Expand Down
1 change: 0 additions & 1 deletion src/managers/BetterInfoOnline.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class BetterInfoOnline : public cocos2d::CCObject {
void loadScores(int accountID, bool force);
void loadScores(int accountID, bool force, BILeaderboardDelegate* delegate);
void loadScores(int accountID, bool force, ProfilePage* profilePage);
void onScoresFinished(cocos2d::extension::CCHttpClient* client, cocos2d::extension::CCHttpResponse* response);
void generateScores(const std::string& response, int accountID);
void sendScores(cocos2d::CCArray* scores, int accountID);
void sendScoreToProfilePage(cocos2d::CCArray* scores, int accountID);
Expand Down

0 comments on commit 44faff6

Please sign in to comment.