Skip to content

Commit

Permalink
[Feature] Add 'Interrupted' Cast Bar (#194)
Browse files Browse the repository at this point in the history
* add defaults

* add menu options

* add consts

* implement functionality

* label %i => %t

* locale and tooltips
  • Loading branch information
Krealle authored Dec 17, 2024
1 parent 2075e23 commit cbac929
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Data/Constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ const.OPTION_KIND = {
GLOW = "glow",
SHOW_TARGET = "showTarget",
TARGET_SEPARATOR = "targetSeparator",
TIME_TO_HOLD = "timeToHold",
INTERRUPTED_LABEL = "interruptedLabel",
}

---@enum AURA_OPTION_KIND
Expand Down
3 changes: 3 additions & 0 deletions Data/Defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,9 @@ Defaults.Widgets = {
frameLevel = 10,
onlyShowInterrupt = false,
anchorToParent = true,
timeToHold = 0,
interruptedLabel = "%t",
showInterruptedSpell = false,
position = {
point = "TOPLEFT",
offsetY = -30,
Expand Down
5 changes: 5 additions & 0 deletions Locales/enUS.lua
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ L.playerCastBar = "Player Cast Bar"
L.HideAtMaxLevel = "Hide at Max Level"
L.ShowTarget = "Show Target"
L.Separator = "Separator"
L.TimeToHold = "Time to Hold"
L.TimeToHoldTooltip = "Time in seconds to hold the Cast Bar after the spell has failed or been interrupted"
L.Label = "Label"
L.InterruptedLabelTooltip = [[%s - Type (%s or %s)
%s - Spell Name]]

-- Custom Formats
L.ValidTags = "Valid Tags"
Expand Down
14 changes: 13 additions & 1 deletion Menu/Builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ Builder.MenuOptions = {
Glow = 37
}

local FAILED = FAILED or "Failed"
local INTERRUPTED = INTERRUPTED or "Interrupted"

-------------------------------------------------
-- MARK: Build Menu
-------------------------------------------------
Expand Down Expand Up @@ -1555,7 +1558,7 @@ function Builder:CreateCastBarGeneralOptions(parent, widgetName)
---@class CastBarOptions: OptionsFrame
local f = CUF:CreateFrame(nil, parent, 1, 1, true, true)
f.id = "CastBarOptions"
f.optionHeight = 135
f.optionHeight = 195

-- Title
f.title = self:CreateOptionTitle(f, "General")
Expand All @@ -1575,6 +1578,15 @@ function Builder:CreateCastBarGeneralOptions(parent, widgetName)
const.OPTION_KIND.ONLY_SHOW_INTERRUPT)
self:AnchorBelowCB(f.onlyShowInterruptableCB, f.reverseCB)

f.timeToHoldSlider = self:CreateSlider(f, widgetName, L.TimeToHold, nil, 0, 10, const.OPTION_KIND.TIME_TO_HOLD)
self:AnchorBelow(f.timeToHoldSlider, f.onlyShowInterruptableCB)
CUF:SetTooltips(f.timeToHoldSlider, "ANCHOR_TOPLEFT", 0, 3, L.TimeToHold, L.TimeToHoldTooltip)

f.interruptedLabelEditBox = self:CreateEditBox(f, widgetName, L.Label, nil, const.OPTION_KIND.INTERRUPTED_LABEL)
self:AnchorRight(f.interruptedLabelEditBox, f.timeToHoldSlider)
CUF:SetTooltips(f.interruptedLabelEditBox, "ANCHOR_TOPLEFT", 0, 3, L.Label,
string.format(L.InterruptedLabelTooltip, "%t", INTERRUPTED, FAILED, "%s"))

local function LoadPageDB()
f.onlyShowInterruptableCB:SetEnabled(CUF.vars.selectedUnit ~= const.UNIT.PLAYER)
end
Expand Down
3 changes: 3 additions & 0 deletions WidgetAnnotations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@
---@field icon CastBarIconOpt
---@field useClassColor boolean
---@field onlyShowInterrupt boolean
---@field timeToHold number
---@field interruptedLabel string
---@field showInterruptedSpell boolean

---@class CastBarSparkOpt
---@field enabled boolean
Expand Down
36 changes: 35 additions & 1 deletion Widgets/Bars/CastBar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ local Builder = CUF.Builder
local Handler = CUF.Handler
local P = CUF.PixelPerfect

local FAILED = FAILED or "Failed"
local INTERRUPTED = INTERRUPTED or "Interrupted"

-------------------------------------------------
-- MARK: AddWidget
-------------------------------------------------
Expand Down Expand Up @@ -62,6 +65,12 @@ function W.UpdateCastBarWidget(button, unit, setting, subSetting, ...)
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.TIME_TO_HOLD then
castBar.timeToHold = styleTable.timeToHold
end
if not setting or setting == const.OPTION_KIND.INTERRUPTED_LABEL then
castBar.interruptedLabel = styleTable.interruptedLabel
end

if not setting or setting == const.OPTION_KIND.SPARK then
castBar.spark.enabled = styleTable.spark.enabled
Expand Down Expand Up @@ -244,6 +253,8 @@ function CastStart(button, event, unit, castGUID)
castBar.max = endTime - startTime
castBar.startTime = startTime

castBar.holdTime = 0

castBar.notInterruptible = notInterruptible
castBar.castID = castID
castBar.spellID = spellID
Expand Down Expand Up @@ -363,6 +374,21 @@ function CastFail(button, event, unit, castID, spellID)
return
end

if castBar.timeToHold > 0 then
castBar.holdTime = castBar.timeToHold

local type = event == 'UNIT_SPELLCAST_FAILED' and FAILED or INTERRUPTED
castBar.spellText:SetText(castBar.interruptedLabel:gsub("%%t", type):gsub("%%s",
castBar.displayName ~= "" and castBar.displayName or castBar.spellName or ""))

if castBar.spark:IsShown() then
castBar.spark:Hide()
end

castBar:SetValue(castBar.max)
castBar:SetCastBarColor()
end

castBar:ResetAttributes()
end

Expand Down Expand Up @@ -457,6 +483,8 @@ local function onUpdate(self, elapsed)
self:OnUpdateStage()
end
end
elseif self.holdTime > 0 then
self.holdTime = self.holdTime - elapsed
else
self:ResetAttributes()
self:Hide()
Expand Down Expand Up @@ -726,7 +754,9 @@ end

---@param self CastBarWidget
local function SetCastBarColor(self)
if self.useClassColor then
if self.holdTime > 0 then
self.statusBar:SetStatusBarColor(1, 0, 0, 1)
elseif self.useClassColor then
local r, g, b = CUF.Util:GetUnitClassColor(self._owner.states.unit)
self.statusBar:SetStatusBarColor(r, g, b, 1)
elseif self.notInterruptible then
Expand Down Expand Up @@ -901,6 +931,10 @@ function W:CreateCastBar(button)
castBar.useClassColor = false
castBar.onlyShowInterrupt = false

castBar.timeToHold = 0
castBar.holdTime = 0
castBar.interruptedLabel = ""

-- Number of stages in current empower
castBar.NumStages = 0
-- Current stage defaults to CASTBAR_STAGE_INVALID (-1)
Expand Down

0 comments on commit cbac929

Please sign in to comment.