forked from Nevcairiel/Mapster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMapster.lua
322 lines (272 loc) · 8.19 KB
/
Mapster.lua
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
--[[
Copyright (c) 2009-2018, Hendrik "Nevcairiel" Leppkes < [email protected] >
All rights reserved.
]]
local Mapster = LibStub("AceAddon-3.0"):NewAddon("Mapster", "AceEvent-3.0", "AceHook-3.0")
local LibWindow = LibStub("LibWindow-1.1")
local L = LibStub("AceLocale-3.0"):GetLocale("Mapster")
local defaults = {
profile = {
hideMapButton = false,
arrowScale = 0.9,
modules = {
['*'] = true,
},
scale = 1,
poiScale = 0.9,
ejScale = 0.8,
alpha = 1,
fadealpha = 0.5,
disableMouse = false,
-- position defaults for LibWindow
x = 40,
y = 140,
point = "LEFT",
}
}
local WorldMapFrameStartMoving, WorldMapFrameStopMoving
local WorldMapUnitPin, WorldMapUnitPinSizes
local db
function Mapster:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("MapsterDB", defaults, true)
db = self.db.profile
self.db.RegisterCallback(self, "OnProfileChanged", "Refresh")
self.db.RegisterCallback(self, "OnProfileCopied", "Refresh")
self.db.RegisterCallback(self, "OnProfileReset", "Refresh")
self.elementsToHide = {}
self.UIHider = CreateFrame("Frame")
self.UIHider:Hide()
self:SetupOptions()
end
local function purgeKey(t, k)
t[k] = nil
local c = 42
repeat
if t[c] == nil then
t[c] = nil
end
c = c + 1
until issecurevariable(t, k)
end
local function FaderOnUpdate(frame, elapsed)
Mapster:WorldMapFrameOnUpdate(elapsed)
end
local FaderFrame = CreateFrame("Frame", nil, WorldMapFrame)
FaderFrame:Hide()
FaderFrame:SetScript("OnUpdate", FaderOnUpdate)
function Mapster:OnEnable()
LibWindow.RegisterConfig(WorldMapFrame, db)
-- remove from UI panel system
purgeKey(UIPanelWindows, "WorldMapFrame")
WorldMapFrame:SetAttribute("UIPanelLayout-area", nil)
WorldMapFrame:SetAttribute("UIPanelLayout-enabled", false)
-- make the map movable
WorldMapFrame:SetMovable(true)
WorldMapFrame:RegisterForDrag("LeftButton")
WorldMapFrame:SetScript("OnDragStart", WorldMapFrameStartMoving)
WorldMapFrame:SetScript("OnDragStop", WorldMapFrameStopMoving)
-- map transition
if WorldMapFrame.SynchronizeDisplayState then
self:SecureHook(WorldMapFrame, "SynchronizeDisplayState", "WorldMapFrame_SynchronizeDisplayState")
end
-- hook Show events for fading
self:SecureHookScript(WorldMapFrame, "OnShow", "WorldMapFrame_OnShow")
-- hooks for scale
if HelpPlate_Show then
self:SecureHook("HelpPlate_Show")
self:SecureHook("HelpPlate_Hide")
self:SecureHook("HelpPlate_Button_AnimGroup_Show_OnFinished")
end
-- hook into EJ icons
self:SecureHook(EncounterJournalPinMixin, "OnAcquired", "EncounterJournalPin_OnAcquired")
for pin in WorldMapFrame:EnumeratePinsByTemplate("EncounterJournalPinTemplate") do
pin.OnAcquired = EncounterJournalPinMixin.OnAcquired
end
-- hook into Quest POI icons
self:SecureHook(BonusObjectivePinMixin, "OnAcquired", "QuestPOI_OnAcquired")
self:SecureHook(QuestPinMixin, "OnAcquired", "QuestPOI_OnAcquired")
self:SecureHook(WorldMap_WorldQuestPinMixin, "OnAcquired", "QuestPOI_OnAcquired")
for pin in WorldMapFrame:EnumeratePinsByTemplate("BonusObjectivePinTemplate") do
pin.OnAcquired = BonusObjectivePinMixin.OnAcquired
end
for pin in WorldMapFrame:EnumeratePinsByTemplate("QuestPinTemplate") do
pin.OnAcquired = QuestPinMixin.OnAcquired
end
for pin in WorldMapFrame:EnumeratePinsByTemplate("WorldMap_WorldQuestPinTemplate") do
pin.OnAcquired = WorldMap_WorldQuestPinMixin.OnAcquired
end
-- hook into unit provider
for pin in WorldMapFrame:EnumeratePinsByTemplate("GroupMembersPinTemplate") do
WorldMapUnitPin = pin
WorldMapUnitPinSizes = pin.dataProvider:GetUnitPinSizesTable()
break
end
self:SecureHook("ShowUIPanel", "ShowUIPanelHook")
-- close the map on escape
table.insert(UISpecialFrames, "WorldMapFrame")
-- load settings
--self:SetAlpha()
self:SetFadeAlpha()
self:SetArrow()
self:SetEJScale()
self:SetPOIScale()
self:SetScale()
self:SetPosition()
if not db.hideMapButton then
self:SetupMapButton()
end
end
function Mapster:Refresh()
db = self.db.profile
for k,v in self:IterateModules() do
if self:GetModuleEnabled(k) and not v:IsEnabled() then
self:EnableModule(k)
elseif not self:GetModuleEnabled(k) and v:IsEnabled() then
self:DisableModule(k)
end
if type(v.Refresh) == "function" then
v:Refresh()
end
end
-- apply new settings
--self:SetAlpha()
self:SetFadeAlpha()
self:SetArrow()
self:SetEJScale()
self:SetPOIScale()
self:SetScale()
self:SetPosition()
if db.hideMapButton then
if self.optionsButton then
self.optionsButton:Hide()
end
else
if not self.optionsButton then
self:SetupMapButton()
end
self.optionsButton:Show()
end
end
function Mapster:SetFadeAlpha()
if GetCVarBool("mapFade") then
FaderFrame:Show()
else
FaderFrame:Hide()
end
end
function Mapster:WorldMapFrameOnUpdate(elapsed)
local fadeOut = IsPlayerMoving() and (GetCVarBool("mapFade") and not WorldMapFrame:IsMouseOver())
local alpha = DeltaLerp(WorldMapFrame:GetAlpha(), fadeOut and db.fadealpha or 1.0, 0.2, elapsed)
if alpha >= 0.98 then alpha = 1.0 end
WorldMapFrame:SetAlpha(alpha)
end
function WorldMapFrameStartMoving(frame)
if not WorldMapFrame:IsMaximized() then
WorldMapFrame:StartMoving()
end
end
function WorldMapFrameStopMoving(frame)
WorldMapFrame:StopMovingOrSizing()
if not WorldMapFrame:IsMaximized() then
LibWindow.SavePosition(WorldMapFrame)
end
end
function Mapster:SetPosition()
if not WorldMapFrame:IsMaximized() then
LibWindow.RestorePosition(WorldMapFrame)
end
end
function Mapster:WorldMapFrame_OnShow()
PlayerMovementFrameFader.RemoveFrame(WorldMapFrame)
end
function Mapster:SetScale(force)
if WorldMapFrame:IsMaximized() and WorldMapFrame:GetScale() ~= 1 then
WorldMapFrame:SetScale(1)
elseif not WorldMapFrame:IsMaximized() and (WorldMapFrame:GetScale() ~= db.scale or force) then
WorldMapFrame:SetScale(db.scale)
end
end
function Mapster:WorldMapFrame_ScrollContainer_GetCursorPosition()
-- intentionally not calling the original function to avoid double-hooks with addons trying to fix the same thing
local x,y = GetCursorPosition()
local s = WorldMapFrame:GetEffectiveScale()
return x / s, y / s
end
function Mapster:WorldMapFrame_SynchronizeDisplayState()
self:SetScale()
if not WorldMapFrame:IsMaximized() then
self:SetPosition()
end
end
function Mapster:HelpPlate_Show(plate, frame)
if frame == WorldMapFrame then
HelpPlate:SetScale(db.scale)
HelpPlate.__Mapster = true
end
end
function Mapster:HelpPlate_Hide(userToggled)
if HelpPlate.__Mapster and not userToggled then
HelpPlate:SetScale(1.0)
HelpPlate.__Mapster = nil
end
end
function Mapster:HelpPlate_Button_AnimGroup_Show_OnFinished()
if HelpPlate.__Mapster then
HelpPlate:SetScale(1.0)
HelpPlate.__Mapster = nil
end
end
function Mapster:EncounterJournalPin_OnAcquired(pin)
pin:SetSize(50 * db.ejScale, 49 * db.ejScale)
pin.Background:SetScale(db.ejScale)
pin.DefeatedOverlay:SetScale(db.ejScale)
end
function Mapster:SetEJScale()
for pin in WorldMapFrame:EnumeratePinsByTemplate("EncounterJournalPinTemplate") do
self:EncounterJournalPin_OnAcquired(pin)
end
end
function Mapster:QuestPOI_OnAcquired(pin)
pin:SetSize(50 * db.poiScale, 50 * db.poiScale)
pin.Display:SetScale(db.poiScale)
pin.NormalTexture:SetScale(db.poiScale)
pin.PushedTexture:SetScale(db.poiScale)
pin.HighlightTexture:SetScale(db.poiScale)
end
function Mapster:SetPOIScale()
for pin in WorldMapFrame:EnumeratePinsByTemplate("BonusObjectivePinTemplate") do
self:QuestPOI_OnAcquired(pin)
end
for pin in WorldMapFrame:EnumeratePinsByTemplate("QuestPinTemplate") do
self:QuestPOI_OnAcquired(pin)
end
for pin in WorldMapFrame:EnumeratePinsByTemplate("WorldMap_WorldQuestPinTemplate") do
self:QuestPOI_OnAcquired(pin)
end
end
function Mapster:ShowUIPanelHook(frame)
if frame == WorldMapFrame and InCombatLockdown() and not frame:IsShown() then
frame:Show()
end
end
function Mapster:SetArrow()
if not WorldMapUnitPin or not WorldMapUnitPinSizes then
return
end
WorldMapUnitPinSizes.player = 27 * db.arrowScale
WorldMapUnitPin:SynchronizePinSizes()
end
function Mapster:GetModuleEnabled(module)
return db.modules[module]
end
function Mapster:SetModuleEnabled(module, value)
local old = db.modules[module]
db.modules[module] = value
if old ~= value then
if value then
self:EnableModule(module)
else
self:DisableModule(module)
end
end
end