Fully implemented controller/keyboard controls for Inventory Consumable Window. Fix bug with loadout items that were set during file loads were not selected in consumable window. Release Build 6907.
This commit is contained in:
@@ -88,10 +88,20 @@ void Menu::InitializeConsumableInventoryWindow(){
|
||||
|
||||
inventoryWindow->SetupKeyboardNavigation(
|
||||
[](MenuType type,Data&returnData){ //On Open
|
||||
//Get the first component in the consumables list.
|
||||
//Try to find the component that matches the loadout item we have on us.
|
||||
std::vector<std::weak_ptr<MenuComponent>>&components=Component<InventoryScrollableWindowComponent>(INVENTORY_CONSUMABLES,"inventory")->GetComponents();
|
||||
auto inventory=Component<InventoryScrollableWindowComponent>(INVENTORY_CONSUMABLES,"inventory");
|
||||
auto foundComponent=std::find_if(components.begin(),components.end(),[&](auto&component){
|
||||
if(!ISBLANK(DYNAMIC_POINTER_CAST<MenuItemButton>(component)->GetItem().lock())&&DYNAMIC_POINTER_CAST<MenuItemButton>(component)->GetItem().lock()->ActualName()==game->GetLoadoutItem(Menu::menus[type]->I(A::LOADOUT_SLOT)).lock()->ActualName()){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
if(foundComponent!=components.end()){
|
||||
returnData=*foundComponent;
|
||||
}else
|
||||
if(components.size()>0){
|
||||
returnData=components[0].lock()->GetName();
|
||||
returnData=components.front();
|
||||
}else{
|
||||
returnData="OK Button";
|
||||
}
|
||||
@@ -103,17 +113,37 @@ void Menu::InitializeConsumableInventoryWindow(){
|
||||
}}},
|
||||
}
|
||||
,{ //Button Navigation Rules
|
||||
{"OK Button",{
|
||||
.up=[](MenuType type,Data&returnData){
|
||||
auto&itemsList=Component<InventoryScrollableWindowComponent>(type,"inventory")->GetComponents();
|
||||
if(itemsList.size()>0){
|
||||
returnData=itemsList.back();
|
||||
}
|
||||
},
|
||||
.down=[](MenuType type,Data&returnData){
|
||||
auto&itemsList=Component<InventoryScrollableWindowComponent>(type,"inventory")->GetComponents();
|
||||
if(itemsList.size()>0){
|
||||
returnData=itemsList.front();
|
||||
}
|
||||
},
|
||||
.left=[](MenuType type,Data&returnData){
|
||||
auto&itemsList=Component<InventoryScrollableWindowComponent>(type,"inventory")->GetComponents();
|
||||
if(itemsList.size()>0){
|
||||
returnData=itemsList.back();
|
||||
}
|
||||
},
|
||||
.right=[](MenuType type,Data&returnData){
|
||||
auto&itemsList=Component<InventoryScrollableWindowComponent>(type,"inventory")->GetComponents();
|
||||
if(itemsList.size()>0){
|
||||
returnData=itemsList.front();
|
||||
}
|
||||
},
|
||||
}},
|
||||
{"inventory",{
|
||||
.up="Quit Game Button",
|
||||
.down="Load Game Button",}},
|
||||
{"Load Game Button",{
|
||||
.up="New Game Button",
|
||||
.down="Quit Game Button",}},
|
||||
{"Quit Game Button",{
|
||||
.up=[](MenuType type,Data&returnData){
|
||||
auto&selection=Menu::menus[type]->GetSelection();
|
||||
auto&itemsList=Component<InventoryScrollableWindowComponent>(type,"inventory")->GetComponents();
|
||||
auto itemsWindow=Component<InventoryScrollableWindowComponent>(type,"inventory")
|
||||
auto itemsWindow=Component<InventoryScrollableWindowComponent>(type,"inventory");
|
||||
auto component=std::find_if(itemsList.begin(),itemsList.end(),[&](auto&comp){return comp.lock()==selection.lock();});
|
||||
if(itemsList.size()>0){
|
||||
if(component==itemsList.end()){
|
||||
@@ -121,44 +151,18 @@ void Menu::InitializeConsumableInventoryWindow(){
|
||||
returnData=itemsList.back();
|
||||
}else{
|
||||
int invWidth=int((itemsWindow->rect.size.x-12)/(float(itemsWindow->options.size.x)+itemsWindow->options.padding));
|
||||
std::weak_ptr<MenuItemButton>selectedButton=DYNAMIC_POINTER_CAST<MenuItemButton>(component);
|
||||
std::weak_ptr<MenuItemButton>selectedButton=DYNAMIC_POINTER_CAST<MenuItemButton>(*component);
|
||||
int newRowIndex=selectedButton.lock()->inventoryIndex-invWidth; //Moving up moves the cursor up an entire row.
|
||||
if(newRowIndex<0){
|
||||
//This means we have to wrap around.
|
||||
newRowIndex+=itemsList.size();
|
||||
returnData="OK Button";
|
||||
return;
|
||||
}
|
||||
if(newRowIndex<0||newRowIndex>=itemsList.size())ERR(std::format("New Row Index ended up out-of-bounds! newRowIndex={}. THIS SHOULD NOT BE HAPPENING!",newRowIndex));
|
||||
//Select the component that matches this new number.
|
||||
auto component=std::find_if(itemsList.begin(),itemsList.end(),[&](auto&comp){return DYNAMIC_POINTER_CAST<MenuItemButton>(comp).lock()->inventoryIndex==newRowIndex;});
|
||||
auto component=std::find_if(itemsList.begin(),itemsList.end(),[&](auto&comp){return DYNAMIC_POINTER_CAST<MenuItemButton>(comp)->inventoryIndex==newRowIndex;});
|
||||
if(component==itemsList.end())ERR(std::format("WARNING! Could not find row index {} in items list while navigating! THIS SHOULD NOT BE HAPPENING!",newRowIndex));
|
||||
returnData=component;
|
||||
}
|
||||
}else{
|
||||
returnData="OK Button";
|
||||
}
|
||||
},
|
||||
.right=[](MenuType type,Data&returnData){
|
||||
auto&selection=Menu::menus[type]->GetSelection();
|
||||
auto&itemsList=Component<InventoryScrollableWindowComponent>(type,"inventory")->GetComponents();
|
||||
auto itemsWindow=Component<InventoryScrollableWindowComponent>(type,"inventory")
|
||||
auto component=std::find_if(itemsList.begin(),itemsList.end(),[&](auto&comp){return comp.lock()==selection.lock();});
|
||||
if(itemsList.size()>0){
|
||||
if(component==itemsList.end()){
|
||||
//Set the selected button to the first element in the list.
|
||||
returnData=itemsList.front();
|
||||
}else{
|
||||
int invWidth=int((itemsWindow->rect.size.x-12)/(float(itemsWindow->options.size.x)+itemsWindow->options.padding));
|
||||
std::weak_ptr<MenuItemButton>selectedButton=DYNAMIC_POINTER_CAST<MenuItemButton>(component);
|
||||
int newRowIndex=std::clamp(selectedButton.lock()->inventoryIndex+1,(selectedButton.lock()->inventoryIndex/invWidth)*invWidth,std::min(itemsList.size(),(selectedButton.lock()->inventoryIndex/invWidth+1)*invWidth-1)); //Moving right, we need to wrap around if we get to the edge.
|
||||
if(newRowIndex>=itemsList.size()){
|
||||
//This means we have to wrap around.
|
||||
newRowIndex-=itemsList.size();
|
||||
}
|
||||
if(newRowIndex<0||newRowIndex>=itemsList.size())ERR(std::format("New Row Index ended up out-of-bounds! newRowIndex={}. THIS SHOULD NOT BE HAPPENING!",newRowIndex));
|
||||
//Select the component that matches this new number.
|
||||
auto component=std::find_if(itemsList.begin(),itemsList.end(),[&](auto&comp){return DYNAMIC_POINTER_CAST<MenuItemButton>(comp).lock()->inventoryIndex==newRowIndex;});
|
||||
if(component==itemsList.end())ERR(std::format("WARNING! Could not find row index {} in items list while navigating! THIS SHOULD NOT BE HAPPENING!",newRowIndex));
|
||||
returnData=component;
|
||||
returnData=*component;
|
||||
}
|
||||
}else{
|
||||
returnData="OK Button";
|
||||
@@ -167,7 +171,7 @@ void Menu::InitializeConsumableInventoryWindow(){
|
||||
.down=[](MenuType type,Data&returnData){
|
||||
auto&selection=Menu::menus[type]->GetSelection();
|
||||
auto&itemsList=Component<InventoryScrollableWindowComponent>(type,"inventory")->GetComponents();
|
||||
auto itemsWindow=Component<InventoryScrollableWindowComponent>(type,"inventory")
|
||||
auto itemsWindow=Component<InventoryScrollableWindowComponent>(type,"inventory");
|
||||
auto component=std::find_if(itemsList.begin(),itemsList.end(),[&](auto&comp){return comp.lock()==selection.lock();});
|
||||
if(itemsList.size()>0){
|
||||
if(component==itemsList.end()){
|
||||
@@ -175,17 +179,18 @@ void Menu::InitializeConsumableInventoryWindow(){
|
||||
returnData=itemsList.front();
|
||||
}else{
|
||||
int invWidth=int((itemsWindow->rect.size.x-12)/(float(itemsWindow->options.size.x)+itemsWindow->options.padding));
|
||||
std::weak_ptr<MenuItemButton>selectedButton=DYNAMIC_POINTER_CAST<MenuItemButton>(component);
|
||||
std::weak_ptr<MenuItemButton>selectedButton=DYNAMIC_POINTER_CAST<MenuItemButton>(*component);
|
||||
int newRowIndex=selectedButton.lock()->inventoryIndex+invWidth; //Moving down moves the cursor down an entire row.
|
||||
if(newRowIndex>=itemsList.size()){
|
||||
//This means we have to wrap around.
|
||||
newRowIndex-=itemsList.size();
|
||||
returnData="OK Button";
|
||||
return;
|
||||
}
|
||||
if(newRowIndex<0||newRowIndex>=itemsList.size())ERR(std::format("New Row Index ended up out-of-bounds! newRowIndex={}. THIS SHOULD NOT BE HAPPENING!",newRowIndex));
|
||||
//Select the component that matches this new number.
|
||||
auto component=std::find_if(itemsList.begin(),itemsList.end(),[&](auto&comp){return DYNAMIC_POINTER_CAST<MenuItemButton>(comp).lock()->inventoryIndex==newRowIndex;});
|
||||
auto component=std::find_if(itemsList.begin(),itemsList.end(),[&](auto&comp){return DYNAMIC_POINTER_CAST<MenuItemButton>(comp)->inventoryIndex==newRowIndex;});
|
||||
if(component==itemsList.end())ERR(std::format("WARNING! Could not find row index {} in items list while navigating! THIS SHOULD NOT BE HAPPENING!",newRowIndex));
|
||||
returnData=component;
|
||||
returnData=*component;
|
||||
}
|
||||
}else{
|
||||
returnData="OK Button";
|
||||
@@ -194,7 +199,7 @@ void Menu::InitializeConsumableInventoryWindow(){
|
||||
.left=[](MenuType type,Data&returnData){
|
||||
auto&selection=Menu::menus[type]->GetSelection();
|
||||
auto&itemsList=Component<InventoryScrollableWindowComponent>(type,"inventory")->GetComponents();
|
||||
auto itemsWindow=Component<InventoryScrollableWindowComponent>(type,"inventory")
|
||||
auto itemsWindow=Component<InventoryScrollableWindowComponent>(type,"inventory");
|
||||
auto component=std::find_if(itemsList.begin(),itemsList.end(),[&](auto&comp){return comp.lock()==selection.lock();});
|
||||
if(itemsList.size()>0){
|
||||
if(component==itemsList.end()){
|
||||
@@ -202,18 +207,48 @@ void Menu::InitializeConsumableInventoryWindow(){
|
||||
returnData=itemsList.back();
|
||||
}else{
|
||||
int invWidth=int((itemsWindow->rect.size.x-12)/(float(itemsWindow->options.size.x)+itemsWindow->options.padding));
|
||||
std::weak_ptr<MenuItemButton>selectedButton=DYNAMIC_POINTER_CAST<MenuItemButton>(component);
|
||||
|
||||
int newRowIndex=std::clamp(selectedButton.lock()->inventoryIndex-1,(selectedButton.lock()->inventoryIndex/invWidth)*invWidth,std::min(itemsList.size(),(selectedButton.lock()->inventoryIndex/invWidth+1)*invWidth-1)); //Moving left, we need to wrap around if we get to the edge.
|
||||
std::weak_ptr<MenuItemButton>selectedButton=DYNAMIC_POINTER_CAST<MenuItemButton>(*component);
|
||||
|
||||
int rowBaseIndex=(selectedButton.lock()->inventoryIndex/invWidth)*invWidth;
|
||||
int newRowIndex=selectedButton.lock()->inventoryIndex-1;
|
||||
if(newRowIndex<rowBaseIndex)newRowIndex+=invWidth;
|
||||
newRowIndex=std::min(int(itemsList.size())-1,newRowIndex);
|
||||
if(newRowIndex<0){
|
||||
//This means we have to wrap around.
|
||||
newRowIndex+=itemsList.size();
|
||||
}
|
||||
if(newRowIndex<0||newRowIndex>=itemsList.size())ERR(std::format("New Row Index ended up out-of-bounds! newRowIndex={}. THIS SHOULD NOT BE HAPPENING!",newRowIndex));
|
||||
//Select the component that matches this new number.
|
||||
auto component=std::find_if(itemsList.begin(),itemsList.end(),[&](auto&comp){return DYNAMIC_POINTER_CAST<MenuItemButton>(comp).lock()->inventoryIndex==newRowIndex;});
|
||||
auto component=std::find_if(itemsList.begin(),itemsList.end(),[&](auto&comp){return DYNAMIC_POINTER_CAST<MenuItemButton>(comp)->inventoryIndex==newRowIndex;});
|
||||
if(component==itemsList.end())ERR(std::format("WARNING! Could not find row index {} in items list while navigating! THIS SHOULD NOT BE HAPPENING!",newRowIndex));
|
||||
returnData=component;
|
||||
returnData=*component;
|
||||
}
|
||||
}else{
|
||||
returnData="OK Button";
|
||||
}
|
||||
},
|
||||
.right=[](MenuType type,Data&returnData){
|
||||
auto&selection=Menu::menus[type]->GetSelection();
|
||||
auto&itemsList=Component<InventoryScrollableWindowComponent>(type,"inventory")->GetComponents();
|
||||
auto itemsWindow=Component<InventoryScrollableWindowComponent>(type,"inventory");
|
||||
auto component=std::find_if(itemsList.begin(),itemsList.end(),[&](auto&comp){return comp.lock()==selection.lock();});
|
||||
if(itemsList.size()>0){
|
||||
if(component==itemsList.end()){
|
||||
//Set the selected button to the first element in the list.
|
||||
returnData=itemsList.front();
|
||||
}else{
|
||||
int invWidth=int((itemsWindow->rect.size.x-12)/(float(itemsWindow->options.size.x)+itemsWindow->options.padding));
|
||||
std::weak_ptr<MenuItemButton>selectedButton=DYNAMIC_POINTER_CAST<MenuItemButton>(*component);
|
||||
|
||||
int rowBaseIndex=(selectedButton.lock()->inventoryIndex/invWidth)*invWidth;
|
||||
int newRowIndex=selectedButton.lock()->inventoryIndex+1;
|
||||
if(newRowIndex>rowBaseIndex+invWidth-1)newRowIndex-=invWidth;
|
||||
newRowIndex=std::clamp(newRowIndex,0,int(itemsList.size()-1));
|
||||
if(newRowIndex<0||newRowIndex>=itemsList.size())ERR(std::format("New Row Index ended up out-of-bounds! newRowIndex={}. THIS SHOULD NOT BE HAPPENING!",newRowIndex));
|
||||
//Select the component that matches this new number.
|
||||
auto component=std::find_if(itemsList.begin(),itemsList.end(),[&](auto&comp){return DYNAMIC_POINTER_CAST<MenuItemButton>(comp)->inventoryIndex==newRowIndex;});
|
||||
if(component==itemsList.end())ERR(std::format("WARNING! Could not find row index {} in items list while navigating! THIS SHOULD NOT BE HAPPENING!",newRowIndex));
|
||||
returnData=*component;
|
||||
}
|
||||
}else{
|
||||
returnData="OK Button";
|
||||
|
||||
Reference in New Issue
Block a user