Begin work on Level Completion controller compatibility. Add in inventory scrollable window helper navigation macros to make coding wrapping functionality easier. Release Build 7010.

pull/35/head
sigonasr2 10 months ago
parent 5169670b76
commit 52a01d04ad
  1. 233
      Adventures in Lestoria/InventoryConsumableWindow.cpp
  2. 8
      Adventures in Lestoria/Key.cpp
  3. 2
      Adventures in Lestoria/Key.h
  4. 73
      Adventures in Lestoria/LevelCompleteWindow.cpp
  5. 8
      Adventures in Lestoria/Menu.cpp
  6. 2
      Adventures in Lestoria/Version.h
  7. BIN
      x64/Release/Adventures in Lestoria.exe

@ -152,121 +152,166 @@ void Menu::InitializeConsumableInventoryWindow(){
}}, }},
{"inventory",{ {"inventory",{
.up=[](MenuType type,Data&returnData){ .up=[](MenuType type,Data&returnData){
auto&selection=Menu::menus[type]->GetSelection(); #pragma region Inventory Wrapping Handling Up Macros
auto&itemsList=Component<InventoryScrollableWindowComponent>(type,"inventory")->GetComponents(); //Make sure before using this you have #define SUBCLASS with the children class for this inventory scrollable window component!
auto itemsWindow=Component<InventoryScrollableWindowComponent>(type,"inventory"); #define DetectInventory(menuClass,menuType,inventoryComponentName) \
auto component=std::find_if(itemsList.begin(),itemsList.end(),[&](auto&comp){return comp.lock()==selection.lock();}); auto&selection=Menu::menus[menuType]->GetSelection(); \
if(itemsList.size()>0){ auto&itemsList=Component<menuClass>(menuType,inventoryComponentName)->GetComponents(); \
if(component==itemsList.end()){ auto itemsWindow=Component<menuClass>(menuType,inventoryComponentName); \
//Set the selected button to the last element in the list. auto component=std::find_if(itemsList.begin(),itemsList.end(),[&](auto&comp){return comp.lock()==selection.lock();}); \
returnData=itemsList.back(); if(itemsList.size()>0){ \
}else{ if(component==itemsList.end()){ \
int invWidth=int((itemsWindow->rect.size.x-12)/(float(itemsWindow->options.size.x)+itemsWindow->options.padding)); /*Set the selected button to the last element in the list.*/ \
std::weak_ptr<MenuItemButton>selectedButton=DYNAMIC_POINTER_CAST<MenuItemButton>(*component); returnData=itemsList.back(); \
int newRowIndex=selectedButton.lock()->inventoryIndex-invWidth; //Moving up moves the cursor up an entire row. }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){ if(newRowIndex<0){
//This means we have to wrap around. #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"; returnData="OK Button";
return; 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)); DefaultBehavior{ //When nothing is found...
//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"; returnData="OK Button";
} }
}, },
.down=[](MenuType type,Data&returnData){ .down=[](MenuType type,Data&returnData){
auto&selection=Menu::menus[type]->GetSelection(); #pragma region Inventory Wrapping Handling Down Macros
auto&itemsList=Component<InventoryScrollableWindowComponent>(type,"inventory")->GetComponents(); //Make sure before using this you have #define SUBCLASS with the children class for this inventory scrollable window component!
auto itemsWindow=Component<InventoryScrollableWindowComponent>(type,"inventory"); #define DetectInventory(menuClass,menuType,inventoryComponentName) \
auto component=std::find_if(itemsList.begin(),itemsList.end(),[&](auto&comp){return comp.lock()==selection.lock();}); auto&selection=Menu::menus[menuType]->GetSelection(); \
if(itemsList.size()>0){ auto&itemsList=Component<menuClass>(menuType,inventoryComponentName)->GetComponents(); \
if(component==itemsList.end()){ auto itemsWindow=Component<menuClass>(menuType,inventoryComponentName); \
//Set the selected button to the first element in the list. auto component=std::find_if(itemsList.begin(),itemsList.end(),[&](auto&comp){return comp.lock()==selection.lock();}); \
returnData=itemsList.front(); if(itemsList.size()>0){ \
}else{ if(component==itemsList.end()){ \
int invWidth=int((itemsWindow->rect.size.x-12)/(float(itemsWindow->options.size.x)+itemsWindow->options.padding)); /*Set the selected button to the last element in the list.*/ \
std::weak_ptr<MenuItemButton>selectedButton=DYNAMIC_POINTER_CAST<MenuItemButton>(*component); returnData=itemsList.front();\
int newRowIndex=selectedButton.lock()->inventoryIndex+invWidth; //Moving down moves the cursor down an entire row. }else{ \
if(newRowIndex>=itemsList.size()){ int invWidth=int((itemsWindow->rect.size.x-12)/(float(itemsWindow->options.size.x)+itemsWindow->options.padding)); \
int currentRow=newRowIndex/invWidth; std::weak_ptr<SUBCLASS>selectedButton=DYNAMIC_POINTER_CAST<SUBCLASS>(*component); \
//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. int newRowIndex=selectedButton.lock()->inventoryIndex+invWidth; /*Moving down moves the cursor down an entire row.*/ \
newRowIndex=std::clamp(newRowIndex,0,int(itemsList.size()-1)); if(newRowIndex>=itemsList.size()){ \
int newRow=newRowIndex/invWidth; int currentRow=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. /*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"; returnData="OK Button";
return; return;
} }
} DefaultBehavior{ //When nothing is found...
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"; returnData="OK Button";
} }
}, },
.left=[](MenuType type,Data&returnData){ .left=[](MenuType type,Data&returnData){
auto&selection=Menu::menus[type]->GetSelection(); #pragma region Inventory Wrapping Handling Left Macros
auto&itemsList=Component<InventoryScrollableWindowComponent>(type,"inventory")->GetComponents(); #define DetectInventory(menuClass,menuType,inventoryComponentName) \
auto itemsWindow=Component<InventoryScrollableWindowComponent>(type,"inventory"); auto&selection=Menu::menus[menuType]->GetSelection(); \
auto component=std::find_if(itemsList.begin(),itemsList.end(),[&](auto&comp){return comp.lock()==selection.lock();}); auto&itemsList=Component<menuClass>(menuType,inventoryComponentName)->GetComponents(); \
if(itemsList.size()>0){ auto itemsWindow=Component<menuClass>(menuType,inventoryComponentName); \
if(component==itemsList.end()){ auto component=std::find_if(itemsList.begin(),itemsList.end(),[&](auto&comp){return comp.lock()==selection.lock();}); \
//Set the selected button to the last element in the list. if(itemsList.size()>0){ \
returnData=itemsList.back(); if(component==itemsList.end()){ \
}else{ /*Set the selected button to the last element in the list.*/ \
int invWidth=int((itemsWindow->rect.size.x-12)/(float(itemsWindow->options.size.x)+itemsWindow->options.padding)); returnData=itemsList.back(); \
std::weak_ptr<MenuItemButton>selectedButton=DYNAMIC_POINTER_CAST<MenuItemButton>(*component); }else{ \
int invWidth=int((itemsWindow->rect.size.x-12)/(float(itemsWindow->options.size.x)+itemsWindow->options.padding)); \
int rowBaseIndex=(selectedButton.lock()->inventoryIndex/invWidth)*invWidth; std::weak_ptr<SUBCLASS>selectedButton=DYNAMIC_POINTER_CAST<SUBCLASS>(*component); \
int newRowIndex=selectedButton.lock()->inventoryIndex-1; int rowBaseIndex=(selectedButton.lock()->inventoryIndex/invWidth)*invWidth; \
if(newRowIndex<rowBaseIndex)newRowIndex+=invWidth; int newRowIndex=selectedButton.lock()->inventoryIndex-1; \
newRowIndex=std::min(int(itemsList.size())-1,newRowIndex); if(newRowIndex<rowBaseIndex)
if(newRowIndex<0){ #define DefaultBehavior \
//This means we have to wrap around. newRowIndex=std::min(int(itemsList.size())-1,newRowIndex); \
newRowIndex+=itemsList.size(); 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)); \
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.*/ \
//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;}); \
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)); \
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
#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;
} }
}else{ DefaultBehavior{ //When nothing is found...
returnData="OK Button"; returnData="OK Button";
} }
}, },
.right=[](MenuType type,Data&returnData){ .right=[](MenuType type,Data&returnData){
auto&selection=Menu::menus[type]->GetSelection(); #pragma region Inventory Wrapping Handling Right Macros
auto&itemsList=Component<InventoryScrollableWindowComponent>(type,"inventory")->GetComponents(); #define DetectInventory(menuClass,menuType,inventoryComponentName) \
auto itemsWindow=Component<InventoryScrollableWindowComponent>(type,"inventory"); auto&selection=Menu::menus[menuType]->GetSelection(); \
auto component=std::find_if(itemsList.begin(),itemsList.end(),[&](auto&comp){return comp.lock()==selection.lock();}); auto&itemsList=Component<menuClass>(menuType,inventoryComponentName)->GetComponents(); \
if(itemsList.size()>0){ auto itemsWindow=Component<menuClass>(menuType,inventoryComponentName); \
if(component==itemsList.end()){ auto component=std::find_if(itemsList.begin(),itemsList.end(),[&](auto&comp){return comp.lock()==selection.lock();}); \
//Set the selected button to the first element in the list. if(itemsList.size()>0){ \
returnData=itemsList.front(); if(component==itemsList.end()){ \
}else{ /*Set the selected button to the last element in the list.*/ \
int invWidth=int((itemsWindow->rect.size.x-12)/(float(itemsWindow->options.size.x)+itemsWindow->options.padding)); returnData=itemsList.front(); \
std::weak_ptr<MenuItemButton>selectedButton=DYNAMIC_POINTER_CAST<MenuItemButton>(*component); }else{ \
int invWidth=int((itemsWindow->rect.size.x-12)/(float(itemsWindow->options.size.x)+itemsWindow->options.padding)); \
int rowBaseIndex=(selectedButton.lock()->inventoryIndex/invWidth)*invWidth; std::weak_ptr<SUBCLASS>selectedButton=DYNAMIC_POINTER_CAST<SUBCLASS>(*component); \
int newRowIndex=selectedButton.lock()->inventoryIndex+1; int rowBaseIndex=(selectedButton.lock()->inventoryIndex/invWidth)*invWidth; \
if(newRowIndex>rowBaseIndex+invWidth-1)newRowIndex-=invWidth; int newRowIndex=selectedButton.lock()->inventoryIndex+1; \
newRowIndex=std::clamp(newRowIndex,0,int(itemsList.size()-1)); if(newRowIndex>rowBaseIndex+invWidth-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)); #define DefaultBehavior \
//Select the component that matches this new number. newRowIndex=std::clamp(newRowIndex,0,int(itemsList.size()-1)); \
auto component=std::find_if(itemsList.begin(),itemsList.end(),[&](auto&comp){return DYNAMIC_POINTER_CAST<MenuItemButton>(comp)->inventoryIndex==newRowIndex;}); newRowIndex=std::min(int(itemsList.size())-1,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)); if(newRowIndex<0||newRowIndex>=itemsList.size())ERR(std::format("New Row Index ended up out-of-bounds! newRowIndex={}. THIS SHOULD NOT BE HAPPENING!",newRowIndex)); \
returnData=*component; /*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;
} }
}else{ DefaultBehavior{ //When nothing is found...
returnData="OK Button"; returnData="OK Button";
} }
}, },

@ -262,14 +262,14 @@ const float InputGroup::Analog()const{
return 0.f; return 0.f;
} }
const float InputGroup::AnalogDAS(){ const float InputGroup::AnalogDAS(const float threshold){
for(Input input:keys){ for(Input input:keys){
float analogVal=input.Analog(); float analogVal=input.Analog();
if(analogVal!=0.f&&initialHoldDownTime==0.f){ if(abs(analogVal)>=threshold&&initialHoldDownTime==0.f){
initialHoldDownTime="Interface.InitialScrollDelay"_F; initialHoldDownTime="Interface.InitialScrollDelay"_F;
return analogVal; return analogVal;
}else }else
if(analogVal!=0.f&&initialHoldDownTime>0.f){ if(abs(analogVal)>=threshold&&initialHoldDownTime>0.f){
initialHoldDownTime-=game->GetElapsedTime(); initialHoldDownTime-=game->GetElapsedTime();
if(initialHoldDownTime<=0.f){ if(initialHoldDownTime<=0.f){
holdDownTime="Interface.ScrollDelay"_F; holdDownTime="Interface.ScrollDelay"_F;
@ -277,7 +277,7 @@ const float InputGroup::AnalogDAS(){
} }
return 0.f; return 0.f;
}else }else
if(analogVal!=0.f&&holdDownTime>0.f){ if(abs(analogVal)>=threshold&&holdDownTime>0.f){
holdDownTime-=game->GetElapsedTime(); holdDownTime-=game->GetElapsedTime();
if(holdDownTime<=0.f){ if(holdDownTime<=0.f){
holdDownTime="Interface.ScrollDelay"_F; holdDownTime="Interface.ScrollDelay"_F;

@ -113,7 +113,7 @@ public:
const bool Held()const; const bool Held()const;
const bool Released(); const bool Released();
const float Analog()const; const float Analog()const;
const float AnalogDAS(); const float AnalogDAS(const float threshold=0.2f);
std::string GetDisplayName(); std::string GetDisplayName();
//Draws an input display with accompanying text centered at given position. //Draws an input display with accompanying text centered at given position.
void DrawInput(const std::variant<AiL*const,TileTransformedView*const>renderer,const vf2d pos,const std::string_view displayText,const uint8_t alpha)const; void DrawInput(const std::variant<AiL*const,TileTransformedView*const>renderer,const vf2d pos,const std::string_view displayText,const uint8_t alpha)const;

@ -79,4 +79,77 @@ void Menu::InitializeLevelCompleteWindow(){
levelCompleteWindow->ADD("Stage Loot Popup Item Name",PopupMenuLabel)(geom2d::rect<float>{{0,32},{windowSize.size.x-80.f,12}},"",1.0f,ComponentAttr::LEFT_ALIGN|ComponentAttr::SHADOW|ComponentAttr::OUTLINE|ComponentAttr::BACKGROUND)END; levelCompleteWindow->ADD("Stage Loot Popup Item Name",PopupMenuLabel)(geom2d::rect<float>{{0,32},{windowSize.size.x-80.f,12}},"",1.0f,ComponentAttr::LEFT_ALIGN|ComponentAttr::SHADOW|ComponentAttr::OUTLINE|ComponentAttr::BACKGROUND)END;
levelCompleteWindow->ADD("Stage Loot Popup Item Description",PopupMenuLabel)(geom2d::rect<float>{{0,44},{windowSize.size.x-80.f,60}},"",1.0f,ComponentAttr::LEFT_ALIGN|ComponentAttr::SHADOW|ComponentAttr::OUTLINE|ComponentAttr::BACKGROUND)END; levelCompleteWindow->ADD("Stage Loot Popup Item Description",PopupMenuLabel)(geom2d::rect<float>{{0,44},{windowSize.size.x-80.f,60}},"",1.0f,ComponentAttr::LEFT_ALIGN|ComponentAttr::SHADOW|ComponentAttr::OUTLINE|ComponentAttr::BACKGROUND)END;
levelCompleteWindow->SetupKeyboardNavigation(
[](MenuType type,Data&returnData){ //On Open
auto monsterLoot=Component<InventoryScrollableWindowComponent>(type,"Monster Loot Window");
auto stageLoot=Component<InventoryScrollableWindowComponent>(type,"Stage Loot Window");
if(monsterLoot->GetComponents().size()>0){
returnData=monsterLoot->GetComponents().front();
}else
if(stageLoot->GetComponents().size()>0){
returnData=stageLoot->GetComponents().front();
}else{
returnData="Next Button";
}
},
{ //Button Key
{{game->KEY_SHOULDER,Pressed},{"Scroll",[](MenuType type){}}},
{{game->KEY_FASTSCROLLDOWN,PressedDAS,InputEngageGroup::NOT_VISIBLE},{"Scroll",[](MenuType type){
auto selection=Menu::menus[type]->GetSelection();
if(!selection.expired()){
auto parentComponent=DYNAMIC_POINTER_CAST<InventoryScrollableWindowComponent>(selection.lock()->parentComponent);
int invWidth=int((parentComponent->rect.size.x-12)/(float(parentComponent->options.size.x)+parentComponent->options.padding));
parentComponent->IncreaseSelectionIndex(invWidth*3.f);
}
}}},
{{game->KEY_FASTSCROLLUP,PressedDAS,InputEngageGroup::NOT_VISIBLE},{"Scroll",[](MenuType type){
auto selection=Menu::menus[type]->GetSelection();
if(!selection.expired()){
auto parentComponent=DYNAMIC_POINTER_CAST<InventoryScrollableWindowComponent>(selection.lock()->parentComponent);
int invWidth=int((parentComponent->rect.size.x-12)/(float(parentComponent->options.size.x)+parentComponent->options.padding));
parentComponent->IncreaseSelectionIndex(invWidth*-3.f);
}
}}},
{game->KEY_SCROLL,{"View Items",[](MenuType type){}}},
{game->KEY_START,{"Continue",[](MenuType type){}}},
}
,{ //Button Navigation Rules
{"Monster Loot Window",{
.up=[](MenuType type,Data&returnData){
auto&selection=Menu::menus[type]->GetSelection();
auto&itemsList=Component<InventoryScrollableWindowComponent>(type,"Monster Loot Window")->GetComponents();
auto itemsWindow=Component<InventoryScrollableWindowComponent>(type,"Monster Loot Window");
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{
returnData="OK Button";
}
},
.down="Load Game Button",}},
{"Load Game Button",{
.up="New Game Button",
.down="Quit Game Button",}},
{"Quit Game Button",{
.up="Load Game Button",
.down="New Game Button",}},
});
} }

@ -346,7 +346,7 @@ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){
} }
if(navigationGroups.count(selectionButtonName)){ if(navigationGroups.count(selectionButtonName)){
Navigation nav=navigationGroups[selectionButtonName]; Navigation nav=navigationGroups[selectionButtonName];
if(game->KEY_UP.PressedDAS()||game->KEY_SCROLLUP.AnalogDAS()<-0.2f){ if(game->KEY_UP.PressedDAS()||game->KEY_SCROLLUP.AnalogDAS(0.5f)<-0.5f){
SetMouseNavigation(false); SetMouseNavigation(false);
if(std::holds_alternative<std::string>(nav.up)&&std::get<std::string>(nav.up).length()>0)SetSelection(std::string_view(std::get<std::string>(nav.up))); if(std::holds_alternative<std::string>(nav.up)&&std::get<std::string>(nav.up).length()>0)SetSelection(std::string_view(std::get<std::string>(nav.up)));
else else
@ -356,7 +356,7 @@ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){
SetSelection(returnData); SetSelection(returnData);
} }
} }
if(game->KEY_DOWN.PressedDAS()||game->KEY_SCROLLDOWN.AnalogDAS()>0.2f){ if(game->KEY_DOWN.PressedDAS()||game->KEY_SCROLLDOWN.AnalogDAS(0.5f)>0.5f){
SetMouseNavigation(false); SetMouseNavigation(false);
if(std::holds_alternative<std::string>(nav.down)&&std::get<std::string>(nav.down).length()>0)SetSelection(std::string_view(std::get<std::string>(nav.down))); if(std::holds_alternative<std::string>(nav.down)&&std::get<std::string>(nav.down).length()>0)SetSelection(std::string_view(std::get<std::string>(nav.down)));
else else
@ -366,7 +366,7 @@ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){
SetSelection(returnData); SetSelection(returnData);
} }
} }
if(game->KEY_LEFT.PressedDAS()||game->KEY_SCROLLLEFT.AnalogDAS()<-0.2f){ if(game->KEY_LEFT.PressedDAS()||game->KEY_SCROLLLEFT.AnalogDAS(0.5f)<-0.5f){
SetMouseNavigation(false); SetMouseNavigation(false);
if(std::holds_alternative<std::string>(nav.left)&&std::get<std::string>(nav.left).length()>0)SetSelection(std::string_view(std::get<std::string>(nav.left))); if(std::holds_alternative<std::string>(nav.left)&&std::get<std::string>(nav.left).length()>0)SetSelection(std::string_view(std::get<std::string>(nav.left)));
else else
@ -376,7 +376,7 @@ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){
SetSelection(returnData); SetSelection(returnData);
} }
} }
if(game->KEY_RIGHT.PressedDAS()||game->KEY_SCROLLRIGHT.AnalogDAS()>0.2f){ if(game->KEY_RIGHT.PressedDAS()||game->KEY_SCROLLRIGHT.AnalogDAS(0.5f)>0.5f){
SetMouseNavigation(false); SetMouseNavigation(false);
if(std::holds_alternative<std::string>(nav.right)&&std::get<std::string>(nav.right).length()>0)SetSelection(std::string_view(std::get<std::string>(nav.right))); if(std::holds_alternative<std::string>(nav.right)&&std::get<std::string>(nav.right).length()>0)SetSelection(std::string_view(std::get<std::string>(nav.right)));
else else

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 3 #define VERSION_MINOR 3
#define VERSION_PATCH 0 #define VERSION_PATCH 0
#define VERSION_BUILD 7005 #define VERSION_BUILD 7010
#define stringify(a) stringify_(a) #define stringify(a) stringify_(a)
#define stringify_(a) #a #define stringify_(a) #a

Loading…
Cancel
Save