forked from michaelnpsp/Grid2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGridStatusLoad.lua
134 lines (118 loc) · 3.61 KB
/
GridStatusLoad.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
-- Statuses Load filter management, by MiCHaEL
local Grid2 = Grid2
local Grid2Frame = Grid2Frame
local pairs = pairs
local next = next
-- local variables
local indicators = {} -- indicators marked for update
local registered = {} -- registered messages
local statuses = { playerClassSpec = {}, groupInstType = {}, instNameID = {} }
-- local functions
local function RegisterMessage(message, enabled)
if not enabled ~= not registered[message] then
registered[message] = not not enabled
if enabled then
Grid2:RegisterMessage(message)
else
Grid2:UnregisterMessage(message)
end
end
end
local function UpdateMessages(status, load)
statuses.playerClassSpec[status] = load and load.playerClassSpec~=nil or nil
statuses.instNameID[status] = load and load.instNameID~=nil or nil
statuses.groupInstType[status] = load and (load.groupType~=nil or load.instType~=nil) or nil
RegisterMessage( "Grid_GroupTypeChanged", next(statuses.groupInstType) )
RegisterMessage( "Grid_PlayerSpecChanged", next(statuses.playerClassSpec) )
RegisterMessage( "Grid_ZoneChangedNewArea", next(statuses.instNameID) )
end
local function RegisterIndicators(self)
local method = self.suspended and "UnregisterStatus" or "RegisterStatus"
for indicator, priority in pairs(self.priorities) do -- register/unregister indicators
indicator[method](indicator, self, priority)
indicators[indicator] = true
end
if not self.suspended then
self:Refresh() -- needed by aura statuses, to fill status cache with units aura info
end
end
local function UpdateIndicators()
for _, frame in next, Grid2Frame.registeredFrames do
local unit = frame.unit
if unit then
for indicator in next, indicators do
indicator:Update(frame, unit)
end
end
end
wipe(indicators)
end
local function CheckZoneFilter(filter)
local instanceName,_,_,_,_,_,_,instanceID = GetInstanceInfo()
return filter[instanceName] or filter[instanceID]
end
local function UpdateStatus(self)
local prev = self.suspended
local load = self.dbx.load
if load then
self.suspended =
( load.disabled ) or
( load.playerClass and not load.playerClass[ Grid2.playerClass ] ) or
( load.playerClassSpec and not load.playerClassSpec[ Grid2.playerClassSpec ] ) or
( load.groupType and not load.groupType[ Grid2.groupType ] ) or
( load.instType and not load.instType[ Grid2.instType ] ) or
( load.instNameID and not CheckZoneFilter(load.instNameID) ) or nil
return self.suspended ~= prev
else
self.suspended = nil
return prev
end
end
local function RefreshStatus(self)
if UpdateStatus(self) then
RegisterIndicators(self)
UpdateIndicators()
return true
end
end
local function RefreshStatuses(filterType)
local notify
for status in pairs(statuses[filterType]) do
if UpdateStatus(status) then
RegisterIndicators(status)
notify = true
end
end
UpdateIndicators()
if notify then
Grid2:SendMessage("Grid_StatusLoadChanged")
end
end
-- message events
function Grid2:Grid_GroupTypeChanged()
RefreshStatuses('groupInstType')
end
function Grid2:Grid_PlayerSpecChanged()
RefreshStatuses('playerClassSpec')
end
function Grid2:Grid_ZoneChangedNewArea()
RefreshStatuses('instNameID')
end
-- status methods
local status = Grid2.statusPrototype
function status:RegisterLoad()
local load = self.dbx and self.dbx.load
if load then
UpdateMessages(self, load)
UpdateStatus(self)
end
end
function status:UnregisterLoad()
if self.dbx and self.dbx.load then
UpdateMessages(self)
end
end
function status:RefreshLoad() -- used by options
UpdateMessages(self, self.dbx and self.dbx.load)
return RefreshStatus(self)
end