//bevy system signatures often violate these rules #![allow(clippy::type_complexity)] #![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) { app.add_systems( EguiPrimaryContextPass, resource_ui.run_if(in_state(GameUIState::Default)), ); } } fn resource_ui( mut contexts: EguiContexts, resources: Res, buildings: Query<(&BuildingInfo, &Cost, &Name)>, mut select_writer: EventWriter, ) { 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))); } } }); }