Skip to content

Commit

Permalink
2.207
Browse files Browse the repository at this point in the history
hiimjasmine00 committed Nov 15, 2024
1 parent c0d1e5d commit eb15557
Showing 13 changed files with 117 additions and 110 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -36,8 +36,6 @@ jobs:
- name: Build the mod
uses: geode-sdk/build-geode-mod@main
with:
bindings: hiimjustin000/bindings
bindings-ref: ccdictionary
build-config: ${{ matrix.config.build-config || 'Release' }}
export-pdb: true
combine: true
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -4,10 +4,11 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64")
set(CMAKE_CXX_VISIBILITY_PRESET hidden)

project(MoreIcons VERSION 1.4.5)
project(MoreIcons VERSION 1.4.6)

add_library(${PROJECT_NAME} SHARED
src/api/MoreIconsAPI.cpp
src/classes/ButtonHooker.cpp
src/classes/LogCell.cpp
src/classes/LogLayer.cpp
src/hooks/AppDelegate.cpp
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# More Icons Changelog
## v1.4.6-beta.1 (2024-11-13)
- Ported to Geometry Dash v2.207

## v1.4.5 (2024-11-04)
- Fixed potential blending issues with robots and spiders

10 changes: 5 additions & 5 deletions mod.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"geode": "3.9.0",
"geode": "4.0.0-alpha.1",
"gd": {
"android": "2.206",
"win": "2.206",
"mac": "2.206"
"android": "2.2074",
"win": "2.2074",
"mac": "2.2074"
},
"version": "v1.4.5",
"version": "v1.4.6-beta.1",
"id": "hiimjustin000.more_icons",
"name": "More Icons",
"developer": "hiimjustin000",
39 changes: 18 additions & 21 deletions src/MoreIcons.cpp
Original file line number Diff line number Diff line change
@@ -200,17 +200,16 @@ void MoreIcons::loadIcons(const std::vector<std::filesystem::path>& packs, const
std::ifstream file(packJSON);
std::stringstream bufferStream;
bufferStream << file.rdbuf();
std::string error;
auto tryJson = matjson::parse(bufferStream.str(), error);
auto tryJson = matjson::parse(bufferStream.str());
auto packFileName = rootPackPath.filename().string();
if (!error.empty()) {
if (!tryJson.isOk()) {
packName = packFileName;
packID = packFileName;
}
auto json = tryJson.value_or(matjson::Object());
if (json.contains("name") && json["name"].is_string()) packName = json["name"].as_string();
auto json = tryJson.unwrapOr(matjson::Value());
if (json.contains("name") && json["name"].isString()) packName = json["name"].asString().unwrap();
else packName = packFileName;
if (json.contains("id") && json["id"].is_string()) packID = json["id"].as_string();
if (json.contains("id") && json["id"].isString()) packID = json["id"].asString().unwrap();
else packID = packFileName;
}
}
@@ -439,17 +438,16 @@ void MoreIcons::loadTrails(const std::vector<std::filesystem::path>& packs) {
std::ifstream file(packJSON);
std::stringstream bufferStream;
bufferStream << file.rdbuf();
std::string error;
auto tryJson = matjson::parse(bufferStream.str(), error);
auto tryJson = matjson::parse(bufferStream.str());
auto packFileName = rootPackPath.filename().string();
if (!error.empty()) {
if (!tryJson.isOk()) {
packName = packFileName;
packID = packFileName;
}
auto json = tryJson.value_or(matjson::Object());
if (json.contains("name") && json["name"].is_string()) packName = json["name"].as_string();
auto json = tryJson.unwrapOr(matjson::Value());
if (json.contains("name") && json["name"].isString()) packName = json["name"].asString().unwrap();
else packName = packFileName;
if (json.contains("id") && json["id"].is_string()) packID = json["id"].as_string();
if (json.contains("id") && json["id"].isString()) packID = json["id"].asString().unwrap();
else packID = packFileName;
}
}
@@ -488,24 +486,23 @@ void MoreIcons::loadTrail(const std::filesystem::path& path, const TexturePack&
auto name = (!pack.id.empty() ? pack.id + ":" : "") + path.stem().string();
auto jsonPath = std::filesystem::path(path).replace_extension(".json");
matjson::Value json;
if (!std::filesystem::exists(jsonPath)) json = matjson::Object { { "blend", false }, { "tint", false } };
if (!std::filesystem::exists(jsonPath)) json = matjson::makeObject({ { "blend", false }, { "tint", false } });
else {
std::ifstream file(jsonPath);
std::stringstream bufferStream;
bufferStream << file.rdbuf();
std::string error;
auto tryJson = matjson::parse(bufferStream.str(), error);
if (!error.empty()) {
auto logMessage = fmt::format("{}: Failed to parse JSON file ({})", path.string(), error);
auto tryJson = matjson::parse(bufferStream.str());
if (!tryJson.isOk()) {
auto logMessage = fmt::format("{}: Failed to parse JSON file ({})", path.string(), tryJson.unwrapErr());
log::warn("{}", logMessage);
{
std::lock_guard lock(LOG_MUTEX);
LOGS.push_back({ .message = logMessage, .type = LogType::Warn });
if (HIGHEST_SEVERITY < LogType::Warn) HIGHEST_SEVERITY = LogType::Warn;
}
json = matjson::Object { { "blend", false }, { "tint", false } };
json = matjson::makeObject({ { "blend", false }, { "tint", false } });
}
else json = tryJson.value_or(matjson::Object { { "blend", false }, { "tint", false } });
else json = tryJson.unwrap();
}

auto fullTexturePath = path.string();
@@ -521,8 +518,8 @@ void MoreIcons::loadTrail(const std::filesystem::path& path, const TexturePack&
.pack = pack,
.type = IconType::Special,
.index = 0,
.blend = json.contains("blend") && json["blend"].is_bool() ? json["blend"].as_bool() : false,
.tint = json.contains("tint") && json["tint"].is_bool() ? json["tint"].as_bool() : false,
.blend = json.contains("blend") && json["blend"].isBool() ? json["blend"].asBool().unwrap() : false,
.tint = json.contains("tint") && json["tint"].isBool() ? json["tint"].asBool().unwrap() : false,
});
}
else image->release();
4 changes: 2 additions & 2 deletions src/MoreIcons.hpp
Original file line number Diff line number Diff line change
@@ -156,10 +156,10 @@ class MoreIcons {
static void saveTrails() {
for (auto& [trail, info] : TRAIL_INFO) {
std::fstream file(std::filesystem::path(info.texture).replace_extension(".json"), std::ios::out);
file << matjson::Value(matjson::Object {
file << matjson::Value(matjson::makeObject({
{ "blend", info.blend },
{ "tint", info.tint },
}).dump();
})).dump();
file.close();
}
}
20 changes: 20 additions & 0 deletions src/classes/ButtonHooker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "ButtonHooker.hpp"

using namespace geode::prelude;

ButtonHooker* ButtonHooker::create(CCMenuItem* button, CCObject* listener, SEL_MenuHandler selector) {
auto hooker = new ButtonHooker();
hooker->m_listener = button->m_pListener;
hooker->m_newListener = listener;
hooker->m_selector = button->m_pfnSelector;
hooker->m_newSelector = selector;
hooker->autorelease();
button->setTarget(hooker, menu_selector(ButtonHooker::onClick));
button->setUserObject("hooker"_spr, hooker);
return hooker;
}

void ButtonHooker::onClick(CCObject* sender) {
(m_listener->*m_selector)(sender);
(m_newListener->*m_newSelector)(sender);
}
11 changes: 11 additions & 0 deletions src/classes/ButtonHooker.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class ButtonHooker : public cocos2d::CCObject {
private:
cocos2d::CCObject* m_listener;
cocos2d::CCObject* m_newListener;
cocos2d::SEL_MenuHandler m_selector;
cocos2d::SEL_MenuHandler m_newSelector;
public:
static ButtonHooker* create(cocos2d::CCMenuItem* button, cocos2d::CCObject* listener, cocos2d::SEL_MenuHandler selector);

void onClick(cocos2d::CCObject* sender);
};
8 changes: 4 additions & 4 deletions src/classes/LogCell.cpp
Original file line number Diff line number Diff line change
@@ -28,22 +28,22 @@ bool LogCell::init(LogData const& data, int index, int total, bool dark) {
bg->ignoreAnchorPointForPosition(false);
if (index == 0) {
bg->setContentSize({ 400.0f, 35.0f });
bg->setPosition(200.0f, 17.5f);
bg->setPosition({ 200.0f, 17.5f });
}
else if (index == total - 1) {
bg->setContentSize({ 400.0f, 35.0f });
bg->setPosition(200.0f, 52.5f);
bg->setPosition({ 200.0f, 52.5f });
}
else {
bg->setContentSize({ 400.0f, 70.0f });
bg->setPosition(200.0f, 35.0f);
bg->setPosition({ 200.0f, 35.0f });
}
addChild(bg, -1);

if (index == 0 || index == total - 1) {
auto bgBg = CCScale9Sprite::create("square02b_001.png", { 0, 0, 80, 80 });
bgBg->setContentSize({ 400.0f, 70.0f });
bgBg->setPosition(200.0f, 35.0f);
bgBg->setPosition({ 200.0f, 35.0f });
bgBg->setColor(bg->getColor());
addChild(bgBg, -2);
}
6 changes: 3 additions & 3 deletions src/classes/LogLayer.cpp
Original file line number Diff line number Diff line change
@@ -18,12 +18,12 @@ bool LogLayer::setup() {

auto background = CCScale9Sprite::create("square02_001.png", { 0, 0, 80, 80 });
background->setContentSize({ 400.0f, 230.0f });
background->setPosition(220.0f, 135.0f);
background->setPosition({ 220.0f, 135.0f });
background->setOpacity(127);
m_mainLayer->addChild(background);

auto scrollLayer = ScrollLayer::create({ 400.0f, 230.0f });
scrollLayer->setPosition(20.0f, 20.0f);
scrollLayer->setPosition({ 20.0f, 20.0f });
scrollLayer->m_contentLayer->setLayout(
ColumnLayout::create()
->setAxisReverse(true)
@@ -44,7 +44,7 @@ bool LogLayer::setup() {
scrollLayer->scrollToTop();

auto topButtons = CCMenu::create();
topButtons->setPosition(420.0f, 270.0f);
topButtons->setPosition({ 420.0f, 270.0f });
topButtons->setContentSize({ 100.0f, 30.0f });
topButtons->setAnchorPoint({ 1.0f, 0.5f });
topButtons->setLayout(
68 changes: 29 additions & 39 deletions src/hooks/GJGarageLayer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "../MoreIcons.hpp"
#include "../classes/ButtonHooker.hpp"
#include "../classes/LogLayer.hpp"

using namespace geode::prelude;
@@ -9,8 +10,6 @@ class $modify(MIGarageLayer, GJGarageLayer) {
ListButtonBar* m_pageBar;
CCMenu* m_navMenu;
std::map<IconType, int> m_pages;
SEL_MenuHandler m_originalSDISwitch;
SEL_MenuHandler m_originalSDISwap;
};

static void onModify(auto& self) {
@@ -37,22 +36,20 @@ class $modify(MIGarageLayer, GJGarageLayer) {
if (!customIcon.empty() && MoreIconsAPI::hasIcon(customIcon, IconType::Cube)) setupCustomPage(MoreIcons::findIconPage(IconType::Cube));
else createNavMenu();

auto shardsMenu = getChildByID("shards-menu");
if (sdi) {
if (auto playerButtonsMenu = getChildByID("player-buttons-menu")) {
auto p1Button = static_cast<CCMenuItemSpriteExtra*>(playerButtonsMenu->getChildByID("player1-button"));
auto p2Button = static_cast<CCMenuItemSpriteExtra*>(playerButtonsMenu->getChildByID("player2-button"));
if (p1Button && p2Button) {
f->m_originalSDISwitch = p2Button->m_pfnSelector;
p1Button->m_pfnSelector = menu_selector(MIGarageLayer::newOn2PToggle);
p2Button->m_pfnSelector = menu_selector(MIGarageLayer::newOn2PToggle);
ButtonHooker::create(p1Button, this, menu_selector(MIGarageLayer::onSelectTab));
ButtonHooker::create(p2Button, this, menu_selector(MIGarageLayer::onSelectTab));
}
}

if (auto shardsMenu = getChildByID("shards-menu")) {
if (auto swap2PButton = static_cast<CCMenuItemSpriteExtra*>(shardsMenu->getChildByID("swap-2p-button"))) {
f->m_originalSDISwap = swap2PButton->m_pfnSelector;
swap2PButton->m_pfnSelector = menu_selector(MIGarageLayer::newSwap2PKit);
}
if (shardsMenu) {
if (auto swap2PButton = static_cast<CCMenuItemSpriteExtra*>(shardsMenu->getChildByID("swap-2p-button")))
ButtonHooker::create(swap2PButton, this, menu_selector(MIGarageLayer::newSwap2PKit));
}
}

@@ -69,19 +66,21 @@ class $modify(MIGarageLayer, GJGarageLayer) {
severitySprite->setScale(0.6f);
moreIconsSprite->addChild(severitySprite, 1);
}
auto moreIconsButton = CCMenuItemExt::createSpriteExtra(moreIconsSprite, [this](auto) {
if (!MoreIcons::LOGS.empty()) LogLayer::create()->show();
else MoreIcons::showInfoPopup(true);
});
auto moreIconsButton = CCMenuItemSpriteExtra::create(moreIconsSprite, this, menu_selector(MIGarageLayer::onMoreIcons));
moreIconsButton->setID("more-icons-button"_spr);
if (auto shardsMenu = getChildByID("shards-menu")) {
if (shardsMenu) {
shardsMenu->addChild(moreIconsButton);
shardsMenu->updateLayout();
}

return true;
}

void onMoreIcons(CCObject* sender) {
if (!MoreIcons::LOGS.empty()) LogLayer::create()->show();
else MoreIcons::showInfoPopup(true);
}

void onSelect(CCObject* sender) {
auto btn = static_cast<CCMenuItemSpriteExtra*>(sender);
if (btn->getUserObject("name"_spr)) {
@@ -98,16 +97,10 @@ class $modify(MIGarageLayer, GJGarageLayer) {
}

void newOn2PToggle(CCObject* sender) {
auto f = m_fields.self();
(this->*f->m_originalSDISwitch)(sender);

setupCustomPage(f->m_pages[m_iconType]);
setupCustomPage(m_fields->m_pages[m_iconType]);
}

void newSwap2PKit(CCObject* sender) {
auto f = m_fields.self();
(this->*f->m_originalSDISwap)(sender);

MoreIcons::swapDual("icon");
MoreIcons::swapDual("ship");
MoreIcons::swapDual("ball");
@@ -123,7 +116,7 @@ class $modify(MIGarageLayer, GJGarageLayer) {
auto lastmode = (IconType)Loader::get()->getLoadedMod("weebify.separate_dual_icons")->getSavedValue("lastmode", 0);
MoreIconsAPI::updateSimplePlayer(static_cast<SimplePlayer*>(getChildByID("player2-icon")),
Mod::get()->getSavedValue<std::string>(MoreIconsAPI::savedForType(lastmode, true), ""), lastmode);
setupCustomPage(f->m_pages[m_iconType]);
setupCustomPage(m_fields->m_pages[m_iconType]);
}

void updatePlayerColors() {
@@ -137,7 +130,7 @@ class $modify(MIGarageLayer, GJGarageLayer) {
auto winSize = CCDirector::get()->getWinSize();
if (!f->m_navMenu) {
f->m_navMenu = CCMenu::create();
f->m_navMenu->setPosition(winSize.width / 2, 15.0f);
f->m_navMenu->setPosition({ winSize.width / 2, 15.0f });
f->m_navMenu->setLayout(RowLayout::create()->setGap(6.0f)->setAxisAlignment(AxisAlignment::Center));
f->m_navMenu->setContentSize({ winSize.width - 60.0f, 20.0f });
f->m_navMenu->setID("navdot-menu"_spr);
@@ -353,19 +346,17 @@ class $modify(MIGarageLayer, GJGarageLayer) {
}
auto unlockType = GameManager::get()->iconTypeToUnlockType(m_iconType);
auto popup = ItemInfoPopup::create(iconID, unlockType);
if (auto nameLabel = popup->m_mainLayer->getChildByType<CCLabelBMFont>(0))
if (auto nameLabel = static_cast<CCLabelBMFont*>(popup->m_mainLayer->getChildByID("name-label")))
nameLabel->setString(name.substr(name.find_first_of(':') + 1).c_str());
if (auto achLabel = popup->m_mainLayer->getChildByType<CCLabelBMFont>(1)) achLabel->setString("Custom");
if (auto popupIcon = findFirstChildRecursive<GJItemIcon>(popup->m_mainLayer, [](auto) { return true; }))
if (auto achLabel = static_cast<CCLabelBMFont*>(popup->m_mainLayer->getChildByID("achievement-label"))) achLabel->setString("Custom");
if (auto popupIcon = static_cast<GJItemIcon*>(popup->m_mainLayer->getChildByIDRecursive("item-icon")))
MoreIconsAPI::updateSimplePlayer(popupIcon->m_player, name, m_iconType);
if (auto descText = popup->m_mainLayer->getChildByType<TextArea>(0)) descText->setString(
if (auto descText = static_cast<TextArea*>(popup->m_mainLayer->getChildByID("description-area"))) descText->setString(
fmt::format("This <cg>{}</c> is added by the <cl>More Icons</c> mod.", std::string(ItemInfoPopup::nameForUnlockType(1, unlockType))));
if (auto completionMenu = popup->m_mainLayer->getChildByID("completionMenu")) completionMenu->setVisible(false);
if (auto infoButton = popup->m_buttonMenu->getChildByID("infoButton")) infoButton->setVisible(false);
if (!iconInfo.id.empty()) {
if (auto creditButton = findFirstChildRecursive<CCMenuItemSpriteExtra>(popup->m_buttonMenu, [](CCMenuItemSpriteExtra* btn) {
return typeinfo_cast<CCLabelBMFont*>(btn->getNormalImage()) != nullptr;
})) {
if (auto creditButton = static_cast<CCMenuItemSpriteExtra*>(popup->m_buttonMenu->getChildByID("author-button"))) {
auto creditText = static_cast<CCLabelBMFont*>(creditButton->getNormalImage());
creditText->setString(iconInfo.name.c_str());
creditText->limitLabelWidth(100.0f, 0.5f, 0.0f);
@@ -439,21 +430,22 @@ class $modify(MIGarageLayer, GJGarageLayer) {
}

void onCustomSpecialSelect(CCMenuItemSpriteExtra* sender) {
using namespace std::string_view_literals;

auto sdi = Loader::get()->getLoadedMod("weebify.separate_dual_icons");
auto dual = sdi && sdi->getSavedValue("2pselected", false);
std::string name = static_cast<CCString*>(sender->getUserObject("name"_spr))->getCString();
using namespace std::string_view_literals;

m_cursor1->setPosition(sender->getParent()->convertToWorldSpace(sender->getPosition()));
m_cursor1->setVisible(true);
auto selectedIconType = dual ? (IconType)sdi->getSavedValue("lasttype", 0) : m_selectedIconType;
if (Mod::get()->setSavedValue<std::string>(MoreIcons::savedForType(m_iconType), name) == name && selectedIconType == m_iconType) {
auto trailInfo = MoreIcons::TRAIL_INFO[name];
auto popup = ItemInfoPopup::create(!trailInfo.pack.id.empty() ? 128 : 1, UnlockType::Cube);
if (auto nameLabel = popup->m_mainLayer->getChildByType<CCLabelBMFont>(0))
if (auto nameLabel = static_cast<CCLabelBMFont*>(popup->m_mainLayer->getChildByID("name-label")))
nameLabel->setString(name.substr(name.find_first_of(':') + 1).c_str());
if (auto achLabel = popup->m_mainLayer->getChildByType<CCLabelBMFont>(1)) achLabel->setString("Custom");
if (auto popupIcon = popup->m_mainLayer->getChildByType<GJItemIcon>(0)) {
if (auto achLabel = static_cast<CCLabelBMFont*>(popup->m_mainLayer->getChildByID("achievement-label"))) achLabel->setString("Custom");
if (auto popupIcon = static_cast<GJItemIcon*>(popup->m_mainLayer->getChildByIDRecursive("item-icon"))) {
popupIcon->setVisible(false);
auto square = CCSprite::createWithSpriteFrameName("playerSquare_001.png");
square->setColor({ 150, 150, 150 });
@@ -467,14 +459,12 @@ class $modify(MIGarageLayer, GJGarageLayer) {
square->setID("trail-square"_spr);
popup->m_mainLayer->addChild(square);
}
if (auto descText = popup->m_mainLayer->getChildByType<TextArea>(0)) descText->setString(
if (auto descText = static_cast<TextArea*>(popup->m_mainLayer->getChildByID("description-area"))) descText->setString(
fmt::format("This <cg>{}</c> is added by the <cl>More Icons</c> mod.", std::string(ItemInfoPopup::nameForUnlockType(1, UnlockType::Streak))));
if (auto completionMenu = popup->m_mainLayer->getChildByID("completionMenu")) completionMenu->setVisible(false);
if (auto infoButton = popup->m_buttonMenu->getChildByID("infoButton")) infoButton->setVisible(false);
if (!trailInfo.pack.id.empty()) {
if (auto creditButton = findFirstChildRecursive<CCMenuItemSpriteExtra>(popup->m_buttonMenu, [](CCMenuItemSpriteExtra* btn) {
return typeinfo_cast<CCLabelBMFont*>(btn->getNormalImage()) != nullptr;
})) {
if (auto creditButton = static_cast<CCMenuItemSpriteExtra*>(popup->m_buttonMenu->getChildByID("author-button"))) {
auto creditText = static_cast<CCLabelBMFont*>(creditButton->getNormalImage());
creditText->setString(trailInfo.pack.name.c_str());
creditText->limitLabelWidth(100.0f, 0.5f, 0.0f);
17 changes: 14 additions & 3 deletions src/hooks/MenuLayer.cpp
Original file line number Diff line number Diff line change
@@ -5,14 +5,25 @@ using namespace geode::prelude;
#include <Geode/modify/MenuLayer.hpp>
class $modify(MIMenuLayer, MenuLayer) {
static void onModify(auto& self) {
(void)self.setHookPriority("MenuLayer::init", -1);
if (auto initHookRes = self.getHook("MenuLayer::init")) {
auto initHook = initHookRes.unwrap();
if (auto iconProfile = Loader::get()->getInstalledMod("capeling.icon_profile")) {
if (iconProfile->shouldLoad()) {
initHook->setPriority(-1);
return;
}
}

queueInMainThread([initHook] {
if (!initHook->disable()) log::error("Failed to disable MenuLayer::init hook");
});
}
else log::error("Failed to find MenuLayer::init hook");
}

bool init() {
if (!MenuLayer::init()) return false;

if (!Loader::get()->isModLoaded("capeling.icon_profile")) return true;

auto profileMenu = getChildByID("profile-menu");
if (!profileMenu) return true;

36 changes: 6 additions & 30 deletions src/hooks/ProfilePage.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
#include "../MoreIcons.hpp"
#include "../classes/ButtonHooker.hpp"

using namespace geode::prelude;

#include <Geode/modify/ProfilePage.hpp>
class $modify(MIProfilePage, ProfilePage) {
struct Fields {
SEL_MenuHandler m_originalSDIToggle;
SEL_MenuHandler m_originalSDIShip;
IconType m_shipType = IconType::Ship;
};

static void onModify(auto& self) {
(void)self.setHookPriority("ProfilePage::loadPageFromUserInfo", -1);
}
@@ -33,31 +28,20 @@ class $modify(MIProfilePage, ProfilePage) {
MoreIcons::changeSimplePlayer(MoreIcons::findPlayer(playerMenu->getChildByID("player-jetpack")), IconType::Jetpack);

if (Loader::get()->isModLoaded("weebify.separate_dual_icons")) {
auto f = m_fields.self();
if (auto leftMenu = m_mainLayer->getChildByID("left-menu")) {
if (auto twoPToggler = static_cast<CCMenuItemSpriteExtra*>(leftMenu->getChildByID("2p-toggler"))) {
f->m_originalSDIToggle = twoPToggler->m_pfnSelector;
twoPToggler->m_pfnSelector = menu_selector(MIProfilePage::newOn2PToggle);
}
}
if (!Loader::get()->isModLoaded("rynat.better_unlock_info")) {
if (auto shipToggler = static_cast<CCMenuItemSpriteExtra*>(playerMenu->getChildByID("player-ship"))) {
f->m_originalSDIShip = shipToggler->m_pfnSelector;
shipToggler->m_pfnSelector = menu_selector(MIProfilePage::newOnShipToggle);
}
if (auto twoPToggler = static_cast<CCMenuItemSpriteExtra*>(leftMenu->getChildByID("2p-toggler")))
ButtonHooker::create(twoPToggler, this, menu_selector(MIProfilePage::newOn2PToggle));
}
}
}

void newOn2PToggle(CCObject* sender) {
auto f = m_fields.self();
(this->*f->m_originalSDIToggle)(sender);

auto playerMenu = m_mainLayer->getChildByID("player-menu");
if (!playerMenu) return;

auto playerShip = playerMenu->getChildByID("player-ship");
MoreIcons::changeSimplePlayer(MoreIcons::findPlayer(playerMenu->getChildByID("player-icon")), IconType::Cube);
MoreIcons::changeSimplePlayer(MoreIcons::findPlayer(playerMenu->getChildByID("player-ship")), f->m_shipType);
MoreIcons::changeSimplePlayer(MoreIcons::findPlayer(playerShip), playerShip ? (IconType)playerShip->getTag() : IconType::Ship);
MoreIcons::changeSimplePlayer(MoreIcons::findPlayer(playerMenu->getChildByID("player-ball")), IconType::Ball);
MoreIcons::changeSimplePlayer(MoreIcons::findPlayer(playerMenu->getChildByID("player-ufo")), IconType::Ufo);
MoreIcons::changeSimplePlayer(MoreIcons::findPlayer(playerMenu->getChildByID("player-wave")), IconType::Wave);
@@ -72,14 +56,6 @@ class $modify(MIProfilePage, ProfilePage) {

if (!m_ownProfile) return;

MoreIcons::changeSimplePlayer(static_cast<SimplePlayer*>(static_cast<CCMenuItemSpriteExtra*>(sender)->getNormalImage()), (IconType)sender->getTag());
}

void newOnShipToggle(CCObject* sender) {
auto f = m_fields.self();
(this->*f->m_originalSDIShip)(sender);

f->m_shipType = f->m_shipType == IconType::Ship ? IconType::Jetpack : IconType::Ship;
MoreIcons::changeSimplePlayer(static_cast<SimplePlayer*>(static_cast<CCMenuItemSpriteExtra*>(sender)->getNormalImage()), f->m_shipType);
MoreIcons::changeSimplePlayer(MoreIcons::findPlayer(static_cast<CCNode*>(sender)), (IconType)sender->getTag());
}
};

0 comments on commit eb15557

Please sign in to comment.