Skip to content

Commit

Permalink
add ChallengeNode IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
Cvolton committed Feb 24, 2024
1 parent 7608d7a commit 02b86d5
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 3 deletions.
3 changes: 2 additions & 1 deletion about.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
91 changes: 91 additions & 0 deletions src/ChallengeNode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#include <Geode/Bindings.hpp>
#include <Geode/modify/ChallengeNode.hpp>
#include <Geode/utils/cocos.hpp>
#include <Geode/ui/BasedButtonSprite.hpp>
#include <Geode/utils/NodeIDs.hpp>


using namespace geode::prelude;
using namespace geode::node_ids;

struct ChallengeNodeIDs : Modify<ChallengeNodeIDs, ChallengeNode> {
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<ChallengeNodeIDs*>(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"
);

};
20 changes: 18 additions & 2 deletions src/ChallengesPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ using namespace geode::node_ids;
);
closeMenu->updateLayout();
}
getChildOfType<ChallengeNode>(m_mainLayer, 0)->setID("top-quest");
/*getChildOfType<ChallengeNode>(m_mainLayer, 0)->setID("top-quest");
getChildOfType<ChallengeNode>(m_mainLayer, 1)->setID("middle-quest");
getChildOfType<ChallengeNode>(m_mainLayer, 2)->setID("bottom-quest");
getChildOfType<ChallengeNode>(m_mainLayer, 2)->setID("bottom-quest");*/
getChildOfType<cocos2d::CCLabelBMFont>(m_mainLayer, 0)->setID("new-quest-label");
getChildOfType<cocos2d::CCLabelBMFont>(m_mainLayer, 1)->setID("top-quest-indicator");
getChildOfType<cocos2d::CCLabelBMFont>(m_mainLayer, 2)->setID("middle-quest-indicator");
Expand All @@ -84,6 +84,22 @@ struct ChallengesPageIDs : Modify<ChallengesPageIDs, ChallengesPage> {
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() {
Expand Down

0 comments on commit 02b86d5

Please sign in to comment.