Skip to content

Commit

Permalink
power: Add support for atlas textures
Browse files Browse the repository at this point in the history
  • Loading branch information
p3lim committed Nov 20, 2024
1 parent 91d0de9 commit 407a457
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions elements/power.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ A default texture will be applied if the widget is a StatusBar and doesn't have
.displayAltPower - Use this to let the widget display alternative power, if the unit has one.
By default, it does so only for raid and party units. If none, the display will fall
back to the primary power (boolean)
.useAtlas - Use the atlas associated with the power color for the texture if available (boolean)
.smoothGradient - 9 color values to be used with the .colorSmooth option (table)
.considerSelectionInCombatHostile - Indicates whether selection should be considered hostile while the unit is in
combat with the player (boolean)
Expand Down Expand Up @@ -120,7 +121,7 @@ local function UpdateColor(self, event, unit)

local pType, pToken, altR, altG, altB = UnitPowerType(unit)

local r, g, b, color
local r, g, b, color, atlas
if(element.colorDisconnected and not UnitIsConnected(unit)) then
color = self.colors.disconnected
elseif(element.colorTapping and not UnitPlayerControlled(unit) and UnitIsTapDenied(unit)) then
Expand All @@ -146,6 +147,10 @@ local function UpdateColor(self, event, unit)
else
color = self.colors.power[ALTERNATE_POWER_INDEX]
end

if(element.useAtlas and color and color.atlas) then
atlas = color.atlas
end
elseif(element.colorClass and (UnitIsPlayer(unit) or UnitInPartyIsAI(unit)))
or (element.colorClassNPC and not (UnitIsPlayer(unit) or UnitInPartyIsAI(unit)))
or (element.colorClassPet and UnitPlayerControlled(unit) and not UnitIsPlayer(unit)) then
Expand All @@ -160,31 +165,37 @@ local function UpdateColor(self, event, unit)
r, g, b = self:ColorGradient((element.cur or 1) + adjust, (element.max or 1) + adjust, unpack(element.smoothGradient or self.colors.smooth))
end

if(color) then
r, g, b = color[1], color[2], color[3]
end
if(atlas) then
element:SetStatusBarTexture(atlas)
element:SetStatusBarColor(1, 1, 1)
else
if(color) then
r, g, b = color[1], color[2], color[3]
end

if(b) then
element:SetStatusBarColor(r, g, b)
if(b) then
element:SetStatusBarColor(r, g, b)

local bg = element.bg
if(bg) then
local mu = bg.multiplier or 1
bg:SetVertexColor(r * mu, g * mu, b * mu)
local bg = element.bg
if(bg) then
local mu = bg.multiplier or 1
bg:SetVertexColor(r * mu, g * mu, b * mu)
end
end
end

--[[ Callback: Power:PostUpdateColor(unit, r, g, b)
Called after the element color has been updated.
* self - the Power element
* unit - the unit for which the update has been triggered (string)
* r - the red component of the used color (number)[0-1]
* g - the green component of the used color (number)[0-1]
* b - the blue component of the used color (number)[0-1]
* self - the Power element
* unit - the unit for which the update has been triggered (string)
* r - the red component of the used color (number?)[0-1]
* g - the green component of the used color (number?)[0-1]
* b - the blue component of the used color (number?)[0-1]
* atlas - the atlas used instead of color (string)
--]]
if(element.PostUpdateColor) then
element:PostUpdateColor(unit, r, g, b)
element:PostUpdateColor(unit, r, g, b, atlas)
end
end

Expand Down

0 comments on commit 407a457

Please sign in to comment.