Skip to content

Commit

Permalink
[Feature] Add "Only show interruptable casts" toggle for Cast Bar (#161)
Browse files Browse the repository at this point in the history
* defaults

* const

* add menu option

* locale

* implement logic
  • Loading branch information
Krealle authored Oct 31, 2024
1 parent 1399353 commit 9997c4a
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Data/Constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ const.OPTION_KIND = {
MAGIC = "magic",
POISON = "poison",
BLEED = "bleed",
ICON_STYLE = "iconStyle"
ICON_STYLE = "iconStyle",
ONLY_SHOW_INTERRUPT = "onlyShowInterrupt"
}

---@enum AURA_OPTION_KIND
Expand Down
1 change: 1 addition & 0 deletions Data/Defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ Defaults.Widgets = {
enabled = false,
useClassColor = true,
frameLevel = 10,
onlyShowInterrupt = false,
position = {
point = "TOPLEFT",
offsetY = -30,
Expand Down
2 changes: 2 additions & 0 deletions Locales/enUS.lua
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ L.Zoom = "Zoom"
L.UseFullyChargedTooltip = "Use fully charged color for the final stage"
L.ShowEmpowerNameTooltip = "Show the spell name for Empowers"

L.OnlyShowInterruptableCast = "Only show interruptable casts"

-- Name Format
L.NameFormats = "Name Formats"

Expand Down
11 changes: 10 additions & 1 deletion Menu/Builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@ function Builder:CreateCastBarGeneralOptions(parent, widgetName)
---@class CastBarOptions: OptionsFrame
local f = CUF:CreateFrame(nil, parent, 1, 1, true, true)
f.id = "CastBarOptions"
f.optionHeight = 165
f.optionHeight = 185

-- Title
f.title = self:CreateOptionTitle(f, "General")
Expand All @@ -1404,6 +1404,15 @@ function Builder:CreateCastBarGeneralOptions(parent, widgetName)
f.classColorCB = self:CreateCheckBox(f, widgetName, L.UseClassColor, const.OPTION_KIND.USE_CLASS_COLOR)
self:AnchorRightOfCB(f.classColorCB, f.reverseCB)

f.onlyShowInterruptableCB = self:CreateCheckBox(f, widgetName, L.OnlyShowInterruptableCast,
const.OPTION_KIND.ONLY_SHOW_INTERRUPT)
self:AnchorBelowCB(f.onlyShowInterruptableCB, f.reverseCB)

local function LoadPageDB()
f.onlyShowInterruptableCB:SetEnabled(CUF.vars.selectedUnit ~= const.UNIT.PLAYER)
end
Handler:RegisterOption(LoadPageDB, widgetName, "CheckBox_CastBarGeneralOptions_OnlyShowInterruptableCast")

return f
end

Expand Down
1 change: 1 addition & 0 deletions WidgetAnnotations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@
---@field border BorderOpt
---@field icon CastBarIconOpt
---@field useClassColor boolean
---@field onlyShowInterrupt boolean

---@class CastBarSparkOpt
---@field enabled boolean
Expand Down
19 changes: 15 additions & 4 deletions Widgets/Bars/CastBar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ function W.UpdateCastBarWidget(button, unit, setting, subSetting, ...)
if not setting or setting == const.OPTION_KIND.SPELL_WIDTH then
castBar.spellText.width = styleTable.spellWidth
end
if not setting or setting == const.OPTION_KIND.ONLY_SHOW_INTERRUPT then
castBar.onlyShowInterrupt = styleTable.onlyShowInterrupt
end

castBar.Update(button)
end
Expand Down Expand Up @@ -214,7 +217,7 @@ function CastStart(button, event, unit, castGUID)
event = (numStages and numStages > 0) and "UNIT_SPELLCAST_EMPOWER_START" or "UNIT_SPELLCAST_CHANNEL_START"
end

if not name then
if (not name) or (castBar.onlyShowInterrupt and notInterruptible) then
castBar:ResetAttributes()
castBar:Hide()

Expand Down Expand Up @@ -278,11 +281,18 @@ function CastUpdate(button, event, unit, castID, spellID)
return
end

local name, startTime, endTime, _
local name, startTime, endTime, _, notInterruptible
if (event == "UNIT_SPELLCAST_DELAYED") then
name, _, _, startTime, endTime = UnitCastingInfo(unit)
name, _, _, startTime, endTime, _, _, notInterruptible = UnitCastingInfo(unit)
else
name, _, _, startTime, endTime = UnitChannelInfo(unit)
name, _, _, startTime, endTime, _, notInterruptible = UnitChannelInfo(unit)
end

if castBar.onlyShowInterrupt and notInterruptible then
castBar:ResetAttributes()
castBar:Hide()

return
end

if (not name) then return end
Expand Down Expand Up @@ -843,6 +853,7 @@ function W:CreateCastBar(button)
castBar.interruptibleColor = { 1, 1, 0, 0.25 }
castBar.nonInterruptibleColor = { 1, 1, 0, 0.25 }
castBar.useClassColor = false
castBar.onlyShowInterrupt = false

-- Number of stages in current empower
castBar.NumStages = 0
Expand Down

0 comments on commit 9997c4a

Please sign in to comment.