diff --git a/src/hooks/LevelCell.cpp b/src/hooks/LevelCell.cpp index d199572..dc57f46 100644 --- a/src/hooks/LevelCell.cpp +++ b/src/hooks/LevelCell.cpp @@ -8,10 +8,94 @@ using namespace geode::prelude; class $modify(BILevelCell, LevelCell) { + int m_hoverCount = 0; + CCPoint m_lastMousePos = {0,0}; + CCNode* m_levelDesc = nullptr; + static void onModify(auto& self) { auto res = self.setHookPriority("LevelCell::onViewProfile", 99999); } + void showDesc() { + if(m_fields->m_levelDesc) return; + + auto parent = CCSprite::create(); + parent->setID("bi-leveldesc"); + + /*auto bg = CCScale9Sprite::create("square02b_small.png", { 0, 0, 40, 40 }); + bg->setColor({ 0, 0, 0 }); + parent->addChild(bg); + + auto label = CCLabelBMFont::create(m_level->m_levelDesc.c_str(), "bigFont.fnt"); + label->setScale(.6f); + parent->addChild(label);*/ + + cocos2d::extension::CCScale9Sprite* descBg = cocos2d::extension::CCScale9Sprite::create("square02b_001.png", { 0.0f, 0.0f, 80.0f, 80.0f }); + descBg->setContentSize({340,55}); + descBg->setColor({130,64,33}); + descBg->setColor({0,0,0}); + descBg->setOpacity(230); + parent->addChild(descBg, -1); + descBg->setPosition({0,52}); + + auto descText = BetterInfo::fixNullByteCrash(BetterInfo::fixColorCrashes(m_level->getUnpackedLevelDescription())); + size_t descLength = descText.length(); + float descDelimiter = 1; + if(descLength > 140) descLength = 140; + if(descLength > 70) descDelimiter = ((((140 - descLength) / 140) * 0.3f) + 0.7f); + auto description = TextArea::create(descText, "chatFont.fnt", 1, 295 / descDelimiter, {0.5f,0.5f}, 20, false); + description->setScale(descDelimiter); + description->setAnchorPoint({1,1}); + description->setPosition( ( (description->getContentSize() / 2 ) * descDelimiter ) + (CCPoint(340,55) / 2) ); + auto descSprite = CCSprite::create(); + descSprite->addChild(description); + descSprite->setContentSize({340,55}); + descSprite->setPosition({0,52}); + parent->addChild(descSprite); + + auto winSize = CCDirector::sharedDirector()->getWinSize(); + CCScene::get()->addChild(parent); + parent->setPositionX(winSize.width / 2); + m_fields->m_levelDesc = parent; + + description->setOpacity(0); + description->runAction(CCFadeTo::create(0.3f, 255)); + description->setID("bi-leveldesc-area"); + + descBg->setOpacity(0); + descBg->runAction(CCFadeTo::create(0.3f, 230)); + descBg->setID("bi-leveldesc-bg"); + } + + void hideDesc() { + if(!m_fields->m_levelDesc) return; + + auto description = static_cast(m_fields->m_levelDesc->getChildByIDRecursive("bi-leveldesc-area")); + auto descBg = static_cast(m_fields->m_levelDesc->getChildByIDRecursive("bi-leveldesc-bg")); + + //m_fields->m_levelDesc->removeFromParentAndCleanup(true); + if(description) description->runAction(CCFadeTo::create(0.3f, 0)); + if(descBg) descBg->runAction(CCFadeTo::create(0.3f, 0)); + + m_fields->m_levelDesc = nullptr; + } + + void checkHover(float dt) { + if(getMousePos() == m_lastMousePos && BetterInfo::isHoveringNode(this) && typeinfo_cast(CCScene::get()) == nullptr) { + m_hoverCount++; + + if(m_hoverCount == 3) { + log::info("Hovering: {}", m_level->m_levelName); + showDesc(); + } + } else { + m_hoverCount = 0; + hideDesc(); + }; + + m_lastMousePos = getMousePos(); + } + /* * Hooks */ @@ -33,6 +117,8 @@ class $modify(BILevelCell, LevelCell) { LevelCell::loadCustomLevelCell(); + this->getScheduler()->scheduleSelector(schedule_selector(BILevelCell::checkHover), this, 0.1f, false); + auto layer = static_cast(this->getChildren()->objectAtIndex(1)); bool menuDone = false; diff --git a/src/utils.cpp b/src/utils.cpp index e88f4e3..0dd37ec 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -604,4 +604,23 @@ void BetterInfo::loadImportantNotices(CCLayer* layer) { }).expect([](const std::string& error){ log::warn("Fetching important notices failed: {}", error); }); +} + +//from coloride on geode sdk discord +bool BetterInfo::isHoveringNode(CCNode* target) { + CCPoint touchPos = getMousePos(); + + CCPoint targetWorldPos = target->getParent()->convertToWorldSpace(target->getPosition()); + auto targetSize = target->getContentSize(); + auto targetScale = target->getScale(); + auto anchorPoint = target->getAnchorPoint(); + + CCRect bounds = CCRect( + targetWorldPos.x,// - targetSize.width * targetScale * anchorPoint.x, + targetWorldPos.y,// - targetSize.height * targetScale * anchorPoint.y, + targetSize.width * targetScale, + targetSize.height * targetScale + ); + + return bounds.containsPoint(touchPos); } \ No newline at end of file diff --git a/src/utils.hpp b/src/utils.hpp index a6a38b6..e3aa4da 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -59,4 +59,5 @@ namespace BetterInfo { bool controllerConnected(); void loadImportantNotices(CCLayer* layer); + bool isHoveringNode(CCNode* target); } \ No newline at end of file