//! Designer category widgets and the Unit DAT part-role word. use fparkan_prototype::UnitComponentRecord; const ROWS: usize = 6; /// Display order of the original designer category tabs. #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] pub enum DesignerCategory { /// Chassis. #[default] Chassis, /// Turret. Turret, /// External weapon. Weapon, /// Armour plating. Armour, /// Internal equipment. Systems, /// Ammunition. Ammo, } impl DesignerCategory { /// Tabs in screen order from left to right. pub const ALL: [Self; 6] = [ Self::Chassis, Self::Turret, Self::Weapon, Self::Armour, Self::Systems, Self::Ammo, ]; /// Reads the role stored by the original Unit DAT writer. pub fn from_record(record: &UnitComponentRecord) -> Option { Some(match record.tail0 { 0 => Self::Chassis, 1 => Self::Turret, 2 => Self::Armour, 3 => Self::Systems, 4 => Self::Weapon, 5 => Self::Ammo, _ => return None, }) } /// Resource string ID of the category. pub const fn label_id(self) -> u16 { match self { Self::Chassis => 0x1848, Self::Armour => 0x1849, Self::Turret => 0x184a, Self::Weapon => 0x184b, Self::Ammo => 0x184c, Self::Systems => 0x184d, } } pub(crate) const fn tab(self) -> (u32, u32, [u32; 4]) { // Frame X, glyph X, glyph atlas rectangle, all from iron3d+0x4c390. match self { Self::Chassis => (8, 9, [48, 72, 24, 24]), Self::Turret => (35, 36, [72, 72, 24, 24]), Self::Weapon => (61, 62, [96, 72, 24, 24]), Self::Armour => (101, 102, [193, 97, 24, 24]), Self::Systems => (128, 129, [120, 72, 24, 24]), Self::Ammo => (154, 155, [206, 192, 24, 24]), } } pub(crate) const fn tint(self, enabled: bool, selected: bool) -> [u8; 3] { let outer = matches!(self, Self::Chassis | Self::Turret | Self::Weapon); match (outer, enabled, selected) { (true, true, true) => [220, 220, 255], (true, true, false) => [150, 150, 230], (true, false, _) => [64, 64, 100], (false, true, true) => [210, 230, 230], (false, true, false) => [120, 200, 200], (false, false, _) => [64, 75, 75], } } /// Record indices in their original project order, retaining duplicate parts. pub fn mounts(self, records: &[UnitComponentRecord]) -> impl Iterator + '_ { records .iter() .enumerate() .filter_map(move |(index, record)| { (Self::from_record(record) == Some(self)).then_some(index) }) } } /// Side of the designer displaying mount records or replacement parts. #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum DesignerPartsPane { /// The replacement choices for the inspected mount. Parts, /// The installed mounts of the selected category. Model, } impl DesignerPartsPane { pub(crate) const fn left(self) -> u32 { match self { Self::Parts => 0, Self::Model => 457, } } /// Which pane contains a point in the replacement and model lists. pub fn at([x, y]: [f32; 2]) -> Option { [Self::Parts, Self::Model].into_iter().find(|pane| { let left = pane.left() as f32; (left..left + 180.0).contains(&x) && (65.0..224.0).contains(&y) }) } pub(crate) const fn row(self, index: usize) -> [u32; 4] { let top = 65 + index as u32 * 23; [self.left(), top, self.left() + 180, top + 21] } pub(crate) const fn arrow(self, forward: bool) -> [u32; 4] { let left = self.left(); if forward { [left + 162, 203, left + 180, 224] } else { [left + 147, 203, left + 162, 224] } } } /// Six visible original rows per list. pub const DESIGNER_PARTS_ROWS: usize = ROWS; pub(crate) fn contains(rect: [u32; 4], [x, y]: [f32; 2]) -> bool { let [left, top, right, bottom] = rect.map(|value| value as f32); (left..right).contains(&x) && (top..bottom).contains(&y) }