aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-assets/src/strategic_roster.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-02 10:40:01 +0300
committerValentin Popov <valentin@popov.link>2026-12-02 10:40:01 +0300
commit20161fbf4fab9080a2d0d6ceedbf1344435cfda0 (patch)
tree174be0827089abc4407af7289142d66d9f995ae7 /crates/fparkan-assets/src/strategic_roster.rs
parent5f0b8c076b40f8eca67e2745367c731f803914f4 (diff)
downloadfparkan-20161fbf4fab9080a2d0d6ceedbf1344435cfda0.tar.xz
fparkan-20161fbf4fab9080a2d0d6ceedbf1344435cfda0.zip
feat(ui): show live Control stats in the warbot card
Diffstat (limited to 'crates/fparkan-assets/src/strategic_roster.rs')
-rw-r--r--crates/fparkan-assets/src/strategic_roster.rs45
1 files changed, 43 insertions, 2 deletions
diff --git a/crates/fparkan-assets/src/strategic_roster.rs b/crates/fparkan-assets/src/strategic_roster.rs
index 3a28ac2a..0faeb7e4 100644
--- a/crates/fparkan-assets/src/strategic_roster.rs
+++ b/crates/fparkan-assets/src/strategic_roster.rs
@@ -4,6 +4,7 @@ use crate::{
game_font::{load_layout_font, BitmapFont},
mission_pager::copy_sprite,
ui_sprite::{atlas_region, load_ui_page, load_ui_sprites},
+ warbot_card::{self, CardLine},
RgbaImage,
};
use fparkan_vfs::Vfs;
@@ -47,6 +48,7 @@ pub struct Row<'a> {
pub size: u32,
pub chassis: u32,
pub selected: bool,
+ pub durability_percent: Option<i32>,
}
/// Resident art for the header, selected-unit frame, and rows.
@@ -150,14 +152,19 @@ impl RosterImages {
})
}
- /// Renders the visible rows and the identity of the selected unit.
- pub fn paint(&self, rows: &[Row<'_>]) -> Result<RgbaImage, String> {
+ /// Renders the visible rows and card of the selected unit.
+ pub fn paint(
+ &self,
+ rows: &[Row<'_>],
+ card: &[Option<CardLine<'_>>],
+ ) -> Result<RgbaImage, String> {
let mut panel = self.background.clone();
if let Some(row) = rows.iter().find(|row| row.selected) {
self.icons(&mut panel, row, [9, 27]);
let width = u32::from(self.font.line_metrics(row.label)?[0]).min(263);
let name = self.font.centered_line(row.label, width as u16, 16)?;
stamp(&mut panel, &name, [49, 25, 49 + width, 41], [255, 255, 0]);
+ warbot_card::paint(&self.font, &mut panel, card)?;
}
for (index, row) in rows.iter().take(19).enumerate() {
let y = ROW_TOP + index as u32 * ROW_PITCH;
@@ -179,6 +186,19 @@ impl RosterImages {
);
}
self.icons(&mut panel, row, [12, y + 2]);
+ if let Some((width, rgba)) = row.durability_percent.and_then(durability_fill) {
+ let fill = RgbaImage {
+ width: 1,
+ height: 1,
+ rgba8: rgba.to_vec(),
+ };
+ stamp(
+ &mut panel,
+ &fill,
+ [TEXT_LEFT + 2, y + 3, TEXT_LEFT + width, bottom - 3],
+ [255; 3],
+ );
+ }
let name = self
.font
.centered_line(row.label, TEXT_WIDTH as u16, ROW_HEIGHT as u16)?;
@@ -221,6 +241,17 @@ fn stamp(panel: &mut RgbaImage, sprite: &RgbaImage, bounds: [u32; 4], tint: [u8;
copy_sprite(panel, sprite, bounds, [false; 2], tint);
}
+fn durability_fill(percent: i32) -> Option<(u32, [u8; 4])> {
+ let width = (f64::from(percent.min(100)) * f64::from(TEXT_WIDTH) * f64::from(0.01_f32))
+ .round_ties_even() as u32;
+ let rgba = match percent {
+ ..=19 => [128, 0, 0, 128],
+ 20..=79 => [128, 128, 0, 128],
+ _ => [0, 128, 0, 128],
+ };
+ (width > 2).then_some((width, rgba))
+}
+
#[cfg(test)]
mod tests {
use super::*;
@@ -234,4 +265,14 @@ mod tests {
assert_eq!(hit_test([200.0, 158.0], 2), None);
assert_eq!(hit_test([200.0, 480.0], 20), None);
}
+
+ #[test]
+ fn original_durability_colours_follow_the_rounded_health_percentage() {
+ assert_eq!(durability_fill(0), None);
+ assert_eq!(durability_fill(19), Some((47, [128, 0, 0, 128])));
+ assert_eq!(durability_fill(20), Some((50, [128, 128, 0, 128])));
+ assert_eq!(durability_fill(79), Some((196, [128, 128, 0, 128])));
+ assert_eq!(durability_fill(80), Some((198, [0, 128, 0, 128])));
+ assert_eq!(durability_fill(100), Some((248, [0, 128, 0, 128])));
+ }
}