Skip to content

Commit

Permalink
elements: retrive RGB values by name instead of index
Browse files Browse the repository at this point in the history
This is in preparation to ditch the array part we added to
ColorMixin for backwards compatibility.
I keep the direct tble access instead of calling color:getRGB()
for perfomance.
  • Loading branch information
Rainrider committed Mar 27, 2022
1 parent 5007027 commit a418179
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 52 deletions.
10 changes: 5 additions & 5 deletions elements/additionalpower.lua
Expand Up @@ -68,17 +68,17 @@ local function UpdateColor(self, event, unit, powerType)
if(not (unit and UnitIsUnit(unit, 'player') and powerType == ADDITIONAL_POWER_BAR_NAME)) then return end
local element = self.AdditionalPower
local r, g, b, t
local r, g, b, color
if(element.colorPower) then
t = self.colors.power[ADDITIONAL_POWER_BAR_INDEX]
color = self.colors.power[ADDITIONAL_POWER_BAR_INDEX]
elseif(element.colorClass) then
t = self.colors.class[playerClass]
color = self.colors.class[playerClass]
elseif(element.colorSmooth) then
r, g, b = self:ColorGradient(element.cur or 1, element.max or 1, unpack(element.smoothGradient or self.colors.smooth))
end
if(t) then
r, g, b = t[1], t[2], t[3]
if(color) then
r, g, b = color.r, color.g, color.b
end
if(b) then
Expand Down
16 changes: 8 additions & 8 deletions elements/alternativepower.lua
Expand Up @@ -82,26 +82,26 @@ local function UpdateColor(self, event, unit, powerType)
if(self.unit ~= unit or powerType ~= ALTERNATE_POWER_NAME) then return end
local element = self.AlternativePower
local r, g, b, t
local r, g, b, color
if(element.colorThreat and not UnitPlayerControlled(unit) and UnitThreatSituation('player', unit)) then
t = self.colors.threat[UnitThreatSituation('player', unit)]
color = self.colors.threat[UnitThreatSituation('player', unit)]
elseif(element.colorPower) then
t = self.colors.power[ALTERNATE_POWER_INDEX]
color = self.colors.power[ALTERNATE_POWER_INDEX]
elseif(element.colorClass and UnitIsPlayer(unit))
or (element.colorClassNPC and not UnitIsPlayer(unit)) then
local _, class = UnitClass(unit)
t = self.colors.class[class]
color = self.colors.class[class]
elseif(element.colorSelection and unitSelectionType(unit, element.considerSelectionInCombatHostile)) then
t = self.colors.selection[unitSelectionType(unit, element.considerSelectionInCombatHostile)]
color = self.colors.selection[unitSelectionType(unit, element.considerSelectionInCombatHostile)]
elseif(element.colorReaction and UnitReaction(unit, 'player')) then
t = self.colors.reaction[UnitReaction(unit, 'player')]
color = self.colors.reaction[UnitReaction(unit, 'player')]
elseif(element.colorSmooth) then
local adjust = 0 - (element.min or 0)
r, g, b = self:ColorGradient((element.cur or 1) + adjust, (element.max or 1) + adjust, unpack(element.smoothGradient or self.colors.smooth))
end
if(t) then
r, g, b = t[1], t[2], t[3]
if(color) then
r, g, b = color.r, color.g, color.b
end
if(b) then
Expand Down
2 changes: 1 addition & 1 deletion elements/auras.lua
Expand Up @@ -215,7 +215,7 @@ local function updateIcon(element, unit, index, offset, filter, isDebuff, visibl
if((isDebuff and element.showDebuffType) or (not isDebuff and element.showBuffType) or element.showType) then
local color = element.__owner.colors.debuff[debuffType] or element.__owner.colors.debuff.none
button.overlay:SetVertexColor(color[1], color[2], color[3])
button.overlay:SetVertexColor(color.r, color.g, color.b)
button.overlay:Show()
else
button.overlay:Hide()
Expand Down
2 changes: 1 addition & 1 deletion elements/classpower.lua
Expand Up @@ -67,7 +67,7 @@ local RequireSpec, RequirePower, RequireSpell
local function UpdateColor(element, powerType)
local color = element.__owner.colors.power[powerType]
local r, g, b = color[1], color[2], color[3]
local r, g, b = color.r, color.g, color.b
for i = 1, #element do
local bar = element[i]
bar:SetStatusBarColor(r, g, b)
Expand Down
20 changes: 10 additions & 10 deletions elements/health.lua
Expand Up @@ -86,30 +86,30 @@ local function UpdateColor(self, event, unit)
if(not unit or self.unit ~= unit) then return end
local element = self.Health
local r, g, b, t
local r, g, b, color
if(element.colorDisconnected and not UnitIsConnected(unit)) then
t = self.colors.disconnected
color = self.colors.disconnected
elseif(element.colorTapping and not UnitPlayerControlled(unit) and UnitIsTapDenied(unit)) then
t = self.colors.tapped
color = self.colors.tapped
elseif(element.colorThreat and not UnitPlayerControlled(unit) and UnitThreatSituation('player', unit)) then
t = self.colors.threat[UnitThreatSituation('player', unit)]
color = self.colors.threat[UnitThreatSituation('player', unit)]
elseif(element.colorClass and UnitIsPlayer(unit))
or (element.colorClassNPC and not UnitIsPlayer(unit))
or (element.colorClassPet and UnitPlayerControlled(unit) and not UnitIsPlayer(unit)) then
local _, class = UnitClass(unit)
t = self.colors.class[class]
color = self.colors.class[class]
elseif(element.colorSelection and unitSelectionType(unit, element.considerSelectionInCombatHostile)) then
t = self.colors.selection[unitSelectionType(unit, element.considerSelectionInCombatHostile)]
color = self.colors.selection[unitSelectionType(unit, element.considerSelectionInCombatHostile)]
elseif(element.colorReaction and UnitReaction(unit, 'player')) then
t = self.colors.reaction[UnitReaction(unit, 'player')]
color = self.colors.reaction[UnitReaction(unit, 'player')]
elseif(element.colorSmooth) then
r, g, b = self:ColorGradient(element.cur or 1, element.max or 1, unpack(element.smoothGradient or self.colors.smooth))
elseif(element.colorHealth) then
t = self.colors.health
color = self.colors.health
end
if(t) then
r, g, b = t[1], t[2], t[3]
if(color) then
r, g, b = color.r, color.g, color.b
end
if(b) then
Expand Down
26 changes: 13 additions & 13 deletions elements/power.lua
Expand Up @@ -120,17 +120,17 @@ local function UpdateColor(self, event, unit)
local pType, pToken, altR, altG, altB = UnitPowerType(unit)
local r, g, b, t
local r, g, b, color
if(element.colorDisconnected and not UnitIsConnected(unit)) then
t = self.colors.disconnected
color = self.colors.disconnected
elseif(element.colorTapping and not UnitPlayerControlled(unit) and UnitIsTapDenied(unit)) then
t = self.colors.tapped
color = self.colors.tapped
elseif(element.colorThreat and not UnitPlayerControlled(unit) and UnitThreatSituation('player', unit)) then
t = self.colors.threat[UnitThreatSituation('player', unit)]
color = self.colors.threat[UnitThreatSituation('player', unit)]
elseif(element.colorPower) then
if(element.displayType ~= ALTERNATE_POWER_INDEX) then
t = self.colors.power[pToken]
if(not t) then
color = self.colors.power[pToken]
if(not color) then
if(element.GetAlternativeColor) then
r, g, b = element:GetAlternativeColor(unit, pType, pToken, altR, altG, altB)
elseif(altR) then
Expand All @@ -140,28 +140,28 @@ local function UpdateColor(self, event, unit)
r, g, b = r / 255, g / 255, b / 255
end
else
t = self.colors.power[pType] or self.colors.power.MANA
color = self.colors.power[pType] or self.colors.power.MANA
end
end
else
t = self.colors.power[ALTERNATE_POWER_INDEX]
color = self.colors.power[ALTERNATE_POWER_INDEX]
end
elseif(element.colorClass and UnitIsPlayer(unit))
or (element.colorClassNPC and not UnitIsPlayer(unit))
or (element.colorClassPet and UnitPlayerControlled(unit) and not UnitIsPlayer(unit)) then
local _, class = UnitClass(unit)
t = self.colors.class[class]
color = self.colors.class[class]
elseif(element.colorSelection and unitSelectionType(unit, element.considerSelectionInCombatHostile)) then
t = self.colors.selection[unitSelectionType(unit, element.considerSelectionInCombatHostile)]
color = self.colors.selection[unitSelectionType(unit, element.considerSelectionInCombatHostile)]
elseif(element.colorReaction and UnitReaction(unit, 'player')) then
t = self.colors.reaction[UnitReaction(unit, 'player')]
color = self.colors.reaction[UnitReaction(unit, 'player')]
elseif(element.colorSmooth) then
local adjust = 0 - (element.min or 0)
r, g, b = self:ColorGradient((element.cur or 1) + adjust, (element.max or 1) + adjust, unpack(element.smoothGradient or self.colors.smooth))
end
if(t) then
r, g, b = t[1], t[2], t[3]
if(color) then
r, g, b = color.r, color.g, color.b
end
if(b) then
Expand Down
2 changes: 1 addition & 1 deletion elements/runes.lua
Expand Up @@ -92,7 +92,7 @@ local function UpdateColor(self, event)
color = self.colors.power.RUNES
end
local r, g, b = color[1], color[2], color[3]
local r, g, b = color.r, color.g, color.b
for index = 1, #element do
element[index]:SetStatusBarColor(r, g, b)
Expand Down
12 changes: 6 additions & 6 deletions elements/stagger.lua
Expand Up @@ -56,18 +56,18 @@ local function UpdateColor(self, event, unit)
local colors = self.colors.power[BREWMASTER_POWER_BAR_NAME]
local perc = (element.cur or 0) / (element.max or 1)
local t
local color
if(perc >= STAGGER_RED_TRANSITION) then
t = colors and colors[STAGGER_RED_INDEX]
color = colors and colors[STAGGER_RED_INDEX]
elseif(perc > STAGGER_YELLOW_TRANSITION) then
t = colors and colors[STAGGER_YELLOW_INDEX]
color = colors and colors[STAGGER_YELLOW_INDEX]
else
t = colors and colors[STAGGER_GREEN_INDEX]
color = colors and colors[STAGGER_GREEN_INDEX]
end
local r, g, b
if(t) then
r, g, b = t[1], t[2], t[3]
if(color) then
r, g, b = color.r, color.g, color.b
if(b) then
element:SetStatusBarColor(r, g, b)
Expand Down
3 changes: 2 additions & 1 deletion elements/threatindicator.lua
Expand Up @@ -61,7 +61,8 @@ local function Update(self, event, unit)
local r, g, b
if(status and status > 0) then
r, g, b = unpack(self.colors.threat[status])
local color = self.colors.threat[status]
r, g, b = color.r, color.g, color.b
if(element.SetVertexColor) then
element:SetVertexColor(r, g, b)
Expand Down
12 changes: 6 additions & 6 deletions units.lua
Expand Up @@ -46,22 +46,22 @@ local function updateArenaPreparationElements(self, event, elementName, specID)
element:UpdateColorArenaPreparation(specID)
else
-- this section just replicates the color options available to the Health and Power elements
local r, g, b, t, _
local r, g, b, color, _
-- if(element.colorPower and elementName == 'Power') then
-- FIXME: no idea if we can get power type here without the unit
if(element.colorClass) then
local _, _, _, _, _, class = GetSpecializationInfoByID(specID)
t = self.colors.class[class]
color = self.colors.class[class]
elseif(element.colorReaction) then
t = self.colors.reaction[2]
color = self.colors.reaction[2]
elseif(element.colorSmooth) then
_, _, _, _, _, _, r, g, b = unpack(element.smoothGradient or self.colors.smooth)
elseif(element.colorHealth and elementName == 'Health') then
t = self.colors.health
color = self.colors.health
end
if(t) then
r, g, b = t[1], t[2], t[3]
if(color) then
r, g, b = color.r, color.g, color.b
end
if(r or g or b) then
Expand Down

0 comments on commit a418179

Please sign in to comment.