-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUI.lua
More file actions
425 lines (368 loc) · 15.1 KB
/
UI.lua
File metadata and controls
425 lines (368 loc) · 15.1 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
local addonName, addon = ...
local ActionTracker = addon
local AceGUI = LibStub("AceGUI-3.0")
local mainFrame = nil
local currentTab = "combat"
function ActionTracker:ToggleUI()
if mainFrame and mainFrame:IsShown() then
mainFrame:Hide()
else
self:ShowUI()
end
end
function ActionTracker:ShowUI()
if mainFrame then
self:RefreshUI()
mainFrame:Show()
return
end
-- Create main frame
mainFrame = AceGUI:Create("Frame")
mainFrame:SetTitle("ActionTracker Statistics")
mainFrame:SetStatusText("Tracking your gameplay statistics")
mainFrame:SetLayout("Fill")
mainFrame:SetWidth(600)
mainFrame:SetHeight(500)
mainFrame:SetCallback("OnClose", function(widget)
widget:Hide()
end)
-- Create tab group
local tabGroup = AceGUI:Create("TabGroup")
tabGroup:SetLayout("Fill")
tabGroup:SetTabs({
{text = "Combat", value = "combat"},
{text = "Economy", value = "economy"},
{text = "Lifestyle", value = "lifestyle"},
{text = "Account", value = "account"},
})
tabGroup:SetCallback("OnGroupSelected", function(container, event, group)
currentTab = group
self:RefreshTabContent(container, group)
end)
mainFrame:AddChild(tabGroup)
-- Select combat tab by default
tabGroup:SelectTab("combat")
self.tabGroup = tabGroup
end
function ActionTracker:RefreshUI()
if self.tabGroup then
self:RefreshTabContent(self.tabGroup, currentTab)
end
end
function ActionTracker:RefreshTabContent(container, tab)
container:ReleaseChildren()
-- Create scrollable container for all tab content
local scroll = AceGUI:Create("ScrollFrame")
scroll:SetLayout("Flow")
scroll:SetFullWidth(true)
scroll:SetFullHeight(true)
container:AddChild(scroll)
if tab == "combat" then
self:DrawCombatTab(scroll)
elseif tab == "economy" then
self:DrawEconomyTab(scroll)
elseif tab == "lifestyle" then
self:DrawLifestyleTab(scroll)
elseif tab == "account" then
self:DrawAccountTab(scroll)
end
end
function ActionTracker:DrawCombatTab(container)
local data = self:GetCharacterData()
local combat = data.combat
-- Summary section
local summaryGroup = AceGUI:Create("InlineGroup")
summaryGroup:SetTitle("Combat Summary")
summaryGroup:SetFullWidth(true)
summaryGroup:SetLayout("Flow")
container:AddChild(summaryGroup)
local stats = {
{label = "Abilities Used", value = self:FormatNumber(combat.totalAbilitiesUsed)},
{label = "Total Damage", value = self:FormatNumber(combat.totalDamage)},
{label = "Total Healing", value = self:FormatNumber(combat.totalHealing)},
{label = "Damage Taken", value = self:FormatNumber(combat.totalDamageTaken)},
{label = "Total Kills", value = tostring(combat.totalKills)},
{label = "Deaths", value = tostring(combat.deaths)},
{label = "XP from Kills", value = self:FormatNumber(combat.xpFromKills or 0)},
}
for _, stat in ipairs(stats) do
local label = AceGUI:Create("Label")
label:SetText(string.format("|cffffd700%s:|r %s", stat.label, stat.value))
label:SetWidth(180)
summaryGroup:AddChild(label)
end
-- Abilities section
local abilitiesGroup = AceGUI:Create("InlineGroup")
abilitiesGroup:SetTitle("Top Abilities (Top 15)")
abilitiesGroup:SetFullWidth(true)
abilitiesGroup:SetLayout("List")
container:AddChild(abilitiesGroup)
local sorted = self:GetSortedAbilities(combat.abilities, "count")
if #sorted == 0 then
local noData = AceGUI:Create("Label")
noData:SetText("No abilities tracked yet. Start fighting!")
noData:SetFullWidth(true)
abilitiesGroup:AddChild(noData)
else
for i, ability in ipairs(sorted) do
if i > 15 then break end
local row = AceGUI:Create("Label")
local damageStr = ability.damage > 0 and string.format(" | %s dmg", self:FormatNumber(ability.damage)) or ""
local healStr = ability.healing > 0 and string.format(" | %s heal", self:FormatNumber(ability.healing)) or ""
row:SetText(string.format("|cff00ff00%d.|r %s: |cffffffff%d uses|r%s%s",
i, ability.name, ability.count, damageStr, healStr))
row:SetFullWidth(true)
abilitiesGroup:AddChild(row)
end
end
-- Kills section
if combat.kills and next(combat.kills) then
local killsGroup = AceGUI:Create("InlineGroup")
killsGroup:SetTitle("Kills by Mob (Top 15)")
killsGroup:SetFullWidth(true)
killsGroup:SetLayout("List")
container:AddChild(killsGroup)
local killsSorted = {}
for name, count in pairs(combat.kills) do
table.insert(killsSorted, {name = name, count = count})
end
table.sort(killsSorted, function(a, b) return a.count > b.count end)
for i, kill in ipairs(killsSorted) do
if i > 15 then break end
local row = AceGUI:Create("Label")
row:SetText(string.format("|cff00ff00%d.|r %s: |cffffffff%d kills|r", i, kill.name, kill.count))
row:SetFullWidth(true)
killsGroup:AddChild(row)
end
end
end
function ActionTracker:DrawEconomyTab(container)
local data = self:GetCharacterData()
local economy = data.economy
-- Gold Summary
local goldGroup = AceGUI:Create("InlineGroup")
goldGroup:SetTitle("Gold Summary")
goldGroup:SetFullWidth(true)
goldGroup:SetLayout("List")
container:AddChild(goldGroup)
local goldEarned = economy.goldEarned or 0
local goldSpent = economy.goldSpent or 0
local goldStats = {
{label = "Total Gold Earned", value = GetCoinTextureString(goldEarned)},
{label = "Total Gold Spent", value = GetCoinTextureString(goldSpent)},
{label = "Net Gold", value = GetCoinTextureString(goldEarned - goldSpent)},
}
for _, stat in ipairs(goldStats) do
local label = AceGUI:Create("Label")
label:SetText(string.format("|cffffd700%s:|r %s", stat.label, stat.value))
label:SetFullWidth(true)
goldGroup:AddChild(label)
end
-- Gold Sources
local sourcesGroup = AceGUI:Create("InlineGroup")
sourcesGroup:SetTitle("Gold by Source")
sourcesGroup:SetFullWidth(true)
sourcesGroup:SetLayout("List")
container:AddChild(sourcesGroup)
local sourceStats = {
{label = "From Vendors (selling)", value = GetCoinTextureString(economy.goldFromVendor or 0)},
{label = "From Mail", value = GetCoinTextureString(economy.goldFromMail or 0)},
{label = "From Loot", value = GetCoinTextureString(economy.goldFromLoot or 0)},
{label = "From Quests", value = GetCoinTextureString(economy.goldFromQuest or 0)},
}
for _, stat in ipairs(sourceStats) do
local label = AceGUI:Create("Label")
label:SetText(string.format(" |cff888888%s:|r %s", stat.label, stat.value))
label:SetFullWidth(true)
sourcesGroup:AddChild(label)
end
-- XP & Quests
local xpGroup = AceGUI:Create("InlineGroup")
xpGroup:SetTitle("Experience & Quests")
xpGroup:SetFullWidth(true)
xpGroup:SetLayout("List")
container:AddChild(xpGroup)
local xpStats = {
{label = "Quests Completed", value = tostring(economy.questsCompleted or 0)},
{label = "XP from Quests", value = self:FormatNumber(economy.xpFromQuests or 0)},
{label = "Items Looted", value = tostring(economy.itemsLooted or 0)},
}
for _, stat in ipairs(xpStats) do
local label = AceGUI:Create("Label")
label:SetText(string.format("|cffffd700%s:|r %s", stat.label, stat.value))
label:SetFullWidth(true)
xpGroup:AddChild(label)
end
end
local function FormatPlaytime(seconds)
if not seconds or seconds <= 0 then return "0m" end
local days = math.floor(seconds / 86400)
local hours = math.floor((seconds % 86400) / 3600)
local minutes = math.floor((seconds % 3600) / 60)
if days > 0 then
return string.format("%dd %dh %dm", days, hours, minutes)
elseif hours > 0 then
return string.format("%dh %dm", hours, minutes)
else
return string.format("%dm", minutes)
end
end
local function GetClassColor(classEnglish)
if classEnglish and RAID_CLASS_COLORS and RAID_CLASS_COLORS[classEnglish] then
local c = RAID_CLASS_COLORS[classEnglish]
return string.format("%02x%02x%02x", c.r * 255, c.g * 255, c.b * 255)
end
return "ffffff"
end
function ActionTracker:DrawLifestyleTab(container)
-- Collect all characters with playtime data
local characters = {}
local totalTime = 0
for charKey, charData in pairs(self.db.profile.characters) do
if charKey ~= "" and charData.lifestyle then
local time = charData.lifestyle.timePlayed or 0
local meta = charData.meta or {}
table.insert(characters, {
key = charKey,
faction = meta.faction or "Unknown",
class = meta.class or "Unknown",
classEnglish = meta.classEnglish or "WARRIOR",
race = meta.race or "",
level = meta.level or 0,
timePlayed = time,
})
totalTime = totalTime + time
end
end
-- Sort by faction, then class, then time descending
table.sort(characters, function(a, b)
if a.faction ~= b.faction then return a.faction < b.faction end
if a.class ~= b.class then return a.class < b.class end
return a.timePlayed > b.timePlayed
end)
-- Total playtime header
local totalGroup = AceGUI:Create("InlineGroup")
totalGroup:SetTitle("Playtime Overview")
totalGroup:SetFullWidth(true)
totalGroup:SetLayout("List")
container:AddChild(totalGroup)
local totalLabel = AceGUI:Create("Label")
totalLabel:SetText(string.format("|cffffd700Total Playtime:|r |cffffffff%s|r |cff888888(%d characters)|r",
FormatPlaytime(totalTime), #characters))
totalLabel:SetFullWidth(true)
totalGroup:AddChild(totalLabel)
if #characters == 0 then
local note = AceGUI:Create("Label")
note:SetText("\n|cff888888No playtime data yet. Log in to each character to record playtime.|r")
note:SetFullWidth(true)
container:AddChild(note)
return
end
-- Group by faction
local factions = {}
local factionOrder = {}
for _, char in ipairs(characters) do
if not factions[char.faction] then
factions[char.faction] = { time = 0, classes = {}, classOrder = {} }
table.insert(factionOrder, char.faction)
end
local f = factions[char.faction]
f.time = f.time + char.timePlayed
if not f.classes[char.class] then
f.classes[char.class] = { time = 0, classEnglish = char.classEnglish, chars = {} }
table.insert(f.classOrder, char.class)
end
local cl = f.classes[char.class]
cl.time = cl.time + char.timePlayed
table.insert(cl.chars, char)
end
-- Draw faction groups
for _, factionName in ipairs(factionOrder) do
local fData = factions[factionName]
local factionGroup = AceGUI:Create("InlineGroup")
factionGroup:SetTitle(string.format("%s - %s", factionName, FormatPlaytime(fData.time)))
factionGroup:SetFullWidth(true)
factionGroup:SetLayout("List")
container:AddChild(factionGroup)
-- Faction header color
if factionGroup.content then
local bg = factionGroup.content:CreateTexture(nil, "BACKGROUND")
bg:SetAllPoints()
if factionName == "Horde" then
bg:SetColorTexture(0.6, 0.1, 0.1, 0.06)
elseif factionName == "Alliance" then
bg:SetColorTexture(0.1, 0.2, 0.6, 0.06)
end
end
for _, className in ipairs(fData.classOrder) do
local clData = fData.classes[className]
local cColor = GetClassColor(clData.classEnglish)
-- Class header
local classHeader = AceGUI:Create("Label")
classHeader:SetText(string.format(" |cff%s%s|r |cff888888- %s|r",
cColor, className, FormatPlaytime(clData.time)))
classHeader:SetFullWidth(true)
classHeader:SetFontObject(GameFontNormal)
factionGroup:AddChild(classHeader)
-- Character rows
for _, char in ipairs(clData.chars) do
local name = char.key:match("^(.+)-") or char.key
local realm = char.key:match("-(.+)$") or ""
local row = AceGUI:Create("Label")
row:SetText(string.format(
" |cff%s%s|r |cff666666%s|r |cffaaaaaa%s|r |cffffd700Lv %d|r |cffffffff%s|r",
cColor, name, realm, char.race, char.level, FormatPlaytime(char.timePlayed)))
row:SetFullWidth(true)
factionGroup:AddChild(row)
end
end
end
end
function ActionTracker:DrawAccountTab(container)
local account = self:GetAccountData()
local combatGroup = AceGUI:Create("InlineGroup")
combatGroup:SetTitle("Account-Wide Combat Stats")
combatGroup:SetFullWidth(true)
combatGroup:SetLayout("Flow")
container:AddChild(combatGroup)
local stats = {
{label = "Total Abilities Used", value = self:FormatNumber(account.combat.totalAbilitiesUsed)},
{label = "Total Damage Done", value = self:FormatNumber(account.combat.totalDamage)},
{label = "Total Healing Done", value = self:FormatNumber(account.combat.totalHealing)},
{label = "Total Damage Taken", value = self:FormatNumber(account.combat.totalDamageTaken)},
{label = "Total Kills", value = tostring(account.combat.totalKills)},
{label = "Total Deaths", value = tostring(account.combat.deaths)},
}
for _, stat in ipairs(stats) do
local label = AceGUI:Create("Label")
label:SetText(string.format("|cffffd700%s:|r %s", stat.label, stat.value))
label:SetWidth(280)
combatGroup:AddChild(label)
end
-- List characters
local charsGroup = AceGUI:Create("InlineGroup")
charsGroup:SetTitle("Characters Tracked")
charsGroup:SetFullWidth(true)
charsGroup:SetLayout("List")
container:AddChild(charsGroup)
local charCount = 0
for charKey, charData in pairs(self.db.profile.characters) do
if charKey ~= "" and charData.combat then
charCount = charCount + 1
local label = AceGUI:Create("Label")
label:SetText(string.format("|cff00ff00%s|r - %s abilities, %s damage, %d kills",
charKey,
self:FormatNumber(charData.combat.totalAbilitiesUsed),
self:FormatNumber(charData.combat.totalDamage),
charData.combat.totalKills))
label:SetFullWidth(true)
charsGroup:AddChild(label)
end
end
if charCount == 0 then
local noData = AceGUI:Create("Label")
noData:SetText("No character data yet.")
noData:SetFullWidth(true)
charsGroup:AddChild(noData)
end
end