Skip to content

Commit

Permalink
tweaks and fixes to unitframe module
Browse files Browse the repository at this point in the history
  • Loading branch information
ffainy committed Apr 16, 2022
1 parent ceed82f commit 4b586fc
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 62 deletions.
6 changes: 5 additions & 1 deletion gui/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ local function UpdateGCDTicker()
UNITFRAME:UpdateGCDTicker()
end

local function UpdateClassPower()
UNITFRAME:UpdateClassPower()
end

local function UpdatePortrait()
UNITFRAME:UpdatePortrait()
end
Expand Down Expand Up @@ -587,7 +591,7 @@ GUI.OptionsList = {
{1, 'Unitframe', 'Portrait', L['Portrait'], nil, nil, UpdatePortrait, L['Show dynamic portrait on unit frame.']},
{1, 'Unitframe', 'GCDIndicator', L['GCD Indicator'], true, nil, UpdateGCDTicker, L['Show global cooldown ticker above the player frame.']},
{1, 'Unitframe', 'AbbrName', L['Abbreviate Name'], nil, nil, UpdateUnitTags},
{1, 'Unitframe', 'ClassPower', L['Class Power'], true, SetupClassPower, nil, L['Show special resources of the class, such as Combo Points, Holy Power, Chi, Runes, etc.']},
{1, 'Unitframe', 'ClassPower', L['Class Power'], true, SetupClassPower, UpdateClassPower, L['Show special resources of the class, such as Combo Points, Holy Power, Chi, Runes, etc.']},
{1, 'Unitframe', 'HidePlayerTags', L['Hide Player Tags'], nil, nil, UpdateUnitTags, L['Only show player tags on mouseover.']},
{},
{1, 'Unitframe', 'OnlyShowPlayer', L['Player Debuffs Only'], nil, nil, nil, L['Display debuffs cast by player only.']},
Expand Down
2 changes: 1 addition & 1 deletion libs/oUF/elements/castbar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ local function CastStart(self, event, unit)
else
nameStr = string.format('%s%s|r', hexStr, tarName)
end
if(element.Text) then element.Text:SetFormattedText('%s (%s)', name, nameStr) end
if(element.Text and element.SpellTarget) then element.Text:SetFormattedText('%s (%s)', name, nameStr) end
else
resetSpellTarget(self) -- when unit loses target
end
Expand Down
32 changes: 31 additions & 1 deletion modules/unitframe/auras.lua
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,33 @@ function UNITFRAME:UpdateAuras()
end
end

local function UpdatePlayerAuraPosition(self)
local specIndex = GetSpecialization()

if
(C.CLASS == 'ROGUE'
or C.CLASS == 'PALADIN'
or C.CLASS == 'WARLOCK'
or (C.CLASS == 'DRUID' and specIndex == 2)
or (C.CLASS == 'MONK' and specIndex == 3)
or (C.CLASS == 'MAGE' and specIndex == 1))
and C.DB.Unitframe.ClassPower
then
self.Auras:ClearAllPoints()
self.Auras:SetPoint('TOP', self.ClassPowerBar, 'BOTTOM', 0, -5)
else
self.Auras:ClearAllPoints()
self.Auras:SetPoint('TOP', self.Power, 'BOTTOM', 0, -5)
end

self:UnregisterEvent('PLAYER_ENTERING_WORLD', UpdatePlayerAuraPosition, true)
end

function UNITFRAME:UpdatePlayerAuraPosition(self)
self:RegisterEvent('PLAYER_ENTERING_WORLD', UpdatePlayerAuraPosition, true)
self:RegisterEvent('PLAYER_TALENT_UPDATE', UpdatePlayerAuraPosition, true)
end

function UNITFRAME:CreateAuras(self)
local style = self.unitStyle
local bu = CreateFrame('Frame', nil, self)
Expand All @@ -346,7 +373,7 @@ function UNITFRAME:CreateAuras(self)

if style == 'player' then
bu.initialAnchor = 'TOPLEFT'
bu:SetPoint('TOP', self.Power, 'BOTTOM', 0, -4)
bu:SetPoint('TOP', self.Power, 'BOTTOM', 0, -5)
bu['growth-x'] = 'RIGHT'
bu['growth-y'] = 'DOWN'
bu.__value = 'Player'
Expand Down Expand Up @@ -662,3 +689,6 @@ function UNITFRAME:RefreshAurasByCombat(self)
self:RegisterEvent('PLAYER_REGEN_ENABLED', RefreshAurasElements, true)
self:RegisterEvent('PLAYER_REGEN_DISABLED', RefreshAurasElements, true)
end



6 changes: 3 additions & 3 deletions modules/unitframe/castbar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function UNITFRAME:PostCastStart(unit)

self:SetAlpha(1)
self.Spark:Show()
self.Text:SetTextColor(unpack(textColor))
--self.Text:SetTextColor(unpack(textColor))

if unit == 'vehicle' or UnitInVehicle('player') then
if self.SafeZone then
Expand Down Expand Up @@ -223,7 +223,7 @@ function UNITFRAME:PostUpdateInterruptible()
self.Border:SetBackdropBorderColor(0, 0, 0, .35)
end

self.Text:SetTextColor(unpack(textColor))
--self.Text:SetTextColor(unpack(textColor))
end

function UNITFRAME:PostCastStop()
Expand Down Expand Up @@ -448,7 +448,7 @@ function UNITFRAME:CreateNamePlateCastBar(self)




castbar.SpellTarget = true
castbar.OnUpdate = UNITFRAME.OnCastbarUpdate
castbar.PostCastStart = UNITFRAME.PostCastStart
castbar.PostCastUpdate = UNITFRAME.PostCastUpdate
Expand Down
127 changes: 93 additions & 34 deletions modules/unitframe/classpower.lua
Original file line number Diff line number Diff line change
@@ -1,44 +1,63 @@
local F, C = unpack(select(2, ...))
local UNITFRAME = F:GetModule('UnitFrame')
local oUF = F.Libs.oUF

local function SetLastBarColor(element, max, powerType)
if not element or not max then
return
end
local function PostUpdateClassPower(element, cur, max, diff, powerType, chargedPowerPoints)
local gap = 3

local color = element.__owner.colors.power.max[powerType]
if not cur or cur == 0 then
for i = 1, 6 do
element[i].bg:Hide()
end

if element[max] and color then
local r, g, b = color[1], color[2], color[3]
local lastBar = element[max]
lastBar:SetStatusBarColor(r, g, b)
end
end
element.prevColor = nil
else
for i = 1, max do
element[i].bg:Show()
end

local function PostUpdateClassPower(element, _, max, diff, powerType)
local gap = 3
local maxWidth = C.DB.Unitframe.PlayerWidth
element.thisColor = cur == max and 1 or 2
if not element.prevColor or element.prevColor ~= element.thisColor then
local r, g, b = 1, 0, 0
if element.thisColor == 2 then
local color = element.__owner.colors.power[powerType]
r, g, b = color[1], color[2], color[3]
end
for i = 1, #element do
element[i]:SetStatusBarColor(r, g, b)
end
element.prevColor = element.thisColor
end
end

if diff then
for i = 1, max do
element[i]:SetWidth((maxWidth - (max - 1) * gap) / max)
element[i]:SetWidth((element.__owner.ClassPowerBar:GetWidth() - (max - 1) * gap) / max)
end
for i = max + 1, 6 do
element[i].bg:Hide()
end
end

SetLastBarColor(element, max, powerType)
for i = 1, 6 do
local bar = element[i]
if not bar.chargeStar then
break
end

bar.chargeStar:SetShown(chargedPowerPoints and tContains(chargedPowerPoints, i))
end
end

function UNITFRAME:OnUpdateRunes(elapsed)
local duration = self.duration + elapsed
self.duration = duration
self:SetValue(duration)

if self.timer then
self.timer:SetText(nil)
if C.DB.Unitframe.RunesTimer then
local remain = self.runeDuration - duration
if remain > 0 then
self.timer:SetText(F:FormatTime(remain))
else
self.timer:SetText(nil)
end
end
end
Expand All @@ -51,55 +70,95 @@ local function PostUpdateRunes(element, runemap)
if runeReady then
rune:SetAlpha(1)
rune:SetScript('OnUpdate', nil)
if rune.timer then
rune.timer:SetText(nil)
end
rune.timer:SetText(nil)
elseif start then
rune:SetAlpha(.3)
rune:SetAlpha(.45)
rune.runeDuration = duration
rune:SetScript('OnUpdate', UNITFRAME.OnUpdateRunes)
end
end
end
end

function UNITFRAME:CreateClassPowerBar(self)
if not C.DB.Unitframe.ClassPower then
return
end

function UNITFRAME:CreateClassPower(self)
local gap = 3
local barWidth = C.DB.Unitframe.PlayerWidth
local barHeight = C.DB.Unitframe.ClassPowerHeight

local isDK = C.CLASS == 'DEATHKNIGHT'
local holder = CreateFrame('Frame', '$parentClassPowerBar', self)
holder:SetSize(barWidth, barHeight)
holder:SetPoint('TOPLEFT', self, 'BOTTOMLEFT', 0, -3)

if not isDK then
holder.bg = F.SetBD(holder)
holder.bg:SetFrameLevel(5)
holder.bg:SetBackdropBorderColor(1, .8, 0)
holder.bg:Hide()
end

local bars = {}
for i = 1, 6 do
bars[i] = CreateFrame('StatusBar', nil, self.ClassPowerBarHolder)
bars[i] = CreateFrame('StatusBar', 'FreeUIClassPower' .. i, holder)
bars[i]:SetHeight(barHeight)
bars[i]:SetWidth((barWidth - 5 * gap) / 6)
bars[i]:SetStatusBarTexture(C.Assets.Statusbar.Normal)
bars[i]:SetFrameLevel(self:GetFrameLevel() + 5)

F.SetBD(bars[i])
bars[i].__bg = F.SetBD(bars[i], 0)
bars[i].__bg:SetBackdropBorderColor(0, 0, 0, 1)

if i == 1 then
bars[i]:SetPoint('BOTTOMLEFT')
else
bars[i]:SetPoint('LEFT', bars[i - 1], 'RIGHT', gap, 0)
end

if C.CLASS == 'DEATHKNIGHT' and C.DB.Unitframe.RunesTimer then
bars[i].bg = bars[i]:CreateTexture(nil, 'BACKGROUND')
bars[i].bg:SetAllPoints(bars[i])
bars[i].bg:SetTexture(C.Assets.Statusbar.Flat)
bars[i].bg.multiplier = .25

if isDK then
bars[i].timer = F.CreateFS(bars[i], C.Assets.Font.Regular, 11, nil, '')
end
end

if C.CLASS == 'DEATHKNIGHT' then
if isDK then
bars.colorSpec = true
bars.sortOrder = 'asc'
bars.PostUpdate = PostUpdateRunes
bars.__max = 6
self.Runes = bars
else
bars.PostUpdate = PostUpdateClassPower
self.ClassPower = bars
end

self.ClassPowerBar = holder
end

function UNITFRAME:UpdateClassPower()
for _, frame in pairs(oUF.objects) do
if C.DB.Unitframe.ClassPower then
if not frame:IsElementEnabled('ClassPower') then
frame:EnableElement('ClassPower')
if frame.ClassPower then
frame.ClassPower:ForceUpdate()
end
end
if not frame:IsElementEnabled('Runes') then
frame:EnableElement('Runes')
if frame.Runes then
frame.Runes:ForceUpdate()
end
end
else
if frame:IsElementEnabled('ClassPower') then
frame:DisableElement('ClassPower')
end
if frame:IsElementEnabled('Runes') then
frame:DisableElement('Runes')
end
end
end
end
29 changes: 25 additions & 4 deletions modules/unitframe/power.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ local function PostUpdatePower(power, unit, _, _, max)
end
end

local function CheckSpellAvailability(power)
local spec = GetSpecialization() or 0
local isBDK = C.CLASS == 'DEATHKNIGHT' and spec == 1
local r, g, b = power:GetStatusBarColor()

if isBDK then
local _, noRunic = IsUsableSpell(49998)
if noRunic then
power:SetStatusBarColor(r/2, g/2, b/2)
else
power:SetStatusBarColor(r, g, b)
end
end
end

local function UpdatePowerColor(power, unit)
if unit ~= 'player' or UnitHasVehicleUI('player') then
return
Expand Down Expand Up @@ -58,6 +73,8 @@ local function UpdatePowerColor(power, unit)
end
end
end

CheckSpellAvailability(power)
end

function UNITFRAME:CreatePowerBar(self)
Expand Down Expand Up @@ -167,11 +184,15 @@ local function PostUpdateAltPower(self, _, cur, _, max)
end

if self:IsShown() then
parent.ClassPowerBarHolder:ClearAllPoints()
parent.ClassPowerBarHolder:SetPoint('TOPLEFT', self, 'BOTTOMLEFT', 0, -3)
if parent.ClassPowerBar then
parent.ClassPowerBar:ClearAllPoints()
parent.ClassPowerBar:SetPoint('TOPLEFT', self, 'BOTTOMLEFT', 0, -3)
end
else
parent.ClassPowerBarHolder:ClearAllPoints()
parent.ClassPowerBarHolder:SetPoint('TOPLEFT', parent, 'BOTTOMLEFT', 0, -3)
if parent.ClassPowerBar then
parent.ClassPowerBar:ClearAllPoints()
parent.ClassPowerBar:SetPoint('TOPLEFT', parent, 'BOTTOMLEFT', 0, -3)
end
end
end

Expand Down
18 changes: 3 additions & 15 deletions modules/unitframe/unitframe.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ local function UF_OnLeave(self)
self.Highlight:Hide()
end

function UNITFRAME:CreateBackdrop(self)
function UNITFRAME:CreateBackdrop(self, onKeyDown)
local highlight = self:CreateTexture(nil, 'OVERLAY')
highlight:SetAllPoints()
highlight:SetTexture('Interface\\PETBATTLES\\PetBattle-SelectedPetGlow')
Expand All @@ -23,7 +23,7 @@ function UNITFRAME:CreateBackdrop(self)
highlight:Hide()
self.Highlight = highlight

self:RegisterForClicks('AnyUp')
self:RegisterForClicks(onKeyDown and 'AnyDown' or 'AnyUp')
self:HookScript('OnEnter', UF_OnEnter)
self:HookScript('OnLeave', UF_OnLeave)

Expand All @@ -36,19 +36,6 @@ function UNITFRAME:CreateBackdrop(self)
self.backdrop:SetBackdropBorderColor(0, 0, 0, 1)
self.backdrop:SetFrameStrata('BACKGROUND')
self.shadow = self.backdrop.__shadow

if not self.unitStyle == 'player' then
return
end

local width = C.DB.Unitframe.PlayerWidth
local height = C.DB.Unitframe.ClassPowerHeight

local classPowerBarHolder = CreateFrame('Frame', nil, self)
classPowerBarHolder:SetSize(width, height)
classPowerBarHolder:SetPoint('TOPLEFT', self, 'BOTTOMLEFT', 0, -3)

self.ClassPowerBarHolder = classPowerBarHolder
end

-- Selected border
Expand Down Expand Up @@ -168,6 +155,7 @@ function UNITFRAME:UpdateAllElements()
UNITFRAME:UpdateGCDTicker()
UNITFRAME:UpdateAuras()
UNITFRAME:UpdateFader()
UNITFRAME:UpdateClassPower()
end

function UNITFRAME:OnLogin()
Expand Down
Loading

0 comments on commit 4b586fc

Please sign in to comment.