From a587a5f1bfa8347868916266d705aae45255dff8 Mon Sep 17 00:00:00 2001 From: altalk23 <45172705+altalk23@users.noreply.github.com> Date: Sat, 17 Feb 2024 00:14:17 +0300 Subject: [PATCH] fix endlevellayer gg --- src/EndLevelLayer.cpp | 112 ++++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 53 deletions(-) diff --git a/src/EndLevelLayer.cpp b/src/EndLevelLayer.cpp index fe894cf..dd4a572 100644 --- a/src/EndLevelLayer.cpp +++ b/src/EndLevelLayer.cpp @@ -13,64 +13,40 @@ using namespace geode::node_ids; // definitely should be in geode utils // ok it is in geode utils now // use it when we release beta 20 -inline CCNode* getChildBySpriteFrameName(CCNode* parent, const char* name) { + +inline bool isSpriteFrameName(CCNode* node, const char* name) { auto cache = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name); - if (!cache) return nullptr; + if (!cache) return false; auto* texture = cache->getTexture(); auto rect = cache->getRect(); - for (int i = 0; i < parent->getChildrenCount(); ++i) { - auto* child = parent->getChildren()->objectAtIndex(i); - if (auto* spr = typeinfo_cast(child)) { + if (auto* spr = typeinfo_cast(node)) { + if (spr->getTexture() == texture && spr->getTextureRect() == rect) { + return true; + } + } else if (auto* btn = typeinfo_cast(node)) { + auto* img = btn->getNormalImage(); + if (auto* spr = typeinfo_cast(img)) { if (spr->getTexture() == texture && spr->getTextureRect() == rect) { - return spr; - } - } else if (auto* btn = typeinfo_cast(child)) { - auto* img = btn->getNormalImage(); - if (auto* spr = typeinfo_cast(img)) { - if (spr->getTexture() == texture && spr->getTextureRect() == rect) { - return btn; - } + return true; } } } - return nullptr; + return false; } -namespace { - void handleContainers(EndLevelLayer* self) { - for (auto child : CCArrayExt(self->m_mainLayer->getChildren())) { - if (auto star = ::getChildBySpriteFrameName(child, "GJ_bigStar_001.png")) { - child->setID("star-container"); - star->setID("star-sprite"); - getChildOfType(child, 0)->setID("star-label"); - } - else if (auto star = ::getChildBySpriteFrameName(child, "GJ_bigMoon_001.png")) { - child->setID("moon-container"); - star->setID("moon-sprite"); - getChildOfType(child, 0)->setID("moon-label"); - } - else if (auto star = ::getChildBySpriteFrameName(child, "currencyOrbIcon_001.png")) { - child->setID("orb-container"); - star->setID("orb-sprite"); - getChildOfType(child, 0)->setID("orb-label"); - } - else if (auto star = ::getChildBySpriteFrameName(child, "GJ_bigDiamond_001.png")) { - child->setID("diamond-container"); - star->setID("diamond-sprite"); - getChildOfType(child, 0)->setID("diamond-label"); - } +inline CCNode* getChildBySpriteFrameName(CCNode* parent, const char* name) { + for (auto child : CCArrayExt(parent->getChildren())) { + if (::isSpriteFrameName(static_cast(child), name)) { + return child; } } + return nullptr; } -$register_ids(EndLevelLayer) { - if (!m_mainLayer->getID().empty()) { - handleContainers(this); - return; - } +$register_ids(EndLevelLayer) { m_mainLayer->setID("main-layer"); int idx = 0; @@ -126,20 +102,26 @@ namespace { idx += 1; } - m_buttonMenu->setID("button-menu"); + setIDs( + m_mainLayer, + idx, + "button-menu" + ); idx += 1; + auto menu = static_cast(m_mainLayer->getChildByID("button-menu")); + setIDs( - m_buttonMenu, + menu, 0, - "replay-button", - "menu-button" + "retry-button", + "exit-button" ); - if (auto editButton = ::getChildBySpriteFrameName(m_buttonMenu, "GJ_editBtn_001.png")) { + if (auto editButton = ::getChildBySpriteFrameName(menu, "GJ_editBtn_001.png")) { editButton->setID("edit-button"); } - if (auto leaderboardButton = ::getChildBySpriteFrameName(m_buttonMenu, "GJ_levelLeaderboardBtn_001.png")) { + if (auto leaderboardButton = ::getChildBySpriteFrameName(menu, "GJ_levelLeaderboardBtn_001.png")) { leaderboardButton->setID("leaderboard-button"); } @@ -151,8 +133,8 @@ namespace { "secretCoinUI_001.png", "secretCoinUI2_001.png" }) { - if (auto sprite = ::getChildBySpriteFrameName(m_buttonMenu, framename)) { - sprite->setID(fmt::format("coin-{}-sprite", currentCoin)); + if (::isSpriteFrameName(child, framename)) { + child->setID(fmt::format("coin-{}-sprite", currentCoin)); currentCoin += 1; idx += 1; } @@ -163,8 +145,8 @@ namespace { setIDs( m_mainLayer, idx, - "controller-replay-hint", - "controller-menu-hint" + "controller-retry-hint", + "controller-exit-hint" ); idx += 2; } @@ -175,6 +157,9 @@ struct EndLevelLayerIDs : Modify { if (!self.setHookPriority("EndLevelLayer::customSetup", GEODE_ID_PRIORITY)) { log::warn("Failed to set EndLevelLayer::customSetup hook priority, node IDs may not work properly"); } + if (!self.setHookPriority("EndLevelLayer::showLayer", GEODE_ID_PRIORITY)) { + log::warn("Failed to set EndLevelLayer::showLayer hook priority, node IDs may not work properly"); + } } void customSetup() { @@ -186,6 +171,27 @@ struct EndLevelLayerIDs : Modify { void showLayer(bool p0) { EndLevelLayer::showLayer(p0); - NodeIDs::get()->provide(this); + for (auto child : CCArrayExt(m_mainLayer->getChildren())) { + if (auto star = ::getChildBySpriteFrameName(child, "GJ_bigStar_001.png")) { + child->setID("star-container"); + star->setID("star-sprite"); + getChildOfType(child, 0)->setID("star-label"); + } + else if (auto moon = ::getChildBySpriteFrameName(child, "GJ_bigMoon_001.png")) { + child->setID("moon-container"); + moon->setID("moon-sprite"); + getChildOfType(child, 0)->setID("moon-label"); + } + else if (auto orb = ::getChildBySpriteFrameName(child, "currencyOrbIcon_001.png")) { + child->setID("orb-container"); + orb->setID("orb-sprite"); + getChildOfType(child, 0)->setID("orb-label"); + } + else if (auto diamond = ::getChildBySpriteFrameName(child, "GJ_bigDiamond_001.png")) { + child->setID("diamond-container"); + diamond->setID("diamond-sprite"); + getChildOfType(child, 0)->setID("diamond-label"); + } + } } };