Skip to content

Commit

Permalink
Merge pull request #2 from Cvolton/sapphire-ids
Browse files Browse the repository at this point in the history
7 new layers
  • Loading branch information
matcool authored Jan 14, 2024
2 parents 15bea98 + ac4307d commit 11df388
Show file tree
Hide file tree
Showing 15 changed files with 1,140 additions and 65 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ jobs:
- name: Android32
os: ubuntu-latest
target: Android32
- name: Android64
os: ubuntu-latest
target: Android64


name: ${{ matrix.config.name }}
Expand Down
19 changes: 18 additions & 1 deletion about.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# Node IDs

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.
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:

- CommentCell
- CreatorLayer
- DailyLevelNode
- DailyLevelPage
- EditLevelLayer
- InfoLayer
- LeaderboardsLayer
- LevelBrowserLayer
- LevelCell
- LevelInfoLayer
- LevelLeaderboard
- LevelSearchLayer
- ProfilePage
- RewardsPage
5 changes: 3 additions & 2 deletions src/CreatorLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ static void reorderButtons(Args... args) {
setIDSafe(menu, 3, "quests-button"),
setIDSafe(menu, 4, "versus-button")
);
if (winSize.width / winSize.height <= 5.1f / 3.f) {
/*if (winSize.width / winSize.height <= 5.1f / 3.f) {
menu->setContentSize({ winSize.width - 80.f, 310.f });
}
else {
menu->setContentSize({ winSize.width - 120.f, 310.f });
}
}*/
menu->setContentSize({ 450.f, 310.f });
menu->setLayout(
RowLayout::create()
->setGap(6.f)
Expand Down
1 change: 1 addition & 0 deletions src/EditLevelLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ using namespace geode::node_ids;
if (auto menu = this->getChildByID("info-button-menu")) {
setIDSafe(menu, 0, "info-button");
setIDSafe(menu, 1, "guidelines-button");
setIDSafe(menu, 2, "settings-button");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/EditorUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ using namespace geode::node_ids;
menu->getChildByID("copy-values-button"),
menu->getChildByID("hsv-button")
);
for (auto btn : CCArrayExt<CCNode>(rightMenu->getChildren())) {
for (auto btn : CCArrayExt<CCNode*>(rightMenu->getChildren())) {
btn->setContentSize({ 40.f, 40.f });
}
rightMenu->setContentSize({ 210.f, 160.f });
Expand Down
63 changes: 63 additions & 0 deletions src/GJScoreCell.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// #include "AddIDs.hpp"

#include <Geode/modify/GJScoreCell.hpp>
#include <Geode/utils/NodeIDs.hpp>

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

$register_ids(GJScoreCell) {
setIDs(
m_mainLayer,
0,
"player-icon",
"main-menu"
);

if(m_score->m_scoreType != 2) {
setIDs(
m_mainLayer,
2,
"rank-label"
);
}

setIDs(
m_mainLayer,
m_score->m_scoreType == 2 ? 2 : 3,
"stars-label",
"stars-icon",
"moons-label",
"moons-icon",
"diamonds-label",
"diamonds-icon",
"coins-label",
"coins-icon",
"user-coins-label",
"user-coins-icon",
"demons-label",
"demons-icon",
"creator-points-label",
"creator-points-icon"
);

if(auto menu = m_mainLayer->getChildByID("main-menu")) {
if(menu->getChildrenCount() > 0) {
static_cast<CCNode*>(menu->getChildren()->objectAtIndex(0))->setID("player-name");
}
}
}

struct GJScoreCellIDs : Modify<GJScoreCellIDs, GJScoreCell> {
static void onModify(auto& self) {
if (!self.setHookPriority("GJScoreCell::loadFromScore", GEODE_ID_PRIORITY)) {
log::warn("Failed to set GJScoreCell::loadFromScore hook priority, node IDs may not work properly");
}
}

void loadFromScore(GJUserScore* score) {
GJScoreCell::loadFromScore(score);

NodeIDs::get()->provide(this);
}
};
9 changes: 9 additions & 0 deletions src/IDCheck.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#define verifyIDSafe(Member_, ID_) \
if(Member_ && Member_->getID() != ID_) { \
log::warn("{} has an invalid ID - {} (expected {})", #Member_, Member_->getID(), ID_); \
}

#define verifyParentIDSafe(Member_, ID_) \
if(Member_ && Member_->getParent() && Member_->getParent()->getID() != ID_) { \
log::warn("{}'s parent has an invalid ID - {} (expected {})", #Member_, m_rightArrow->getParent()->getID(), ID_); \
}
170 changes: 170 additions & 0 deletions src/InfoLayer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
#include <Geode/Bindings.hpp>
#include <Geode/modify/InfoLayer.hpp>
#include <Geode/utils/cocos.hpp>
#include <Geode/ui/BasedButtonSprite.hpp>
#include <Geode/utils/NodeIDs.hpp>

#include "IDCheck.hpp"

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

$register_ids(InfoLayer) {
bool descNotVisible = GameManager::sharedState()->getGameVariable("0089") || m_score;

size_t buttonOffset = 0;
size_t labelOffset = 0;
size_t menuOffset = 0;

auto winSize = CCDirector::get()->getWinSize();

getChildOfType<CCScale9Sprite>(m_mainLayer, 0)->setID("background");

//this label is created at a different points in init for m_score and !m_score but the index happens to match, since they're right after each other
getChildOfType<CCLabelBMFont>(m_mainLayer, 0)->setID("title-label");
labelOffset++;

getChildOfType<CCMenu>(m_mainLayer, 0)->setID("main-menu");
menuOffset++;

if(!m_score) {
getChildOfType<CCMenuItemSpriteExtra>(m_buttonMenu, buttonOffset)->setID("creator-button");
buttonOffset++;

if(!descNotVisible) {
getChildOfType<CCScale9Sprite>(m_mainLayer, 1)->setID("desc-background");
getChildOfType<TextArea>(m_mainLayer, 0)->setID("description-area");
}

//InfoLayer::setupLevelInfo stuff
if(m_level || m_levelList) {
getChildOfType<CCMenu>(m_mainLayer, menuOffset)->setID("id-menu");
menuOffset++;

getChildOfType<CCLabelBMFont>(m_mainLayer, labelOffset)->setID("version-label");
labelOffset++;
}
//end of InfoLayer::setupLevelInfo stuff

if(m_level && m_level->m_originalLevel != 0 && m_level->m_originalLevel != m_level->m_levelID && !GameManager::sharedState()->getGameVariable("0077")) {
getChildOfType<CCMenuItemSpriteExtra>(m_buttonMenu, buttonOffset)->setID("original-level-button");
buttonOffset++;
}

getChildOfType<CCMenuItemSpriteExtra>(m_buttonMenu, buttonOffset)->setID("comment-button");
buttonOffset++;

getChildOfType<CCMenuItemSpriteExtra>(m_buttonMenu, buttonOffset)->setID("report-button");
buttonOffset++;

}

getChildOfType<CCMenuItemSpriteExtra>(m_buttonMenu, buttonOffset)->setID("close-button");
buttonOffset++;

getChildOfType<LoadingCircle>(m_mainLayer, 0)->setID("loading-circle");


if(auto menu = getChildOfType<CCMenu>(m_mainLayer, menuOffset)){
menu->setID("switch-page-menu");
menuOffset++;

getChildOfType<CCMenuItemSpriteExtra>(menu, 0)->setID("prev-page-button");
getChildOfType<CCMenuItemSpriteExtra>(menu, 1)->setID("next-page-button");
}

getChildOfType<CCLabelBMFont>(m_mainLayer, labelOffset)->setID("comment-count-label");
labelOffset++;

if(auto menu = getChildOfType<CCMenu>(m_mainLayer, menuOffset)){
menu->setID("left-side-menu");
menuOffset++;

getChildOfType<CCMenuItemSpriteExtra>(menu, 0)->setID("sort-likes-button");
getChildOfType<CCMenuItemSpriteExtra>(menu, 1)->setID("sort-recent-button");
getChildOfType<CCMenuItemSpriteExtra>(menu, 2)->setID("small-mode-button");
if(!m_score) {
getChildOfType<CCMenuItemSpriteExtra>(menu, 3)->setID("extend-button");
}

menu->setContentSize({10, 140});
menu->setLayout(
ColumnLayout::create()
->setGap(6.f)
->setAxisAlignment(AxisAlignment::Center)
->setAxisReverse(true)
);

//the default autoscale options make the buttons too big
for(auto& child : CCArrayExt<CCNode*>(menu->getChildren())) {
child->setLayoutOptions(
AxisLayoutOptions::create()
->setMinScale(.1f)
->setMaxScale(.7f)
);
}

}

//now it calls InfoLayer::updateCommentModeButtons but that doesn't do anything important

getChildOfType<CCMenuItemSpriteExtra>(m_buttonMenu, buttonOffset)->setID("load-comments-button");
buttonOffset++;

getChildOfType<CCLabelBMFont>(m_mainLayer, labelOffset)->setID("no-comments");
labelOffset++;

if(!m_score) {
getChildOfType<CCMenuItemSpriteExtra>(m_buttonMenu, buttonOffset)->setID("info-button");
buttonOffset++;
}

getChildOfType<CCMenuItemSpriteExtra>(m_buttonMenu, buttonOffset)->setID("refresh-button");
buttonOffset++;

auto refreshMenu = detachAndCreateMenu(
m_mainLayer, "refresh-menu",
ColumnLayout::create()->setAxisAlignment(AxisAlignment::Start),
m_buttonMenu->getChildByID("refresh-button")
);
refreshMenu->setContentSize({refreshMenu->getContentSize().width, 100.f});
refreshMenu->setPositionY(refreshMenu->getPositionY() + 35);

/**
* Sanity checks
*/
verifyIDSafe(m_loadingCircle, "loading-circle");
verifyIDSafe(m_pageLabel, "comment-count-label");
verifyIDSafe(m_noComments, "no-comments");
verifyIDSafe(m_rightArrow, "next-page-button");
verifyIDSafe(m_leftArrow, "prev-page-button");
verifyIDSafe(m_likeBtn, "sort-likes-button");
verifyIDSafe(m_timeBtn, "sort-recent-button");
//verifyIDSafe(m_reportBtn, "report-button"); //not necessarily nullptr
verifyIDSafe(m_commentsBtn, "load-comments-button");
verifyIDSafe(m_refreshCommentsBtn, "refresh-button");

verifyParentIDSafe(m_rightArrow, "switch-page-menu");
verifyParentIDSafe(m_leftArrow, "switch-page-menu");
verifyParentIDSafe(m_likeBtn, "left-side-menu");
verifyParentIDSafe(m_timeBtn, "left-side-menu");
//verifyParentIDSafe(m_reportBtn, "main-menu");
verifyParentIDSafe(m_commentsBtn, "main-menu");
verifyParentIDSafe(m_refreshCommentsBtn, "refresh-menu");
}

struct InfoLayerIDs : Modify<InfoLayerIDs, InfoLayer> {
static void onModify(auto& self) {
if (!self.setHookPriority("InfoLayer::init", GEODE_ID_PRIORITY)) {
log::warn("Failed to set InfoLayer::init hook priority, node IDs may not work properly");
}
}

bool init(GJGameLevel* level, GJUserScore* score, GJLevelList* list) {
if (!InfoLayer::init(level, score, list)) return false;

NodeIDs::get()->provide(this);

return true;
}
};
70 changes: 70 additions & 0 deletions src/LeaderboardsLayer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include <Geode/Bindings.hpp>
#include <Geode/modify/LeaderboardsLayer.hpp>
#include <Geode/utils/cocos.hpp>
#include <Geode/utils/NodeIDs.hpp>

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

$register_ids(LeaderboardsLayer) {
setIDs(
this,
0,
"background",
"bottom-left-art",
"bottom-right-art",
"loading-circle",
"no-internet-label",
"info-menu",
"top-100-menu",
"friends-menu",
"global-menu",
"creators-menu",
"list-layer",
"back-menu"
);

auto winSize = CCDirector::get()->getWinSize();

auto bottomRightMenu = CCMenu::create();
bottomRightMenu->setID("bottom-right-menu");
bottomRightMenu->setContentSize({ 26.75f*2, winSize.height - 10.f });
bottomRightMenu->setPosition(winSize.width - 26.75f, winSize.height / 2);
bottomRightMenu->setZOrder(2);
bottomRightMenu->setLayout(
ColumnLayout::create()
->setGap(7.f)
->setAxisAlignment(AxisAlignment::Start)
->setAxisReverse(true)
);
this->addChild(bottomRightMenu);

if(auto infoMenu = getChildByID("info-menu")) {
setIDSafe(infoMenu, 0, "info-button");

infoMenu->setContentSize({ 26.75f*2, winSize.height - 37.f });
infoMenu->setPositionY(winSize.height / 2);
infoMenu->setLayout(
ColumnLayout::create()
->setGap(7.f)
->setAxisAlignment(AxisAlignment::Start)
->setAxisReverse(true)
);
}
}

struct LeaderboardsLayerIDs : Modify<LeaderboardsLayerIDs, LeaderboardsLayer> {
static void onModify(auto& self) {
if (!self.setHookPriority("LeaderboardsLayer::init", GEODE_ID_PRIORITY)) {
log::warn("Failed to set LeaderboardsLayer::init hook priority, node IDs may not work properly");
}
}

bool init(LeaderboardState state) {
if (!LeaderboardsLayer::init(state)) return false;

NodeIDs::get()->provide(this);

return true;
}
};
Loading

0 comments on commit 11df388

Please sign in to comment.