-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatronOrderTracker.lua
More file actions
1358 lines (1192 loc) · 54.8 KB
/
PatronOrderTracker.lua
File metadata and controls
1358 lines (1192 loc) · 54.8 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
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local ADDON_NAME = "PatronOrderTracker"
local POT = {}
POT.shoppingListName = nil
POT.trackButton = nil
POT.clearButton = nil
POT.configButton = nil
POT.configFrame = nil
POT.initialized = false
POT.debug = false
POT.currentVersion = nil
POT.showWhatsNew = false
local WHATS_NEW = [[
Version 1.2.0
|cffffffffReward Filters|r
- Choose which patron order rewards to include in your shopping list: Knowledge Points, Artisan's Moxie, or Augment Runes. Open settings to configure.
|cffffffffFree Order Indicator|r
- Orders where the customer provides all reagents now show "|cff00ff00(free)|r" in the order list.
]]
-- ---------------------------------------------------------------------------
-- Event bootstrap
-- ---------------------------------------------------------------------------
local eventFrame = CreateFrame("Frame")
eventFrame:RegisterEvent("ADDON_LOADED")
eventFrame:SetScript("OnEvent", function(_, event, ...)
if event == "ADDON_LOADED" then
local addon = ...
if addon == ADDON_NAME then
eventFrame:UnregisterEvent("ADDON_LOADED")
if not PatronOrderTrackerDB then PatronOrderTrackerDB = {} end
-- Migrate knowledgeOnly → rewardFilter
if PatronOrderTrackerDB.knowledgeOnly ~= nil then
if PatronOrderTrackerDB.knowledgeOnly then
PatronOrderTrackerDB.rewardFilter = { knowledge = true, moxie = false, augmentRune = false }
end
PatronOrderTrackerDB.knowledgeOnly = nil
end
if not PatronOrderTrackerDB.rewardFilter then
PatronOrderTrackerDB.rewardFilter = { knowledge = true, moxie = true, augmentRune = true }
end
-- What's New version tracking
POT.currentVersion = C_AddOns.GetAddOnMetadata(ADDON_NAME, "Version")
if not PatronOrderTrackerDB.lastSeenVersion then
-- First install — don't show What's New
PatronOrderTrackerDB.lastSeenVersion = POT.currentVersion
elseif PatronOrderTrackerDB.lastSeenVersion ~= POT.currentVersion then
POT.showWhatsNew = true
end
eventFrame:RegisterEvent("TRADE_SKILL_DATA_SOURCE_CHANGED")
eventFrame:RegisterEvent("TRADE_SKILL_LIST_UPDATE")
end
elseif event == "TRADE_SKILL_DATA_SOURCE_CHANGED" then
if ProfessionsFrame and ProfessionsFrame.OrdersPage then
POT:InjectButtons()
end
elseif event == "TRADE_SKILL_LIST_UPDATE" then
POT:RefreshCostOverlays()
end
end)
-- ---------------------------------------------------------------------------
-- Chat helper
-- ---------------------------------------------------------------------------
local function PrintMsg(msg)
print("|cff00ccff[PatronOrderTracker]|r " .. msg)
end
local function DebugMsg(msg)
if POT.debug then
print("|cff888888[POT Debug]|r " .. msg)
end
end
local function BuildCustomerProvidedMap(order)
local map = {}
if order.reagents then
for _, r in ipairs(order.reagents) do
local qty = r.reagentInfo and r.reagentInfo.quantity or 0
map[r.slotIndex] = (map[r.slotIndex] or 0) + qty
end
end
return map
end
local function GetItemIDFromLink(itemLink)
if not itemLink then return nil end
return tonumber(itemLink:match("item:(%d+)"))
end
local function GetRewardName(reward)
if not reward.itemLink then return nil end
local name = reward.itemLink:match("|h%[(.-)%]|h")
if not name or name == "" then
local id = GetItemIDFromLink(reward.itemLink)
if id then name = C_Item.GetItemNameByID(id) end
end
return name
end
-- ---------------------------------------------------------------------------
-- Reward data tables
-- ---------------------------------------------------------------------------
local PROF_GLIMMER_ITEMS = {
Alchemy = 246321, Blacksmithing = 246323, Enchanting = 246325,
Engineering = 246327, Inscription = 246329, Jewelcrafting = 246331,
Leatherworking = 246333, Tailoring = 246335,
}
local PROF_FLICKER_ITEMS = {
Alchemy = 246320, Blacksmithing = 246322, Enchanting = 246324,
Engineering = 246326, Inscription = 246328, Jewelcrafting = 246330,
Leatherworking = 246332, Tailoring = 246334,
}
local PROF_MOXIE_CURRENCIES = {
Alchemy = 3256, Blacksmithing = 3257, Enchanting = 3258,
Engineering = 3259, Inscription = 3261, Jewelcrafting = 3262,
Leatherworking = 3263, Tailoring = 3266,
}
local MOXIE_CURRENCY_SET = {}
for _, id in pairs(PROF_MOXIE_CURRENCIES) do MOXIE_CURRENCY_SET[id] = true end
local AUGMENT_RUNE_ITEM_ID = 259085
-- ---------------------------------------------------------------------------
-- Reward detection helpers
-- ---------------------------------------------------------------------------
local function OrderHasRewardType(order, rewardType)
if not order.npcOrderRewards then return false end
for _, reward in ipairs(order.npcOrderRewards) do
if rewardType == "knowledge" then
local name = GetRewardName(reward)
if name and name:find("Knowledge") then return true end
elseif rewardType == "moxie" then
if reward.currencyType and MOXIE_CURRENCY_SET[reward.currencyType] then return true end
elseif rewardType == "augmentRune" then
local name = GetRewardName(reward)
if name and name:find("Augment Rune") then return true end
end
end
return false
end
local function OrderMatchesRewardFilter(order)
local rf = PatronOrderTrackerDB.rewardFilter
if not rf then return true end
if rf.knowledge and OrderHasRewardType(order, "knowledge") then return true end
if rf.moxie and OrderHasRewardType(order, "moxie") then return true end
if rf.augmentRune and OrderHasRewardType(order, "augmentRune") then return true end
return false
end
local function OrderNeedsShopping(order)
local schematic = C_TradeSkillUI.GetRecipeSchematic(order.spellID, order.isRecraft)
if not schematic or not schematic.reagentSlotSchematics then return true end
local customerProvided = BuildCustomerProvidedMap(order)
for _, slot in ipairs(schematic.reagentSlotSchematics) do
if slot.reagentType == Enum.CraftingReagentType.Basic
and slot.required and slot.quantityRequired > 0 then
local playerNeeds = slot.quantityRequired - (customerProvided[slot.slotIndex] or 0)
if playerNeeds > 0 then return true end
end
end
return false
end
local function RewardFilterNeedsCheck()
local rf = PatronOrderTrackerDB.rewardFilter
if not rf then return false end
return rf.knowledge or rf.moxie or rf.augmentRune or false
end
local PROF_ABBR = {
["Alchemy"] = "Alch.", ["Blacksmithing"] = "BS", ["Enchanting"] = "Ench.",
["Engineering"] = "Eng.", ["Inscription"] = "Insc.", ["Jewelcrafting"] = "JC",
["Leatherworking"] = "LW", ["Tailoring"] = "Tail.",
}
-- ---------------------------------------------------------------------------
-- Copyable dump dialog (SimC-style)
-- ---------------------------------------------------------------------------
local REAGENT_TYPE_NAMES = {
[Enum.CraftingReagentType.Basic] = "Basic",
[Enum.CraftingReagentType.Modifying] = "Modifying",
[Enum.CraftingReagentType.Finishing] = "Finishing",
[Enum.CraftingReagentType.Automatic] = "Automatic",
}
local REAGENT_STATE_NAMES = { [0] = "All", [1] = "Some", [2] = "None" }
local function QualityStars(minQuality)
if not minQuality or minQuality <= 0 then return "Any" end
local stars = {}
for i = 1, minQuality do stars[i] = "\226\152\133" end -- ★
return table.concat(stars)
end
function POT:ShowDumpDialog(text)
if not POT.dumpFrame then
local f = CreateFrame("Frame", "PatronOrderTrackerDumpFrame", UIParent, "BackdropTemplate")
f:SetSize(620, 450)
f:SetPoint("CENTER")
f:SetBackdrop({
bgFile = "Interface/DialogFrame/UI-DialogBox-Background",
edgeFile = "Interface/DialogFrame/UI-DialogBox-Border",
tile = true, tileSize = 32, edgeSize = 32,
insets = { left = 11, right = 12, top = 12, bottom = 11 },
})
f:SetFrameStrata("DIALOG")
f:SetMovable(true)
f:EnableMouse(true)
f:EnableKeyboard(true)
f:RegisterForDrag("LeftButton")
f:SetScript("OnDragStart", f.StartMoving)
f:SetScript("OnDragStop", f.StopMovingOrSizing)
f:SetScript("OnKeyDown", function(self, key)
if key == "ESCAPE" then
self:SetPropagateKeyboardInput(false)
self:Hide()
else
self:SetPropagateKeyboardInput(true)
end
end)
local title = f:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
title:SetPoint("TOP", 0, -16)
title:SetText("Patron Order Tracker - Diagnostic Dump")
local close = CreateFrame("Button", nil, f, "UIPanelCloseButton")
close:SetPoint("TOPRIGHT", -4, -4)
local sf = CreateFrame("ScrollFrame", nil, f, "UIPanelScrollFrameTemplate")
sf:SetPoint("TOPLEFT", 16, -40)
sf:SetPoint("BOTTOMRIGHT", -34, 16)
local eb = CreateFrame("EditBox", nil, sf)
eb:SetMultiLine(true)
eb:SetAutoFocus(false)
eb:SetFontObject(GameFontHighlightSmall)
eb:SetWidth(560)
eb:SetScript("OnEscapePressed", function() f:Hide() end)
sf:SetScrollChild(eb)
f.editBox = eb
POT.dumpFrame = f
end
POT.dumpFrame.editBox:SetText(text)
POT.dumpFrame:Show()
POT.dumpFrame.editBox:HighlightText()
POT.dumpFrame.editBox:SetFocus()
end
function POT:BuildDumpString()
local lines = {}
local function add(s) lines[#lines + 1] = s end
add("== Patron Order Tracker Dump ==")
add("")
local profInfo = C_TradeSkillUI.GetChildProfessionInfo()
local profName = profInfo and (profInfo.parentProfessionName or profInfo.professionName) or "Unknown"
add("Profession: " .. profName)
local ordersPage = ProfessionsFrame and ProfessionsFrame.OrdersPage
local tabType = ordersPage and ordersPage.orderType
local tabName = "Unknown"
if tabType == Enum.CraftingOrderType.Npc then tabName = "Npc (Patron Orders)"
elseif tabType == Enum.CraftingOrderType.Public then tabName = "Public"
elseif tabType == Enum.CraftingOrderType.Guild then tabName = "Guild"
elseif tabType == Enum.CraftingOrderType.Personal then tabName = "Personal"
end
add("Active Tab: " .. tabName)
local flatOrders = C_CraftingOrders.GetCrafterOrders() or {}
local buckets = C_CraftingOrders.GetCrafterBuckets() or {}
add(string.format("Data: %d flat orders, %d buckets", #flatOrders, #buckets))
add("")
local npcOrders = {}
for _, order in ipairs(flatOrders) do
if order.orderType == Enum.CraftingOrderType.Npc then
npcOrders[#npcOrders + 1] = order
end
end
if #npcOrders == 0 and #buckets == 0 then
add("No patron order data loaded. Browse the Patron Orders tab first.")
return table.concat(lines, "\n")
end
local orderList = #npcOrders > 0 and npcOrders or nil
if orderList then
add(string.format("=== %d Patron Orders (Flat) ===", #orderList))
add("")
for i, order in ipairs(orderList) do
local itemName = C_Item.GetItemNameByID(order.itemID) or ("itemID:" .. tostring(order.itemID))
local recipeInfo = C_TradeSkillUI.GetRecipeInfo(order.spellID)
local learned = recipeInfo and recipeInfo.learned
add(string.format("--- Order %d ---", i))
add("Item: " .. itemName)
add(string.format("Recipe: spellID %d | Learned: %s", order.spellID, learned and "Yes" or "No"))
add("Quality Requested: " .. QualityStars(order.minQuality))
add("Reagent State: " .. (REAGENT_STATE_NAMES[order.reagentState] or tostring(order.reagentState)))
add("isRecraft: " .. tostring(order.isRecraft))
if order.npcOrderRewards and #order.npcOrderRewards > 0 then
add("Rewards:")
for _, reward in ipairs(order.npcOrderRewards) do
if reward.itemLink then
local name = GetRewardName(reward)
if not name or name == "" then
local id = GetItemIDFromLink(reward.itemLink)
name = id and ("itemID:" .. id) or reward.itemLink
end
add(string.format(" %s x%d", name, reward.count or 1))
elseif reward.currencyType then
add(string.format(" CurrencyType %d x%d", reward.currencyType, reward.count or 1))
end
end
else
add("Rewards: (none)")
end
local schematic = C_TradeSkillUI.GetRecipeSchematic(order.spellID, order.isRecraft)
if schematic and schematic.reagentSlotSchematics then
local customerProvided = BuildCustomerProvidedMap(order)
add("Reagents:")
for _, slot in ipairs(schematic.reagentSlotSchematics) do
local typeName = REAGENT_TYPE_NAMES[slot.reagentType] or "?"
local reagentItemID = slot.reagents and slot.reagents[1] and slot.reagents[1].itemID
local reagentName = reagentItemID and C_Item.GetItemNameByID(reagentItemID) or ("itemID:" .. tostring(reagentItemID or "?"))
local needed = slot.quantityRequired or 0
local custQty = customerProvided[slot.slotIndex] or 0
local delta = needed - custQty
if slot.reagentType == Enum.CraftingReagentType.Basic then
if delta > 0 then
add(string.format(" [%s] %s: need %d, customer %d -> PLAYER SUPPLIES %d",
typeName, reagentName, needed, custQty, delta))
else
add(string.format(" [%s] %s: need %d, customer %d -> covered",
typeName, reagentName, needed, custQty))
end
else
add(string.format(" [%s] %s: need %d (optional, not included)",
typeName, reagentName, needed))
end
end
else
add("Reagents: (schematic unavailable)")
end
add("")
end
else
add(string.format("=== %d Recipe Buckets ===", #buckets))
add("(Per-order reagent detail unavailable in bucketed mode)")
add("")
for i, bucket in ipairs(buckets) do
local itemName = C_Item.GetItemNameByID(bucket.itemID) or ("itemID:" .. tostring(bucket.itemID))
local recipeInfo = C_TradeSkillUI.GetRecipeInfo(bucket.spellID)
local learned = recipeInfo and recipeInfo.learned
add(string.format("--- Bucket %d ---", i))
add("Item: " .. itemName)
add(string.format("Recipe: spellID %d | Learned: %s | Available: %d",
bucket.spellID, learned and "Yes" or "No", bucket.numAvailable or 0))
add("")
end
end
if POT.shoppingListName then
add("Shopping list: " .. POT.shoppingListName)
end
add("")
add("=== Visible Row UI State ===")
local browseFrame = ProfessionsFrame and ProfessionsFrame.OrdersPage
and ProfessionsFrame.OrdersPage.BrowseFrame
if browseFrame and browseFrame.OrderList and browseFrame.OrderList.ScrollBox then
local rowIdx = 0
browseFrame.OrderList.ScrollBox:ForEachFrame(function(row)
rowIdx = rowIdx + 1
-- Read what's actually rendered in the name cell
local nameCell = nil
local nameCellText = "(no name cell)"
for i = 1, row:GetNumChildren() do
local child = select(i, row:GetChildren())
if child.Icon then
nameCell = child
-- Find the text widget inside the name cell
for j = 1, child:GetNumRegions() do
local region = select(j, child:GetRegions())
if region.GetText and region:GetText() then
nameCellText = region:GetText()
break
end
end
break
end
end
-- Read elementData
local ed = row:GetElementData()
local order = ed and ed.option
local edItemName = order and C_Item.GetItemNameByID(order.itemID) or "(no elementData)"
add(string.format("Row %d:", rowIdx))
add(string.format(" Name cell renders: %s", nameCellText))
add(string.format(" elementData says: %s", edItemName))
if order then
add(string.format(" order.spellID: %s", tostring(order.spellID)))
local ri = C_TradeSkillUI.GetRecipeInfo(order.spellID)
add(string.format(" GetRecipeInfo now: learned=%s", ri and tostring(ri.learned) or "nil"))
end
add(string.format(" overlay text: %s", row.potCostText and row.potCostText:GetText() or "(none)"))
add(string.format(" overlay shown: %s", row.potCostText and tostring(row.potCostText:IsShown()) or "N/A"))
add("")
end)
else
add("ScrollBox not available")
end
return table.concat(lines, "\n")
end
-- ---------------------------------------------------------------------------
-- Settings popup
-- ---------------------------------------------------------------------------
function POT:SaveCeilingSetting(text)
local gold = tonumber(text)
local prev = PatronOrderTrackerDB.priceCeiling
if not gold or gold <= 0 then
PatronOrderTrackerDB.priceCeiling = nil
if prev then PrintMsg("Order budget removed.") end
else
local newCeiling = math.floor(gold * 10000)
PatronOrderTrackerDB.priceCeiling = newCeiling
if newCeiling ~= prev then
PrintMsg(string.format("Order budget set to %s.",
GetCoinTextureString(newCeiling)))
end
end
POT:RefreshCostOverlays()
end
function POT:CreateConfigPopup()
if POT.configFrame then return end
local f = CreateFrame("Frame", "PatronOrderTrackerConfigFrame", UIParent, "BasicFrameTemplateWithInset")
f:SetSize(360, 305)
f:SetPoint("CENTER")
f:SetFrameStrata("DIALOG")
f:SetMovable(true)
f:EnableMouse(true)
f:EnableKeyboard(true)
f:RegisterForDrag("LeftButton")
f:SetScript("OnDragStart", f.StartMoving)
f:SetScript("OnDragStop", f.StopMovingOrSizing)
f:SetScript("OnKeyDown", function(self, key)
if key == "ESCAPE" then
self:SetPropagateKeyboardInput(false)
self:Hide()
else
self:SetPropagateKeyboardInput(true)
end
end)
f.TitleText:SetText("Patron Order Tracker Settings")
local label = f:CreateFontString(nil, "OVERLAY", "GameFontNormal")
label:SetPoint("TOPLEFT", f.InsetBg, "TOPLEFT", 10, -10)
label:SetText("Order budget:")
local input = CreateFrame("EditBox", nil, f, "InputBoxTemplate")
input:SetSize(100, 20)
input:SetPoint("LEFT", label, "RIGHT", 10, 0)
input:SetAutoFocus(false)
input:SetMaxLetters(10)
input:SetNumeric(true)
input:SetJustifyH("RIGHT")
input:SetTextInsets(5, 8, 0, 0)
local goldLabel = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
goldLabel:SetPoint("LEFT", input, "RIGHT", 6, 0)
goldLabel:SetText("|TInterface\\MoneyFrame\\UI-GoldIcon:0|t")
local resetButton = CreateFrame("Button", nil, f, "UIPanelButtonTemplate")
resetButton:SetSize(60, 20)
resetButton:SetPoint("LEFT", goldLabel, "RIGHT", 8, 0)
resetButton:SetText("Clear")
resetButton:SetScript("OnClick", function()
input:SetText("")
input:ClearFocus()
POT:SaveCeilingSetting("")
end)
local help = f:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
help:SetPoint("TOPLEFT", label, "BOTTOMLEFT", 0, -12)
help:SetPoint("RIGHT", f.InsetBg, "RIGHT", -10, 0)
help:SetJustifyH("LEFT")
help:SetText("|cff888888Orders that cost more than this will be excluded.\nRequires a recent AH scan for accurate prices.|r")
local showCostsCheck = CreateFrame("CheckButton", nil, f, "UICheckButtonTemplate")
showCostsCheck:SetPoint("TOPLEFT", help, "BOTTOMLEFT", -2, -6)
showCostsCheck.text = showCostsCheck:CreateFontString(nil, "OVERLAY", "GameFontNormal")
showCostsCheck.text:SetPoint("LEFT", showCostsCheck, "RIGHT", 2, 0)
showCostsCheck.text:SetText("Show material costs in order list")
showCostsCheck:SetScript("OnClick", function(self)
PatronOrderTrackerDB.showCostOverlay = self:GetChecked()
POT:RefreshCostOverlays()
end)
-- Reward filter section
local function CreateRewardIcon(parent, anchor, offsetX)
local btn = CreateFrame("Button", nil, parent)
btn:SetSize(16, 16)
btn:SetPoint("LEFT", anchor, "RIGHT", offsetX, 0)
btn.tex = btn:CreateTexture(nil, "ARTWORK")
btn.tex:SetAllPoints()
btn:SetScript("OnEnter", function(self)
if self.tooltipItemID then
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetItemByID(self.tooltipItemID)
GameTooltip:Show()
elseif self.tooltipCurrencyID then
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetCurrencyByID(self.tooltipCurrencyID)
GameTooltip:Show()
end
end)
btn:SetScript("OnLeave", GameTooltip_Hide)
return btn
end
-- Parent reward checkbox (tri-state)
local rewardParentCheck = CreateFrame("CheckButton", nil, f, "UICheckButtonTemplate")
rewardParentCheck:SetPoint("TOPLEFT", showCostsCheck, "BOTTOMLEFT", 0, -2)
rewardParentCheck.text = rewardParentCheck:CreateFontString(nil, "OVERLAY", "GameFontNormal")
rewardParentCheck.text:SetPoint("LEFT", rewardParentCheck, "RIGHT", 2, 0)
rewardParentCheck.text:SetText("Only include orders with these rewards:")
-- Knowledge row (indented)
local knowledgeCheck = CreateFrame("CheckButton", nil, f, "UICheckButtonTemplate")
knowledgeCheck:SetPoint("TOPLEFT", rewardParentCheck, "BOTTOMLEFT", 26, -2)
local glimmerIcon = CreateRewardIcon(f, knowledgeCheck, 2)
local flickerIcon = CreateRewardIcon(f, glimmerIcon, 2)
knowledgeCheck.text = knowledgeCheck:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
knowledgeCheck.text:SetPoint("LEFT", flickerIcon, "RIGHT", 4, 0)
knowledgeCheck.text:SetText("Knowledge points")
-- Moxie row (indented)
local moxieCheck = CreateFrame("CheckButton", nil, f, "UICheckButtonTemplate")
moxieCheck:SetPoint("TOPLEFT", knowledgeCheck, "BOTTOMLEFT", 0, -2)
local moxieIcon = CreateRewardIcon(f, moxieCheck, 2)
moxieCheck.text = moxieCheck:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
moxieCheck.text:SetPoint("LEFT", moxieIcon, "RIGHT", 4, 0)
moxieCheck.text:SetText("Artisan's Moxie")
-- Augment Rune row (indented)
local runeCheck = CreateFrame("CheckButton", nil, f, "UICheckButtonTemplate")
runeCheck:SetPoint("TOPLEFT", moxieCheck, "BOTTOMLEFT", 0, -2)
local runeIcon = CreateRewardIcon(f, runeCheck, 2)
runeCheck.text = runeCheck:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
runeCheck.text:SetPoint("LEFT", runeIcon, "RIGHT", 4, 0)
runeCheck.text:SetText("Augment Runes")
-- Update parent checkbox tri-state to reflect children
local function UpdateRewardFilterUI()
local rf = PatronOrderTrackerDB.rewardFilter
local anyOn = rf.knowledge or rf.moxie or rf.augmentRune
local allOn = rf.knowledge and rf.moxie and rf.augmentRune
if anyOn then
rewardParentCheck:SetChecked(true)
rewardParentCheck:GetCheckedTexture():SetDesaturated(not allOn)
else
rewardParentCheck:SetChecked(false)
end
end
rewardParentCheck:SetScript("OnClick", function(self)
local rf = PatronOrderTrackerDB.rewardFilter
if self:GetChecked() then
-- Turning on: check all children
rf.knowledge = true
rf.moxie = true
rf.augmentRune = true
knowledgeCheck:SetChecked(true)
moxieCheck:SetChecked(true)
runeCheck:SetChecked(true)
else
-- Turning off: uncheck all children
rf.knowledge = false
rf.moxie = false
rf.augmentRune = false
knowledgeCheck:SetChecked(false)
moxieCheck:SetChecked(false)
runeCheck:SetChecked(false)
end
UpdateRewardFilterUI()
POT:RefreshCostOverlays()
end)
knowledgeCheck:SetScript("OnClick", function(self)
PatronOrderTrackerDB.rewardFilter.knowledge = self:GetChecked()
UpdateRewardFilterUI()
POT:RefreshCostOverlays()
end)
moxieCheck:SetScript("OnClick", function(self)
PatronOrderTrackerDB.rewardFilter.moxie = self:GetChecked()
UpdateRewardFilterUI()
POT:RefreshCostOverlays()
end)
runeCheck:SetScript("OnClick", function(self)
PatronOrderTrackerDB.rewardFilter.augmentRune = self:GetChecked()
UpdateRewardFilterUI()
POT:RefreshCostOverlays()
end)
local doneButton = CreateFrame("Button", nil, f, "UIPanelButtonTemplate")
doneButton:SetSize(100, 22)
doneButton:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -16, 16)
doneButton:SetText("Done")
doneButton:SetScript("OnClick", function()
POT:SaveCeilingSetting(input:GetText())
input:ClearFocus()
f:Hide()
end)
input:SetScript("OnEnterPressed", function(self)
POT:SaveCeilingSetting(self:GetText())
self:ClearFocus()
f:Hide()
end)
input:SetScript("OnEscapePressed", function(self)
self:ClearFocus()
f:Hide()
end)
f:SetScript("OnShow", function()
local ceiling = PatronOrderTrackerDB and PatronOrderTrackerDB.priceCeiling
if ceiling and ceiling > 0 then
input:SetText(tostring(math.floor(ceiling / 10000)))
else
input:SetText("")
end
showCostsCheck:SetChecked(PatronOrderTrackerDB.showCostOverlay ~= false)
local rf = PatronOrderTrackerDB.rewardFilter
knowledgeCheck:SetChecked(rf and rf.knowledge ~= false)
moxieCheck:SetChecked(rf and rf.moxie ~= false)
runeCheck:SetChecked(rf and rf.augmentRune ~= false)
UpdateRewardFilterUI()
-- Dynamic icons based on current profession
local profInfo = C_TradeSkillUI.GetChildProfessionInfo()
local profName = profInfo and (profInfo.parentProfessionName or profInfo.professionName)
local glimmerID = profName and PROF_GLIMMER_ITEMS[profName]
local flickerID = profName and PROF_FLICKER_ITEMS[profName]
local moxieID = profName and PROF_MOXIE_CURRENCIES[profName]
if glimmerID then
glimmerIcon.tex:SetTexture(C_Item.GetItemIconByID(glimmerID))
glimmerIcon.tooltipItemID = glimmerID
else
glimmerIcon.tex:SetTexture("Interface\\Icons\\INV_Misc_QuestionMark")
glimmerIcon.tooltipItemID = nil
end
if flickerID then
flickerIcon.tex:SetTexture(C_Item.GetItemIconByID(flickerID))
flickerIcon.tooltipItemID = flickerID
else
flickerIcon.tex:SetTexture("Interface\\Icons\\INV_Misc_QuestionMark")
flickerIcon.tooltipItemID = nil
end
if moxieID then
local info = C_CurrencyInfo.GetCurrencyInfo(moxieID)
moxieIcon.tex:SetTexture(info and info.iconFileID or "Interface\\Icons\\INV_Misc_QuestionMark")
moxieIcon.tooltipCurrencyID = moxieID
else
moxieIcon.tex:SetTexture("Interface\\Icons\\INV_Misc_QuestionMark")
moxieIcon.tooltipCurrencyID = nil
end
runeIcon.tex:SetTexture(C_Item.GetItemIconByID(AUGMENT_RUNE_ITEM_ID))
runeIcon.tooltipItemID = AUGMENT_RUNE_ITEM_ID
end)
f.input = input
POT.configFrame = f
f:Hide()
end
function POT:ToggleConfigPopup()
POT:CreateConfigPopup()
if POT.configFrame:IsShown() then
POT.configFrame:Hide()
else
POT.configFrame:Show()
end
end
-- ---------------------------------------------------------------------------
-- What's New popup
-- ---------------------------------------------------------------------------
function POT:ShowWhatsNew()
if POT.whatsNewFrame then
POT.whatsNewFrame:Show()
return
end
local f = CreateFrame("Frame", "PatronOrderTrackerWhatsNewFrame", UIParent, "BasicFrameTemplateWithInset")
f:SetSize(380, 300)
f:SetPoint("CENTER")
f:SetFrameStrata("DIALOG")
f:SetMovable(true)
f:EnableMouse(true)
f:EnableKeyboard(true)
f:RegisterForDrag("LeftButton")
f:SetScript("OnDragStart", f.StartMoving)
f:SetScript("OnDragStop", f.StopMovingOrSizing)
f:SetScript("OnKeyDown", function(self, key)
if key == "ESCAPE" then
self:SetPropagateKeyboardInput(false)
self:Hide()
else
self:SetPropagateKeyboardInput(true)
end
end)
f.TitleText:SetText("Patron Order Tracker — What's New")
local sf = CreateFrame("ScrollFrame", nil, f, "UIPanelScrollFrameTemplate")
sf:SetPoint("TOPLEFT", f.InsetBg, "TOPLEFT", 6, -6)
sf:SetPoint("BOTTOMRIGHT", f.InsetBg, "BOTTOMRIGHT", -24, 30)
local text = CreateFrame("Frame", nil, sf)
text:SetSize(1, 1)
sf:SetScrollChild(text)
local body = text:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
body:SetPoint("TOPLEFT")
body:SetWidth(sf:GetWidth() - 8)
body:SetJustifyH("LEFT")
body:SetJustifyV("TOP")
body:SetText(WHATS_NEW)
body:SetSpacing(2)
text:SetSize(body:GetStringWidth(), body:GetStringHeight() + 20)
local dismissButton = CreateFrame("Button", nil, f, "UIPanelButtonTemplate")
dismissButton:SetSize(80, 22)
dismissButton:SetPoint("BOTTOM", f, "BOTTOM", 0, 16)
dismissButton:SetText("Got it")
local function Dismiss()
PatronOrderTrackerDB.lastSeenVersion = POT.currentVersion
f:Hide()
end
dismissButton:SetScript("OnClick", Dismiss)
f.CloseButton:HookScript("OnClick", Dismiss)
POT.whatsNewFrame = f
end
-- ---------------------------------------------------------------------------
-- Slash commands
-- ---------------------------------------------------------------------------
SLASH_PATRONORDERTRACKER1 = "/pot"
SlashCmdList["PATRONORDERTRACKER"] = function(input)
local cmd = strtrim(input):lower()
if cmd == "debug" then
POT.debug = not POT.debug
PrintMsg("Debug mode " .. (POT.debug and "ON" or "OFF"))
elseif cmd == "dump" then
POT:ShowDumpDialog(POT:BuildDumpString())
else
PrintMsg("Commands: /pot debug | /pot dump")
end
end
-- ---------------------------------------------------------------------------
-- UI injection
-- ---------------------------------------------------------------------------
function POT:InjectButtons()
if not Auctionator or not Auctionator.API or not Auctionator.API.v1 then return end
if POT.initialized then
POT:UpdateButtonState()
return
end
local browseFrame = ProfessionsFrame.OrdersPage.BrowseFrame
if not browseFrame then return end
POT.trackButton = CreateFrame("Button", nil, browseFrame, "UIPanelButtonTemplate")
POT.trackButton:SetSize(220, 22)
POT.trackButton:SetText("Create Auctionator Shopping List")
POT.trackButton:SetPoint("TOPRIGHT", browseFrame, "TOPRIGHT", -35, -32)
POT.trackButton:SetScript("OnClick", function() POT:ScanAndCreateList() end)
POT.trackButton:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_TOP")
GameTooltip:AddLine("Create an Auctionator shopping list with only the reagents you need to supply.", 1, 1, 1)
GameTooltip:Show()
end)
POT.trackButton:SetScript("OnLeave", GameTooltip_Hide)
POT.configButton = CreateFrame("Button", nil, browseFrame, "UIPanelButtonTemplate")
POT.configButton:SetSize(26, 22)
POT.configButton:SetPoint("TOPRIGHT", browseFrame, "TOPRIGHT", -8, -32)
POT.configButton:SetText("")
local configIcon = POT.configButton:CreateTexture(nil, "ARTWORK")
configIcon:SetSize(14, 14)
configIcon:SetPoint("CENTER")
configIcon:SetTexture("Interface\\Buttons\\UI-OptionsButton")
POT.configButton:SetScript("OnClick", function() POT:ToggleConfigPopup() end)
POT.configButton:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_TOP")
GameTooltip:AddLine("Patron Order Tracker Settings", 1, 1, 1)
GameTooltip:Show()
end)
POT.configButton:SetScript("OnLeave", GameTooltip_Hide)
POT.clearButton = CreateFrame("Button", nil, browseFrame, "UIPanelButtonTemplate")
POT.clearButton:SetSize(210, 22)
POT.clearButton:SetText("Clear Auctionator Shopping List")
POT.clearButton:SetPoint("RIGHT", POT.trackButton, "LEFT", -5, 0)
POT.clearButton:SetScript("OnClick", function() POT:ClearShoppingList() end)
hooksecurefunc(ProfessionsFrame.OrdersPage, "SetCraftingOrderType", function()
POT:UpdateButtonState()
POT:RefreshCostOverlays()
end)
browseFrame:HookScript("OnHide", function()
if POT.trackButton then POT.trackButton:Hide() end
if POT.configButton then POT.configButton:Hide() end
if POT.clearButton then POT.clearButton:Hide() end
if POT.configFrame then POT.configFrame:Hide() end
end)
browseFrame:HookScript("OnShow", function()
POT:UpdateButtonState()
end)
POT:HookOrderRows(browseFrame)
pcall(function()
Auctionator.API.v1.RegisterForDBUpdate(ADDON_NAME, function()
POT:RefreshCostOverlays()
end)
end)
POT.initialized = true
POT:UpdateButtonState()
if POT.showWhatsNew then
POT.showWhatsNew = false
POT:ShowWhatsNew()
end
end
-- ---------------------------------------------------------------------------
-- Order row cost overlay
-- ---------------------------------------------------------------------------
local function FindNameCell(row)
for i = 1, row:GetNumChildren() do
local child = select(i, row:GetChildren())
if child.Icon then return child end
end
end
local function UpdateRowCostOverlay(row, elementData)
local nameCell = FindNameCell(row)
if not nameCell then return end
if not row.potCostText then
row.potCostText = row:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
end
row.potCostText:ClearAllPoints()
row.potCostText:SetPoint("RIGHT", nameCell, "RIGHT", -4, 0)
row.potCostText:Hide()
if PatronOrderTrackerDB.showCostOverlay == false then return end
local order = elementData and elementData.option
if not order or order.orderType ~= Enum.CraftingOrderType.Npc then return end
local recipeInfo = C_TradeSkillUI.GetRecipeInfo(order.spellID)
if not recipeInfo then return end
if not recipeInfo.learned then
row.potCostText:SetText("|cff888888(unlearned)|r")
row.potCostText:Show()
return
end
local isFree = not OrderNeedsShopping(order)
if isFree then
row.potCostText:SetText("|cff00ff00(free)|r")
row.potCostText:Show()
return
end
if RewardFilterNeedsCheck() and not OrderMatchesRewardFilter(order) then
row.potCostText:SetText("|cff888888(excluded)|r")
row.potCostText:Show()
return
end
local customerProvided = BuildCustomerProvidedMap(order)
local cost, hasMissing = POT:CalculateOrderCost(order.spellID, order.isRecraft, customerProvided)
if not cost and hasMissing then
row.potCostText:SetText("|cff888888No price data|r")
row.potCostText:Show()
return
end
local ceiling = PatronOrderTrackerDB.priceCeiling
local costStr = GetCoinTextureString(cost)
if ceiling then
if cost > ceiling then
row.potCostText:SetText("|cffff4444" .. costStr .. "|r")
else
row.potCostText:SetText("|cff00ff00" .. costStr .. "|r")
end
else
row.potCostText:SetText(costStr)
end
row.potCostText:Show()
end
function POT:RefreshCostOverlays()
local browseFrame = ProfessionsFrame and ProfessionsFrame.OrdersPage
and ProfessionsFrame.OrdersPage.BrowseFrame
if not browseFrame or not browseFrame.OrderList or not browseFrame.OrderList.ScrollBox then return end
browseFrame.OrderList.ScrollBox:ForEachFrame(function(row)
local elementData = row.GetElementData and row:GetElementData()
if elementData then
UpdateRowCostOverlay(row, elementData)
end
end)
end
function POT:HookOrderRows(browseFrame)
local orderList = browseFrame.OrderList
if not orderList or not orderList.ScrollBox then return end
local scrollBox = orderList.ScrollBox
-- OnAcquiredFrame: fires when ScrollBox takes a frame from pool (before Init).
-- Hides stale overlay, then defers update to next frame so Init has run first.
-- Uses GetElementData() for current data instead of capturing stale closure data.
if scrollBox.RegisterCallback and ScrollBoxListMixin and ScrollBoxListMixin.Event then
pcall(function()
scrollBox:RegisterCallback(ScrollBoxListMixin.Event.OnAcquiredFrame, function(_, row)
if row.potCostText then row.potCostText:Hide() end
C_Timer.After(0, function()
local currentData = row.GetElementData and row:GetElementData()
if currentData then
UpdateRowCostOverlay(row, currentData)
end
end)
end, POT)
end)
DebugMsg("Hooked order rows via ScrollBox callback")
end
-- Init hook: fires after Blizzard populates row children, so FindNameCell succeeds.
-- Primary path on second+ loads; may not exist on first load (mixin lazy-loaded).
if ProfessionsCrafterOrderListElementMixin and ProfessionsCrafterOrderListElementMixin.Init then
hooksecurefunc(ProfessionsCrafterOrderListElementMixin, "Init", function(self, elementData)
UpdateRowCostOverlay(self, elementData)
end)
DebugMsg("Hooked order rows via mixin Init")
end
end
function POT:UpdateButtonState()
local ordersPage = ProfessionsFrame and ProfessionsFrame.OrdersPage
if not ordersPage then return end
local isNpcTab = (ordersPage.orderType == Enum.CraftingOrderType.Npc)
local browseVisible = ordersPage.BrowseFrame and ordersPage.BrowseFrame:IsShown()
if POT.trackButton then