diff --git a/Adventures in Lestoria/Error.h b/Adventures in Lestoria/Error.h index 47190b9c..a2c30c73 100644 --- a/Adventures in Lestoria/Error.h +++ b/Adventures in Lestoria/Error.h @@ -88,13 +88,13 @@ type DYNAMIC_CAST(auto variable){ template std::shared_ptrDYNAMIC_POINTER_CAST(const std::shared_ptr&variable){ std::shared_ptr newVariable=dynamic_pointer_cast(variable); - if(!newVariable)ERR("Could not dynamic cast to pointer type "< std::shared_ptrDYNAMIC_POINTER_CAST(const std::weak_ptr&variable){ std::shared_ptr newVariable=dynamic_pointer_cast(variable.lock()); - if(!newVariable)ERR("Could not dynamic cast to pointer type "<KEY_START,{"Load File",[](MenuType type){ - Menu::menus[type]->GetSelection().lock()->Click(); - }}}, {game->KEY_BACK,{"Back to Title Screen",[](MenuType type){ - Component(type,"Back Button")->Click(); + Component(type,"Go Back Button")->Click(); }}}, } ,{ //Button Navigation Rules diff --git a/Adventures in Lestoria/Menu.cpp b/Adventures in Lestoria/Menu.cpp index 0d303bc5..415db363 100644 --- a/Adventures in Lestoria/Menu.cpp +++ b/Adventures in Lestoria/Menu.cpp @@ -116,10 +116,8 @@ Menu*Menu::CreateMenu(MenuType type,vf2d pos,vf2d size){ } void Menu::CheckClickAndPerformMenuSelect(AiL*game){ - if(game->KEY_CONFIRM.Released()){ - if(ignoreInputs){ - ignoreInputs=false; - }else{ + if(game->KEY_CONFIRM.Released()&&(MOUSE_NAVIGATION||(!MOUSE_NAVIGATION&&!game->GetMouse(Mouse::LEFT).bReleased&&!game->GetMouse(Mouse::RIGHT).bReleased&&!game->GetMouse(Mouse::MIDDLE).bReleased))){ + if(!GetSelection().expired()){ //If we are on controller/gamepad it's possible we haven't highlighted a button yet, so don't click this button right away. MenuSelect(game); } } @@ -298,6 +296,19 @@ void Menu::OpenMenu(MenuType menu,bool cover){ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){ std::weak_ptrprevSelection=selection; + for(auto&[input,data]:inputGroups){ + if(input.Released()){ + SetMouseNavigation(false); + auto&action=data.second; + if(std::holds_alternative(action))Component(type,std::get(action))->Click(); + else + if(std::holds_alternative>(action))std::get>(action)(type); + else{ + ERR("WARNING! Navigation data has an unrecognized type or is empty! This should not be happening!") + } + } + } + if(!selection.expired()){ std::string selectionButtonName=selection.lock()->GetName(); if(!selection.lock()->parentComponent.expired()){ //If a component has a parent, then we use the parent as the identifier for what should happen next. @@ -350,10 +361,10 @@ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){ } } - if(game->KEY_UP.Pressed()||game->KEY_RIGHT.Pressed()||game->KEY_LEFT.Pressed()||game->KEY_DOWN.Pressed()|| - game->KEY_BACK.Pressed()||game->KEY_CONFIRM.Pressed()||game->KEY_START.Pressed()||game->KEY_SELECT.Pressed()|| - game->KEY_SCROLLDOWN.Pressed()||game->KEY_SCROLLUP.Pressed()){ - SetMouseNavigation(game->GetMouse(Mouse::LEFT).bPressed||game->GetMouse(Mouse::RIGHT).bPressed||game->GetMouse(Mouse::MIDDLE).bPressed); //If a click occurs we use mouse controls. + if(game->KEY_UP.Released()||game->KEY_RIGHT.Released()||game->KEY_LEFT.Released()||game->KEY_DOWN.Released()|| + game->KEY_BACK.Released()||game->KEY_CONFIRM.Released()||game->KEY_START.Released()||game->KEY_SELECT.Released()|| + game->KEY_SCROLLDOWN.Released()||game->KEY_SCROLLUP.Released()){ + SetMouseNavigation(game->GetMouse(Mouse::LEFT).bReleased||game->GetMouse(Mouse::RIGHT).bReleased||game->GetMouse(Mouse::MIDDLE).bReleased); //If a click occurs we use mouse controls. buttonHoldTime=0; } if(&*prevSelection.lock()!=&*selection.lock()){ @@ -473,7 +484,6 @@ void Menu::SetMouseNavigation(bool mouseNavigation){ if(MOUSE_NAVIGATION&&!mouseNavigation){ //When mouse navigation was enabled and now needs to be disabled, we store the mouse position. lastActiveMousePos=game->GetMousePos(); - ignoreInputs=true; if(!keyboardSelection.expired()){ SetSelection(keyboardSelection); } diff --git a/Adventures in Lestoria/Menu.h b/Adventures in Lestoria/Menu.h index 08633418..ff84b270 100644 --- a/Adventures in Lestoria/Menu.h +++ b/Adventures in Lestoria/Menu.h @@ -250,8 +250,6 @@ private: std::weak_ptrselection; std::weak_ptrkeyboardSelection; - bool ignoreInputs=false; //We set this to true because on the next button release, we don't want buttons to cause menu navigation. This is for when the player needs to activate the cursor via keyboard/gamepad and nothing is highlighted. It gets reset to false once a button has been released. - static bool MOUSE_NAVIGATION; bool cover; //A black cover for when a menu pops up to fade out the stuff behind it. }; diff --git a/Adventures in Lestoria/MenuComponent.cpp b/Adventures in Lestoria/MenuComponent.cpp index 0468caa9..b828931c 100644 --- a/Adventures in Lestoria/MenuComponent.cpp +++ b/Adventures in Lestoria/MenuComponent.cpp @@ -246,5 +246,5 @@ void MenuComponent::OnPlayerMoneyUpdate(uint32_t newMoney){} void MenuComponent::OnChapterUpdate(uint8_t newChapter){} void MenuComponent::Click(){ - onClick(MenuFuncData{*Menu::menus[parentMenu],game,std::make_shared(*this)}); + onClick(MenuFuncData{*Menu::menus[parentMenu],game,Menu::menus[parentMenu]->components[name]}); } \ No newline at end of file diff --git a/Adventures in Lestoria/Version.h b/Adventures in Lestoria/Version.h index ad5a83ec..72d37dd7 100644 --- a/Adventures in Lestoria/Version.h +++ b/Adventures in Lestoria/Version.h @@ -39,7 +39,7 @@ All rights reserved. #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 1 -#define VERSION_BUILD 6020 +#define VERSION_BUILD 6033 #define stringify(a) stringify_(a) #define stringify_(a) #a