The world map lights and names the continent under the cursor (#1715)

At the world view of the world map, pointing at a continent showed no name and no outline: `UpdateMapHighlight` answered nothing at world level. In 1.12.1 the verb (`0x4a7fa0`) finds the continent whose sheet rect holds the point (`0x4a7620`) and returns its Map.dbc name (`0x4a825b`), its WorldMapArea file, the texture share (`0x4a83b9`: 1 by H/W when wider, else W/H by 1) and the quad from its WorldMapContinent row (`0x4a8407`: W·s/62.625, H·s/41.75, the corner by the builder's sheet law).

`worldmap::world_hover` now builds those eight values, and the catalog carries each continent's WorldMapContinent row. The click's citation moves from the unreached `0x4a7100` to its inline loop `0x4a755a`.

Tests: the eight values for Kalimdor, the Eastern Kingdoms, the sea and a wide continent; and the stock WorldMapFrame over Kalimdor on the install, checking label, texture and quad. Both fail without the change.

Fixes #866

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Sam Sung
2026-10-17 02:46:53 +07:00
committed by GitHub
parent a8ad08a391
commit 67345f9914
6 changed files with 297 additions and 21 deletions
@@ -79,6 +79,7 @@ fn catalog() -> Vec<WorldMapContinentView> {
map_file: "Kalimdor".into(),
world_rect: (0.0, 0.0, 1.0, 1.0),
loc_rect: (10000.0, -10000.0, 10000.0, -10000.0),
sheet: None,
zone_grid: Vec::new(),
zones: vec![WorldMapZoneView {
name: "Warsong Gulch".into(),
@@ -730,6 +730,80 @@ fn the_real_feralas_catalog_names_dire_maul_under_the_cursor() {
);
}
/// The real catalog at the world level: the cursor over Kalimdor puts its `Map.dbc` name in the
/// label and shows `Interface\WorldMap\Kalimdor\KalimdorHighlight` over its sheet rect, from its
/// `WorldMapContinent` row (`0x4a83b9`): tiles 23..=48 by 9..=52 at scale 0.75, so 26 by 44 tiles
/// of the 62.625 by 41.75 sheet, the texture's left 26/44 drawn.
#[test]
fn hovering_a_continent_on_the_world_map_lights_it() {
let data = benilla_formats::wow_data_or_skip!();
let mut s = harness();
let mut chain = benilla_formats::open_chain(&data).expect("chain");
for file in ["Kalimdor", "Azeroth"] {
let path = format!("Interface\\WorldMap\\{file}\\{file}Highlight.blp");
assert!(chain.contains(&path), "{path} ships");
}
let areas = benilla_formats::load_area_table_catalog(&mut chain).expect("AreaTable");
let maps =
benilla_assets::MapCatalogRes(benilla_formats::load_map_catalog(&mut chain).expect("Map"));
let (views, _) =
crate::ui_world_map::build_catalog(&mut chain, &areas, &maps).expect("the real catalog");
// Every continent has its row, so no stock data reaches the rowless branch.
assert!(views.iter().all(|c| c.sheet.is_some()));
let kalimdor = views
.iter()
.find(|c| c.map_file == "Kalimdor")
.expect("Kalimdor is in the catalog");
let row = kalimdor
.sheet
.expect("Kalimdor has its WorldMapContinent row");
assert_eq!((row.tiles, row.scale), ((23, 48, 9, 52), 0.75));
s.set_world_map_catalog(views);
s.run("ToggleWorldMap()").unwrap();
s.run("SetMapZoom(0)").unwrap();
s.resolve();
let (l, r, t, b, eff) = s
.eval::<(f32, f32, f32, f32, f32)>(
"return WorldMapButton:GetLeft(), WorldMapButton:GetRight(), WorldMapButton:GetTop(), \
WorldMapButton:GetBottom(), WorldMapButton:GetEffectiveScale()",
)
.unwrap();
let (x, y) = ((l + (r - l) * 0.25) * eff, (t - (t - b) * 0.45) * eff);
s.mouse_move(x, y);
update(&mut s);
s.resolve();
assert_eq!(
s.eval::<String>("return WorldMapFrameAreaLabel:GetText()")
.unwrap(),
"Kalimdor"
);
let (shown, texture, w, h, dx, dy) = s
.eval::<(bool, String, f32, f32, f32, f32)>(
"return WorldMapHighlight:IsShown() == 1, WorldMapHighlight:GetTexture(), \
WorldMapHighlight:GetWidth(), WorldMapHighlight:GetHeight(), \
WorldMapHighlight:GetLeft() - WorldMapDetailFrame:GetLeft(), \
WorldMapDetailFrame:GetTop() - WorldMapHighlight:GetTop()",
)
.unwrap();
assert!(shown, "the stock OnUpdate shows the quad for a fileName");
assert!(
texture
.to_ascii_lowercase()
.ends_with("worldmap\\kalimdor\\kalimdorhighlight"),
"{texture}"
);
let (bw, bh) = (r - l, t - b);
let near = |a: f32, b: f32| (a - b).abs() < 0.01;
assert!(near(w, 19.5 / 62.625 * bw), "width {w}");
assert!(near(h, 33.0 / 41.75 * bh), "height {h}");
// Seated on `WorldMapDetailFrame`'s top-left, in the button's own units.
assert!(near(dx, 5.5625 / 62.625 * bw), "left {dx}");
assert!(near(dy, 3.302_502 / 41.75 * bh), "top {dy}");
}
/// An addon that windows the map (Cartographer's `LookNFeel`) stamps userPlaced through a drag
/// (`0x7652b0`, at `0x7652e5`). The layout cache gates both ends on `movable|resizable` too, as the
/// reference does (writer `0x490e97`; apply `0x490600`, `0x490689`), and stock `WorldMapFrame` has
+11 -1
View File
@@ -18,7 +18,7 @@ use benilla_formats::{
};
use benilla_ui::script::{
UiScript, WorldMapContinentView, WorldMapLandmarkSource, WorldMapLevel, WorldMapOverlayView,
WorldMapZoneView,
WorldMapSheetRow, WorldMapZoneView,
};
use crate::net::{ObjectStore, SelfPlayer};
@@ -221,6 +221,16 @@ pub(crate) fn build_catalog(
map_file: cont.name.clone(),
world_rect,
loc_rect: (cont.loc_left, cont.loc_right, cont.loc_top, cont.loc_bottom),
sheet: wmc.get(cont.map_id).map(|c| WorldMapSheetRow {
tiles: (
c.left_boundary,
c.right_boundary,
c.top_boundary,
c.bottom_boundary,
),
offset: (c.offset_x, c.offset_y),
scale: c.scale,
}),
zone_grid,
zones: zones
.iter()
+1 -1
View File
@@ -339,7 +339,7 @@ pub use weapon_enchant::WeaponEnchant;
pub use who_sort::{WhoSortChain, WhoSortKey};
pub use worldmap::{
WorldMapContinentView, WorldMapLandmarkSource, WorldMapLandmarkView, WorldMapLevel,
WorldMapOverlayView, WorldMapState, WorldMapZoneView,
WorldMapOverlayView, WorldMapSheetRow, WorldMapState, WorldMapZoneView,
};
pub use worldstate::WorldStateUiView;
pub use worn_display::WornDisplay;
@@ -21,6 +21,11 @@ fn push_catalog(s: &mut UiScript) {
map_file: "Kalimdor".into(),
world_rect: (0.08882, 0.07910, 0.40020, 0.86952),
loc_rect: (17066.6, -19733.2, 12799.9, -11733.3),
sheet: Some(WorldMapSheetRow {
tiles: (23, 48, 9, 52),
offset: (-19.0, -0.322_498),
scale: 0.75,
}),
zone_grid: Vec::new(),
zones: vec![
WorldMapZoneView {
@@ -44,6 +49,11 @@ fn push_catalog(s: &mut UiScript) {
map_file: "Azeroth".into(),
world_rect: (0.62375, 0.02695, 0.92315, 0.87126),
loc_rect: (16000.0, -19199.9, 7466.6, -16000.0),
sheet: Some(WorldMapSheetRow {
tiles: (23, 47, 15, 61),
offset: (14.5, -7.0),
scale: 0.75,
}),
zone_grid: ek_grid,
zones: vec![
WorldMapZoneView {
@@ -494,6 +504,114 @@ fn worldmap_click_containment_and_zone_grid() {
assert_eq!(s.eval::<i64>("return GetCurrentMapContinent()").unwrap(), 0);
}
/// At world level `UpdateMapHighlight` lights the continent under the cursor (`0x4a7639`,
/// `0x4a83b9`): its `Map.dbc` name, its art folder for `<file>\<file>Highlight`, the texture's
/// share on each axis from the `WorldMapContinent` tile counts (the longer axis whole), and the
/// quad over its sheet rect from that row: Kalimdor's 26 by 44 tiles at scale 0.75 from
/// (5.5625, 3.302502) sheet tiles, the Eastern Kingdoms' 25 by 47 from (39.0625, 1.125).
#[test]
fn worldmap_world_level_hover_lights_the_continent() {
let mut s = script();
push_catalog(&mut s);
assert_eq!(s.eval::<i64>("return GetCurrentMapContinent()").unwrap(), 0);
type Answer = (Option<String>, Option<String>, f64, f64, f64, f64, f64, f64);
let hover = |s: &mut UiScript, x: f32, y: f32| {
s.eval::<Answer>(&format!("return UpdateMapHighlight({x}, {y})"))
.unwrap()
};
let close = |got: Answer, want: (&str, &str, [f64; 6])| {
assert_eq!(got.0.as_deref(), Some(want.0));
assert_eq!(got.1.as_deref(), Some(want.1));
let nums = [got.2, got.3, got.4, got.5, got.6, got.7];
for (i, (g, w)) in nums.iter().zip(want.2).enumerate() {
assert!(
(g - w).abs() < 1e-6,
"value {} of {}: {g} vs {w}",
i + 3,
want.0
);
}
};
close(
hover(&mut s, 0.25, 0.45),
(
"Kalimdor",
"Kalimdor",
[
26.0 / 44.0,
1.0,
19.5 / 62.625,
33.0 / 41.75,
5.5625 / 62.625,
3.302_502 / 41.75,
],
),
);
close(
hover(&mut s, 0.72, 0.63),
(
"Eastern Kingdoms",
"Azeroth",
[
25.0 / 47.0,
1.0,
18.75 / 62.625,
35.25 / 41.75,
39.0625 / 62.625,
1.125 / 41.75,
],
),
);
// The open sea between the sheet rects: the nil tail, which hides the quad.
let miss: Answer = (None, None, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
assert_eq!(hover(&mut s, 0.5, 0.5), miss);
// A wide continent gives its height the share (`0x4a83c6`); one with no row keeps 64 by 64
// tiles and a zero quad (`0x4a82a2`, `0x4a8401`).
s.set_world_map_catalog(vec![
WorldMapContinentView {
name: "Wide".into(),
map_file: "Wide".into(),
world_rect: (0.0, 0.0, 0.5, 1.0),
loc_rect: (1.0, 0.0, 1.0, 0.0),
sheet: Some(WorldMapSheetRow {
tiles: (0, 9, 0, 4),
offset: (0.0, 0.0),
scale: 1.0,
}),
..Default::default()
},
WorldMapContinentView {
name: "Rowless".into(),
map_file: "Rowless".into(),
world_rect: (0.5, 0.0, 1.0, 1.0),
loc_rect: (1.0, 0.0, 1.0, 0.0),
..Default::default()
},
]);
close(
hover(&mut s, 0.25, 0.5),
(
"Wide",
"Wide",
[
1.0,
0.5,
10.0 / 62.625,
5.0 / 41.75,
-0.6875 / 62.625,
-11.125 / 41.75,
],
),
);
close(
hover(&mut s, 0.75, 0.5),
("Rowless", "Rowless", [1.0, 1.0, 0.0, 0.0, 0.0, 0.0]),
);
}
/// At zone level `UpdateMapHighlight` answers a name only (`0x4a812e`): a revealed overlay's
/// sub-area under the cursor, else the neighbouring zone or city whose cell the cursor is in
/// through the displayed zone's rect, never that zone itself. The file name is nil and the
+92 -19
View File
@@ -115,16 +115,30 @@ pub struct WorldMapContinentView {
pub name: String,
pub map_file: String,
/// The rect on the world sheet in UV `(u0, v0, u1, v1)`, from the `WorldMapContinent` tile
/// bounds (`0x4a5d00`); a world-level click takes the first that holds it (`0x4a7100`).
/// bounds (`0x4a5d00`); a world-level hover or click takes the first that holds it.
pub world_rect: (f32, f32, f32, f32),
/// The `WorldMapArea` loc rect the cell law un-lerps a hover or click through.
pub loc_rect: (f32, f32, f32, f32),
/// The `WorldMapContinent.dbc` row of the continent's map, which seats its world-level
/// highlight (`0x4a82c6`); `None` when the map has none.
pub sheet: Option<WorldMapSheetRow>,
/// The 128×128 area bitmap (`<Continent>.zmp`, read at `0x4a5feb`) as 1-based indices into
/// [`Self::zones`], 0 for none; empty when no bitmap ships, leaving hover and click inert.
pub zone_grid: Vec<u16>,
pub zones: Vec<WorldMapZoneView>,
}
/// A continent's place on the world sheet: the `WorldMapContinent.dbc` fields the world-level
/// highlight reads (`0x4a82ed`, `0x4a8407`).
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct WorldMapSheetRow {
/// The ADT tile bounds `(left, right, top, bottom)`, both ends inclusive.
pub tiles: (u32, u32, u32, u32),
/// `OffsetX` and `OffsetY`, in sheet tiles.
pub offset: (f32, f32),
pub scale: f32,
}
/// The `0x4a6ec0` cell law: clamp the UV, un-lerp through the loc rect to world coordinates,
/// scale by `0x806544` (1/(64·533.33)), range-check, and index `col - row·128`, `row` being
/// truncated from the negated axis and so `<= 0`.
@@ -278,7 +292,7 @@ enum Hover {
Highlight {
name: String,
file: String,
tex_pct_y: f64,
tex_pct: (f64, f64),
texture: (f64, f64),
scroll: (f64, f64),
},
@@ -314,23 +328,88 @@ fn continent_hover(cont: &WorldMapContinentView, zone: &WorldMapZoneView) -> Opt
Some(Hover::Highlight {
name: zone.name.clone(),
file: zone.map_file.clone(),
tex_pct_y,
tex_pct: (1.0, tex_pct_y),
texture: (texture_x, texture_y),
scroll: (scroll_x, scroll_y),
})
}
/// `0x4a7fa0`'s level dispatch. Continent level: the grid's zone highlights. Zone level: the
/// overlay pre-search, then the grid through the displayed zone's rect (`0x4a7620`), naming a
/// neighbour but never the displayed zone, name only (`0x4a812e`). World level: the tail, as the
/// continent highlight the reference draws there is not built here.
/// The 1-based continent whose sheet rect holds `(x, y)`, edges inclusive, the first in catalog
/// order: the world-level leg of the hover (`0x4a7639`) and of the click (`0x4a755a`).
fn sheet_continent(wm: &WorldMapState, x: f32, y: f32) -> Option<u32> {
wm.continents
.iter()
.position(|cont| {
let (u0, v0, u1, v1) = cont.world_rect;
(u0..=u1).contains(&x) && (v0..=v1).contains(&y)
})
.map(|i| i as u32 + 1)
}
/// The world-level highlight (`0x4a81de` → `0x4a825b` → `0x4a83b9`): the continent's `Map.dbc`
/// name and art folder, drawn as `<file>\<file>Highlight`. The texture's long side is the tile
/// rect's longer one, the other in proportion; the quad is the continent's sheet rect, recomputed
/// from its `WorldMapContinent` row (`0x4a8407`) by the builder's law (`0x4a5f42`).
fn world_hover(cont: &WorldMapContinentView) -> Hover {
// `[0x8029d4]`, 2^-22: a loc rect of four near-zeros is a miss (`0x4a81de..0x4a8224`).
const EPS: f32 = f32::from_bits(0x3480_0000);
// `[0x806528]` = 1/62.625 and `[0x806524]` = 1/41.75, the sheet's tile spans.
const K_U: f64 = f32::from_bits(0x3c82_cf75) as f64;
const K_V: f64 = f32::from_bits(0x3cc4_3730) as f64;
let (l, r, t, b) = cont.loc_rect;
if [l, r, t, b].iter().all(|v| v.abs() < EPS) {
return Hover::Miss;
}
// The tile counts, 64 by 64 with no row (`0x4a82a2`), and the quad zero (`0x4a8401`).
let count = |lo: u32, hi: u32| (hi as i32).wrapping_sub(lo as i32).wrapping_add(1) as f32;
let (w, h) = cont.sheet.map_or((64.0, 64.0), |row| {
let (left, right, top, bottom) = row.tiles;
(count(left, right), count(top, bottom))
});
// `0x4a83b9`: the strictly longer axis is 1.0.
let tex_pct = if w > h {
(1.0, f64::from(h) / f64::from(w))
} else {
(f64::from(w) / f64::from(h), 1.0)
};
let (texture, scroll) = cont.sheet.map_or(((0.0, 0.0), (0.0, 0.0)), |row| {
let s = f64::from(row.scale);
// The top-left corner in sheet tiles, stored as f32 (`0x4a8428`, `0x4a843e`).
let corner = |tile: u32, base: f64, offset: f32| {
(f64::from(tile as i32) * s + (base - 32.0 * s) + f64::from(offset)) as f32
};
let x = corner(row.tiles.0, 31.3125, row.offset.0);
let y = corner(row.tiles.2, 20.875, row.offset.1);
(
(f64::from(w) * s * K_U, f64::from(h) * s * K_V),
(f64::from(x) * K_U, f64::from(y) * K_V),
)
});
Hover::Highlight {
name: cont.name.clone(),
file: cont.map_file.clone(),
tex_pct,
texture,
scroll,
}
}
/// `0x4a7fa0`'s level dispatch. World level: the continent under the cursor (`0x4a7639`), lit.
/// Continent level: the grid's zone highlights. Zone level: the overlay pre-search, then the grid
/// through the displayed zone's rect (`0x4a7620`), naming a neighbour but never the displayed
/// zone, name only (`0x4a812e`).
fn hover(wm: &WorldMapState, x: f32, y: f32) -> Hover {
// An instance map resolves no area (`0x4a7620` opens `cmp esi,-2; je 0x4a76d7`).
if wm.direct_area.is_some() {
return Hover::Miss;
}
let (c, z) = wm.selection;
let Some(cont) = c.checked_sub(1).and_then(|i| wm.continents.get(i as usize)) else {
if c == 0 {
return sheet_continent(wm, x, y)
.and_then(|ci| wm.continents.get(ci as usize - 1))
.map_or(Hover::Miss, world_hover);
}
let Some(cont) = wm.continents.get(c as usize - 1) else {
return Hover::Miss;
};
if z != 0 {
@@ -778,7 +857,7 @@ pub(super) fn install(lua: &Lua) -> mlua::Result<()> {
)?;
// ProcessMapClick(x, y) (`0x4a7f30`): at world level the first continent whose sheet rect
// holds the click (`0x4a7100`); otherwise the zone or city under it through the displayed
// holds the click (`0x4a755a`); otherwise the zone or city under it through the displayed
// rect (`0x4a6ec0`), which it drills into.
g.set(
"ProcessMapClick",
@@ -791,13 +870,7 @@ pub(super) fn install(lua: &Lua) -> mlua::Result<()> {
if wm.direct_area.is_some() {
None
} else if wm.selection.0 == 0 {
wm.continents
.iter()
.position(|cont| {
let (u0, v0, u1, v1) = cont.world_rect;
(u0..=u1).contains(&x) && (v0..=v1).contains(&y)
})
.map(|i| (i as i64 + 1, 0))
sheet_continent(wm, x, y).map(|ci| (i64::from(ci), 0))
} else {
grid_area(wm, x, y).map(|zi| (i64::from(wm.selection.0), i64::from(zi)))
}
@@ -829,14 +902,14 @@ pub(super) fn install(lua: &Lua) -> mlua::Result<()> {
Hover::Highlight {
name,
file,
tex_pct_y,
tex_pct,
texture,
scroll,
} => (
string(&name)?,
string(&file)?,
1.0f64,
tex_pct_y,
tex_pct.0,
tex_pct.1,
texture.0,
texture.1,
scroll.0,