Skip to content

Commit 51bd80e

Browse files
committed
show dead/disconnect color when testing frames and some status text
1 parent 7367df9 commit 51bd80e

File tree

3 files changed

+67
-35
lines changed

3 files changed

+67
-35
lines changed

ElvUI/Core/General/Tags.lua

+1-5
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,8 @@ local UnitGUID = UnitGUID
4444
local UnitHealthMax = UnitHealthMax
4545
local UnitIsAFK = UnitIsAFK
4646
local UnitIsBattlePetCompanion = UnitIsBattlePetCompanion
47-
local UnitIsConnected = UnitIsConnected
48-
local UnitIsDead = UnitIsDead
49-
local UnitIsDeadOrGhost = UnitIsDeadOrGhost
5047
local UnitIsDND = UnitIsDND
5148
local UnitIsFeignDeath = UnitIsFeignDeath
52-
local UnitIsGhost = UnitIsGhost
5349
local UnitIsPlayer = UnitIsPlayer
5450
local UnitIsPVP = UnitIsPVP
5551
local UnitIsPVPFreeForAll = UnitIsPVPFreeForAll
@@ -79,7 +75,7 @@ local SPEC_MONK_BREWMASTER = SPEC_MONK_BREWMASTER
7975
local PVP = PVP
8076

8177
-- GLOBALS: Hex, _TAGS, _COLORS -- added by oUF
82-
-- GLOBALS: UnitPower, UnitHealth, UnitName, UnitClass -- override during testing groups
78+
-- GLOBALS: UnitPower, UnitHealth, UnitName, UnitClass, UnitIsDead, UnitIsGhost, UnitIsDeadOrGhost, UnitIsConnected -- override during testing groups
8379
-- GLOBALS: GetTitleNPC, Abbrev, GetClassPower, GetQuestData, UnitEffectiveLevel, NameHealthColor -- custom ones we made
8480

8581
local RefreshNewTags -- will turn true at EOF

ElvUI/Core/Modules/UnitFrames/ConfigEnviroment.lua

+47-14
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ local E, L, V, P, G = unpack(ElvUI)
22
local UF = E:GetModule('UnitFrames')
33
local ElvUF = E.oUF
44

5-
local _G = _G
6-
local setmetatable, getfenv, setfenv = setmetatable, getfenv, setfenv
5+
local _G, getfenv, setfenv = _G, getfenv, setfenv
6+
local setmetatable, rawget, rawset = setmetatable, rawget, rawset
77
local type, pairs, min, random, strfind, next = type, pairs, min, random, strfind, next
88

99
local UnitName = UnitName
@@ -35,13 +35,24 @@ local attributeBlacklist = {
3535
showSolo = true
3636
}
3737

