Skip to content

Commit

Permalink
oUF Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Wutname1 committed Dec 6, 2024
1 parent 9ec80dd commit 542f8aa
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,6 @@
"libs\\oUF_Plugins",
"Modules",
"Themes",
"~\\.vscode\\extensions\\ketho.wow-api-0.17.6\\Annotations"
"~\\.vscode\\extensions\\ketho.wow-api-0.17.8\\Annotations"
]
}
7 changes: 5 additions & 2 deletions libs/oUF/.luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ read_globals = {
'GetUnitTotalModifiedMaxHealthPercent',
'HasLFGRestrictions',
'InCombatLockdown',
'IsInInstance',
'IsLoggedIn',
'IsPlayerSpell',
'IsResting',
Expand All @@ -107,32 +108,34 @@ read_globals = {
'UnitClassBase',
'UnitExists',
'UnitFactionGroup',
'UnitGUID',
'UnitGetIncomingHeals',
'UnitGetTotalAbsorbs',
'UnitGetTotalHealAbsorbs',
'UnitGroupRolesAssigned',
'UnitGUID',
'UnitHasIncomingResurrection',
'UnitHasVehiclePlayerFrameUI',
'UnitHasVehicleUI',
'UnitHealth',
'UnitHealthMax',
'UnitHonorLevel',
'UnitInParty',
'UnitInPartyIsAI',
'UnitInRaid',
'UnitInRange',
'UnitIsConnected',
'UnitIsGroupAssistant',
'UnitIsGroupLeader',
'UnitIsMercenary',
'UnitIsOwnerOrControllerOfUnit',
'UnitIsPlayer',
'UnitIsPVP',
'UnitIsPVPFreeForAll',
'UnitIsPlayer',
'UnitIsQuestBoss',
'UnitIsTapDenied',
'UnitIsUnit',
'UnitIsVisible',
'UnitLeadsAnyGroup',
'UnitPhaseReason',
'UnitPlayerControlled',
'UnitPower',
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion libs/oUF/blizzard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local _, ns = ...
local oUF = ns.oUF

-- sourced from Blizzard_UnitFrame/TargetFrame.lua
local MAX_BOSS_FRAMES = _G.MAX_BOSS_FRAMES or 5
local MAX_BOSS_FRAMES = 8 -- blizzard can spawn more than the default 5 apparently

-- sourced from Blizzard_FrameXMLBase/Shared/Constants.lua
local MEMBERS_PER_RAID_GROUP = _G.MEMBERS_PER_RAID_GROUP or 5
Expand Down
4 changes: 3 additions & 1 deletion libs/oUF/elements/alternativepower.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ local function updateTooltip(self)
end

local function onEnter(self)
if(not self:IsVisible()) then return end
if(GameTooltip:IsForbidden() or not self:IsVisible()) then return end

GameTooltip_SetDefaultAnchor(GameTooltip, self)
self:UpdateTooltip()
end

local function onLeave()
if(GameTooltip:IsForbidden()) then return end

GameTooltip:Hide()
end

Expand Down
17 changes: 8 additions & 9 deletions libs/oUF/elements/combatindicator.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--[[
# Element: Combat Indicator
Toggles the visibility of an indicator based on the player's combat status.
Toggles the visibility of an indicator based on the unit's combat status.
## Widget
Expand All @@ -25,7 +25,8 @@ A default texture will be applied if the widget is a Texture and doesn't have a
local _, ns = ...
local oUF = ns.oUF

local function Update(self, event)
local function Update(self, event, unit)
if(not unit or self.unit ~= unit) then return end
local element = self.CombatIndicator

--[[ Callback: CombatIndicator:PreUpdate()
Expand All @@ -37,7 +38,7 @@ local function Update(self, event)
element:PreUpdate()
end

local inCombat = UnitAffectingCombat('player')
local inCombat = UnitAffectingCombat(unit)
if(inCombat) then
element:Show()
else
Expand All @@ -48,7 +49,7 @@ local function Update(self, event)
Called after the element has been updated.
* self - the CombatIndicator element
* inCombat - indicates if the player is affecting combat (boolean)
* inCombat - indicates if the unit is affecting combat (boolean)
--]]
if(element.PostUpdate) then
return element:PostUpdate(inCombat)
Expand All @@ -71,12 +72,11 @@ end

local function Enable(self, unit)
local element = self.CombatIndicator
if(element and UnitIsUnit(unit, 'player')) then
if(element) then
element.__owner = self
element.ForceUpdate = ForceUpdate

self:RegisterEvent('PLAYER_REGEN_DISABLED', Path, true)
self:RegisterEvent('PLAYER_REGEN_ENABLED', Path, true)
self:RegisterEvent('UNIT_FLAGS', Path)

if(element:IsObjectType('Texture') and not element:GetTexture()) then
element:SetTexture([[Interface\CharacterFrame\UI-StateIcon]])
Expand All @@ -92,8 +92,7 @@ local function Disable(self)
if(element) then
element:Hide()

self:UnregisterEvent('PLAYER_REGEN_DISABLED', Path)
self:UnregisterEvent('PLAYER_REGEN_ENABLED', Path)
self:UnregisterEvent('UNIT_FLAGS', Path)
end
end

Expand Down
10 changes: 9 additions & 1 deletion libs/oUF/elements/leaderindicator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ local function Update(self, event)
-- UnitLeadsAnyGroup(unit). Inside the group formed by the dungeon finder UnitIsGroupLeader(unit) will only return
-- true for the instance leader.
local isInLFGInstance = HasLFGRestrictions()
local isLeader = UnitIsGroupLeader(unit)
local isLeader
if(IsInInstance()) then
isLeader = UnitIsGroupLeader(unit)
else
isLeader = UnitLeadsAnyGroup(unit)
end

if(isLeader) then
if(isInLFGInstance) then
element:SetTexture([[Interface\LFGFrame\UI-LFG-ICON-PORTRAITROLES]])
Expand Down Expand Up @@ -96,6 +102,7 @@ local function Enable(self)
element.__owner = self
element.ForceUpdate = ForceUpdate

self:RegisterEvent('UNIT_FLAGS', Path)
self:RegisterEvent('PARTY_LEADER_CHANGED', Path, true)
self:RegisterEvent('GROUP_ROSTER_UPDATE', Path, true)

Expand All @@ -108,6 +115,7 @@ local function Disable(self)
if(element) then
element:Hide()

self:UnregisterEvent('UNIT_FLAGS', Path)
self:UnregisterEvent('PARTY_LEADER_CHANGED', Path)
self:UnregisterEvent('GROUP_ROSTER_UPDATE', Path)
end
Expand Down
4 changes: 3 additions & 1 deletion libs/oUF/elements/phaseindicator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ local function UpdateTooltip(element)
end

local function onEnter(element)
if(not element:IsVisible()) then return end
if(GameTooltip:IsForbidden() or not element:IsVisible()) then return end

if(element.reason) then
GameTooltip:SetOwner(element, 'ANCHOR_BOTTOMRIGHT')
Expand All @@ -59,6 +59,8 @@ local function onEnter(element)
end

local function onLeave()
if(GameTooltip:IsForbidden()) then return end

GameTooltip:Hide()
end

Expand Down
8 changes: 7 additions & 1 deletion libs/oUF/elements/portrait.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ local function Update(self, event, unit)
element:SetUnit(unit)
end
else
local class = element.showClass and UnitClassBase(unit)
local class, _
if(element.showClass) then
-- BUG: UnitClassBase can't be trusted
-- https://github.com/Stanzilla/WoWUIBugs/issues/621
_, class = UnitClass(unit)
end

if(class) then
element:SetAtlas('classicon-' .. class)
else
Expand Down
56 changes: 39 additions & 17 deletions libs/oUF/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 @@ -219,7 +236,8 @@ local function Update(self, event, unit)
end

local cur, max = UnitPower(unit, displayType), UnitPowerMax(unit, displayType)
element:SetMinMaxValues(min or 0, max)
min = min or 0 -- ensure we always have a minimum value to avoid errors
element:SetMinMaxValues(min, max)

if(UnitIsConnected(unit)) then
element:SetValue(cur)
Expand Down Expand Up @@ -398,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
3 changes: 2 additions & 1 deletion libs/oUF/elements/runes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ local function Update(self, event)
hasSortOrder = false
end

local currentTime = GetTime()
local rune, start, duration, runeReady
for index, runeID in next, runemap do
rune = element[index]
Expand All @@ -156,7 +157,7 @@ local function Update(self, event)
rune:SetValue(1)
rune:SetScript('OnUpdate', nil)
elseif(start) then
rune.duration = GetTime() - start
rune.duration = currentTime - start
rune:SetMinMaxValues(0, duration)
rune:SetValue(0)
rune:SetScript('OnUpdate', onUpdate)
Expand Down
16 changes: 11 additions & 5 deletions libs/oUF/elements/totems.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ OnEnter and OnLeave script handlers will be set to display a Tooltip if the `Tot
## Examples
local Totems = {}
for index = 1, 5 do
for index = 1, 4 do
-- Position and size of the totem indicator
local Totem = CreateFrame('Button', nil, self)
Totem:SetSize(40, 40)
Expand All @@ -48,18 +48,25 @@ OnEnter and OnLeave script handlers will be set to display a Tooltip if the `Tot
local _, ns = ...
local oUF = ns.oUF

local TOTEM_PRIORITIES = _G.STANDARD_TOTEM_PRIORITIES
if(UnitClassBase('player') == 'SHAMAN') then
TOTEM_PRIORITIES = _G.SHAMAN_TOTEM_PRIORITIES
end

local function UpdateTooltip(self)
GameTooltip:SetTotem(self:GetID())
end

local function OnEnter(self)
if(not self:IsVisible()) then return end
if(GameTooltip:IsForbidden() or not self:IsVisible()) then return end

GameTooltip:SetOwner(self, 'ANCHOR_BOTTOMRIGHT')
self:UpdateTooltip()
end

local function OnLeave()
if(GameTooltip:IsForbidden()) then return end

GameTooltip:Hide()
end

Expand All @@ -75,7 +82,7 @@ local function UpdateTotem(self, event, slot)
--]]
if(element.PreUpdate) then element:PreUpdate(slot) end

local totem = element[slot]
local totem = element[TOTEM_PRIORITIES[slot]]
local haveTotem, name, start, duration, icon = GetTotemInfo(slot)
if(haveTotem and duration > 0) then
if(totem.Icon) then
Expand Down Expand Up @@ -135,8 +142,7 @@ local function Enable(self)
element.ForceUpdate = ForceUpdate

for i = 1, #element do
local totem = element[i]

local totem = element[TOTEM_PRIORITIES[i]]
totem:SetID(i)

if(totem:IsMouseEnabled()) then
Expand Down
2 changes: 2 additions & 0 deletions libs/oUF/oUF.lua
Original file line number Diff line number Diff line change
Expand Up @@ -834,11 +834,13 @@ function oUF:SpawnNamePlates(namePrefix, nameplateCallback, nameplateCVars)
if(nameplate.UnitFrame) then
if(nameplate.UnitFrame.WidgetContainer) then
nameplate.UnitFrame.WidgetContainer:SetParent(nameplate.unitFrame)
nameplate.UnitFrame.WidgetContainer:SetIgnoreParentAlpha(true)
nameplate.unitFrame.WidgetContainer = nameplate.UnitFrame.WidgetContainer
end

if(nameplate.UnitFrame.SoftTargetFrame) then
nameplate.UnitFrame.SoftTargetFrame:SetParent(nameplate.unitFrame)
nameplate.UnitFrame.SoftTargetFrame:SetIgnoreParentAlpha(true)
nameplate.unitFrame.SoftTargetFrame = nameplate.UnitFrame.SoftTargetFrame
end
end
Expand Down

0 comments on commit 542f8aa

Please sign in to comment.