From 02b86d5e8a4f55e1f15e8ec21a1f4ca5194ca587 Mon Sep 17 00:00:00 2001 From: Cvolton Date: Sat, 24 Feb 2024 02:09:06 +0100 Subject: [PATCH] add ChallengeNode IDs --- about.md | 3 +- src/ChallengeNode.cpp | 91 ++++++++++++++++++++++++++++++++++++++++++ src/ChallengesPage.cpp | 20 +++++++++- 3 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 src/ChallengeNode.cpp diff --git a/about.md b/about.md index d461ac0..8e72faa 100644 --- a/about.md +++ b/about.md @@ -2,11 +2,12 @@ Adds node IDs to layers for other mods to base their UI on, for preserving mod compatibility. See the [Github repository](https://github.com/geode-sdk/NodeIDs) for contributing. -Has ids for: +Has IDs for: - CommentCell - CreatorLayer - CustomizeObjectLayer (Windows and Android only) +- ChallengeNode - ChallengesPage - DailyLevelNode - DailyLevelPage diff --git a/src/ChallengeNode.cpp b/src/ChallengeNode.cpp new file mode 100644 index 0000000..338e4e9 --- /dev/null +++ b/src/ChallengeNode.cpp @@ -0,0 +1,91 @@ +#include +#include +#include +#include +#include + + +using namespace geode::prelude; +using namespace geode::node_ids; + +struct ChallengeNodeIDs : Modify { + bool m_isNew; + + static void onModify(auto& self) { + if (!self.setHookPriority("ChallengeNode::init", GEODE_ID_PRIORITY)) { + log::warn("Failed to set ChallengeNode::init hook priority, node IDs may not work properly"); + } + } + + bool init(GJChallengeItem* challenge, ChallengesPage* page, bool isNew) { + if(!ChallengeNode::init(challenge, page, isNew)) return false; + + m_fields->m_isNew = isNew; + + NodeIDs::get()->provide(this); + + return true; + } +}; + +$register_ids(ChallengeNode) { + size_t offset = 0; + auto self = reinterpret_cast(this); + + if(!m_challengeItem) { + setIDs( + this, + offset, + "background", + "countdown-label" + ); + + return; + } + + setIDs( + this, + offset, + "background", + "title-label", + "collect-label", + "collect-icon" + ); + + offset += 4; + + if(self->m_fields->m_isNew) { + setIDSafe(this, offset, "new-label"); + offset += 1; + } + + setIDs( + this, + offset, + "progress-bar", + "progress-label" + ); + + offset += 2; + + if(m_challengeItem->m_canClaim) { + if(auto menu = setIDSafe(this, offset, "claim-menu")) { + setIDs( + menu, + 0, + "claim-button" + ); + offset += 1; + } + } + + // technically these get created in the if and else branches + // but they get created in the same order, they just differ in sizes + setIDs( + this, + offset, + "reward-sprite", + "reward-label" + ); + +}; \ No newline at end of file diff --git a/src/ChallengesPage.cpp b/src/ChallengesPage.cpp index 4281b96..00ae4f9 100644 --- a/src/ChallengesPage.cpp +++ b/src/ChallengesPage.cpp @@ -69,9 +69,9 @@ using namespace geode::node_ids; ); closeMenu->updateLayout(); } - getChildOfType(m_mainLayer, 0)->setID("top-quest"); + /*getChildOfType(m_mainLayer, 0)->setID("top-quest"); getChildOfType(m_mainLayer, 1)->setID("middle-quest"); - getChildOfType(m_mainLayer, 2)->setID("bottom-quest"); + getChildOfType(m_mainLayer, 2)->setID("bottom-quest");*/ getChildOfType(m_mainLayer, 0)->setID("new-quest-label"); getChildOfType(m_mainLayer, 1)->setID("top-quest-indicator"); getChildOfType(m_mainLayer, 2)->setID("middle-quest-indicator"); @@ -84,6 +84,22 @@ struct ChallengesPageIDs : Modify { if (!self.setHookPriority("ChallengesPage::init", GEODE_ID_PRIORITY)) { log::warn("Failed to set ChallengesPage::init hook priority, node IDs may not work properly"); } + if (!self.setHookPriority("ChallengesPage::createChallengeNode", GEODE_ID_PRIORITY)) { + log::warn("Failed to set ChallengesPage::createChallengeNode hook priority, node IDs may not work properly"); + } + } + + ChallengeNode* createChallengeNode(int number, bool skipAnimation, float animLength, bool isNew) { + auto node = ChallengesPage::createChallengeNode(number, skipAnimation, animLength, isNew); + if(!node) return nullptr; + + switch(number) { + case 1: node->setID("top-quest"); break; + case 2: node->setID("middle-quest"); break; + case 3: node->setID("bottom-quest"); break; + default: node->setID(fmt::format("quest-{}", number)); break; + } + return node; } bool init() {