Skip to content

Commit

Permalink
Added contributor badge
Browse files Browse the repository at this point in the history
  • Loading branch information
Jouca committed Jul 9, 2024
1 parent a6d857a commit 33dd95b
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 19 deletions.
4 changes: 3 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Changelog
## <cj>v1.3.2</c> <cb>(2024-07-03)</c>
## <cj>v1.3.2</c> <cb>(2024-07-10)</c>
* <cg>Added</c> Mac Support
* <cg>Added</c> <cg>Monster</c>, Doom, <cj>Portal</c>, <cp>Strange</c>, <co>Fantasy</c>, <cy>Mystery</c>, <cg>Cursed</c>, <cy>World</c>, <co>Galaxy</c>, <cp>Universe</c> and <cp>Split</c> gauntlets particles
* <cg>Added</c> clicking notifications for new rates & daily chests
* <cg>Added</c> contributor badge

## <cj>v1.3.1</c> <cb>(2024-06-29)</c>
* <cg>Added</c> <cb>Discord</c> gauntlet design
Expand Down
Binary file added resources/contributorBadge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
123 changes: 106 additions & 17 deletions src/Utils/NewProfilePage.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include "NewProfilePage.h"
#include "../includes.h"
#include <Geode/modify/ProfilePage.hpp>
#include <Geode/utils/web.hpp>

static std::unordered_map<std::string, web::WebTask> RUNNING_REQUESTS {};
static std::mutex lock_var;

void NewProfilePage::onBadgePressed(CCObject* pSender) {
GJUserScore* score = static_cast<GJUserScore*>(static_cast<CCNode*>(pSender)->getUserObject());
Expand Down Expand Up @@ -124,7 +128,7 @@ There's currently <cp>no way</c> to become a <cb>Leaderboard Moderator</c> by ap
}
}

void NewProfilePage::onGDUtilsBadgePressed(CCObject* pSender) {
void NewProfilePage::onGDUtilsDevBadgePressed(CCObject* pSender) {
FLAlertLayer::create(
nullptr,
"GDUtils Developer",
Expand All @@ -135,7 +139,21 @@ You found a <co>GDUtils developer</c>! :O
nullptr,
250.0f
)->show();
}

void NewProfilePage::onGDUtilsContributorBadgePressed(CCObject* pSender) {
FLAlertLayer::create(
nullptr,
"GDUtils Contributor",
R"text(
<cg>GDUtils Contributor</c> is a user that has contributed to the <cl>GDUtils</c> project by <cy>writing code</c>, <cy>adding new features</c> on GitHub.
This badge is given to users that have contributed to the project by having merged <cy>pull requests</c> and have been recognized by the <cl>GDUtils</c> team.
)text",
"OK",
nullptr,
350.0f
)->show();
}

