aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/fparkan-assets/src/strategy_toolbar.rs38
1 files changed, 29 insertions, 9 deletions
diff --git a/crates/fparkan-assets/src/strategy_toolbar.rs b/crates/fparkan-assets/src/strategy_toolbar.rs
index ac06e26e..9269b957 100644
--- a/crates/fparkan-assets/src/strategy_toolbar.rs
+++ b/crates/fparkan-assets/src/strategy_toolbar.rs
@@ -9,6 +9,10 @@ pub const EXTENT: [u32; 2] = [46, 480];
// Each row uses the ordinary enabled button and its own glyph.
// The constructor at iron3d+0x82930 also determines the sections' order.
const BUTTON_TOPS: [u32; 12] = [12, 65, 94, 123, 176, 229, 258, 287, 316, 369, 399, 428];
+/// String resources assigned to the buttons by iron3d+0x82930, top to bottom.
+pub const TOOLTIP_IDS: [u32; BUTTON_TOPS.len()] = [
+ 0x64c, 0x640, 0x642, 0x641, 0x13d8, 0x647, 0x64e, 0x648, 0x64a, 0x13ae, 0x5dd, 0x516,
+];
const SEPARATORS: [u32; 4] = [41, 152, 205, 345];
const LOCK_TOP: u32 = 457;
const GLYPH_OFFSET: [u32; 2] = [16, 3];
@@ -30,19 +34,24 @@ pub enum ToolbarAction {
/// Tests the native button bounds in the original 640×480 screen space.
#[must_use]
pub fn command_button_at([x, y]: [f32; 2]) -> Option<ToolbarAction> {
+ match button_index_at([x, y])? {
+ 0 => Some(ToolbarAction::Hero),
+ 1 => Some(ToolbarAction::Warbots),
+ 10 => Some(ToolbarAction::Map),
+ _ => None,
+ }
+}
+
+/// Index of the button under the pointer, including disabled buttons.
+#[must_use]
+pub fn button_index_at([x, y]: [f32; 2]) -> Option<usize> {
if !(0.0..EXTENT[0] as f32).contains(&x.round_ties_even()) {
return None;
}
let y = y.round_ties_even();
- [
- (0, ToolbarAction::Hero),
- (1, ToolbarAction::Warbots),
- (10, ToolbarAction::Map),
- ]
- .into_iter()
- .find_map(|(index, action)| {
- let top = BUTTON_TOPS[index] as f32;
- (top..top + 29.0).contains(&y).then_some(action)
+ BUTTON_TOPS.into_iter().position(|top| {
+ let top = top as f32;
+ (top..top + 29.0).contains(&y)
})
}
@@ -128,6 +137,17 @@ mod tests {
}
#[test]
+ fn tooltip_targets_include_disabled_buttons_but_exclude_separators_and_lock() {
+ let resource = |x, y| button_index_at([x, y]).map(|index| TOOLTIP_IDS[index]);
+ assert_eq!(resource(45.0, 258.0), Some(0x64e));
+ assert_eq!(resource(0.0, 456.0), Some(0x516));
+ for gap in [11.0, 41.0, 152.0, 205.0, 345.0, 457.0, 479.0] {
+ assert_eq!(resource(24.0, gap), None);
+ }
+ assert_eq!(resource(46.0, 258.0), None);
+ }
+
+ #[test]
#[ignore = "requires licensed corpus"]
fn expanded_toolbar_loads_the_native_buttons_in_order() {
let root = std::env::var_os("FPARKAN_CORPUS_PART1_ROOT").unwrap();