Repository navigation
Expand file tree
/
Copy pathNotify.lua
More file actions
944 lines (857 loc) · 29.1 KB
/
Copy pathNotify.lua
File metadata and controls
944 lines (857 loc) · 29.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
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
local _, ns = ...
ns.Notify = ns.Notify or {}
local Notify = ns.Notify
local pool = {} -- recipeId -> frame (active only)
local freeToasts = {} -- recycled toast frames
local container
local dragBar
local collapseBtn
local tabHost
local pageBar
local profTabs = {} -- reusable tab buttons
local DIFF_COLOR = {
orange = { 1.0, 0.5, 0.0 },
yellow = { 1.0, 1.0, 0.0 },
green = { 0.25, 0.75, 0.25 },
gray = { 0.6, 0.6, 0.6 },
}
local PROF_SHORT = {
Alchemy = "Alch",
Blacksmithing = "BS",
Enchanting = "Enc",
Engineering = "Eng",
Leatherworking = "LW",
Tailoring = "Tail",
Mining = "Mine",
Cooking = "Cook",
["First Aid"] = "Aid",
}
local TOAST_W, TOAST_H = 320, 72
local TOAST_GAP = 6
local DRAG_H = 22
local TAB_H = 20
local PAGE_H = 20
-- Bump to force-rebuild toast chrome after visual changes (/reload).
local TOAST_LAYOUT = 1
local PANEL_STONE = "Interface\\AddOns\\ProfessionMaster\\Media\\panel-stone"
local CHIP_BACKDROP = {
bgFile = PANEL_STONE,
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true,
tileSize = 64,
edgeSize = 8,
insets = { left = 2, right = 2, top = 2, bottom = 2 },
}
local TOAST_BACKDROP = {
bgFile = PANEL_STONE,
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true,
tileSize = 64,
edgeSize = 12,
insets = { left = 3, right = 3, top = 3, bottom = 3 },
}
local CHROME = {
gold = { 1, 0.82, 0, 1 },
goldSoft = { 0.85, 0.70, 0.20, 1 },
stone = { 1, 1, 1, 0.95 },
chipOff = { 1, 1, 1, 0.9 },
chipOffBorder = { 0.70, 0.58, 0.18, 0.85 },
}
local EnsureContainer -- forward decl
local Layout
local function IsCollapsed()
return ns.db and ns.db.settings and ns.db.settings.toastCollapsed and true or false
end
local function ClampToastScale(scale)
scale = tonumber(scale) or 1
return math.max(0.7, math.min(1.5, scale))
end
local function GetToastScale()
return ClampToastScale(ns.db and ns.db.settings and ns.db.settings.toastScale)
end
local function ApplyToastScale()
if container then
container:SetScale(GetToastScale())
end
end
local function SetToastScale(scale)
if not ns.db or not ns.db.settings then
return
end
ns.db.settings.toastScale = ClampToastScale(scale)
EnsureContainer()
ApplyToastScale()
end
local function GetFilterProfession()
if not ns.db or not ns.db.settings then
return nil
end
local f = ns.db.settings.toastFilterProfession
if f == "" or f == "All" then
return nil
end
return f
end
local function GetPageSize()
local n = ns.db and ns.db.settings and tonumber(ns.db.settings.toastPageSize)
n = n or 4
return math.max(1, math.min(12, n))
end
local function GetPage()
local n = ns.db and ns.db.settings and tonumber(ns.db.settings.toastPage)
return math.max(1, n or 1)
end
local function SetPage(page)
if not ns.db or not ns.db.settings then
return
end
ns.db.settings.toastPage = math.max(1, page or 1)
end
local function SetFilterProfession(profKey)
if not ns.db or not ns.db.settings then
return
end
ns.db.settings.toastFilterProfession = profKey
ns.db.settings.toastPage = 1
Layout()
end
local function SaveContainerPoint()
if not container or not ns.db or not ns.db.settings then
return
end
local point, relativeTo, relativePoint, x, y = container:GetPoint(1)
local relName = "UIParent"
if type(relativeTo) == "table" and relativeTo.GetName then
relName = relativeTo:GetName() or "UIParent"
end
ns.db.settings.toastPoint = { point or "TOP", relName, relativePoint or "TOP", x or 0, y or 0 }
end
local function ResolveItemIcon(itemId)
if not itemId or itemId <= 0 then
return nil
end
if C_Item and C_Item.GetItemIconByID then
local ok, tex = pcall(C_Item.GetItemIconByID, itemId)
if ok and tex and tex ~= 0 then
return tex
end
end
if GetItemIcon then
local ok, tex = pcall(GetItemIcon, itemId)
if ok and tex and tex ~= 0 then
return tex
end
end
return nil
end
local function ResolveSpellIcon(spellId)
if not spellId then
return nil
end
if C_Spell and C_Spell.GetSpellTexture then
local ok, tex = pcall(C_Spell.GetSpellTexture, spellId)
if ok and tex and tex ~= 0 then
return tex
end
end
if GetSpellTexture then
local ok, tex = pcall(GetSpellTexture, spellId)
if ok and tex and tex ~= 0 then
return tex
end
end
return nil
end
local function SetToastIcon(frame, recipe)
local itemId = recipe and recipe.itemId
local tex = ResolveItemIcon(itemId)
if not tex then
tex = ResolveSpellIcon(recipe and recipe.id)
end
frame.icon:SetTexture(tex or "Interface\\Icons\\INV_Misc_QuestionMark")
frame.itemId = itemId
local ItemMixin = _G.Item
if itemId and not tex and ItemMixin and ItemMixin.CreateFromItemID then
local item = ItemMixin:CreateFromItemID(itemId)
if item and item.ContinueOnItemLoad then
item:ContinueOnItemLoad(function()
if frame.itemId ~= itemId then
return
end
local loaded = ResolveItemIcon(itemId)
if loaded then
frame.icon:SetTexture(loaded)
end
end)
end
elseif itemId and not tex and C_Item and C_Item.RequestLoadItemDataByID then
pcall(C_Item.RequestLoadItemDataByID, itemId)
C_Timer.After(0.35, function()
if frame.itemId ~= itemId then
return
end
local loaded = ResolveItemIcon(itemId)
if loaded then
frame.icon:SetTexture(loaded)
end
end)
end
end
local function ShowItemTooltip(owner, itemId)
if not itemId or itemId <= 0 then
return false
end
GameTooltip:SetOwner(owner, "ANCHOR_LEFT")
local ok = false
if GameTooltip.SetItemByID then
ok = pcall(GameTooltip.SetItemByID, GameTooltip, itemId)
end
if not ok and GameTooltip.SetHyperlink then
ok = pcall(GameTooltip.SetHyperlink, GameTooltip, "item:" .. itemId)
end
if ok then
GameTooltip:Show()
return true
end
GameTooltip:Hide()
return false
end
local function ShowCraftTooltip(owner, data)
if not data or not data.recipe then
return
end
local r = data.recipe
GameTooltip:SetOwner(owner, "ANCHOR_LEFT")
if r.itemId and r.itemId > 0 then
local ok = false
if GameTooltip.SetItemByID then
ok = pcall(GameTooltip.SetItemByID, GameTooltip, r.itemId)
end
if not ok and GameTooltip.SetHyperlink then
ok = pcall(GameTooltip.SetHyperlink, GameTooltip, "item:" .. r.itemId)
end
if ok then
GameTooltip:AddLine(" ")
else
GameTooltip:AddLine(r.name, 1, 0.82, 0)
end
else
GameTooltip:AddLine(r.name, 1, 0.82, 0)
end
GameTooltip:AddLine(r.profession, 0.7, 0.7, 0.7)
if data.difficulty then
local col = DIFF_COLOR[data.difficulty] or DIFF_COLOR.gray
GameTooltip:AddLine(
string.format("Difficulty: %s", data.difficulty),
col[1], col[2], col[3]
)
end
if r.reagents then
GameTooltip:AddLine(" ")
GameTooltip:AddLine("Reagents:", 0.9, 0.9, 0.9)
for _, rg in ipairs(r.reagents) do
local itemId = ns.RecipeDB.ReagentItemId(rg)
local have = ns.Inventory:GetCount(itemId)
local need = ns.RecipeDB.ReagentCount(rg)
local c = have >= need and "|cff00ff00" or "|cffff6666"
local nm = rg.name or ns.RecipeDB:ItemName(itemId)
GameTooltip:AddLine(
string.format("%s%s|r %d / %d", c, nm, have, need),
1, 1, 1
)
end
end
if data.accountBankOnly then
GameTooltip:AddLine("Some mats only in account bank", 1, 0.6, 0.2)
end
GameTooltip:AddLine(" ")
GameTooltip:AddLine("Left-click: craft · Shift: craft max", 0.55, 0.75, 1)
GameTooltip:AddLine("Right-click: hide this recipe from toasts", 0.65, 0.65, 0.65)
GameTooltip:Show()
end
local function CollectActiveSorted()
local list = {}
for _, frame in pairs(pool) do
if frame.active then
list[#list + 1] = frame
end
end
local rank = { orange = 0, yellow = 1, green = 2, gray = 3 }
table.sort(list, function(a, b)
local da = rank[a.data and a.data.difficulty] or 9
local db = rank[b.data and b.data.difficulty] or 9
if da ~= db then
return da < db
end
local sa = (a.data and a.data.skillUps) or 0
local sb = (b.data and b.data.skillUps) or 0
if sa ~= sb then
return sa > sb
end
return (a.data and a.data.recipe and a.data.recipe.name or "")
< (b.data and b.data.recipe and b.data.recipe.name or "")
end)
return list
end
local function FilterByProfession(list, profKey)
if not profKey then
return list
end
local out = {}
for i = 1, #list do
local f = list[i]
local p = f.data and f.data.recipe and f.data.recipe.profession
if p == profKey then
out[#out + 1] = f
end
end
return out
end
local function ProfessionKeysPresent(list)
local seen = {}
local keys = {}
for i = 1, #list do
local p = list[i].data and list[i].data.recipe and list[i].data.recipe.profession
if p and not seen[p] then
seen[p] = true
keys[#keys + 1] = p
end
end
table.sort(keys, function(a, b)
return (PROF_SHORT[a] or a) < (PROF_SHORT[b] or b)
end)
return keys
end
local function UpdateCollapseChrome(activeCount, filteredCount)
if not dragBar or not collapseBtn then
return
end
local collapsed = IsCollapsed()
if collapsed then
collapseBtn:SetNormalTexture("Interface\\Buttons\\UI-PlusButton-UP")
collapseBtn:SetPushedTexture("Interface\\Buttons\\UI-PlusButton-DOWN")
collapseBtn:SetHighlightTexture("Interface\\Buttons\\UI-PlusButton-Hilight")
local filter = GetFilterProfession()
if filter then
dragBar.label:SetText(string.format(
"%s · %d/%d",
PROF_SHORT[filter] or filter,
filteredCount,
activeCount
))
else
dragBar.label:SetText(string.format(
"ProfessionMaster · %d craft%s",
activeCount,
activeCount == 1 and "" or "s"
))
end
else
collapseBtn:SetNormalTexture("Interface\\Buttons\\UI-MinusButton-UP")
collapseBtn:SetPushedTexture("Interface\\Buttons\\UI-MinusButton-DOWN")
collapseBtn:SetHighlightTexture("Interface\\Buttons\\UI-PlusButton-Hilight")
dragBar.label:SetText("ProfessionMaster · drag to move")
end
end
local function RebuildProfTabs(allList, filteredList)
if not tabHost then
return
end
for _, tab in ipairs(profTabs) do
tab:Hide()
end
local collapsed = IsCollapsed()
if collapsed or #allList == 0 then
tabHost:Hide()
tabHost:SetHeight(1)
return
end
local profKeys = ProfessionKeysPresent(allList)
-- Only show tab row when 2+ professions (or always with All for clarity).
local tabs = { { key = nil, label = "All" } }
for i = 1, #profKeys do
local k = profKeys[i]
tabs[#tabs + 1] = { key = k, label = PROF_SHORT[k] or k }
end
tabHost:Show()
tabHost:SetHeight(TAB_H)
local filter = GetFilterProfession()
local x = 0
for i, spec in ipairs(tabs) do
local tab = profTabs[i]
if not tab then
tab = CreateFrame("Button", nil, tabHost, "BackdropTemplate")
tab:SetHeight(TAB_H - 2)
tab:SetBackdrop(CHIP_BACKDROP)
tab.label = tab:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
tab.label:SetPoint("CENTER")
tab:SetScript("OnClick", function(self)
SetFilterProfession(self.profKey)
end)
profTabs[i] = tab
end
tab.profKey = spec.key
local count = 0
if not spec.key then
count = #allList
else
for j = 1, #allList do
local p = allList[j].data and allList[j].data.recipe and allList[j].data.recipe.profession
if p == spec.key then
count = count + 1
end
end
end
tab.label:SetText(string.format("%s %d", spec.label, count))
local w = math.max(36, (tab.label:GetStringWidth() or 30) + 12)
tab:SetWidth(w)
tab:ClearAllPoints()
tab:SetPoint("LEFT", tabHost, "LEFT", x, 0)
local selected = (spec.key == nil and filter == nil) or (spec.key ~= nil and filter == spec.key)
if selected then
tab:SetBackdropColor(0.25, 0.45, 0.75, 0.95)
tab:SetBackdropBorderColor(0.55, 0.7, 0.95, 1)
else
tab:SetBackdropColor(CHROME.chipOff[1], CHROME.chipOff[2], CHROME.chipOff[3], CHROME.chipOff[4])
tab:SetBackdropBorderColor(
CHROME.chipOffBorder[1],
CHROME.chipOffBorder[2],
CHROME.chipOffBorder[3],
CHROME.chipOffBorder[4]
)
end
tab:Show()
x = x + w + 3
end
end
local function UpdatePageBar(filteredCount, page, pageSize, totalPages)
if not pageBar then
return
end
local collapsed = IsCollapsed()
if collapsed or filteredCount <= pageSize then
pageBar:Hide()
pageBar:SetHeight(1)
return
end
pageBar:Show()
pageBar:SetHeight(PAGE_H)
pageBar.label:SetText(string.format("%d–%d / %d", (page - 1) * pageSize + 1, math.min(page * pageSize, filteredCount), filteredCount))
pageBar.prev:SetEnabled(page > 1)
pageBar.next:SetEnabled(page < totalPages)
end
Layout = function()
local parent = EnsureContainer()
local allList = CollectActiveSorted()
local filter = GetFilterProfession()
if filter then
local present = false
for i = 1, #allList do
local p = allList[i].data and allList[i].data.recipe and allList[i].data.recipe.profession
if p == filter then
present = true
break
end
end
if not present and ns.db and ns.db.settings then
ns.db.settings.toastFilterProfession = nil
filter = nil
SetPage(1)
end
end
local filtered = FilterByProfession(allList, filter)
local pageSize = GetPageSize()
local totalPages = 1
if #filtered > 0 then
totalPages = math.max(1, math.ceil(#filtered / pageSize))
end
local page = GetPage()
if page > totalPages then
page = totalPages
SetPage(page)
end
local collapsed = IsCollapsed()
local headerVisible = #allList > 0
if dragBar then
if headerVisible then
dragBar:Show()
UpdateCollapseChrome(#allList, #filtered)
else
dragBar:Hide()
end
end
RebuildProfTabs(allList, filtered)
local yOff = DRAG_H
if tabHost and tabHost:IsShown() and not collapsed then
yOff = yOff + TAB_H + 2
tabHost:ClearAllPoints()
tabHost:SetPoint("TOPLEFT", parent, "TOPLEFT", 0, -DRAG_H)
tabHost:SetPoint("TOPRIGHT", parent, "TOPRIGHT", 0, -DRAG_H)
end
-- Hide all first.
for _, frame in pairs(pool) do
frame:Hide()
end
if not collapsed then
local startIdx = (page - 1) * pageSize + 1
local endIdx = math.min(#filtered, page * pageSize)
local row = 0
for i = startIdx, endIdx do
local frame = filtered[i]
frame:ClearAllPoints()
frame:SetPoint("TOP", parent, "TOP", 0, -(yOff + 2 + row * (TOAST_H + TOAST_GAP)))
frame:Show()
row = row + 1
end
yOff = yOff + 2 + row * (TOAST_H + TOAST_GAP)
end
UpdatePageBar(#filtered, page, pageSize, totalPages)
if pageBar and pageBar:IsShown() and not collapsed then
pageBar:ClearAllPoints()
pageBar:SetPoint("TOPLEFT", parent, "TOPLEFT", 0, -yOff)
pageBar:SetPoint("TOPRIGHT", parent, "TOPRIGHT", 0, -yOff)
end
end
local function ToggleCollapsed()
if not ns.db or not ns.db.settings then
return
end
ns.db.settings.toastCollapsed = not IsCollapsed()
Layout()
end
local function ShiftPage(delta)
local allList = CollectActiveSorted()
local filtered = FilterByProfession(allList, GetFilterProfession())
local pageSize = GetPageSize()
local totalPages = math.max(1, math.ceil(#filtered / pageSize))
local page = math.min(totalPages, math.max(1, GetPage() + delta))
SetPage(page)
Layout()
end
local function ResetToastChrome()
if container then
container:Hide()
container:SetParent(nil)
container = nil
end
dragBar = nil
collapseBtn = nil
tabHost = nil
pageBar = nil
wipe(profTabs)
-- Drop toast frames so they rebuild with the new backdrop (do not recycle old chrome).
for id, frame in pairs(pool) do
if frame then
frame:Hide()
frame:SetParent(nil)
end
pool[id] = nil
end
wipe(freeToasts)
end
EnsureContainer = function()
if container and container.layoutVersion ~= TOAST_LAYOUT then
ResetToastChrome()
end
if container then
return container
end
container = CreateFrame("Frame", "ProfessionMasterToastContainer", UIParent, "BackdropTemplate")
container:SetSize(TOAST_W, DRAG_H + TAB_H + PAGE_H + 400)
container:SetFrameStrata("HIGH")
container:SetClampedToScreen(true)
container:SetMovable(true)
container:EnableMouse(false)
container:SetDontSavePosition(true)
container.layoutVersion = TOAST_LAYOUT
local point = ns.db and ns.db.settings and ns.db.settings.toastPoint
if type(point) == "table" and point[1] then
container:SetPoint(point[1], _G[point[2]] or UIParent, point[3], point[4] or 0, point[5] or 0)
else
container:SetPoint("TOP", UIParent, "TOP", 0, -80)
end
dragBar = CreateFrame("Button", nil, container, "BackdropTemplate")
dragBar:SetPoint("TOPLEFT", 0, 0)
dragBar:SetPoint("TOPRIGHT", 0, 0)
dragBar:SetHeight(DRAG_H)
dragBar:SetBackdrop(CHIP_BACKDROP)
dragBar:SetBackdropColor(CHROME.stone[1], CHROME.stone[2], CHROME.stone[3], CHROME.stone[4])
dragBar:SetBackdropBorderColor(CHROME.gold[1], CHROME.gold[2], CHROME.gold[3], CHROME.gold[4])
dragBar:EnableMouse(true)
dragBar:RegisterForDrag("LeftButton")
dragBar:RegisterForClicks("LeftButtonUp")
dragBar:SetScript("OnDragStart", function()
container:StartMoving()
end)
dragBar:SetScript("OnDragStop", function()
container:StopMovingOrSizing()
SaveContainerPoint()
end)
dragBar:SetScript("OnClick", function()
if IsCollapsed() then
ToggleCollapsed()
end
end)
dragBar:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_BOTTOM")
GameTooltip:AddLine("ProfessionMaster toasts", 1, 0.82, 0)
GameTooltip:AddLine("Drag to move. − collapses. Tabs filter by profession.", 0.75, 0.75, 0.75, true)
GameTooltip:Show()
end)
dragBar:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
collapseBtn = CreateFrame("Button", nil, dragBar)
collapseBtn:SetSize(16, 16)
collapseBtn:SetPoint("RIGHT", -4, 0)
collapseBtn:SetFrameLevel(dragBar:GetFrameLevel() + 2)
collapseBtn:SetScript("OnClick", function()
ToggleCollapsed()
end)
collapseBtn:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_LEFT")
GameTooltip:AddLine(IsCollapsed() and "Expand craft toasts" or "Collapse craft toasts", 1, 0.82, 0)
GameTooltip:Show()
end)
collapseBtn:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
local dragLabel = dragBar:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
dragLabel:SetPoint("LEFT", 8, 0)
dragLabel:SetPoint("RIGHT", collapseBtn, "LEFT", -4, 0)
dragLabel:SetJustifyH("LEFT")
dragLabel:SetText("ProfessionMaster · drag to move")
dragBar.label = dragLabel
ApplyToastScale()
tabHost = CreateFrame("Frame", nil, container)
tabHost:SetPoint("TOPLEFT", 0, -DRAG_H)
tabHost:SetPoint("TOPRIGHT", 0, -DRAG_H)
tabHost:SetHeight(TAB_H)
tabHost:Hide()
pageBar = CreateFrame("Frame", nil, container, "BackdropTemplate")
pageBar:SetHeight(PAGE_H)
pageBar:SetBackdrop(CHIP_BACKDROP)
pageBar:SetBackdropColor(CHROME.stone[1], CHROME.stone[2], CHROME.stone[3], 0.9)
pageBar:SetBackdropBorderColor(CHROME.goldSoft[1], CHROME.goldSoft[2], CHROME.goldSoft[3], CHROME.goldSoft[4])
pageBar:Hide()
pageBar.prev = CreateFrame("Button", nil, pageBar)
pageBar.prev:SetSize(18, 18)
pageBar.prev:SetPoint("LEFT", 4, 0)
pageBar.prev:SetNormalTexture("Interface\\Buttons\\UI-SpellbookIcon-PrevPage-Up")
pageBar.prev:SetPushedTexture("Interface\\Buttons\\UI-SpellbookIcon-PrevPage-Down")
pageBar.prev:SetDisabledTexture("Interface\\Buttons\\UI-SpellbookIcon-PrevPage-Disabled")
pageBar.prev:SetHighlightTexture("Interface\\Buttons\\UI-Common-MouseHilight")
pageBar.prev:SetScript("OnClick", function()
ShiftPage(-1)
end)
pageBar.next = CreateFrame("Button", nil, pageBar)
pageBar.next:SetSize(18, 18)
pageBar.next:SetPoint("RIGHT", -4, 0)
pageBar.next:SetNormalTexture("Interface\\Buttons\\UI-SpellbookIcon-NextPage-Up")
pageBar.next:SetPushedTexture("Interface\\Buttons\\UI-SpellbookIcon-NextPage-Down")
pageBar.next:SetDisabledTexture("Interface\\Buttons\\UI-SpellbookIcon-NextPage-Disabled")
pageBar.next:SetHighlightTexture("Interface\\Buttons\\UI-Common-MouseHilight")
pageBar.next:SetScript("OnClick", function()
ShiftPage(1)
end)
pageBar.label = pageBar:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
pageBar.label:SetPoint("CENTER")
pageBar.label:SetText("1 / 1")
UpdateCollapseChrome(0, 0)
dragBar:Hide()
return container
end
local function CreateToast(recipeId)
local parent = EnsureContainer()
local f = CreateFrame("Button", nil, parent, "BackdropTemplate")
f:SetSize(TOAST_W, TOAST_H)
f:SetBackdrop(TOAST_BACKDROP)
f:SetBackdropColor(CHROME.stone[1], CHROME.stone[2], CHROME.stone[3], CHROME.stone[4])
f:SetBackdropBorderColor(CHROME.goldSoft[1], CHROME.goldSoft[2], CHROME.goldSoft[3], CHROME.goldSoft[4])
f:EnableMouse(true)
f:RegisterForClicks("LeftButtonUp", "RightButtonUp")
local iconBtn = CreateFrame("Button", nil, f)
iconBtn:SetSize(48, 48)
iconBtn:SetPoint("LEFT", 10, 0)
iconBtn:EnableMouse(true)
iconBtn:RegisterForClicks("LeftButtonUp", "RightButtonUp")
local icon = iconBtn:CreateTexture(nil, "ARTWORK")
icon:SetAllPoints()
icon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
f.icon = icon
f.iconBtn = iconBtn
local title = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
title:SetPoint("TOPLEFT", iconBtn, "TOPRIGHT", 8, 2)
title:SetPoint("RIGHT", f, "RIGHT", -10, 0)
title:SetJustifyH("LEFT")
f.title = title
local sub = f:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
sub:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -2)
sub:SetPoint("RIGHT", f, "RIGHT", -10, 0)
sub:SetJustifyH("LEFT")
f.sub = sub
local hint = f:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
hint:SetPoint("BOTTOMLEFT", iconBtn, "BOTTOMRIGHT", 8, 0)
hint:SetPoint("RIGHT", f, "RIGHT", -10, 0)
hint:SetJustifyH("LEFT")
hint:SetText("Click craft · Shift=max · Right-click hide")
f.hint = hint
iconBtn:SetScript("OnEnter", function(self)
local parentToast = self:GetParent()
local itemId = parentToast and parentToast.itemId
if itemId and ShowItemTooltip(self, itemId) then
return
end
if parentToast and parentToast.data then
ShowCraftTooltip(self, parentToast.data)
end
end)
iconBtn:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
iconBtn:SetScript("OnClick", function(self, button)
local parentToast = self:GetParent()
if parentToast and parentToast:GetScript("OnClick") then
parentToast:GetScript("OnClick")(parentToast, button)
end
end)
f:SetScript("OnEnter", function(self)
ShowCraftTooltip(self, self.data)
end)
f:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
f:SetScript("OnClick", function(self, button)
if button == "RightButton" then
if self.data and self.data.recipeId and ns.RecipeDB then
local name = self.data.recipe and self.data.recipe.name or tostring(self.data.recipeId)
ns.RecipeDB:HideRecipe(self.data.recipeId)
ns.Print("Hidden toast: %s (/pm unhide to restore)", name)
if ns.ScheduleRescan then
ns.ScheduleRescan()
end
end
return
end
if not self.data then
return
end
local num = 1
if IsShiftKeyDown() and ns.db.settings.shiftCraftMax ~= false then
num = self.data.craftable or 1
end
if ns.Craft then
ns.Craft:CraftRecipe(self.data.recipeId, num)
end
end)
f.recipeId = recipeId
return f
end
local function UpdateToast(frame, data)
frame.data = data
local recipe = data.recipe
SetToastIcon(frame, recipe)
-- Keep stone fill; difficulty tints the gold tooltip border.
frame:SetBackdropColor(CHROME.stone[1], CHROME.stone[2], CHROME.stone[3], CHROME.stone[4])
local col = DIFF_COLOR[data.difficulty] or DIFF_COLOR.yellow
frame:SetBackdropBorderColor(col[1], col[2], col[3], 1)
frame.title:SetText(recipe.name)
frame.title:SetTextColor(col[1], col[2], col[3])
local approx = (data.difficulty == "yellow" or data.difficulty == "green") and "~" or ""
local bankNote = data.accountBankOnly and " |cffFFA500(acct bank)|r" or ""
frame.sub:SetText(string.format(
"%s · skill %d/%d · x%d · %s%d skill-up(s)%s",
recipe.profession,
data.skill or 0,
data.skillMax or 300,
data.craftable or 0,
approx,
data.skillUps or 0,
bankNote
))
end
function Notify:Init()
EnsureContainer()
ApplyToastScale()
end
function Notify:GetScale()
return GetToastScale()
end
function Notify:SetScale(scale)
SetToastScale(scale)
end
function Notify:Sync(candidates)
candidates = candidates or {}
local seen = {}
local parent = EnsureContainer()
local list
if candidates[1] ~= nil or #candidates > 0 then
list = candidates
else
list = {}
for recipeId, data in pairs(candidates) do
if type(data) == "table" and data.recipe then
data.recipeId = data.recipeId or recipeId
list[#list + 1] = data
end
end
end
for i = 1, #list do
local data = list[i]
local recipeId = data.recipeId
if recipeId then
seen[recipeId] = true
local frame = pool[recipeId]
if not frame then
frame = table.remove(freeToasts)
if not frame then
frame = CreateToast(recipeId)
if ns.db and ns.db.settings and ns.db.settings.toastSound ~= false then
if PlaySound then
pcall(PlaySound, SOUNDKIT and SOUNDKIT.UI_PROFESSION_CRAFTING_RESULT_QUALITY1 or 5274)
end
end
end
pool[recipeId] = frame
frame.recipeId = recipeId
frame:SetParent(parent)
frame:SetBackdrop(TOAST_BACKDROP)
end
UpdateToast(frame, data)
frame.active = true
end
end
for recipeId, frame in pairs(pool) do
if not seen[recipeId] then
frame.active = false
frame:Hide()
frame.data = nil
frame.itemId = nil
pool[recipeId] = nil
-- Cap recycled frames so idle toasts cannot grow without bound.
if #freeToasts < 24 then
freeToasts[#freeToasts + 1] = frame
else
frame:SetParent(nil)
end
end
end
-- Keep page in range after sync.
Layout()
end
function Notify:IsCollapsed()
return IsCollapsed()
end
function Notify:SetCollapsed(collapsed)
if not ns.db or not ns.db.settings then
return
end
ns.db.settings.toastCollapsed = collapsed and true or false
Layout()
end
function Notify:SetPoint(point, relativeTo, relativePoint, x, y)
local c = EnsureContainer()
c:ClearAllPoints()
c:SetPoint(point, relativeTo or UIParent, relativePoint, x or 0, y or 0)
SaveContainerPoint()
end