Files
hide-coa-ui/Options.lua
T
Narcasung 920b1b234b 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.
2026-07-07 22:17:47 +02:00

418 lines
12 KiB
Lua

local ElvSkins
if ElvUI then
local E = unpack(ElvUI)
ElvSkins = E:GetModule("Skins")
end
local panel = CreateFrame("Frame")
panel.name = "HideCoAUI"
local title = panel:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
title:SetPoint("TOPLEFT", 16, -16)
title:SetText("HideCoAUI")
local subtitle = panel:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
subtitle:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -8)
subtitle:SetText("Select a class, then toggle the checkboxes to hide its class resource:")
local sidebar = CreateFrame("Frame", nil, panel)
sidebar:SetPoint("TOPLEFT", subtitle, "BOTTOMLEFT", 0, -12)
sidebar:SetPoint("BOTTOMLEFT", panel, "BOTTOMLEFT", 16, 16)
sidebar:SetWidth(150)
local content = CreateFrame("Frame", nil, panel)
content:SetPoint("TOPLEFT", sidebar, "TOPRIGHT", 16, 0)
content:SetPoint("BOTTOMRIGHT", panel, "BOTTOMRIGHT", -16, 16)
local classContent = CreateFrame("Frame", nil, content)
classContent:SetAllPoints(content)
local profileContent
local classTitle = classContent:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
classTitle:SetPoint("TOPLEFT", classContent, "TOPLEFT", 0, 0)
local titleFont, titleSize = classTitle:GetFont()
classTitle:SetFont(titleFont, titleSize + 4, "OUTLINE")
local checks = {}
local selectedClass = nil
local previousAnchor = classTitle
local previousSpacing = -12
for _, frameName in ipairs(HideCoA.FRAMES) do
local check = CreateFrame("CheckButton", "HideCoAClassCheck" .. frameName, classContent, "InterfaceOptionsCheckButtonTemplate")
check:SetPoint("TOPLEFT", previousAnchor, "BOTTOMLEFT", 0, previousSpacing)
_G[check:GetName() .. "Text"]:SetText("Hide " .. frameName)
check.frameName = frameName
if ElvSkins then
ElvSkins:HandleCheckBox(check)
end
check:SetScript("OnClick", function(self)
if not selectedClass then
return
end
HideCoA.GetActiveClassSettings()[selectedClass][self.frameName] = self:GetChecked() and true or false
HideCoA.ApplySetting()
end)
checks[frameName] = check
previousAnchor = check
previousSpacing = -8
end
local TAB_HEIGHT = 18
local tabButtons = {}
local profileTabButton
local function SelectClass(class)
selectedClass = class
classContent:Show()
profileContent:Hide()
profileTabButton.selectedTexture:Hide()
local displayName = (LOCALIZED_CLASS_NAMES_MALE and LOCALIZED_CLASS_NAMES_MALE[class]) or class
classTitle:SetText(displayName)
local color = RAID_CLASS_COLORS and RAID_CLASS_COLORS[class]
if color then
classTitle:SetTextColor(color.r, color.g, color.b)
else
classTitle:SetTextColor(1, 1, 1)
end
for _, frameName in ipairs(HideCoA.FRAMES) do
checks[frameName]:SetChecked(HideCoA.GetActiveClassSettings()[class][frameName])
end
for tabClass, button in pairs(tabButtons) do
if tabClass == class then
button.selectedTexture:Show()
else
button.selectedTexture:Hide()
end
end
end
for index, class in ipairs(HideCoA.CUSTOM_CLASSES) do
local button = CreateFrame("Button", "HideCoAClassTab" .. class, sidebar)
button:SetHeight(TAB_HEIGHT)
button:SetPoint("TOPLEFT", sidebar, "TOPLEFT", 0, -(index - 1) * TAB_HEIGHT)
button:SetPoint("RIGHT", sidebar, "RIGHT", 0, 0)
local selectedTexture = button:CreateTexture(nil, "BACKGROUND")
selectedTexture:SetAllPoints()
selectedTexture:SetTexture(1, 1, 1, 0.2)
selectedTexture:Hide()
button.selectedTexture = selectedTexture
button:SetHighlightTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight", "ADD")
local displayName = (LOCALIZED_CLASS_NAMES_MALE and LOCALIZED_CLASS_NAMES_MALE[class]) or class
local text = button:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
text:SetPoint("LEFT", 4, 0)
text:SetText(displayName)
local color = RAID_CLASS_COLORS and RAID_CLASS_COLORS[class]
if color then
text:SetTextColor(color.r, color.g, color.b)
end
button:SetScript("OnClick", function()
SelectClass(class)
end)
tabButtons[class] = button
end
profileContent = CreateFrame("Frame", nil, content)
profileContent:SetAllPoints(content)
profileContent:Hide()
local profileTitle = profileContent:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
profileTitle:SetPoint("TOPLEFT", profileContent, "TOPLEFT", 0, 0)
profileTitle:SetFont(titleFont, titleSize + 4, "OUTLINE")
profileTitle:SetText("Profiles")
local function GetProfileNames()
local names = {}
local hasDefault = false
if HideCoADB and HideCoADB.profiles then
for name in pairs(HideCoADB.profiles) do
if name == "Default" then
hasDefault = true
else
table.insert(names, name)
end
end
end
table.sort(names)
if hasDefault then
table.insert(names, 1, "Default")
end
return names
end
local profileDropDown = CreateFrame("Frame", "HideCoAProfileDropDown", profileContent, "UIDropDownMenuTemplate")
profileDropDown:SetPoint("TOPLEFT", profileTitle, "BOTTOMLEFT", -16, -12)
if ElvSkins then
ElvSkins:HandleDropDownBox(profileDropDown, 140)
end
local function ProfileDropDown_OnClick(self)
HideCoA.SetActiveProfileName(self.value)
UIDropDownMenu_SetText(profileDropDown, self.value)
HideCoA.ApplySetting()
end
UIDropDownMenu_Initialize(profileDropDown, function(self, level)
for _, name in ipairs(GetProfileNames()) do
local info = UIDropDownMenu_CreateInfo()
info.text = name
info.value = name
info.func = ProfileDropDown_OnClick
info.checked = HideCoADB and HideCoADB.charProfile and (HideCoA.GetActiveProfileName() == name)
UIDropDownMenu_AddButton(info, level)
end
end)
UIDropDownMenu_SetWidth(profileDropDown, 140)
local resetDesc = profileContent:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
resetDesc:SetPoint("TOPLEFT", profileDropDown, "BOTTOMLEFT", 16, -20)
resetDesc:SetWidth(260)
resetDesc:SetJustifyH("LEFT")
resetDesc:SetText("Reset the currently active profile's settings back to their defaults.")
local resetButton = CreateFrame("Button", "HideCoAResetProfileButton", profileContent, "UIPanelButtonTemplate")
resetButton:SetPoint("TOPLEFT", resetDesc, "BOTTOMLEFT", 0, -8)
resetButton:SetSize(140, 22)
resetButton:SetText("Reset Profile")
if ElvSkins then
ElvSkins:HandleButton(resetButton)
end
StaticPopupDialogs["HIDECOA_CONFIRM_RESET_PROFILE"] = {
text = "Reset the active profile '%s' to its default settings? This cannot be undone.",
button1 = YES,
button2 = NO,
OnAccept = function()
HideCoA.ResetProfile()
if selectedClass then
SelectClass(selectedClass)
end
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
preferredIndex = 3,
}
resetButton:SetScript("OnClick", function()
StaticPopup_Show("HIDECOA_CONFIRM_RESET_PROFILE", HideCoA.GetActiveProfileName())
end)
local copyDesc = profileContent:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
copyDesc:SetPoint("TOPLEFT", resetButton, "BOTTOMLEFT", 0, -20)
copyDesc:SetWidth(260)
copyDesc:SetJustifyH("LEFT")
copyDesc:SetText("Copy the settings from one existing profile into the currently active profile.")
local copyLabel = profileContent:CreateFontString(nil, "ARTWORK", "GameFontNormal")
copyLabel:SetPoint("TOPLEFT", copyDesc, "BOTTOMLEFT", 0, -8)
copyLabel:SetTextColor(1, 0.82, 0)
copyLabel:SetText("Copy From")
local copyDropDown = CreateFrame("Frame", "HideCoACopyProfileDropDown", profileContent, "UIDropDownMenuTemplate")
copyDropDown:SetPoint("TOPLEFT", copyLabel, "BOTTOMLEFT", -16, -4)
if ElvSkins then
ElvSkins:HandleDropDownBox(copyDropDown, 140)
end
StaticPopupDialogs["HIDECOA_CONFIRM_COPY_PROFILE"] = {
text = "Copy settings from '%s' into the active profile '%s'? This will overwrite the active profile's settings.",
button1 = YES,
button2 = NO,
OnAccept = function(self, data)
HideCoA.CopyProfile(data.sourceName, data.activeName)
UIDropDownMenu_SetText(copyDropDown, "")
if selectedClass then
SelectClass(selectedClass)
end
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
preferredIndex = 3,
}
local function CopyProfile_OnClick(self)
local sourceName = self.value
local activeName = HideCoA.GetActiveProfileName()
StaticPopup_Show("HIDECOA_CONFIRM_COPY_PROFILE", sourceName, activeName,
{ sourceName = sourceName, activeName = activeName })
end
UIDropDownMenu_Initialize(copyDropDown, function(self, level)
local activeName = HideCoADB and HideCoA.GetActiveProfileName()
for _, name in ipairs(GetProfileNames()) do
if name ~= activeName then
local info = UIDropDownMenu_CreateInfo()
info.text = name
info.value = name
info.func = CopyProfile_OnClick
UIDropDownMenu_AddButton(info, level)
end
end
end)
UIDropDownMenu_SetWidth(copyDropDown, 140)
UIDropDownMenu_SetText(copyDropDown, "")
local deleteDesc = profileContent:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
deleteDesc:SetPoint("TOPLEFT", copyDropDown, "BOTTOMLEFT", 16, -20)
deleteDesc:SetWidth(260)
deleteDesc:SetJustifyH("LEFT")
deleteDesc:SetText("Delete existing and unused profiles from the database to save space, and cleanup the SavedVariables file.")
local deleteLabel = profileContent:CreateFontString(nil, "ARTWORK", "GameFontNormal")
deleteLabel:SetPoint("TOPLEFT", deleteDesc, "BOTTOMLEFT", 0, -8)
deleteLabel:SetTextColor(1, 0.82, 0)
deleteLabel:SetText("Delete a Profile")
local deleteDropDown = CreateFrame("Frame", "HideCoADeleteProfileDropDown", profileContent, "UIDropDownMenuTemplate")
deleteDropDown:SetPoint("TOPLEFT", deleteLabel, "BOTTOMLEFT", -16, -4)
if ElvSkins then
ElvSkins:HandleDropDownBox(deleteDropDown, 140)
end
StaticPopupDialogs["HIDECOA_CONFIRM_DELETE_PROFILE"] = {
text = "Delete profile '%s'? This cannot be undone.",
button1 = YES,
button2 = NO,
OnAccept = function(self, data)
HideCoA.DeleteProfile(data.targetName)
UIDropDownMenu_SetText(deleteDropDown, "")
UIDropDownMenu_SetText(profileDropDown, HideCoA.GetActiveProfileName())
HideCoA.ApplySetting()
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
preferredIndex = 3,
}
local function DeleteProfile_OnClick(self)
local targetName = self.value
StaticPopup_Show("HIDECOA_CONFIRM_DELETE_PROFILE", targetName, nil, { targetName = targetName })
end
UIDropDownMenu_Initialize(deleteDropDown, function(self, level)
for _, name in ipairs(GetProfileNames()) do
if name ~= "Default" then
local info = UIDropDownMenu_CreateInfo()
info.text = name
info.value = name
info.func = DeleteProfile_OnClick
UIDropDownMenu_AddButton(info, level)
end
end
end)
UIDropDownMenu_SetWidth(deleteDropDown, 140)
UIDropDownMenu_SetText(deleteDropDown, "")
local divider = sidebar:CreateTexture(nil, "ARTWORK")
divider:SetHeight(1)
divider:SetTexture(1, 1, 1, 0.3)
profileTabButton = CreateFrame("Button", "HideCoAProfileTab", sidebar)
profileTabButton:SetHeight(TAB_HEIGHT)
profileTabButton:SetPoint("BOTTOMLEFT", sidebar, "BOTTOMLEFT", 0, 0)
profileTabButton:SetPoint("RIGHT", sidebar, "RIGHT", 0, 0)
divider:SetPoint("BOTTOMLEFT", profileTabButton, "TOPLEFT", 0, 4)
divider:SetPoint("BOTTOMRIGHT", profileTabButton, "TOPRIGHT", 0, 4)
local profileSelectedTexture = profileTabButton:CreateTexture(nil, "BACKGROUND")
profileSelectedTexture:SetAllPoints()
profileSelectedTexture:SetTexture(1, 1, 1, 0.2)
profileSelectedTexture:Hide()
profileTabButton.selectedTexture = profileSelectedTexture
profileTabButton:SetHighlightTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight", "ADD")
local profileTabText = profileTabButton:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
profileTabText:SetPoint("LEFT", 4, 0)
profileTabText:SetText("Profiles")
local function SelectProfileTab()
classContent:Hide()
profileContent:Show()
for _, button in pairs(tabButtons) do
button.selectedTexture:Hide()
end
profileTabButton.selectedTexture:Show()
UIDropDownMenu_SetText(profileDropDown, HideCoA.GetActiveProfileName())
end
profileTabButton:SetScript("OnClick", SelectProfileTab)
panel:SetScript("OnShow", function()
SelectClass(selectedClass or HideCoA.CUSTOM_CLASSES[1])
end)
InterfaceOptions_AddCategory(panel)