Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions src/Features/VR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1554,18 +1554,27 @@ void VR::UpdateOverlayMenuStateFromInput()
return;
}

// Check if we're in a valid menu state for input
bool inValidMenuState = globals::game::ui &&
(globals::game::ui->IsMenuOpen(RE::MainMenu::MENU_NAME) || globals::game::ui->IsMenuOpen(RE::TweenMenu::MENU_NAME));
// Compute whether the game's UI menus we care about are open. Do this early so
// downstream logic can reuse the result and we only check the UI once.
bool uiMenusOpen = globals::game::ui &&
(globals::game::ui->IsMenuOpen(RE::MainMenu::MENU_NAME) || globals::game::ui->IsMenuOpen(RE::TweenMenu::MENU_NAME));
Comment thread
alandtse marked this conversation as resolved.

// Valid menu state means either one of those UI menus is open, or our menu is
// enabled (but only if the game's UI system is present).
bool inValidMenuState = uiMenusOpen || (globals::game::ui && isEnabled);

if (!inValidMenuState)
return;

// Define menu state mappings
// Define menu state mappings. The `allowWhenUIMenusClosed` flag controls whether
// a mapping is allowed to run when our menu is enabled but the game's UI menus
// are not reported open. This prevents 'open' controls from firing in that state
// while still allowing 'close' actions.
struct MenuStateMapping
{
std::function<bool()> condition;
std::function<void()> action;
bool allowWhenUIMenusClosed = false;
};

// Generic combo checking function - makes the system truly extensible
Expand Down Expand Up @@ -1616,7 +1625,8 @@ void VR::UpdateOverlayMenuStateFromInput()
{ [&]() {
return CheckCombo(settings.VRMenuCloseKeys) && isEnabled;
},
[&]() { isEnabled = false; } },
[&]() { isEnabled = false; },
true },

// Open VR overlay when closed
{ [&]() {
Expand All @@ -1631,8 +1641,15 @@ void VR::UpdateOverlayMenuStateFromInput()
[&]() { overlayEnabled = false; } }
};

// Process mappings in order
// Process mappings in order. If our menu is enabled but the game's UI menus
// are not open, only allow mappings explicitly marked with
// allowWhenUIMenusClosed (close actions).
bool onlyAllowClose = isEnabled && !uiMenusOpen;
Comment thread
alandtse marked this conversation as resolved.

for (const auto& mapping : mappings) {
if (onlyAllowClose && !mapping.allowWhenUIMenusClosed)
continue;

if (mapping.condition()) {
mapping.action();
break; // Only execute one action per frame
Expand Down