--[[ Author: Jarth Filename: CBs_Settings.lua ]] -- ------------------------------------------------------------------------------------------------- -- VARIABLES -- ------------------------------------------------------------------------------------------------- local base = CollectionBars local texts = base.Texts ------------------------------------------------------------------------------------------------- -- FUNCTIONS -- ------------------------------------------------------------------------------------------------- function base.InitializeSettingsSlash() SLASH_COMMANDS[base.Addon.SettingsSlash] = function() base.ShowSettings() end end function base.ToggleEnableSettings() base.Global.EnableSettings = not base.Global.EnableSettings base.RestoreFrames() base.RestoreCombineLabels() end function base.SetupToggleSettings(_type) local toggleSettings = GetControl(base.Addon.Abbreviation .. texts.Helpers.Lowdash .. texts.Components.HideAll .. _type.Name .. texts.Components.Toggle .. texts.Components.Settings) if toggleSettings then local hideAllSettingsFunc = function() base.ShowSettings(_type) end toggleSettings:SetHandler(texts.Action.OnClicked, hideAllSettingsFunc) end end function base.UpdateToggleSettings(_type) local offsetX = 0 if base.Global.EnableSettings then offsetX = -19 end if _type.FrameLabel and _type.FrameToggleSettings then _type.FrameToggleSettings:ClearAnchors() _type.FrameToggleSettings:SetAnchor(TOPLEFT, _type.FrameLabel, TOPRIGHT, offsetX, 0) _type.FrameToggleSettings:SetAnchor(BOTTOMRIGHT, _type.FrameLabel, BOTTOMRIGHT, 0, 0) end if _type.FrameLabel and _type.FrameLabelButton then _type.FrameLabelButton:ClearAnchors() _type.FrameLabelButton:SetAnchor(TOPLEFT, _type.FrameLabel, TOPLEFT, 0, 0) _type.FrameLabelButton:SetAnchor(BOTTOMRIGHT, _type.FrameLabel, BOTTOMRIGHT, offsetX, 0) end end function base.SetupSettingsFrameHandlers(control, text, onClicked) control.tooltipText = text control:SetHandler(texts.Action.OnClicked, onClicked) control:SetHandler(texts.Action.OnMouseEnter, function(_control) ZO_Tooltips_ShowTextTooltip(_control, BOTTOM, _control.tooltipText) end) control:SetHandler(texts.Action.OnMouseExit, function() ZO_Tooltips_HideTextTooltip() end) end function base.SetupSetttingsFrame(_type) local selector = base.Addon.Abbreviation .. texts.Helpers.Lowdash .. texts.Components.Settings base.Global.SettingsFrame = base.WM:CreateControlFromVirtual(selector, GuiRoot, selector) base.Global.SettingsLabel = GetControl(selector .. texts.Components.Label) base.Global.SettingsList = CBs_Settings_List:New(_type, base.Global.SettingsFrame) local titleControl = GetControl(selector .. texts.Components.Title) titleControl:SetText(base.Addon.DisplayName .. texts.Helpers.Space .. texts.Components.Settings) if base.Global.SettingsFrame.closeFrame == nil then base.Global.SettingsFrame.closeFrame = GetControl(base.Global.SettingsFrame, texts.Components.Close) end if base.Global.SettingsFrame.closeFrame then base.SetupSettingsFrameHandlers(base.Global.SettingsFrame.closeFrame, texts.Components.Close, function(buttonControl) buttonControl:GetParent():SetHidden(true) end) end if base.Global.SettingsFrame.moveFrame == nil then base.Global.SettingsFrame.moveFrame = GetControl(base.Global.SettingsFrame, texts.Components.Move) end if base.Global.SettingsFrame.moveFrame then base.SetupSettingsFrameHandlers(base.Global.SettingsFrame.moveFrame, texts.Settings.ToggleMoveFrameText, function() base.Global.IsMoveEnabled = not base.Global.IsMoveEnabled base.Global.SettingsList:RefreshData() base.RestoreFrames() end) end if base.Global.SettingsFrame.refreshFrame == nil then base.Global.SettingsFrame.refreshFrame = GetControl(base.Global.SettingsFrame, texts.Components.Refresh) end if base.Global.SettingsFrame.refreshFrame then base.SetupSettingsFrameHandlers(base.Global.SettingsFrame.refreshFrame, texts.Settings.ReloadText, function() if base.Global.SettingsList._type ~= nil then base.CreateCategory(base.Global.SettingsList._type) base.RestoreFrame(base.Global.SettingsList._type) end base.RestoreCombineLabels() base.Global.SettingsList:RefreshData() end) end for controlName, displayName in pairs(base.Global.SettingsFilters) do base.SetupSettingsFilter(base.Global.SettingsFrame, controlName, displayName) end end function base.SetupSettingsFilter(control, controlName, displayName) local filterControl = GetControl(control, controlName) if filterControl then base.SetControlText(filterControl, displayName) filterControl:SetHandler(texts.Action.OnClicked, function() base.Global.SettingsList.masterListType = controlName base.Global.SettingsList:RefreshFilters() end) end end function base.ShowSettings(_type) local show = base.Global.SettingsFrame == nil if show then base.SetupSetttingsFrame(_type) end show = show or base.Global.SettingsFrame:IsHidden() or _type ~= base.Global.SettingsList._type base.Global.SettingsFrame:SetHidden(not show) base.UpdateSettingsType(show, _type) if show then base.Global.SettingsList._type = show and _type or nil base.Global.SettingsList:RefreshData() end end function base.UpdateSettingsType(show, _type) if base.Global.SettingsList ~= nil then base.Global.SettingsList._type = _type end if base.Global.SettingsLabel ~= nil then base.Global.SettingsLabel:SetText(show and _type and _type.Name or texts.Components.Global) end end