-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsPanel.lua
More file actions
175 lines (145 loc) · 7.02 KB
/
SettingsPanel.lua
File metadata and controls
175 lines (145 loc) · 7.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
local _, ns = ...
local SettingsPanel = {}
local function createText(parent, fontObject, text, anchor, relativeTo, relativePoint, x, y, color)
local label = parent:CreateFontString(nil, "ARTWORK", fontObject)
label:SetPoint(anchor, relativeTo, relativePoint, x or 0, y or 0)
label:SetJustifyH("LEFT")
label:SetJustifyV("TOP")
if color then
label:SetTextColor(color[1], color[2], color[3], color[4] or 1)
end
label:SetText(text or "")
return label
end
function SettingsPanel:RefreshStatus()
if not self.statusText then
return
end
local store = ns.Addon:GetModule("CombatStore")
local tracker = ns.Addon:GetModule("CombatTracker")
local stats = store and store:GetStorageStats() or {}
local active = tracker and tracker:GetCurrentSession() or nil
local lines = {
"Status",
string.format("Stored sessions: %d", stats.sessions or 0),
string.format("Stored matches: %d", stats.matches or 0),
string.format("Stored raw events: %d", stats.totalRawEvents or 0),
string.format("Active session: %s", active and active.id or "none"),
string.format("Active context: %s", active and active.context or "none"),
"Combat analytics source: built-in Damage Meter (Midnight-safe mode)",
"",
"Settings",
string.format("Debug logging: %s", ns.Addon:IsDebugEnabled() and "enabled" or "disabled"),
"Raw event timeline: unavailable on Midnight-safe mode",
string.format("Include general combat: %s", ns.Addon:GetSetting("includeGeneralCombat") and "enabled" or "disabled"),
string.format("Theme preset: %s", ns.Addon:GetSetting("themePreset") or "default"),
string.format("Minimap button: %s (use /ca minimap to toggle)", ns.Addon:GetSetting("showMinimapButton") and "shown" or "hidden"),
string.format("Animations: %s", ns.Addon:GetSetting("enableAnimations") and "enabled" or "disabled"),
string.format("Max suggestions displayed: %d", ns.Addon:GetSetting("maxSuggestionsDisplay") or 3),
"",
"Use /caa or /combatanalytics to open the addon directly.",
}
self.statusText:SetText(table.concat(lines, "\n"))
end
function SettingsPanel:Open()
if InCombatLockdown and InCombatLockdown() then
ns.Addon:PrintWarning("CombatAnalytics settings cannot open during combat.")
return
end
if not self.initialized then
self:Initialize()
end
if self.category and Settings and Settings.OpenToCategory then
Settings.OpenToCategory(self.category:GetID())
return
end
if InterfaceOptionsFrame_OpenToCategory and self.panel then
InterfaceOptionsFrame_OpenToCategory(self.panel)
InterfaceOptionsFrame_OpenToCategory(self.panel)
end
end
function SettingsPanel:BuildPanel()
if self.panel then
return
end
local panel = CreateFrame("Frame")
panel.name = "CombatAnalytics"
panel:Hide()
self.title = createText(panel, "GameFontNormalLarge", "CombatAnalytics", "TOPLEFT", panel, "TOPLEFT", 16, -16, ns.Widgets.THEME.text)
self.subtitle = createText(panel, "GameFontHighlightSmall", "Post-combat analytics for arenas, duels, battlegrounds, and training dummies.", "TOPLEFT", self.title, "BOTTOMLEFT", 0, -6, ns.Widgets.THEME.textMuted)
self.openButton = ns.Widgets.CreateButton(panel, "Open Summary", 120, 24)
self.openButton:SetPoint("TOPLEFT", self.subtitle, "BOTTOMLEFT", 0, -18)
self.openButton:SetScript("OnClick", function()
ns.Addon:OpenView("summary")
end)
self.historyButton = ns.Widgets.CreateButton(panel, "Open History", 120, 24)
self.historyButton:SetPoint("LEFT", self.openButton, "RIGHT", 8, 0)
self.historyButton:SetScript("OnClick", function()
ns.Addon:OpenView("history")
end)
self.insightsButton = ns.Widgets.CreateButton(panel, "Open Insights", 120, 24)
self.insightsButton:SetPoint("LEFT", self.historyButton, "RIGHT", 8, 0)
self.insightsButton:SetScript("OnClick", function()
ns.Addon:OpenView("insights")
end)
self.cleanupButton = ns.Widgets.CreateButton(panel, "Open Cleanup", 120, 24)
self.cleanupButton:SetPoint("LEFT", self.insightsButton, "RIGHT", 8, 0)
self.cleanupButton:SetScript("OnClick", function()
ns.Addon:OpenView("cleanup")
end)
self.debugButton = ns.Widgets.CreateButton(panel, "Toggle Debug", 120, 24)
self.debugButton:SetPoint("TOPLEFT", self.openButton, "BOTTOMLEFT", 0, -16)
self.debugButton:SetScript("OnClick", function()
ns.Addon:SetSetting("enableDebugLogging", not ns.Addon:IsDebugEnabled())
self:RefreshStatus()
end)
self.rawButton = ns.Widgets.CreateButton(panel, "Toggle Raw Events", 140, 24)
self.rawButton:SetPoint("LEFT", self.debugButton, "RIGHT", 8, 0)
self.rawButton:SetScript("OnClick", function()
ns.Addon:SetSetting("keepRawEvents", not ns.Addon:GetSetting("keepRawEvents"))
self:RefreshStatus()
end)
self.rawButton:SetText("Raw Events N/A")
self.rawButton:SetEnabled(false)
self.generalButton = ns.Widgets.CreateButton(panel, "Toggle General Combat", 160, 24)
self.generalButton:SetPoint("LEFT", self.rawButton, "RIGHT", 8, 0)
self.generalButton:SetScript("OnClick", function()
ns.Addon:SetSetting("includeGeneralCombat", not ns.Addon:GetSetting("includeGeneralCombat"))
self:RefreshStatus()
end)
self.minimapButton = ns.Widgets.CreateButton(panel, "Toggle Minimap", 130, 24)
self.minimapButton:SetPoint("LEFT", self.generalButton, "RIGHT", 8, 0)
self.minimapButton:SetScript("OnClick", function()
local current = ns.Addon:GetSetting("showMinimapButton")
ns.Addon:SetSetting("showMinimapButton", not current)
local minimapModule = ns.Addon:GetModule("MinimapButton")
if minimapModule then minimapModule:RefreshVisibility() end
self:RefreshStatus()
end)
self.animationsButton = ns.Widgets.CreateButton(panel, "Toggle Animations", 150, 24)
self.animationsButton:SetPoint("TOPLEFT", self.debugButton, "BOTTOMLEFT", 0, -48)
self.animationsButton:SetScript("OnClick", function()
ns.Addon:SetSetting("enableAnimations", not ns.Addon:GetSetting("enableAnimations"))
self:RefreshStatus()
end)
self.statusText = createText(panel, "GameFontHighlight", "", "TOPLEFT", self.animationsButton, "BOTTOMLEFT", 0, -18, ns.Widgets.THEME.text)
self.statusText:SetWidth(680)
panel:SetScript("OnShow", function()
self:RefreshStatus()
end)
self.panel = panel
end
function SettingsPanel:Initialize()
if self.initialized then
return
end
self:BuildPanel()
if Settings and Settings.RegisterCanvasLayoutCategory and Settings.RegisterAddOnCategory then
self.category = Settings.RegisterCanvasLayoutCategory(self.panel, self.panel.name)
Settings.RegisterAddOnCategory(self.category)
elseif InterfaceOptions_AddCategory then
InterfaceOptions_AddCategory(self.panel)
end
self.initialized = true
end
ns.Addon:RegisterModule("SettingsPanel", SettingsPanel)