Implemented controller compatibility for sell item menu. Keyboard/controller menu navigation now auto-repopulates with a default selection if the current selection becomes expired for some reason (such as selling an item). Release Build 7249.

This commit is contained in:
2024-02-16 18:30:14 -06:00
parent 5d315ada93
commit d8d50f74a7
7 changed files with 153 additions and 8 deletions
+87 -2
View File
@@ -43,6 +43,7 @@ All rights reserved.
using A=Attribute;
void Menu::InitializeSellItemWindow(){
static bool incrementButtonDisabled=false;
Menu*sellItemWindow=CreateMenu(SELL_ITEM,CENTERED,{192,72});
static auto GetQuantity=[&](){
return std::stoi(Component<MenuLabel>(SELL_ITEM,"Amount to sell Amount Label")->GetLabel());
@@ -72,11 +73,17 @@ void Menu::InitializeSellItemWindow(){
sellItemWindow->ADD("Amount to sell Amount Label",MenuLabel)(geom2d::rect<float>{{sellItemWindow->size.x/2+48,34},{32,12}},"0",1.0f,ComponentAttr::SHADOW|ComponentAttr::OUTLINE|ComponentAttr::FIT_TO_LABEL)END;
sellItemWindow->ADD("Increase sell amount Button",MenuComponent)(geom2d::rect<float>{{sellItemWindow->size.x/2+80+2,34},{12,12}},"+",[&](MenuFuncData data){
UpdateMenu(GetQuantity()+1);
if(!incrementButtonDisabled){
UpdateMenu(GetQuantity()+1);
}
incrementButtonDisabled=false;
return true;
})END;
sellItemWindow->ADD("Decrease sell amount Button",MenuComponent)(geom2d::rect<float>{{sellItemWindow->size.x/2+48-14,34},{12,12}},"-",[](MenuFuncData data){
UpdateMenu(GetQuantity()-1);
if(!incrementButtonDisabled){
UpdateMenu(GetQuantity()-1);
}
incrementButtonDisabled=false;
return true;
})END;
@@ -93,4 +100,82 @@ void Menu::InitializeSellItemWindow(){
Menu::CloseMenu();
return true;
})END;
sellItemWindow->SetupKeyboardNavigation(
[](MenuType type,Data&returnData){ //On Open
if(Component<MenuComponent>(type,"Sell Button")->IsGreyedOut()){
returnData="Cancel Button";
}else{
returnData="Sell Button";
}
},
{ //Button Key
{game->KEY_START,{[](MenuFuncData data){
if(Component<MenuComponent>(data.menu.GetType(),"Sell Button")->IsGreyedOut()){
return "";
}else{
return "Sell";
}
},[](MenuType type){
Component<MenuComponent>(type,"Sell Button")->Click();
}}},
{{game->KEY_SHOULDER,Pressed},{"Qty Up/Down",[](MenuType type){}}},
{{game->KEY_FASTSCROLLDOWN,PressedDAS},{"",[](MenuType type){
Component<MenuComponent>(type,"Increase sell amount Button")->Click();
if(Component<MenuComponent>(type,"Sell Button")->IsGreyedOut()){
Component<MenuComponent>(type,"Decrease sell amount Button")->Click();
}
}}},
{{game->KEY_FASTSCROLLUP,PressedDAS},{"",[](MenuType type){
bool foundValidAmt=!Component<MenuComponent>(type,"Sell Button")->IsGreyedOut();
Component<MenuComponent>(type,"Decrease sell amount Button")->Click();
if(foundValidAmt&&Component<MenuComponent>(type,"Sell Button")->IsGreyedOut()){
Component<MenuComponent>(type,"Increase sell amount Button")->Click();
}
}}},
{game->KEY_BACK,{"Back",[](MenuType type){
Menu::CloseMenu();
}}},
{{game->KEY_CONFIRM,PressedDAS},{"",[](MenuType type){
if(Menu::menus[type]->GetSelection().expired())return;
incrementButtonDisabled=false;
if(Menu::menus[type]->GetSelection().lock()->GetName()=="Increase sell amount Button"){
Component<MenuComponent>(type,"Increase sell amount Button")->Click();
if(Component<MenuComponent>(type,"Sell Button")->IsGreyedOut()){
Component<MenuComponent>(type,"Decrease sell amount Button")->Click();
}
}else
if(Menu::menus[type]->GetSelection().lock()->GetName()=="Decrease sell amount Button"){
bool foundValidAmt=!Component<MenuComponent>(type,"Sell Button")->IsGreyedOut();
Component<MenuComponent>(type,"Decrease sell amount Button")->Click();
if(foundValidAmt&&Component<MenuComponent>(type,"Sell Button")->IsGreyedOut()){
Component<MenuComponent>(type,"Increase sell amount Button")->Click();
}
}
incrementButtonDisabled=true; //We handled the clicks ourselves, we don't want it to cause another click on release.
}}},
{game->KEY_CONFIRM,{"Select",[](MenuType type){}}},
}
,{ //Button Navigation Rules
{"Cancel Button",{
.up="Decrease sell amount Button",
.down="Decrease sell amount Button",
.left="Sell Button",
.right="Sell Button",}},
{"Sell Button",{
.up="Increase sell amount Button",
.down="Increase sell amount Button",
.left="Cancel Button",
.right="Cancel Button",}},
{"Increase sell amount Button",{
.up="Sell Button",
.down="Sell Button",
.left="Decrease sell amount Button",
.right="Decrease sell amount Button",}},
{"Decrease sell amount Button",{
.up="Cancel Button",
.down="Cancel Button",
.left="Increase sell amount Button",
.right="Increase sell amount Button",}},
});
}