fix(android): close HUD popovers on Escape instead of opening Pause
When the Menu or Modes popover was open, pressing Escape (Android back) fired the Pause system instead of closing the popover, because both systems listened to the same key with no coordination. Fix: - Add HudPopoverOpen marker to both popover entities on spawn. - Add close_menu/modes_popover_on_escape systems in HudPlugin that despawn the popover + backdrop when Escape is pressed. - Guard toggle_pause with an open_hud_popovers query: bail if any HudPopoverOpen entity exists, preventing Pause from stacking behind the closing popover. - Init ButtonInput<KeyCode> in HudPlugin::build() so the new systems work under MinimalPlugins in tests. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -35,6 +35,7 @@ use crate::resources::{DragState, GameStateResource};
|
||||
use crate::selection_plugin::{SelectionKeySet, SelectionState};
|
||||
use crate::settings_plugin::{SettingsChangedEvent, SettingsResource, SettingsStoragePath};
|
||||
use crate::stats_plugin::StatsResource;
|
||||
use crate::hud_plugin::HudPopoverOpen;
|
||||
use crate::ui_modal::{
|
||||
spawn_modal, spawn_modal_actions, spawn_modal_body_text, spawn_modal_button,
|
||||
spawn_modal_header, ButtonVariant, ModalScrim,
|
||||
@@ -137,6 +138,7 @@ struct PauseModalQueries<'w, 's> {
|
||||
forfeit_screens: Query<'w, 's, Entity, With<ForfeitConfirmScreen>>,
|
||||
game_over_screens: Query<'w, 's, Entity, With<GameOverScreen>>,
|
||||
other_modal_scrims: Query<'w, 's, Entity, (With<ModalScrim>, Without<PauseScreen>)>,
|
||||
open_hud_popovers: Query<'w, 's, Entity, With<HudPopoverOpen>>,
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
@@ -162,6 +164,7 @@ fn toggle_pause(
|
||||
forfeit_screens,
|
||||
game_over_screens,
|
||||
other_modal_scrims,
|
||||
open_hud_popovers,
|
||||
} = modal_queries;
|
||||
|
||||
// Either Esc or a click on the HUD "Pause" button (which fires
|
||||
@@ -186,6 +189,12 @@ fn toggle_pause(
|
||||
if !other_modal_scrims.is_empty() {
|
||||
return;
|
||||
}
|
||||
// A HUD popover (Menu or Modes dropdown) is open — the popover's own
|
||||
// Escape handler (in HudPlugin) will close it this frame. Don't also
|
||||
// spawn the pause overlay on top of the closing popover.
|
||||
if !open_hud_popovers.is_empty() {
|
||||
return;
|
||||
}
|
||||
// If a replay is currently playing, let `replay_overlay::handle_stop_keyboard`
|
||||
// own the Esc press — that handler stops the replay. Without this guard a
|
||||
// single Esc both stops the replay AND opens the pause modal on top of the
|
||||
|
||||
Reference in New Issue
Block a user