Skip to content

Commit

Permalink
Better cheated button hover thingy
Browse files Browse the repository at this point in the history
  • Loading branch information
Alphalaneous committed May 21, 2024
1 parent 7b7ec8a commit e6d4156
Showing 1 changed file with 41 additions and 6 deletions.
47 changes: 41 additions & 6 deletions src/nodes/CCMenuItemSpriteExtra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ CCMenuItemSpriteExtra* EventCCMenuItemSpriteExtra::create(cocos2d::CCNode* p0, c
return ret;
}



void EventCCMenuItemSpriteExtra::checkTouch(float dt){

CCPoint point = getMousePos();
Expand All @@ -93,14 +95,47 @@ void EventCCMenuItemSpriteExtra::checkTouch(float dt){

bool containsPoint = r.containsPoint(local);

if (containsPoint && !m_fields->isHovering && nodeIsVisible(this)) {
m_fields->isHovering = true;
runOnHover();
return;
CCScene* currentScene = CCDirector::get()->getRunningScene();
CCNode* buttonLayer;

for(CCNode* node : CCArrayExt<CCNode*>(currentScene->getChildren())){
if(node->getChildrenCount() > 1){
buttonLayer = node;
break;
}
}

bool hasLayerOnTop = false;
bool doCheck = false;
for(CCNode* node : CCArrayExt<CCNode*>(currentScene->getChildren())){
if(node == buttonLayer) {
doCheck = true;
continue;
}
if(doCheck){
if(node->getContentSize() != CCSize{0,0} && node->isVisible()){
hasLayerOnTop = true;
break;
}
}
}

if(getChildOfType<GJDropDownLayer>(buttonLayer, 0)){
hasLayerOnTop = true;
}

if(!hasLayerOnTop){
if (containsPoint && !m_fields->isHovering && nodeIsVisible(this)) {
m_fields->isHovering = true;
runOnHover();
}
if (!containsPoint && m_fields->isHovering){
m_fields->isHovering = false;
runOnExit();
}
}
if (!containsPoint && m_fields->isHovering){
else{
m_fields->isHovering = false;
runOnExit();
return;
}
}

0 comments on commit e6d4156

Please sign in to comment.