Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

power: Add support for atlas textures #694

Merged
merged 5 commits into from
Dec 1, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 34 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,40 @@ 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
element:SetStatusBarColor(r, g, b)
p3lim marked this conversation as resolved.
Show resolved Hide resolved

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)
p3lim marked this conversation as resolved.
Show resolved Hide resolved
--]]
if(element.PostUpdateColor) then
element:PostUpdateColor(unit, r, g, b)
element:PostUpdateColor(unit, r, g, b, atlas)
end
end

Expand Down Expand Up @@ -398,6 +412,10 @@ local function Enable(self)
element:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
end

if(element.useAtlas) then
element.__texture = element:GetStatusBarTexture():GetTexture()
p3lim marked this conversation as resolved.
Show resolved Hide resolved
end

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