-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFunctions.lua
617 lines (529 loc) · 18.1 KB
/
Functions.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
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
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
--[[--------------------------------------------------------------------
oUF_Phanx
Fully-featured PVE-oriented layout for oUF.
Copyright 2008-2018 Phanx <[email protected]>. All rights reserved.
https://www.wowinterface.com/downloads/info13993-oUF_Phanx.html
https://www.curseforge.com/wow/addons/ouf-phanx
https://github.com/Phanx/oUF_Phanx
----------------------------------------------------------------------]]
local _, ns = ...
local _, playerClass = UnitClass("player")
local colors = oUF.colors
local noop = function() return end
local playerUnits = { player = true, pet = true, vehicle = true }
local si = ns.si
ns.noop = noop
------------------------------------------------------------------------
ns.framePrototype = {
RegisterForMouseover = function(self, element)
if not self.mouseovers then
self.mouseovers = {}
else
for i = 1, #self.mouseovers do
if self.mouseovers[i] == element then
return
end
end
end
tinsert(self.mouseovers, element)
end,
RegisterForRoleChange = function(self, func)
if not self.updateOnRoleChange then
self.updateOnRoleChange = {}
else
for i = 1, #self.updateOnRoleChange do
if self.updateOnRoleChange[i] == func then
return
end
end
end
tinsert(self.updateOnRoleChange, func)
end,
}
------------------------------------------------------------------------
-- General utility
------------------------------------------------------------------------
if playerClass == "HUNTER" or playerClass == "MAGE" or playerClass == "ROGUE" or playerClass == "WARLOCK" then
function ns.GetPlayerRole()
return "DAMAGER"
end
else
function ns.GetPlayerRole()
local spec = GetSpecialization() or 0
local _, _, _, _, _, role = GetSpecializationInfo(spec)
return role or "DAMAGER"
end
end
------------------------------------------------------------------------
-- Border
------------------------------------------------------------------------
function ns.ExtraBar_OnShow(self) --if self.__name then print("Show", self.__name) end
local frame = self.__owner
frame:SetBorderSize(nil, 0, 0, self:GetHeight() - 1 + (self.borderOffset or 0), 0)
if self.value then
return self.value:SetParent(frame.overlay)
end
for i = 1, #self do
local v = self[i]
if type(v) == "table" and v.value then
v.value:SetParent(frame.overlay)
end
end
end
function ns.ExtraBar_OnHide(self) --if self.__name then print("Hide", self.__name) end
local frame = self.__owner
frame:SetBorderSize(nil, 0, 0, 0, 0)
if self.value then
return self.value:SetParent(self)
end
for i = 1, #self do
local v = self[i]
if type(v) == "table" and v.value then
v.value:SetParent(self)
end
end
end
function ns.UpdateBorder(self)
local threat, debuff, dispellable = self.threatLevel, self.debuffType, self.debuffDispellable
-- print("UpdateBorder", self.unit, "threatLevel", threat, "debuffType", debuff, "debuffDispellable", dispellable)
local color, glow
if debuff and dispellable then
-- print(self.unit, "has dispellable debuff:", debuff)
color = colors.debuff[debuff]
glow = true
elseif threat and threat > 1 then
-- print(self.unit, "has aggro:", threat)
color = colors.threat[threat]
glow = true
elseif debuff and not ns.config.dispelFilter then
-- print(self.unit, "has debuff:", debuff)
color = colors.debuff[debuff]
elseif threat and threat > 0 then
-- print(self.unit, "has high threat")
color = colors.threat[threat]
end
if color then
self:SetBackdropBorderColor(color[1], color[2], color[3], 1, glow and ns.config.borderGlow)
else
self:SetBackdropBorderColor(0, 0, 0, 0)
end
end
------------------------------------------------------------------------
-- Health
------------------------------------------------------------------------
do
local GHOST = GetSpellInfo(8326)
if GetLocale() == "deDE" then
GHOST = "Geist" -- TOO LONG OMG
end
local UnitIsConnected, UnitIsGhost, UnitIsDead, UnitIsPlayer, UnitClass, UnitIsTapDenied, UnitIsEnemy, UnitReaction, UnitCanAssist
= UnitIsConnected, UnitIsGhost, UnitIsDead, UnitIsPlayer, UnitClass, UnitIsTapDenied, UnitIsEnemy, UnitReaction, UnitCanAssist
function ns.Health_PostUpdate(bar, unit, cur, max)
if not unit then return end -- Blizz bug in 7.1
local frame = bar.__owner
ns.HealthPrediction_Override(frame, "Health_PostUpdate", unit)
local absent = not UnitIsConnected(unit) and PLAYER_OFFLINE or UnitIsGhost(unit) and GHOST or UnitIsDead(unit) and DEAD
if absent then
bar:SetValue(0) -- 5.2: UnitHealth is sometimes > 0 for dead units
local power = frame.Power
if power then
power:SetValue(0)
if power.value then
power.value:SetText(nil)
end
end
local color = colors.disconnected
if frame.isMouseOver and max > 0 then -- max is 0 for offline units
return bar.value:SetFormattedText("|cff%02x%02x%02x%s|r", color[1] * 255, color[2] * 255, color[3] * 255, si(max))
else
return bar.value:SetFormattedText("|cff%02x%02x%02x%s|r", color[1] * 255, color[2] * 255, color[3] * 255, absent)
end
end
local color = ns.GetUnitColor(unit)
-- HEALER: deficit, percent on mouseover
-- OTHER: percent, current on mouseover
if cur < max then
if ns.GetPlayerRole() == "HEALER" and UnitCanAssist("player", unit) then
if frame.isMouseOver and not frame.isGroupFrame then
-- don't change text on party frames, it's annoying for click-cast or mouseover healing
bar.value:SetFormattedText("|cff%02x%02x%02x%s|r", color[1] * 255, color[2] * 255, color[3] * 255, si(cur))
else
bar.value:SetFormattedText("|cff%02x%02x%02x%s|r", color[1] * 255, color[2] * 255, color[3] * 255, si(cur - max))
end
elseif frame.isMouseOver then
bar.value:SetFormattedText("|cff%02x%02x%02x%s|r", color[1] * 255, color[2] * 255, color[3] * 255, si(cur))
else
bar.value:SetFormattedText("|cff%02x%02x%02x%d%%|r", color[1] * 255, color[2] * 255, color[3] * 255, floor(cur / max * 100 + 0.5))
end
elseif frame.isMouseOver then
bar.value:SetFormattedText("|cff%02x%02x%02x%s|r", color[1] * 255, color[2] * 255, color[3] * 255, si(max))
else
bar.value:SetText(nil)
end
end
end
------------------------------------------------------------------------
-- HealthPrediction
------------------------------------------------------------------------
do
local UnitHealth, UnitHealthMax, UnitGetTotalAbsorbs, UnitGetIncomingHeals
= UnitHealth, UnitHealthMax, UnitGetTotalAbsorbs, UnitGetIncomingHeals
function ns.HealthPrediction_Override(self, event, unit)
--print("HealthPrediction Override", event, unit)
local element = self.HealthPrediction
local parent = self.Health
local health, maxHealth = UnitHealth(unit), UnitHealthMax(unit)
if maxHealth == 0 or UnitIsDeadOrGhost(unit) then
element.healingBar:Hide()
element.healingBar.cap:Hide()
element.absorbsBar:Hide()
element.absorbsBar.cap:Hide()
return
end
local missing = maxHealth - health
local healing = UnitGetIncomingHeals(unit) or 0
if healing > 0 and ns.config.ignoreOwnHeals then
healing = healing - (UnitGetIncomingHeals(unit, "player") or 0)
end
if (healing / maxHealth) >= 0.1 and missing > 0 then
local bar = element.healingBar
bar:Show()
bar:SetMinMaxValues(0, maxHealth)
if healing > missing then
bar:SetValue(missing)
bar.cap:SetShown((healing - missing) / maxHealth > element.maxOverflow)
missing = 0
else
bar:SetValue(healing)
bar.cap:Hide()
missing = missing - healing
end
parent = bar
else
element.healingBar:Hide()
element.healingBar.cap:SetShown(healing / maxHealth > element.maxOverflow)
end
local absorbs = UnitGetTotalAbsorbs(unit) or 0
if (absorbs / maxHealth) >= 0.1 and missing > 0 then
local bar = element.absorbsBar
bar:Show()
bar:SetPoint("TOPLEFT", parent.fg, "TOPRIGHT")
bar:SetPoint("BOTTOMLEFT", parent.fg, "BOTTOMRIGHT")
bar:SetMinMaxValues(0, maxHealth)
if absorbs > missing then
bar:SetValue(missing)
bar.cap:SetShown((absorbs - missing) / maxHealth > element.maxOverflow)
else
bar:SetValue(absorbs)
bar.cap:Hide()
end
else
element.absorbsBar:Hide()
element.absorbsBar.cap:SetShown(absorbs / maxHealth > element.maxOverflow)
end
end
end
------------------------------------------------------------------------
-- Power
------------------------------------------------------------------------
do
local UnitIsDeadOrGhost, UnitPowerType, UnitPower, UnitPowerMax
= UnitIsDeadOrGhost, UnitPowerType, UnitPower, UnitPowerMax
function ns.Power_PostUpdate(self, unit, cur, min, max)
if max == 0 then
self.__owner.Health:SetPoint("BOTTOM", self.__owner, "BOTTOM", 0, 1)
return self:Hide()
else
self.__owner.Health:SetPoint("BOTTOM", self, "TOP", 0, 1)
self:Show()
end
if UnitIsDeadOrGhost(unit) then
self:SetValue(0)
if self.value then
self.value:SetText(nil)
end
return
end
if not self.value then return end
local _, powerType = UnitPowerType(unit)
local color = colors.power[powerType] or colors.power.FUEL
if cur < max then
if self.__owner.isMouseOver then
self.value:SetFormattedText("%s.|cff%02x%02x%02x%s|r", si(cur), color[1] * 255, color[2] * 255, color[3] * 255, si(max))
elseif powerType == "MANA" then
self.value:SetFormattedText("%d|cff%02x%02x%02x%%|r", floor(cur / max * 100 + 0.5), color[1] * 255, color[2] * 255, color[3] * 255)
elseif cur > 0 then
self.value:SetText(cur)
else
self.value:SetText(nil)
end
elseif powerType == "MANA" and self.__owner.isMouseOver then
self.value:SetFormattedText("|cff%02x%02x%02x%s|r", color[1] * 255, color[2] * 255, color[3] * 255, si(max))
else
self.value:SetText(nil)
end
end
end
------------------------------------------------------------------------
-- ClassPower
------------------------------------------------------------------------
function ns.ClassPower_PostUpdate(element, cur, max, hasMaxChanged, event)
--print("ClassPower PostUpdate", cur, max, hasMaxChanged)
ns.Orbs.Update(element, cur, max)
--[[
for i = 1, max do
local icon = element[i]
if i > cur then
icon.bg:SetVertexColor(0.4, 0.4, 0.4)
icon.bg:SetAlpha(0.5)
icon.fg:Hide()
icon:Show()
else
icon.bg:SetVertexColor(0.25, 0.25, 0.25)
icon.bg:SetAlpha(1)
icon.fg:Show()
end
end
]]
end
------------------------------------------------------------------------
-- Druid mana
------------------------------------------------------------------------
function ns.AdditionalPower_PostUpdate(bar, unit, mana, maxMana)
bar.value:SetFormattedText(si(mana, true))
end
------------------------------------------------------------------------
-- Stagger
-- TODO reimplement or remove
------------------------------------------------------------------------
function ns.Stagger_PostUpdate(bar, cur, max)
local perc = cur / max * 100
if perc < 5 then
return bar:Hide()
end
--print("Stagger PostUpdate", stagger, perc)
bar.value:SetFormattedText("%.0f%%", perc)
bar:Show()
end
------------------------------------------------------------------------
-- Dungeon role icon
------------------------------------------------------------------------
local roleTexCoords = {
DAMAGER = { 0.25, 0.5, 0, 1 },
TANK = { 0.5, 0.75, 0, 1 },
HEALER = { 0.75, 1, 0, 1 },
}
function ns.GroupRoleIndicator_Override(self, event)
local lfdrole = self.GroupRoleIndicator
if(lfdrole.PreUpdate) then
lfdrole:PreUpdate()
end
local role = UnitGroupRolesAssigned(self.unit)
local coords = roleTexCoords[role or ""]
if coords then
lfdrole:SetTexCoord(unpack(coords))
lfdrole:Show()
else
lfdrole:Hide()
end
if(lfdrole.PostUpdate) then
return lfdrole:PostUpdate(role)
end
end
------------------------------------------------------------------------
-- Phase icon
------------------------------------------------------------------------
function ns.PhaseIndicator_PostUpdate(icon, inPhase)
if not inPhase and not UnitIsPlayer(icon.__owner.unit) then
return icon:Hide()
end
end
------------------------------------------------------------------------
-- PvP icon
------------------------------------------------------------------------
local PLAYER_FACTION = UnitFactionGroup("player")
local pvpTextures = {
Alliance = "Interface\\AddOns\\oUF_Phanx\\Media\\DotDiamond",
Horde = "Interface\\AddOns\\oUF_Phanx\\Media\\DotCircle",
FFA = "Interface\\AddOns\\oUF_Phanx\\Media\\DotSquare",
}
function ns.PvPIndicator_PostUpdate(element, unit, status)
--print("PvP PostUpdate", element.__owner.unit, status)
if not status or status == PLAYER_FACTION then
return element:Hide()
end
local tex = pvpTextures[status] or pvpTextures[PLAYER_FACTION]
element:SetTexture(tex)
if status == "FFA" then
element:SetVertexColor(0.8, 0.4, 0)
elseif status == "Alliance" then
element:SetVertexColor(0.2, 0.4, 1)
elseif status == "Horde" then
element:SetVertexColor(0.6, 0, 0)
end
element:Show()
end
------------------------------------------------------------------------
-- Buffs & debuffs
------------------------------------------------------------------------
local function AuraIconCD_OnShow(cd)
local button = cd:GetParent()
button:SetBorderParent(cd)
button.count:SetParent(cd)
end
local function AuraIconCD_OnHide(cd)
local button = cd:GetParent()
button:SetBorderParent(button)
button.count:SetParent(button)
end
local function AuraIconOverlay_SetBorderColor(overlay, r, g, b)
if not r or not g or not b then
local color = ns.config.borderColor
r, g, b = color[1], color[2], color[3]
end
overlay:GetParent():SetBorderColor(r, g, b)
end
function ns.Auras_PostCreateIcon(element, button)
ns.CreateBorder(button, 12)
button.cd:SetReverse(true)
button.cd:SetScript("OnHide", AuraIconCD_OnHide)
button.cd:SetScript("OnShow", AuraIconCD_OnShow)
if button.cd:IsShown() then AuraIconCD_OnShow(button.cd) end
button.icon:SetTexCoord(0.03, 0.97, 0.03, 0.97)
button.overlay:Hide()
button.overlay.Hide = AuraIconOverlay_SetBorderColor
button.overlay.SetVertexColor = AuraIconOverlay_SetBorderColor
button.overlay.Show = noop
end
local function FindAuraTimer(button, unit)
local timer
if OmniCC then
for i = 1, button:GetNumChildren() do
local child = select(i, button:GetChildren())
if child.text and (child.icon == button.icon or child.cooldown == button.cd) then
child.ClearAllPoints = noop
child.SetAlpha = noop
child.SetPoint = noop
child.SetScale = noop
timer = child.text
break
end
end
else
local region = button.cd:GetRegions()
timer = region.SetText and region
end
if timer then
timer:ClearAllPoints()
timer.ClearAllPoints = noop
timer:SetPoint("CENTER", button, "TOP", 0, 2)
timer.SetPoint = noop
timer:SetFont(ns.GetFontFile(), unit:match("^party") and 12 or 16, ns.config.fontOutline)
timer.SetFont = noop
timer:SetTextColor(1, 0.8, 0)
timer.SetTextColor = noop
timer.SetVertexColor = noop
tinsert(ns.fontstrings, timer)
return timer
end
return not OmniCC
end
function ns.Auras_PostUpdateIcon(element, unit, button, index, offset)
button.icon:SetDesaturated(not playerUnits[button.caster or ""])
if not button.timer then
button.timer = FindAuraTimer(button, unit)
end
end
function ns.Auras_PostUpdate(self, unit)
-- self.__owner.Health:ForceUpdate() -- required to detect Dead => Ghost
-- TODO: check if PLAYER_FLAGS_CHANGED or UNIT_FLAGS can work for this
end
------------------------------------------------------------------------
-- Threat
------------------------------------------------------------------------
function ns.Threat_Override(frame, event, unit)
if unit ~= frame.unit then return end
local status = UnitThreatSituation(unit or frame.unit) or 0
if not ns.config.threatLevels then
status = status > 1 and 3 or 0
end
if frame.threatLevel == status then return end
--print("ThreatHighlightOverride", frame.unit, status)
frame.threatLevel = status
frame:UpdateBorder()
end
------------------------------------------------------------------------
-- Dispel highlight
------------------------------------------------------------------------
function ns.DispelHighlight_Override(element, debuffType, canDispel)
local frame = element.__owner
if frame.debuffType == debuffType then return end
-- print("DispelHighlightOverride", unit, debuffType, canDispel)
frame.debuffType = debuffType
frame.debuffDispellable = canDispel
frame:UpdateBorder()
end
------------------------------------------------------------------------
-- Frames
------------------------------------------------------------------------
function ns.UnitFrame_OnEnter(self)
if self.__owner then
self = self.__owner
end
if IsShiftKeyDown() or not UnitAffectingCombat("player") then
local noobTips = SHOW_NEWBIE_TIPS == "1"
if noobTips and self.unit == "player" then
GameTooltip_SetDefaultAnchor(GameTooltip, self)
GameTooltip_AddNewbieTip(self, PARTY_OPTIONS_LABEL, 1, 1, 1, NEWBIE_TOOLTIP_PARTYOPTIONS)
elseif noobTips and self.unit == "target" and UnitPlayerControlled("target") and not UnitIsUnit("target", "player") and not UnitIsUnit("target", "pet") then
GameTooltip_SetDefaultAnchor(GameTooltip, self)
GameTooltip_AddNewbieTip(self, PLAYER_OPTIONS_LABEL, 1, 1, 1, NEWBIE_TOOLTIP_PLAYEROPTIONS)
else
UnitFrame_OnEnter(self)
end
end
self.isMouseOver = true
if self.mouseovers then
for _, element in pairs(self.mouseovers) do
if type(element) == "function" then
element(self, true)
elseif element.ForceUpdate then
element:ForceUpdate()
else
element:Show()
end
end
end
end
function ns.UnitFrame_OnLeave(self)
if self.__owner then
self = self.__owner
end
UnitFrame_OnLeave(self)
self.isMouseOver = nil
if self.mouseovers then
for _, element in pairs(self.mouseovers) do
if type(element) == "function" then
element(self)
elseif element.ForceUpdate then
element:ForceUpdate()
else
element:Hide()
end
end
end
end
function ns.UnitFrame_DropdownMenu(self)
local unit = self.unit:sub(1, -2)
if unit == "party" or unit == "partypet" then
ToggleDropDownMenu(1, nil, _G["PartyMemberFrame" .. self.id .. "DropDown"], "cursor", 0, 0)
else
local cunit = gsub(self.unit, "^%l", strupper)
if cunit == "Vehicle" then
cunit = "Pet"
end
if _G[cunit .. "FrameDropDown"] then
ToggleDropDownMenu(1, nil, _G[cunit .. "FrameDropDown"], "cursor", 0, 0)
end
end
end