38-
local colorTags = {
38+
local allowTags = {
39+
dead = true,
40+
ghost = true,
41+
status = true,
42+
resting = true,
43+
offline = true,
3944
healthcolor = true,
4045
powercolor = true,
4146
classcolor = true,
4247
namecolor = true
4348
}
4449

50+
local statusChanceDefault = 10
51+
local statusChance = {
52+
UnitIsConnected = 15, -- less likely
53+
UnitIsDeadOrGhost = 5 -- more likely
54+
}
55+
4556
local PowerType = Enum.PowerType
4657
local classPowers = {
4758
[0] = PowerType.Mana,
@@ -76,10 +87,30 @@ local function envUnit(arg1)
7687
end
7788
end
7889

90+
local function generateStatusFunc(tag)
91+
return function(arg1)
92+
local unit, real = envUnit(arg1)
93+
if real then
94+
return _G[tag](unit)
95+
end
96+
97+
local chance = random(1, statusChance[tag] or statusChanceDefault)
98+
if tag == 'UnitIsConnected' then
99+
return chance ~= 1
100+
else
101+
return chance == 1
102+
end
103+
end
104+
end
105+
79106
local function createConfigEnv()
80107
if configEnv then return end
81108

82-
configEnv = setmetatable({
109+
UF.ConfigEnv = {
110+
Env = ElvUF.Tags.Env,
111+
_VARS = ElvUF.Tags.Vars,
112+
_COLORS = ElvUF.colors,
113+
ColorGradient = ElvUF.ColorGradient,
83114
UnitPower = function(arg1, displayType)
84115
local unit, real = envUnit(arg1)
85116
if real then
@@ -128,27 +159,29 @@ local function createConfigEnv()
128159

129160
local classToken = CLASS_SORT_ORDER[random(1, NUM_CLASS_ORDER)]
130161
return LOCALIZED_CLASS_NAMES_MALE[classToken], classToken
131-
end,
132-
Env = ElvUF.Tags.Env,
133-
_VARS = ElvUF.Tags.Vars,
134-
_COLORS = ElvUF.colors,
135-
ColorGradient = ElvUF.ColorGradient,
136-
}, {
162+
end
163+
}
164+
165+
for _, name in next, { 'IsResting', 'UnitIsDead', 'UnitIsGhost', 'UnitIsDeadOrGhost', 'UnitIsConnected' } do
166+
UF.ConfigEnv[name] = generateStatusFunc(name)
167+
end
168+
169+
configEnv = setmetatable(UF.ConfigEnv, {
137170
__index = function(obj, key)
138171
local envValue = ElvUF.Tags.Env[key]
139172
if envValue ~= nil then
140173
return envValue
141174
end
142175

143-
return obj[key]
176+
return rawget(obj, key)
144177
end,
145-
__newindex = function(_, key, value)
146-
_G[key] = value
178+
__newindex = function(obj, key, value)
179+
rawset(obj, key, value)
147180
end,
148181
})
149182

150183
for tag, func in next, ElvUF.Tags.Methods do
151-
if colorTags[tag] or UF.overrideTags[tag] or (strfind(tag, '^name:') or strfind(tag, '^health:') or strfind(tag, '^power:')) then
184+
if allowTags[tag] or UF.overrideTags[tag] or (strfind(tag, '^name:') or strfind(tag, '^health:') or strfind(tag, '^power:')) then
152185
overrideFuncs[tag] = func
153186
end
154187
end

ElvUI/Core/Modules/UnitFrames/Elements/Health.lua

+19-16
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ local E, L, V, P, G = unpack(ElvUI)
22
local UF = E:GetModule('UnitFrames')
33
local ElvUF = E.oUF
44

5+
local _G = _G
56
local random = random
67
local strmatch = strmatch
8+
79
local CreateFrame = CreateFrame
10+
local UnitInPartyIsAI = UnitInPartyIsAI
11+
local UnitIsCharmed = UnitIsCharmed
12+
local UnitIsEnemy = UnitIsEnemy
13+
local UnitIsFriend = UnitIsFriend
14+
local UnitIsPlayer = UnitIsPlayer
815
local UnitIsTapDenied = UnitIsTapDenied
916
local UnitReaction = UnitReaction
10-
local UnitIsPlayer = UnitIsPlayer
1117
local UnitClass = UnitClass
12-
local UnitIsConnected = UnitIsConnected
13-
local UnitIsDeadOrGhost = UnitIsDeadOrGhost
14-
local UnitIsCharmed = UnitIsCharmed
15-
local UnitIsFriend = UnitIsFriend
16-
local UnitIsEnemy = UnitIsEnemy
17-
local UnitInPartyIsAI = UnitInPartyIsAI
1818

1919
local BACKDROP_MULT = 0.35
2020

@@ -252,19 +252,25 @@ local HOSTILE_REACTION = 2
252252
function UF:PostUpdateHealthColor(unit, r, g, b)
253253
local parent = self:GetParent()
254254
local colors = E.db.unitframe.colors
255+
local env = (parent.isForced and UF.ConfigEnv) or _G
255256

256257
local isTapped = UnitIsTapDenied(unit)
257-
local isDeadOrGhost = UnitIsDeadOrGhost(unit)
258+
local isDeadOrGhost = env.UnitIsDeadOrGhost(unit)
258259
local healthBreak = not isTapped and colors.healthBreak
259260

260261
local color -- main bar
261262
if not b then
262263
r, g, b = colors.health.r, colors.health.g, colors.health.b
263264
end
264265

266+
-- Recheck offline status when forced
267+
if parent.isForced and self.colorDisconnected and not env.UnitIsConnected(unit) then
268+
color = parent.colors.disconnected
269+
end
270+
265271
-- Charmed player should have hostile color
266272
if unit and (strmatch(unit, 'raid%d+') or strmatch(unit, 'party%d+')) then
267-
if not isDeadOrGhost and UnitIsConnected(unit) and UnitIsCharmed(unit) and UnitIsEnemy('player', unit) then
273+
if not isDeadOrGhost and env.UnitIsConnected(unit) and UnitIsCharmed(unit) and UnitIsEnemy('player', unit) then
268274
color = parent.colors.reaction[HOSTILE_REACTION]
269275
end
270276
end
@@ -339,14 +345,11 @@ end
339345
function UF:PostUpdateHealth(_, cur)
340346
local parent = self:GetParent()
341347
if parent.isForced then
342-
cur = random(1, 100)
343-
local max = 100
344-
345-
self.cur = cur
346-
self.max = max
348+
self.cur = random(1, 100)
349+
self.max = 100
347350

348-
self:SetMinMaxValues(0, max)
349-
self:SetValue(cur)
351+
self:SetMinMaxValues(0, self.max)
352+
self:SetValue(self.cur)
350353
elseif parent.ResurrectIndicator then
351354
parent.ResurrectIndicator:SetAlpha(cur == 0 and 1 or 0)
352355
end

0 commit comments

Comments
 (0)