void NewProfilePage::onRobTopBadgePressed(CCObject* pSender) {
Expand All @@ -155,6 +173,91 @@ He is the <cy>only developer of the game</c> and is responsible for <cy>all the

// Mod badges descriptions & GDUtils dev badge
class $modify(ProfilePage) {
void requestGDUtilsBadges(int accountID, CCLayer* layer) {
const geode::utils::MiniFunction<void(std::string const&)> then = [this, accountID, layer](std::string const& result) {
std::vector<std::string> data_user = MoreLeaderboards::getWords(result, "|");

while (data_user.size() > 0) {
std::vector<std::string> data = MoreLeaderboards::getWords(data_user[0], "?");

int badge = 0;
int accountID_data = 0;

while (data.size() > 0) {
std::string id = data[0];
std::string name = data[1];

if (id == "1") {
accountID_data = std::stoi(name);
} else if (id == "3") {
badge = std::stoi(name);
}

data.erase(data.begin());
data.erase(data.begin());
}

if (accountID_data == accountID) {
if (badge == 1) {
if (!layer->getChildByIDRecursive("gdutils-contributor-badge")) {
CCMenu* username_menu = typeinfo_cast<CCMenu*>(layer->getChildByIDRecursive("username-menu"));

auto badgeGDUtil = CCSprite::create("contributorBadge.png"_spr);
badgeGDUtil->setScale(1.075f);
auto badgeGDUtilBtn = CCMenuItemSpriteExtra::create(
badgeGDUtil,
layer,
menu_selector(NewProfilePage::onGDUtilsContributorBadgePressed)
);

badgeGDUtilBtn->setID("gdutils-contributor-badge");
username_menu->addChild(badgeGDUtilBtn);
username_menu->updateLayout();
}
} else if (badge == 2) {
if (!layer->getChildByIDRecursive("gdutils-dev-badge")) {
CCMenu* username_menu = typeinfo_cast<CCMenu*>(layer->getChildByIDRecursive("username-menu"));

auto badgeGDUtil = CCSprite::create("gdutils_badge.png"_spr);
badgeGDUtil->setScale(.3f);
auto badgeGDUtilBtn = CCMenuItemSpriteExtra::create(
badgeGDUtil,
layer,
menu_selector(NewProfilePage::onGDUtilsDevBadgePressed)
);

badgeGDUtilBtn->setID("gdutils-dev-badge");
username_menu->addChild(badgeGDUtilBtn);
username_menu->updateLayout();
}
}
}

data_user.erase(data_user.begin());
}
};
const geode::utils::MiniFunction<void(std::string const&)> expect = [this](std::string const& error) {
log::error("Failed to get GDUtils badges: {}", error);
};

geode::utils::web::WebRequest request = web::WebRequest();
RUNNING_REQUESTS.emplace(
"@loaderGDUtilsBadgesGet",
request.get("https://clarifygdps.com/gdutils/gdutils_roles.php").map(
[expect = std::move(expect), then = std::move(then)](web::WebResponse* response) {
if (response->ok()) {
then(response->string().value());
} else {
expect("Request failed");
}

RUNNING_REQUESTS.erase("@loaderGDUtilsBadgesGet");
return *response;
}
)
);
}

void loadPageFromUserInfo(GJUserScore* a2) {
auto layer = m_mainLayer;
CCMenuItemSpriteExtra* badgeBtn = nullptr;
Expand Down Expand Up @@ -197,23 +300,9 @@ class $modify(ProfilePage) {
modbadge_bool = true;
}

std::vector<int> gdutils_accountID_devs = { 7026949, 6253758, 5509312 };
if (std::find(gdutils_accountID_devs.begin(), gdutils_accountID_devs.end(), a2->m_accountID) != gdutils_accountID_devs.end()) {
if (label != nullptr && !layer->getChildByIDRecursive("gdutils-badge")) {
auto badgeGDUtil = CCSprite::create("gdutils_badge.png"_spr);
badgeGDUtil->setScale(.3f);
badgeGDUtilBtn = CCMenuItemSpriteExtra::create(
badgeGDUtil,
this,
menu_selector(NewProfilePage::onGDUtilsBadgePressed)
);

badgeGDUtilBtn->setID("gdutils-badge");
username_menu->addChild(badgeGDUtilBtn);
}
}

if (username_menu != nullptr) username_menu->updateLayout();
}

requestGDUtilsBadges(a2->m_accountID, layer);
}
};
4 changes: 3 additions & 1 deletion src/Utils/NewProfilePage.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#pragma once
#include <iostream>
#include <Geode/Geode.hpp>
#include "../MoreLeaderboards/MoreLeaderboards.h"

using namespace geode::prelude;

class NewProfilePage : public CCLayer {
public:
void onBadgePressed(CCObject* pSender);
void onGDUtilsBadgePressed(CCObject* pSender);
void onGDUtilsDevBadgePressed(CCObject* pSender);
void onGDUtilsContributorBadgePressed(CCObject* pSender);
void onRobTopBadgePressed(CCObject* pSender);
};

0 comments on commit 33dd95b

Please sign in to comment.