Repository navigation
Expand file tree
/
Copy pathEasyTrackerCore.lua
More file actions
871 lines (795 loc) · 31 KB
/
Copy pathEasyTrackerCore.lua
File metadata and controls
871 lines (795 loc) · 31 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
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
local ADDON_NAME = ...
local addon = CreateFrame("Frame")
local MAX_LOOT_ROWS = 16
local MAX_STORED_LOOT = 40
local XP_WINDOW_SECONDS = 15 * 60
local UPDATE_INTERVAL = 1
local ROW_HEIGHT = 22
local ROWS_TOP = 188
local FOOTER_SPACE = 45
local defaults = {
point = "CENTER",
relativePoint = "CENTER",
x = 300,
y = 20,
width = 410,
height = 410,
locked = false,
collapsed = false,
loot = {},
session = {
startedAt = 0,
cashGained = 0,
xpGained = 0,
},
settings = {
alertGold = 25,
alertSound = true,
minimumQuality = 0,
sortMode = "newest",
},
}
local db
local panel
local content
local xpBar
local xpText
local rateText
local etaText
local sessionText
local farmLine1
local farmLine2
local lootTotalText
local scanAgeText
local settingsPanel
local lootRows = {}
local visibleEntries = {}
local samples = {}
local lastXP = 0
local lastXPMax = 0
local lastLevel = 0
local lastMoney = 0
local elapsedSinceUpdate = 0
local activeRowCount = 0
local changingCollapse = false
local floor = math.floor
local max = math.max
local min = math.min
local RefreshLoot
local UpdateAll
local ResetXPTracking
local StartNewSession
local ClearLoot
local qualityNames = {
[0] = "All qualities",
[1] = "Common+",
[2] = "Uncommon+",
[3] = "Rare+",
[4] = "Epic+",
}
local function CopyDefaults(target, source)
for key, value in pairs(source) do
if target[key] == nil then
if type(value) == "table" then
target[key] = {}
CopyDefaults(target[key], value)
else
target[key] = value
end
elseif type(value) == "table" and type(target[key]) == "table" then
CopyDefaults(target[key], value)
end
end
end
local function FormatNumber(value)
value = floor(tonumber(value) or 0)
local formatted = tostring(value)
while true do
local replaced
formatted, replaced = string.gsub(formatted, "^(-?%d+)(%d%d%d)", "%1,%2")
if replaced == 0 then break end
end
return formatted
end
local function FormatDuration(seconds)
if not seconds or seconds < 0 or seconds == math.huge then return "--" end
seconds = floor(seconds + 0.5)
if seconds < 60 then
return seconds .. "s"
elseif seconds < 3600 then
return floor(seconds / 60) .. "m " .. (seconds % 60) .. "s"
elseif seconds < 86400 then
return floor(seconds / 3600) .. "h " .. floor((seconds % 3600) / 60) .. "m"
end
return floor(seconds / 86400) .. "d " .. floor((seconds % 86400) / 3600) .. "h"
end
local function FormatMoney(copper, noDataText)
copper = floor(tonumber(copper) or 0)
if copper <= 0 then return noDataText or "0|cffb87333c|r" end
local gold = floor(copper / 10000)
local silver = floor((copper % 10000) / 100)
local coins = copper % 100
local result = ""
if gold > 0 then result = result .. FormatNumber(gold) .. "|cffffd36bg|r " end
if silver > 0 or gold > 0 then result = result .. silver .. "|cffc7c7c7s|r " end
return result .. coins .. "|cffb87333c|r"
end
local function ShortName(name, length)
name = name or "Unknown item"
length = length or 20
if string.len(name) <= length then return name end
return string.sub(name, 1, length - 3) .. "..."
end
local function AuctionPrice(item)
if not item then return nil end
if type(Atr_GetAuctionPrice) == "function" then
local price = Atr_GetAuctionPrice(item)
if price and price > 0 then return price end
end
if type(Atr_GetAuctionBuyout) == "function" then
local price = Atr_GetAuctionBuyout(item)
if price and price > 0 then return price end
end
if type(GetAuctionBuyout) == "function" then
local price = GetAuctionBuyout(item)
if price and price > 0 then return price end
end
return nil
end
local function MakeText(parent, size, color)
local text = parent:CreateFontString(nil, "OVERLAY")
text:SetFont("Fonts\\FRIZQT__.TTF", size, "OUTLINE")
text:SetTextColor(color[1], color[2], color[3])
return text
end
local function MakeButton(parent, text, width)
local button = CreateFrame("Button", nil, parent, "UIPanelButtonTemplate")
button:SetSize(width or 86, 20)
button:SetText(text)
return button
end
local function SavePosition()
local point, _, relativePoint, x, y = panel:GetPoint(1)
db.point = point or "CENTER"
db.relativePoint = relativePoint or "CENTER"
db.x = floor((x or 0) + 0.5)
db.y = floor((y or 0) + 0.5)
end
local function SaveSize()
if not db.collapsed and not changingCollapse then
db.width = floor(panel:GetWidth() + 0.5)
db.height = floor(panel:GetHeight() + 0.5)
end
end
local function TrimSamples(now)
while #samples > 0 and now - samples[1].time > XP_WINDOW_SECONDS do
table.remove(samples, 1)
end
end
local function AddXPSample(amount)
if not amount or amount <= 0 then return end
local now = GetTime()
samples[#samples + 1] = { time = now, amount = amount }
db.session.xpGained = (db.session.xpGained or 0) + amount
TrimSamples(now)
end
local function CalculateRate()
local now = GetTime()
TrimSamples(now)
if #samples == 0 then return 0 end
local gained = 0
for index = 1, #samples do gained = gained + samples[index].amount end
local window = now - samples[1].time
if window < 30 then return 0 end
return gained / window * 3600
end
local function CalculateLootStats()
local totalValue = 0
local totalCount = 0
local bestEntry
local bestValue = 0
visibleEntries = {}
for index = 1, #db.loot do
local entry = db.loot[index]
local itemName, _, rarity, _, _, _, _, _, _, texture = GetItemInfo(entry.link)
entry.name = itemName or entry.name or "Unknown item"
entry.rarity = rarity or entry.rarity or 1
entry.texture = texture or entry.texture or "Interface\\Icons\\INV_Misc_QuestionMark"
entry.unitPrice = AuctionPrice(entry.link) or AuctionPrice(entry.name) or entry.unitPrice or 0
entry.count = entry.count or 1
entry.lootedAt = entry.lootedAt or time()
local value = entry.unitPrice * entry.count
totalValue = totalValue + value
totalCount = totalCount + entry.count
if value > bestValue then
bestValue = value
bestEntry = entry
end
if entry.rarity >= db.settings.minimumQuality then
visibleEntries[#visibleEntries + 1] = entry
end
end
table.sort(visibleEntries, function(a, b)
if db.settings.sortMode == "value" then
local av = (a.unitPrice or 0) * (a.count or 1)
local bv = (b.unitPrice or 0) * (b.count or 1)
if av == bv then return (a.lootedAt or 0) > (b.lootedAt or 0) end
return av > bv
end
return (a.lootedAt or 0) > (b.lootedAt or 0)
end)
return totalValue, totalCount, bestEntry, bestValue
end
local function UpdateScanAge()
local scanTime = tonumber(AUCTIONATOR_LAST_SCAN_TIME)
if not scanTime or scanTime <= 0 then
scanAgeText:SetText("|cffff8a5cAuctionator: no scan timestamp|r")
return
end
local age = max(0, time() - scanTime)
local color = age > (7 * 86400) and "|cffff8a5c" or "|cff8faf79"
scanAgeText:SetText(color .. "Auctionator scan: " .. FormatDuration(age) .. " ago|r")
end
local function UpdateFarmStats(totalValue, totalCount, bestEntry)
local elapsed = max(1, time() - (db.session.startedAt or time()))
local valuePerHour = totalValue / elapsed * 3600
farmLine1:SetText("Farm " .. FormatDuration(elapsed) .. " | " .. totalCount .. " items | " .. FormatMoney(totalValue))
local bestName = bestEntry and ShortName(bestEntry.name, 18) or "--"
farmLine2:SetText(FormatMoney(valuePerHour) .. "/hr | +" .. FormatMoney(db.session.cashGained or 0) .. " cash | Best: " .. bestName)
end
local function UpdateRows()
for index = 1, MAX_LOOT_ROWS do
local row = lootRows[index]
local entry = index <= activeRowCount and visibleEntries[index] or nil
if entry then
local color = ITEM_QUALITY_COLORS and ITEM_QUALITY_COLORS[entry.rarity]
if color then row.name:SetTextColor(color.r, color.g, color.b) else row.name:SetTextColor(1, 1, 1) end
row.icon:SetTexture(entry.texture)
row.name:SetText(entry.name)
row.count:SetText(entry.count > 1 and ("x" .. entry.count) or "")
row.price:SetText(FormatMoney(entry.unitPrice * entry.count, "|cff8b7d6bNo AH data|r"))
row.entry = entry
row:Show()
else
row.entry = nil
row:Hide()
end
end
end
RefreshLoot = function()
if not panel then return end
local totalValue, totalCount, bestEntry = CalculateLootStats()
lootTotalText:SetText("Total " .. FormatMoney(totalValue))
UpdateFarmStats(totalValue, totalCount, bestEntry)
UpdateRows()
UpdateScanAge()
end
local function UpdateXP()
if not panel then return end
local current = UnitXP("player") or 0
local maximum = UnitXPMax("player") or 0
local level = UnitLevel("player") or 0
local rate = CalculateRate()
xpBar:SetMinMaxValues(0, max(1, maximum))
xpBar:SetValue(current)
if maximum <= 0 then
xpText:SetText("Level " .. level .. " - Maximum level")
etaText:SetText("Level complete")
else
xpText:SetText("Level " .. level .. " - " .. FormatNumber(current) .. " / " .. FormatNumber(maximum) .. " XP")
etaText:SetText(rate > 0 and ("Level in " .. FormatDuration((maximum - current) / rate * 3600)) or "Level in --")
end
rateText:SetText(rate > 0 and (FormatNumber(rate) .. " XP/hr") or "Measuring XP pace...")
sessionText:SetText("Session: +" .. FormatNumber(db.session.xpGained or 0) .. " XP")
local rested = GetXPExhaustion and GetXPExhaustion()
if rested and rested > 0 and maximum > 0 then
sessionText:SetText(sessionText:GetText() .. " | Rested " .. floor(rested / maximum * 100) .. "%")
end
end
UpdateAll = function()
UpdateXP()
RefreshLoot()
end
local function ExtractItemLink(message)
return message:match("(|c%x+|Hitem:.-|h%[.-%]|h|r)") or message:match("(|Hitem:.-|h%[.-%]|h)")
end
local function ExtractQuantity(message, link)
local position = message:find(link, 1, true)
local afterLink = position and message:sub(position + #link) or ""
local count = afterLink:match("[xX](%d+)") or afterLink:match("(%d+)%s*[xX]")
return max(1, tonumber(count) or 1)
end
local function ShowValueAlert(link, value)
local message = link .. " " .. FormatMoney(value)
if RaidNotice_AddMessage and RaidWarningFrame then
RaidNotice_AddMessage(RaidWarningFrame, message, ChatTypeInfo["RAID_WARNING"])
elseif UIErrorsFrame then
UIErrorsFrame:AddMessage(message, 1, 0.82, 0.2, 1)
end
if db.settings.alertSound then PlaySound("LEVELUP") end
end
local function AddLoot(message)
local otherLooter = message:match("([^%s]+)%s+receives loot:")
if otherLooter and otherLooter ~= UnitName("player") then return end
local link = ExtractItemLink(message)
if not link then return end
local count = ExtractQuantity(message, link)
local itemName, _, rarity, _, _, _, _, _, _, texture = GetItemInfo(link)
local key = link:match("item:([^|]+)") or link
local entry
local entryIndex
for index = 1, #db.loot do
if db.loot[index].key == key or (not db.loot[index].key and db.loot[index].link == link) then
entry = db.loot[index]
entryIndex = index
break
end
end
if entry then
entry.key = key
entry.count = (entry.count or 1) + count
entry.link = link
entry.lootedAt = time()
table.remove(db.loot, entryIndex)
table.insert(db.loot, 1, entry)
else
entry = {
key = key,
link = link,
name = itemName,
count = count,
rarity = rarity or 1,
texture = texture,
unitPrice = AuctionPrice(link) or AuctionPrice(itemName) or 0,
lootedAt = time(),
}
table.insert(db.loot, 1, entry)
end
while #db.loot > MAX_STORED_LOOT do table.remove(db.loot) end
local dropValue = (AuctionPrice(link) or entry.unitPrice or 0) * count
local threshold = (tonumber(db.settings.alertGold) or 0) * 10000
if threshold > 0 and dropValue >= threshold then ShowValueAlert(link, dropValue) end
RefreshLoot()
end
ResetXPTracking = function()
samples = {}
db.session.xpGained = 0
lastXP = UnitXP("player") or 0
lastXPMax = UnitXPMax("player") or 0
lastLevel = UnitLevel("player") or 0
UpdateXP()
end
ClearLoot = function()
db.loot = {}
RefreshLoot()
end
StartNewSession = function()
db.loot = {}
db.session = {
startedAt = time(),
cashGained = 0,
xpGained = 0,
}
samples = {}
lastMoney = GetMoney() or 0
lastXP = UnitXP("player") or 0
lastXPMax = UnitXPMax("player") or 0
lastLevel = UnitLevel("player") or 0
UpdateAll()
end
StaticPopupDialogs["EASYTRACKER_CLEAR_LOOT"] = {
text = "Clear all loot from the current EasyTracker session?",
button1 = YES,
button2 = NO,
OnAccept = ClearLoot,
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
}
StaticPopupDialogs["EASYTRACKER_NEW_SESSION"] = {
text = "Start a new EasyTracker session? Current XP, cash and loot totals will reset.",
button1 = YES,
button2 = NO,
OnAccept = StartNewSession,
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
}
local function LayoutRows()
if not panel then return end
if db.collapsed then
activeRowCount = 0
else
activeRowCount = floor((panel:GetHeight() - ROWS_TOP - FOOTER_SPACE) / ROW_HEIGHT)
activeRowCount = max(2, min(MAX_LOOT_ROWS, activeRowCount))
end
UpdateRows()
end
local function ApplyLockState()
if db.locked then
panel:RegisterForDrag()
else
panel:RegisterForDrag("LeftButton")
end
panel.rightResize:SetShown(not db.locked and not db.collapsed)
panel.bottomResize:SetShown(not db.locked and not db.collapsed)
end
local function ApplyCollapsedState()
changingCollapse = true
if db.collapsed then
content:Hide()
panel:SetHeight(62)
panel.collapse:SetText("+")
else
panel:SetHeight(max(300, db.height or 410))
content:Show()
panel.collapse:SetText("-")
end
changingCollapse = false
ApplyLockState()
LayoutRows()
end
local function UpdateSettingsControls()
if not settingsPanel then return end
settingsPanel.alertBox:SetText(tostring(db.settings.alertGold or 0))
settingsPanel.qualityButton:SetText(qualityNames[db.settings.minimumQuality] or "All qualities")
settingsPanel.sortButton:SetText(db.settings.sortMode == "value" and "Highest value" or "Newest first")
settingsPanel.soundCheck:SetChecked(db.settings.alertSound)
end
local function SaveAlertThreshold()
local value = tonumber(settingsPanel.alertBox:GetText()) or 0
db.settings.alertGold = max(0, floor(value + 0.5))
settingsPanel.alertBox:SetText(tostring(db.settings.alertGold))
settingsPanel.alertBox:ClearFocus()
end
local function CreateSettingsPanel()
settingsPanel = CreateFrame("Frame", "EasyTrackerSettingsFrame", panel)
settingsPanel:SetSize(250, 190)
settingsPanel:SetPoint("TOPLEFT", panel, "TOPRIGHT", 6, -5)
settingsPanel:SetFrameStrata("DIALOG")
settingsPanel:SetClampedToScreen(true)
settingsPanel:SetBackdrop({
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tileSize = 32, edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 },
})
settingsPanel:SetBackdropColor(0.05, 0.035, 0.02, 0.98)
settingsPanel:SetBackdropBorderColor(0.72, 0.55, 0.27, 1)
local title = MakeText(settingsPanel, 14, {1, 0.82, 0.42})
title:SetPoint("TOPLEFT", 14, -14)
title:SetText("EASYTRACKER SETTINGS")
local close = CreateFrame("Button", nil, settingsPanel, "UIPanelCloseButton")
close:SetPoint("TOPRIGHT", 2, 2)
local alertLabel = MakeText(settingsPanel, 11, {0.9, 0.85, 0.75})
alertLabel:SetPoint("TOPLEFT", 16, -48)
alertLabel:SetText("High-value alert at")
settingsPanel.alertBox = CreateFrame("EditBox", nil, settingsPanel, "InputBoxTemplate")
settingsPanel.alertBox:SetSize(55, 20)
settingsPanel.alertBox:SetPoint("LEFT", alertLabel, "RIGHT", 8, 0)
settingsPanel.alertBox:SetNumeric(true)
settingsPanel.alertBox:SetAutoFocus(false)
settingsPanel.alertBox:SetScript("OnEnterPressed", SaveAlertThreshold)
settingsPanel.alertBox:SetScript("OnEditFocusLost", SaveAlertThreshold)
local goldLabel = MakeText(settingsPanel, 11, {1, 0.82, 0.42})
goldLabel:SetPoint("LEFT", settingsPanel.alertBox, "RIGHT", 5, 0)
goldLabel:SetText("gold")
local qualityLabel = MakeText(settingsPanel, 11, {0.9, 0.85, 0.75})
qualityLabel:SetPoint("TOPLEFT", 16, -82)
qualityLabel:SetText("Minimum quality")
settingsPanel.qualityButton = MakeButton(settingsPanel, "", 105)
settingsPanel.qualityButton:SetPoint("LEFT", qualityLabel, "RIGHT", 8, 0)
settingsPanel.qualityButton:SetScript("OnClick", function()
db.settings.minimumQuality = (db.settings.minimumQuality + 1) % 5
UpdateSettingsControls()
RefreshLoot()
end)
local sortLabel = MakeText(settingsPanel, 11, {0.9, 0.85, 0.75})
sortLabel:SetPoint("TOPLEFT", 16, -114)
sortLabel:SetText("Loot sorting")
settingsPanel.sortButton = MakeButton(settingsPanel, "", 105)
settingsPanel.sortButton:SetPoint("LEFT", sortLabel, "RIGHT", 23, 0)
settingsPanel.sortButton:SetScript("OnClick", function()
db.settings.sortMode = db.settings.sortMode == "value" and "newest" or "value"
UpdateSettingsControls()
RefreshLoot()
end)
settingsPanel.soundCheck = CreateFrame("CheckButton", nil, settingsPanel, "UICheckButtonTemplate")
settingsPanel.soundCheck:SetSize(24, 24)
settingsPanel.soundCheck:SetPoint("TOPLEFT", 13, -142)
settingsPanel.soundCheck:SetScript("OnClick", function(self)
db.settings.alertSound = self:GetChecked() and true or false
end)
local soundLabel = MakeText(settingsPanel, 11, {0.9, 0.85, 0.75})
soundLabel:SetPoint("LEFT", settingsPanel.soundCheck, "RIGHT", 2, 0)
soundLabel:SetText("Play sound for valuable drops")
settingsPanel:Hide()
end
local function CreateResizeEdge(direction)
local grip = CreateFrame("Button", nil, panel)
if direction == "RIGHT" then
grip:SetPoint("TOPRIGHT", -1, -34)
grip:SetPoint("BOTTOMRIGHT", -1, 9)
grip:SetWidth(8)
else
grip:SetPoint("BOTTOMLEFT", 10, 1)
grip:SetPoint("BOTTOMRIGHT", -10, 1)
grip:SetHeight(8)
end
local highlight = grip:CreateTexture(nil, "HIGHLIGHT")
highlight:SetAllPoints()
highlight:SetTexture("Interface\\Buttons\\WHITE8X8")
highlight:SetVertexColor(0.9, 0.65, 0.25, 0.28)
local marker = grip:CreateTexture(nil, "ARTWORK")
marker:SetTexture("Interface\\Buttons\\WHITE8X8")
marker:SetVertexColor(0.85, 0.62, 0.25, 0.55)
marker:SetPoint("CENTER")
if direction == "RIGHT" then marker:SetSize(2, 28) else marker:SetSize(28, 2) end
grip:SetScript("OnMouseDown", function(_, button)
if button == "LeftButton" and not db.locked and not db.collapsed then panel:StartSizing(direction) end
end)
grip:SetScript("OnMouseUp", function()
panel:StopMovingOrSizing()
SaveSize()
LayoutRows()
end)
grip:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, direction == "RIGHT" and "ANCHOR_LEFT" or "ANCHOR_TOP")
GameTooltip:SetText(direction == "RIGHT" and "Drag horizontally" or "Drag vertically")
GameTooltip:Show()
end)
grip:SetScript("OnLeave", function() GameTooltip:Hide() end)
return grip
end
local function CreateUI()
panel = CreateFrame("Frame", "EasyTrackerFrame", UIParent)
panel:SetSize(db.width or 410, db.height or 410)
panel:SetPoint(db.point, UIParent, db.relativePoint, db.x, db.y)
panel:SetFrameStrata("MEDIUM")
panel:SetClampedToScreen(true)
panel:SetMovable(true)
panel:SetResizable(true)
panel:SetMinResize(330, 300)
panel:SetMaxResize(700, 650)
panel:EnableMouse(true)
panel:SetBackdrop({
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tileSize = 32, edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 },
})
panel:SetBackdropColor(0.05, 0.035, 0.02, 0.96)
panel:SetBackdropBorderColor(0.72, 0.55, 0.27, 1)
panel:SetScript("OnDragStart", function(self) if not db.locked then self:StartMoving() end end)
panel:SetScript("OnDragStop", function(self) self:StopMovingOrSizing(); SavePosition() end)
panel:SetScript("OnSizeChanged", function()
SaveSize()
LayoutRows()
end)
local header = panel:CreateTexture(nil, "ARTWORK")
header:SetTexture("Interface\\QuestFrame\\UI-QuestLogTitleHighlight")
header:SetBlendMode("ADD")
header:SetVertexColor(0.82, 0.57, 0.2, 0.45)
header:SetPoint("TOPLEFT", 10, -8)
header:SetPoint("TOPRIGHT", -10, -8)
header:SetHeight(28)
local title = MakeText(panel, 15, {1, 0.82, 0.42})
title:SetPoint("TOPLEFT", 18, -15)
title:SetText("EASYTRACKER")
panel.collapse = CreateFrame("Button", nil, panel)
panel.collapse:SetSize(22, 22)
panel.collapse:SetPoint("TOPRIGHT", -10, -11)
panel.collapse:SetNormalFontObject(GameFontNormalLarge)
panel.collapse:SetHighlightFontObject(GameFontHighlightLarge)
panel.collapse:SetScript("OnClick", function()
db.collapsed = not db.collapsed
ApplyCollapsedState()
end)
local settingsButton = MakeButton(panel, "...", 28)
settingsButton:SetPoint("RIGHT", panel.collapse, "LEFT", -2, 0)
settingsButton:SetScript("OnClick", function()
UpdateSettingsControls()
settingsPanel:SetShown(not settingsPanel:IsShown())
end)
settingsButton:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_TOP")
GameTooltip:SetText("EasyTracker settings")
GameTooltip:Show()
end)
settingsButton:SetScript("OnLeave", function() GameTooltip:Hide() end)
xpBar = CreateFrame("StatusBar", nil, panel)
xpBar:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar")
xpBar:SetStatusBarColor(0.48, 0.12, 0.65, 1)
xpBar:SetPoint("TOPLEFT", 14, -40)
xpBar:SetPoint("TOPRIGHT", -14, -40)
xpBar:SetHeight(12)
xpBar:SetBackdrop({ bgFile = "Interface\\Buttons\\WHITE8X8", edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", edgeSize = 8 })
xpBar:SetBackdropColor(0.03, 0.02, 0.04, 1)
xpBar:SetBackdropBorderColor(0.35, 0.25, 0.42, 1)
content = CreateFrame("Frame", nil, panel)
content:SetAllPoints(panel)
xpText = MakeText(content, 11, {0.94, 0.88, 0.75})
xpText:SetPoint("TOPLEFT", 16, -66)
rateText = MakeText(content, 11, {0.68, 0.87, 1})
rateText:SetPoint("TOPLEFT", 16, -85)
etaText = MakeText(content, 11, {1, 0.82, 0.35})
etaText:SetPoint("TOPRIGHT", -16, -85)
sessionText = MakeText(content, 10, {0.67, 0.62, 0.53})
sessionText:SetPoint("TOPLEFT", 16, -103)
local farmBox = CreateFrame("Frame", nil, content)
farmBox:SetPoint("TOPLEFT", 12, -120)
farmBox:SetPoint("TOPRIGHT", -12, -120)
farmBox:SetHeight(42)
farmBox:SetBackdrop({ bgFile = "Interface\\Buttons\\WHITE8X8", edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", edgeSize = 8 })
farmBox:SetBackdropColor(0.12, 0.075, 0.025, 0.8)
farmBox:SetBackdropBorderColor(0.42, 0.31, 0.15, 0.8)
farmLine1 = MakeText(farmBox, 10, {0.94, 0.85, 0.67})
farmLine1:SetPoint("TOPLEFT", 8, -7)
farmLine1:SetPoint("RIGHT", -8, 0)
farmLine1:SetJustifyH("LEFT")
farmLine2 = MakeText(farmBox, 10, {0.72, 0.78, 0.65})
farmLine2:SetPoint("BOTTOMLEFT", 8, 7)
farmLine2:SetPoint("RIGHT", -8, 0)
farmLine2:SetJustifyH("LEFT")
local divider = content:CreateTexture(nil, "ARTWORK")
divider:SetTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight")
divider:SetBlendMode("ADD")
divider:SetVertexColor(0.75, 0.55, 0.25, 0.35)
divider:SetPoint("TOPLEFT", 12, -165)
divider:SetPoint("TOPRIGHT", -12, -165)
divider:SetHeight(20)
local lootTitle = MakeText(content, 12, {1, 0.82, 0.42})
lootTitle:SetPoint("TOPLEFT", 16, -168)
lootTitle:SetText("RECENT SPOILS")
lootTotalText = MakeText(content, 10, {0.88, 0.79, 0.61})
lootTotalText:SetPoint("TOPRIGHT", -16, -170)
for index = 1, MAX_LOOT_ROWS do
local row = CreateFrame("Button", nil, content)
row:SetHeight(20)
row:SetPoint("TOPLEFT", panel, "TOPLEFT", 14, -ROWS_TOP - ((index - 1) * ROW_HEIGHT))
row:SetPoint("TOPRIGHT", panel, "TOPRIGHT", -14, -ROWS_TOP - ((index - 1) * ROW_HEIGHT))
local highlight = row:CreateTexture(nil, "HIGHLIGHT")
highlight:SetAllPoints()
highlight:SetTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight")
highlight:SetBlendMode("ADD")
highlight:SetVertexColor(0.75, 0.55, 0.25, 0.28)
row.icon = row:CreateTexture(nil, "ARTWORK")
row.icon:SetSize(18, 18)
row.icon:SetPoint("LEFT", 1, 0)
row.price = MakeText(row, 10, {1, 1, 1})
row.price:SetPoint("RIGHT", -2, 0)
row.price:SetWidth(116)
row.price:SetJustifyH("RIGHT")
row.count = MakeText(row, 10, {0.78, 0.74, 0.66})
row.count:SetPoint("RIGHT", row.price, "LEFT", -4, 0)
row.count:SetWidth(34)
row.name = MakeText(row, 10, {1, 1, 1})
row.name:SetPoint("LEFT", row.icon, "RIGHT", 5, 0)
row.name:SetPoint("RIGHT", row.count, "LEFT", -4, 0)
row.name:SetJustifyH("LEFT")
row:SetScript("OnEnter", function(self)
if not self.entry then return end
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetHyperlink(self.entry.link)
GameTooltip:AddLine(" ")
GameTooltip:AddDoubleLine("Auctionator each", FormatMoney(self.entry.unitPrice, "No AH data"), 0.8, 0.75, 0.62, 1, 1, 1)
GameTooltip:AddDoubleLine("Session quantity", tostring(self.entry.count), 0.8, 0.75, 0.62, 1, 1, 1)
GameTooltip:Show()
end)
row:SetScript("OnLeave", function() GameTooltip:Hide() end)
lootRows[index] = row
end
scanAgeText = MakeText(content, 9, {0.56, 0.66, 0.48})
scanAgeText:SetPoint("BOTTOMLEFT", 16, 37)
local newButton = MakeButton(content, "New Session", 94)
newButton:SetPoint("BOTTOMLEFT", 14, 10)
newButton:SetScript("OnClick", function() StaticPopup_Show("EASYTRACKER_NEW_SESSION") end)
local resetButton = MakeButton(content, "Reset XP", 82)
resetButton:SetPoint("LEFT", newButton, "RIGHT", 5, 0)
resetButton:SetScript("OnClick", function()
ResetXPTracking()
DEFAULT_CHAT_FRAME:AddMessage("|cffd8b66cEasyTracker|r: XP pace reset.")
end)
local clearButton = MakeButton(content, "Clear Loot", 82)
clearButton:SetPoint("LEFT", resetButton, "RIGHT", 5, 0)
clearButton:SetScript("OnClick", function() StaticPopup_Show("EASYTRACKER_CLEAR_LOOT") end)
panel.rightResize = CreateResizeEdge("RIGHT")
panel.bottomResize = CreateResizeEdge("BOTTOM")
CreateSettingsPanel()
ApplyCollapsedState()
UpdateSettingsControls()
UpdateAll()
panel:Show()
end
local function PrintHelp()
DEFAULT_CHAT_FRAME:AddMessage("|cffd8b66cEasyTracker|r: /easytracker show, hide, new, reset, clear, lock, unlock, settings, levels")
end
SLASH_EASYTRACKER1 = "/easytracker"
SLASH_EASYTRACKER2 = "/et"
SLASH_EASYTRACKER3 = "/wledger"
SlashCmdList.EASYTRACKER = function(message)
local command = string.lower((message or ""):match("^%s*(.-)%s*$"))
if command == "show" then
panel:Show()
elseif command == "hide" then
panel:Hide()
elseif command == "new" then
StaticPopup_Show("EASYTRACKER_NEW_SESSION")
elseif command == "reset" then
ResetXPTracking()
elseif command == "clear" then
StaticPopup_Show("EASYTRACKER_CLEAR_LOOT")
elseif command == "lock" then
db.locked = true
ApplyLockState()
elseif command == "unlock" then
db.locked = false
ApplyLockState()
elseif command == "settings" then
UpdateSettingsControls()
settingsPanel:SetShown(not settingsPanel:IsShown())
else
PrintHelp()
end
end
addon:RegisterEvent("ADDON_LOADED")
addon:RegisterEvent("PLAYER_ENTERING_WORLD")
addon:RegisterEvent("PLAYER_XP_UPDATE")
addon:RegisterEvent("PLAYER_LEVEL_UP")
addon:RegisterEvent("UPDATE_EXHAUSTION")
addon:RegisterEvent("CHAT_MSG_LOOT")
addon:RegisterEvent("GET_ITEM_INFO_RECEIVED")
addon:RegisterEvent("AUCTION_HOUSE_CLOSED")
addon:RegisterEvent("PLAYER_MONEY")
addon:SetScript("OnEvent", function(_, event, arg1)
if event == "ADDON_LOADED" and arg1 == ADDON_NAME then
if type(EasyTrackerSelectCharacterProfile) == "function" then EasyTrackerSelectCharacterProfile() end
EasyTrackerDB = EasyTrackerDB or WayfarersLedgerDB or {}
CopyDefaults(EasyTrackerDB, defaults)
db = EasyTrackerDB
if not db.session.startedAt or db.session.startedAt <= 0 then db.session.startedAt = time() end
CreateUI()
lastXP = UnitXP("player") or 0
lastXPMax = UnitXPMax("player") or 0
lastLevel = UnitLevel("player") or 0
lastMoney = GetMoney() or 0
elseif event == "PLAYER_ENTERING_WORLD" then
if not db then return end
lastXP = UnitXP("player") or 0
lastXPMax = UnitXPMax("player") or 0
lastLevel = UnitLevel("player") or 0
lastMoney = GetMoney() or 0
UpdateAll()
elseif event == "PLAYER_XP_UPDATE" then
local current = UnitXP("player") or 0
local maximum = UnitXPMax("player") or 0
local level = UnitLevel("player") or 0
local gained = 0
if current >= lastXP and level == lastLevel then
gained = current - lastXP
elseif current < lastXP or level > lastLevel then
gained = max(0, lastXPMax - lastXP) + current
end
AddXPSample(gained)
lastXP, lastXPMax, lastLevel = current, maximum, level
UpdateXP()
elseif event == "PLAYER_LEVEL_UP" or event == "UPDATE_EXHAUSTION" then
UpdateXP()
elseif event == "CHAT_MSG_LOOT" then
AddLoot(arg1 or "")
elseif event == "GET_ITEM_INFO_RECEIVED" or event == "AUCTION_HOUSE_CLOSED" then
RefreshLoot()
elseif event == "PLAYER_MONEY" then
local money = GetMoney() or 0
local gained = money - lastMoney
if gained > 0 then db.session.cashGained = (db.session.cashGained or 0) + gained end
lastMoney = money
RefreshLoot()
end
end)
addon:SetScript("OnUpdate", function(_, elapsed)
elapsedSinceUpdate = elapsedSinceUpdate + elapsed
if elapsedSinceUpdate < UPDATE_INTERVAL then return end
elapsedSinceUpdate = 0
if db then UpdateAll() end
end)