1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
use super::{
mission_overlay::{add_overlay_sprite, overlay_texture},
DirectoryVfs, EnvironmentGpuRange, StaticPreviewScene, VulkanSmokeRenderer,
};
use fparkan_assets::{
satellite_map_chrome::{Contact, MapChrome, FOOTER, HEADER},
RgbaImage,
};
use fparkan_platform_winit::text::StringResources;
use fparkan_runtime::strategic_map_readout::ContactReadout;
use std::path::Path;
pub(super) struct SatelliteMapChrome {
header: EnvironmentGpuRange,
footer: EnvironmentGpuRange,
art: MapChrome,
strings: StringResources,
current: Option<ContactReadout>,
}
impl SatelliteMapChrome {
pub(super) fn load(
root: &Path,
icons: RgbaImage,
preview: &mut StaticPreviewScene,
) -> Result<Self, String> {
let strings = StringResources::open(&root.join("iron3d.dll"))?;
let title = strings.get(0x13d2).ok_or("missing satellite map title")?;
let art = MapChrome::load(&DirectoryVfs::new(root), icons)?;
Ok(Self {
header: add_overlay_sprite(
preview,
art.header(&title)?,
HEADER.map(|n| n as f32),
[1.0; 3],
1.0,
)?,
footer: add_overlay_sprite(
preview,
art.footer(None)?,
FOOTER.map(|n| n as f32),
[1.0; 3],
1.0,
)?,
art,
strings,
current: None,
})
}
pub(super) fn ranges(&self) -> [usize; 2] {
[self.header.range_index, self.footer.range_index]
}
pub(super) fn draw(
&mut self,
renderer: &mut VulkanSmokeRenderer,
visible: bool,
contact: Option<ContactReadout>,
) -> Result<(), String> {
for range in self.ranges() {
renderer
.set_draw_range_index_count(range, if visible { 6 } else { 0 })
.map_err(|error| error.to_string())?;
}
if visible && (contact != self.current) {
let label = contact.map(|entry| self.label(entry)).transpose()?;
let entry = contact.zip(label.as_deref()).map(|(entry, label)| Contact {
label,
class: entry.class,
size: entry.size,
chassis: entry.chassis,
clan: entry.clan,
emblem_tint: entry.emblem_tint,
durability_percent: entry.durability_percent,
});
renderer
.update_material_texture(
self.footer.material_index,
0,
&overlay_texture(self.art.footer(entry)?),
)
.map_err(|error| error.to_string())?;
self.current = contact;
}
Ok(())
}
fn label(&self, contact: ContactReadout) -> Result<String, String> {
let mut name = self
.strings
.get(contact.name_label)
.ok_or_else(|| format!("missing map contact string {:#x}", contact.name_label))?;
if let Some((prefix, serial)) = contact.callsign {
let prefix: String = prefix.into_iter().collect();
name = format!("{prefix}-{serial} {name}");
}
if let Some(order) = contact.order_label {
let status = self
.strings
.get(order)
.ok_or_else(|| format!("missing map order string {order:#x}"))?;
name.push_str(&format!(" [{status}]"));
}
Ok(name)
}
}
|