Add per-profile class settings with Reset/Copy/Delete and per-character profile assignment
Each profile now owns its own hide/show settings instead of sharing one global table, and profile selection is tracked per character instead of account-wide. Adds Reset Profile, Copy From, and Delete a Profile controls to the Profiles tab, each ElvUI-skinned and gated behind a confirmation popup.
This commit is contained in:
+189
-26
@@ -32,9 +32,158 @@ HideCoA.FRAMES = {
|
||||
"CoAResourceBar",
|
||||
}
|
||||
|
||||
local function CreateDefaultClassSettings()
|
||||
|
||||
local classSettings = {}
|
||||
|
||||
for _, class in ipairs(HideCoA.CUSTOM_CLASSES) do
|
||||
classSettings[class] = {}
|
||||
for _, frameName in ipairs(HideCoA.FRAMES) do
|
||||
classSettings[class][frameName] = true
|
||||
end
|
||||
end
|
||||
|
||||
return classSettings
|
||||
|
||||
end
|
||||
|
||||
local function EnsureClassSettingsComplete(classSettings)
|
||||
|
||||
for _, class in ipairs(HideCoA.CUSTOM_CLASSES) do
|
||||
|
||||
if type(classSettings[class]) ~= "table" then
|
||||
classSettings[class] = {}
|
||||
end
|
||||
|
||||
for _, frameName in ipairs(HideCoA.FRAMES) do
|
||||
if classSettings[class][frameName] == nil then
|
||||
classSettings[class][frameName] = true
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
local function GetCharacterKey()
|
||||
return UnitName("player") .. " - " .. GetRealmName()
|
||||
end
|
||||
|
||||
HideCoA.GetCharacterKey = GetCharacterKey
|
||||
|
||||
local function GetActiveProfileName()
|
||||
|
||||
local charKey = GetCharacterKey()
|
||||
local assigned = HideCoADB.charProfile and HideCoADB.charProfile[charKey]
|
||||
|
||||
if assigned and HideCoADB.profiles[assigned] then
|
||||
return assigned
|
||||
end
|
||||
|
||||
return charKey
|
||||
|
||||
end
|
||||
|
||||
HideCoA.GetActiveProfileName = GetActiveProfileName
|
||||
|
||||
local function SetActiveProfileName(name)
|
||||
HideCoADB.charProfile[GetCharacterKey()] = name
|
||||
end
|
||||
|
||||
HideCoA.SetActiveProfileName = SetActiveProfileName
|
||||
|
||||
local function GetActiveClassSettings()
|
||||
|
||||
local name = GetActiveProfileName()
|
||||
local profile = HideCoADB.profiles[name]
|
||||
|
||||
if not profile then
|
||||
profile = { classSettings = CreateDefaultClassSettings() }
|
||||
HideCoADB.profiles[name] = profile
|
||||
end
|
||||
|
||||
if not profile.classSettings then
|
||||
profile.classSettings = CreateDefaultClassSettings()
|
||||
end
|
||||
|
||||
return profile.classSettings
|
||||
|
||||
end
|
||||
|
||||
HideCoA.GetActiveClassSettings = GetActiveClassSettings
|
||||
|
||||
local function CopyProfile(sourceName, destName)
|
||||
|
||||
local source = HideCoADB.profiles[sourceName]
|
||||
|
||||
if not source or not source.classSettings then
|
||||
return
|
||||
end
|
||||
|
||||
local copy = {}
|
||||
|
||||
for class, settings in pairs(source.classSettings) do
|
||||
copy[class] = {}
|
||||
for frameName, value in pairs(settings) do
|
||||
copy[class][frameName] = value
|
||||
end
|
||||
end
|
||||
|
||||
if not HideCoADB.profiles[destName] then
|
||||
HideCoADB.profiles[destName] = {}
|
||||
end
|
||||
|
||||
HideCoADB.profiles[destName].classSettings = copy
|
||||
|
||||
HideCoA.ApplySetting()
|
||||
|
||||
end
|
||||
|
||||
HideCoA.CopyProfile = CopyProfile
|
||||
|
||||
local function ResetProfile()
|
||||
|
||||
local name = GetActiveProfileName()
|
||||
|
||||
if not HideCoADB.profiles[name] then
|
||||
HideCoADB.profiles[name] = {}
|
||||
end
|
||||
|
||||
HideCoADB.profiles[name].classSettings = CreateDefaultClassSettings()
|
||||
|
||||
HideCoA.ApplySetting()
|
||||
|
||||
end
|
||||
|
||||
HideCoA.ResetProfile = ResetProfile
|
||||
|
||||
local function DeleteProfile(name)
|
||||
|
||||
if name == "Default" then
|
||||
return
|
||||
end
|
||||
|
||||
local wasActive = (name == GetActiveProfileName())
|
||||
|
||||
HideCoADB.profiles[name] = nil
|
||||
|
||||
for charKey, assigned in pairs(HideCoADB.charProfile) do
|
||||
if assigned == name then
|
||||
HideCoADB.charProfile[charKey] = nil
|
||||
end
|
||||
end
|
||||
|
||||
if wasActive then
|
||||
HideCoADB.charProfile[GetCharacterKey()] = "Default"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
HideCoA.DeleteProfile = DeleteProfile
|
||||
|
||||
local function ShouldHideForClass(playerClass, frameName)
|
||||
|
||||
local classSettings = HideCoADB.classSettings[playerClass]
|
||||
local classSettings = GetActiveClassSettings()[playerClass]
|
||||
|
||||
if not classSettings or classSettings[frameName] == nil then
|
||||
return true
|
||||
@@ -107,46 +256,60 @@ f:SetScript("OnEvent", function(self, event, arg1)
|
||||
HideCoADB = {}
|
||||
end
|
||||
|
||||
if not HideCoADB.classSettings then
|
||||
HideCoADB.classSettings = {}
|
||||
end
|
||||
|
||||
for _, class in ipairs(HideCoA.CUSTOM_CLASSES) do
|
||||
|
||||
if type(HideCoADB.classSettings[class]) ~= "table" then
|
||||
HideCoADB.classSettings[class] = {}
|
||||
end
|
||||
|
||||
for _, frameName in ipairs(HideCoA.FRAMES) do
|
||||
if HideCoADB.classSettings[class][frameName] == nil then
|
||||
HideCoADB.classSettings[class][frameName] = true
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if not HideCoADB.profiles then
|
||||
HideCoADB.profiles = {}
|
||||
end
|
||||
|
||||
if not HideCoADB.charProfile then
|
||||
HideCoADB.charProfile = {}
|
||||
end
|
||||
|
||||
-- Legacy pre-profile saved variables stored a single flat classSettings
|
||||
-- table shared by every character. Fold it into "Default" so nobody's
|
||||
-- existing hide/show choices vanish when profiles were introduced.
|
||||
if HideCoADB.classSettings and not HideCoADB.profiles["Default"] then
|
||||
HideCoADB.profiles["Default"] = { classSettings = HideCoADB.classSettings }
|
||||
end
|
||||
|
||||
HideCoADB.classSettings = nil
|
||||
|
||||
if not HideCoADB.profiles["Default"] then
|
||||
HideCoADB.profiles["Default"] = {}
|
||||
HideCoADB.profiles["Default"] = { classSettings = CreateDefaultClassSettings() }
|
||||
end
|
||||
|
||||
local realmCharProfile = GetRealmName() .. " - " .. UnitName("player")
|
||||
local charKey = GetCharacterKey()
|
||||
|
||||
if not HideCoADB.profiles[realmCharProfile] then
|
||||
HideCoADB.profiles[realmCharProfile] = {}
|
||||
-- The profile-name syntax used to be "realm - character"; rename any
|
||||
-- existing profile created under that scheme to the new ordering
|
||||
-- instead of leaving it orphaned in the list.
|
||||
local oldCharKey = GetRealmName() .. " - " .. UnitName("player")
|
||||
|
||||
if HideCoADB.profiles[oldCharKey] and not HideCoADB.profiles[charKey] then
|
||||
HideCoADB.profiles[charKey] = HideCoADB.profiles[oldCharKey]
|
||||
HideCoADB.profiles[oldCharKey] = nil
|
||||
end
|
||||
|
||||
if not HideCoADB.selectedProfile then
|
||||
HideCoADB.selectedProfile = "Default"
|
||||
if not HideCoADB.profiles[charKey] then
|
||||
HideCoADB.profiles[charKey] = { classSettings = CreateDefaultClassSettings() }
|
||||
end
|
||||
|
||||
for _, profile in pairs(HideCoADB.profiles) do
|
||||
if not profile.classSettings then
|
||||
profile.classSettings = CreateDefaultClassSettings()
|
||||
end
|
||||
EnsureClassSettingsComplete(profile.classSettings)
|
||||
end
|
||||
|
||||
if not HideCoADB.charProfile[charKey] then
|
||||
HideCoADB.charProfile[charKey] = charKey
|
||||
end
|
||||
|
||||
HideCoADB.selectedProfile = nil
|
||||
|
||||
elseif event == "PLAYER_LOGIN" then
|
||||
|
||||
ApplySetting()
|
||||
|
||||
end
|
||||
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user