Repository navigation
Expand file tree
/
Copy pathUI.lua
More file actions
1461 lines (1345 loc) · 50.3 KB
/
Copy pathUI.lua
File metadata and controls
1461 lines (1345 loc) · 50.3 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 _, ns = ...
ns.UI = ns.UI or {}
local UI = ns.UI
local mainFrame
local charTabs = {}
local profChips = {}
local recipeRows = {}
local selectedChar
local selectedProf
local recipeSearch = ""
local RebuildRecipeList -- forward decl (search box OnTextChanged)
local function GetRecipePageSize()
local n = ns.db and ns.db.settings and tonumber(ns.db.settings.recipePageSize)
n = n or 12
return math.max(8, math.min(30, n))
end
local function GetRecipePage()
local n = ns.db and ns.db.settings and tonumber(ns.db.settings.recipePage)
return math.max(1, n or 1)
end
local function SetRecipePage(page)
if not ns.db or not ns.db.settings then
return
end
ns.db.settings.recipePage = math.max(1, page or 1)
if ProfessionMasterDB and ProfessionMasterDB.settings then
ProfessionMasterDB.settings.recipePage = ns.db.settings.recipePage
end
end
local function ResetRecipePage()
SetRecipePage(1)
end
local PAD = 16
local SIDEBAR_W = 168
local FOOTER_H = 36
local TAB_SIZE_DEFAULT = 28
local TAB_SIZE_MIN = 20
local TAB_SIZE_MAX = 40
local SIDEBAR_ROW_H = 36
local SIDEBAR_GAP = 4
-- Bump to force-rebuild the main frame after chrome/layout changes (/reload).
local UI_LAYOUT = 2
local CLASS_ICON_PATH = "Interface\\Glues\\CharacterCreate\\UI-CharacterCreate-Classes"
local CLASS_CIRCLE_PATH = "Interface\\TargetingFrame\\UI-Classes-Circles"
local PROF_ICONS = {
Alchemy = "Interface\\Icons\\Trade_Alchemy",
Blacksmithing = "Interface\\Icons\\Trade_BlackSmithing",
Enchanting = "Interface\\Icons\\Trade_Engraving",
Engineering = "Interface\\Icons\\Trade_Engineering",
Herbalism = "Interface\\Icons\\Trade_Herbalism",
Inscription = "Interface\\Icons\\INV_Inscription_Tradeskill01",
Jewelcrafting = "Interface\\Icons\\INV_Misc_Gem_01",
Leatherworking = "Interface\\Icons\\Trade_LeatherWorking",
Mining = "Interface\\Icons\\Trade_Mining",
Skinning = "Interface\\Icons\\INV_Misc_Pelt_Wolf_01",
Tailoring = "Interface\\Icons\\Trade_Tailoring",
Cooking = "Interface\\Icons\\INV_Misc_Food_15",
Fishing = "Interface\\Icons\\Trade_Fishing",
["First Aid"] = "Interface\\Icons\\Spell_Holy_SealOfSacrifice",
}
-- Charcoal fill — chrome uses native Blizzard gold dialog/tooltip borders.
local PANEL_STONE = "Interface\\AddOns\\ProfessionMaster\\Media\\panel-stone"
local WINDOW_BACKDROP = {
bgFile = PANEL_STONE,
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
tile = true,
tileSize = 128,
edgeSize = 32,
insets = { left = 11, right = 12, top = 12, bottom = 11 },
}
local INSET_BACKDROP = {
bgFile = PANEL_STONE,
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true,
tileSize = 128,
edgeSize = 12,
insets = { left = 3, right = 3, top = 3, bottom = 3 },
}
local CHIP_BACKDROP = {
bgFile = PANEL_STONE,
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true,
tileSize = 64,
edgeSize = 10,
insets = { left = 2, right = 2, top = 2, bottom = 2 },
}
local ROW_BACKDROP = {
bgFile = PANEL_STONE,
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true,
tileSize = 64,
edgeSize = 10,
insets = { left = 2, right = 2, top = 2, bottom = 2 },
}
local THEME = {
window = { 1, 1, 1, 1 }, -- stone texture carries color
border = { 1, 0.82, 0, 1 }, -- Blizzard gold
inset = { 1, 1, 1, 1 },
insetBorder = { 0.85, 0.70, 0.20, 1 },
row = { 1, 1, 1, 0.95 },
rowBorder = { 0.70, 0.58, 0.18, 0.75 },
chipOff = { 1, 1, 1, 0.9 },
chipOffBorder = { 0.70, 0.58, 0.18, 0.85 },
title = { 1, 0.82, 0 },
subtitle = { 0.85, 0.82, 0.75 },
}
local DIFF_HEX = {
orange = "|cffff7f00",
yellow = "|cffffff00",
green = "|cff40c040",
gray = "|cff999999",
unavailable = "|cff666666",
}
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 SetRowRecipeIcon(row, recipe)
local itemId = recipe and recipe.itemId
local tex = ResolveItemIcon(itemId)
if not tex then
tex = ResolveSpellIcon(recipe and recipe.id)
end
row.icon:SetTexture(tex or "Interface\\Icons\\INV_Misc_QuestionMark")
row.itemId = itemId
if itemId and not tex and C_Item and C_Item.RequestLoadItemDataByID then
pcall(C_Item.RequestLoadItemDataByID, itemId)
C_Timer.After(0.35, function()
if row.itemId ~= itemId then
return
end
local loaded = ResolveItemIcon(itemId)
if loaded then
row.icon:SetTexture(loaded)
end
end)
end
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 row.itemId ~= itemId then
return
end
local loaded = ResolveItemIcon(itemId)
if loaded then
row.icon:SetTexture(loaded)
end
end)
end
end
end
local function ShowRecipeTooltip(owner, recipe, anchor)
if not recipe then
return
end
GameTooltip:SetOwner(owner, anchor or "ANCHOR_RIGHT")
local showedItem = false
if recipe.itemId and recipe.itemId > 0 then
if GameTooltip.SetItemByID then
showedItem = pcall(GameTooltip.SetItemByID, GameTooltip, recipe.itemId)
end
if not showedItem and GameTooltip.SetHyperlink then
showedItem = pcall(GameTooltip.SetHyperlink, GameTooltip, "item:" .. recipe.itemId)
end
end
if showedItem then
GameTooltip:AddLine(" ")
else
GameTooltip:AddLine(recipe.name, 1, 0.82, 0)
end
if recipe.profession then
GameTooltip:AddLine(recipe.profession, 0.7, 0.7, 0.7)
end
if recipe.gather then
if recipe.static then
local approx = (recipe.approx or not ns.isForever) and "~" or ""
GameTooltip:AddLine(string.format("Requires %s %s%d", recipe.profession or "", approx, recipe.orange or 0), 1, 0.82, 0)
GameTooltip:AddLine(string.format("Yellow %d · Green %d · Gray %d",
recipe.yellow or 0, recipe.green or 0, recipe.gray or 0), 0.7, 0.7, 0.7)
end
local users = ns.Gathering and ns.Gathering:UsedBy(recipe.itemId) or {}
local hookCovers = showedItem and ns.Gathering.hooked and ns.db.settings.gatherTooltips ~= false
and ns.Gathering:TooltipLines(recipe.itemId) ~= nil
if #users > 0 and not hookCovers then
GameTooltip:AddLine("Used by your characters:", 0.9, 0.9, 0.9)
for _, u in ipairs(users) do
GameTooltip:AddLine(string.format("%s — %s (%d recipes)", u.charKey, u.prof, u.recipes), 0.49, 0.81, 0.63)
end
end
elseif recipe.reagents and #recipe.reagents > 0 then
GameTooltip:AddLine("Reagents:", 0.9, 0.9, 0.9)
for _, rg in ipairs(recipe.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
GameTooltip:Show()
end
local function ApplyWindow(frame)
frame:SetBackdrop(WINDOW_BACKDROP)
frame:SetBackdropColor(THEME.window[1], THEME.window[2], THEME.window[3], THEME.window[4])
frame:SetBackdropBorderColor(THEME.border[1], THEME.border[2], THEME.border[3], THEME.border[4])
end
local function ApplyInset(frame)
frame:SetBackdrop(INSET_BACKDROP)
frame:SetBackdropColor(THEME.inset[1], THEME.inset[2], THEME.inset[3], THEME.inset[4] or 1)
frame:SetBackdropBorderColor(
THEME.insetBorder[1],
THEME.insetBorder[2],
THEME.insetBorder[3],
THEME.insetBorder[4]
)
end
local function ResetMainFrame()
if mainFrame then
mainFrame:Hide()
mainFrame:SetParent(nil)
mainFrame = nil
end
wipe(charTabs)
wipe(profChips)
wipe(recipeRows)
end
local function ClampCharTabSize(size)
size = tonumber(size) or TAB_SIZE_DEFAULT
return math.max(TAB_SIZE_MIN, math.min(TAB_SIZE_MAX, math.floor(size + 0.5)))
end
local function TabSize()
return ClampCharTabSize(ns.db and ns.db.settings and ns.db.settings.charTabSize)
end
local function SetCharTabSize(size)
if not ns.db or not ns.db.settings then
return
end
ns.db.settings.charTabSize = ClampCharTabSize(size)
if mainFrame and mainFrame:IsShown() then
UI:Refresh()
end
end
local function ClassFileOf(char)
local classFile = char and char.class
if type(classFile) == "string" and classFile ~= "" then
return string.upper(classFile)
end
return ""
end
local function ClassRGB(classFile)
local colors = CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS
local c = classFile and colors and colors[classFile]
if c then
return c.r or 1, c.g or 1, c.b or 1
end
return 1, 0.82, 0
end
local function LocalizedClassName(classFile)
if LOCALIZED_CLASS_NAMES_MALE and classFile and LOCALIZED_CLASS_NAMES_MALE[classFile] then
return LOCALIZED_CLASS_NAMES_MALE[classFile]
end
return classFile ~= "" and classFile or "Unknown"
end
local function ShortCharName(charKey, char)
if char and type(char.name) == "string" and char.name ~= "" then
local bare = char.name:match("^([^%-]+)") or char.name
return bare
end
if type(charKey) == "string" then
return charKey:match("^([^%-]+)") or charKey
end
return "?"
end
local function DestLabel(charKey, char)
local name = ShortCharName(charKey, char)
local classFile = ClassFileOf(char)
local className = LocalizedClassName(classFile)
local r, g, b = ClassRGB(classFile)
return string.format(
"|cff%02x%02x%02x%s (%s)|r",
math.floor(r * 255 + 0.5),
math.floor(g * 255 + 0.5),
math.floor(b * 255 + 0.5),
name,
className
)
end
local function SetClassIcon(tex, classFile, circular)
if not tex then
return
end
classFile = classFile and string.upper(tostring(classFile or ""))
local coords = (CLASS_ICON_TCOORDS and classFile ~= "" and CLASS_ICON_TCOORDS[classFile])
or (ns.CLASS_ICON_COORDS and ns.CLASS_ICON_COORDS[classFile])
if coords then
tex:SetTexture(circular and CLASS_CIRCLE_PATH or CLASS_ICON_PATH)
tex:SetTexCoord(coords[1], coords[2], coords[3], coords[4])
else
tex:SetTexture("Interface\\Icons\\INV_Misc_QuestionMark")
tex:SetTexCoord(0.08, 0.92, 0.08, 0.92)
end
tex:Show()
end
local function SelectChar(charKey)
selectedChar = charKey
local char = ns.CharDB:GetChar(charKey)
if char and char.professions then
local first
for _, p in ipairs(ns.Professions) do
if char.professions[p.key] and char.professions[p.key] > 0 then
first = p.key
break
end
end
selectedProf = first
end
ResetRecipePage()
UI:Refresh()
end
local function EnsureFrame()
if mainFrame and mainFrame.layoutVersion ~= UI_LAYOUT then
ResetMainFrame()
end
if mainFrame then
return mainFrame
end
local f = CreateFrame("Frame", "ProfessionMasterFrame", UIParent, "BackdropTemplate")
f:SetSize(860, 620)
f:SetPoint("CENTER")
f.layoutVersion = UI_LAYOUT
ApplyWindow(f)
f:SetMovable(true)
f:SetClampedToScreen(true)
f:EnableMouse(true)
f:RegisterForDrag("LeftButton")
f:SetScript("OnDragStart", f.StartMoving)
f:SetScript("OnDragStop", f.StopMovingOrSizing)
f:SetFrameStrata("DIALOG")
f:Hide()
tinsert(UISpecialFrames, "ProfessionMasterFrame")
local title = f:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
title:SetPoint("TOP", f, "TOP", 0, -14)
title:SetText("ProfessionMaster")
title:SetTextColor(THEME.title[1], THEME.title[2], THEME.title[3])
local subtitle = f:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
subtitle:SetPoint("TOP", title, "BOTTOM", 0, -2)
subtitle:SetPoint("LEFT", f, "LEFT", PAD + 4, 0)
subtitle:SetPoint("RIGHT", f, "RIGHT", -(PAD + 4), 0)
subtitle:SetJustifyH("CENTER")
subtitle:SetTextColor(THEME.subtitle[1], THEME.subtitle[2], THEME.subtitle[3])
subtitle:SetText("Browse alt professions and craft skill-ups. Mats use bags + account bank on this character.")
local close = CreateFrame("Button", nil, f, "UIPanelCloseButton")
close:SetPoint("TOPRIGHT", -2, -2)
close:SetFrameLevel(f:GetFrameLevel() + 20)
close:SetScript("OnClick", function()
f:Hide()
end)
-- Left alt sidebar (SnapPost Forever mapper style).
f.sidebar = CreateFrame("Frame", nil, f, "BackdropTemplate")
f.sidebar:SetPoint("TOPLEFT", PAD, -48)
f.sidebar:SetPoint("BOTTOMLEFT", PAD, PAD + FOOTER_H)
f.sidebar:SetWidth(SIDEBAR_W)
ApplyInset(f.sidebar)
f.sidebarTitle = f.sidebar:CreateFontString(nil, "OVERLAY", "GameFontNormal")
f.sidebarTitle:SetPoint("TOPLEFT", 10, -10)
f.sidebarTitle:SetText("Alts")
f.sidebarTitle:SetTextColor(THEME.title[1], THEME.title[2], THEME.title[3])
f.sidebarScroll = CreateFrame("ScrollFrame", "ProfessionMasterCharSidebarScroll", f.sidebar, "UIPanelScrollFrameTemplate")
f.sidebarScroll:SetPoint("TOPLEFT", 6, -28)
f.sidebarScroll:SetPoint("BOTTOMRIGHT", -28, 10)
f.sidebarContent = CreateFrame("Frame", nil, f.sidebarScroll)
f.sidebarContent:SetSize(SIDEBAR_W - 40, 1)
f.sidebarScroll:SetScrollChild(f.sidebarContent)
-- Main pane.
f.mainWell = CreateFrame("Frame", nil, f, "BackdropTemplate")
f.mainWell:SetPoint("TOPLEFT", f.sidebar, "TOPRIGHT", 10, 0)
f.mainWell:SetPoint("BOTTOMRIGHT", -PAD, PAD + FOOTER_H)
ApplyInset(f.mainWell)
f.main = CreateFrame("Frame", nil, f.mainWell)
f.main:SetPoint("TOPLEFT", 10, -10)
f.main:SetPoint("BOTTOMRIGHT", -10, 10)
f.profSectionLabel = f.main:CreateFontString(nil, "OVERLAY", "GameFontNormal")
f.profSectionLabel:SetPoint("TOPLEFT", 0, 0)
f.profSectionLabel:SetText("Professions")
f.profSectionLabel:SetTextColor(THEME.title[1], THEME.title[2], THEME.title[3])
f.scanBtn = CreateFrame("Button", nil, f.main, "UIPanelButtonTemplate")
f.scanBtn:SetSize(80, 22)
f.scanBtn:SetPoint("TOPRIGHT", 0, 2)
f.scanBtn:SetText("Scan")
f.scanBtn:SetScript("OnClick", function()
SelectChar(ns.PlayerKey())
ns.CharDB:SyncAllProfessionRecipes()
end)
f.charDetail = f.main:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
f.charDetail:SetPoint("TOPLEFT", f.profSectionLabel, "BOTTOMLEFT", 0, -2)
f.charDetail:SetPoint("RIGHT", f.scanBtn, "LEFT", -8, 0)
f.charDetail:SetJustifyH("LEFT")
f.charDetail:SetWordWrap(false)
f.charDetail:SetTextColor(THEME.subtitle[1], THEME.subtitle[2], THEME.subtitle[3])
f.charDetail:SetText("Select an alt, then Scan on that character.")
f.chipHost = CreateFrame("Frame", nil, f.main)
f.chipHost:SetPoint("TOPLEFT", f.charDetail, "BOTTOMLEFT", 0, -8)
f.chipHost:SetPoint("TOPRIGHT", f.main, "TOPRIGHT", 0, -40)
f.chipHost:SetHeight(104)
-- Compat aliases for older refresh helpers.
f.charPanel = {
chipHost = f.chipHost,
title = f.charDetail,
detail = f.charDetail,
icon = nil,
}
f.filterHost = CreateFrame("Frame", nil, f.main)
f.filterHost:SetPoint("TOPLEFT", f.chipHost, "BOTTOMLEFT", 0, -8)
f.filterHost:SetPoint("TOPRIGHT", f.chipHost, "BOTTOMRIGHT", 0, -8)
f.filterHost:SetHeight(24)
f.searchBox = CreateFrame("EditBox", "ProfessionMasterRecipeSearch", f.filterHost, "InputBoxTemplate")
f.searchBox:SetSize(200, 20)
f.searchBox:SetPoint("LEFT", f.filterHost, "LEFT", 6, 0)
f.searchBox:SetAutoFocus(false)
f.searchBox:SetMaxLetters(64)
f.searchBox:SetText(recipeSearch)
f.searchBox:SetScript("OnTextChanged", function(self)
local text = self:GetText() or ""
if text == recipeSearch then
return
end
recipeSearch = text
ResetRecipePage()
if mainFrame and mainFrame:IsShown() then
local char = ns.CharDB and ns.CharDB:GetChar(selectedChar)
RebuildRecipeList(mainFrame, char)
end
end)
f.searchBox:SetScript("OnEscapePressed", function(self)
self:ClearFocus()
end)
f.searchBox:SetScript("OnEnterPressed", function(self)
self:ClearFocus()
end)
f.searchClear = CreateFrame("Button", nil, f.filterHost, "UIPanelButtonTemplate")
f.searchClear:SetSize(48, 20)
f.searchClear:SetPoint("LEFT", f.searchBox, "RIGHT", 4, 0)
f.searchClear:SetText("Clear")
f.searchClear:SetScript("OnClick", function()
recipeSearch = ""
f.searchBox:SetText("")
f.searchBox:ClearFocus()
ResetRecipePage()
if mainFrame and mainFrame:IsShown() then
local char = ns.CharDB and ns.CharDB:GetChar(selectedChar)
RebuildRecipeList(mainFrame, char)
end
end)
local function MakeFilterToggle(key, label, defaultOn)
local btn = CreateFrame("Button", nil, f.filterHost, "BackdropTemplate")
btn:SetHeight(20)
btn:SetBackdrop(CHIP_BACKDROP)
btn.key = key
btn.defaultOn = defaultOn
btn.label = btn:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
btn.label:SetPoint("CENTER")
btn.baseLabel = label
btn:SetScript("OnClick", function(self)
local settings = ns.db and ns.db.settings
if not settings then
return
end
local cur = settings[self.key]
if cur == nil then
cur = self.defaultOn
end
settings[self.key] = not cur
-- Keep SavedVariables root in sync (ns.db is ProfessionMasterDB).
if ProfessionMasterDB and ProfessionMasterDB.settings then
ProfessionMasterDB.settings[self.key] = settings[self.key]
end
ResetRecipePage()
UI:Refresh()
end)
return btn
end
f.filterLearned = MakeFilterToggle("showLearnedRecipes", "Learned", true)
f.filterUnlearned = MakeFilterToggle("showUnlearnedRecipes", "Unlearned", true)
-- Cycles: low first -> high first -> off (difficulty sort).
f.sortSkill = CreateFrame("Button", nil, f.filterHost, "BackdropTemplate")
f.sortSkill:SetHeight(20)
f.sortSkill:SetBackdrop(CHIP_BACKDROP)
f.sortSkill.label = f.sortSkill:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
f.sortSkill.label:SetPoint("CENTER")
f.sortSkill:SetScript("OnClick", function()
local settings = ns.db and ns.db.settings
if not settings then
return
end
local cur = settings.unlearnedSortBySkill
local nextMode
if cur == "asc" then
nextMode = "desc"
elseif cur == "desc" then
nextMode = "off" -- not nil: nil is wiped from the table and defaults refill on load
else
nextMode = "asc"
end
settings.unlearnedSortBySkill = nextMode
if ProfessionMasterDB and ProfessionMasterDB.settings then
ProfessionMasterDB.settings.unlearnedSortBySkill = nextMode
end
ResetRecipePage()
UI:Refresh()
end)
f.sortSkill:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_BOTTOM")
GameTooltip:AddLine("Sort unlearned by skill needed", 1, 0.82, 0)
GameTooltip:AddLine("Click to cycle: low first, high first, or off (difficulty order).", 0.8, 0.8, 0.8, true)
GameTooltip:Show()
end)
f.sortSkill:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
f.filterUnlearned:SetPoint("RIGHT", f.filterHost, "RIGHT", 0, 0)
f.filterLearned:SetPoint("RIGHT", f.filterUnlearned, "LEFT", -6, 0)
f.sortSkill:SetPoint("RIGHT", f.filterLearned, "LEFT", -6, 0)
f.listInset = CreateFrame("Frame", nil, f.main, "BackdropTemplate")
f.listInset:SetPoint("TOPLEFT", f.filterHost, "BOTTOMLEFT", 0, -8)
f.listInset:SetPoint("BOTTOMRIGHT", 0, 0)
ApplyInset(f.listInset)
f.scroll = CreateFrame("ScrollFrame", "ProfessionMasterRecipeScroll", f.listInset, "UIPanelScrollFrameTemplate")
f.scroll:SetPoint("TOPLEFT", 8, -8)
f.scroll:SetPoint("BOTTOMRIGHT", -28, 8)
f.scrollChild = CreateFrame("Frame", nil, f.scroll)
f.scrollChild:SetSize(520, 100)
f.scroll:SetScrollChild(f.scrollChild)
f.pageBar = CreateFrame("Frame", nil, f)
f.pageBar:SetPoint("BOTTOMLEFT", PAD, 10)
f.pageBar:SetPoint("BOTTOMRIGHT", -PAD, 10)
f.pageBar:SetHeight(22)
f.pageBar.prev = CreateFrame("Button", nil, f.pageBar)
f.pageBar.prev:SetSize(24, 24)
f.pageBar.prev:SetPoint("LEFT", 0, 0)
f.pageBar.prev:SetNormalTexture("Interface\\Buttons\\UI-SpellbookIcon-PrevPage-Up")
f.pageBar.prev:SetPushedTexture("Interface\\Buttons\\UI-SpellbookIcon-PrevPage-Down")
f.pageBar.prev:SetDisabledTexture("Interface\\Buttons\\UI-SpellbookIcon-PrevPage-Disabled")
f.pageBar.prev:SetScript("OnClick", function()
SetRecipePage(GetRecipePage() - 1)
if mainFrame and mainFrame:IsShown() then
local char = ns.CharDB and ns.CharDB:GetChar(selectedChar)
RebuildRecipeList(mainFrame, char)
end
end)
f.pageBar.next = CreateFrame("Button", nil, f.pageBar)
f.pageBar.next:SetSize(24, 24)
f.pageBar.next:SetPoint("LEFT", f.pageBar.prev, "RIGHT", 4, 0)
f.pageBar.next:SetNormalTexture("Interface\\Buttons\\UI-SpellbookIcon-NextPage-Up")
f.pageBar.next:SetPushedTexture("Interface\\Buttons\\UI-SpellbookIcon-NextPage-Down")
f.pageBar.next:SetDisabledTexture("Interface\\Buttons\\UI-SpellbookIcon-NextPage-Disabled")
f.pageBar.next:SetScript("OnClick", function()
SetRecipePage(GetRecipePage() + 1)
if mainFrame and mainFrame:IsShown() then
local char = ns.CharDB and ns.CharDB:GetChar(selectedChar)
RebuildRecipeList(mainFrame, char)
end
end)
f.pageBar.label = f.pageBar:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
f.pageBar.label:SetPoint("LEFT", f.pageBar.next, "RIGHT", 10, 0)
f.pageBar.label:SetText("Page 1 / 1")
mainFrame = f
return f
end
local function GetCharTab(i, parent)
local tab = charTabs[i]
if tab then
return tab
end
tab = CreateFrame("Button", "ProfessionMasterCharTab" .. i, parent, "BackdropTemplate")
tab:EnableMouse(true)
tab:RegisterForClicks("AnyUp")
tab:SetBackdrop(CHIP_BACKDROP)
tab:SetBackdropColor(0.08, 0.07, 0.06, 1)
tab:SetBackdropBorderColor(THEME.insetBorder[1], THEME.insetBorder[2], THEME.insetBorder[3], 1)
tab:SetWidth(SIDEBAR_W - 40)
tab.icon = tab:CreateTexture(nil, "ARTWORK")
tab.icon:SetPoint("LEFT", 6, 0)
tab.name = tab:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
tab.name:SetPoint("LEFT", tab.icon, "RIGHT", 6, 0)
tab.name:SetPoint("RIGHT", -6, 0)
tab.name:SetJustifyH("LEFT")
tab.name:SetWordWrap(false)
tab.selectedGlow = tab:CreateTexture(nil, "OVERLAY")
tab.selectedGlow:SetTexture("Interface\\Buttons\\CheckButtonHilight")
tab.selectedGlow:SetBlendMode("ADD")
tab.selectedGlow:SetAllPoints()
tab.selectedGlow:SetAlpha(0.45)
tab.selectedGlow:Hide()
tab.highlight = tab:CreateTexture(nil, "HIGHLIGHT")
tab.highlight:SetTexture("Interface\\Buttons\\ButtonHilight-Square")
tab.highlight:SetBlendMode("ADD")
tab.highlight:SetAllPoints()
charTabs[i] = tab
return tab
end
local function GetProfChip(i, host)
local chip = profChips[i]
if chip then
return chip
end
chip = CreateFrame("Button", nil, host, "BackdropTemplate")
chip:SetSize(96, 48)
chip:SetBackdrop(CHIP_BACKDROP)
chip.icon = chip:CreateTexture(nil, "ARTWORK")
chip.icon:SetSize(22, 22)
chip.icon:SetPoint("TOP", 0, -4)
chip.text = chip:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
chip.text:SetPoint("TOP", chip.icon, "BOTTOM", 0, -2)
chip.text:SetPoint("LEFT", 2, 0)
chip.text:SetPoint("RIGHT", -2, 0)
chip.text:SetJustifyH("CENTER")
chip.text:SetWordWrap(false)
chip:SetScript("OnClick", function(self)
if not self.profKey then
return
end
if selectedProf ~= self.profKey then
ResetRecipePage()
end
selectedProf = self.profKey
UI:Refresh()
end)
profChips[i] = chip
return chip
end
local function RebuildCharTabs(f)
local keys = ns.CharDB:SortedCharKeys()
if #keys == 0 and ns.CharDB.ScanPlayer then
ns.CharDB:ScanPlayer()
keys = ns.CharDB:SortedCharKeys()
end
if #keys == 0 then
selectedChar = nil
elseif not selectedChar then
local me = ns.PlayerKey()
local found
for _, key in ipairs(keys) do
if key == me then
found = me
break
end
end
selectedChar = found or keys[1]
else
local still = false
for _, key in ipairs(keys) do
if key == selectedChar then
still = true
break
end
end
if not still then
selectedChar = keys[1]
end
end
local size = TabSize()
local rowH = math.max(SIDEBAR_ROW_H, size + 8)
local y = 0
local parent = f.sidebarContent or f
for i = 1, math.max(#keys, #charTabs) do
local tab = GetCharTab(i, parent)
local key = keys[i]
if key then
local char = ns.CharDB:GetChar(key)
local classFile = ClassFileOf(char)
local r, g, b = ClassRGB(classFile)
local selected = key == selectedChar
tab.charKey = key
tab:SetHeight(rowH)
tab.icon:SetSize(size, size)
SetClassIcon(tab.icon, classFile, false)
tab.name:SetText(ShortCharName(key, char))
tab.name:SetTextColor(r, g, b)
tab:ClearAllPoints()
tab:SetPoint("TOPLEFT", parent, "TOPLEFT", 0, -y)
tab:SetPoint("TOPRIGHT", parent, "TOPRIGHT", 0, -y)
y = y + rowH + SIDEBAR_GAP
if selected then
tab:SetBackdropColor(0.10, 0.16, 0.28, 1)
tab:SetBackdropBorderColor(0.45, 0.70, 1.0, 1)
tab.selectedGlow:Show()
else
tab:SetBackdropColor(0.08, 0.07, 0.06, 1)
tab:SetBackdropBorderColor(THEME.insetBorder[1], THEME.insetBorder[2], THEME.insetBorder[3], 1)
tab.selectedGlow:Hide()
end
tab:SetScript("OnClick", function()
SelectChar(key)
end)
tab:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:AddLine(ShortCharName(key, char), r, g, b)
GameTooltip:AddLine(key, 0.65, 0.65, 0.65)
if char and char.professions then
for _, p in ipairs(ns.Professions) do
local sk = char.professions[p.key]
if sk and sk > 0 then
GameTooltip:AddLine(string.format("%s %d", p.label, sk), 0.85, 0.85, 0.85)
end
end
else
GameTooltip:AddLine("No professions scanned", 0.6, 0.6, 0.6)
end
GameTooltip:AddLine("Click to browse this character's recipes.", 0.55, 0.75, 1)
GameTooltip:Show()
end)
tab:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
tab:Show()
else
tab:Hide()
end
end
if f.sidebarContent then
f.sidebarContent:SetHeight(math.max(1, y))
end
end
local function RebuildProfChips(f, char)
for _, chip in ipairs(profChips) do
chip:Hide()
end
local host = f.chipHost or (f.charPanel and f.charPanel.chipHost)
if not host or not char or not char.professions then
return
end
local chipW, chipH, chipGap = 96, 48, 8
local chipX, chipY = 0, 0
local hostW = host:GetWidth()
if not hostW or hostW < 50 then
hostW = 520
end
local idx = 0
for _, p in ipairs(ns.Professions) do
local skill = char.professions[p.key]
if skill and skill > 0 then
idx = idx + 1
local chip = GetProfChip(idx, host)
chip.profKey = p.key
chip.text:SetText(p.label)
chip.icon:SetTexture(PROF_ICONS[p.key] or "Interface\\Icons\\INV_Misc_QuestionMark")
chip.icon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
if chipX > 0 and (chipX + chipW) > hostW then
chipX = 0
chipY = chipY - (chipH + chipGap)
end
chip:ClearAllPoints()
chip:SetPoint("TOPLEFT", host, "TOPLEFT", chipX, chipY)
chipX = chipX + chipW + chipGap
if p.key == selectedProf then
chip:SetBackdropColor(0.18, 0.16, 0.10, 1)
chip:SetBackdropBorderColor(0.95, 0.75, 0.20, 1)
chip.text:SetTextColor(1, 0.90, 0.55)
else
chip:SetBackdropColor(0.14, 0.14, 0.16, 1)
chip:SetBackdropBorderColor(THEME.chipOffBorder[1], THEME.chipOffBorder[2], THEME.chipOffBorder[3], 1)
chip.text:SetTextColor(0.85, 0.85, 0.85)
end
chip:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_TOP")
GameTooltip:AddLine(p.label, 1, 0.82, 0)
GameTooltip:AddLine(string.format("Skill %d", skill), 0.85, 0.85, 0.85)
GameTooltip:AddLine("Click to show recipes for this profession.", 0.55, 0.75, 1)
GameTooltip:Show()
end)
chip:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
chip:Show()
end
end
end
local function EnsureRow(i, parent)
local row = recipeRows[i]
if row then
return row
end
row = CreateFrame("Button", nil, parent, "BackdropTemplate")
row:SetHeight(36)
row:SetBackdrop(ROW_BACKDROP)
row:SetBackdropColor(THEME.row[1], THEME.row[2], THEME.row[3], THEME.row[4])
row:SetBackdropBorderColor(THEME.rowBorder[1], THEME.rowBorder[2], THEME.rowBorder[3], THEME.rowBorder[4])
local iconBtn = CreateFrame("Button", nil, row)
iconBtn:SetSize(28, 28)
iconBtn:SetPoint("LEFT", 6, 0)
iconBtn:EnableMouse(true)
row.icon = iconBtn:CreateTexture(nil, "ARTWORK")
row.icon:SetAllPoints()
row.icon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
row.iconBtn = iconBtn
row.title = row:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
row.title:SetPoint("LEFT", iconBtn, "RIGHT", 8, 6)
row.title:SetPoint("RIGHT", -90, 6)
row.title:SetJustifyH("LEFT")
row.title:SetWordWrap(false)
row.sub = row:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
row.sub:SetPoint("LEFT", iconBtn, "RIGHT", 8, -8)
row.sub:SetPoint("RIGHT", -90, -8)
row.sub:SetJustifyH("LEFT")
row.sub:SetWordWrap(false)
row.craftBtn = CreateFrame("Button", nil, row, "UIPanelButtonTemplate")
row.craftBtn:SetSize(70, 22)
row.craftBtn:SetPoint("RIGHT", -8, 0)
row.craftBtn:SetText("Craft")
row.craftBtn:SetScript("OnClick", function(self)
local parentRow = self:GetParent()
if parentRow.recipeId and ns.Craft then
local num = 1
if IsShiftKeyDown() then
num = parentRow.craftable or 1
end
ns.Craft:CraftRecipe(parentRow.recipeId, num)
end
end)
iconBtn:SetScript("OnEnter", function(self)
local parentRow = self:GetParent()
if parentRow and parentRow.recipe then
ShowRecipeTooltip(self, parentRow.recipe, "ANCHOR_RIGHT")
end
end)
iconBtn:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
row:SetScript("OnEnter", function(self)
if not self.recipe then
return
end
ShowRecipeTooltip(self, self.recipe, "ANCHOR_RIGHT")
end)
row:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
recipeRows[i] = row
return row
end
local function FilterEnabled(key, defaultOn)
if not ns.db or not ns.db.settings then
return defaultOn
end
local v = ns.db.settings[key]
if v == nil then
return defaultOn
end
return v and true or false
end
local function RecipeMatchesSearch(recipe, query)
if not query or query == "" then
return true
end
local q = string.lower(query)
local name = recipe and recipe.name
if type(name) == "string" and string.find(string.lower(name), q, 1, true) then
return true
end
if recipe and recipe.itemId and string.find(tostring(recipe.itemId), q, 1, true) then
return true
end
if recipe and type(recipe.reagents) == "table" then
for i = 1, #recipe.reagents do
local rg = recipe.reagents[i]
local itemId = ns.RecipeDB.ReagentItemId(rg)
if itemId and string.find(tostring(itemId), q, 1, true) then
return true
end
local rname = ns.RecipeDB:ItemName(itemId)
if type(rname) == "string" and string.find(string.lower(rname), q, 1, true) then
return true