| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459 |
- use egui::{Color32, RichText};
- use crate::sim::inventory::ItemKind;
- use crate::sim::orders::{AiAssistRequest, RulesOfEngagement, SquadFormation};
- use crate::sim::radio::{RadioEar, RadioState, FREQ_STEP_KHZ, MAX_FREQ_KHZ, MIN_FREQ_KHZ};
- use crate::sim::Simulation;
- #[derive(Clone, Debug)]
- pub struct TacticalWindowsState {
- pub show_squad: bool,
- pub show_radio: bool,
- pub show_inventory: bool,
- pub show_ai_bar: bool,
- pub new_squad_name: String,
- pub radio_loopback_test: bool,
- }
- impl Default for TacticalWindowsState {
- fn default() -> Self {
- Self {
- show_squad: false,
- show_radio: false,
- show_inventory: false,
- show_ai_bar: false,
- new_squad_name: "Alpha-2".to_string(),
- radio_loopback_test: false,
- }
- }
- }
- #[derive(Default)]
- pub struct TacticalWindowActions {
- pub radio_tuned: bool,
- pub create_squad_name: Option<String>,
- pub join_squad_id: Option<usize>,
- pub leave_squad: bool,
- pub recruit_ai_squad_id: Option<usize>,
- pub set_formation: Option<(usize, SquadFormation)>,
- pub set_roe: Option<(usize, RulesOfEngagement)>,
- pub set_squad_freq: Option<(usize, u32)>,
- pub deploy_rally: bool,
- pub ai_assist: Option<AiAssistRequest>,
- pub use_item: Option<ItemKind>,
- pub do_mag_check: bool,
- pub do_mag_repack: bool,
- }
- pub fn draw_tactical_windows(
- ctx: &egui::Context,
- sim: &mut Simulation,
- state: &mut TacticalWindowsState,
- mic_available: bool,
- ) -> TacticalWindowActions {
- let mut actions = TacticalWindowActions::default();
- if state.show_squad {
- draw_squad_manager_window(ctx, sim, state, &mut actions);
- }
- if state.show_radio {
- draw_radio_tuner_window(ctx, sim, state, mic_available, &mut actions);
- }
- if state.show_inventory {
- draw_inventory_window(ctx, sim, state, &mut actions);
- }
- if state.show_ai_bar {
- draw_ai_quick_bar(ctx, sim, state, &mut actions);
- }
- actions
- }
- fn draw_squad_manager_window(
- ctx: &egui::Context,
- sim: &mut Simulation,
- state: &mut TacticalWindowsState,
- actions: &mut TacticalWindowActions,
- ) {
- let my_sq = sim.player_squad_id();
- let my_faction = sim.player.faction;
- let mut open = state.show_squad;
- egui::Window::new("🛡 Squad Manager [U]")
- .open(&mut open)
- .default_width(370.0)
- .resizable(true)
- .show(ctx, |ui| {
- ui.horizontal(|ui| {
- ui.label("New Squad:");
- ui.text_edit_singleline(&mut state.new_squad_name);
- if ui.button("Create").clicked() {
- actions.create_squad_name = Some(state.new_squad_name.clone());
- }
- if my_sq.is_some() && ui.button("Leave").clicked() {
- actions.leave_squad = true;
- }
- });
- ui.separator();
- ui.label(RichText::new("Friendly Squads:").strong());
- egui::ScrollArea::vertical().max_height(155.0).show(ui, |ui| {
- for sq in &sim.squads {
- if sq.faction != my_faction {
- continue;
- }
- let alive_cnt = sq
- .member_ids
- .iter()
- .filter(|&&id| sim.soldiers.get(id).is_some_and(|s| s.alive))
- .count();
- let is_mine = my_sq == Some(sq.id);
- ui.horizontal(|ui| {
- let col = if is_mine {
- Color32::from_rgb(135, 240, 155)
- } else {
- Color32::from_rgb(220, 224, 230)
- };
- ui.colored_label(
- col,
- format!(
- "{} ({} alive) | {} | {} | {:.3} MHz",
- sq.name,
- alive_cnt,
- sq.formation.label(),
- sq.roe.label(),
- sq.radio_freq_khz as f32 / 1000.0
- ),
- );
- if !is_mine && !sq.locked && ui.small_button("Join").clicked() {
- actions.join_squad_id = Some(sq.id);
- }
- });
- }
- });
- if let Some(sq_id) = my_sq {
- if let Some(sq) = sim.squads.get_mut(sq_id) {
- ui.separator();
- ui.horizontal(|ui| {
- ui.strong(format!("Active Squad: {}", sq.name));
- ui.checkbox(&mut sq.locked, "Lock Squad");
- });
- ui.horizontal(|ui| {
- ui.label("Formation:");
- for &fmt in &SquadFormation::ALL {
- if ui.selectable_label(sq.formation == fmt, fmt.label()).clicked() {
- actions.set_formation = Some((sq_id, fmt));
- }
- }
- });
- ui.horizontal(|ui| {
- ui.label("ROE:");
- for &roe in &RulesOfEngagement::ALL {
- if ui.selectable_label(sq.roe == roe, roe.label()).clicked() {
- actions.set_roe = Some((sq_id, roe));
- }
- }
- });
- let freq = sq.radio_freq_khz;
- ui.horizontal(|ui| {
- if ui.button("Recruit Nearby AI (+4)").clicked() {
- actions.recruit_ai_squad_id = Some(sq_id);
- }
- if ui.button("Deploy Rally Point").clicked() {
- actions.deploy_rally = true;
- }
- if ui
- .button(format!("Sync Squad Net ({:.3} MHz)", freq as f32 / 1000.0))
- .clicked()
- {
- actions.set_squad_freq = Some((sq_id, sim.player.radio.active_freq_khz()));
- }
- });
- }
- } else {
- ui.separator();
- ui.weak("Create or join a friendly squad to manage formations, ROE & rally beacons.");
- }
- });
- state.show_squad = open;
- }
- fn draw_radio_tuner_window(
- ctx: &egui::Context,
- sim: &mut Simulation,
- state: &mut TacticalWindowsState,
- mic_available: bool,
- actions: &mut TacticalWindowActions,
- ) {
- let mut open = state.show_radio;
- egui::Window::new("📻 Tactical VHF Radio [N]")
- .open(&mut open)
- .default_width(350.0)
- .resizable(true)
- .show(ctx, |ui| {
- let radio = &mut sim.player.radio;
- ui.horizontal(|ui| {
- ui.strong(radio.radio_type.label());
- ui.separator();
- if ui.checkbox(&mut radio.encrypted, "Encrypt (Faction Key)").clicked() {
- actions.radio_tuned = true;
- }
- });
- ui.weak("Clear traffic can be heard across factions; Enable Encrypt to block eavesdropping.");
- ui.separator();
- // Primary channel
- ui.label(
- RichText::new(format!(
- "Primary Channel: {}",
- RadioState::format_freq_mhz(radio.primary_freq_khz)
- ))
- .size(16.0)
- .color(Color32::from_rgb(135, 235, 165)),
- );
- let mut mhz = radio.primary_freq_khz as f32 / 1000.0;
- if ui
- .add(
- egui::Slider::new(
- &mut mhz,
- (MIN_FREQ_KHZ as f32 / 1000.0)..=(MAX_FREQ_KHZ as f32 / 1000.0),
- )
- .step_by(FREQ_STEP_KHZ as f64 / 1000.0)
- .fixed_decimals(3)
- .text("MHz"),
- )
- .changed()
- {
- radio.tune_primary((mhz * 1000.0).round() as u32);
- actions.radio_tuned = true;
- }
- ui.horizontal(|ui| {
- for (lbl, delta) in [("-1 MHz", -1000), ("-25 kHz", -25), ("+25 kHz", 25), ("+1 MHz", 1000)] {
- if ui.small_button(lbl).clicked() {
- radio.step_primary(delta);
- actions.radio_tuned = true;
- }
- }
- });
- ui.horizontal(|ui| {
- ui.label("Ear Routing:");
- for &ear in &RadioEar::ALL {
- if ui.selectable_label(radio.primary_ear == ear, ear.label()).clicked() {
- radio.primary_ear = ear;
- actions.radio_tuned = true;
- }
- }
- });
- ui.horizontal(|ui| {
- ui.label("Presets:");
- let presets = radio.presets_khz;
- for (idx, p) in presets.iter().enumerate() {
- if ui
- .small_button(format!("Ch{} {:.2}", idx + 1, *p as f32 / 1000.0))
- .clicked()
- {
- radio.tune_primary(*p);
- actions.radio_tuned = true;
- }
- }
- });
- if radio.radio_type.supports_dual_watch() {
- ui.separator();
- let sec_khz = radio.secondary_freq_khz.unwrap_or(MIN_FREQ_KHZ);
- ui.label(
- RichText::new(format!(
- "Secondary Watch (Manpack): {}",
- radio
- .secondary_freq_khz
- .map_or_else(|| "OFF".into(), RadioState::format_freq_mhz)
- ))
- .color(Color32::from_rgb(160, 210, 250)),
- );
- ui.horizontal(|ui| {
- if ui.small_button("Command 68.0").clicked() {
- radio.tune_secondary(Some(68_000));
- actions.radio_tuned = true;
- }
- if ui.small_button("-25k").clicked() {
- radio.tune_secondary(Some(sec_khz.saturating_sub(25)));
- actions.radio_tuned = true;
- }
- if ui.small_button("+25k").clicked() {
- radio.tune_secondary(Some(sec_khz + 25));
- actions.radio_tuned = true;
- }
- if ui.small_button("Disable").clicked() {
- radio.tune_secondary(None);
- actions.radio_tuned = true;
- }
- });
- ui.horizontal(|ui| {
- ui.label("Secondary Ear:");
- for &ear in &RadioEar::ALL {
- if ui.selectable_label(radio.secondary_ear == ear, ear.label()).clicked() {
- radio.secondary_ear = ear;
- actions.radio_tuned = true;
- }
- }
- });
- }
- ui.separator();
- ui.horizontal(|ui| {
- let mic_col = if mic_available {
- Color32::from_rgb(120, 235, 145)
- } else {
- Color32::from_rgb(240, 175, 95)
- };
- ui.colored_label(
- mic_col,
- if mic_available { "Mic: Ready" } else { "Mic: Unavailable" },
- );
- ui.checkbox(&mut state.radio_loopback_test, "Loopback Mic Test (DSP)");
- });
- ui.weak("PTT Keys: Hold [CapsLock] Proximity (35m BVH occluded) | Hold [X] Radio TX");
- ui.separator();
- ui.strong("Comms & Radio Log:");
- egui::ScrollArea::vertical().max_height(130.0).show(ui, |ui| {
- for entry in sim.radio_log.iter().rev() {
- let prefix = if entry.is_proximity {
- "[PROX]".to_string()
- } else if let Some(f) = entry.freq_khz {
- format!("[{:.3}]", f as f32 / 1000.0)
- } else {
- "[NET]".to_string()
- };
- ui.label(format!("{prefix} {}: {}", entry.sender, entry.text));
- }
- });
- });
- state.show_radio = open;
- }
- fn draw_inventory_window(
- ctx: &egui::Context,
- sim: &mut Simulation,
- state: &mut TacticalWindowsState,
- actions: &mut TacticalWindowActions,
- ) {
- let mut open = state.show_inventory;
- egui::Window::new("🎒 Inventory, Kit & Magazines [I]")
- .open(&mut open)
- .default_width(360.0)
- .resizable(true)
- .show(ctx, |ui| {
- let p = &mut sim.player;
- let weight = p.inventory.total_weight_kg(&p.mag_banks);
- let spd_pct = (p.inventory.speed_multiplier(weight) * 100.0).round();
- ui.horizontal(|ui| {
- ui.strong(format!("Kit: {}", p.inventory.kit.label()));
- ui.separator();
- ui.label(format!("Load: {weight:.1} kg (Speed {spd_pct:.0}%)"));
- });
- if p.bleed_rate > 0.01 {
- ui.colored_label(
- Color32::from_rgb(245, 95, 85),
- format!("⚠ BLEEDING ({:.1} HP/s) — Use Field Bandage [7]!", p.bleed_rate),
- );
- }
- ui.separator();
- ui.strong("Field Gear & Consumables:");
- let items = p.inventory.items.clone();
- for slot in items {
- if slot.count == 0 {
- continue;
- }
- ui.horizontal(|ui| {
- ui.label(format!("{} x{}", slot.kind.label(), slot.count));
- if !matches!(slot.kind, ItemKind::RadioUnit(_)) && ui.small_button("Use").clicked() {
- actions.use_item = Some(slot.kind);
- }
- });
- }
- ui.separator();
- let (loaded_rounds, can_repack, chambered, cap, spares, w_name) = {
- let bank = p.current_mag_state();
- (
- bank.loaded_mag_rounds(),
- bank.can_repack(),
- bank.chambered,
- bank.capacity,
- bank.spare_mags.clone(),
- p.weapon.spec().name,
- )
- };
- ui.horizontal(|ui| {
- ui.strong(format!("Magazines ({w_name}):"));
- if ui.small_button("Mag Check [Ctrl+R]").clicked() {
- actions.do_mag_check = true;
- }
- if can_repack && ui.small_button("Repack [Shift+R]").clicked() {
- actions.do_mag_repack = true;
- }
- });
- ui.checkbox(&mut p.show_exact_ammo_hud, "Show Exact Round Counts on HUD");
- let chamber_str = if chambered { "+1 in chamber" } else { "chamber empty" };
- ui.label(format!("Loaded Mag: {loaded_rounds} / {cap} ({chamber_str})"));
- egui::ScrollArea::vertical().max_height(105.0).show(ui, |ui| {
- for (i, m) in spares.iter().enumerate() {
- let frac = m.fill_fraction();
- ui.horizontal(|ui| {
- ui.label(format!("Spare #{}:", i + 1));
- ui.add(
- egui::ProgressBar::new(frac)
- .desired_width(140.0)
- .text(format!("{}/{}", m.rounds, m.capacity)),
- );
- });
- }
- });
- });
- state.show_inventory = open;
- }
- fn draw_ai_quick_bar(
- ctx: &egui::Context,
- sim: &Simulation,
- state: &mut TacticalWindowsState,
- actions: &mut TacticalWindowActions,
- ) {
- let mut open = state.show_ai_bar;
- egui::Window::new("⚡ AI Squad Helpers [Z]")
- .open(&mut open)
- .anchor(egui::Align2::CENTER_BOTTOM, [0.0, -76.0])
- .title_bar(true)
- .resizable(false)
- .show(ctx, |ui| {
- ui.horizontal(|ui| {
- if ui.button("🏥 Call Medic").clicked() {
- actions.ai_assist = Some(AiAssistRequest::NeedMedic);
- }
- if ui.button("📦 Call Ammo").clicked() {
- actions.ai_assist = Some(AiAssistRequest::NeedAmmo);
- }
- if ui.button("🏃 Follow Me").clicked() {
- actions.ai_assist = Some(AiAssistRequest::FollowMe);
- }
- if ui.button("💨 Pop Smoke").clicked() {
- let target = sim.player.pos + glam::Vec3::new(sim.player.yaw.sin(), 0.0, -sim.player.yaw.cos()) * 14.0;
- actions.ai_assist = Some(AiAssistRequest::PopSmoke(target));
- }
- if ui.button("🚙 Mount Vehicle").clicked() {
- let vid = sim.player.in_vehicle.map(|(v, _)| v).unwrap_or(usize::MAX);
- actions.ai_assist = Some(AiAssistRequest::MountMyVehicle(vid));
- }
- if ui.button("⬇ Dismount All").clicked() {
- actions.ai_assist = Some(AiAssistRequest::DismountAll);
- }
- });
- });
- state.show_ai_bar = open;
- }
|