aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-assets/src
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-02 09:44:41 +0300
committerValentin Popov <valentin@popov.link>2026-12-02 09:44:41 +0300
commit7dfbf534267011ad629c11c7140d0f9c0fe9cd3b (patch)
tree700cbf12d944764a7b7a5b299bf0a48522a75f97 /crates/fparkan-assets/src
parent149a8142d17e166fda8f15ce09eb3777b0e12ce7 (diff)
downloadfparkan-7dfbf534267011ad629c11c7140d0f9c0fe9cd3b.tar.xz
fparkan-7dfbf534267011ad629c11c7140d0f9c0fe9cd3b.zip
feat(ui): show the original strategic resource balances
Diffstat (limited to 'crates/fparkan-assets/src')
-rw-r--r--crates/fparkan-assets/src/lib.rs1
-rw-r--r--crates/fparkan-assets/src/strategic_balance.rs130
2 files changed, 131 insertions, 0 deletions
diff --git a/crates/fparkan-assets/src/lib.rs b/crates/fparkan-assets/src/lib.rs
index 5bdd7579..d64425ef 100644
--- a/crates/fparkan-assets/src/lib.rs
+++ b/crates/fparkan-assets/src/lib.rs
@@ -46,6 +46,7 @@ pub mod mission_loader;
pub mod mission_pager;
pub mod object_descriptions;
pub mod satellite_map;
+pub mod strategic_balance;
pub mod strategy_toolbar;
mod turret_elevation;
mod ui_configuration;
diff --git a/crates/fparkan-assets/src/strategic_balance.rs b/crates/fparkan-assets/src/strategic_balance.rs
new file mode 100644
index 00000000..eeebbce0
--- /dev/null
+++ b/crates/fparkan-assets/src/strategic_balance.rs
@@ -0,0 +1,130 @@
+//! Resource balance rows assembled from the original compound controls.
+
+use crate::{game_font::load_layout_font, mission_pager::copy_sprite, ui_sprite::load_ui_sprites};
+use fparkan_font::BitmapFont;
+use fparkan_texm::RgbaImage;
+use fparkan_vfs::Vfs;
+
+const ROW_HEIGHT: u16 = 19;
+const SEPARATION: u32 = 21;
+const LABEL_WIDTH: u16 = 205;
+const VALUE_WIDTH: u16 = 35;
+const GREEN: [u8; 3] = [128, 255, 128];
+const RED: [u8; 3] = [255, 50, 50];
+
+/// Panel size in the original 640×480 layout, including the overlapping edge pixel.
+pub const EXTENT: [u32; 2] = [267, SEPARATION + ROW_HEIGHT as u32];
+
+/// Atlas pieces and the original font for the two strategic balance rows.
+pub struct BalancePanel {
+ background: RgbaImage,
+ labels: [RgbaImage; 2],
+ font: BitmapFont,
+}
+
+impl BalancePanel {
+ /// Loads the reusable atlas art and centers the localized labels in their fields.
+ pub fn load(vfs: &dyn Vfs, labels: [&str; 2]) -> Result<Self, String> {
+ let [end, value, separator, emitter, body, cap] = load_ui_sprites(
+ vfs,
+ "ui/compaund.cfg",
+ [
+ "ccres_ending_text",
+ "ccres_body_text",
+ "ccres_separator_left_text",
+ "ccres_ray_emitter_off",
+ "ccres_ray_body",
+ "ccres_ray_ending",
+ ],
+ )?;
+ let cells = [
+ (&end, 5),
+ (&value, u32::from(VALUE_WIDTH)),
+ (&separator, 5),
+ (&emitter, 10),
+ (&body, u32::from(LABEL_WIDTH)),
+ (&cap, 6),
+ ];
+ let [width, height] = EXTENT;
+ let mut background = RgbaImage {
+ width,
+ height,
+ rgba8: vec![0; (width * height * 4) as usize],
+ };
+ for y in [0, SEPARATION] {
+ let mut right = width;
+ for (sprite, width) in cells {
+ copy_sprite(
+ &mut background,
+ sprite,
+ [right - width - 1, y, right, y + u32::from(ROW_HEIGHT)],
+ [false; 2],
+ [255; 3],
+ );
+ right -= width;
+ }
+ }
+ let font = load_layout_font(vfs)?;
+ let [ore, power] = labels.map(|text| font.centered_line(text, LABEL_WIDTH, ROW_HEIGHT));
+ Ok(Self {
+ background,
+ labels: [ore?, power?],
+ font,
+ })
+ }
+
+ /// Composes the filled bars and their text. A hidden zero keeps the row frame.
+ pub fn paint(&self, [ore, power]: [Option<u8>; 2]) -> Result<RgbaImage, String> {
+ const LABEL_LEFT: u32 = 7;
+ const LABEL_RIGHT: u32 = LABEL_LEFT + LABEL_WIDTH as u32;
+ const VALUE_LEFT: u32 = EXTENT[0] - 5 - VALUE_WIDTH as u32;
+ let mut image = self.background.clone();
+ for (row, percent) in [ore, power].into_iter().enumerate() {
+ let Some(percent) = percent else {
+ continue;
+ };
+ let y = row as u32 * SEPARATION;
+ let end = y + u32::from(ROW_HEIGHT);
+ let filled =
+ (f64::from(percent.min(100)) * f64::from(LABEL_WIDTH) * f64::from(0.01_f32))
+ .round_ties_even() as u32;
+ if filled > 2 {
+ let color = match percent {
+ 0..=19 => [128, 0, 0, 128],
+ 20..=79 => [128, 128, 0, 128],
+ _ => [0, 128, 0, 128],
+ };
+ copy_sprite(
+ &mut image,
+ &RgbaImage {
+ width: 1,
+ height: 1,
+ rgba8: color.to_vec(),
+ },
+ [LABEL_RIGHT - filled, y + 3, LABEL_RIGHT - 2, end - 3],
+ [false; 2],
+ [255; 3],
+ );
+ }
+ let tint = if percent == 0 { RED } else { GREEN };
+ copy_sprite(
+ &mut image,
+ &self.labels[row],
+ [LABEL_LEFT, y, LABEL_RIGHT, end],
+ [false; 2],
+ tint,
+ );
+ let number =
+ self.font
+ .centered_line(&format!("{percent}%"), VALUE_WIDTH, ROW_HEIGHT)?;
+ copy_sprite(
+ &mut image,
+ &number,
+ [VALUE_LEFT, y, VALUE_LEFT + u32::from(VALUE_WIDTH), end],
+ [false; 2],
+ tint,
+ );
+ }
+ Ok(image)
+ }
+}