add tower selection UI, cancellable actions, and pause UI

This commit is contained in:
Jim 2025-08-31 12:08:44 -04:00
parent 138a524abd
commit 918b4884b2
Signed by: jim
GPG key ID: 3D7D94BA53088BF4
18 changed files with 468 additions and 23 deletions

View file

@ -5,6 +5,7 @@ edition = "2024"
[dependencies]
bevy = { workspace = true }
bevy_egui = { workspace = true }
state = { path = "../state" }
input = { path = "../input" }

View file

@ -3,7 +3,11 @@
#![allow(clippy::too_many_arguments)]
use bevy::prelude::*;
use input::{actions::InputAction, conditions::action_just_pressed};
use bevy_egui::{
EguiContexts, EguiPrimaryContextPass,
egui::{self, Align2, RichText},
};
use input::{Cancellable, actions::InputAction, conditions::action_just_pressed};
use state::GameState;
pub struct UiPausePlugin;
@ -13,11 +17,35 @@ impl Plugin for UiPausePlugin {
app.add_systems(
Update,
toggle_pause.run_if(action_just_pressed::<Update>(InputAction::TogglePause)),
)
.add_systems(
EguiPrimaryContextPass,
pause_screen.run_if(in_state(GameState::Paused)),
);
}
}
fn toggle_pause(state: Res<State<GameState>>, mut next_state: ResMut<NextState<GameState>>) {
fn pause_screen(mut contexts: EguiContexts) {
let ctx = contexts.ctx_mut().unwrap();
egui::Window::new("Pause")
.resizable(false)
.collapsible(false)
.title_bar(false)
.anchor(Align2::CENTER_CENTER, [0., 0.])
.show(ctx, |ui| {
ui.label(RichText::new(format!("Paused")).size(64.));
});
}
fn toggle_pause(
state: Res<State<GameState>>,
mut next_state: ResMut<NextState<GameState>>,
query: Query<(), With<Cancellable>>,
) {
if !query.is_empty() {
// cancelling takes priority over pausing
return;
}
let next = match state.get() {
GameState::Loading => GameState::Loading,
GameState::Running => GameState::Paused,