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

@ -3,9 +3,59 @@
#![allow(clippy::too_many_arguments)]
use bevy::prelude::*;
use bevy_egui::{
EguiContexts, EguiPrimaryContextPass,
egui::{self, Align2, RichText},
};
use building::BuildingInfo;
use building_placement::SelectBuildingPreview;
use resources::{Cost, Resources};
use ui_state::GameUIState;
pub struct UiIngamePlugin;
impl Plugin for UiIngamePlugin {
fn build(&self, app: &mut App) {}
fn build(&self, app: &mut App) {
app.add_systems(
EguiPrimaryContextPass,
resource_ui.run_if(in_state(GameUIState::Default)),
);
}
}
fn resource_ui(
mut contexts: EguiContexts,
resources: Res<Resources>,
buildings: Query<(&BuildingInfo, &Cost, &Name)>,
mut select_writer: EventWriter<SelectBuildingPreview>,
) {
let ctx = contexts.ctx_mut().unwrap();
let large_font_size = 24.;
let font_size = 16.;
egui::Window::new("Resources")
.resizable(false)
.collapsible(false)
.title_bar(false)
.anchor(Align2::RIGHT_TOP, [0., 0.])
.show(ctx, |ui| {
ui.label(RichText::new(format!("Souls: {}", resources.souls)).size(large_font_size));
ui.heading(RichText::new("Buildings").underline());
for (info, cost, name) in buildings.iter() {
if !info.unlocked {
continue;
}
if ui
.button(
RichText::new(format!(
"{} - {} souls, {} bones",
name, cost.souls, cost.bones
))
.size(font_size),
)
.clicked()
{
select_writer.write(SelectBuildingPreview(Some(info.preview)));
}
}
});
}