Skip to content

Commit

Permalink
power: Add support for atlas textures (#694)
Browse files Browse the repository at this point in the history
  • Loading branch information
p3lim authored Dec 1, 2024
1 parent ad3375c commit 69b0819
Showing 1 changed file with 37 additions and 16 deletions.
53 changes: 37 additions & 16 deletions elements/power.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ The following options are listed by priority. The first check that returns true
.colorTapping - Use `self.colors.tapping` to color the bar if the unit isn't tapped by the player (boolean)
.colorThreat - Use `self.colors.threat[threat]` to color the bar based on the unit's threat status. `threat` is
defined by the first return of [UnitThreatSituation](https://warcraft.wiki.gg/wiki/API_UnitThreatSituation) (boolean)
.colorPowerAtlas - Use `self.colors.power[token].atlas` to replace the texture whenever it's available. The previously
defined texture (if any) will be restored if the color changes to one that doesn't have an atlas
(boolean)
.colorPower - Use `self.colors.power[token]` to color the bar based on the unit's power type. This method will
fall-back to `:GetAlternativeColor()` if it can't find a color matching the token. If this function
isn't defined, then it will attempt to color based upon the alternative power colors returned by
Expand Down Expand Up @@ -120,7 +123,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 +149,10 @@ local function UpdateColor(self, event, unit)
else
color = self.colors.power[ALTERNATE_POWER_INDEX]
end

if(element.colorPowerAtlas and color) 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 +167,41 @@ 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
if(element.__texture) then
element:SetStatusBarTexture(element.__texture)
end

local bg = element.bg
if(bg) then
local mu = bg.multiplier or 1
bg:SetVertexColor(r * mu, g * mu, b * mu)
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)
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 Expand Up @@ -399,6 +416,10 @@ local function Enable(self)
element:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
end

if(element.colorPowerAtlas) then
element.__texture = element.__texture or element:GetStatusBarTexture():GetTexture()
end

if(not element.GetDisplayPower) then
element.GetDisplayPower = GetDisplayPower
end
Expand Down

0 comments on commit 69b0819

Please sign in to comment.