From 3ff1ff0b04f4480a24b78d4b3ff5611eac206b92 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Tue, 16 Jan 2024 22:30:10 -0600 Subject: [PATCH] Fix menu hovering causing selection on menus to be messed up in mouse navigation mode. --- Adventures in Lestoria/Menu.cpp | 55 ++++++++++++++------------ Adventures in Lestoria/Menu.h | 3 +- Adventures in Lestoria/MenuComponent.h | 1 + Adventures in Lestoria/TODO.txt | 5 ++- Adventures in Lestoria/Version.h | 2 +- 5 files changed, 36 insertions(+), 30 deletions(-) diff --git a/Adventures in Lestoria/Menu.cpp b/Adventures in Lestoria/Menu.cpp index e7e74d96..6c4f4e7a 100644 --- a/Adventures in Lestoria/Menu.cpp +++ b/Adventures in Lestoria/Menu.cpp @@ -203,6 +203,7 @@ void Menu::Update(AiL*game){ } } }else{ + selection={}; for(auto&[key,component]:components){ if(component->selectable){ if(!component->disabled&&!component->grayedOut){ @@ -321,33 +322,35 @@ void Menu::SetDefaultButton(std::weak_ptrbutton){ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){ std::weak_ptrprevSelection=selection; - std::string selectionButtonName=selection.lock()->GetName(); - if(navigationGroups.count(selectionButtonName)){ - Navigation nav=navigationGroups[selectionButtonName]; + if(!selection.expired()){ + std::string selectionButtonName=selection.lock()->GetName(); + if(navigationGroups.count(selectionButtonName)){ + Navigation nav=navigationGroups[selectionButtonName]; - if(game->KEY_UP.Pressed()){ - SetMouseNavigation(false); - if(std::holds_alternative(nav.up)&&std::get(nav.up).length()>0)selection=components[std::get(nav.up)]; - else - if(std::holds_alternative(nav.up))std::get(nav.up)(type); - } - if(game->KEY_DOWN.Pressed()){ - SetMouseNavigation(false); - if(std::holds_alternative(nav.down)&&std::get(nav.down).length()>0)selection=components[std::get(nav.down)]; - else - if(std::holds_alternative(nav.down))std::get(nav.down)(type); - } - if(game->KEY_LEFT.Pressed()){ - SetMouseNavigation(false); - if(std::holds_alternative(nav.left)&&std::get(nav.left).length()>0)selection=components[std::get(nav.left)]; - else - if(std::holds_alternative(nav.left))std::get(nav.left)(type); - } - if(game->KEY_RIGHT.Pressed()){ - SetMouseNavigation(false); - if(std::holds_alternative(nav.right)&&std::get(nav.right).length()>0)selection=components[std::get(nav.right)]; - else - if(std::holds_alternative(nav.right))std::get(nav.right)(type); + if(game->KEY_UP.Pressed()){ + SetMouseNavigation(false); + if(std::holds_alternative(nav.up)&&std::get(nav.up).length()>0)selection=components[std::get(nav.up)]; + else + if(std::holds_alternative(nav.up))std::get(nav.up)(type); + } + if(game->KEY_DOWN.Pressed()){ + SetMouseNavigation(false); + if(std::holds_alternative(nav.down)&&std::get(nav.down).length()>0)selection=components[std::get(nav.down)]; + else + if(std::holds_alternative(nav.down))std::get(nav.down)(type); + } + if(game->KEY_LEFT.Pressed()){ + SetMouseNavigation(false); + if(std::holds_alternative(nav.left)&&std::get(nav.left).length()>0)selection=components[std::get(nav.left)]; + else + if(std::holds_alternative(nav.left))std::get(nav.left)(type); + } + if(game->KEY_RIGHT.Pressed()){ + SetMouseNavigation(false); + if(std::holds_alternative(nav.right)&&std::get(nav.right).length()>0)selection=components[std::get(nav.right)]; + else + if(std::holds_alternative(nav.right))std::get(nav.right)(type); + } } } diff --git a/Adventures in Lestoria/Menu.h b/Adventures in Lestoria/Menu.h index b61750ff..2e19322f 100644 --- a/Adventures in Lestoria/Menu.h +++ b/Adventures in Lestoria/Menu.h @@ -163,7 +163,6 @@ public: }else{ component->depth=depth; } - RecalculateComponentCount(); if(components.count(componentKey)){ ERR("WARNING! Key "<SetupKeyboardNavigation( { diff --git a/Adventures in Lestoria/Version.h b/Adventures in Lestoria/Version.h index e2c26062..25956157 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 5969 +#define VERSION_BUILD 5974 #define stringify(a) stringify_(a) #define stringify_(a) #a