|
|
@ -23,16 +23,16 @@ void Menu::InitializeMenus(){ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Menu::AddButton(const MenuButton&button){ |
|
|
|
void Menu::AddComponent(MenuComponent*button){ |
|
|
|
buttons[button.rect.pos.y].push_back(button); |
|
|
|
buttons[button->rect.pos.y].push_back(button); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Menu::MenuSelect(Crawler*game){ |
|
|
|
void Menu::MenuSelect(Crawler*game){ |
|
|
|
if(selection==vi2d{-1,-1})return; |
|
|
|
if(selection==vi2d{-1,-1})return; |
|
|
|
buttons[selection.y][selection.x].onClick(*this,game); |
|
|
|
buttons[selection.y][selection.x]->onClick(*this,game); |
|
|
|
if(buttons[selection.y][selection.x].menuDest!=MenuType::ENUM_END){ |
|
|
|
if(buttons[selection.y][selection.x]->menuDest!=MenuType::ENUM_END){ |
|
|
|
if(stack.size()<32){ |
|
|
|
if(stack.size()<32){ |
|
|
|
stack.push_back(&menus[buttons[selection.y][selection.x].menuDest]);//Navigate to the next menu.
|
|
|
|
stack.push_back(&menus[buttons[selection.y][selection.x]->menuDest]);//Navigate to the next menu.
|
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|
std::cout<<"WARNING! Exceeded menu stack size limit!"<<std::endl; |
|
|
|
std::cout<<"WARNING! Exceeded menu stack size limit!"<<std::endl; |
|
|
|
throw; |
|
|
|
throw; |
|
|
@ -45,16 +45,16 @@ void Menu::Update(Crawler*game){ |
|
|
|
|
|
|
|
|
|
|
|
for(auto&key:buttons){ |
|
|
|
for(auto&key:buttons){ |
|
|
|
for(auto&button:key.second){ |
|
|
|
for(auto&button:key.second){ |
|
|
|
button.hovered=false; |
|
|
|
button->hovered=false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if(!MOUSE_NAVIGATION){ |
|
|
|
if(!MOUSE_NAVIGATION){ |
|
|
|
if(selection!=vi2d{-1,-1})buttons[selection.y][selection.x].hovered=true; |
|
|
|
if(selection!=vi2d{-1,-1})buttons[selection.y][selection.x]->hovered=true; |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|
for(auto&key:buttons){ |
|
|
|
for(auto&key:buttons){ |
|
|
|
for(auto&button:key.second){ |
|
|
|
for(auto&button:key.second){ |
|
|
|
if(geom2d::overlaps(geom2d::rect<float>{button.rect.pos+upperLeftPos,button.rect.size},game->GetMousePos())){ |
|
|
|
if(geom2d::overlaps(geom2d::rect<float>{button->rect.pos+upperLeftPos,button->rect.size},game->GetMousePos())){ |
|
|
|
button.hovered=true; |
|
|
|
button->hovered=true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -84,7 +84,7 @@ void Menu::Update(Crawler*game){ |
|
|
|
for(auto&key:buttons){ |
|
|
|
for(auto&key:buttons){ |
|
|
|
int index=0; |
|
|
|
int index=0; |
|
|
|
for(auto&button:key.second){ |
|
|
|
for(auto&button:key.second){ |
|
|
|
if(geom2d::overlaps(geom2d::rect<float>{button.rect.pos+upperLeftPos,button.rect.size},game->GetMousePos())){ |
|
|
|
if(geom2d::overlaps(geom2d::rect<float>{button->rect.pos+upperLeftPos,button->rect.size},game->GetMousePos())){ |
|
|
|
selection={index,key.first}; |
|
|
|
selection={index,key.first}; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -96,7 +96,7 @@ void Menu::Update(Crawler*game){ |
|
|
|
} |
|
|
|
} |
|
|
|
for(auto&key:buttons){ |
|
|
|
for(auto&key:buttons){ |
|
|
|
for(auto&button:key.second){ |
|
|
|
for(auto&button:key.second){ |
|
|
|
button.Update(game); |
|
|
|
button->Update(game); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
@ -106,7 +106,7 @@ void Menu::Draw(Crawler*game){ |
|
|
|
game->FillRectDecal(upperLeftPos,size,VERY_DARK_BLUE); |
|
|
|
game->FillRectDecal(upperLeftPos,size,VERY_DARK_BLUE); |
|
|
|
for(auto&key:buttons){ |
|
|
|
for(auto&key:buttons){ |
|
|
|
for(auto&button:key.second){ |
|
|
|
for(auto&button:key.second){ |
|
|
|
button.Draw(game,upperLeftPos); |
|
|
|
button->Draw(game,upperLeftPos); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
@ -141,11 +141,11 @@ void Menu::KeyboardButtonNavigation(Crawler*game){ |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|
for(auto&key:buttons){ |
|
|
|
for(auto&key:buttons){ |
|
|
|
if(found){ //Once we discover the previous element, the next element becomes our next selection.
|
|
|
|
if(found){ //Once we discover the previous element, the next element becomes our next selection.
|
|
|
|
int previousButtonX=buttons[selection.y][selection.x].rect.pos.x; |
|
|
|
int previousButtonX=buttons[selection.y][selection.x]->rect.pos.x; |
|
|
|
selection.y=key.first; |
|
|
|
selection.y=key.first; |
|
|
|
int index=0; |
|
|
|
int index=0; |
|
|
|
for(auto&button:key.second){ //Try to match a button in the same column as this button first.
|
|
|
|
for(auto&button:key.second){ //Try to match a button in the same column as this button first.
|
|
|
|
if(previousButtonX==button.rect.pos.x){ |
|
|
|
if(previousButtonX==button->rect.pos.x){ |
|
|
|
selection.x=index; |
|
|
|
selection.x=index; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -183,11 +183,11 @@ void Menu::KeyboardButtonNavigation(Crawler*game){ |
|
|
|
prevInd=key.first; |
|
|
|
prevInd=key.first; |
|
|
|
} |
|
|
|
} |
|
|
|
if(prevInd!=-1){ |
|
|
|
if(prevInd!=-1){ |
|
|
|
int previousButtonX=buttons[selection.y][selection.x].rect.pos.x; |
|
|
|
int previousButtonX=buttons[selection.y][selection.x]->rect.pos.x; |
|
|
|
selection.y=prevInd; |
|
|
|
selection.y=prevInd; |
|
|
|
int index=0; |
|
|
|
int index=0; |
|
|
|
for(auto&button:buttons[prevInd]){ //Try to match a button in the same column as this button first.
|
|
|
|
for(auto&button:buttons[prevInd]){ //Try to match a button in the same column as this button first.
|
|
|
|
if(previousButtonX==button.rect.pos.x){ |
|
|
|
if(previousButtonX==button->rect.pos.x){ |
|
|
|
selection.x=index; |
|
|
|
selection.x=index; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|