Repository navigation
Expand file tree
/
Copy pathCore.lua
More file actions
135 lines (135 loc) · 6.93 KB
/
Copy pathCore.lua
File metadata and controls
135 lines (135 loc) · 6.93 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
local addon, Maps = ...
local events=CreateFrame("Frame")
for _,event in ipairs({"ADDON_LOADED","PLAYER_LOGIN","PLAYER_REGEN_ENABLED","PLAYER_REGEN_DISABLED","MAP_EXPLORATION_UPDATED","DISPLAY_SIZE_CHANGED","CVAR_UPDATE"}) 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.customFrame and not (InCombatLockdown and InCombatLockdown()) then self:DiscoverFrameWidgets() end
if InCombatLockdown and InCombatLockdown() then self:RestoreCombatWindow() end
if self.resetPending then self:ResetWindow() else self:ApplyWindow() end
if InCombatLockdown and InCombatLockdown() then self:RestoreCombatWindow(); self:RestoreCombatFrame() end
self:ApplyMapOpacity()
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 not (InCombatLockdown and InCombatLockdown()) 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:InstallCustomFrame(self.map)
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 self.customFrame and type(self.map.OnMapChanged)=="function" then
hooksecurefunc(self.map,"OnMapChanged",function()
C_Timer.After(0,function()
if self:UseCustomFrame() and self.map:IsShown() then self:Refresh() end
end)
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
if type(PatchToolsMapsCharacterDB)~="table" then
PatchToolsMapsCharacterDB={scale=self.db.scale,x=self.db.x,y=self.db.y}
end
self.windowDB=PatchToolsMapsCharacterDB
if type(self.windowDB.scale)~="number" then self.windowDB.scale=1 end
for key,value in pairs({movable=true,resizable=true,extendedZoom=true,mode="mist"}) do
if type(self.db[key])~=type(value) then self.db[key]=value end
end
if type(self.db.customFrame)~="boolean" then self.db.customFrame=PT.isClassicEra==true 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.windowDB.scale
self.windowDB.scale=scale==scale and scale<math.huge and math.max(.6,scale) or 1
for _,key in ipairs({"x","y"}) do
local value=self.windowDB[key]
if type(value)~="number" or value~=value or math.abs(value)==math.huge then self.windowDB[key]=nil end
end
if not self.windowDB.x or not self.windowDB.y then self.windowDB.x,self.windowDB.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*debug%s*$") then
if PT.OpenDebugReport then PT:OpenDebugReport()
else PT:Print(PT.locale=="deDE" and "Für den Diagnosebericht bitte PatchTools aktualisieren." or "Update PatchTools to use the diagnostic report.") end
elseif (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 and not Maps:CanChangeWindow() then
Maps:FinishResize()
Maps.moveDriver:SetScript("OnUpdate",nil); Maps.moving=nil; Maps.extraZoomScale=nil
end
elseif event=="ADDON_LOADED" or event=="PLAYER_LOGIN" then
Maps:Attach()
if Maps.customFrame and not (InCombatLockdown and InCombatLockdown()) then
Maps:DiscoverFrameWidgets(); Maps:LayoutCustomFrame()
if event=="PLAYER_LOGIN" then Maps:ApplyWindow() end
end
elseif event=="CVAR_UPDATE" then
if type(name)=="string" and name:lower():gsub("_","")=="worldmapopacity" then
Maps:ApplyMapOpacity(); Maps:UpdateOptions(); Maps:UpdateOpacityPopup()
end
elseif event=="PLAYER_REGEN_ENABLED" or event=="DISPLAY_SIZE_CHANGED" then Maps:Refresh()
elseif event=="MAP_EXPLORATION_UPDATED" then Maps:RefreshReveal() end
end
end)