Repository navigation
Expand file tree
/
Copy pathCore.lua
More file actions
105 lines (105 loc) · 4.99 KB
/
Copy pathCore.lua
File metadata and controls
105 lines (105 loc) · 4.99 KB
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
local addon, Maps = ...
local events=CreateFrame("Frame")
for _,event in ipairs({"ADDON_LOADED","PLAYER_REGEN_ENABLED","PLAYER_REGEN_DISABLED","MAP_EXPLORATION_UPDATED","DISPLAY_SIZE_CHANGED"}) do
events:RegisterEvent(event)
end
function Maps:Refresh(rebuildZoom)
if rebuildZoom then self.zoomPending=true end
if not self.map then self:Attach(); return end
if self.resetPending then self:ResetWindow() else self:ApplyWindow() end
if self.zoomPending and not (InCombatLockdown and InCombatLockdown()) and self.map:IsShown()
and self.map.ScrollContainer and type(self.map.ScrollContainer.zoomLevels)=="table"
and #self.map.ScrollContainer.zoomLevels>0 then
self.zoomPending=nil
end
if self.resetViewPending and not self.zoomPending and self:CanChangeWindow() and self.map:IsShown()
and self:GetReadyLayerIndex() then
local scroll=self.map.ScrollContainer
if scroll and type(scroll.ResetZoom)=="function" then
if securecallfunction then securecallfunction(scroll.ResetZoom,scroll,true)
else scroll:ResetZoom(true) end
self.resetViewPending=nil
end
end
if self.closeAfterReset and not (InCombatLockdown and InCombatLockdown()) then
self.closeAfterReset=nil
if self.map:IsShown() then
if HideUIPanel then
if securecallfunction then securecallfunction(HideUIPanel,self.map) else HideUIPanel(self.map) end
else self.map:Hide() end
end
end
self:RefreshReveal()
self:UpdateOptions()
end
function Maps:Attach()
if self.map or (InCombatLockdown and InCombatLockdown()) or not WorldMapFrame or not WorldMapFrame.GetCanvas then return end
self.map=WorldMapFrame
self:InstallWindow(self.map)
local function Reveal() self.extraZoomScale=nil; self:RefreshReveal() end
for _,method in ipairs({"OnMapChanged","OnCanvasSizeChanged"}) do
if type(self.map[method])=="function" then hooksecurefunc(self.map,method,Reveal) end
end
if type(self.map.RefreshMaskableTextures)=="function" then
hooksecurefunc(self.map,"RefreshMaskableTextures",function() self:UpdateRevealMasks() end)
end
if type(self.map.OnCanvasScaleChanged)=="function" then
local lastLayer
hooksecurefunc(self.map,"OnCanvasScaleChanged",function()
local layer=self:GetReadyLayerIndex()
if layer and layer~=lastLayer then lastLayer=layer; Reveal() end
end)
end
if self.map:IsShown() then self:Refresh(true) end
end
function Maps:Initialize()
if self.initialized then return end
local PT=_G.PatchTools
if not PT or not PT.extensionAPI or PT.extensionAPI<1 then
print("PatchToolsMaps: "..self:T("API")); return
end
if type(PatchToolsMapsDB)~="table" then PatchToolsMapsDB={} end
self.db=PatchToolsMapsDB
for key,value in pairs({movable=true,resizable=true,extendedZoom=true,scale=1,mode="mist"}) do
if type(self.db[key])~=type(value) then self.db[key]=value end
end
if self.db.mode~="classic" and self.db.mode~="mist" and self.db.mode~="full" then self.db.mode="mist" end
local scale=self.db.scale
self.db.scale=scale==scale and scale<math.huge and math.max(.6,scale) or 1
for _,key in ipairs({"x","y"}) do
local value=self.db[key]
if type(value)~="number" or value~=value or math.abs(value)==math.huge then self.db[key]=nil end
end
if not self.db.x or not self.db.y then self.db.x,self.db.y=nil,nil end
if type(self.db.knownOverlays)~="table" then self.db.knownOverlays={} end
for key,value in pairs(self.db.knownOverlays) do
if type(value)~="table" then self.db.knownOverlays[key]=nil end
end
self.initialized=PT:RegisterOptionsPage("maps",self:T("TITLE"),function(parent) self:BuildOptions(parent) end)
if self.initialized then
SLASH_PATCHTOOLSMAPS1="/ptmaps"
SLASH_PATCHTOOLSMAPS2="/patchtoolsmaps"
SlashCmdList.PATCHTOOLSMAPS=function(message)
if (message or ""):lower():match("^%s*status%s*$") then
self:PrintZoomStatus()
elseif (message or ""):lower():match("^%s*reset%s*$") then
self:ResetMap()
PT:Print(self:T(InCombatLockdown and InCombatLockdown() and "RESET_PENDING" or "RESET_DONE"))
else PT:OpenOptions(); PT:SelectOptionsPage("maps") end
end
self:Attach()
end
end
events:SetScript("OnEvent",function(_,event,name)
if event=="ADDON_LOADED" and name==addon then Maps:Initialize()
elseif Maps.initialized then
if event=="PLAYER_REGEN_DISABLED" then
if Maps.resizeGrip then
Maps:FinishResize()
Maps.moveDriver:SetScript("OnUpdate",nil); Maps.moving=nil; Maps.extraZoomScale=nil
end
elseif event=="ADDON_LOADED" then Maps:Attach()
elseif event=="PLAYER_REGEN_ENABLED" or event=="DISPLAY_SIZE_CHANGED" then Maps:Refresh()
elseif event=="MAP_EXPLORATION_UPDATED" then Maps:RefreshReveal() end
end
end)