Merge branch '66-add-keybinds' into 'dev'

Add keybinds for Inventory and Settings

See merge request softwaregrundprojekt/2025-2026/einzelprojekt/tutorium-moritz/bernroider-dominik/bernroider-dominik!41
This commit is contained in:
Dominik Bernroider
2025-12-10 17:31:48 +00:00
2 changed files with 27 additions and 5 deletions

View File

@@ -59,13 +59,13 @@ fn setup(mut commands: Commands, game_config: Res<GameConfig>, asset_server: Res
inventory::components::ButtonType::InventoryOpen,
ButtonVariant::Secondary,
Node::from_padding(UiRect::all(px(10))),
|color| text("Inventar", 16.0, color)
|color| text("Inventar [I]", 16.0, color)
),
button(
ButtonType::SettingsOpen,
ButtonVariant::Secondary,
Node::from_padding(UiRect::all(px(10))),
|color| text("Einstellungen", 16.0, color)
|color| text("Einstellungen [Esc]", 16.0, color)
)
],
));

View File

@@ -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::<ClosePopupMessage>();
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<ButtonInput<KeyCode>>,
mut commands: Commands,
item_stacks: Query<&ItemStack>,
game_config: Res<GameConfig>,
asset_server: Res<AssetServer>,
) {
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<ClosePopupMessage>,
keys: Res<ButtonInput<KeyCode>>,
popup_query: Query<Entity, With<PopupRoot>>,
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);
}
}
}