562 lines
17 KiB
Lua
562 lines
17 KiB
Lua
-- Guda Settings Popup
|
|
-- UI for adjusting addon settings
|
|
|
|
local addon = Guda
|
|
|
|
local SettingsPopup = {}
|
|
addon.Modules.SettingsPopup = SettingsPopup
|
|
|
|
-- Global function to open settings (called from XML)
|
|
function Guda_OpenSettings()
|
|
local frame = getglobal("Guda_SettingsPopup")
|
|
if frame then
|
|
frame:Show()
|
|
end
|
|
end
|
|
|
|
-- OnLoad
|
|
function Guda_SettingsPopup_OnLoad(self)
|
|
local title = getglobal(self:GetName().."_Title")
|
|
title:SetText("Guda Settings")
|
|
-- Increase title font size
|
|
local titleFont, _, titleFlags = title:GetFont()
|
|
if titleFont then
|
|
title:SetFont(titleFont, 16, titleFlags)
|
|
end
|
|
Guda:Debug("Settings popup loaded")
|
|
end
|
|
|
|
-- OnShow
|
|
function Guda_SettingsPopup_OnShow(self)
|
|
-- Load current settings
|
|
local bagColumns = Guda.Modules.DB:GetSetting("bagColumns") or 10
|
|
local bankColumns = Guda.Modules.DB:GetSetting("bankColumns") or 10
|
|
local iconSize = Guda.Modules.DB:GetSetting("iconSize") or 40
|
|
local iconFontSize = Guda.Modules.DB:GetSetting("iconFontSize") or 12
|
|
local iconSpacing = Guda.Modules.DB:GetSetting("iconSpacing") or 0
|
|
local lockBags = Guda.Modules.DB:GetSetting("lockBags")
|
|
if lockBags == nil then
|
|
lockBags = false
|
|
end
|
|
local hideBorders = Guda.Modules.DB:GetSetting("hideBorders")
|
|
if hideBorders == nil then
|
|
hideBorders = false
|
|
end
|
|
local showQualityBorderEquipment = Guda.Modules.DB:GetSetting("showQualityBorderEquipment")
|
|
if showQualityBorderEquipment == nil then
|
|
showQualityBorderEquipment = true
|
|
end
|
|
local showQualityBorderOther = Guda.Modules.DB:GetSetting("showQualityBorderOther")
|
|
if showQualityBorderOther == nil then
|
|
showQualityBorderOther = true
|
|
end
|
|
local showSearchBar = Guda.Modules.DB:GetSetting("showSearchBar")
|
|
if showSearchBar == nil then
|
|
showSearchBar = true
|
|
end
|
|
|
|
-- Update sliders and checkboxes
|
|
local bagSlider = getglobal("Guda_SettingsPopup_BagColumnsSlider")
|
|
local bankSlider = getglobal("Guda_SettingsPopup_BankColumnsSlider")
|
|
local iconSizeSlider = getglobal("Guda_SettingsPopup_IconSizeSlider")
|
|
local iconFontSizeSlider = getglobal("Guda_SettingsPopup_IconFontSizeSlider")
|
|
local iconSpacingSlider = getglobal("Guda_SettingsPopup_IconSpacingSlider")
|
|
local lockCheckbox = getglobal("Guda_SettingsPopup_LockBagsCheckbox")
|
|
local hideBordersCheckbox = getglobal("Guda_SettingsPopup_HideBordersCheckbox")
|
|
local qualityBorderEquipmentCheckbox = getglobal("Guda_SettingsPopup_QualityBorderEquipmentCheckbox")
|
|
local qualityBorderOtherCheckbox = getglobal("Guda_SettingsPopup_QualityBorderOtherCheckbox")
|
|
local showSearchBarCheckbox = getglobal("Guda_SettingsPopup_ShowSearchBarCheckbox")
|
|
|
|
if bagSlider then
|
|
bagSlider:SetValue(bagColumns)
|
|
end
|
|
|
|
if bankSlider then
|
|
bankSlider:SetValue(bankColumns)
|
|
end
|
|
|
|
if iconSizeSlider then
|
|
iconSizeSlider:SetValue(iconSize)
|
|
end
|
|
|
|
if iconFontSizeSlider then
|
|
iconFontSizeSlider:SetValue(iconFontSize)
|
|
end
|
|
|
|
if iconSpacingSlider then
|
|
iconSpacingSlider:SetValue(iconSpacing)
|
|
end
|
|
|
|
if lockCheckbox then
|
|
lockCheckbox:SetChecked(lockBags and 1 or 0)
|
|
end
|
|
|
|
if hideBordersCheckbox then
|
|
hideBordersCheckbox:SetChecked(hideBorders and 1 or 0)
|
|
end
|
|
|
|
if qualityBorderEquipmentCheckbox then
|
|
qualityBorderEquipmentCheckbox:SetChecked(showQualityBorderEquipment and 1 or 0)
|
|
end
|
|
|
|
if qualityBorderOtherCheckbox then
|
|
qualityBorderOtherCheckbox:SetChecked(showQualityBorderOther and 1 or 0)
|
|
end
|
|
|
|
if showSearchBarCheckbox then
|
|
showSearchBarCheckbox:SetChecked(showSearchBar and 1 or 0)
|
|
end
|
|
end
|
|
|
|
-- Toggle visibility
|
|
function SettingsPopup:Toggle()
|
|
local frame = getglobal("Guda_SettingsPopup")
|
|
if frame then
|
|
if frame:IsShown() then
|
|
frame:Hide()
|
|
else
|
|
frame:Show()
|
|
end
|
|
end
|
|
end
|
|
|
|
-- Bag Columns Slider OnLoad
|
|
function Guda_SettingsPopup_BagColumnsSlider_OnLoad(self)
|
|
getglobal(self:GetName().."Low"):SetText("5")
|
|
getglobal(self:GetName().."High"):SetText("20")
|
|
|
|
local text = getglobal(self:GetName().."Text")
|
|
text:SetText("Bag columns")
|
|
|
|
-- Increase font size
|
|
local font, _, flags = text:GetFont()
|
|
if font then
|
|
text:SetFont(font, 12, flags)
|
|
end
|
|
|
|
self:SetMinMaxValues(5, 20)
|
|
self:SetValueStep(1)
|
|
|
|
local currentValue = Guda.Modules.DB:GetSetting("bagColumns") or 10
|
|
self:SetValue(currentValue)
|
|
end
|
|
|
|
-- Bag Columns Slider OnValueChanged
|
|
function Guda_SettingsPopup_BagColumnsSlider_OnValueChanged(self)
|
|
local value = self:GetValue()
|
|
|
|
-- Update display text
|
|
getglobal(self:GetName().."Text"):SetText("Bag columns: " .. value)
|
|
|
|
-- Save setting
|
|
Guda.Modules.DB:SetSetting("bagColumns", value)
|
|
|
|
-- Refresh bag frame if it's open
|
|
local bagFrame = getglobal("Guda_BagFrame")
|
|
if bagFrame and bagFrame:IsShown() then
|
|
Guda.Modules.BagFrame:Update()
|
|
end
|
|
end
|
|
|
|
-- Bank Columns Slider OnLoad
|
|
function Guda_SettingsPopup_BankColumnsSlider_OnLoad(self)
|
|
getglobal(self:GetName().."Low"):SetText("5")
|
|
getglobal(self:GetName().."High"):SetText("20")
|
|
|
|
local text = getglobal(self:GetName().."Text")
|
|
text:SetText("Bank columns")
|
|
|
|
-- Increase font size
|
|
local font, _, flags = text:GetFont()
|
|
if font then
|
|
text:SetFont(font, 12, flags)
|
|
end
|
|
|
|
self:SetMinMaxValues(5, 20)
|
|
self:SetValueStep(1)
|
|
|
|
local currentValue = Guda.Modules.DB:GetSetting("bankColumns") or 10
|
|
self:SetValue(currentValue)
|
|
end
|
|
|
|
-- Bank Columns Slider OnValueChanged
|
|
function Guda_SettingsPopup_BankColumnsSlider_OnValueChanged(self)
|
|
local value = self:GetValue()
|
|
|
|
-- Update display text
|
|
getglobal(self:GetName().."Text"):SetText("Bank columns: " .. value)
|
|
|
|
-- Save setting
|
|
Guda.Modules.DB:SetSetting("bankColumns", value)
|
|
|
|
-- Refresh bank frame if it's open
|
|
local bankFrame = getglobal("Guda_BankFrame")
|
|
if bankFrame and bankFrame:IsShown() then
|
|
Guda.Modules.BankFrame:Update()
|
|
end
|
|
end
|
|
|
|
-- Icon Size Slider OnLoad
|
|
function Guda_SettingsPopup_IconSizeSlider_OnLoad(self)
|
|
getglobal(self:GetName().."Low"):SetText("30px")
|
|
getglobal(self:GetName().."High"):SetText("64px")
|
|
|
|
local text = getglobal(self:GetName().."Text")
|
|
text:SetText("Icon size")
|
|
|
|
-- Increase font size
|
|
local font, _, flags = text:GetFont()
|
|
if font then
|
|
text:SetFont(font, 12, flags)
|
|
end
|
|
|
|
self:SetMinMaxValues(30, 64)
|
|
self:SetValueStep(1)
|
|
|
|
local currentValue = Guda.Modules.DB:GetSetting("iconSize") or addon.Constants.BUTTON_SIZE
|
|
self:SetValue(currentValue)
|
|
end
|
|
|
|
-- Icon Size Slider OnValueChanged
|
|
function Guda_SettingsPopup_IconSizeSlider_OnValueChanged(self)
|
|
local value = math.floor(self:GetValue() + 0.5)
|
|
|
|
getglobal(self:GetName().."Text"):SetText("Icon size: " .. value .. "px")
|
|
|
|
Guda.Modules.DB:SetSetting("iconSize", value)
|
|
|
|
local bagFrame = getglobal("Guda_BagFrame")
|
|
if bagFrame and bagFrame:IsShown() then
|
|
Guda.Modules.BagFrame:Update()
|
|
end
|
|
|
|
local bankFrame = getglobal("Guda_BankFrame")
|
|
if bankFrame and bankFrame:IsShown() then
|
|
Guda.Modules.BankFrame:Update()
|
|
end
|
|
end
|
|
|
|
-- Icon Font Size Slider OnLoad
|
|
function Guda_SettingsPopup_IconFontSizeSlider_OnLoad(self)
|
|
getglobal(self:GetName().."Low"):SetText("8px")
|
|
getglobal(self:GetName().."High"):SetText("20px")
|
|
|
|
local text = getglobal(self:GetName().."Text")
|
|
text:SetText("Icon font size")
|
|
|
|
-- Increase font size
|
|
local font, _, flags = text:GetFont()
|
|
if font then
|
|
text:SetFont(font, 12, flags)
|
|
end
|
|
|
|
self:SetMinMaxValues(8, 20)
|
|
self:SetValueStep(1)
|
|
|
|
local currentValue = Guda.Modules.DB:GetSetting("iconFontSize") or 12
|
|
self:SetValue(currentValue)
|
|
end
|
|
|
|
-- Icon Font Size Slider OnValueChanged
|
|
function Guda_SettingsPopup_IconFontSizeSlider_OnValueChanged(self)
|
|
local value = math.floor(self:GetValue() + 0.5)
|
|
|
|
getglobal(self:GetName().."Text"):SetText("Icon font size: " .. value .. "px")
|
|
|
|
Guda.Modules.DB:SetSetting("iconFontSize", value)
|
|
|
|
local bagFrame = getglobal("Guda_BagFrame")
|
|
if bagFrame and bagFrame:IsShown() then
|
|
Guda.Modules.BagFrame:Update()
|
|
end
|
|
|
|
local bankFrame = getglobal("Guda_BankFrame")
|
|
if bankFrame and bankFrame:IsShown() then
|
|
Guda.Modules.BankFrame:Update()
|
|
end
|
|
end
|
|
|
|
-- Icon Spacing Slider OnLoad
|
|
function Guda_SettingsPopup_IconSpacingSlider_OnLoad(self)
|
|
getglobal(self:GetName().."Low"):SetText("-5px")
|
|
getglobal(self:GetName().."High"):SetText("10px")
|
|
|
|
local text = getglobal(self:GetName().."Text")
|
|
text:SetText("Icon spacing")
|
|
|
|
-- Increase font size
|
|
local font, _, flags = text:GetFont()
|
|
if font then
|
|
text:SetFont(font, 12, flags)
|
|
end
|
|
|
|
self:SetMinMaxValues(-5, 10)
|
|
self:SetValueStep(1)
|
|
|
|
local currentValue = Guda.Modules.DB:GetSetting("iconSpacing") or 0
|
|
self:SetValue(currentValue)
|
|
end
|
|
|
|
-- Icon Spacing Slider OnValueChanged
|
|
function Guda_SettingsPopup_IconSpacingSlider_OnValueChanged(self)
|
|
local value = math.floor(self:GetValue() + 0.5)
|
|
local displayValue = value >= 0 and value .. "px" or value .. "px"
|
|
getglobal(self:GetName().."Text"):SetText("Icon spacing: " .. displayValue)
|
|
|
|
-- Save setting
|
|
Guda.Modules.DB:SetSetting("iconSpacing", value)
|
|
|
|
-- Update bag frame
|
|
local bagFrame = getglobal("Guda_BagFrame")
|
|
if bagFrame and bagFrame:IsShown() then
|
|
Guda.Modules.BagFrame:Update()
|
|
end
|
|
|
|
-- Update bank frame
|
|
local bankFrame = getglobal("Guda_BankFrame")
|
|
if bankFrame and bankFrame:IsShown() then
|
|
Guda.Modules.BankFrame:Update()
|
|
end
|
|
end
|
|
|
|
-- Lock Bags Checkbox OnLoad
|
|
function Guda_SettingsPopup_LockBagsCheckbox_OnLoad(self)
|
|
local text = getglobal(self:GetName().."Text")
|
|
if text then
|
|
text:SetText("Lock Bags")
|
|
|
|
-- Increase font size
|
|
local font, _, flags = text:GetFont()
|
|
if font then
|
|
text:SetFont(font, 13, flags)
|
|
end
|
|
end
|
|
|
|
local isLocked = false
|
|
if Guda and Guda.Modules and Guda.Modules.DB then
|
|
isLocked = Guda.Modules.DB:GetSetting("lockBags")
|
|
if isLocked == nil then
|
|
isLocked = false
|
|
end
|
|
end
|
|
|
|
self:SetChecked(isLocked and 1 or 0)
|
|
end
|
|
|
|
-- Lock Bags Checkbox OnClick
|
|
function Guda_SettingsPopup_LockBagsCheckbox_OnClick(self)
|
|
local isChecked = self:GetChecked() == 1
|
|
|
|
-- Save setting
|
|
if Guda and Guda.Modules and Guda.Modules.DB then
|
|
Guda.Modules.DB:SetSetting("lockBags", isChecked)
|
|
end
|
|
|
|
-- Update bag frame draggability
|
|
if Guda and Guda.Modules and Guda.Modules.BagFrame and Guda.Modules.BagFrame.UpdateLockState then
|
|
Guda.Modules.BagFrame:UpdateLockState()
|
|
end
|
|
end
|
|
|
|
-- Hide Borders Checkbox OnLoad
|
|
function Guda_SettingsPopup_HideBordersCheckbox_OnLoad(self)
|
|
local text = getglobal(self:GetName().."Text")
|
|
if text then
|
|
text:SetText("Hide Frame Borders")
|
|
|
|
-- Increase font size
|
|
local font, _, flags = text:GetFont()
|
|
if font then
|
|
text:SetFont(font, 13, flags)
|
|
end
|
|
end
|
|
|
|
local hideBorders = false
|
|
if Guda and Guda.Modules and Guda.Modules.DB then
|
|
hideBorders = Guda.Modules.DB:GetSetting("hideBorders")
|
|
if hideBorders == nil then
|
|
hideBorders = false
|
|
end
|
|
end
|
|
|
|
self:SetChecked(hideBorders and 1 or 0)
|
|
end
|
|
|
|
-- Hide Borders Checkbox OnClick
|
|
function Guda_SettingsPopup_HideBordersCheckbox_OnClick(self)
|
|
local isChecked = self:GetChecked() == 1
|
|
|
|
-- Save setting
|
|
if Guda and Guda.Modules and Guda.Modules.DB then
|
|
Guda.Modules.DB:SetSetting("hideBorders", isChecked)
|
|
end
|
|
|
|
-- Update border visibility on both bag and bank frames using helper function
|
|
local bagFrame = getglobal("Guda_BagFrame")
|
|
if bagFrame then
|
|
if isChecked then
|
|
Guda:ApplyBackdrop(bagFrame, "MINIMALIST_BORDER", "DEFAULT")
|
|
else
|
|
Guda:ApplyBackdrop(bagFrame, "DEFAULT_FRAME", "DEFAULT")
|
|
end
|
|
end
|
|
|
|
local bankFrame = getglobal("Guda_BankFrame")
|
|
if bankFrame then
|
|
if isChecked then
|
|
Guda:ApplyBackdrop(bankFrame, "MINIMALIST_BORDER", "DEFAULT")
|
|
else
|
|
Guda:ApplyBackdrop(bankFrame, "DEFAULT_FRAME", "DEFAULT")
|
|
end
|
|
end
|
|
end
|
|
|
|
-- Quality Border Equipment Checkbox OnLoad
|
|
function Guda_SettingsPopup_QualityBorderEquipmentCheckbox_OnLoad(self)
|
|
local text = getglobal(self:GetName().."Text")
|
|
if text then
|
|
text:SetText("Equipment Borders")
|
|
|
|
-- Increase font size
|
|
local font, _, flags = text:GetFont()
|
|
if font then
|
|
text:SetFont(font, 13, flags)
|
|
end
|
|
end
|
|
|
|
local showBorders = true
|
|
if Guda and Guda.Modules and Guda.Modules.DB then
|
|
showBorders = Guda.Modules.DB:GetSetting("showQualityBorderEquipment")
|
|
if showBorders == nil then
|
|
showBorders = true
|
|
end
|
|
end
|
|
|
|
self:SetChecked(showBorders and 1 or 0)
|
|
end
|
|
|
|
-- Quality Border Equipment Checkbox OnClick
|
|
function Guda_SettingsPopup_QualityBorderEquipmentCheckbox_OnClick(self)
|
|
local isChecked = self:GetChecked() == 1
|
|
|
|
-- Save setting
|
|
if Guda and Guda.Modules and Guda.Modules.DB then
|
|
Guda.Modules.DB:SetSetting("showQualityBorderEquipment", isChecked)
|
|
end
|
|
|
|
-- Update bag and bank frames
|
|
local bagFrame = getglobal("Guda_BagFrame")
|
|
if bagFrame and bagFrame:IsShown() then
|
|
Guda.Modules.BagFrame:Update()
|
|
end
|
|
|
|
local bankFrame = getglobal("Guda_BankFrame")
|
|
if bankFrame and bankFrame:IsShown() then
|
|
Guda.Modules.BankFrame:Update()
|
|
end
|
|
end
|
|
|
|
-- Quality Border Other Checkbox OnLoad
|
|
function Guda_SettingsPopup_QualityBorderOtherCheckbox_OnLoad(self)
|
|
local text = getglobal(self:GetName().."Text")
|
|
if text then
|
|
text:SetText("Other Item Borders")
|
|
|
|
-- Increase font size
|
|
local font, _, flags = text:GetFont()
|
|
if font then
|
|
text:SetFont(font, 13, flags)
|
|
end
|
|
end
|
|
|
|
local showBorders = true
|
|
if Guda and Guda.Modules and Guda.Modules.DB then
|
|
showBorders = Guda.Modules.DB:GetSetting("showQualityBorderOther")
|
|
if showBorders == nil then
|
|
showBorders = true
|
|
end
|
|
end
|
|
|
|
self:SetChecked(showBorders and 1 or 0)
|
|
end
|
|
|
|
-- Quality Border Other Checkbox OnClick
|
|
function Guda_SettingsPopup_QualityBorderOtherCheckbox_OnClick(self)
|
|
local isChecked = self:GetChecked() == 1
|
|
|
|
-- Save setting
|
|
if Guda and Guda.Modules and Guda.Modules.DB then
|
|
Guda.Modules.DB:SetSetting("showQualityBorderOther", isChecked)
|
|
end
|
|
|
|
-- Update bag and bank frames
|
|
local bagFrame = getglobal("Guda_BagFrame")
|
|
if bagFrame and bagFrame:IsShown() then
|
|
Guda.Modules.BagFrame:Update()
|
|
end
|
|
|
|
local bankFrame = getglobal("Guda_BankFrame")
|
|
if bankFrame and bankFrame:IsShown() then
|
|
Guda.Modules.BankFrame:Update()
|
|
end
|
|
end
|
|
|
|
-- Show Search Bar Checkbox OnLoad
|
|
function Guda_SettingsPopup_ShowSearchBarCheckbox_OnLoad(self)
|
|
local text = getglobal(self:GetName().."Text")
|
|
if text then
|
|
text:SetText("Show Search Bar")
|
|
|
|
-- Increase font size
|
|
local font, _, flags = text:GetFont()
|
|
if font then
|
|
text:SetFont(font, 13, flags)
|
|
end
|
|
end
|
|
|
|
local showSearchBar = true
|
|
if Guda and Guda.Modules and Guda.Modules.DB then
|
|
showSearchBar = Guda.Modules.DB:GetSetting("showSearchBar")
|
|
if showSearchBar == nil then
|
|
showSearchBar = true
|
|
end
|
|
end
|
|
|
|
self:SetChecked(showSearchBar and 1 or 0)
|
|
end
|
|
|
|
-- Show Search Bar Checkbox OnClick
|
|
function Guda_SettingsPopup_ShowSearchBarCheckbox_OnClick(self)
|
|
local isChecked = self:GetChecked() == 1
|
|
|
|
-- Save setting
|
|
if Guda and Guda.Modules and Guda.Modules.DB then
|
|
Guda.Modules.DB:SetSetting("showSearchBar", isChecked)
|
|
end
|
|
|
|
-- Update search bar visibility in bag frame
|
|
local bagFrame = getglobal("Guda_BagFrame")
|
|
if bagFrame and bagFrame:IsShown() then
|
|
-- Use the UpdateSearchBarVisibility function which handles anchoring
|
|
if Guda.Modules.BagFrame.UpdateSearchBarVisibility then
|
|
Guda.Modules.BagFrame:UpdateSearchBarVisibility()
|
|
end
|
|
Guda.Modules.BagFrame:Update()
|
|
end
|
|
|
|
-- Update search bar visibility in bank frame
|
|
local bankFrame = getglobal("Guda_BankFrame")
|
|
if bankFrame and bankFrame:IsShown() then
|
|
-- Use the UpdateSearchBarVisibility function which handles anchoring
|
|
if Guda.Modules.BankFrame.UpdateSearchBarVisibility then
|
|
Guda.Modules.BankFrame:UpdateSearchBarVisibility()
|
|
end
|
|
Guda.Modules.BankFrame:Update()
|
|
end
|
|
end
|
|
|
|
-- Initialize
|
|
function SettingsPopup:Initialize()
|
|
Guda:Debug("Settings popup initialized")
|
|
end
|