Fix menu hovering causing selection on menus to be messed up in mouse navigation mode.

This commit is contained in:
sigonasr2 2024-01-16 22:30:10 -06:00
parent 4aaa954d05
commit 3ff1ff0b04
5 changed files with 36 additions and 30 deletions

View File

@ -203,6 +203,7 @@ void Menu::Update(AiL*game){
} }
} }
}else{ }else{
selection={};
for(auto&[key,component]:components){ for(auto&[key,component]:components){
if(component->selectable){ if(component->selectable){
if(!component->disabled&&!component->grayedOut){ if(!component->disabled&&!component->grayedOut){
@ -321,33 +322,35 @@ void Menu::SetDefaultButton(std::weak_ptr<MenuComponent>button){
void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){
std::weak_ptr<MenuComponent>prevSelection=selection; std::weak_ptr<MenuComponent>prevSelection=selection;
std::string selectionButtonName=selection.lock()->GetName(); if(!selection.expired()){
if(navigationGroups.count(selectionButtonName)){ std::string selectionButtonName=selection.lock()->GetName();
Navigation nav=navigationGroups[selectionButtonName]; if(navigationGroups.count(selectionButtonName)){
Navigation nav=navigationGroups[selectionButtonName];
if(game->KEY_UP.Pressed()){ if(game->KEY_UP.Pressed()){
SetMouseNavigation(false); SetMouseNavigation(false);
if(std::holds_alternative<std::string>(nav.up)&&std::get<std::string>(nav.up).length()>0)selection=components[std::get<std::string>(nav.up)]; if(std::holds_alternative<std::string>(nav.up)&&std::get<std::string>(nav.up).length()>0)selection=components[std::get<std::string>(nav.up)];
else else
if(std::holds_alternative<MenuDataFunc>(nav.up))std::get<MenuDataFunc>(nav.up)(type); if(std::holds_alternative<MenuDataFunc>(nav.up))std::get<MenuDataFunc>(nav.up)(type);
} }
if(game->KEY_DOWN.Pressed()){ if(game->KEY_DOWN.Pressed()){
SetMouseNavigation(false); SetMouseNavigation(false);
if(std::holds_alternative<std::string>(nav.down)&&std::get<std::string>(nav.down).length()>0)selection=components[std::get<std::string>(nav.down)]; if(std::holds_alternative<std::string>(nav.down)&&std::get<std::string>(nav.down).length()>0)selection=components[std::get<std::string>(nav.down)];
else else
if(std::holds_alternative<MenuDataFunc>(nav.down))std::get<MenuDataFunc>(nav.down)(type); if(std::holds_alternative<MenuDataFunc>(nav.down))std::get<MenuDataFunc>(nav.down)(type);
} }
if(game->KEY_LEFT.Pressed()){ if(game->KEY_LEFT.Pressed()){
SetMouseNavigation(false); SetMouseNavigation(false);
if(std::holds_alternative<std::string>(nav.left)&&std::get<std::string>(nav.left).length()>0)selection=components[std::get<std::string>(nav.left)]; if(std::holds_alternative<std::string>(nav.left)&&std::get<std::string>(nav.left).length()>0)selection=components[std::get<std::string>(nav.left)];
else else
if(std::holds_alternative<MenuDataFunc>(nav.left))std::get<MenuDataFunc>(nav.left)(type); if(std::holds_alternative<MenuDataFunc>(nav.left))std::get<MenuDataFunc>(nav.left)(type);
} }
if(game->KEY_RIGHT.Pressed()){ if(game->KEY_RIGHT.Pressed()){
SetMouseNavigation(false); SetMouseNavigation(false);
if(std::holds_alternative<std::string>(nav.right)&&std::get<std::string>(nav.right).length()>0)selection=components[std::get<std::string>(nav.right)]; if(std::holds_alternative<std::string>(nav.right)&&std::get<std::string>(nav.right).length()>0)selection=components[std::get<std::string>(nav.right)];
else else
if(std::holds_alternative<MenuDataFunc>(nav.right))std::get<MenuDataFunc>(nav.right)(type); if(std::holds_alternative<MenuDataFunc>(nav.right))std::get<MenuDataFunc>(nav.right)(type);
}
} }
} }

View File

@ -163,7 +163,6 @@ public:
}else{ }else{
component->depth=depth; component->depth=depth;
} }
RecalculateComponentCount();
if(components.count(componentKey)){ if(components.count(componentKey)){
ERR("WARNING! Key "<<componentKey<<" for this sub-menu already exists! Key names must be unique!") ERR("WARNING! Key "<<componentKey<<" for this sub-menu already exists! Key names must be unique!")
@ -174,6 +173,8 @@ public:
components.SetInitialized(); components.SetInitialized();
lastRegisteredComponent=componentKey; lastRegisteredComponent=componentKey;
RecalculateComponentCount();
return component; return component;
} }
void Update(AiL*game); void Update(AiL*game);

View File

@ -74,6 +74,7 @@ class MenuComponent:public IAttributable{
friend class MenuItemButton; friend class MenuItemButton;
friend class ScrollableWindowComponent; friend class ScrollableWindowComponent;
friend class InventoryScrollableWindowComponent; friend class InventoryScrollableWindowComponent;
friend class EncountersSpawnListScrollableWindowComponent;
friend class MenuItemItemButton; friend class MenuItemItemButton;
friend class RowItemDisplay; friend class RowItemDisplay;
MenuType menuDest; MenuType menuDest;

View File

@ -11,6 +11,8 @@ Settings Menu
remove that bind from the list. Up to two keys may be binded per action. remove that bind from the list. Up to two keys may be binded per action.
-We have to save keybinds to the save file. -We have to save keybinds to the save file.
- Fix Stage Completed screen, item displays can hit the scrollbar.
January 31st January 31st
============ ============
Make new unlocked nodes more obvious, made neighboring nodes more obvious Make new unlocked nodes more obvious, made neighboring nodes more obvious
@ -28,10 +30,9 @@ Story proofreading/correcting/storyboarding
- Lock up unimplemented classes. - Lock up unimplemented classes.
- Don't enable all stage plates normally. - Don't enable all stage plates normally.
- Hide mouse cursor during controller play. Reveal it again during mouse play.
- Emscripten _DEBUG flag add as an option when building
mainMenuWindow->SetupKeyboardNavigation( mainMenuWindow->SetupKeyboardNavigation(
{ {

View File

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 2 #define VERSION_MINOR 2
#define VERSION_PATCH 1 #define VERSION_PATCH 1
#define VERSION_BUILD 5969 #define VERSION_BUILD 5974
#define stringify(a) stringify_(a) #define stringify(a) stringify_(a)
#define stringify_(a) #a #define stringify_(a) #a