Begin work on Level Completion controller compatibility. Add in inventory scrollable window helper navigation macros to make coding wrapping functionality easier. Release Build 7010.
This commit is contained in:
@@ -152,121 +152,166 @@ void Menu::InitializeConsumableInventoryWindow(){
|
||||
}},
|
||||
{"inventory",{
|
||||
.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 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 last element in the list.
|
||||
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=selectedButton.lock()->inventoryIndex-invWidth; //Moving up moves the cursor up an entire row.
|
||||
if(newRowIndex<0){
|
||||
//This means we have to wrap around.
|
||||
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)->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{
|
||||
#pragma region Inventory Wrapping Handling Up Macros
|
||||
//Make sure before using this you have #define SUBCLASS with the children class for this inventory scrollable window component!
|
||||
#define DetectInventory(menuClass,menuType,inventoryComponentName) \
|
||||
auto&selection=Menu::menus[menuType]->GetSelection(); \
|
||||
auto&itemsList=Component<menuClass>(menuType,inventoryComponentName)->GetComponents(); \
|
||||
auto itemsWindow=Component<menuClass>(menuType,inventoryComponentName); \
|
||||
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 last element in the list.*/ \
|
||||
returnData=itemsList.back(); \
|
||||
}else{ \
|
||||
int invWidth=int((itemsWindow->rect.size.x-12)/(float(itemsWindow->options.size.x)+itemsWindow->options.padding)); \
|
||||
std::weak_ptr<SUBCLASS>selectedButton=DYNAMIC_POINTER_CAST<SUBCLASS>(*component); \
|
||||
int newRowIndex=selectedButton.lock()->inventoryIndex-invWidth; /*Moving up moves the cursor up an entire row.*/ \
|
||||
if(newRowIndex<0){
|
||||
#define DefaultBehavior \
|
||||
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<SUBCLASS>(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
|
||||
#define DEFAULT_WRAPPING_BEHAVIOR newRowIndex=itemsList.size()-1;
|
||||
#pragma endregion
|
||||
#define SUBCLASS MenuItemButton
|
||||
DetectInventory(InventoryScrollableWindowComponent,type,"inventory")
|
||||
{ //This means we have to wrap around. We have access to itemsList if we needed to point to a specific item in the inventory.
|
||||
//By returning here, you are processing returnData yourself. Otherwise manipulate newRowIndex to point to an item in the itemsList when wrapping.
|
||||
returnData="OK Button";
|
||||
return;
|
||||
}
|
||||
DefaultBehavior{ //When nothing is found...
|
||||
returnData="OK Button";
|
||||
}
|
||||
},
|
||||
.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 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=selectedButton.lock()->inventoryIndex+invWidth; //Moving down moves the cursor down an entire row.
|
||||
if(newRowIndex>=itemsList.size()){
|
||||
int currentRow=newRowIndex/invWidth;
|
||||
//The logic here is, if we clamp this row index to the last possible index and we're still on the same row, it means there is at least an item on this row. So we go to that instead.
|
||||
newRowIndex=std::clamp(newRowIndex,0,int(itemsList.size()-1));
|
||||
int newRow=newRowIndex/invWidth;
|
||||
if(currentRow!=newRow){ //This means we are on a different row, so the row we went down on didn't have any items. Simply drop down to the OK Button.
|
||||
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)->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{
|
||||
#pragma region Inventory Wrapping Handling Down Macros
|
||||
//Make sure before using this you have #define SUBCLASS with the children class for this inventory scrollable window component!
|
||||
#define DetectInventory(menuClass,menuType,inventoryComponentName) \
|
||||
auto&selection=Menu::menus[menuType]->GetSelection(); \
|
||||
auto&itemsList=Component<menuClass>(menuType,inventoryComponentName)->GetComponents(); \
|
||||
auto itemsWindow=Component<menuClass>(menuType,inventoryComponentName); \
|
||||
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 last 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<SUBCLASS>selectedButton=DYNAMIC_POINTER_CAST<SUBCLASS>(*component); \
|
||||
int newRowIndex=selectedButton.lock()->inventoryIndex+invWidth; /*Moving down moves the cursor down an entire row.*/ \
|
||||
if(newRowIndex>=itemsList.size()){ \
|
||||
int currentRow=newRowIndex/invWidth; \
|
||||
/*The logic here is, if we clamp this row index to the last possible index and we're still on the same row, it means there is at least an item on this row. So we go to that instead.*/ \
|
||||
newRowIndex=std::clamp(newRowIndex,0,int(itemsList.size()-1)); \
|
||||
int newRow=newRowIndex/invWidth; \
|
||||
if(currentRow!=newRow) //This means we are on a different row, so the row we went down on didn't have any items. Simply drop down to the OK Button.
|
||||
#define DefaultBehavior \
|
||||
} \
|
||||
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<SUBCLASS>(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
|
||||
#define DEFAULT_WRAPPING_BEHAVIOR newRowIndex=0;
|
||||
#pragma endregion
|
||||
#define SUBCLASS MenuItemButton
|
||||
DetectInventory(InventoryScrollableWindowComponent,type,"inventory")
|
||||
{ //This means we have to wrap around. We have access to itemsList if we needed to point to a specific item in the inventory.
|
||||
//By returning here, you are processing returnData yourself. Otherwise manipulate newRowIndex to point to an item in the itemsList when wrapping.
|
||||
returnData="OK Button";
|
||||
return;
|
||||
}
|
||||
DefaultBehavior{ //When nothing is found...
|
||||
returnData="OK Button";
|
||||
}
|
||||
},
|
||||
.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 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 last element in the list.
|
||||
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 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)->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{
|
||||
#pragma region Inventory Wrapping Handling Left Macros
|
||||
#define DetectInventory(menuClass,menuType,inventoryComponentName) \
|
||||
auto&selection=Menu::menus[menuType]->GetSelection(); \
|
||||
auto&itemsList=Component<menuClass>(menuType,inventoryComponentName)->GetComponents(); \
|
||||
auto itemsWindow=Component<menuClass>(menuType,inventoryComponentName); \
|
||||
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 last element in the list.*/ \
|
||||
returnData=itemsList.back(); \
|
||||
}else{ \
|
||||
int invWidth=int((itemsWindow->rect.size.x-12)/(float(itemsWindow->options.size.x)+itemsWindow->options.padding)); \
|
||||
std::weak_ptr<SUBCLASS>selectedButton=DYNAMIC_POINTER_CAST<SUBCLASS>(*component); \
|
||||
int rowBaseIndex=(selectedButton.lock()->inventoryIndex/invWidth)*invWidth; \
|
||||
int newRowIndex=selectedButton.lock()->inventoryIndex-1; \
|
||||
if(newRowIndex<rowBaseIndex)
|
||||
#define DefaultBehavior \
|
||||
newRowIndex=std::min(int(itemsList.size())-1,newRowIndex); \
|
||||
if(newRowIndex<0)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<SUBCLASS>(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
|
||||
#define DEFAULT_WRAPPING_BEHAVIOR newRowIndex+=invWidth;
|
||||
#pragma endregion
|
||||
#define SUBCLASS MenuItemButton
|
||||
DetectInventory(InventoryScrollableWindowComponent,type,"inventory")
|
||||
{ //This means we have to wrap around. We have access to itemsList if we needed to point to a specific item in the inventory.
|
||||
//By returning here, you are processing returnData yourself. Otherwise manipulate newRowIndex to point to an item in the itemsList when wrapping.
|
||||
DEFAULT_WRAPPING_BEHAVIOR;
|
||||
}
|
||||
DefaultBehavior{ //When nothing is found...
|
||||
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{
|
||||
#pragma region Inventory Wrapping Handling Right Macros
|
||||
#define DetectInventory(menuClass,menuType,inventoryComponentName) \
|
||||
auto&selection=Menu::menus[menuType]->GetSelection(); \
|
||||
auto&itemsList=Component<menuClass>(menuType,inventoryComponentName)->GetComponents(); \
|
||||
auto itemsWindow=Component<menuClass>(menuType,inventoryComponentName); \
|
||||
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 last 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<SUBCLASS>selectedButton=DYNAMIC_POINTER_CAST<SUBCLASS>(*component); \
|
||||
int rowBaseIndex=(selectedButton.lock()->inventoryIndex/invWidth)*invWidth; \
|
||||
int newRowIndex=selectedButton.lock()->inventoryIndex+1; \
|
||||
if(newRowIndex>rowBaseIndex+invWidth-1)
|
||||
#define DefaultBehavior \
|
||||
newRowIndex=std::clamp(newRowIndex,0,int(itemsList.size()-1)); \
|
||||
newRowIndex=std::min(int(itemsList.size())-1,newRowIndex); \
|
||||
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<SUBCLASS>(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
|
||||
#define DEFAULT_WRAPPING_BEHAVIOR newRowIndex-=invWidth;
|
||||
#pragma endregion
|
||||
#define SUBCLASS MenuItemButton
|
||||
DetectInventory(InventoryScrollableWindowComponent,type,"inventory")
|
||||
{ //This means we have to wrap around. We have access to itemsList if we needed to point to a specific item in the inventory.
|
||||
//By returning here, you are processing returnData yourself. Otherwise manipulate newRowIndex to point to an item in the itemsList when wrapping.
|
||||
DEFAULT_WRAPPING_BEHAVIOR;
|
||||
}
|
||||
DefaultBehavior{ //When nothing is found...
|
||||
returnData="OK Button";
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user