Implement parent component hover state handling.

This commit is contained in:
2023-10-12 19:35:16 -05:00
parent 1c4ec84d75
commit 18db45e6c3
5 changed files with 86 additions and 21 deletions
+23 -14
View File
@@ -56,7 +56,7 @@ void Menu::CheckClickAndPerformMenuSelect(Crawler*game){
}
void Menu::HoverMenuSelect(Crawler*game){
if(selection==vi2d{-1,-1})return;
if(selection==vi2d{-1,-1}||buttons[selection.y][selection.x]->disabled)return;
if(buttons[selection.y][selection.x]->draggable)
if(buttonHoldTime<"ThemeGlobal.MenuHoldTime"_F)CheckClickAndPerformMenuSelect(game);
else{
@@ -67,7 +67,7 @@ void Menu::HoverMenuSelect(Crawler*game){
}
void Menu::MenuSelect(Crawler*game){
if(selection==vi2d{-1,-1})return;
if(selection==vi2d{-1,-1}||buttons[selection.y][selection.x]->disabled)return;
buttons[selection.y][selection.x]->onClick(MenuFuncData{*this,game,buttons[selection.y][selection.x]});
if(buttons[selection.y][selection.x]->menuDest!=MenuType::ENUM_END){
if(stack.size()<32){
@@ -90,7 +90,9 @@ void Menu::Update(Crawler*game){
for(auto&key:buttons){
for(auto&button:key.second){
button->hovered=false;
if(!button->disabled){
button->hovered=false;
}
}
}
if(!MOUSE_NAVIGATION){
@@ -99,12 +101,14 @@ void Menu::Update(Crawler*game){
for(auto&key:buttons){
int index=0;
for(auto&button:key.second){
if(geom2d::overlaps(geom2d::rect<float>{button->rect.pos+pos,button->rect.size},game->GetMousePos())){
button->hovered=true;
selection.y=key.first;
selection.x=index;
if(!button->disabled){
if(button->GetHoverState(game)){
button->hovered=true;
selection.y=key.first;
selection.x=index;
}
index++;
}
index++;
}
}
}
@@ -132,13 +136,13 @@ void Menu::Update(Crawler*game){
for(auto&key:buttons){
for(auto&button:key.second){
if(button->renderInMain){
button->Update(game);
button->_Update(game);
}
}
}
for(auto&component:displayComponents){
if(component->renderInMain){
component->Update(game);
component->_Update(game);
}
}
};
@@ -157,13 +161,13 @@ void Menu::Draw(Crawler*game){
for(auto&key:buttons){
for(auto&button:key.second){
if(button->renderInMain){
button->Draw(game,{0,0},this==Menu::stack.back());
button->_Draw(game,{0,0},this==Menu::stack.back());
}
}
}
for(auto&component:displayComponents){
if(component->renderInMain){
component->Draw(game,{0,0},this==Menu::stack.back());
component->_Draw(game,{0,0},this==Menu::stack.back());
}
}
game->SetPixelMode(prevMode);
@@ -173,13 +177,13 @@ void Menu::Draw(Crawler*game){
for(auto&key:buttons){
for(auto&button:key.second){
if(button->renderInMain){
button->DrawDecal(game,pos,this==Menu::stack.back());
button->_DrawDecal(game,pos,this==Menu::stack.back());
}
}
}
for(auto&component:displayComponents){
if(component->renderInMain){
component->DrawDecal(game,pos,this==Menu::stack.back());
component->_DrawDecal(game,pos,this==Menu::stack.back());
}
}
@@ -220,6 +224,7 @@ void Menu::OpenMenu(MenuType menu){
}
void Menu::KeyboardButtonNavigation(Crawler*game,vf2d menuPos){
vi2d prevSelection=selection;
if(game->GetKey(RIGHT).bPressed){
if(selection==vi2d{-1,-1})return;
MOUSE_NAVIGATION=false;
@@ -345,6 +350,10 @@ void Menu::KeyboardButtonNavigation(Crawler*game,vf2d menuPos){
buttonHoldTime=0;
}
}
if(prevSelection!=selection){
if(selection!=vi2d{-1,-1}&&buttons[selection.y][selection.x]->disabled)selection=prevSelection;
// If the new selection of a button on this frame is disabled for some reason, we need to go back to what we had selected before.
}
}
void Menu::DrawScaledWindowBorder(Crawler*game,vf2d menuPos){