Files
pfUI/modules/mapreveal.lua
T
Brues f37ea00226 Give pfUI its own EventRegistry and move event-only frames onto it
pfUI.events was a bare CallbackRegistry for pfUI's custom events. Build it
from ClassicAPI's EventRegistry instead, so the same object also takes game
events through RegisterFrameEventAndCallback, sharing one frame for all of
them.

Move the frames that existed only to listen for a few events onto it:
libspell, focus, pixelperfect, innervatecall, loothistory, unusable,
equipmentmanager (bank + window refresh), the actionbar grid, updatenotify,
turtle-wow's steady shot, nampower's spell queue, superwow's group tracking
and unitxp's notifications, plus newitem and mapreveal, which used the
global EventRegistry. Handlers take their payload as arguments instead of
the event/arg globals, and the per-frame PLAYER_LOGOUT teardown goes away,
since the registry unregisters its frame on logout.
2026-10-30 12:37:56 -05:00

190 lines
7.2 KiB
Lua

pfUI:RegisterModule("mapreveal", function ()
if Cartographer then return end
if METAMAP_TITLE then return end
pfUI.mapreveal = {}
function pfUI.mapreveal:UpdateConfig()
WorldMapFrame_Update()
end
pfUI.mapreveal.onmap = CreateFrame("CheckButton", "pfUI_mapreveal_onmap", WorldMapFrame, "UICheckButtonTemplate")
pfUI.mapreveal.onmap:SetNormalTexture("")
pfUI.mapreveal.onmap:SetPushedTexture("")
pfUI.mapreveal.onmap:SetHighlightTexture("")
pfUI.mapreveal.onmap.text = _G["pfUI_mapreveal_onmapText"]
CreateBackdrop(pfUI.mapreveal.onmap, nil, true)
pfUI.mapreveal.onmap:SetWidth(14)
pfUI.mapreveal.onmap:SetHeight(14)
pfUI.mapreveal.onmap:SetPoint("LEFT", WorldMapZoomOutButton, "RIGHT", 20, 0)
pfUI.mapreveal.onmap.text:SetPoint("LEFT", pfUI.mapreveal.onmap, "RIGHT", 2, 0)
pfUI.mapreveal.onmap.text:SetText(T["Reveal Unexplored Areas"])
pfUI.mapreveal.onmap:SetScript("OnShow", function()
this:SetChecked(C.appearance.worldmap.mapreveal == "1")
end)
pfUI.mapreveal.onmap:SetScript("OnClick", function ()
if this:GetChecked() then
C.appearance.worldmap.mapreveal = "1"
else
C.appearance.worldmap.mapreveal = "0"
end
pfUI.mapreveal:UpdateConfig()
end)
local explorecaches = {}
-- Own texture pool - separate from Blizzard's WorldMapOverlay textures
local overlayPool = CreateTexturePool(WorldMapDetailFrame, "BORDER", nil, nil, function(_, tex)
tex:Hide()
tex:ClearAllPoints()
end)
local exploreEnter = function()
WorldMapTooltip:ClearLines()
WorldMapTooltip:SetOwner(this, "ANCHOR_TOP")
WorldMapTooltip:AddLine(T["Exploration Point"]..":", .3, 1, .8)
WorldMapTooltip:AddLine(this.name, 1, 1, 1)
WorldMapTooltip:Show()
if not explorecaches[this.area] then return end
if C.appearance.worldmap.mapreveal == "0" then return end
for texture in pairs(explorecaches[this.area]) do
texture:SetVertexColor(1,1,1,1)
end
end
local exploreLeave = function()
WorldMapTooltip:Hide()
if not explorecaches[this.area] then return end
if C.appearance.worldmap.mapreveal == "0" then return end
local r,g,b,a = GetStringColor(C.appearance.worldmap.mapreveal_color)
for texture in pairs(explorecaches[this.area]) do
texture:SetVertexColor(r,g,b,a)
end
end
-- Magnifying-glass icons for unexplored overlays. Everything constant lives
-- in the creator; the update only anchors and labels what it acquires -- and
-- it only acquires the ones it is going to show, where the old table grew an
-- icon for every overlay in the zone and hid most of them again.
local function CreateExplore()
local explore = CreateFrame("Frame", nil, WorldMapDetailFrame)
explore:SetSize(16, 16)
explore:SetScript("OnEnter", exploreEnter)
explore:SetScript("OnLeave", exploreLeave)
explore:EnableMouse(true)
explore:SetFrameLevel(255)
explore.tex = explore:CreateTexture(nil, "OVERLAY")
explore.tex:SetTexture("Interface\\WorldMap\\WorldMap-MagnifyingGlass")
explore.tex:SetBlendMode("ADD")
explore.tex:SetTexCoord(.08, .92, .08, .92)
explore.tex:SetAllPoints()
return explore
end
local explorePool = CreateObjectPool(CreateExplore, function(_, explore)
explore:Hide()
explore:ClearAllPoints()
end)
local function pfWorldMapFrame_Update()
-- clear stale caches
for k in pairs(explorecaches) do explorecaches[k] = nil end
-- hide all our textures and icons from last frame
overlayPool:ReleaseAll()
explorePool:ReleaseAll()
local showExplore = C.appearance.worldmap.mapexploration == "1"
local showReveal = C.appearance.worldmap.mapreveal == "1"
if not showExplore and not showReveal then return end
local r,g,b,a = GetStringColor(C.appearance.worldmap.mapreveal_color)
local mapFileName = GetMapInfo()
if not mapFileName then mapFileName = "World" end
-- ClassicAPI: full overlay list for the viewed zone (explored + unexplored),
-- read straight from WorldMapOverlay.dbc. Replaces the hand-measured pfMapOverlayData.
local zoneData = C_Map.GetMapOverlays() or {}
-- ClassicAPI: the unexplored subset of the viewed zone, using the engine's
-- own explored-bit test. Replaces the alreadyknown accumulator, which
-- replayed the explored-only GetMapOverlayInfo view. Keyed by the bare
-- texture name, the same key the icon cache below uses.
local unknown = {}
if showExplore then
for _, overlay in ipairs(C_MapExplorationInfo.GetUnexploredMapTextures() or {}) do
if overlay.textureName and overlay.textureName ~= "" then
unknown[string.upper(overlay.textureName)] = true
end
end
end
for _, overlay in ipairs(zoneData) do
local name = overlay.textureName -- bare, e.g. "DRYGULCHRAVINE"
local textureWidth = overlay.textureWidth
local textureHeight = overlay.textureHeight
local offsetX = overlay.offsetX
local offsetY = overlay.offsetY
-- explore magnifying glass icon for overlays the engine still
-- counts as unexplored.
if showExplore and unknown[string.upper(name)] then
local explore = explorePool:Acquire()
explore:SetPoint("TOPLEFT", "WorldMapDetailFrame", "TOPLEFT", offsetX + textureWidth/2, -offsetY - textureHeight/2)
explore.name = mapFileName .. " (" .. name .. ")"
explore.area = name -- cache key: explorecaches is keyed by the plain area name
explore:Show()
end
-- render overlay texture tiles on BORDER draw layer
-- Blizzard's explored overlays on ARTWORK draw on top of BORDER
--
-- overlay.tiles is pre-resolved by ClassicAPI: per-tile file /
-- draw size / texcoords / canvas position, with Octo's data
-- quirks (sliver columns the DBC rect rounds away, foreign tiles
-- appended to the number sequence, upscaled re-exports) already
-- disambiguated from the actual BLP dimensions. No 256px grid
-- math here — deriving the grid from textureWidth/Height is
-- exactly what shears quirky overlays (e.g. Icepoint's Kaneq'nuun).
if showReveal then
for _, tile in ipairs(overlay.tiles) do
local tex = overlayPool:Acquire()
tex:SetSize(tile.width, tile.height)
tex:SetTexCoord(0, tile.texCoordX, 0, tile.texCoordY)
tex:ClearAllPoints()
tex:SetPoint("TOPLEFT", "WorldMapDetailFrame", "TOPLEFT", tile.offsetX, -tile.offsetY)
tex:SetTexture(tile.file)
explorecaches[name] = explorecaches[name] or {}
explorecaches[name][tex] = true
tex:SetVertexColor(r,g,b,a)
tex:Show()
end
end
end
end
-- hook WorldMapFrame_Update
local origUpdate = _G.WorldMapFrame_Update
_G.WorldMapFrame_Update = function(...)
origUpdate(unpack(arg))
pfWorldMapFrame_Update()
end
-- live refresh while the map is open: exploration changes arrive on this
-- event. Zone switches, zoom and (re)opens still come through the hook
-- above, so nothing is redrawn while the map is closed — the next open
-- rebuilds from the current state.
pfUI.events:RegisterFrameEventAndCallback("MAP_EXPLORATION_UPDATED", function()
if WorldMapFrame and WorldMapFrame:IsShown() then
pfWorldMapFrame_Update()
end
end)
end)