forked from Nevcairiel/Mapster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBattleMap.lua
141 lines (122 loc) · 3.35 KB
/
BattleMap.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
--[[
Copyright (c) 2009-2016, Hendrik "Nevcairiel" Leppkes < [email protected] >
All rights reserved.
]]
local Mapster = LibStub("AceAddon-3.0"):GetAddon("Mapster")
local L = LibStub("AceLocale-3.0"):GetLocale("Mapster")
local MODNAME = "BattleMap"
local BattleMap = Mapster:NewModule(MODNAME, "AceEvent-3.0")
local FogClear
-- Make sure to get the global before FogClear loads and overwrites it
local GetNumMapOverlays = GetNumMapOverlays
local db
local defaults = {
profile = {
hideTextures = false,
}
}
local optGetter, optSetter
do
local mod = BattleMap
function optGetter(info)
local key = info[#info]
return db[key]
end
function optSetter(info, value)
local key = info[#info]
db[key] = value
mod:Refresh()
end
end
local options
local function getOptions()
if not options then
options = {
type = "group",
name = L["BattleMap"],
arg = MODNAME,
get = optGetter,
set = optSetter,
args = {
intro = {
order = 1,
type = "description",
name = L["The BattleMap module allows you to change the style of the BattlefieldMinimap, removing unnecessary textures or PvP Objectives."],
},
enabled = {
order = 2,
type = "toggle",
name = L["Enable BattleMap"],
get = function() return Mapster:GetModuleEnabled(MODNAME) end,
set = function(info, value) Mapster:SetModuleEnabled(MODNAME, value) end,
},
texturesdesc = {
order = 3,
type = "description",
name = "\n" .. L["Hide the surrounding textures around the BattleMap, only leaving you with the pure map overlays."],
},
hideTextures = {
order = 4,
type = "toggle",
name = L["Hide Textures"],
},
},
}
end
return options
end
function BattleMap:OnInitialize()
self.db = Mapster.db:RegisterNamespace(MODNAME, defaults)
db = self.db.profile
self:SetEnabledState(Mapster:GetModuleEnabled(MODNAME))
Mapster:RegisterModuleOptions(MODNAME, getOptions, L["BattleMap"])
FogClear = Mapster:GetModule("FogClear", true)
end
function BattleMap:OnEnable()
if not C_AddOns.IsAddOnLoaded("Blizzard_BattlefieldMinimap") then
self:RegisterEvent("ADDON_LOADED", function(event, addon)
if addon == "Blizzard_BattlefieldMinimap" then
BattleMap:UnregisterEvent("ADDON_LOADED")
BattleMap:SetupMap()
end
end)
else
self:SetupMap()
end
end
function BattleMap:OnDisable()
if BattlefieldMinimap then
BattlefieldMinimapCorner:Show()
BattlefieldMinimapBackground:Show()
BattlefieldMinimapCloseButton:Show()
BattlefieldMinimapTab:Show()
end
self:UpdateTextureVisibility()
end
function BattleMap:SetupMap()
BattlefieldMinimapCorner:Hide()
BattlefieldMinimapBackground:Hide()
BattlefieldMinimapCloseButton:Hide()
BattlefieldMinimapTab:Hide()
self:RegisterEvent("WORLD_MAP_UPDATE", "UpdateTextureVisibility")
self:UpdateTextureVisibility()
end
function BattleMap:Refresh()
db = self.db.profile
if not self:IsEnabled() then return end
self:UpdateTextureVisibility()
end
function BattleMap:UpdateTextureVisibility()
if not BattlefieldMinimap then return end
local hasOverlays
if FogClear and FogClear:IsEnabled() then hasOverlays = FogClear:RealHasOverlays() else hasOverlays = GetNumMapOverlays() > 0 end
if hasOverlays and db.hideTextures and self:IsEnabled() then
for i=1,12 do
_G["BattlefieldMinimap"..i]:Hide()
end
else
for i=1,12 do
_G["BattlefieldMinimap"..i]:Show()
end
end
end