//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.label(RichText::new(format!("Bones: {}", resources.bones)).size(large_font_size)); ui.heading(RichText::new("Buildings").underline()); for (info, cost, name) in buildings.iter() { if !info.unlocked { continue; } let souls_text = if cost.souls > 0 { format!("{} souls", cost.souls) } else { "".to_string() }; let divider_text = if cost.souls > 0 && cost.bones > 0 { ", " } else if cost.souls == 0 && cost.bones == 0 { "FREE!!!" } else { "" }; let bones_text = if cost.bones > 0 { format!("{} bones", cost.bones) } else { "".to_string() }; if ui .button( RichText::new(format!( "{} - {}{}{}", name, souls_text, divider_text, bones_text )) .size(font_size), ) .clicked() { select_writer.write(SelectBuildingPreview(Some(info.preview))); } } }); }