Add a command post and shared unit cards (#153)
This commit is contained in:
@@ -114,6 +114,7 @@ pub fn tree() -> Tree {
|
||||
Node::lit("reset").runs(),
|
||||
])),
|
||||
Node::lit("recon").runs(),
|
||||
Node::lit("post").runs().then(Node::arg("поиск", Value::word()).runs()),
|
||||
Node::lit("stats").runs(),
|
||||
])
|
||||
}
|
||||
@@ -170,7 +171,7 @@ mod tests {
|
||||
#[test]
|
||||
fn every_branch_of_the_handler_parses() {
|
||||
for line in [
|
||||
"", "menu", "capabilities", "monitor", "grid", "give", "raid", "repair", "import", "flare", "clear", "stats", "recon", "roles",
|
||||
"", "menu", "capabilities", "monitor", "grid", "post", "post Панцирь", "post 82", "give", "raid", "repair", "import", "flare", "clear", "stats", "recon", "roles",
|
||||
"replay", "replay map", "replay full", "replay reel", "replay film", "replay film best", "replay film all",
|
||||
"replay film 3", "replay export", "replay export mine", "replay export best", "replay export all", "replay export 3",
|
||||
"replay export mine all fps=30 size=1280x720 crf=18 sec=12.5 noaudio", "replay export fps=60", "replay stop",
|
||||
@@ -253,7 +254,8 @@ mod tests {
|
||||
"target", "give", "deploy", "wave", "clear", "targets", "damage", "truth", "shader", "hold", "lastchance", "roles", "doctrine", "stats", "recon", "sites", "strike", "ground-stock", "ground-load", "ground-unload", "ground-cancel", "chains"] {
|
||||
assert!(top.contains(&w.to_string()), "{w} in {top:?}");
|
||||
}
|
||||
assert_eq!(top.len(), 38);
|
||||
assert!(top.contains(&"post".to_string()));
|
||||
assert_eq!(top.len(), 39);
|
||||
assert_eq!(complete("rep", &[]), ["repair", "replay"]);
|
||||
assert_eq!(complete("replay ", &[]), ["export", "film", "full", "map", "reel", "stop"]);
|
||||
assert_eq!(complete("replay film ", &[]), ["all", "best"]);
|
||||
|
||||
+255
-25
@@ -9,7 +9,7 @@ use horizon_mod_sdk::{
|
||||
input::{self, Event},
|
||||
render::{self, Lighting, ModelInstanceId, ParticleSpawn, PointLight, SpotLight},
|
||||
storage,
|
||||
ui::{self, ButtonWidget, ItemWidget, ListWidget, Screen, Widget},
|
||||
ui::{self, ButtonWidget, ItemWidget, ListWidget, Screen, TextWidget, Widget},
|
||||
};
|
||||
|
||||
mod battery_view;
|
||||
@@ -23,6 +23,7 @@ pub mod film;
|
||||
mod monitor;
|
||||
mod overlay;
|
||||
mod panel;
|
||||
mod post;
|
||||
mod presentation;
|
||||
mod radar;
|
||||
mod recon_view;
|
||||
@@ -48,13 +49,14 @@ struct AirDef {
|
||||
/// second while guns fire, and a pause after a failed write).
|
||||
next_save: u64,
|
||||
hud_shown: bool,
|
||||
/// The system the monitor shows (K cycles), none: hidden.
|
||||
monitor: Option<usize>,
|
||||
/// The ID of the system the monitor shows (K cycles), none: hidden.
|
||||
monitor: Option<u32>,
|
||||
monitor_shown: bool,
|
||||
/// Every system's monitor in a grid (J).
|
||||
/// The optional grid of live cameras.
|
||||
grid: bool,
|
||||
/// The systems the grid shows (ids), the busiest, chosen every few seconds.
|
||||
grid_ids: Vec<u32>,
|
||||
post: post::Post,
|
||||
/// The raid the wave menu orders.
|
||||
wave: wave::WaveConfig,
|
||||
village: Option<village::Village>,
|
||||
@@ -210,6 +212,9 @@ enum Page {
|
||||
WaveGo,
|
||||
Village,
|
||||
Breaches(usize),
|
||||
Post,
|
||||
Unit(u32, post::From),
|
||||
UnitChecks(u32, post::From),
|
||||
/// Fire, repair, effects, damage.
|
||||
More,
|
||||
/// The last raid's events and its replays.
|
||||
@@ -288,12 +293,38 @@ const VILLAGE_STOP: u32 = 67;
|
||||
const BREACHES_LIST: u32 = 68;
|
||||
const BREACHES_PREV: u32 = 69;
|
||||
const BREACHES_NEXT: u32 = 70;
|
||||
const POST_ROWS: u32 = 71;
|
||||
const POST_FILTER: u32 = 72;
|
||||
const POST_VIEW: u32 = 73;
|
||||
const POST_PREV: u32 = 74;
|
||||
const POST_NEXT: u32 = 75;
|
||||
const POST_CLEAR: u32 = 76;
|
||||
const POST_ACTIONS: u32 = 77;
|
||||
const BTN_BACK: u32 = 199;
|
||||
|
||||
fn say(text: &str) {
|
||||
chat::show(text);
|
||||
}
|
||||
|
||||
/// Wrap diagnostics to the engine widget column (200 GUI pixels, minus list padding).
|
||||
fn ui_lines(text: &str) -> Vec<String> {
|
||||
let mut lines = Vec::new();
|
||||
let mut line = String::new();
|
||||
for word in text.split_whitespace() {
|
||||
let next = if line.is_empty() { word.to_owned() } else { format!("{line} {word}") };
|
||||
if !line.is_empty() && render::text_width(&next) > 184.0 {
|
||||
lines.push(std::mem::take(&mut line));
|
||||
line.push_str(word);
|
||||
} else {
|
||||
line = next;
|
||||
}
|
||||
}
|
||||
if !line.is_empty() {
|
||||
lines.push(line);
|
||||
}
|
||||
lines
|
||||
}
|
||||
|
||||
/// What the effects draw this tick (`Mod::shown`).
|
||||
struct Shown {
|
||||
blasts: Vec<sim::Blast>,
|
||||
@@ -923,8 +954,9 @@ impl AirDef {
|
||||
self.overlay_held
|
||||
&& self.presentation.is_live()
|
||||
&& !self.grid
|
||||
&& self.monitor.is_none_or(|i| i >= self.sim.sams.len())
|
||||
&& self.monitor_index().is_none()
|
||||
&& !self.map.open
|
||||
&& self.menu.is_none()
|
||||
}
|
||||
|
||||
fn draw_overlay(&mut self) {
|
||||
@@ -1274,9 +1306,13 @@ impl AirDef {
|
||||
self.sim.shader = shader;
|
||||
self.ground = Ground::default();
|
||||
self.monitor = None;
|
||||
if self.menu.take().is_some() {
|
||||
ui::close_screen();
|
||||
}
|
||||
self.map_close();
|
||||
self.grid = false;
|
||||
self.grid_ids.clear();
|
||||
self.post = post::Post::default();
|
||||
// The overlay key lets go with the world: its camera projects nothing here anyway.
|
||||
self.overlay_held = false;
|
||||
self.overlay_shown = false;
|
||||
@@ -1595,15 +1631,15 @@ impl AirDef {
|
||||
/// The systems the grid shows: the busiest (firing, locking, hit, burning) first, the
|
||||
/// monitored one always; those shown keep a head start, so the grid doesn't flicker.
|
||||
fn pick_grid(&mut self) {
|
||||
let preferred = self.post.pinned.or(self.monitor);
|
||||
let shown = &self.grid_ids;
|
||||
// Units that shoot, the radars and the passive optics; depots, trucks and lights have nothing to show.
|
||||
let mut scored: Vec<(f64, u32)> = self
|
||||
.sim
|
||||
.sams
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(_, s)| s.kind.armed() || s.kind == SamKind::Radar || s.kind == SamKind::Optical)
|
||||
.map(|(i, s)| {
|
||||
.filter(|s| Some(s.id) == preferred || s.kind.armed() || s.kind == SamKind::Radar || s.kind == SamKind::Optical)
|
||||
.map(|s| {
|
||||
let busy = if self.sim.showing_kill(s) { 98.0 } else { match s.state {
|
||||
sim::SamState::Launch | sim::SamState::Fire => 100.0,
|
||||
sim::SamState::Lock => 85.0,
|
||||
@@ -1623,7 +1659,7 @@ impl AirDef {
|
||||
};
|
||||
let hurt = if s.alive() && s.health < 0.7 { 15.0 } else { 0.0 };
|
||||
let keep = if shown.contains(&s.id) { 12.0 } else { 0.0 };
|
||||
let pinned = if self.monitor == Some(i) { 1000.0 } else { 0.0 };
|
||||
let pinned = if Some(s.id) == preferred { 1000.0 } else { 0.0 };
|
||||
(busy + near + hurt + keep + pinned + s.seen.len().min(5) as f64, s.id)
|
||||
})
|
||||
.collect();
|
||||
@@ -1634,12 +1670,32 @@ impl AirDef {
|
||||
self.grid_ids = ids;
|
||||
}
|
||||
|
||||
fn monitor_index(&self) -> Option<usize> {
|
||||
self.monitor.and_then(|id| self.sim.sams.iter().position(|s| s.id == id))
|
||||
}
|
||||
|
||||
fn cycle_monitor(&mut self) {
|
||||
self.monitor = match self.monitor {
|
||||
None if !self.sim.sams.is_empty() => Some(0),
|
||||
Some(i) if i + 1 < self.sim.sams.len() => Some(i + 1),
|
||||
_ => None,
|
||||
};
|
||||
self.monitor = self.sim.sams.get(self.monitor_index().map_or(0, |i| i + 1)).map(|s| s.id);
|
||||
}
|
||||
|
||||
fn close_menu(&mut self) {
|
||||
self.menu = None;
|
||||
ui::close_screen();
|
||||
}
|
||||
|
||||
fn open_post(&mut self) {
|
||||
if self.presentation.is_live() {
|
||||
self.grid = false;
|
||||
self.open_menu(Page::Post);
|
||||
}
|
||||
}
|
||||
|
||||
fn open_monitor_card(&mut self) {
|
||||
if self.presentation.is_live()
|
||||
&& let Some(id) = self.monitor.filter(|_| self.monitor_index().is_some())
|
||||
{
|
||||
self.open_menu(Page::Unit(id, post::From::Monitor));
|
||||
}
|
||||
}
|
||||
|
||||
/// Places a configured system at `at` facing `heading` and settles it.
|
||||
@@ -1673,6 +1729,7 @@ impl AirDef {
|
||||
}
|
||||
|
||||
fn open_menu(&mut self, page: Page) {
|
||||
self.post.transition = None;
|
||||
self.menu = Some(page);
|
||||
let onoff = |b: bool| if b { "вкл" } else { "выкл" };
|
||||
let mut widgets = Vec::new();
|
||||
@@ -1689,8 +1746,7 @@ impl AirDef {
|
||||
})
|
||||
.collect();
|
||||
widgets.push(Widget::List(ListWidget { id: MENU_KINDS, rows, selected: None }));
|
||||
let _ = &self.monitor;
|
||||
widgets.push(Widget::Button(ButtonWidget { id: BTN_GRID, label: "Командный пункт: все комплексы (J)".into() }));
|
||||
widgets.push(Widget::Button(ButtonWidget { id: BTN_GRID, label: "Командный пункт (J)".into() }));
|
||||
let custom = self.sim.sams.iter().filter(|s| !s.doctrine.is_default()).count();
|
||||
widgets.push(Widget::Button(ButtonWidget { id: BTN_DOCTRINE, label: format!("Доктрины: охрана, сектор, резерв (особых: {custom})…") }));
|
||||
widgets.push(Widget::Button(ButtonWidget { id: BTN_WAVE, label: "Налёт: состав и запуск…".into() }));
|
||||
@@ -1699,6 +1755,90 @@ impl AirDef {
|
||||
widgets.push(Widget::Button(ButtonWidget { id: BTN_RECON, label: "Разведка противника (разбор)…".into() }));
|
||||
widgets.push(Widget::Button(ButtonWidget { id: BTN_MORE, label: "Огонь, ремонт, эффекты…".into() }));
|
||||
}
|
||||
Page::Post => {
|
||||
let indices = self.post.matching(&self.sim.sams);
|
||||
let pages = indices.len().div_ceil(post::PAGE_SIZE).max(1);
|
||||
self.post.page = self.post.page.min(pages - 1);
|
||||
title = format!("Командный пункт · {} из {}", indices.len(), self.sim.sams.len());
|
||||
let start = self.post.page * post::PAGE_SIZE;
|
||||
let indices = &indices[start..(start + post::PAGE_SIZE).min(indices.len())];
|
||||
self.post.shown = indices.iter().map(|&i| self.sim.sams[i].id).collect();
|
||||
widgets.push(Widget::Button(ButtonWidget { id: POST_FILTER, label: format!("Фильтр · {}", self.post.filter.label()) }));
|
||||
let rows = indices.iter().map(|&i| {
|
||||
let sam = &self.sim.sams[i];
|
||||
post::row(sam, i, self.post.pinned == Some(sam.id))
|
||||
}).collect();
|
||||
if self.post.shown.is_empty() {
|
||||
widgets.push(Widget::Text(TextWidget { id: 0, text: "Подходящей техники нет".into(), color: 0 }));
|
||||
} else {
|
||||
widgets.push(Widget::List(ListWidget { id: POST_ROWS, rows, selected: None }));
|
||||
}
|
||||
if !self.post.query.is_empty() {
|
||||
widgets.push(Widget::Button(ButtonWidget { id: POST_CLEAR, label: "Сбросить поиск".into() }));
|
||||
}
|
||||
if pages > 1 {
|
||||
if self.post.page > 0 {
|
||||
widgets.push(Widget::Button(ButtonWidget { id: POST_PREV, label: format!("← Страница {}", self.post.page) }));
|
||||
}
|
||||
if self.post.page + 1 < pages {
|
||||
widgets.push(Widget::Button(ButtonWidget { id: POST_NEXT, label: format!("Страница {} →", self.post.page + 2) }));
|
||||
}
|
||||
}
|
||||
widgets.push(Widget::Button(ButtonWidget { id: POST_VIEW, label: "Сетка камер".into() }));
|
||||
}
|
||||
Page::Unit(id, from) | Page::UnitChecks(id, from) => {
|
||||
let Some(i) = self.sim.sams.iter().position(|s| s.id == id) else {
|
||||
return self.open_menu(Page::Post);
|
||||
};
|
||||
let sam = &self.sim.sams[i];
|
||||
title = format!("№{} {} · {}", i + 1, sam.kind.name(), post::state(sam));
|
||||
let reason = self.sim.battle_reason(i);
|
||||
if matches!(page, Page::UnitChecks(_, _)) {
|
||||
let mut details = vec![battery_view::sam_status(sam, self.sim.tick)];
|
||||
if let Some(reason) = reason {
|
||||
if let (Some(target), Some(mark)) = (reason.target, reason.mark) {
|
||||
details.push(format!("Трек №{target} · {}", why_view::mark_text(&mark)));
|
||||
}
|
||||
if let Some((used, total)) = reason.channels {
|
||||
details.push(format!("Каналы сопровождения: {used}/{total}"));
|
||||
}
|
||||
}
|
||||
let rows = details.iter().flat_map(|detail| ui_lines(detail)).collect();
|
||||
widgets.push(Widget::List(ListWidget { id: POST_ACTIONS, rows, selected: None }));
|
||||
} else {
|
||||
use post::Action;
|
||||
let headline = reason.filter(|_| sam.kind.armed()).map_or_else(
|
||||
|| post::state(sam).to_owned(),
|
||||
why_view::unit_headline,
|
||||
);
|
||||
for text in ui_lines(&format!("Сейчас · {headline}")) {
|
||||
widgets.push(Widget::Text(TextWidget { id: 0, text, color: 0 }));
|
||||
}
|
||||
let mut actions = vec![
|
||||
(Action::Checks, "Статус и отметка"),
|
||||
(Action::Map, "Показать на карте"),
|
||||
(Action::Camera, "Открыть камеру"),
|
||||
];
|
||||
if let Some(source) = reason.and_then(|r| r.mark)
|
||||
.filter(|mark| !mark.own)
|
||||
.and_then(|mark| mark.source)
|
||||
.and_then(|i| self.sim.sams.get(i))
|
||||
{
|
||||
actions.push((Action::Source(source.id), "Источник отметки"));
|
||||
}
|
||||
actions.push((Action::History, "Цепочки в последнем повторе"));
|
||||
actions.push((Action::Pin, if self.post.pinned == Some(id) { "Открепить" } else { "Закрепить в списке и сетке" }));
|
||||
self.post.actions = actions.iter().map(|(action, _)| *action).collect();
|
||||
widgets.push(Widget::List(ListWidget { id: POST_ACTIONS, rows: actions.into_iter().map(|(_, label)| label.into()).collect(), selected: None }));
|
||||
}
|
||||
let label = match (page, from) {
|
||||
(Page::UnitChecks(_, _), _) => "К карточке",
|
||||
(_, post::From::Post) => "К списку",
|
||||
(_, post::From::Map(_)) => "К карте",
|
||||
(_, post::From::Monitor) => "К монитору",
|
||||
};
|
||||
widgets.push(Widget::Button(ButtonWidget { id: BTN_BACK, label: label.into() }));
|
||||
}
|
||||
Page::Village => {
|
||||
title = "Оборона деревни".into();
|
||||
let status = self.village_status();
|
||||
@@ -2020,6 +2160,7 @@ impl Mod for AirDef {
|
||||
monitor_shown: false,
|
||||
grid: false,
|
||||
grid_ids: Vec::new(),
|
||||
post: post::Post::default(),
|
||||
wave: wave::WaveConfig::default(),
|
||||
village: None,
|
||||
presentation: presentation::Session::default(),
|
||||
@@ -2055,6 +2196,7 @@ impl Mod for AirDef {
|
||||
let _ = input::register_key("menu", "Меню AirDef", "key.keyboard.n");
|
||||
let _ = input::register_key("monitor", "Монитор ПВО: следующий комплекс", "key.keyboard.k");
|
||||
let _ = input::register_key("grid", "Командный пункт: все комплексы", "key.keyboard.j");
|
||||
let _ = input::register_key("inspect", "Карточка комплекса на мониторе", "key.keyboard.i");
|
||||
let _ = input::register_key("replay", "Повтор налёта: карта / выход", "key.keyboard.r");
|
||||
let _ = input::register_key("ew", "РЭБ: включить / выключить", "key.keyboard.u");
|
||||
// The replay's own keys (they do nothing outside a replay).
|
||||
@@ -2114,7 +2256,8 @@ impl Mod for AirDef {
|
||||
}
|
||||
}
|
||||
Event::KeyDown(k) if k == "monitor" => self.cycle_monitor(),
|
||||
Event::KeyDown(k) if k == "grid" => self.grid = !self.grid,
|
||||
Event::KeyDown(k) if k == "grid" => self.open_post(),
|
||||
Event::KeyDown(k) if k == "inspect" => self.open_monitor_card(),
|
||||
Event::KeyDown(k) if k == "ew" => self.toggle_ew(),
|
||||
Event::KeyDown(k) if k == "replay" => {
|
||||
if self.presentation.playback().is_some() {
|
||||
@@ -2264,6 +2407,13 @@ impl Mod for AirDef {
|
||||
render::set_time_override(ctx.day_time);
|
||||
self.show_world_at(r.rec, r.time(), r.filming());
|
||||
self.monitor_shown = true;
|
||||
} else if matches!(self.menu, Some(Page::Post | Page::Unit(..) | Page::UnitChecks(..))) {
|
||||
if self.monitor_shown || self.overlay_shown {
|
||||
render::set_hud(&[]);
|
||||
render::set_views(&[]);
|
||||
self.monitor_shown = false;
|
||||
self.overlay_shown = false;
|
||||
}
|
||||
} else if self.grid {
|
||||
let stale = self.grid_ids.iter().any(|id| !self.sim.sams.iter().any(|s| s.id == *id));
|
||||
if self.sim.tick % 40 == 0 || stale || self.grid_ids.len() < self.sim.sams.len().min(8) {
|
||||
@@ -2276,8 +2426,8 @@ impl Mod for AirDef {
|
||||
render::set_views(&views);
|
||||
self.monitor_shown = true;
|
||||
} else {
|
||||
match self.monitor {
|
||||
Some(i) if i < self.sim.sams.len() => {
|
||||
match self.monitor_index() {
|
||||
Some(i) => {
|
||||
render::set_hud(&monitor::draw(&self.sim, i));
|
||||
render::set_views(&[monitor::camera(&self.sim, &self.sim.sams[i])]);
|
||||
self.monitor_shown = true;
|
||||
@@ -2315,6 +2465,67 @@ impl Mod for AirDef {
|
||||
fn ui_select(&mut self, id: u32, row: u32) {
|
||||
let page = self.menu.unwrap_or(Page::Main);
|
||||
match (page, id) {
|
||||
(Page::Post, POST_ROWS) => {
|
||||
if let Some(&id) = self.post.shown.get(row as usize) {
|
||||
if self.sim.sams.iter().any(|sam| sam.id == id) {
|
||||
self.open_menu(Page::Unit(id, post::From::Post));
|
||||
} else {
|
||||
self.open_menu(Page::Post);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
(Page::Post, POST_FILTER) => {
|
||||
self.post.filter = self.post.filter.next();
|
||||
self.post.page = 0;
|
||||
}
|
||||
(Page::Post, POST_CLEAR) => {
|
||||
self.post.query.clear();
|
||||
self.post.page = 0;
|
||||
}
|
||||
(Page::Post, POST_PREV) => self.post.page = self.post.page.saturating_sub(1),
|
||||
(Page::Post, POST_NEXT) => self.post.page += 1,
|
||||
(Page::Post, POST_VIEW) => {
|
||||
self.pick_grid();
|
||||
self.grid = true;
|
||||
self.close_menu();
|
||||
return;
|
||||
}
|
||||
(Page::Unit(unit, from), POST_ACTIONS) => {
|
||||
match self.post.actions.get(row as usize).copied() {
|
||||
Some(post::Action::Checks) => self.open_menu(Page::UnitChecks(unit, from)),
|
||||
Some(post::Action::Map) => self.open_unit_map(unit),
|
||||
Some(post::Action::Camera) if self.sim.sams.iter().any(|s| s.id == unit) => {
|
||||
self.monitor = Some(unit);
|
||||
self.grid = false;
|
||||
self.close_menu();
|
||||
}
|
||||
Some(post::Action::Source(source)) => self.open_menu(Page::Unit(source, from)),
|
||||
Some(post::Action::History) => {
|
||||
self.chain_filter = Some(unit);
|
||||
self.open_menu(Page::Chains);
|
||||
}
|
||||
Some(post::Action::Pin) => {
|
||||
self.post.pinned = (self.post.pinned != Some(unit)).then_some(unit);
|
||||
self.post.page = 0;
|
||||
self.open_menu(page);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
return;
|
||||
}
|
||||
(Page::UnitChecks(unit, from), BTN_BACK) => {
|
||||
self.open_menu(Page::Unit(unit, from));
|
||||
return;
|
||||
}
|
||||
(Page::Unit(_, from), BTN_BACK) => {
|
||||
match from {
|
||||
post::From::Post => self.open_post(),
|
||||
post::From::Map(id) => self.open_unit_map(id),
|
||||
post::From::Monitor => self.close_menu(),
|
||||
}
|
||||
return;
|
||||
}
|
||||
(Page::Main, MENU_KINDS) => {
|
||||
if let Some(k) = SamKind::ARMED.get(row as usize) {
|
||||
self.open_menu(Page::Roles(*k));
|
||||
@@ -2540,9 +2751,7 @@ impl Mod for AirDef {
|
||||
return;
|
||||
}
|
||||
(Page::Main, BTN_GRID) => {
|
||||
self.grid = true;
|
||||
self.menu = None;
|
||||
ui::close_screen();
|
||||
self.open_post();
|
||||
return;
|
||||
}
|
||||
(Page::More, BTN_SHADER) => {
|
||||
@@ -2607,6 +2816,14 @@ impl Mod for AirDef {
|
||||
/// export still active there is ended, so its capture cannot go on recording the title.
|
||||
fn frame(&mut self, _seconds: f32) {
|
||||
if self.presentation.is_live() {
|
||||
match self.post.transition.take() {
|
||||
Some((transition, false)) => self.post.transition = Some((transition, true)),
|
||||
Some((post::Transition::Map(id), true)) => self.show_unit_on_map(id),
|
||||
Some((post::Transition::Card(id), true)) if player().is_some() => {
|
||||
self.open_menu(Page::Unit(id, post::From::Map(id)));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
// The overlay tracks the drawn camera frame by frame (`render.project` is at most a
|
||||
// frame behind); the other screens own the HUD at the tick's pace, as before.
|
||||
if self.overlay_active() {
|
||||
@@ -2642,6 +2859,17 @@ impl Mod for AirDef {
|
||||
self.grid = !self.grid;
|
||||
None
|
||||
}
|
||||
["post"] | ["post", _] => {
|
||||
switch_allowed(self.presentation.is_exporting())?;
|
||||
if !self.presentation.is_live() {
|
||||
return Err("Командный пункт: сначала закройте повтор".into());
|
||||
}
|
||||
self.post.query = w.get(1).map_or_else(String::new, |search| search.to_lowercase());
|
||||
self.post.filter = post::Filter::All;
|
||||
self.post.page = 0;
|
||||
self.open_post();
|
||||
None
|
||||
}
|
||||
["give"] => {
|
||||
self.give();
|
||||
None
|
||||
@@ -2719,7 +2947,7 @@ impl Mod for AirDef {
|
||||
// The system n of the summary, else the monitored one.
|
||||
let i = match rest.first() {
|
||||
Some(n) => n.parse::<usize>().ok().and_then(|n| n.checked_sub(1)).ok_or("/airdef why <номер>")?,
|
||||
None => self.monitor.ok_or("/airdef why <номер> (или откройте монитор K)")?,
|
||||
None => self.monitor_index().ok_or("/airdef why <номер> (или откройте монитор K)")?,
|
||||
};
|
||||
if i >= self.sim.sams.len() {
|
||||
return Err("Нет такой техники".into());
|
||||
@@ -2732,8 +2960,9 @@ impl Mod for AirDef {
|
||||
return Err("Отметка своя: источник — сама батарея".into());
|
||||
}
|
||||
let Some(source) = mark.source else { return Err("Источник отметки неизвестен".into()) };
|
||||
self.monitor = Some(source);
|
||||
let name = self.sim.sams.get(source).map_or("РЛС", |s| s.kind.name());
|
||||
let station = &self.sim.sams[source];
|
||||
self.monitor = Some(station.id);
|
||||
let name = station.kind.name();
|
||||
return Ok(Some(format!(
|
||||
"Переход к источнику отметки: №{} {}, возраст {:.1} с",
|
||||
source + 1,
|
||||
@@ -3059,6 +3288,7 @@ mod tests {
|
||||
monitor_shown: false,
|
||||
grid: false,
|
||||
grid_ids: Vec::new(),
|
||||
post: post::Post::default(),
|
||||
wave: wave::WaveConfig::default(),
|
||||
village: None,
|
||||
presentation: presentation::Session::default(),
|
||||
|
||||
@@ -116,6 +116,7 @@ enum Act {
|
||||
ResetDoc,
|
||||
Strike(u32),
|
||||
Centre,
|
||||
Inspect,
|
||||
Follow,
|
||||
Rotate,
|
||||
Delete,
|
||||
@@ -916,6 +917,26 @@ impl AirDef {
|
||||
self.map.drag = None;
|
||||
}
|
||||
|
||||
pub(crate) fn open_unit_map(&mut self, id: u32) {
|
||||
self.close_menu();
|
||||
self.post.transition = Some((crate::post::Transition::Map(id), false));
|
||||
}
|
||||
|
||||
pub(crate) fn show_unit_on_map(&mut self, id: u32) {
|
||||
let Some(sam) = self.sim.sams.iter().find(|sam| sam.id == id) else {
|
||||
say("Комплекс уже убран");
|
||||
return;
|
||||
};
|
||||
let pos = sam.pos;
|
||||
if !self.map.open {
|
||||
self.map_toggle();
|
||||
}
|
||||
self.map.sel = Some(Sel::Sam(id));
|
||||
self.map.centre = (pos.x, pos.z);
|
||||
self.map.follow = false;
|
||||
self.map.dirty = true;
|
||||
}
|
||||
|
||||
/// Once a frame while the map is open.
|
||||
pub(crate) fn map_frame(&mut self) {
|
||||
if !self.map.open {
|
||||
@@ -1321,6 +1342,14 @@ impl AirDef {
|
||||
ui.centre = (p.x, p.z);
|
||||
}
|
||||
}
|
||||
Act::Inspect => {
|
||||
if matches!(ui.mode, Mode::View)
|
||||
&& let Some(Sel::Sam(id)) = ui.sel
|
||||
{
|
||||
self.post.transition = Some((crate::post::Transition::Card(id), false));
|
||||
ui.close = true;
|
||||
}
|
||||
}
|
||||
Act::Follow => {
|
||||
if matches!(ui.sel, Some(Sel::Track(_))) {
|
||||
ui.follow = !ui.follow;
|
||||
@@ -2748,6 +2777,9 @@ impl AirDef {
|
||||
let Some((n, sam)) = self.sim.sams.iter().enumerate().find(|(_, s)| s.id == id) else { return };
|
||||
let k = sam.kind;
|
||||
lines.push((format!("{} №{}", k.name(), n + 1), CYAN));
|
||||
if matches!(ui.mode, Mode::View) {
|
||||
btns.push(("Карточка…".into(), Act::Inspect, false));
|
||||
}
|
||||
if k == SamKind::Radar {
|
||||
let profile = sam.radar_profile();
|
||||
lines.push((format!("Профиль РЛС: {} [{}]", profile.name, profile.id), WHITE));
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! The air-defence monitor: a system's state, its radar's picture round it
|
||||
//! and its camera (a real view of the world from the system, the game
|
||||
//! renders it) locked on its target. K shows one system at a time, J all of
|
||||
//! them in a grid.
|
||||
//! renders it) locked on its target. K shows one system at a time. The
|
||||
//! command post can also open a grid of up to eight cameras.
|
||||
use crate::panel::distance;
|
||||
use crate::sim::{ClassEst, OpticalState, Sam, SamKind, SamState, Sim, heading_of, roles_text};
|
||||
use glam::DVec3;
|
||||
|
||||
@@ -0,0 +1,192 @@
|
||||
//! The command post lists every deployed unit without requesting camera views.
|
||||
use crate::sim::{Part, PartState, Sam, SamKind, SamState};
|
||||
|
||||
/// Keep enough room under the engine's 512-row limit for large layouts.
|
||||
pub const PAGE_SIZE: usize = 200;
|
||||
|
||||
#[derive(Clone, Copy, Default, PartialEq, Eq)]
|
||||
pub enum Filter {
|
||||
#[default]
|
||||
All,
|
||||
Weapons,
|
||||
Sensors,
|
||||
Support,
|
||||
InCombat,
|
||||
NoAmmo,
|
||||
NoLink,
|
||||
Damaged,
|
||||
}
|
||||
|
||||
impl Filter {
|
||||
const ALL: [Self; 8] = [
|
||||
Self::All, Self::Weapons, Self::Sensors, Self::Support, Self::InCombat,
|
||||
Self::NoAmmo, Self::NoLink, Self::Damaged,
|
||||
];
|
||||
|
||||
pub fn next(self) -> Self {
|
||||
Self::ALL[(self as usize + 1) % Self::ALL.len()]
|
||||
}
|
||||
|
||||
pub fn label(self) -> &'static str {
|
||||
match self {
|
||||
Self::All => "Все",
|
||||
Self::Weapons => "Огневые",
|
||||
Self::Sensors => "Наблюдение",
|
||||
Self::Support => "Поддержка",
|
||||
Self::InCombat => "В работе",
|
||||
Self::NoAmmo => "Без боезапаса",
|
||||
Self::NoLink => "Отказ связи",
|
||||
Self::Damaged => "Повреждённые",
|
||||
}
|
||||
}
|
||||
|
||||
fn matches(self, sam: &Sam) -> bool {
|
||||
let sensor = matches!(sam.kind, SamKind::Radar | SamKind::Optical);
|
||||
match self {
|
||||
Self::All => true,
|
||||
Self::Weapons => sam.kind.armed(),
|
||||
Self::Sensors => sensor,
|
||||
Self::Support => !sam.kind.armed() && !sensor,
|
||||
Self::InCombat => sam.alive() && (
|
||||
matches!(sam.state, SamState::Track | SamState::Slew | SamState::Lock | SamState::Launch | SamState::Fire)
|
||||
|| sam.ew_on
|
||||
|| (sensor && !sam.own.is_empty())
|
||||
|| (sam.kind == SamKind::Optical && sam.optical.state() == crate::sim::OpticalState::Observing)
|
||||
),
|
||||
Self::NoAmmo => sam.alive() && sam.kind.armed() && sam.missiles == 0 && sam.bursts == 0,
|
||||
Self::NoLink => sam.alive() && Part::Comms.on(sam.kind) && sam.part_state(Part::Comms) == PartState::Failed,
|
||||
Self::Damaged => sam.health < 1.0 || !sam.comps.whole(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
pub enum From {
|
||||
Post,
|
||||
Map(u32),
|
||||
Monitor,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum Action {
|
||||
Checks,
|
||||
Map,
|
||||
Camera,
|
||||
Source(u32),
|
||||
Pin,
|
||||
History,
|
||||
}
|
||||
|
||||
pub enum Transition {
|
||||
Map(u32),
|
||||
Card(u32),
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Post {
|
||||
pub filter: Filter,
|
||||
pub query: String,
|
||||
pub page: usize,
|
||||
pub pinned: Option<u32>,
|
||||
/// IDs and actions exactly as shown in the screen, even if the sim advances before a click.
|
||||
pub shown: Vec<u32>,
|
||||
pub actions: Vec<Action>,
|
||||
/// Let the client finish closing one screen before opening a different kind.
|
||||
pub transition: Option<(Transition, bool)>,
|
||||
}
|
||||
|
||||
impl Post {
|
||||
pub fn matching(&self, sams: &[Sam]) -> Vec<usize> {
|
||||
let number = self.query.trim_start_matches('№').parse::<usize>().ok();
|
||||
let mut rows: Vec<_> = sams.iter().enumerate()
|
||||
.filter(|(i, sam)| self.filter.matches(sam) && (self.query.is_empty()
|
||||
|| number == Some(i + 1)
|
||||
|| sam.kind.key().contains(&self.query)
|
||||
|| sam.kind.name().to_lowercase().contains(&self.query)))
|
||||
.map(|(i, _)| i)
|
||||
.collect();
|
||||
if let Some(i) = rows.iter().position(|&i| self.pinned == Some(sams[i].id)) {
|
||||
let pinned = rows.remove(i);
|
||||
rows.insert(0, pinned);
|
||||
}
|
||||
rows
|
||||
}
|
||||
}
|
||||
|
||||
pub fn state(sam: &Sam) -> &'static str {
|
||||
if !sam.alive() {
|
||||
return "Уничтожен";
|
||||
}
|
||||
if sam.moving() {
|
||||
return sam.state.name();
|
||||
}
|
||||
match sam.kind {
|
||||
SamKind::Optical => sam.optical.state().name(),
|
||||
SamKind::Radar if !sam.radar_on => "Излучение выкл.",
|
||||
SamKind::Radar if !sam.radar_up() => "РЛС недоступна",
|
||||
SamKind::Radar if !sam.own.is_empty() => "Есть отметки",
|
||||
SamKind::Ew if sam.ew_on => "Активна",
|
||||
SamKind::Ew | SamKind::Depot | SamKind::Tzm | SamKind::Light => "На позиции",
|
||||
_ => sam.state.name(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn row(sam: &Sam, index: usize, pinned: bool) -> String {
|
||||
let name = sam.kind.name();
|
||||
let status = if Filter::NoLink.matches(sam) {
|
||||
"Нет связи"
|
||||
} else if Filter::NoAmmo.matches(sam) && sam.reloading == 0 {
|
||||
"Нет БК"
|
||||
} else {
|
||||
state(sam)
|
||||
};
|
||||
let pin = if pinned { "★ " } else { "" };
|
||||
let health = if sam.alive() && Filter::Damaged.matches(sam) {
|
||||
format!(" · {:.0}%", sam.health * 100.0)
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
format!("{pin}№{} {name} · {status}{health}", index + 1)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use glam::DVec3;
|
||||
|
||||
#[test]
|
||||
fn the_post_includes_support_and_searches_names_keys_and_shown_numbers() {
|
||||
let sams = [
|
||||
Sam::new(77, SamKind::Pantsir, DVec3::ZERO, 0.0),
|
||||
Sam::new(90, SamKind::Depot, DVec3::ZERO, 0.0),
|
||||
Sam::new(23, SamKind::Radar, DVec3::ZERO, 0.0),
|
||||
];
|
||||
let mut post = Post { pinned: Some(23), ..Post::default() };
|
||||
assert_eq!(post.matching(&sams), [2, 0, 1]);
|
||||
for (query, expected) in [("панц", 0), ("depot", 1), ("№3", 2)] {
|
||||
post.query = query.to_string();
|
||||
assert_eq!(post.matching(&sams), [expected]);
|
||||
}
|
||||
post.query.clear();
|
||||
post.filter = Filter::Support;
|
||||
assert_eq!(post.matching(&sams), [1]);
|
||||
assert_eq!(post.pinned, Some(23));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn availability_filters_distinguish_empty_worn_and_destroyed_units() {
|
||||
let mut ready = Sam::new(15, SamKind::Pantsir, DVec3::ZERO, 0.0);
|
||||
ready.missiles = 0;
|
||||
ready.bursts = 0;
|
||||
ready.comps.0[Part::Comms as usize] = 0.0;
|
||||
assert!(Filter::NoAmmo.matches(&ready));
|
||||
assert!(Filter::NoLink.matches(&ready));
|
||||
assert!(Filter::Damaged.matches(&ready));
|
||||
assert!(row(&ready, 0, true).starts_with("★ №1"));
|
||||
ready.health = 0.0;
|
||||
assert!(!Filter::NoAmmo.matches(&ready));
|
||||
assert!(!Filter::NoLink.matches(&ready));
|
||||
assert_eq!(state(&ready), "Уничтожен");
|
||||
assert!(Filter::Damaged.matches(&ready));
|
||||
}
|
||||
}
|
||||
@@ -79,6 +79,7 @@ impl AirDef {
|
||||
self.sim.hits = 0;
|
||||
self.sim.launched = 0;
|
||||
self.monitor = None;
|
||||
self.post = crate::post::Post::default();
|
||||
self.grid_ids.clear();
|
||||
self.moving = None;
|
||||
self.pending.clear();
|
||||
|
||||
@@ -27,7 +27,7 @@ pub fn worst(comps: &Comps, kind: SamKind) -> String {
|
||||
|
||||
/// The mark's age and where it came from, in the battery's own picture: a relayed plot names
|
||||
/// its station, never the target's true place or kind.
|
||||
fn mark_text(mark: &BattleMark) -> String {
|
||||
pub fn mark_text(mark: &BattleMark) -> String {
|
||||
let age = if mark.age == 0 { "сейчас".to_string() } else { format!("{:.1} с назад", mark.age as f64 / 20.0) };
|
||||
let source = if mark.own {
|
||||
"своя РЛС".to_string()
|
||||
@@ -96,6 +96,15 @@ pub fn battle_text(reason: &BattleReason) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
/// A card can be opened in normal play, where an unobserved contact is absent from the UI.
|
||||
pub fn unit_headline(mut reason: BattleReason) -> String {
|
||||
if reason.mark.is_none() && (reason.target.is_some() || reason.block == Some(BattleBlock::NoTarget)) {
|
||||
return "нет отметки у комплекса".into();
|
||||
}
|
||||
reason.mark = None;
|
||||
battle_text(&reason)
|
||||
}
|
||||
|
||||
pub fn reason(reason: &CheckReason) -> String {
|
||||
match reason {
|
||||
CheckReason::Text(text) => text.clone(),
|
||||
|
||||
Reference in New Issue
Block a user