|
|
|
@ -55,9 +55,10 @@ void Menu::CheckClickAndPerformMenuSelect(Crawler*game){ |
|
|
|
|
void Menu::HoverMenuSelect(Crawler*game){ |
|
|
|
|
if(selection==vi2d{-1,-1})return; |
|
|
|
|
if(buttons[selection.y][selection.x]->draggable) |
|
|
|
|
if(buttonHoldTime<0.3)CheckClickAndPerformMenuSelect(game); |
|
|
|
|
if(buttonHoldTime<"ThemeGlobal.MenuHoldTime"_F)CheckClickAndPerformMenuSelect(game); |
|
|
|
|
else{ |
|
|
|
|
draggingComponent=buttons[selection.y][selection.x]; |
|
|
|
|
draggingComponent=buttons[selection.y][selection.x]->PickUpDraggableItem(); |
|
|
|
|
buttonHoldTime=0; |
|
|
|
|
} |
|
|
|
|
else CheckClickAndPerformMenuSelect(game); |
|
|
|
|
} |
|
|
|
@ -76,11 +77,13 @@ void Menu::MenuSelect(Crawler*game){ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Menu::Update(Crawler*game){ |
|
|
|
|
if(draggingComponent!=nullptr&&(!MOUSE_NAVIGATION||game->GetMouse(Mouse::LEFT).bHeld)){ |
|
|
|
|
if(draggingComponent==nullptr&&(((!MOUSE_NAVIGATION&&(game->GetKey(ENTER).bHeld)||game->GetKey(SPACE).bHeld))||game->GetMouse(Mouse::LEFT).bHeld)){ |
|
|
|
|
buttonHoldTime+=game->GetElapsedTime(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
HoverMenuSelect(game); |
|
|
|
|
if(draggingComponent==nullptr){ |
|
|
|
|
HoverMenuSelect(game); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for(auto&key:buttons){ |
|
|
|
|
for(auto&button:key.second){ |
|
|
|
@ -91,9 +94,30 @@ void Menu::Update(Crawler*game){ |
|
|
|
|
if(selection!=vi2d{-1,-1})buttons[selection.y][selection.x]->hovered=true; |
|
|
|
|
}else{ |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
index++; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(draggingComponent!=nullptr&&selection!=vi2d{-1,-1}){ |
|
|
|
|
MenuComponent*selectedComponent=buttons[selection.y][selection.x]; |
|
|
|
|
if(!MOUSE_NAVIGATION){ |
|
|
|
|
if(game->GetKey(ENTER).bReleased||game->GetKey(SPACE).bReleased){ |
|
|
|
|
if(selectedComponent->DropDraggableItem(draggingComponent)){ |
|
|
|
|
draggingComponent=nullptr; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
if(game->GetMouse(Mouse::LEFT).bReleased){ |
|
|
|
|
if(selectedComponent->DropDraggableItem(draggingComponent)){ |
|
|
|
|
draggingComponent=nullptr; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -126,6 +150,16 @@ void Menu::Draw(Crawler*game){ |
|
|
|
|
for(auto&component:displayComponents){ |
|
|
|
|
component->Draw(game,pos,this==Menu::stack.back()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(draggingComponent!=nullptr){ |
|
|
|
|
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()); |
|
|
|
|
}else{ |
|
|
|
|
draggingComponent->Draw(game,-offsetPos+game->GetMousePos(),this==Menu::stack.back()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
void Menu::OpenMenu(MenuType menu){ |
|
|
|
|