-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
SexyMap_Vanilla.lua
603 lines (559 loc) · 16.3 KB
/
SexyMap_Vanilla.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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
local name, sm = ...
sm.core = {}
local mod = sm.core
local L = sm.L
sm.backdrop = {
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
insets = {left = 4, top = 4, right = 4, bottom = 4}, -- Change the Clock/Coords/ZoneText clamp if this is changed
edgeSize = 16,
tile = true,
}
mod.frame = CreateFrame("Frame")
mod.button = CreateFrame("Button")
mod.font = mod.button:CreateFontString()
mod.texture = mod.button:CreateTexture()
mod.frame:Hide()
mod.button:Hide()
mod.deepCopyHash = function(t)
local nt = {}
for k, v in pairs(t) do
if type(v) == "table" then
nt[k] = mod.deepCopyHash(v)
else
nt[k] = v
end
end
return nt
end
mod.frame:SetScript("OnEvent", function(_, event, ...)
mod[event](sm, ...)
end)
mod.options = {
type = "group",
name = name,
args = {
lock = {
order = 1,
name = L["Lock Minimap"],
type = "toggle",
get = function()
return mod.db.lock
end,
set = function(info, v)
mod.db.lock = v
Minimap:SetMovable(not mod.db.lock)
end,
},
clamp = {
order = 2,
type = "toggle",
name = L["Clamp to screen"],
desc = L["Prevent the minimap from being moved off the screen"],
get = function()
return mod.db.clamp
end,
set = function(info, v)
mod.db.clamp = v
Minimap:SetClampedToScreen(v)
end,
},
rotate = {
order = 3,
type = "toggle",
name = ROTATE_MINIMAP,
desc = OPTION_TOOLTIP_ROTATE_MINIMAP,
get = function()
return mod.db.rotate
end,
set = function(_, value)
if value then
mod.db.rotate = true
C_CVar.SetCVar("rotateMinimap", 1)
else
mod.db.rotate = nil
C_CVar.SetCVar("rotateMinimap", 0)
end
end,
},
rightClickToConfig = {
order = 4,
type = "toggle",
name = L["Right Click Configure"],
desc = L["Right clicking the map will open the SexyMap options"],
get = function()
return mod.db.rightClickToConfig
end,
set = function(info, v)
mod.db.rightClickToConfig = v
end,
},
scale = {
order = 5,
type = "range",
name = L["Scale"],
min = 0.2,
max = 3.0,
step = 0.01,
bigStep = 0.01,
width = 2,
get = function(info)
return mod.db.scale or 1
end,
set = function(info, v)
mod.db.scale = v
Minimap:SetScale(v)
end,
},
northTag = {
order = 6,
type = "toggle",
name = L["Show North Tag"],
get = function()
return mod.db.northTag
end,
set = function(info, v)
if not MinimapNorthTag then return end
if v then
MinimapNorthTag.Show = MinimapNorthTag.oldShow
MinimapNorthTag.oldShow = nil
MinimapCompassTexture.Show = MinimapCompassTexture.oldShow
MinimapCompassTexture.oldShow = nil
if C_CVar.GetCVarBool("rotateMinimap") then
MinimapCompassTexture:Show()
else
MinimapNorthTag:Show()
end
else
MinimapNorthTag:Hide()
MinimapNorthTag.oldShow = MinimapNorthTag.Show
MinimapNorthTag.Show = MinimapNorthTag.Hide
MinimapCompassTexture:Hide()
MinimapCompassTexture.oldShow = MinimapCompassTexture.Show
MinimapCompassTexture.Show = MinimapCompassTexture.Hide
end
mod.db.northTag = v
end,
hidden = not MinimapNorthTag,
},
zoom = {
order = 7,
type = "range",
name = L["Auto Zoom-Out Delay"],
desc = L["If you zoom into the map, this feature will automatically zoom out after the selected period of time (seconds). Using a value of 0 will disable Auto Zoom-Out."],
width = 2,
min = 0,
max = 30,
step = 1,
bigStep = 1,
get = function()
return mod.db.autoZoom
end,
set = function(info, v)
mod.db.autoZoom = v
end,
},
spacer1 = {
order = 8,
type = "description",
width = "full",
name = "\n\n",
},
presetHeader = {
order = 9,
type = "header",
name = L["Preset"],
},
spacer2 = {
order = 10,
type = "description",
width = "full",
name = L["Quickly change the look of your minimap by using a minimap preset."].."\n",
},
spacer3 = {
order = 12,
type = "description",
width = 0.5,
name = "",
},
spacer4 = {
order = 14,
type = "description",
width = "full",
name = "\n",
},
profilesHeader = {
order = 15,
type = "header",
name = L["Profiles"],
},
spacer5 = {
order = 16,
type = "description",
width = "full",
name = L["Use the global profile if you want the same look on every character, or use a character-specific profile for a unique look on each character."].."\n",
},
globalProf = {
order = 17,
type = "toggle",
name = L["Use Global Profile"],
width = "full",
confirm = function(info, v)
if v and SexyMap2DB.global then
return L["A global profile already exists. You will be switched over to it and your UI will be reloaded, are you sure?"]
elseif v and not SexyMap2DB.global then
return L["No global profile exists. Your current profile will be copied over and used as the global profile, are you sure? This will also reload your UI."]
elseif not v then
return L["Are you sure you want to switch back to using a character specific profile? This will reload your UI."]
end
end,
get = function()
local char = (UnitName("player").."-"..GetRealmName())
return type(SexyMap2DB[char]) == "string"
end,
set = function(info, v)
local char = (UnitName("player").."-"..GetRealmName())
if v then
if not SexyMap2DB.global then
SexyMap2DB.global = mod.deepCopyHash(SexyMap2DB[char])
end
SexyMap2DB[char] = "global"
ReloadUI()
else
SexyMap2DB[char] = nil
ReloadUI()
end
end,
},
copy = {
type = "select",
name = L["Copy a Profile"],
order = 18,
confirm = true,
confirmText = L["Copying this profile will reload your UI, are you sure?"],
values = function()
local tbl = {}
for k,v in pairs(SexyMap2DB) do
if k ~= "presets" and k ~= "global" and k ~= (UnitName("player").."-"..GetRealmName()) and type(v) == "table" then
tbl[k]=k
end
end
return tbl
end,
set = function(info, v)
local char = (UnitName("player").."-"..GetRealmName())
SexyMap2DB[char] = mod.deepCopyHash(SexyMap2DB[v])
ReloadUI()
end,
disabled = function()
local char = (UnitName("player").."-"..GetRealmName())
if type(SexyMap2DB[char]) == "string" then
return true
end
for k,v in pairs(SexyMap2DB) do
if k ~= "presets" and k ~= "global" and k ~= char and type(v) == "table" then
return false
end
end
return true
end,
},
delete = {
type = "select",
name = L["Delete a Profile"],
order = 19,
confirm = true,
confirmText = L["Really delete this profile?"],
values = function()
local tbl = {}
for k,v in pairs(SexyMap2DB) do
if k ~= "presets" and k ~= "global" and k ~= (UnitName("player").."-"..GetRealmName()) and type(v) == "table" then
tbl[k]=k
end
end
return tbl
end,
set = function(info, v)
SexyMap2DB[v] = nil
end,
disabled = function()
local char = (UnitName("player").."-"..GetRealmName())
if type(SexyMap2DB[char]) == "string" then
return true
end
for k,v in pairs(SexyMap2DB) do
if k ~= "presets" and k ~= "global" and k ~= char and type(v) == "table" then
return false
end
end
return true
end,
},
reset = {
type = "execute",
name = L["Reset Current Profile"],
confirm = true,
confirmText = L["Resetting this profile will reload your UI, are you sure?"],
order = 20,
func = function()
local char = UnitName("player").."-"..GetRealmName()
SexyMap2DB[char] = nil
ReloadUI()
end,
disabled = function()
local char = (UnitName("player").."-"..GetRealmName())
if type(SexyMap2DB[char]) == "string" then
return true
end
end,
},
}
}
function mod:ADDON_LOADED(addon)
if addon == "SexyMap" then
mod.frame:UnregisterEvent("ADDON_LOADED")
if type(SexyMap2DB) ~= "table" then
SexyMap2DB = {}
end
-- XXX 9.0.1
for character, tbl in next, SexyMap2DB do
if tbl.borders and tbl.borders.backdrop and tbl.borders.backdrop.settings then
local tex = tbl.borders.backdrop.settings.bgFile
if type(tex) == "string" then
if tex == "Interface\\Addons\\SexyMap\\media\\rusticbg" then
tbl.borders.backdrop.settings.bgFile = 249644
elseif tex == "Interface\\Addons\\SexyMap\\media\\ruinsbg" then
tbl.borders.backdrop.settings.bgFile = 191258
end
end
end
end
if SexyMap2DB.presets then
for name, tbl in next, SexyMap2DB.presets do
if tbl.backdrop and tbl.backdrop.settings then
local tex = tbl.backdrop.settings.bgFile
if type(tex) == "string" then
if tex == "Interface\\Addons\\SexyMap\\media\\rusticbg" then
tbl.backdrop.settings.bgFile = 249644
elseif tex == "Interface\\Addons\\SexyMap\\media\\ruinsbg" then
tbl.backdrop.settings.bgFile = 191258
end
end
end
end
end
-- XXX end
-- XXX temp 1.14.2
for character, tbl in next, SexyMap2DB do
if tbl.borders and type(tbl.borders.borders) == "table" then
for i = 1, #tbl.borders.borders do
if tbl.borders.borders[i].texture == "INTERFACE\\ADDONS\\SEXYMAP\\MEDIA\\T_VFX_HERO_CIRCLE.BLP" or tbl.borders.borders[i].texture == "SPELLS\\T_VFX_HERO_CIRCLE.BLP" then
tbl.borders.borders[i].texture = 167062
end
end
end
end
-- End
local char = UnitName("player").."-"..GetRealmName()
if not SexyMap2DB[char] then
SexyMap2DB[char] = {}
end
local dbToDispatch
if type(SexyMap2DB[char]) == "string" then
if not SexyMap2DB.global then
SexyMap2DB.global = {}
end
dbToDispatch = SexyMap2DB.global
else
dbToDispatch = SexyMap2DB[char]
end
if not dbToDispatch.core then
dbToDispatch.core = {
lock = false,
clamp = true,
rightClickToConfig = true,
autoZoom = 5,
northTag = true,
shape = "Interface\\AddOns\\SexyMap\\shapes\\circle.tga",
}
end
mod.db = dbToDispatch.core
mod.loadModules = {}
for k,v in pairs(sm) do
if v.OnInitialize then
v:OnInitialize(dbToDispatch)
v.OnInitialize = nil
tinsert(mod.loadModules, k)
end
end
mod.ADDON_LOADED = nil
end
end
mod.frame:RegisterEvent("ADDON_LOADED")
function mod:PLAYER_LOGIN()
mod.frame:UnregisterEvent("PLAYER_LOGIN")
-- Setup config
LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable(name, mod.options, true)
local _, categoryID = LibStub("AceConfigDialog-3.0"):AddToBlizOptions(name)
-- Configure slash handler
SlashCmdList.SexyMap = function()
Settings.OpenToCategory(categoryID)
end
SLASH_SexyMap1 = "/minimap"
SLASH_SexyMap2 = "/sexymap"
Minimap:SetScript("OnMouseUp", function(frame, button)
if button == "RightButton" and mod.db.rightClickToConfig then
SlashCmdList.SexyMap()
else
Minimap_OnClick(frame, button)
end
end)
mod:SetupMap()
-- Load the modules in alphabetical order
table.sort(mod.loadModules)
for i=1, #mod.loadModules do
sm[mod.loadModules[i]]:OnEnable()
sm[mod.loadModules[i]].OnEnable = nil
end
mod.PLAYER_LOGIN = nil
end
mod.frame:RegisterEvent("PLAYER_LOGIN")
-- Hopefully temporary workaround for string size functions returning 0 for foreign fonts at PLAYER_LOGIN on a cold boot
function mod:LOADING_SCREEN_DISABLED()
mod.frame:UnregisterEvent("LOADING_SCREEN_DISABLED")
if not mod.PLAYER_LOGIN then -- Only if PLAYER_LOGIN has fired before LOADING_SCREEN_DISABLED
for i=1, #mod.loadModules do
local module = sm[mod.loadModules[i]]
if module and module.OnLoadingScreenOver then
sm[mod.loadModules[i]]:OnLoadingScreenOver()
sm[mod.loadModules[i]].OnLoadingScreenOver = nil
end
end
mod.loadModules = nil
end
mod.LOADING_SCREEN_DISABLED = nil
end
mod.frame:RegisterEvent("LOADING_SCREEN_DISABLED")
if mod.frame.GetFrameStrata(Minimap) ~= "LOW" then
mod.frame.SetFrameStrata(Minimap, "LOW") -- Blizz Defaults patch 9.0.1 Minimap.xml
end
if mod.frame.GetFrameLevel(Minimap) ~= 2 then
mod.frame.SetFrameLevel(Minimap, 2) -- Blizz Defaults patch 9.0.1 Minimap.xml
end
-- Prevent the damage caused by automagic fuckery when a frame changes parent by locking the strata/level in place
mod.frame.SetFixedFrameStrata(Minimap, true)
mod.frame.SetFixedFrameLevel(Minimap, true)
mod.frame.SetParent(Minimap, UIParent)
-- Prevent some addons doing dumb things that breaks SexyMap. #175
hooksecurefunc(Minimap, "SetParent", function()
mod.frame.SetParent(Minimap, UIParent)
end)
-- Make sure the various minimap buttons follow the minimap
-- We do this before login to prevent button placement issues
MinimapBackdrop:ClearAllPoints()
MinimapBackdrop:SetPoint("CENTER", Minimap, "CENTER", -8, -23)
function mod:SetupMap()
local Minimap = Minimap
-- Hide the Minimap during a pet battle
mod.frame:RegisterEvent("PET_BATTLE_OPENING_START")
mod.PET_BATTLE_OPENING_START = function()
Minimap:Hide()
end
mod.frame:RegisterEvent("PET_BATTLE_CLOSE")
mod.PET_BATTLE_CLOSE = function()
Minimap:Show()
end
-- Hide the Minimap during combat. Remove the comments (--) to enable.
--mod.frame:RegisterEvent("PLAYER_REGEN_DISABLED")
--mod.PLAYER_REGEN_DISABLED = function()
-- Minimap:Hide()
--end
--mod.frame:RegisterEvent("PLAYER_REGEN_ENABLED")
--mod.PLAYER_REGEN_ENABLED = function()
-- Minimap:Show()
--end
-- This is our method of cancelling timers, we only let the very last scheduled timer actually run the code.
-- We do this by using a simple counter, which saves us using the more expensive C_Timer.NewTimer API.
local started, current = 0, 0
--[[ Auto Zoom Out ]]--
local zoomOut = function()
current = current + 1
if started == current then
for i = 1, Minimap:GetZoom() or 0 do
Minimap_ZoomOutClick() -- Call it directly so we don't run our own hook
end
started, current = 0, 0
end
end
local zoomBtnFunc = function()
if mod.db.autoZoom > 0 then
started = started + 1
C_Timer.After(mod.db.autoZoom, zoomOut)
end
end
zoomBtnFunc()
MinimapZoomIn:HookScript("OnClick", zoomBtnFunc)
MinimapZoomOut:HookScript("OnClick", zoomBtnFunc)
--[[ MouseWheel Zoom ]]--
Minimap:EnableMouseWheel(true)
Minimap:SetScript("OnMouseWheel", function(frame, d)
if d > 0 then
MinimapZoomIn:Click()
elseif d < 0 then
MinimapZoomOut:Click()
end
end)
MinimapCluster:EnableMouse(false) -- Don't leave an invisible dead zone
-- Removes the circular "waffle-like" texture that shows when using a non-circular minimap in the blue quest objective area.
--Minimap:SetArchBlobRingScalar(0)
--Minimap:SetArchBlobRingAlpha(0)
--Minimap:SetQuestBlobRingScalar(0)
--Minimap:SetQuestBlobRingAlpha(0)
if not mod.db.northTag then
MinimapNorthTag:Hide()
MinimapNorthTag.oldShow = MinimapNorthTag.Show
MinimapNorthTag.Show = MinimapNorthTag.Hide
MinimapCompassTexture:Hide()
MinimapCompassTexture.oldShow = MinimapCompassTexture.Show
MinimapCompassTexture.Show = MinimapCompassTexture.Hide
end
-- Minimap "X" to close button
local MinimapToggleButton = MinimapToggleButton
sm.core.button.SetParent(MinimapToggleButton, sm.core.button)
hooksecurefunc(MinimapToggleButton, "SetParent", function()
sm.core.button.SetParent(MinimapToggleButton, sm.core.button)
end)
-- Border texture around the zone text and the "X" to close button
local MinimapBorderTop = MinimapBorderTop
sm.core.texture.SetParent(MinimapBorderTop, sm.core.button)
hooksecurefunc(MinimapBorderTop, "SetParent", function()
sm.core.texture.SetParent(MinimapBorderTop, sm.core.button)
end)
Minimap:RegisterForDrag("LeftButton")
Minimap:SetClampedToScreen(mod.db.clamp)
Minimap:SetScale(mod.db.scale or 1)
Minimap:SetMovable(not mod.db.lock)
if mod.db.rotate then
C_CVar.SetCVar("rotateMinimap", 1)
end
--hooksecurefunc(MinimapCluster, "SetRotateMinimap", function()
-- if mod.db.rotate then
-- C_CVar.SetCVar("rotateMinimap", 1)
-- end
--end)
Minimap:SetScript("OnDragStart", function(self) if self:IsMovable() then self:StartMoving() end end)
Minimap:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
local p, _, rp, x, y = Minimap:GetPoint()
mod.db.point, mod.db.relpoint, mod.db.x, mod.db.y = p, rp, x, y
end)
if mod.db.point then
Minimap:ClearAllPoints()
Minimap:SetPoint(mod.db.point, UIParent, mod.db.relpoint, mod.db.x, mod.db.y)
end
self.SetupMap = nil
end
function mod:RegisterModuleOptions(modName, optionTbl, displayName)
LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable(name..modName, optionTbl, true)
LibStub("AceConfigDialog-3.0"):AddToBlizOptions(name..modName, displayName, name)
end