聊天重做前缓存
This commit is contained in:
204
MapIcons.lua
204
MapIcons.lua
@@ -127,6 +127,64 @@ local function GetZoneYards()
|
||||
return nil, nil
|
||||
end
|
||||
|
||||
local function IsMapStateProtected()
|
||||
if WorldMapFrame and WorldMapFrame:IsVisible() then
|
||||
return true
|
||||
end
|
||||
if BattlefieldMinimap and BattlefieldMinimap:IsVisible() then
|
||||
return true
|
||||
end
|
||||
if BattlefieldMinimapFrame and BattlefieldMinimapFrame:IsVisible() then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function SafeSetMapToCurrentZone()
|
||||
if not SetMapToCurrentZone then
|
||||
return
|
||||
end
|
||||
if SFrames and SFrames.CallWithPreservedBattlefieldMinimap then
|
||||
return SFrames:CallWithPreservedBattlefieldMinimap(SetMapToCurrentZone)
|
||||
end
|
||||
return pcall(SetMapToCurrentZone)
|
||||
end
|
||||
|
||||
local function SafeSetMapZoom(continent, zone)
|
||||
if not SetMapZoom then
|
||||
return
|
||||
end
|
||||
if SFrames and SFrames.CallWithPreservedBattlefieldMinimap then
|
||||
return SFrames:CallWithPreservedBattlefieldMinimap(SetMapZoom, continent, zone)
|
||||
end
|
||||
return pcall(SetMapZoom, continent, zone)
|
||||
end
|
||||
|
||||
local function WithPlayerZoneMap(func)
|
||||
if type(func) ~= "function" then
|
||||
return
|
||||
end
|
||||
if IsMapStateProtected() or not SetMapToCurrentZone then
|
||||
return func()
|
||||
end
|
||||
|
||||
local savedC = GetCurrentMapContinent and GetCurrentMapContinent() or 0
|
||||
local savedZ = GetCurrentMapZone and GetCurrentMapZone() or 0
|
||||
|
||||
SafeSetMapToCurrentZone()
|
||||
local results = { func() }
|
||||
|
||||
if SetMapZoom then
|
||||
if savedZ and savedZ > 0 and savedC and savedC > 0 then
|
||||
SafeSetMapZoom(savedC, savedZ)
|
||||
elseif savedC and savedC > 0 then
|
||||
SafeSetMapZoom(savedC, 0)
|
||||
end
|
||||
end
|
||||
|
||||
return unpack(results)
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- 1. World Map + Battlefield Minimap: class icon overlays
|
||||
--------------------------------------------------------------------------------
|
||||
@@ -224,97 +282,95 @@ local function UpdateMinimapDots()
|
||||
return
|
||||
end
|
||||
|
||||
if WorldMapFrame and WorldMapFrame:IsVisible() then
|
||||
if IsMapStateProtected() then
|
||||
return
|
||||
end
|
||||
|
||||
if SetMapToCurrentZone then
|
||||
pcall(SetMapToCurrentZone)
|
||||
end
|
||||
WithPlayerZoneMap(function()
|
||||
local px, py = GetPlayerMapPosition("player")
|
||||
if not px or not py or (px == 0 and py == 0) then
|
||||
for i = 1, MAX_PARTY do
|
||||
if mmDots[i] then mmDots[i]:Hide() end
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
local zw, zh = GetZoneYards()
|
||||
if not zw or not zh or zw == 0 or zh == 0 then
|
||||
for i = 1, MAX_PARTY do
|
||||
if mmDots[i] then mmDots[i]:Hide() end
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
local now = GetTime()
|
||||
if now - indoorCheckTime > 3 then
|
||||
indoorCheckTime = now
|
||||
cachedIndoor = DetectIndoor()
|
||||
end
|
||||
|
||||
local zoom = Minimap:GetZoom()
|
||||
local mmYards = MM_ZOOM[cachedIndoor] and MM_ZOOM[cachedIndoor][zoom]
|
||||
or MM_ZOOM[1][zoom] or 466.67
|
||||
local mmHalfYards = mmYards / 2
|
||||
local mmHalfPx = Minimap:GetWidth() / 2
|
||||
|
||||
local facing = 0
|
||||
local doRotate = false
|
||||
local okCvar, rotateVal = pcall(GetCVar, "rotateMinimap")
|
||||
if okCvar and rotateVal == "1" and GetPlayerFacing then
|
||||
local ok2, f = pcall(GetPlayerFacing)
|
||||
if ok2 and f then
|
||||
facing = f
|
||||
doRotate = true
|
||||
end
|
||||
end
|
||||
|
||||
local px, py = GetPlayerMapPosition("player")
|
||||
if not px or not py or (px == 0 and py == 0) then
|
||||
for i = 1, MAX_PARTY do
|
||||
if mmDots[i] then mmDots[i]:Hide() end
|
||||
end
|
||||
return
|
||||
end
|
||||
local unit = "party" .. i
|
||||
if i <= numParty and UnitExists(unit) and UnitIsConnected(unit) then
|
||||
local mx, my = GetPlayerMapPosition(unit)
|
||||
if mx and my and (mx ~= 0 or my ~= 0) then
|
||||
local dx = (mx - px) * zw
|
||||
local dy = (py - my) * zh
|
||||
|
||||
local zw, zh = GetZoneYards()
|
||||
if not zw or not zh or zw == 0 or zh == 0 then
|
||||
for i = 1, MAX_PARTY do
|
||||
if mmDots[i] then mmDots[i]:Hide() end
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
local now = GetTime()
|
||||
if now - indoorCheckTime > 3 then
|
||||
indoorCheckTime = now
|
||||
cachedIndoor = DetectIndoor()
|
||||
end
|
||||
|
||||
local zoom = Minimap:GetZoom()
|
||||
local mmYards = MM_ZOOM[cachedIndoor] and MM_ZOOM[cachedIndoor][zoom]
|
||||
or MM_ZOOM[1][zoom] or 466.67
|
||||
local mmHalfYards = mmYards / 2
|
||||
local mmHalfPx = Minimap:GetWidth() / 2
|
||||
|
||||
local facing = 0
|
||||
local doRotate = false
|
||||
local okCvar, rotateVal = pcall(GetCVar, "rotateMinimap")
|
||||
if okCvar and rotateVal == "1" and GetPlayerFacing then
|
||||
local ok2, f = pcall(GetPlayerFacing)
|
||||
if ok2 and f then
|
||||
facing = f
|
||||
doRotate = true
|
||||
end
|
||||
end
|
||||
|
||||
for i = 1, MAX_PARTY do
|
||||
local unit = "party" .. i
|
||||
if i <= numParty and UnitExists(unit) and UnitIsConnected(unit) then
|
||||
local mx, my = GetPlayerMapPosition(unit)
|
||||
if mx and my and (mx ~= 0 or my ~= 0) then
|
||||
local dx = (mx - px) * zw
|
||||
local dy = (py - my) * zh
|
||||
|
||||
if doRotate then
|
||||
local s = math.sin(facing)
|
||||
local c = math.cos(facing)
|
||||
dx, dy = dx * c + dy * s, -dx * s + dy * c
|
||||
end
|
||||
|
||||
local dist = math.sqrt(dx * dx + dy * dy)
|
||||
if dist < mmHalfYards * 0.92 then
|
||||
local scale = mmHalfPx / mmHalfYards
|
||||
|
||||
if not mmDots[i] then
|
||||
mmDots[i] = CreateMinimapDot(i)
|
||||
if doRotate then
|
||||
local s = math.sin(facing)
|
||||
local c = math.cos(facing)
|
||||
dx, dy = dx * c + dy * s, -dx * s + dy * c
|
||||
end
|
||||
local dot = mmDots[i]
|
||||
|
||||
local _, class = UnitClass(unit)
|
||||
local cc = class and CLASS_COLORS and CLASS_COLORS[class]
|
||||
if cc then
|
||||
dot.icon:SetVertexColor(cc.r, cc.g, cc.b, 1)
|
||||
local dist = math.sqrt(dx * dx + dy * dy)
|
||||
if dist < mmHalfYards * 0.92 then
|
||||
local scale = mmHalfPx / mmHalfYards
|
||||
|
||||
if not mmDots[i] then
|
||||
mmDots[i] = CreateMinimapDot(i)
|
||||
end
|
||||
local dot = mmDots[i]
|
||||
|
||||
local _, class = UnitClass(unit)
|
||||
local cc = class and CLASS_COLORS and CLASS_COLORS[class]
|
||||
if cc then
|
||||
dot.icon:SetVertexColor(cc.r, cc.g, cc.b, 1)
|
||||
else
|
||||
dot.icon:SetVertexColor(1, 0.82, 0, 1)
|
||||
end
|
||||
|
||||
dot:ClearAllPoints()
|
||||
dot:SetPoint("CENTER", Minimap, "CENTER", dx * scale, dy * scale)
|
||||
dot:Show()
|
||||
else
|
||||
dot.icon:SetVertexColor(1, 0.82, 0, 1)
|
||||
if mmDots[i] then mmDots[i]:Hide() end
|
||||
end
|
||||
|
||||
dot:ClearAllPoints()
|
||||
dot:SetPoint("CENTER", Minimap, "CENTER", dx * scale, dy * scale)
|
||||
dot:Show()
|
||||
else
|
||||
if mmDots[i] then mmDots[i]:Hide() end
|
||||
end
|
||||
else
|
||||
if mmDots[i] then mmDots[i]:Hide() end
|
||||
end
|
||||
else
|
||||
if mmDots[i] then mmDots[i]:Hide() end
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user