2025-08-30 23:39:18 -04:00
|
|
|
//bevy system signatures often violate these rules
|
|
|
|
|
#![allow(clippy::type_complexity)]
|
|
|
|
|
#![allow(clippy::too_many_arguments)]
|
|
|
|
|
|
|
|
|
|
use bevy::prelude::*;
|
2025-08-31 12:08:44 -04:00
|
|
|
use bevy_egui::{
|
|
|
|
|
EguiContexts, EguiPrimaryContextPass,
|
|
|
|
|
egui::{self, Align2, RichText},
|
|
|
|
|
};
|
|
|
|
|
use building::BuildingInfo;
|
|
|
|
|
use building_placement::SelectBuildingPreview;
|
2025-08-31 22:26:07 -04:00
|
|
|
use input::{SelectEntity, Selected};
|
|
|
|
|
use resources::{AvailableWorkers, Cost, ResourceDeposit, Resources, WorkedResourceDeposit};
|
2025-08-31 12:08:44 -04:00
|
|
|
use ui_state::GameUIState;
|
2025-08-31 23:59:50 -04:00
|
|
|
use upgrade::{UnlockUpgrade, Upgradable, Upgrade};
|
2025-08-30 23:39:18 -04:00
|
|
|
|
|
|
|
|
pub struct UiIngamePlugin;
|
|
|
|
|
|
|
|
|
|
impl Plugin for UiIngamePlugin {
|
2025-08-31 12:08:44 -04:00
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
|
app.add_systems(
|
|
|
|
|
EguiPrimaryContextPass,
|
|
|
|
|
resource_ui.run_if(in_state(GameUIState::Default)),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn resource_ui(
|
|
|
|
|
mut contexts: EguiContexts,
|
2025-08-31 22:26:07 -04:00
|
|
|
mut commands: Commands,
|
2025-08-31 12:08:44 -04:00
|
|
|
resources: Res<Resources>,
|
2025-08-31 22:26:07 -04:00
|
|
|
mut available_workers: ResMut<AvailableWorkers>,
|
2025-08-31 12:08:44 -04:00
|
|
|
buildings: Query<(&BuildingInfo, &Cost, &Name)>,
|
2025-08-31 22:26:07 -04:00
|
|
|
selected: Query<(Entity, &Name), With<Selected>>,
|
2025-08-31 23:59:50 -04:00
|
|
|
upgradable: Query<&Upgradable>,
|
|
|
|
|
upgrades: Query<(&Upgrade, &Name)>,
|
2025-08-31 22:26:07 -04:00
|
|
|
mut selected_resource_deposit: Query<(&ResourceDeposit, Option<&mut WorkedResourceDeposit>)>,
|
|
|
|
|
mut selected_preview_writer: EventWriter<SelectBuildingPreview>,
|
|
|
|
|
mut select_writer: EventWriter<SelectEntity>,
|
2025-08-31 12:08:44 -04:00
|
|
|
) {
|
|
|
|
|
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| {
|
2025-08-31 22:26:07 -04:00
|
|
|
if let Ok((selected, selected_name)) = selected.single() {
|
|
|
|
|
if ui.button("x").clicked() {
|
|
|
|
|
select_writer.write(SelectEntity(None));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ui.heading(selected_name.as_str());
|
2025-08-31 23:59:50 -04:00
|
|
|
// resource deposit management
|
2025-08-31 22:26:07 -04:00
|
|
|
if let Ok((deposit, mut opt_worked)) = selected_resource_deposit.get_mut(selected) {
|
|
|
|
|
ui.label(
|
|
|
|
|
RichText::new(format!("Level {} deposit", deposit.level)).size(font_size),
|
|
|
|
|
);
|
|
|
|
|
ui.heading(
|
|
|
|
|
RichText::new(if let Some(ref worked) = opt_worked {
|
|
|
|
|
format!("{} workers", worked.workers)
|
|
|
|
|
} else {
|
|
|
|
|
"Not worked".to_string()
|
|
|
|
|
})
|
|
|
|
|
.size(large_font_size)
|
|
|
|
|
.underline(),
|
|
|
|
|
);
|
|
|
|
|
// worker management buttons
|
|
|
|
|
// add
|
|
|
|
|
if available_workers.0 == 0 {
|
|
|
|
|
ui.add_enabled(false, egui::Button::new("No workers available"));
|
|
|
|
|
} else {
|
|
|
|
|
if ui.button("Add worker").clicked() {
|
|
|
|
|
available_workers.0 = available_workers.0.saturating_sub(1);
|
|
|
|
|
if let Some(ref mut worked) = opt_worked {
|
|
|
|
|
worked.workers = worked.workers.saturating_add(1);
|
|
|
|
|
} else {
|
|
|
|
|
commands.entity(selected).insert(WorkedResourceDeposit {
|
|
|
|
|
workers: 1,
|
|
|
|
|
..default()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// remove
|
|
|
|
|
if let Some(ref mut worked) = opt_worked {
|
|
|
|
|
if ui.button("Remove worker").clicked() {
|
|
|
|
|
worked.workers = worked.workers.saturating_sub(1);
|
|
|
|
|
available_workers.0 = available_workers.0.saturating_add(1);
|
|
|
|
|
if worked.workers == 0 {
|
|
|
|
|
commands.entity(selected).remove::<WorkedResourceDeposit>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ui.heading(RichText::new("Bounty").underline());
|
|
|
|
|
ui.label(
|
|
|
|
|
RichText::new(format!("Souls: {}", deposit.bounty.souls)).size(font_size),
|
|
|
|
|
);
|
|
|
|
|
ui.label(
|
|
|
|
|
RichText::new(format!("Bones: {}", deposit.bounty.bones)).size(font_size),
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-08-31 23:59:50 -04:00
|
|
|
|
|
|
|
|
//upgrades
|
|
|
|
|
if let Ok(Upgradable {
|
|
|
|
|
active_upgrades,
|
|
|
|
|
available_upgrades,
|
|
|
|
|
..
|
|
|
|
|
}) = upgradable.get(selected)
|
|
|
|
|
{
|
|
|
|
|
if !active_upgrades.is_empty() && !available_upgrades.is_empty() {
|
|
|
|
|
ui.heading(RichText::new("Upgrades").underline());
|
|
|
|
|
}
|
|
|
|
|
for (upgrade_entity, upgrade, upgrade_name) in available_upgrades
|
|
|
|
|
.iter()
|
|
|
|
|
.filter_map(|u| upgrades.get(*u).map(|(up, n)| (*u, up, n)).ok())
|
|
|
|
|
{
|
|
|
|
|
if ui
|
|
|
|
|
.button(RichText::new(upgrade_name.as_str()).size(large_font_size))
|
|
|
|
|
.clicked()
|
|
|
|
|
{
|
|
|
|
|
commands.trigger_targets(
|
|
|
|
|
UnlockUpgrade { building: selected },
|
|
|
|
|
upgrade_entity,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
ui.label(RichText::new(upgrade.description.as_str()).size(font_size));
|
|
|
|
|
ui.label(RichText::new(upgrade.cost.to_string()).size(font_size));
|
|
|
|
|
}
|
|
|
|
|
if !active_upgrades.is_empty() {
|
|
|
|
|
ui.collapsing("Active Upgrades", |ui| {
|
|
|
|
|
for (upgrade, upgrade_name) in
|
|
|
|
|
active_upgrades.iter().filter_map(|u| upgrades.get(*u).ok())
|
|
|
|
|
{
|
|
|
|
|
ui.label(
|
|
|
|
|
RichText::new(upgrade_name.as_str()).size(large_font_size),
|
|
|
|
|
);
|
|
|
|
|
ui.label(
|
|
|
|
|
RichText::new(upgrade.description.as_str()).size(font_size),
|
|
|
|
|
);
|
|
|
|
|
ui.label(RichText::new(upgrade.cost.to_string()).size(font_size));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-08-31 22:26:07 -04:00
|
|
|
return;
|
|
|
|
|
}
|
2025-08-31 12:08:44 -04:00
|
|
|
ui.label(RichText::new(format!("Souls: {}", resources.souls)).size(large_font_size));
|
2025-08-31 19:00:19 -04:00
|
|
|
ui.label(RichText::new(format!("Bones: {}", resources.bones)).size(large_font_size));
|
2025-08-31 12:08:44 -04:00
|
|
|
ui.heading(RichText::new("Buildings").underline());
|
|
|
|
|
for (info, cost, name) in buildings.iter() {
|
|
|
|
|
if !info.unlocked {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2025-08-31 23:59:50 -04:00
|
|
|
|
2025-08-31 12:08:44 -04:00
|
|
|
if ui
|
|
|
|
|
.button(
|
2025-08-31 23:59:50 -04:00
|
|
|
RichText::new(format!("{} - {}", name, cost.0.to_string())).size(font_size),
|
2025-08-31 12:08:44 -04:00
|
|
|
)
|
|
|
|
|
.clicked()
|
|
|
|
|
{
|
2025-08-31 22:26:07 -04:00
|
|
|
selected_preview_writer.write(SelectBuildingPreview(Some(info.preview)));
|
2025-08-31 12:08:44 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2025-08-30 23:39:18 -04:00
|
|
|
}
|