-
Notifications
You must be signed in to change notification settings - Fork 2
/
FogClear.lua
193 lines (167 loc) · 5.79 KB
/
FogClear.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
--[[
Copyright (c) 2009-2018, 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 = "FogClear"
local FogClear = Mapster:NewModule(MODNAME, "AceHook-3.0", "AceEvent-3.0")
local mod, floor, ceil, tonumber = math.fmod, math.floor, math.ceil, tonumber
local ipairs, pairs = ipairs, pairs
local db
local defaults = {
profile = {
colorR = 1,
colorG = 1,
colorB = 1,
colorA = 1,
},
}
local options
local function getOptions()
if not options then
options = {
type = "group",
name = L["FogClear"],
arg = MODNAME,
args = {
intro = {
order = 1,
type = "description",
name = L["The FogClear module removes the Fog of War from the World map, thus displaying the artwork for all the undiscovered zones, optionally with a color overlay on undiscovered areas."] .. "\n",
},
enabled = {
order = 2,
type = "toggle",
name = L["Enable FogClear"],
get = function() return Mapster:GetModuleEnabled(MODNAME) end,
set = function(info, value) Mapster:SetModuleEnabled(MODNAME, value) end,
},
color = {
order = 3,
type = "color",
name = L["Overlay Color"],
get = "GetOverlayColor",
set = "SetOverlayColor",
handler = FogClear,
hasAlpha = true,
},
}
}
end
return options
end
function FogClear:OnInitialize()
self.db = Mapster.db:RegisterNamespace(MODNAME, defaults)
db = self.db.profile
self.db.global.errata = nil
self:SetEnabledState(Mapster:GetModuleEnabled(MODNAME))
Mapster:RegisterModuleOptions(MODNAME, getOptions, L["FogClear"])
end
function FogClear:OnEnable()
for pin in WorldMapFrame:EnumeratePinsByTemplate("MapExplorationPinTemplate") do
self:SecureHook(pin, "RefreshOverlays", "MapExplorationPin_RefreshOverlays")
end
end
function FogClear:OnDisable()
self:UnhookAll()
end
function FogClear:Refresh()
db = self.db.profile
if not self:IsEnabled() then return end
for pin in WorldMapFrame:EnumeratePinsByTemplate("MapExplorationPinTemplate") do
pin:RefreshOverlays(true)
end
end
local FogData = MapsterFogClearData or {}
function FogClear:MapExplorationPin_RefreshOverlays(pin, fullUpdate)
-- remove color tint from active overlays
for overlay in pin.overlayTexturePool:EnumerateActive() do
overlay:SetVertexColor(1,1,1)
overlay:SetAlpha(1)
end
local mapCanvas = pin:GetMap()
local mapID = mapCanvas:GetMapID()
if not mapID then return end
local artID = C_Map.GetMapArtID(mapID)
if not artID or not FogData[artID] then return end
local data = FogData[artID]
local exploredTilesKeyed = {}
local exploredMapTextures = C_MapExplorationInfo.GetExploredMapTextures(mapID)
if exploredMapTextures then
for _i, exploredTextureInfo in ipairs(exploredMapTextures) do
local key = exploredTextureInfo.textureWidth * 2^39 + exploredTextureInfo.textureHeight * 2^26 + exploredTextureInfo.offsetX * 2^13 + exploredTextureInfo.offsetY
exploredTilesKeyed[key] = true
end
end
pin.layerIndex = mapCanvas:GetCanvasContainer():GetCurrentLayerIndex()
local layers = C_Map.GetMapArtLayers(mapID)
local layerInfo = layers and layers[pin.layerIndex]
if not layerInfo then return end
local TILE_SIZE_WIDTH = layerInfo.tileWidth
local TILE_SIZE_HEIGHT = layerInfo.tileHeight
local r, g, b, a = self:GetOverlayColor()
local drawLayer, subLevel = pin.dataProvider:GetDrawLayer()
for key, files in pairs(data) do
if not exploredTilesKeyed[key] then
local width, height, offsetX, offsetY = mod(floor(key / 2^39), 2^13), mod(floor(key / 2^26), 2^13), mod(floor(key / 2^13), 2^13), mod(key, 2^13)
local fileDataIDs = { strsplit(",", files) }
local numTexturesWide = ceil(width/TILE_SIZE_WIDTH)
local numTexturesTall = ceil(height/TILE_SIZE_HEIGHT)
local texturePixelWidth, textureFileWidth, texturePixelHeight, textureFileHeight
for j = 1, numTexturesTall do
if ( j < numTexturesTall ) then
texturePixelHeight = TILE_SIZE_HEIGHT
textureFileHeight = TILE_SIZE_HEIGHT
else
texturePixelHeight = mod(height, TILE_SIZE_HEIGHT)
if ( texturePixelHeight == 0 ) then
texturePixelHeight = TILE_SIZE_HEIGHT
end
textureFileHeight = 16
while(textureFileHeight < texturePixelHeight) do
textureFileHeight = textureFileHeight * 2
end
end
for k = 1, numTexturesWide do
local texture = pin.overlayTexturePool:Acquire()
mapCanvas:AddMaskableTexture(texture)
if ( k < numTexturesWide ) then
texturePixelWidth = TILE_SIZE_WIDTH
textureFileWidth = TILE_SIZE_WIDTH
else
texturePixelWidth = mod(width, TILE_SIZE_WIDTH)
if ( texturePixelWidth == 0 ) then
texturePixelWidth = TILE_SIZE_WIDTH
end
textureFileWidth = 16
while(textureFileWidth < texturePixelWidth) do
textureFileWidth = textureFileWidth * 2
end
end
texture:SetWidth(texturePixelWidth)
texture:SetHeight(texturePixelHeight)
texture:SetTexCoord(0, texturePixelWidth/textureFileWidth, 0, texturePixelHeight/textureFileHeight)
texture:SetPoint("TOPLEFT", offsetX + (TILE_SIZE_WIDTH * (k-1)), -(offsetY + (TILE_SIZE_HEIGHT * (j - 1))))
texture:SetTexture(tonumber(fileDataIDs[((j - 1) * numTexturesWide) + k]), nil, nil, "TRILINEAR")
texture:SetVertexColor(r, g, b)
texture:SetAlpha(a)
texture:SetDrawLayer(drawLayer, subLevel - 1)
texture:Show()
if fullUpdate then
pin.textureLoadGroup:AddTexture(texture)
end
end
end
end
end
end
function FogClear:GetOverlayColor()
return db.colorR, db.colorG, db.colorB, db.colorA
end
function FogClear:SetOverlayColor(info, r,g,b,a)
db.colorR, db.colorG, db.colorB, db.colorA = r,g,b,a
if self:IsEnabled() then self:Refresh() end
end
-- remove data from global scope
MapsterFogClearData = nil