mirror of
https://github.com/geode-sdk/geode.git
synced 2025-02-17 00:30:26 -05:00
Merge branch 'main' of https://github.com/geode-sdk/geode into main
This commit is contained in:
commit
d0ed9844be
2 changed files with 55 additions and 0 deletions
|
@ -737,6 +737,30 @@ namespace geode::cocos {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a node has the given sprite frame
|
||||
* name either in the sprite or in the sprite inside
|
||||
* the button.
|
||||
*
|
||||
* @param node Node to check
|
||||
* @param name Name of the sprite frame to search for
|
||||
* @returns True if the node has the given sprite frame
|
||||
* name
|
||||
*/
|
||||
bool isSpriteFrameName(cocos2d::CCNode* node, const char* name);
|
||||
|
||||
/**
|
||||
* Get the first child that has the given sprite frame
|
||||
* name either in the sprite or in the sprite inside
|
||||
* the button.
|
||||
*
|
||||
* @param parent Parent node to search in
|
||||
* @param name Name of the sprite frame to search for
|
||||
* @returns Child with the given sprite frame name, or
|
||||
* nullptr if there is none
|
||||
*/
|
||||
cocos2d::CCNode* getChildBySpriteFrameName(cocos2d::CCNode* parent, const char* name);
|
||||
|
||||
/**
|
||||
* Checks if a given file exists in CCFileUtils
|
||||
* search paths.
|
||||
|
|
|
@ -339,6 +339,37 @@ std::shared_ptr<WeakRefController> WeakRefPool::manage(CCObject* obj) {
|
|||
return m_pool.at(obj);
|
||||
}
|
||||
|
||||
bool geode::cocos::isSpriteFrameName(CCNode* node, const char* name) {
|
||||
auto cache = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name);
|
||||
if (!cache) return false;
|
||||
|
||||
auto* texture = cache->getTexture();
|
||||
auto rect = cache->getRect();
|
||||
|
||||
if (auto* spr = typeinfo_cast<CCSprite*>(node)) {
|
||||
if (spr->getTexture() == texture && spr->getTextureRect() == rect) {
|
||||
return true;
|
||||
}
|
||||
} else if (auto* btn = typeinfo_cast<CCMenuItemSprite*>(node)) {
|
||||
auto* img = btn->getNormalImage();
|
||||
if (auto* spr = typeinfo_cast<CCSprite*>(img)) {
|
||||
if (spr->getTexture() == texture && spr->getTextureRect() == rect) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
CCNode* geode::cocos::getChildBySpriteFrameName(CCNode* parent, const char* name) {
|
||||
for (auto child : CCArrayExt<CCNode*>(parent->getChildren())) {
|
||||
if (::isSpriteFrameName(static_cast<CCNode*>(child), name)) {
|
||||
return child;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CCRect geode::cocos::calculateNodeCoverage(std::vector<CCNode*> const& nodes) {
|
||||
CCRect coverage;
|
||||
for (auto child : nodes) {
|
||||
|
|
Loading…
Reference in a new issue