|
|
|
@ -13,6 +13,8 @@ const vf2d Menu::CENTERED = {-456,-456}; |
|
|
|
|
INCLUDE_GFX |
|
|
|
|
extern vi2d WINDOW_SIZE; |
|
|
|
|
|
|
|
|
|
typedef Attribute A; |
|
|
|
|
|
|
|
|
|
Menu::Menu(){} |
|
|
|
|
|
|
|
|
|
Menu::Menu(vf2d pos,vf2d size) |
|
|
|
@ -80,7 +82,7 @@ void Menu::MenuSelect(Crawler*game){ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Menu::Update(Crawler*game){ |
|
|
|
|
if(draggingComponent==nullptr&&(((!MOUSE_NAVIGATION&&(game->GetKey(ENTER).bHeld)||game->GetKey(SPACE).bHeld))||game->GetMouse(Mouse::LEFT).bHeld)){ |
|
|
|
|
if(draggingComponent==nullptr&&selection!=vi2d{-1,-1}&&(((!MOUSE_NAVIGATION&&(game->GetKey(ENTER).bHeld)||game->GetKey(SPACE).bHeld))||game->GetMouse(Mouse::LEFT).bHeld)){ |
|
|
|
|
buttonHoldTime+=game->GetElapsedTime(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -98,6 +100,7 @@ void Menu::Update(Crawler*game){ |
|
|
|
|
if(!MOUSE_NAVIGATION){ |
|
|
|
|
if(selection!=vi2d{-1,-1})buttons[selection.y][selection.x]->hovered=true; |
|
|
|
|
}else{ |
|
|
|
|
selection={-1,-1}; |
|
|
|
|
for(auto&key:buttons){ |
|
|
|
|
int index=0; |
|
|
|
|
for(auto&button:key.second){ |
|
|
|
@ -201,7 +204,11 @@ void Menu::Draw(Crawler*game){ |
|
|
|
|
vf2d offsetPos=draggingComponent->rect.pos; |
|
|
|
|
if(!MOUSE_NAVIGATION){ |
|
|
|
|
MenuComponent*selectedComponent=buttons[selection.y][selection.x]; |
|
|
|
|
draggingComponent->Draw(game,pos-offsetPos+selectedComponent->rect.pos+vi2d{1,-4},this==Menu::stack.back()); |
|
|
|
|
vf2d drawOffset{}; |
|
|
|
|
if(selectedComponent->parentComponent!=nullptr){ |
|
|
|
|
drawOffset+=selectedComponent->parentComponent->V(A::SCROLL_OFFSET); |
|
|
|
|
} |
|
|
|
|
draggingComponent->Draw(game,drawOffset+pos-offsetPos+selectedComponent->rect.pos+vi2d{1,-4},this==Menu::stack.back()); |
|
|
|
|
}else{ |
|
|
|
|
draggingComponent->Draw(game,-offsetPos+game->GetMousePos(),this==Menu::stack.back()); |
|
|
|
|
} |
|
|
|
@ -211,7 +218,11 @@ void Menu::Draw(Crawler*game){ |
|
|
|
|
game->DrawDecal({0,0},overlay.Decal()); |
|
|
|
|
if(!MOUSE_NAVIGATION){ |
|
|
|
|
MenuComponent*selectedComponent=buttons[selection.y][selection.x]; |
|
|
|
|
draggingComponent->DrawDecal(game,pos-offsetPos+selectedComponent->rect.pos+vi2d{1,-4},this==Menu::stack.back()); |
|
|
|
|
vf2d drawOffset{}; |
|
|
|
|
if(selectedComponent->parentComponent!=nullptr){ |
|
|
|
|
drawOffset+=selectedComponent->parentComponent->V(A::SCROLL_OFFSET); |
|
|
|
|
} |
|
|
|
|
draggingComponent->DrawDecal(game,drawOffset+pos-offsetPos+selectedComponent->rect.pos+vi2d{1,-4},this==Menu::stack.back()); |
|
|
|
|
}else{ |
|
|
|
|
draggingComponent->DrawDecal(game,-offsetPos+game->GetMousePos(),this==Menu::stack.back()); |
|
|
|
|
} |
|
|
|
@ -340,10 +351,12 @@ void Menu::KeyboardButtonNavigation(Crawler*game,vf2d menuPos){ |
|
|
|
|
for(auto&key:buttons){ |
|
|
|
|
int index=0; |
|
|
|
|
for(auto&button:key.second){ |
|
|
|
|
if(!button->disabled){ |
|
|
|
|
if(geom2d::overlaps(geom2d::rect<float>{button->rect.pos+menuPos,button->rect.size},game->GetMousePos())){ |
|
|
|
|
selection={index,key.first}; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
index++; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|