Skip to content

Commit

Permalink
Add a reset element button to the options
Browse files Browse the repository at this point in the history
  • Loading branch information
Wutname1 committed Aug 17, 2024
1 parent 15ccdd0 commit 5aa0022
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion Modules/UnitFrames/Options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,21 @@ function Options:Initialize()
local ElementSettings = UF.CurrentSettings[frameName].elements[elementName]
local UserSetting = UF.DB.UserSettings[UF.DB.Style][frameName].elements[elementName]

---@param UserSetting table
---@param DefaultSetting table
---@return boolean
local function hasChanges(UserSetting, DefaultSetting)
if not UserSetting or not DefaultSetting then return false end
for k, v in pairs(UserSetting) do
if type(v) == 'table' then
if hasChanges(v, DefaultSetting[k]) then return true end
elseif v ~= DefaultSetting[k] then
return true
end
end
return false
end

---@type AceConfig.OptionsTable
local ElementOptSet = {
name = elementConfig.DisplayName and L[elementConfig.DisplayName] or elementName,
Expand All @@ -1214,7 +1229,26 @@ function Options:Initialize()
--Update the screen
builtFrame:UpdateAll()
end,
args = {},
args = {
resetElement = {
name = L['Reset Element'],
type = 'execute',
order = 0,
hidden = function()
return not hasChanges(UserSetting, UF.Unit.defaultConfigs[frameName].elements[elementName])
end,
func = function()
-- Reset the element's settings to default
UF.DB.UserSettings[UF.DB.Style][frameName].elements[elementName] = nil

-- Trigger a full update of the UnitFrames
UF:Update()

-- Refresh the options UI
SUI.Lib.AceConfigRegistry:NotifyChange('SpartanUI')
end,
},
},
}

local PositionGet = function(info)
Expand Down

0 comments on commit 5aa0022

Please sign in to comment.