-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleRaidFrames_Indicators.lua
More file actions
executable file
·422 lines (383 loc) · 13.4 KB
/
SimpleRaidFrames_Indicators.lua
File metadata and controls
executable file
·422 lines (383 loc) · 13.4 KB
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
local ADDON_NAME = ...
local M = _G[ADDON_NAME]
local DEFAULTS = M.DEFAULTS
local CONST = M.CONST
local ICONS = CONST.ICONS
local isFrameInRaidContainer = M.IsFrameInRaidContainer
local safeGetValue = M.SafeGetValue
local getFrameUnit = M.GetFrameUnit
local isSecretValue = M.IsSecretValue or issecretvalue or function() return false end
local function isTrue(value)
return not isSecretValue(value) and value == true
end
local function getClassColor(unit)
if not unit then return nil end
local okPlayer, isPlayer = pcall(UnitIsPlayer, unit)
if not okPlayer or isSecretValue(isPlayer) or not isPlayer then return nil end
local okClass, _, class = pcall(UnitClass, unit)
if not okClass or isSecretValue(class) or not class then return nil end
return RAID_CLASS_COLORS and RAID_CLASS_COLORS[class] or nil
end
local function tintIndicator(tex, unit, settingKey, desaturateWhenTinted)
if not tex or not tex.SetVertexColor then return end
if M.DB and M.DB[settingKey] then
local color = getClassColor(unit)
if color then
if desaturateWhenTinted and tex.SetDesaturated then
tex:SetDesaturated(true)
end
tex:SetVertexColor(color.r, color.g, color.b, 1)
return
end
end
if tex.SetDesaturated then
tex:SetDesaturated(false)
end
tex:SetVertexColor(1, 1, 1, 1)
end
local function getRosterUnit(frame)
if not frame then return nil end
local unit = safeGetValue(frame, "unit")
if type(unit) == "string" and unit ~= "" then
return unit
end
return getFrameUnit(frame)
end
local function getIndicatorAnchorInfo(anchor)
if anchor == "RIGHT" then
return "LEFT", "RIGHT", 2, 0, "X", 1
elseif anchor == "BOTTOM" then
return "TOP", "BOTTOM", 0, -2, "X", -1
elseif anchor == "LEFT" then
return "RIGHT", "LEFT", -2, 0, "X", -1
elseif anchor == "CENTER" then
return "CENTER", "CENTER", 0, 0, "X", -1
end
-- default TOP
return "BOTTOM", "TOP", 0, 2, "X", -1
end
local function placeIndicatorIcon(frame, tex, anchor, index, iconSize, spacing, extraX, extraY)
if not tex or not frame then return end
local point, relPoint, baseX, baseY, axis, dir = getIndicatorAnchorInfo(anchor)
local offsetX = baseX + (extraX or 0)
local offsetY = baseY + (extraY or 0)
if axis == "X" and index and index > 1 then
offsetX = offsetX + dir * (iconSize + spacing) * (index - 1)
elseif axis == "Y" and index and index > 1 then
offsetY = offsetY + dir * (iconSize + spacing) * (index - 1)
end
tex:ClearAllPoints()
if frame.name then
tex:SetPoint(point, frame.name, relPoint, offsetX, offsetY)
else
tex:SetPoint("CENTER", frame, "CENTER", offsetX, offsetY)
end
end
local function getReadyCheckAtlas(status)
if status == "ready" then
return READY_CHECK_READY_TEXTURE_RAID or "UI-LFG-ReadyMark-Raid"
elseif status == "notready" then
return READY_CHECK_NOT_READY_TEXTURE_RAID or "UI-LFG-DeclineMark-Raid"
elseif status == "waiting" then
return READY_CHECK_WAITING_TEXTURE_RAID or "UI-LFG-PendingMark-Raid"
end
return nil
end
local function setReadyCheckAtlas(tex, atlas)
if not tex or not atlas then return end
if tex.SetAtlas then
if TextureKitConstants and TextureKitConstants.IgnoreAtlasSize ~= nil then
tex:SetAtlas(atlas, TextureKitConstants.IgnoreAtlasSize)
else
tex:SetAtlas(atlas)
end
end
end
local function getReadyCheckIconSize()
local iconSize = tonumber(M.DB and M.DB.readyCheckIconSize) or DEFAULTS.readyCheckIconSize
if iconSize < 8 then iconSize = 8 end
if iconSize > 40 then iconSize = 40 end
return iconSize
end
local function applyReadyCheckIconStyle(readyCheckIcon, status)
if not readyCheckIcon or not M.DB then return end
local frame = readyCheckIcon.GetParent and readyCheckIcon:GetParent()
if not frame or not isFrameInRaidContainer(frame) then return end
readyCheckIcon._srfLastStatus = status
local customIcon = frame._srfReadyCheckIcon
if not M.DB.readyCheckIconEnabled then
if customIcon then customIcon:Hide() end
return
end
local atlas = getReadyCheckAtlas(status)
if not atlas then
if customIcon then customIcon:Hide() end
if readyCheckIcon.Hide then readyCheckIcon:Hide() end
return
end
if not customIcon then
customIcon = frame:CreateTexture(nil, "OVERLAY", nil, 7)
customIcon:SetTexCoord(0, 1, 0, 1)
if customIcon.SetIgnoreParentAlpha then
customIcon:SetIgnoreParentAlpha(true)
end
frame._srfReadyCheckIcon = customIcon
end
local iconSize = getReadyCheckIconSize()
local anchor = M.DB.readyCheckIconAnchor or DEFAULTS.readyCheckIconAnchor
local offsetX = tonumber(M.DB.readyCheckIconOffsetX) or 0
local offsetY = tonumber(M.DB.readyCheckIconOffsetY) or 0
setReadyCheckAtlas(customIcon, atlas)
customIcon:SetVertexColor(1, 1, 1, 1)
customIcon:SetSize(iconSize, iconSize)
placeIndicatorIcon(frame, customIcon, anchor, 1, iconSize, 2, offsetX, offsetY)
customIcon:Show()
if readyCheckIcon.Hide then readyCheckIcon:Hide() end
end
local function refreshReadyCheckIcon(frame)
if not frame or not frame.readyCheckIcon or not isFrameInRaidContainer(frame) then return end
local status = frame.readyCheckIcon._srfLastStatus or frame.readyCheckStatus
if M.DB and not M.DB.readyCheckIconEnabled and frame.readyCheckIcon.SetStatus then
frame.readyCheckIcon:SetStatus(status)
end
applyReadyCheckIconStyle(frame.readyCheckIcon, status)
end
local function updateLeaderAssistIndicator(frame)
local unit = getRosterUnit(frame)
if not frame or not unit or not M.DB then return end
if not isFrameInRaidContainer(frame) then return end
local inGroup = (IsInGroup and IsInGroup()) or false
local okLeader, isLeader = pcall(UnitIsGroupLeader, unit)
local okAssist, isAssist = pcall(UnitIsGroupAssistant, unit)
local showLeader = inGroup and okLeader and isTrue(isLeader) and M.DB.leaderAssistEnabled
local showAssist = inGroup and okAssist and isTrue(isAssist) and M.DB.leaderAssistEnabled
local leaderIcon = frame._srfLeaderIcon
if not leaderIcon then
leaderIcon = frame:CreateTexture(nil, "OVERLAY", nil, 6)
leaderIcon:SetTexture(ICONS.leader)
leaderIcon:SetTexCoord(0, 1, 0, 1)
if leaderIcon.SetDesaturated then
leaderIcon:SetDesaturated(false)
end
leaderIcon:SetVertexColor(1, 1, 1, 1)
frame._srfLeaderIcon = leaderIcon
end
local assistIcon = frame._srfAssistIcon
if not assistIcon then
assistIcon = frame:CreateTexture(nil, "OVERLAY", nil, 6)
assistIcon:SetTexture(ICONS.assist)
assistIcon:SetTexCoord(0, 1, 0, 1)
if assistIcon.SetDesaturated then
assistIcon:SetDesaturated(false)
end
assistIcon:SetVertexColor(1, 1, 1, 1)
frame._srfAssistIcon = assistIcon
end
leaderIcon:Hide()
assistIcon:Hide()
if not showLeader and not showAssist then
return
end
local _, size
local nameRegion = safeGetValue(frame, "name")
if nameRegion and nameRegion.GetFont then
_, size = nameRegion:GetFont()
end
local iconSize = tonumber(size) or 12
if iconSize < 8 then iconSize = 8 end
if iconSize > 20 then iconSize = 20 end
local anchor = M.DB.leaderAssistAnchor or DEFAULTS.leaderAssistAnchor
local offsetX = tonumber(M.DB.leaderAssistOffsetX) or 0
local offsetY = tonumber(M.DB.leaderAssistOffsetY) or 0
local spacing = 2
if showLeader then
leaderIcon:SetSize(iconSize, iconSize)
tintIndicator(leaderIcon, unit, "leaderAssistClassColor", true)
placeIndicatorIcon(frame, leaderIcon, anchor, 1, iconSize, spacing, offsetX, offsetY)
leaderIcon:Show()
elseif showAssist then
assistIcon:SetSize(iconSize, iconSize)
tintIndicator(assistIcon, unit, "leaderAssistClassColor", true)
placeIndicatorIcon(frame, assistIcon, anchor, 1, iconSize, spacing, offsetX, offsetY)
assistIcon:Show()
end
end
local function updateOfflineIndicator(frame)
local statusText = safeGetValue(frame, "statusText")
local unit = getFrameUnit(frame)
if not frame or not statusText or not unit or not M.DB then return end
if not isFrameInRaidContainer(frame) then return end
if not M.DB.statusIndicatorsEnabled then
if frame._srfOfflineIcon then frame._srfOfflineIcon:Hide() end
if frame._srfAfkIcon then frame._srfAfkIcon:Hide() end
if frame._srfDndIcon then frame._srfDndIcon:Hide() end
if frame._srfDeadIcon then frame._srfDeadIcon:Hide() end
if frame._srfGhostIcon then frame._srfGhostIcon:Hide() end
return
end
local isOffline = false
local ok, connected = pcall(UnitIsConnected, unit)
if ok and not isSecretValue(connected) and connected == false then
isOffline = true
end
local isAfk = false
local isDnd = false
local chatLockedDown = false
if C_ChatInfo and C_ChatInfo.InChatMessagingLockdown then
local okChat, locked = pcall(C_ChatInfo.InChatMessagingLockdown)
if okChat and isTrue(locked) then
chatLockedDown = true
end
end
if not chatLockedDown then
local okAfk, afk = pcall(UnitIsAFK, unit)
if okAfk and isTrue(afk) then
isAfk = true
end
local okDnd, dnd = pcall(UnitIsDND, unit)
if okDnd and isTrue(dnd) then
isDnd = true
end
end
local isGhost = false
local okGhost, ghost = pcall(UnitIsGhost, unit)
if okGhost and isTrue(ghost) then
isGhost = true
end
local isDead = false
local okDead, deadOrGhost = pcall(UnitIsDeadOrGhost, unit)
if okDead and isTrue(deadOrGhost) and not isGhost then
isDead = true
end
local icon = frame._srfOfflineIcon
if not icon then
icon = frame:CreateTexture(nil, "OVERLAY", nil, 7)
icon:SetTexture(ICONS.offline)
icon:SetTexCoord(0, 1, 0, 1)
frame._srfOfflineIcon = icon
end
local afkIcon = frame._srfAfkIcon
if not afkIcon then
afkIcon = frame:CreateTexture(nil, "OVERLAY", nil, 7)
afkIcon:SetTexture(ICONS.afk)
afkIcon:SetTexCoord(0, 1, 0, 1)
frame._srfAfkIcon = afkIcon
end
local dndIcon = frame._srfDndIcon
if not dndIcon then
dndIcon = frame:CreateTexture(nil, "OVERLAY", nil, 7)
dndIcon:SetTexture(ICONS.dnd)
dndIcon:SetTexCoord(0, 1, 0, 1)
frame._srfDndIcon = dndIcon
end
local deadIcon = frame._srfDeadIcon
if not deadIcon then
deadIcon = frame:CreateTexture(nil, "OVERLAY", nil, 7)
deadIcon:SetTexture(ICONS.dead)
deadIcon:SetTexCoord(0, 1, 0, 1)
frame._srfDeadIcon = deadIcon
end
local ghostIcon = frame._srfGhostIcon
if not ghostIcon then
ghostIcon = frame:CreateTexture(nil, "OVERLAY", nil, 7)
ghostIcon:SetTexture(ICONS.ghost)
ghostIcon:SetTexCoord(0, 1, 0, 1)
frame._srfGhostIcon = ghostIcon
end
local _, size
local nameRegion = safeGetValue(frame, "name")
if nameRegion and nameRegion.GetFont then
_, size = nameRegion:GetFont()
end
if not size and statusText.GetFont then
_, size = statusText:GetFont()
end
local iconSize = tonumber(size) or 12
if iconSize < 8 then iconSize = 8 end
if iconSize > 20 then iconSize = 20 end
local spacing = 2
local anchor = M.DB.statusIndicatorAnchor or DEFAULTS.statusIndicatorAnchor
local offsetX = tonumber(M.DB.statusIndicatorOffsetX) or 0
local offsetY = tonumber(M.DB.statusIndicatorOffsetY) or 0
icon:Hide()
afkIcon:Hide()
dndIcon:Hide()
deadIcon:Hide()
ghostIcon:Hide()
if isOffline then
if statusText.Hide then statusText:Hide() end
icon:SetSize(iconSize, iconSize)
tintIndicator(icon, unit, "statusIndicatorClassColor")
placeIndicatorIcon(frame, icon, anchor, 1, iconSize, spacing, offsetX, offsetY)
icon:Show()
return
end
if isDead or isGhost then
if statusText.Hide then statusText:Hide() end
end
if isAfk then
afkIcon:SetSize(iconSize, iconSize)
tintIndicator(afkIcon, unit, "statusIndicatorClassColor")
placeIndicatorIcon(frame, afkIcon, anchor, 1, iconSize, spacing, offsetX, offsetY)
afkIcon:Show()
end
if isDead or isGhost then
local tex = isGhost and ghostIcon or deadIcon
tex:SetSize(iconSize, iconSize)
tintIndicator(tex, unit, "statusIndicatorClassColor")
local index = isAfk and 2 or 1
placeIndicatorIcon(frame, tex, anchor, index, iconSize, spacing, offsetX, offsetY)
tex:Show()
end
if not isAfk and not isDead and not isGhost and isDnd then
dndIcon:SetSize(iconSize, iconSize)
tintIndicator(dndIcon, unit, "statusIndicatorClassColor")
placeIndicatorIcon(frame, dndIcon, anchor, 1, iconSize, spacing, offsetX, offsetY)
dndIcon:Show()
end
end
function M:RefreshRaidStatusText()
local function refresh(frame)
if not frame then return end
updateOfflineIndicator(frame)
updateLeaderAssistIndicator(frame)
refreshReadyCheckIcon(frame)
end
if CompactRaidFrameContainer and CompactRaidFrameContainer.ApplyToFrames then
CompactRaidFrameContainer:ApplyToFrames("normal", refresh)
CompactRaidFrameContainer:ApplyToFrames("mini", refresh)
end
if CompactPartyFrame and CompactPartyFrame.ApplyFunctionToAllFrames and CompactPartyFrame:IsShown() then
CompactPartyFrame:ApplyFunctionToAllFrames("normal", refresh)
CompactPartyFrame:ApplyFunctionToAllFrames("mini", refresh)
end
end
local statusRefreshPending
local statusRefreshFrame
local function scheduleStatusRefresh()
if statusRefreshPending then return end
statusRefreshPending = true
local function refresh()
statusRefreshPending = false
if M and M.RefreshRaidStatusText then
M:RefreshRaidStatusText()
end
end
if C_Timer and C_Timer.After then
C_Timer.After(0, refresh)
else
refresh()
end
end
local function ensureStatusIndicatorRefresh()
if statusRefreshFrame then return end
statusRefreshFrame = CreateFrame("Frame")
statusRefreshFrame:RegisterEvent("GROUP_ROSTER_UPDATE")
statusRefreshFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
statusRefreshFrame:RegisterEvent("PARTY_LEADER_CHANGED")
statusRefreshFrame:SetScript("OnEvent", scheduleStatusRefresh)
end
M.UpdateOfflineIndicator = updateOfflineIndicator
M.UpdateLeaderAssistIndicator = updateLeaderAssistIndicator
M.ApplyReadyCheckIconStyle = applyReadyCheckIconStyle
M.EnsureStatusIndicatorRefresh = ensureStatusIndicatorRefresh