From 81ff75630e6acf9b2ba6a010a4db593b655ac78b Mon Sep 17 00:00:00 2001 From: demenik Date: Wed, 10 Dec 2025 18:28:55 +0100 Subject: [PATCH] feat: add keybinds for inventory and settings (#66) --- src/features/input/mod.rs | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/features/input/mod.rs b/src/features/input/mod.rs index d2dd287..a57be0b 100644 --- a/src/features/input/mod.rs +++ b/src/features/input/mod.rs @@ -1,9 +1,11 @@ use crate::features::{ + hud::ui::settings::open_settings, input::utils::mouse_to_grid, + inventory::{components::ItemStack, ui::open_inventory}, phase::messages::{NextPhaseMessage, PhaseTimerPauseMessage}, pom::messages::InvalidMoveMessage, shop::ui::open_shop, - ui::messages::ClosePopupMessage, + ui::{messages::ClosePopupMessage, ui::popups::PopupRoot}, }; use crate::prelude::*; use bevy::input::mouse::MouseButton; @@ -40,6 +42,7 @@ impl Plugin for InputPlugin { app.add_systems(Update, next_phase.run_if(in_state(AppState::GameScreen))); app.add_systems(Update, shop_keybind.run_if(in_state(AppState::GameScreen))); + app.add_systems(Update, inventory_keybind.run_if(in_state(AppState::GameScreen))); app.add_message::(); app.add_systems(Update, popup_keybind); @@ -261,12 +264,31 @@ fn shop_keybind( } } -/// Closes popups on Escape press. +/// Opens the inventory on 'I' press. +fn inventory_keybind( + keys: Res>, + mut commands: Commands, + item_stacks: Query<&ItemStack>, + game_config: Res, + asset_server: Res, +) { + if keys.just_pressed(KeyCode::KeyI) { + open_inventory(&mut commands, item_stacks, &game_config, &asset_server); + } +} + +/// Closes popups on Escape press or opens settings if no popup is open. fn popup_keybind( mut close_popup_messages: MessageWriter, keys: Res>, + popup_query: Query>, + mut commands: Commands, ) { if keys.just_pressed(KeyCode::Escape) { - close_popup_messages.write(ClosePopupMessage); + if !popup_query.is_empty() { + close_popup_messages.write(ClosePopupMessage); + } else { + open_settings(&mut commands); + } } }