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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
//! 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<Self> {
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<Item = usize> + '_ {
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> {
[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)
}
|