Skip to content

Commit

Permalink
[Feature] Add "Hide at Max Level" option for Resting Icon
Browse files Browse the repository at this point in the history
  • Loading branch information
Krealle committed Nov 8, 2024
1 parent 45177c8 commit 376601b
Show file tree
Hide file tree
Showing 6 changed files with 93 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 @@ -172,7 +172,8 @@ const.OPTION_KIND = {
POISON = "poison",
BLEED = "bleed",
ICON_STYLE = "iconStyle",
ONLY_SHOW_INTERRUPT = "onlyShowInterrupt"
ONLY_SHOW_INTERRUPT = "onlyShowInterrupt",
HIDE_AT_MAX_LEVEL = "hideAtMaxLevel",
}

---@enum AURA_OPTION_KIND
Expand Down
4 changes: 3 additions & 1 deletion Data/Defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ local Util = CUF.Util
local Defaults = CUF.Defaults

Defaults.Values = {
maxAuraIcons = 20
maxAuraIcons = 20,
maxLevel = 80,
}

Defaults.Options = {}
Expand Down Expand Up @@ -618,6 +619,7 @@ Defaults.Widgets = {
restingIcon = {
enabled = false,
frameLevel = 10,
hideAtMaxLevel = false,
size = {
width = 20,
height = 20,
Expand Down
1 change: 1 addition & 0 deletions Locales/enUS.lua
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ Reload after toggling to fully update all frames]]
L.buffFrame = "Buff Frame"
L.debuffFrame = "Debuff Frame"
L.playerCastBar = "Player Cast Bar"
L.HideAtMaxLevel = "Hide at Max Level"

-- Custom Formats
L.ValidTags = "Valid Tags"
Expand Down
24 changes: 23 additions & 1 deletion Menu/Builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ Builder.MenuOptions = {
CustomText = 31,
DispelsOptions = 32,
TrueSingleSizeOptions = 33,
TotemOptions = 34
TotemOptions = 34,
HideAtMaxLevel = 35
}

-------------------------------------------------
Expand Down Expand Up @@ -1080,6 +1081,26 @@ function Builder:CreateFrameLevelOptions(parent, widgetName)
return f
end

-------------------------------------------------
-- MARK: Max Level
-------------------------------------------------

---@param parent Frame
---@param widgetName WIDGET_KIND
---@return FrameLevelOptions
function Builder:CreateHideAtMaxLevel(parent, widgetName)
---@class FrameLevelOptions: OptionsFrame
local f = CUF:CreateFrame(nil, parent, 1, 1, true, true)
f.id = "FrameLevelOptions"
f.optionHeight = 20

f.hideAtMaxLevelCB = self:CreateCheckBox(f, widgetName, L.HideAtMaxLevel,
const.OPTION_KIND.HIDE_AT_MAX_LEVEL)
f.hideAtMaxLevelCB:SetPoint("TOPLEFT", f)

return f
end

-----------------------------------------------
-- MARK: Texture Dropdown
-----------------------------------------------
Expand Down Expand Up @@ -1961,4 +1982,5 @@ Builder.MenuFuncs = {
[Builder.MenuOptions.DispelsOptions] = Builder.CreateDispelsOptions,
[Builder.MenuOptions.TrueSingleSizeOptions] = Builder.CreateTrueSingleSizeOptions,
[Builder.MenuOptions.TotemOptions] = Builder.CreateTotemOptions,
[Builder.MenuOptions.HideAtMaxLevel] = Builder.CreateHideAtMaxLevel,
}
1 change: 1 addition & 0 deletions WidgetAnnotations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
---@field position PositionOpt
---@field frameLevel number
---@field size SizeOpt
---@field hideAtMaxLevel boolean

---@class ReadyCheckIconWidgetTable
---@field enabled boolean
Expand Down
66 changes: 63 additions & 3 deletions Widgets/Icons/RestingIcon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ local Handler = CUF.Handler
local Builder = CUF.Builder
local menu = CUF.Menu
local const = CUF.constants
local DB = CUF.DB

local maxLevel = CUF.Defaults.Values.maxLevel

-------------------------------------------------
-- MARK: AddWidget
Expand All @@ -20,14 +23,22 @@ local const = CUF.constants
menu:AddWidget(const.WIDGET_KIND.RESTING_ICON,
Builder.MenuOptions.Anchor,
Builder.MenuOptions.SingleSize,
Builder.MenuOptions.HideAtMaxLevel,
Builder.MenuOptions.FrameLevel)

---@param button CUFUnitButton
---@param unit Unit
---@param setting OPTION_KIND
---@param subSetting string
function W.UpdateRestingIconWidget(button, unit, setting, subSetting)
button.widgets.restingIcon.Update(button)
local restingIcon = button.widgets.restingIcon
local styleTable = DB.GetCurrentWidgetTable(const.WIDGET_KIND.RESTING_ICON, unit)
if not setting or setting == const.OPTION_KIND.HIDE_AT_MAX_LEVEL then
restingIcon.hideAtMaxLevel = styleTable.hideAtMaxLevel
restingIcon:UpdateEventListeners()
end

restingIcon.Update(button)
end

Handler:RegisterWidget(W.UpdateRestingIconWidget, const.WIDGET_KIND.RESTING_ICON)
Expand All @@ -37,7 +48,7 @@ Handler:RegisterWidget(W.UpdateRestingIconWidget, const.WIDGET_KIND.RESTING_ICON
-------------------------------------------------

---@param button CUFUnitButton
local function Update(button)
local function Update(button, event, ...)
local unit = button.states.displayedUnit
if not unit then return end

Expand All @@ -47,6 +58,30 @@ local function Update(button)
local restingIcon = button.widgets.restingIcon

if restingIcon.enabled and (status or restingIcon._isSelected) then
if restingIcon.hideAtMaxLevel then
local level = UnitEffectiveLevel(unit)

-- UnitLevel can return outdated value, so if we have a value from the event
-- We use that instead
if event == "PLAYER_LEVEL_UP" then
local newLevel = ...
if newLevel and newLevel > level then
level = newLevel
end
elseif event == "PLAYER_LEVEL_CHANGED" then
local _, newLevel = ...
if newLevel and newLevel > level then
level = newLevel
end
end

if level == maxLevel then
restingIcon:Hide()
restingIcon:UpdateEventListeners()
return
end
end

restingIcon:Show()
else
restingIcon:Hide()
Expand All @@ -55,14 +90,36 @@ end

---@param self RestingIconWidget
local function Enable(self)
self._owner:AddEventListener("PLAYER_UPDATE_RESTING", Update, true)
self:UpdateEventListeners()

return true
end

---@param self RestingIconWidget
local function Disable(self)
self._owner:RemoveEventListener("PLAYER_UPDATE_RESTING", Update)
self._owner:RemoveEventListener("PLAYER_LEVEL_CHANGED", Update)
self._owner:RemoveEventListener("PLAYER_LEVEL_UP", Update)
end

---@param self RestingIconWidget
local function UpdateEventListeners(self)
if self.hideAtMaxLevel then
if UnitEffectiveLevel(self._owner.states.unit) < maxLevel then
self._owner:AddEventListener("PLAYER_UPDATE_RESTING", Update, true)
self._owner:AddEventListener("PLAYER_LEVEL_CHANGED", Update, true)
self._owner:AddEventListener("PLAYER_LEVEL_UP", Update, true)
else
self._owner:RemoveEventListener("PLAYER_UPDATE_RESTING", Update)
self._owner:RemoveEventListener("PLAYER_LEVEL_CHANGED", Update)
self._owner:RemoveEventListener("PLAYER_LEVEL_UP", Update)
end
else
self._owner:AddEventListener("PLAYER_UPDATE_RESTING", Update, true)

self._owner:RemoveEventListener("PLAYER_LEVEL_CHANGED", Update)
self._owner:RemoveEventListener("PLAYER_LEVEL_UP", Update)
end
end

-------------------------------------------------
Expand All @@ -80,6 +137,7 @@ function W:CreateRestingIcon(button)
restingIcon.id = const.WIDGET_KIND.RESTING_ICON
restingIcon._isSelected = false
restingIcon._owner = button
restingIcon.hideAtMaxLevel = false

restingIcon.tex = restingIcon:CreateTexture(nil, "ARTWORK")
restingIcon.tex:SetTexture("Interface\\CharacterFrame\\UI-StateIcon")
Expand All @@ -94,6 +152,8 @@ function W:CreateRestingIcon(button)
restingIcon.Disable = Disable
restingIcon.Update = Update

restingIcon.UpdateEventListeners = UpdateEventListeners

restingIcon.SetEnabled = W.SetEnabled
restingIcon.SetPosition = W.SetPosition
restingIcon._SetIsSelected = W.SetIsSelected
Expand Down

0 comments on commit 376601b

Please sign in to comment.