Skip to content

Commit

Permalink
[Feature] Unitname on Cast Bar (#193)
Browse files Browse the repository at this point in the history
* remove redundant code

* add defaults

* add consts

* add menu options

* add widget props for new options

* add listener for "UNIT_SPELLCAST_SENT" to track target name

* remove targetName prop if new cast is detected

* update UpdateElements fn to show target name

* locale
  • Loading branch information
Krealle authored Dec 17, 2024
1 parent ab5a625 commit 4a2f230
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 17 deletions.
2 changes: 2 additions & 0 deletions Data/Constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ const.OPTION_KIND = {
HIDE_AT_MAX_LEVEL = "hideAtMaxLevel",
HIDE_OUT_OF_COMBAT = "hideOutOfCombat",
GLOW = "glow",
SHOW_TARGET = "showTarget",
TARGET_SEPARATOR = "targetSeparator",
}

---@enum AURA_OPTION_KIND
Expand Down
2 changes: 2 additions & 0 deletions Data/Defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,8 @@ Defaults.Widgets = {
},
spellWidth = Defaults.Options.fontWidth,
showSpell = true,
showTarget = false,
targetSeparator = "->",
spark = {
enabled = true,
width = 2,
Expand Down
2 changes: 2 additions & 0 deletions Locales/enUS.lua
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ L.buffFrame = "Buff Frame"
L.debuffFrame = "Debuff Frame"
L.playerCastBar = "Player Cast Bar"
L.HideAtMaxLevel = "Hide at Max Level"
L.ShowTarget = "Show Target"
L.Separator = "Separator"

-- Custom Formats
L.ValidTags = "Valid Tags"
Expand Down
31 changes: 29 additions & 2 deletions Menu/Builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1615,10 +1615,37 @@ function Builder:CreateCastBarSpellFontOptions(parent, widgetName)
f.spellCB = self:CreateCheckBox(f, widgetName, L.ShowSpell, const.OPTION_KIND.SHOW_SPELL)
self:AnchorBelow(f.spellCB, f.fontOptions.styleDropdown)

f.showTarget = self:CreateCheckBox(f, widgetName, L.ShowTarget, const.OPTION_KIND.SHOW_TARGET)
self:AnchorBelow(f.showTarget, f.spellCB)

f.targetSeparator = self:CreateEditBox(f, widgetName, L.Separator, nil, const.OPTION_KIND.TARGET_SEPARATOR)
self:AnchorRightOfCB(f.targetSeparator, f.showTarget)

f.spellWidth = self:CreateTextWidthOption(f, widgetName, const.OPTION_KIND.SPELL_WIDTH)
self:AnchorBelow(f.spellWidth, f.spellCB)
self:AnchorBelow(f.spellWidth, f.showTarget)

f.optionHeight = f.optionHeight + 100

local function LoadPageDB()
if CUF.vars.selectedUnit == const.UNIT.PLAYER then
f.wrapperFrame:SetHeight(f.optionHeight + 35)

f.showTarget:Show()
f.targetSeparator:Show()

f.optionHeight = f.optionHeight + 50
f.spellWidth:ClearAllPoints()
self:AnchorBelow(f.spellWidth, f.showTarget)
else
f.wrapperFrame:SetHeight(f.optionHeight - 15)

f.showTarget:Hide()
f.targetSeparator:Hide()

f.spellWidth:ClearAllPoints()
self:AnchorBelow(f.spellWidth, f.spellCB)
end
end
Handler:RegisterOption(LoadPageDB, widgetName, "CastBarSpellFontOptions")

return f
end
Expand Down
2 changes: 2 additions & 0 deletions WidgetAnnotations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@
---@field spell BigFontOpt
---@field spellWidth FontWidthOpt
---@field showSpell boolean
---@field showTarget boolean
---@field targetSeparator string
---@field spark CastBarSparkOpt
---@field empower EmpowerOpt
---@field border BorderOpt
Expand Down
63 changes: 48 additions & 15 deletions Widgets/Bars/CastBar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ function W.UpdateCastBarWidget(button, unit, setting, subSetting, ...)
if not setting or setting == const.OPTION_KIND.SHOW_SPELL then
castBar.spellText.enabled = styleTable.showSpell
end
if not setting or setting == const.OPTION_KIND.SHOW_TARGET then
castBar.spellText.showTarget = styleTable.showTarget
end
if not setting or setting == const.OPTION_KIND.TARGET_SEPARATOR then
castBar.spellText.targetSeparator = styleTable.targetSeparator
end

if not setting or setting == const.OPTION_KIND.SPARK then
castBar.spark.enabled = styleTable.spark.enabled
Expand Down Expand Up @@ -106,6 +112,8 @@ local function ResetAttributes(self)
self.spellName = nil
self.displayName = nil
self.spellTexture = nil
self.castGUID = nil
self.targetName = nil

self:ClearStages()
end
Expand All @@ -117,29 +125,24 @@ local function UpdateElements(self)
if self.icon then self.icon:SetTexture(self.spellTexture --[[ or FALLBACK_ICON ]]) end
if self.spark then self.spark:Show() end

if self.spellText.enabled and not self.empowering then
local name = self.displayName ~= "" and self.displayName or self.spellName
self.SetSpellWidth(self.spellText, name, self.spellText.width, self.statusBar)
elseif not self.spellText.enabled then
self.spellText:SetText("")
end

local name = "" ---@type string?
if self.empowering then
if self.showEmpowerSpellName then
local name = self.displayName ~= "" and self.displayName or self.spellName
self.SetSpellWidth(self.spellText, name, self.spellText.width, self.statusBar)
else
self.spellText:SetText("")
name = self.displayName ~= "" and self.displayName or self.spellName
end
else
if self.spellText.enabled then
local name = self.displayName ~= "" and self.displayName or self.spellName
self.SetSpellWidth(self.spellText, name, self.spellText.width, self.statusBar)
else
self.spellText:SetText("")
name = self.displayName ~= "" and self.displayName or self.spellName
end
end

if self.spellText.showTarget and self.targetName then
name = name .. self.spellText.targetSeparator .. self.targetName
end

self.SetSpellWidth(self.spellText, name, self.spellText.width, self.statusBar)
self.spellText:SetText(name)

if self.timerText then self.timerText:SetText() end

if self.empowering and self:IsShown() then
Expand Down Expand Up @@ -248,6 +251,11 @@ function CastStart(button, event, unit, castGUID)
castBar.displayName = displayName
castBar.spellTexture = texture

if castGUID and castBar.castGUID ~= castGUID then
castBar.targetName = nil
castBar.castGUID = castGUID
end

if castBar.channeling then
castBar.duration = endTime - GetTime()
else
Expand Down Expand Up @@ -358,6 +366,21 @@ function CastFail(button, event, unit, castID, spellID)
castBar:ResetAttributes()
end

---@param button CUFUnitButton
---@param event "UNIT_SPELLCAST_SENT"
---@param unit UnitToken
---@param target string
---@param castID WOWGUID
---@param spellID number
function SpellCastSent(button, event, unit, target, castID, spellID)
if not ShouldShow(button, unit) then return end

local castBar = button.widgets.castBar

castBar.castGUID = castID
castBar.targetName = target
end

-------------------------------------------------
-- MARK: OnUpdate
-------------------------------------------------
Expand Down Expand Up @@ -472,6 +495,10 @@ local function Enable(self)
button:AddEventListener("UNIT_SPELLCAST_FAILED", CastFail)
button:AddEventListener("UNIT_SPELLCAST_INTERRUPTED", CastFail)

if button.states.unit == "player" then
button:AddEventListener("UNIT_SPELLCAST_SENT", SpellCastSent)
end

if CUF.vars.isRetail and (button.states.class == "EVOKER"
or select(2, UnitRace(button.states.unit)) == "EarthenDwarf") then
button:AddEventListener("UNIT_SPELLCAST_EMPOWER_START", CastStart)
Expand All @@ -497,6 +524,8 @@ local function Disable(self)
button:RemoveEventListener("UNIT_SPELLCAST_FAILED", CastFail)
button:RemoveEventListener("UNIT_SPELLCAST_INTERRUPTED", CastFail)

button:RemoveEventListener("UNIT_SPELLCAST_SENT", SpellCastSent)

if CUF.vars.isRetail then
button:RemoveEventListener("UNIT_SPELLCAST_EMPOWER_START", CastStart)
button:RemoveEventListener("UNIT_SPELLCAST_EMPOWER_STOP", CastStop)
Expand Down Expand Up @@ -864,6 +893,8 @@ function W:CreateCastBar(button)
castBar.notInterruptible = false ---@type boolean?
castBar.spellID = 0 ---@type number?
castBar.spellTexture = nil ---@type integer?
castBar.castGUID = nil ---@type WOWGUID?
castBar.targetName = nil ---@type string?

castBar.interruptibleColor = { 1, 1, 0, 0.25 }
castBar.nonInterruptibleColor = { 1, 1, 0, 0.25 }
Expand Down Expand Up @@ -933,6 +964,8 @@ function W:CreateCastBar(button)
spellText.SetPosition = SetFontPosition
spellText.enabled = true
spellText.width = CUF.Defaults.Options.fontWidth
spellText.showTarget = false
spellText.targetSeparator = "->"

---@class IconTexture: Texture
local icon = castBar:CreateTexture(nil, "OVERLAY")
Expand Down

0 comments on commit 4a2f230

Please sign in to comment.