-
Notifications
You must be signed in to change notification settings - Fork 0
/
Core.lua
266 lines (233 loc) · 6.82 KB
/
Core.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
STP = LibStub("AceAddon-3.0"):NewAddon("Simple Threat Plates", "AceConsole-3.0")
STP:RegisterChatCommand("stp", "loadOptions")
STP:RegisterChatCommand("simplethreatplates", "loadOptions")
options = {
name = "Simple Threat Plates",
handler = STP,
type = 'group',
args = {
defaultcolour = {
type = 'color',
name = 'Default Plate Colour',
set = 'SetDefaultColor',
get = 'GetDefaultColor',
},
aggrocolour = {
type = 'color',
name = 'Aggro Plate Colour',
set = 'SetAggroColor',
get = 'GetAggroColor',
},
closecolour = {
type = 'color',
name = 'Insecure Threat Plate Colour',
set = 'SetCloseColor',
get = 'GetCloseColor',
},
offtankcolour = {
type = 'color',
name = 'Other Tank Has Aggro Plate Colour',
set = 'SetOfftankColor',
get = 'GetOfftankColor',
},
nontankcolour = {
type = 'color',
name = 'Non tank Has Aggro Plate Colour',
set = 'SetNontankColor',
get = 'GetNontankColor',
},
},
}
-- declare defaults to be used in the DB
local defaults = {
profile = {
colours = {
default = {
r = 1,
g = 0,
b = 0
},
aggro = {
r = 0,
g = 1,
b = 0
},
close = {
r = 1,
g = 1,
b = 0
},
offtank = {
r = 0,
g = 0.5,
b = 1
},
nontank = {
r = 1,
g = 0,
b = 0
}
}
}
}
local tanks = {}
local nontanks = {}
function STP:OnInitialize()
STP:Print("Simple Threat Plates loaded!")
self.db = LibStub("AceDB-3.0"):New("SimpleThreatPlatesDB", defaults, true)
-- self.db:ResetDB()
options.args.profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
LibStub("AceConfig-3.0"):RegisterOptionsTable("Simple Threat Plates", options)
self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("Simple Threat Plates", "Simple Threat Plates")
hooksecurefunc("CompactUnitFrame_UpdateHealthColor", UpdateThreat)
--hooksecurefunc("CompactUnitFrame_RegisterEvents", UpdateThreat)
local frame = CreateFrame("FRAME", "STPAddonFrame");
frame:RegisterEvent("PLAYER_ENTERING_WORLD");
frame:RegisterEvent("GROUP_ROSTER_UPDATE");
frame:RegisterEvent("PLAYER_SPECIALIZATION_CHANGED");
local function checkSpecs(self, event, ...)
tanks = {}
if IsInRaid() then
for i = 1, GetNumGroupMembers(), 1 do
name = "raid" .. i;
if UnitGroupRolesAssigned(name) == "TANK" then
if UnitName(name) ~= UnitName("player") then
table.insert(tanks, name)
end
else
if UnitName(name) ~= UnitName("player") then
table.insert(nontanks, name)
end
end
end
else
for i = 1, GetNumGroupMembers() - 1, 1 do
name = "party" .. i;
if UnitGroupRolesAssigned(name) == "TANK" then
table.insert(tanks, name)
else
table.insert(nontanks, name)
end
end
end
end
frame:SetScript("OnEvent", checkSpecs);
end
function STP:GetDefaultColor(info)
return self.db.profile.colours.default.r, self.db.profile.colours.default.g, self.db.profile.colours.default.b
end
function STP:SetDefaultColor(t, r, g, b, a)
self.db.profile.colours.default.r = r
self.db.profile.colours.default.g = g
self.db.profile.colours.default.b = b
rerunPlates();
end
function STP:GetAggroColor(info)
return self.db.profile.colours.aggro.r, self.db.profile.colours.aggro.g, self.db.profile.colours.aggro.b
end
function STP:SetAggroColor(t, r, g, b, a)
self.db.profile.colours.aggro.r = r
self.db.profile.colours.aggro.g = g
self.db.profile.colours.aggro.b = b
rerunPlates();
end
function STP:GetCloseColor(info)
return self.db.profile.colours.close.r, self.db.profile.colours.close.g, self.db.profile.colours.close.b
end
function STP:SetCloseColor(t, r, g, b, a)
self.db.profile.colours.close.r = r
self.db.profile.colours.close.g = g
self.db.profile.colours.close.b = b
rerunPlates();
end
function STP:GetOfftankColor(info)
return self.db.profile.colours.offtank.r, self.db.profile.colours.offtank.g, self.db.profile.colours.offtank.b
end
function STP:SetOfftankColor(t, r, g, b, a)
self.db.profile.colours.offtank.r = r
self.db.profile.colours.offtank.g = g
self.db.profile.colours.offtank.b = b
rerunPlates();
end
function STP:GetNontankColor(info)
return self.db.profile.colours.nontank.r, self.db.profile.colours.nontank.g, self.db.profile.colours.nontank.b
end
function STP:SetNontankColor(t, r, g, b, a)
self.db.profile.colours.nontank.r = r
self.db.profile.colours.nontank.g = g
self.db.profile.colours.nontank.b = b
rerunPlates();
end
function rerunPlates()
--Rerun all nameplates through UpdateThreat
if not InCombatLockdown() then
table.foreach(C_NamePlate:GetNamePlates(),
function(k, v)
UpdateThreat(C_NamePlate.GetNamePlateForUnit(v["namePlateUnitToken"])["UnitFrame"])
end)
end
end
function STP:loadOptions(input)
STP:Print("Opening options pane.")
InterfaceOptionsFrame_OpenToCategory("Simple Threat Plates")
end
function UpdateThreat(self)
local unit = self.unit
--If unit is valid, not an enemy
if (not unit) or (not UnitIsEnemy(unit, "player") and not UnitCanAttack("player", unit)) or UnitIsPlayer(unit) then
return
end
if not unit:match('nameplate%d*') then return end
if not C_NamePlate.GetNamePlateForUnit(unit) then return end
local defaultPlateColor = { STP:GetDefaultColor() };
--check if it is a neutral mob
if (not UnitIsEnemy(unit, "player") and UnitCanAttack("player", unit) and not UnitIsPlayer(unit)) then
defaultPlateColor = { self.healthBar:GetStatusBarColor() };
end
updateNameplateColor("player", self, {
default = defaultPlateColor,
close = { STP:GetCloseColor() },
temporary = { STP:GetAggroColor() },
aggro = { STP:GetAggroColor() }
}) --the player
--Check other tanks.
for _, tank in pairs(tanks) do
updateNameplateColor(tank, self, {
default = nil,
close = nil,
temporary = { STP:GetOfftankColor() },
aggro = { STP:GetOfftankColor() }
}) --the offtank
end
for _, nontank in pairs(nontanks) do
updateNameplateColor(nontank, self, {
default = nil,
close = nil,
temporary = { STP:GetNontankColor() },
aggro = { STP:GetNontankColor() }
}) --the nontank
end
end
local statuses = {
"default",
"close",
"temporary",
"aggro"
}
function updateNameplateColor(unit, nameplate, statusColorMap)
local isTanking, status = UnitDetailedThreatSituation(unit, nameplate.unit)
if status == nil then
--status could be nil if target not engaged, we can't do anything with that info!
--ignore or set the default, but only if we are looking for the player
if unit == "player" and statusColorMap.default then
--if the player themselves is not engaged, then reset the status color
nameplate.healthBar:SetStatusBarColor(unpack(statusColorMap.default))
end
return
end
status = status + 1 --lua arrays are weird and start from 1! >:(
local selectedColor = statusColorMap[statuses[status]]
if selectedColor ~= nil then --nil means don't change for it
return nameplate.healthBar:SetStatusBarColor(unpack(selectedColor))
end
end