Repository navigation
Expand file tree
/
Copy pathPlanner.lua
More file actions
1582 lines (1499 loc) · 57.3 KB
/
Copy pathPlanner.lua
File metadata and controls
1582 lines (1499 loc) · 57.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
-- ASBuilder planner: the window where builds are made. Left: your builds. Middle: the class
-- and every spell and piece of jewelry as icons; a click adds or removes one. Right: what
-- you picked, in priority order, with a target rank each, and your notes.
local AB = ASBuilder
local W = AB.W
local T = AB.T
local P = { selected = nil, offset = 0, variant = 1 }
AB.Planner = P
local FW, FH = 1040, 600
local VY = 32 -- the stage bar sits above the editor and the priority list
local LIST_ROWS = 18
local PRIO_ROWS = 9
local CELL, ICON, PER_ROW = 29, 26, 10
local MAX_TARGET = 30
local frame
local labels = {}
local function L(obj, key)
table.insert(labels, { obj, key })
if obj.SetLabel then obj:SetLabel(T(key)) else obj:SetText(T(key)) end
return obj
end
-- re-applies the static labels after the language changed
function P.Relabel()
for i = 1, table.getn(labels) do
local o, key = labels[i][1], labels[i][2]
if o.SetLabel then o:SetLabel(T(key)) else o:SetText(T(key)) end
end
end
local function Err(msg)
UIErrorsFrame:AddMessage(msg, 1, 0.3, 0.3, 1, 3)
end
-- The planner edits a draft: a copy of the selected build. Save writes it back; picking
-- another build throws unsaved changes away, so the build stays as it was last saved.
local function Saved()
local b = AB.GetBuild(P.selected)
if not b then
b = AB.Builds()[1]
P.selected = b and b.id or nil
end
return b
end
local function Draft()
local s = Saved()
if not s then P.draft = nil; return nil end
if not P.draft or P.draft.id ~= s.id then P.draft = AB.CloneBuild(s) end
return P.draft
end
-- the stage being edited, as a view (its picks are the draft's own list)
local function Selected()
local d = Draft()
if not d then return nil end
if not d.variants[P.variant] then P.variant = 1 end
return AB.View(d, P.variant)
end
function P.Select(id)
if P.draft and P.draft.id ~= id and AB.IsDirty(P.draft) then
local s = AB.GetBuild(P.draft.id)
if s then AB.Print(T("Unsaved changes to \"%s\" were discarded.", s.name)) end
end
if not P.draft or P.draft.id ~= id then P.draft = nil; P.variant = 1 end
P.selected = id
if P.nameEdit then P.nameEdit:ClearFocus() end
end
local function Changed()
P.Refresh()
if AB.RefreshTracker then AB.RefreshTracker() end
end
-- ---------------------------------------------------------------- builds list (left)
local function BuildList(f)
local head = W.Text(f, "GameFontNormal")
head:SetPoint("TOPLEFT", f, "TOPLEFT", 14, -44)
L(head, "Builds")
-- move the selected build up or down the list (the order is only local: no rev bump, nothing to sync)
local function Move(step)
local list, at = AB.Builds(), nil
for i = 1, table.getn(list) do
if list[i].id == P.selected then at = i end
end
local to = at and at + step
if not to or to < 1 or to > table.getn(list) then return end
list[at], list[to] = list[to], list[at]
if to <= P.offset then P.offset = to - 1 end
if to > P.offset + LIST_ROWS then P.offset = to - LIST_ROWS end
P.RefreshList()
end
local function MoveButton(step, x, tex, tip)
local m = W.Button(f, "", 20, 18)
m:SetPoint("TOPLEFT", f, "TOPLEFT", x, -40)
m.arrow = m:CreateTexture(nil, "OVERLAY")
m.arrow:SetTexture(tex)
m.arrow:SetWidth(18)
m.arrow:SetHeight(18)
m.arrow:SetPoint("CENTER", m, "CENTER", 0, 0)
m:SetScript("OnClick", function() Move(step) end)
W.Tip(m, function(self, tt) tt:SetText(T(tip), 1, 1, 1) end)
return m
end
P.bUp = MoveButton(-1, 142, "Interface\\Buttons\\UI-ScrollBar-ScrollUpButton-Up", "Move up")
P.bDown = MoveButton(1, 166, "Interface\\Buttons\\UI-ScrollBar-ScrollDownButton-Up", "Move down")
local area = CreateFrame("Frame", nil, f)
area:SetPoint("TOPLEFT", f, "TOPLEFT", 12, -62)
area:SetWidth(176)
area:SetHeight(LIST_ROWS * 22)
W.Panel(area, 0.6, 0.16)
area:EnableMouseWheel(true)
area:SetScript("OnMouseWheel", function()
local n = table.getn(AB.Builds())
P.offset = P.offset - (arg1 or 0)
if P.offset > n - LIST_ROWS then P.offset = n - LIST_ROWS end
if P.offset < 0 then P.offset = 0 end
P.RefreshList()
end)
P.rows = {}
for i = 1, LIST_ROWS do
local r = CreateFrame("Button", nil, area)
r:SetWidth(172)
r:SetHeight(21)
r:SetPoint("TOPLEFT", area, "TOPLEFT", 2, -2 - (i - 1) * 22)
r.sel = r:CreateTexture(nil, "BACKGROUND")
r.sel:SetTexture(W.FLAT)
r.sel:SetAllPoints(r)
r.sel:SetVertexColor(0.3, 0.55, 1, 0.22)
W.Hover(r, 0.07)
r.icon = r:CreateTexture(nil, "ARTWORK")
r.icon:SetWidth(15)
r.icon:SetHeight(15)
r.icon:SetPoint("LEFT", r, "LEFT", 4, 0)
r.icon:SetTexCoord(0.07, 0.93, 0.07, 0.93)
r.name = W.Text(r, "GameFontHighlightSmall")
r.name:SetPoint("LEFT", r.icon, "RIGHT", 6, 0)
r.name:SetWidth(122)
r.name:SetHeight(12)
r.active = r:CreateTexture(nil, "OVERLAY")
r.active:SetTexture("Interface\\Buttons\\UI-CheckBox-Check")
r.active:SetWidth(16)
r.active:SetHeight(16)
r.active:SetPoint("RIGHT", r, "RIGHT", -2, 0)
r.active:SetVertexColor(0.35, 1, 0.35)
r:SetScript("OnClick", function()
if this.buildId then
P.Select(this.buildId)
P.Refresh()
end
end)
W.Tip(r, function(self, tt)
local b = AB.GetBuild(self.buildId)
if not b then return end
local c = AB.ClassInfo(b.class)
tt:SetText(b.name, AB.ClassRGB(b.class))
tt:AddLine(c and AB.N(c.name) or b.class, 0.7, 0.7, 0.7)
if ASBuilderDB.active[b.class] == b.id then tt:AddLine(T("Active"), 0.35, 1, 0.35) end
for vi = 1, table.getn(b.variants) do
local v = b.variants[vi]
local n = table.getn(v.picks)
if n > 0 then tt:AddLine(AB.N(v.name) .. ": " .. n .. " " .. T("picks"), 0.8, 0.8, 0.8) end
end
end)
P.rows[i] = r
end
P.empty = W.Text(area, "GameFontDisableSmall", "CENTER")
P.empty:SetPoint("CENTER", area, "CENTER", 0, 0)
P.empty:SetWidth(160)
L(P.empty, "No builds yet. Press New.")
local bNew = W.Button(f, "", 56, 22)
bNew:SetPoint("BOTTOMLEFT", f, "BOTTOMLEFT", 12, 68)
L(bNew, "New")
bNew:SetScript("OnClick", function()
local b = AB.NewBuild(AB.CurrentClass())
P.Select(b.id)
local n = table.getn(AB.Builds())
if n > LIST_ROWS then P.offset = n - LIST_ROWS end
Changed()
P.nameEdit:SetFocus()
P.nameEdit:HighlightText()
end)
local bCopy = W.Button(f, "", 56, 22)
bCopy:SetPoint("LEFT", bNew, "RIGHT", 4, 0)
L(bCopy, "Copy")
bCopy:SetScript("OnClick", function()
local d = Draft()
if not d then return end
local nb = AB.CopyBuild(d)
P.draft = nil
P.Select(nb.id)
Changed()
end)
P.bCopy = bCopy
local bDel = W.Button(f, "", 56, 22)
bDel:SetPoint("LEFT", bCopy, "RIGHT", 4, 0)
L(bDel, "Delete")
bDel:SetScript("OnClick", function()
local b = Selected()
if not b then return end
P.pendingDelete = b.id
StaticPopup_Show("ASBUILDER_DELETE", T("Delete build \"%s\"?", Saved().name))
end)
P.bDel = bDel
local bImp = W.Button(f, "", 176, 22)
bImp:SetPoint("BOTTOMLEFT", f, "BOTTOMLEFT", 12, 12)
L(bImp, "Import")
bImp:SetScript("OnClick", function() P.ShowCode("import") end)
-- every build in one code, for the website (and back)
local bAll = W.Button(f, "", 176, 22)
bAll:SetPoint("BOTTOMLEFT", f, "BOTTOMLEFT", 12, 40)
L(bAll, "Export all builds")
bAll:SetScript("OnClick", function() P.ShowCode("export", AB.ExportProfile()) end)
W.Tip(bAll, function(self, tt)
tt:SetText(T("Export all builds"), 1, 0.82, 0)
tt:AddLine(T("One code with every build, to paste on the website. Import takes the website's code back."), 0.8, 0.8, 0.8, 1)
end)
P.always = W.Check(f, "", function(on)
ASBuilderDB.tracker.mode = on and "always" or "run"
if AB.RefreshTracker then AB.RefreshTracker() end
end)
P.always:SetPoint("BOTTOMLEFT", f, "BOTTOMLEFT", 14, 100)
L(P.always.text, "Show tracker outside runs")
end
function P.RefreshList()
local list = AB.Builds()
local n = table.getn(list)
if P.offset > n - LIST_ROWS then P.offset = math.max(0, n - LIST_ROWS) end
for i = 1, LIST_ROWS do
local r = P.rows[i]
local b = list[i + P.offset]
if b then
r.buildId = b.id
r.icon:SetTexture(AB.Icon(AB.CLASS_ICON[b.class]))
local shown = b
if P.draft and P.draft.id == b.id then shown = P.draft end
r.name:SetText(shown.name .. ((shown ~= b and AB.IsDirty(P.draft)) and " |cffff9933*|r" or ""))
r.name:SetTextColor(AB.ClassRGB(shown.class))
r.icon:SetTexture(AB.Icon(AB.CLASS_ICON[shown.class]))
if b.id == P.selected then r.sel:Show() else r.sel:Hide() end
if ASBuilderDB.active[b.class] == b.id then r.active:Show() else r.active:Hide() end
r:Show()
else
r.buildId = nil
r:Hide()
end
end
if n == 0 then P.empty:Show() else P.empty:Hide() end
end
-- ---------------------------------------------------------------- editor (middle)
-- as many icons as the game data has (it comes from the game, so new pieces show up here)
local function MostSpells()
local n = 0
for i = 1, table.getn(ASBuilder_Data.classes) do
n = math.max(n, table.getn(ASBuilder_Data.classes[i].spells))
end
return n
end
local SECTIONS = {
{ kind = "spell", label = "Spells", count = MostSpells() },
{ kind = "ring", label = "Rings", count = table.getn(ASBuilder_Data.rings) },
{ kind = "trinket", label = "Trinkets", count = table.getn(ASBuilder_Data.trinkets) },
{ kind = "amulet", label = "Amulet", count = table.getn(ASBuilder_Data.amulets) },
{ kind = "legend", label = "Legendary amulet", count = MostSpells() },
}
-- the picks a section offers for a class, as { t, k } in the data's order
local function Offers(kind, cls, b)
local D, out = ASBuilder_Data, {}
if kind == "spell" or kind == "legend" then
local c = AB.ClassInfo(cls)
if c then
for i = 1, table.getn(c.spells) do
local sp = c.spells[i]
if kind == "spell" or sp.amulet then
table.insert(out, { t = kind, k = sp.key })
end
end
end
elseif kind == "ring" then
for i = 1, table.getn(D.rings) do table.insert(out, { t = "ring", k = D.rings[i].name }) end
elseif kind == "trinket" then
for i = 1, table.getn(D.trinkets) do table.insert(out, { t = "trinket", k = D.trinkets[i].name }) end
elseif kind == "amulet" then
for i = 1, table.getn(D.amulets) do table.insert(out, { t = "amulet", k = D.amulets[i].name }) end
end
return out
end
function P.PaletteTip(self, tt)
local b = Selected()
if not b or not self.pick then return end
AB.FillTooltip(tt, b.class, self.pick)
tt:AddLine(" ")
local idx = AB.FindPick(b, self.pick.t, self.pick.k)
local p = idx and b.picks[idx]
if p and p.ban then
tt:AddLine(T("Will be banished"), 1, 0.3, 0.3)
tt:AddLine(T("Click: remove from the build"), 1, 0.5, 0.5)
tt:AddLine(T("Right-click: take it instead"), 0.5, 1, 0.5)
elseif p then
if p.alt then tt:AddLine(T("Alternative"), 0.5, 0.75, 1) end
tt:AddLine(T("Click: remove from the build"), 1, 0.5, 0.5)
if p.t == "spell" then tt:AddLine(T("Right-click: banish this spell"), 1, 0.5, 0.5) end
else
tt:AddLine(T("Click: add to the build"), 0.5, 1, 0.5)
if self.pick.t == "spell" then tt:AddLine(T("Right-click: banish this spell"), 1, 0.5, 0.5) end
end
end
local function Editor(f)
local ed = CreateFrame("Frame", nil, f)
ed:SetAllPoints(f)
P.ed = ed
local nl = W.Text(ed, "GameFontNormalSmall")
nl:SetPoint("TOPLEFT", f, "TOPLEFT", 200, -44 - VY)
L(nl, "Name")
P.dirtyText = W.Text(ed, "GameFontHighlightSmall", "RIGHT")
P.dirtyText:SetPoint("TOPRIGHT", f, "TOPLEFT", 500, -44 - VY)
P.dirtyText:SetTextColor(1, 0.6, 0.2)
local ne = W.Edit(ed, "ASBuilderNameEdit", 300, 22)
ne:SetPoint("TOPLEFT", f, "TOPLEFT", 200, -58 - VY)
ne:SetScript("OnTextChanged", function()
if P.filling then return end
local d = Draft()
if not d then return end
local t = this:GetText() or ""
if t == "" then return end
d.name = t
P.RefreshDirty()
if AB.RefreshTracker then AB.RefreshTracker() end
end)
ne:SetScript("OnEditFocusLost", function()
local d = Draft()
if d and (this:GetText() or "") == "" then this:SetText(d.name) end
end)
P.nameEdit = ne
-- the class row
P.classBtns = {}
local classes = ASBuilder_Data.classes
for i = 1, table.getn(classes) do
local c = classes[i]
local cb = W.Slot(ed, 24)
cb:SetPoint("TOPLEFT", f, "TOPLEFT", 200 + (i - 1) * 27, -89 - VY)
cb.icon:SetTexture(AB.Icon(AB.CLASS_ICON[c.key]))
cb.classKey = c.key
cb:SetScript("OnClick", function()
local d = Draft()
if not d or d.class == this.classKey then return end
AB.SetClass(d, this.classKey)
Changed()
end)
W.Tip(cb, function(self, tt)
local ci = AB.ClassInfo(self.classKey)
tt:SetText(AB.N(ci.name), AB.ClassRGB(self.classKey))
end)
P.classBtns[i] = cb
end
P.className = W.Text(ed, "GameFontNormalSmall")
P.className:SetPoint("LEFT", P.classBtns[table.getn(classes)], "RIGHT", 6, 0)
-- the icon palette
P.sections = {}
for s = 1, table.getn(SECTIONS) do
local sec = { def = SECTIONS[s], slots = {} }
sec.label = W.Text(ed, "GameFontNormalSmall")
for i = 1, sec.def.count do
local sl = W.Slot(ed, ICON)
sl.badge = sl:CreateTexture(nil, "OVERLAY")
sl.badge:SetWidth(12)
sl.badge:SetHeight(12)
sl.badge:SetPoint("BOTTOMLEFT", sl, "BOTTOMLEFT", 1, 1)
sl.badge:SetTexCoord(0.07, 0.93, 0.07, 0.93)
if sec.def.kind == "spell" then sl:RegisterForClicks("LeftButtonUp", "RightButtonUp") end
sl:SetScript("OnClick", function()
local self, button = this, arg1
local b = Selected()
if not b or not self.pick then return end
local ok, msg
local idx = AB.FindPick(b, self.pick.t, self.pick.k)
if button == "RightButton" then
-- right-click a spell: mark it to banish (or back to take)
if idx then ok, msg = AB.ToggleBan(b, idx) else ok, msg = AB.TogglePick(b, self.pick.t, self.pick.k, true) end
else
ok, msg = AB.TogglePick(b, self.pick.t, self.pick.k)
end
if not ok and msg then Err(msg) end
-- show the tab of what was just changed
P.tab = AB.GROUP[self.pick.t]
Changed()
local tt = W.Tooltip()
if self:IsVisible() and tt.IsOwned and tt:IsOwned(self) then
W.TipOwner(self)
P.PaletteTip(self, tt)
tt:Show()
end
end)
W.Tip(sl, function(self, tt) P.PaletteTip(self, tt) end)
sec.slots[i] = sl
end
P.sections[s] = sec
end
end
local function RefreshPalette(b)
local y = -124 - VY
for s = 1, table.getn(P.sections) do
local sec = P.sections[s]
local kind = sec.def.kind
local group = AB.GROUP[kind]
local offers = Offers(kind, b.class, b)
local have, max = AB.CountGroup(b, group), AB.MAX[group]
local full = have >= max
local label = T(sec.def.label)
if kind ~= "legend" then
local col = full and "|cff55ff55" or "|cffaaaaaa"
label = label .. " " .. col .. have .. "/" .. max .. "|r"
if AB.ALTS[group] then label = label .. " |cff888888(" .. T("%d main + %d alternatives", AB.MAIN[group], AB.ALTS[group]) .. ")|r" end
end
if kind == "spell" and AB.CountBans(b) > 0 then
label = label .. " |cffff5555" .. T("Banish") .. " " .. AB.CountBans(b) .. "/" .. AB.MAX_BAN .. "|r"
end
-- each pick's place within its own tab
local place = {}
local tabIdx = AB.TabIndices(b, group)
for t = 1, table.getn(tabIdx) do place[tabIdx[t]] = t end
sec.label:SetText(label)
sec.label:ClearAllPoints()
sec.label:SetPoint("TOPLEFT", frame, "TOPLEFT", 201, y)
y = y - 14
local n = table.getn(offers)
for i = 1, sec.def.count do
local sl = sec.slots[i]
local p = offers[i]
if p then
local info = AB.Info(b.class, p)
sl.pick = p
sl.icon:SetTexture(AB.Icon(info and info.icon))
local idx = AB.FindPick(b, p.t, p.k)
if idx and b.picks[idx].ban then
sl:SetPicked(false)
sl:SetBanned()
elseif idx and b.picks[idx].alt then
sl:SetPicked(false)
sl:SetAlt()
else
sl:SetPicked(idx ~= nil, idx and place[idx])
-- a full group dims what cannot be added
if not idx then sl:SetDim(full) end
end
if kind == "legend" then
sl.badge:SetTexture(AB.Icon(info.spell.icon))
sl.badge:Show()
else
sl.badge:Hide()
end
local row, col = math.floor((i - 1) / PER_ROW), math.mod(i - 1, PER_ROW)
sl:ClearAllPoints()
sl:SetPoint("TOPLEFT", frame, "TOPLEFT", 200 + col * CELL, y - row * CELL)
sl:Show()
else
sl.pick = nil
sl:Hide()
end
end
y = y - math.ceil(n / PER_ROW) * CELL - 6
end
end
-- ---------------------------------------------------------------- priority list (right)
-- One tab per slot group, each with its own priority order. Spells can be marked to banish.
local TABS = {
{ group = "spell", label = "Spells" },
{ group = "ring", label = "Rings" },
{ group = "trinket", label = "Trinkets" },
{ group = "amulet", label = "Amulet" },
}
P.tab = "spell"
-- a jewelry row's typed target: field "r" (its first stat) or "r2" (an amulet's second stat)
local function ValueBox(r, name, field)
local e = W.Edit(r, name, 40, 18)
e:SetMaxLetters(5)
e:SetTextInsets(4, 4, 0, 0)
if e.SetJustifyH then e:SetJustifyH("RIGHT") end
e.hint = W.Text(e, "GameFontDisableSmall", "CENTER")
e.hint:SetAllPoints(e)
e.hint:SetText((field == "r2") and "-" or T("max"))
e:SetScript("OnTextChanged", function()
local t = this:GetText() or ""
if t == "" then this.hint:Show() else this.hint:Hide() end
if P.filling then return end
local b = Selected()
local p = b and r.pi and b.picks[r.pi]
if not p then return end
local n = tonumber((string.gsub(t, ",", ".")))
p[field] = (n and n > 0) and n or 0
P.RefreshDirty()
end)
e:SetScript("OnEditFocusGained", function() this.focus = true; this:HighlightText() end)
e:SetScript("OnEditFocusLost", function() this.focus = false; P.Refresh() end)
W.Tip(e, function(self, tt)
local b = Selected()
local p = b and r.pi and b.picks[r.pi]
local info = p and AB.Info(b.class, p)
local stat = info and p.t ~= "legend" and ((field == "r2") and AB.StatTemplate2(info) or AB.StatTemplate(info))
tt:SetText(T("Target value"), 1, 0.82, 0)
if stat then tt:AddLine((string.gsub(stat, "{v}", "x")), 0.5, 1, 0.5) end
tt:AddLine(T("What this piece should give before the build moves on, read live from its tooltip: 30 for -30% cooldowns, 4.5 for +4.5 health per second."), 0.8, 0.8, 0.8, 1)
if field == "r2" then
tt:AddLine(T("Empty: no target for this stat."), 0.6, 0.6, 0.6, 1)
else
tt:AddLine(T("Empty: keep upgrading it whenever it is offered."), 0.6, 0.6, 0.6, 1)
end
end)
return e
end
local function Priority(f)
local ed = P.ed
P.tabs = {}
for i = 1, table.getn(TABS) do
local tb = W.Button(ed, "", 72, 22)
tb:SetPoint("TOPLEFT", f, "TOPLEFT", 512 + (i - 1) * 74, -40 - VY)
L(tb, TABS[i].label)
tb.group = TABS[i].group
tb:SetScript("OnClick", function()
P.tab = this.group
P.Refresh()
end)
W.Tip(tb, function(self, tt)
tt:SetText(T(AB.GROUP_LABEL[self.group]), 1, 0.82, 0)
tt:AddLine(T("Top = most important"), 0.8, 0.8, 0.8)
if self.group == "spell" then tt:AddLine(T("Please list spells for upgrade priority"), 0.8, 0.8, 0.8) end
end)
P.tabs[i] = tb
end
P.tabCount = W.Text(ed, "GameFontHighlightSmall")
P.tabCount:SetPoint("TOPLEFT", f, "TOPLEFT", 514, -70 - VY)
-- empties the open tab, in the stage being edited
P.clearBtn = W.Button(ed, "", 56, 18)
P.clearBtn:SetPoint("TOPRIGHT", f, "TOPLEFT", 808, -66 - VY)
L(P.clearBtn, "Clear")
P.clearBtn:SetScript("OnClick", function()
local b = Selected()
if b and AB.ClearGroup(b, P.tab or "spell") > 0 then Changed() end
end)
W.Tip(P.clearBtn, function(self, tt)
local b = Selected()
local group = P.tab or "spell"
tt:SetText(T("Clear"), 1, 0.82, 0)
tt:AddLine(T("Removes every pick of the %s tab from %s.", T(AB.GROUP_LABEL[group]), b and AB.N(b.variant.name) or ""), 0.8, 0.8, 0.8, 1)
if group == "spell" then tt:AddLine(T("Spells marked to banish go too."), 0.6, 0.6, 0.6, 1) end
tt:AddLine(T("Not saved until you press Save."), 0.6, 0.6, 0.6, 1)
end)
P.prio = {}
for i = 1, PRIO_ROWS do
local r = CreateFrame("Frame", nil, ed)
r:SetWidth(296)
r:SetHeight(24)
r:SetPoint("TOPLEFT", f, "TOPLEFT", 512, -86 - VY - (i - 1) * 26)
r.bg = r:CreateTexture(nil, "BACKGROUND")
r.bg:SetTexture(W.FLAT)
r.bg:SetAllPoints(r)
r.num = W.Text(r, "GameFontDisableSmall", "RIGHT")
r.num:SetWidth(18)
r.num:SetPoint("LEFT", r, "LEFT", 0, 0)
r.icon = W.Slot(r, 22)
r.icon:SetPoint("LEFT", r, "LEFT", 22, 0)
r.icon.row = r
W.Tip(r.icon, function(self, tt)
local b = Selected()
local p = b and self.row.pi and b.picks[self.row.pi]
if p then AB.FillTooltip(tt, b.class, p) end
end)
r.name = W.Text(r, "GameFontHighlightSmall")
r.name:SetPoint("LEFT", r, "LEFT", 49, 0)
r.name:SetHeight(12)
local function Target(delta)
local b = Selected()
local p = b and r.pi and b.picks[r.pi]
if not p or p.ban then return end
local v = (p.r or 0) + delta
if v < 0 then v = 0 end
if v > MAX_TARGET then v = MAX_TARGET end
p.r = v
Changed()
end
-- spells only: banish instead of take
r.ban = W.Button(r, "", 38, 18)
r.ban:SetPoint("LEFT", r, "LEFT", 138, 0)
r.ban:SetScript("OnClick", function()
local b = Selected()
if not b or not r.pi then return end
local p = b.picks[r.pi]
local ok, msg
if p and AB.ALTS[AB.GROUP[p.t]] then ok, msg = AB.ToggleAlt(b, r.pi) else ok, msg = AB.ToggleBan(b, r.pi) end
if not ok and msg then Err(msg) end
Changed()
end)
W.Tip(r.ban, function(self, tt)
local b = Selected()
local p = b and r.pi and b.picks[r.pi]
if p and AB.ALTS[AB.GROUP[p.t]] then
local word = ({ ring = "ring", trinket = "trinket" })[AB.GROUP[p.t]] or "amulet"
tt:SetText(T("Alternative"), 0.5, 0.75, 1)
if p.alt then
tt:AddLine(T("An alternative: wearing it fills a %s slot just as well.", word), 0.8, 0.8, 0.8, 1)
tt:AddLine(T("Click: make it a main %s", word), 0.5, 1, 0.5)
else
tt:AddLine(T("A main %s. Click to mark it as an alternative.", word), 0.8, 0.8, 0.8, 1)
end
return
end
tt:SetText(T("Banish"), 1, 0.4, 0.4)
if p and p.ban then
tt:AddLine(T("Will be banished"), 1, 0.3, 0.3)
tt:AddLine(T("Click: take it instead"), 0.5, 1, 0.5)
else
tt:AddLine(T("Mark it to banish: when its card comes up, banish it instead of taking it."), 0.8, 0.8, 0.8, 1)
end
end)
r.banText = W.Text(r, "GameFontHighlightSmall")
r.banText:SetPoint("LEFT", r, "LEFT", 182, 0)
r.banText:SetTextColor(1, 0.35, 0.35)
r.minus = W.IconButton(r, "Interface\\Buttons\\UI-MinusButton-Up", 14)
r.minus:SetPoint("LEFT", r, "LEFT", 180, 0)
r.minus:SetScript("OnClick", function() Target(-1) end)
r.rank = CreateFrame("Button", nil, r)
r.rank:SetWidth(26)
r.rank:SetHeight(18)
r.rank:SetPoint("LEFT", r.minus, "RIGHT", 1, 0)
r.rank.text = W.Text(r.rank, "GameFontHighlightSmall", "CENTER")
r.rank.text:SetAllPoints(r.rank)
r.rank:EnableMouseWheel(true)
r.rank:SetScript("OnMouseWheel", function() Target(arg1 or 0) end)
W.Tip(r.rank, function(self, tt)
tt:SetText(T("Target rank"), 1, 0.82, 0)
tt:AddLine(T("\"max\": keep upgrading it whenever it is offered."), 0.8, 0.8, 0.8, 1)
end)
r.plus = W.IconButton(r, "Interface\\Buttons\\UI-PlusButton-Up", 14)
r.plus:SetPoint("LEFT", r.rank, "RIGHT", 1, 0)
r.plus:SetScript("OnClick", function() Target(1) end)
-- jewelry: the value the piece should give (typed), instead of a rank
r.val = ValueBox(r, "ASBuilderTarget" .. i, "r")
r.val:SetPoint("LEFT", r, "LEFT", 180, 0)
r.unit = W.Text(r, "GameFontHighlightSmall")
r.unit:SetPoint("LEFT", r.val, "RIGHT", 3, 0)
-- an amulet with a second stat: a second box beside the first
r.val2 = ValueBox(r, "ASBuilderTargetB" .. i, "r2")
r.val2:SetPoint("LEFT", r, "LEFT", 210, 0)
r.val2:SetWidth(28)
r.up = W.IconButton(r, "Interface\\Buttons\\UI-ScrollBar-ScrollUpButton-Up", 18)
r.up.tex:SetTexCoord(0.2, 0.8, 0.2, 0.8)
r.up:SetPoint("LEFT", r, "LEFT", 240, 0)
r.up:SetScript("OnClick", function()
local b = Selected()
if b and r.pi then AB.MovePick(b, r.pi, -1); Changed() end
end)
W.Tip(r.up, function(self, tt) tt:SetText(T("Move up")) end)
r.down = W.IconButton(r, "Interface\\Buttons\\UI-ScrollBar-ScrollDownButton-Up", 18)
r.down.tex:SetTexCoord(0.2, 0.8, 0.2, 0.8)
r.down:SetPoint("LEFT", r.up, "RIGHT", 0, 0)
r.down:SetScript("OnClick", function()
local b = Selected()
if b and r.pi then AB.MovePick(b, r.pi, 1); Changed() end
end)
W.Tip(r.down, function(self, tt) tt:SetText(T("Move down")) end)
r.del = W.IconButton(r, "Interface\\Buttons\\UI-Panel-MinimizeButton-Up", 18)
r.del.tex:SetTexCoord(0.18, 0.82, 0.18, 0.82)
r.del:SetPoint("LEFT", r.down, "RIGHT", 2, 0)
r.del:SetScript("OnClick", function()
local b = Selected()
if b and r.pi and b.picks[r.pi] then table.remove(b.picks, r.pi); Changed() end
end)
W.Tip(r.del, function(self, tt) tt:SetText(T("Remove")) end)
P.prio[i] = r
end
P.prioHint = W.Text(ed, "GameFontDisableSmall", "CENTER")
P.prioHint:SetPoint("TOP", f, "TOPLEFT", 512 + 148, -170 - VY)
P.prioHint:SetWidth(260)
local nl = W.Text(ed, "GameFontNormalSmall")
nl:SetPoint("TOPLEFT", f, "TOPLEFT", 512, -364 - VY)
P.notesLabel = nl
P.notes = W.MultiEdit(ed, "ASBuilderNotes", 296, 110, AB.NOTE_MAX)
P.notes:SetPoint("TOPLEFT", f, "TOPLEFT", 512, -378 - VY)
P.notes.edit:SetScript("OnTextChanged", function()
P.notes.scroll:UpdateScrollChildRect()
if P.filling then return end
local d = Draft()
if d then AB.SetNote(d, this:GetText() or ""); P.RefreshDirty() end
end)
-- a link to a picture of the build (talents and so on); addons cannot open a browser,
-- so a click selects it for Ctrl+C
local ll = W.Text(ed, "GameFontNormalSmall")
ll:SetPoint("TOPLEFT", f, "TOPLEFT", 512, -498 - VY)
L(ll, "Image link")
P.link = W.Edit(ed, "ASBuilderLink", 228, 20, GameFontHighlightSmall)
P.link:SetPoint("TOPLEFT", f, "TOPLEFT", 580, -493 - VY)
P.link:SetMaxLetters(255)
P.link:SetScript("OnTextChanged", function()
if P.filling then return end
local d = Draft()
if d then d.link = string.gsub(this:GetText() or "", "%s", ""); P.RefreshDirty() end
end)
P.link:SetScript("OnEditFocusGained", function() this.focus = true; this:HighlightText() end)
P.link:SetScript("OnEditFocusLost", function() this.focus = false; this:HighlightText(0, 0) end)
W.Tip(P.link, function(self, tt)
tt:SetText(T("Image link"), 1, 0.82, 0)
tt:AddLine(T("Paste a picture link (imgur, prnt.sc, Discord) to share your talents with the build."), 0.8, 0.8, 0.8, 1)
tt:AddLine(T("To open it: click the box, press Ctrl+C and paste it into your browser. WoW addons cannot open a browser themselves."), 0.6, 0.6, 0.6, 1)
end)
-- notes and link only change after Edit is pressed (copying always works)
local nlock = W.Lock(P.notes.edit, ed, function() local d = Draft(); return d and d.variants[1] end, "notes",
function() P.RefreshDirty() end)
nlock:SetPoint("BOTTOMRIGHT", P.notes, "TOPRIGHT", 0, 1)
local llock = W.Lock(P.link, ed, Draft, "link", function() P.RefreshDirty() end)
llock:SetPoint("RIGHT", P.link, "RIGHT", -2, 0)
P.link:SetTextInsets(6, 40, 0, 0)
end
local function RefreshPriority(b)
local group = P.tab or "spell"
for i = 1, table.getn(P.tabs) do
local tb = P.tabs[i]
tb:SetSelected(tb.group == group)
end
local have, max = AB.CountGroup(b, group), AB.MAX[group]
local count = T(AB.GROUP_LABEL[group]) .. ": " .. ((have >= max) and "|cff55ff55" or "|cffcccccc") .. have .. "/" .. max .. "|r"
if group == "spell" then
count = count .. " |cffff6666" .. T("Banish") .. ": " .. AB.CountBans(b) .. "/" .. AB.MAX_BAN .. "|r"
elseif AB.ALTS[group] then
local alts = AB.CountAlts(b, group)
count = T(AB.GROUP_LABEL[group]) .. ": " .. (have - alts) .. "/" .. AB.MAIN[group] .. " |cff88bbff" .. T("Alt") .. ": " .. alts .. "/" .. AB.ALTS[group] .. "|r"
end
P.tabCount:SetText(count)
local inTab = 0
for i = 1, table.getn(b.picks) do if AB.GROUP[b.picks[i].t] == group then inTab = inTab + 1 end end
P.clearBtn:SetOn(inTab > 0)
local list = AB.TabIndices(b, group)
local n = table.getn(list)
local takes = AB.CountGroup(b, group)
for i = 1, PRIO_ROWS do
local r = P.prio[i]
local pi = list[i]
local p = pi and b.picks[pi]
if p then
r.pi = pi
local info = AB.Info(b.class, p)
r.icon.icon:SetTexture(AB.Icon(info and info.icon))
r.name:SetText(info and AB.N(info.name) or p.k)
local canAlt = AB.ALTS[AB.GROUP[p.t]] ~= nil
r.name:SetWidth((p.t == "spell" or canAlt) and 86 or 128)
if p.t == "spell" then
r.ban:Show()
r.ban:SetLabel(T("Banish"))
r.ban:SetDanger(p.ban)
elseif canAlt then
r.ban:Show()
r.ban:SetLabel(T("Alt"))
r.ban:SetSelected(p.alt)
if not p.alt then r.ban:SetDanger(false) end
else
r.ban:Hide()
end
if p.ban then
r.num:SetText("")
r.icon:SetBanned()
r.name:SetTextColor(1, 0.45, 0.45)
r.banText:SetText(T("will banish"))
r.banText:Show()
r.minus:Hide(); r.rank:Hide(); r.plus:Hide(); r.val:Hide(); r.unit:Hide(); r.val2:Hide()
r.bg:SetVertexColor(1, 0.2, 0.2, 0.07)
-- banished spells keep their own order below the ones to take
r.up:SetOn(i > takes + 1)
r.down:SetOn(i < n)
else
r.num:SetText(p.alt and "" or (i .. "."))
r.icon:SetPicked(false)
r.icon:SetDim(false)
if p.alt then r.icon:SetAlt() end
if p.t == "legend" then r.name:SetTextColor(1, 0.5, 0)
elseif p.t == "amulet" and info and info.rarity then
local c = AB.RARITY_COLOR[info.rarity]
r.name:SetTextColor(c[1], c[2], c[3])
elseif p.t == "spell" then r.name:SetTextColor(1, 0.82, 0)
else r.name:SetTextColor(1, 1, 1) end
r.banText:Hide()
if p.t == "spell" then
r.val:Hide(); r.unit:Hide(); r.val2:Hide()
r.minus:Show(); r.rank:Show(); r.plus:Show()
if (p.r or 0) == 0 then
r.rank.text:SetText(T("max"))
r.rank.text:SetTextColor(0.6, 0.6, 0.6)
else
r.rank.text:SetText(tostring(p.r))
r.rank.text:SetTextColor(1, 1, 1)
end
r.minus:SetOn((p.r or 0) > 0)
r.plus:SetOn((p.r or 0) < MAX_TARGET)
else
r.minus:Hide(); r.rank:Hide(); r.plus:Hide()
r.val:Show()
if not r.val.focus then
P.filling = true
r.val:SetText(((p.r or 0) > 0) and AB.Num(p.r) or "")
P.filling = false
end
local stat = info and p.t ~= "legend" and AB.StatTemplate(info)
local stat2 = info and p.t ~= "legend" and AB.StatTemplate2(info)
if stat2 then
r.val:SetWidth(28)
r.unit:Hide()
r.val2:Show()
if not r.val2.focus then
P.filling = true
r.val2:SetText(((p.r2 or 0) > 0) and AB.Num(p.r2) or "")
P.filling = false
end
else
r.val:SetWidth(40)
r.val2:Hide()
r.unit:Show()
r.unit:SetText((not stat or string.find(stat, "%%")) and "%" or "")
end
end
if p.alt then r.bg:SetVertexColor(0.3, 0.55, 1, 0.07) else r.bg:SetVertexColor(1, 1, 1, 0.035) end
local mains = takes - (canAlt and AB.CountAlts(b, group) or 0)
if p.alt then
r.up:SetOn(i > mains + 1)
r.down:SetOn(i < takes)
else
r.up:SetOn(i > 1)
r.down:SetOn(i < mains)
end
end
r:Show()
else
r.pi = nil
r:Hide()
end
end
if n == 0 then
P.prioHint:SetText(T(group == "spell" and "Click spells on the left to add them.\nRight-click one to mark it to banish." or "Click icons on the left to add them.\nThe order here is your upgrade priority."))
P.prioHint:Show()
else
P.prioHint:Hide()
end
end
-- ---------------------------------------------------------------- stage bar (top)
-- Four stages of the build. Each has its own picks and notes; the tracker moves on to the
-- next one when the current one is complete.
function P.StageBar(f)
local ed = P.ed
P.stageTabs = {}
for i = 1, table.getn(AB.STAGE_NAMES) do
local tb = W.Button(ed, "", 96, 22)
tb:SetPoint("TOPLEFT", f, "TOPLEFT", 200 + (i - 1) * 99, -40)
tb.vi = i
tb:SetScript("OnClick", function()
P.variant = this.vi
P.stageEdit:ClearFocus()
P.Refresh()
end)
W.Tip(tb, function(self, tt)
local d = Draft()
local v = d and d.variants[self.vi]
if not v then return end
tt:SetText(AB.N(v.name), 1, 0.82, 0)
tt:AddLine(T("Stage %d of %d", self.vi, table.getn(d.variants)), 0.7, 0.7, 0.7)
tt:AddLine(table.getn(v.picks) .. " " .. T("picks"), 0.8, 0.8, 0.8)
tt:AddLine(T("The tracker moves on to the next stage once every pick of this one reaches its target rank. Empty stages are skipped."), 0.6, 0.6, 0.6, 1)
end)
P.stageTabs[i] = tb
end
P.copyPrev = W.Button(ed, "", 104, 22)
P.copyPrev:SetPoint("TOPLEFT", f, "TOPLEFT", 200 + 4 * 99 + 4, -40)
L(P.copyPrev, "Copy previous")
P.copyPrev:SetScript("OnClick", function()
local d = Draft()
if d and AB.CopyPreviousStage(d, P.variant) then Changed() end
end)
W.Tip(P.copyPrev, function(self, tt)
local d = Draft()
local prev = d and d.variants[P.variant - 1]
tt:SetText(T("Copy previous"), 1, 0.82, 0)
if prev then
tt:AddLine(T("Replaces this stage's picks with a copy of \"%s\", to build on: raise target ranks, swap pieces.", prev.name), 0.8, 0.8, 0.8, 1)
end
end)
local se = W.Edit(ed, "ASBuilderStageEdit", 100, 22)
se:SetPoint("TOPLEFT", f, "TOPLEFT", 708, -40)
se:SetMaxLetters(20)
se:SetScript("OnTextChanged", function()
if P.filling then return end
local d = Draft()
local t = this:GetText() or ""
if not d or t == "" then return end
d.variants[P.variant].name = t
P.RefreshDirty()
end)
se:SetScript("OnEditFocusGained", function() P.stageFocus = true end)
se:SetScript("OnEditFocusLost", function()
P.stageFocus = false
local d = Draft()
if d and (this:GetText() or "") == "" then this:SetText(d.variants[P.variant].name) end
end)
W.Tip(se, function(self, tt)
tt:SetText(T("Stage name"), 1, 0.82, 0)
tt:AddLine(T("Type to rename the selected stage."), 0.8, 0.8, 0.8, 1)
end)
P.stageEdit = se
-- a strip under the palette when this stage breaks the run's rules
local w = CreateFrame("Button", nil, ed)
w:SetWidth(300)
w:SetHeight(34)
w:SetPoint("BOTTOMLEFT", f, "BOTTOMLEFT", 200, 48)
W.Panel(w, 1, 0.3)
w:SetBackdropColor(0.35, 0.08, 0.05, 0.9)
w:SetBackdropBorderColor(0.95, 0.35, 0.25, 1)
w.text = W.Text(w, "GameFontHighlightSmall")
w.text:SetPoint("TOPLEFT", w, "TOPLEFT", 8, -5)
w.text:SetPoint("BOTTOMRIGHT", w, "BOTTOMRIGHT", -62, 5)
w.text:SetJustifyV("MIDDLE")
w.fix = W.Button(w, "", 50, 20)
w.fix:SetPoint("RIGHT", w, "RIGHT", -6, 0)
L(w.fix, "Fix")
w.fix:SetScript("OnClick", function()
local d = Draft()
if not d then return end
local left = AB.FixStage(d, P.variant)
if left > 0 then Err(T("No room for %d of them: remove some picks of this stage first.", left)) end
Changed()
end)
W.Tip(w.fix, function(self, tt)
tt:SetText(T("Fix"), 1, 0.82, 0)
tt:AddLine(T("Brings back what earlier stages take and drops spells an earlier stage banishes."), 0.8, 0.8, 0.8, 1)
end)
W.Tip(w, function(self, tt)
local d = Draft()
local issues = d and AB.StageIssues(d, P.variant) or {}
tt:SetText(T("This stage cannot happen in a run"), 1, 0.4, 0.3)
tt:AddLine(T("Spells, rings and trinkets stay once taken; only the amulet can be swapped. A banished card never comes back."), 0.7, 0.7, 0.7, 1)
tt:AddLine(" ")
for i = 1, table.getn(issues) do tt:AddLine("- " .. issues[i].text, 1, 0.75, 0.6, 1) end
end)
w:Hide()
P.warn = w
end
function P.RefreshStages(d)
for i = 1, table.getn(P.stageTabs) do
local tb = P.stageTabs[i]
local v = d.variants[i]
local n = v and table.getn(v.picks) or 0
local bad = table.getn(AB.StageIssues(d, i)) > 0
tb:SetLabel((bad and "|cffff5544!|r " or "") .. (v and AB.N(v.name) or "?") .. ((n > 0) and "" or " |cff666666-|r"))
tb:SetSelected(i == P.variant)
end
P.copyPrev:SetOn(P.variant > 1)
local issues = AB.StageIssues(d, P.variant)