From 5aa00227a0915e78531ba4f25bd336b065aa3c44 Mon Sep 17 00:00:00 2001 From: wutname1 Date: Sat, 17 Aug 2024 15:00:10 -0500 Subject: [PATCH] Add a reset element button to the options --- Modules/UnitFrames/Options.lua | 36 +++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/Modules/UnitFrames/Options.lua b/Modules/UnitFrames/Options.lua index b5f3f4b7..b85d8b4a 100644 --- a/Modules/UnitFrames/Options.lua +++ b/Modules/UnitFrames/Options.lua @@ -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, @@ -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)