-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKitbagUI.lua
More file actions
2018 lines (1793 loc) · 98.7 KB
/
Copy pathKitbagUI.lua
File metadata and controls
2018 lines (1793 loc) · 98.7 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
-- KitbagUI — the main window.
--
-- The brief is "better UI", and the specific thing being fixed is legibility of *state*. ItemRack
-- told you a set existed; it did not tell you whether you could actually wear it. Every row here
-- carries its own readiness, computed from the same planner that would do the equipping — so what
-- the window says and what the button does can never disagree.
--
-- The window is two halves. On the left, the set list and the save box: which sets exist and how
-- ready each one is. On the right, the inspector: the selected set drawn as a paperdoll, one cell
-- per slot, so "what is actually in this set" is answered by looking rather than by hovering. The
-- cells come from Core.Doll and are therefore plan-derived — an off hand that a two-hander is about
-- to free shows as being emptied even though the set never mentions that slot.
--
-- Its neighbours own the rest: KitbagFlyout the per-slot menus on Blizzard's own character sheet,
-- KitbagIcons the icon picker.
Kitbag = Kitbag or {}
local Sets = Kitbag.Sets
local Equip = Kitbag.Equip
local Core = Kitbag.Core
local Compat = Kitbag.Compat
local Skin = Kitbag.Skin
local UI = {}
local ROW_HEIGHT = 26
-- Twelve rather than thirteen: the action bar moved under the list (UI-28) and it had to be paid for
-- out of somewhere. The window's height is spent to the pixel between the list, the status line, the
-- import button and the name box, and this is the one of the four that can give a row up without
-- losing anything — the list scrolls, and a thirteenth set was never invisible, only one row further
-- down. Growing the window instead would have left a band of empty space under the paperdoll, which
-- is a worse trade for a row nobody on this account has ever reached.
local MAX_ROWS = 12
-- The two tools on the action row (UI-23). Both are Blizzard art that has shipped in every flavour
-- since 1.0 rather than an expansion's icon, and both are chosen for what they mean at 24 pixels:
-- the loot-pass X is the game's own "no" and reads as destructive without being a skull, and the
-- group-looking icon is people, which is what a copy TO ANOTHER CHARACTER is about.
--
-- A path that turns out not to exist does not draw nothing — it renders as missing-texture magenta,
-- which is about as loud as a UI fault gets. That is the useful property, and it is the same reason
-- SLOT_ART below is written as paths rather than guarded.
-- Equip is the addon's own icon, the one in the `.toc`'s `## IconTexture` (UI-26). It is the
-- picture a player already associates with Kitbag by the time they reach this button, and "the kit
-- bag you keep your sets in" is the thing it depicts — which is a better answer than a generic tick,
-- because a tick means "confirm" and this button does not confirm anything.
local EQUIP_ICON = Skin.ICON
local DELETE_ICON = "Interface\\Buttons\\UI-GroupLoot-Pass-Up"
-- Rename (UI-29). The guild frame's public-note glyph: Blizzard's own "edit the words attached
-- to this" picture, which is exactly the act, and UI art rather than an expansion icon for the
-- reason the two above are. "Rename" has no universal symbol — a pencil would be inventing one —
-- so the tooltip carries the word and the picture only has to not mean something else.
local RENAME_ICON = "Interface\\Buttons\\UI-GuildButton-PublicNote-Up"
local COPY_ICON = "Interface\\Icons\\INV_Misc_GroupLooking"
-- The two acts on the bottom row (UI-27). A parchment for writing down what you have on, and
-- Blizzard's own plus glyph — the one in the quest log and the tradeskill list — for making an empty
-- one. The plus is the only genuinely universal symbol in this whole set and it is spent on the
-- control that most needed it, since "New set" and "Save" are otherwise the pair a player is likeliest
-- to confuse.
local SAVE_ICON = "Interface\\Icons\\INV_Misc_Note_01"
local NEW_ICON = "Interface\\Buttons\\UI-PlusButton-Up"
-- Settings was a wrench on the bottom row that opened a second window (UI-24). It is a tab now
-- (UI-32), so the icon is gone: a door drawn as a labelled tab needs no picture, and two doors
-- onto one panel is worse than either of them alone.
local CELL = 34 -- a doll cell, big enough to read an icon at a glance
local CELL_GAP = 3
local PITCH = CELL + CELL_GAP
local PANEL_WIDTH = 300
local PARENT_Y = -70 -- the inherit button, between the set's headline and the character model
local KEY_Y = PARENT_Y - 24 -- the keybinding button, on its own row beneath it
local frame, rows, status, scroll, doll, importButton, renameBox
-- The tab strip and the three panels it switches between (UI-32). `activeTab` is an index rather
-- than an id because an index is what Blizzard's tab helpers take, and Core.TabIndex is the only
-- thing that produces one — so a stale id can never quietly become an index nobody meant.
local panels
local activeTab = 1
local selected = nil -- the set the inspector is showing
-- The set the rename box was OPENED on, or nil. Held rather than re-read from `selected` when Enter
-- is pressed, for Delete's reason (BUG-8): the list underneath stays live while the box is up, and a
-- row clicked in between must not change which set moves. A rename is not unrecoverable the way a
-- delete is, but renaming the wrong set is discovered exactly as late.
local renaming = nil
-- How each slot state reads, in one place: the colour of the cell's border and the words the
-- tooltip uses. Keeping them together is what stops the colour and the caption drifting apart.
local STATE = {
worn = { 0.25, 0.85, 0.35, text = "already on" },
swap = { 1.00, 0.82, 0.00, text = "will be equipped" },
clear = { 0.45, 0.55, 0.70, text = "will be emptied" },
bank = { 1.00, 0.60, 0.10, text = "waiting in your bank" },
missing = { 1.00, 0.30, 0.30, text = "not found" },
unknown = { 0.60, 0.60, 0.60, text = "" },
unset = { 0.28, 0.28, 0.28, text = "not part of this set" },
}
-- Blizzard's empty-slot art, so an untouched cell looks like the character sheet rather than a hole.
-- Several slots share one texture — both fingers, both trinkets — and the back slot borrows the
-- chest's, which is what the paperdoll itself does. A path that turns out not to exist on some
-- flavour does NOT draw nothing — it renders as missing-texture magenta, which is about as loud as
-- a UI fault gets. That is the useful property: a wrong path here cannot break the window and cannot
-- hide either, so it is caught the first time the window is opened rather than shipping unnoticed.
local SLOT_ART = {
HEAD = "Head", NECK = "Neck", SHOULDER = "Shoulder", SHIRT = "Shirt", CHEST = "Chest",
WAIST = "Waist", LEGS = "Legs", FEET = "Feet", WRIST = "Wrists", HANDS = "Hands",
FINGER1 = "Finger", FINGER2 = "Finger", TRINKET1 = "Trinket", TRINKET2 = "Trinket",
BACK = "Chest", MAINHAND = "MainHand", OFFHAND = "SecondaryHand", RANGED = "Ranged",
TABARD = "Tabard",
}
-- The three lines the window uses to say how ready a set is, each keyed on the ONE verdict in
-- `Core.Readiness`. The precedence lives there — most sharply that a blank set is asked about before
-- "already worn", since both have nothing to do and only one of them is green (UI-16). What stays
-- here is the phrasing, which is deliberately different in each: a row column has room for a word, a
-- tooltip for a sentence, and the note under the doll for a sentence that says what to do next.
--
-- Module functions rather than file-locals so they can be exercised outside the game: the wording is
-- the whole of what these are, and a wrong word here is not a broken window — it is a confident
-- sentence about the wrong thing, which is exactly the failure nobody reports.
--- The readiness column on a set's row.
function UI.RowText(plan)
local verdict = Core.Readiness(plan)
local state, count = verdict.state, verdict.count
if state == "unknown" then return "|cff808080—|r" end
if state == "blank" then return "|cff808080empty|r" end
if state == "worn" then return "|cff40ff40worn|r" end
if state == "bags" then return "|cffff8080bags full|r" end
if state == "bank" then return string.format("|cffffd100%d at bank|r", count) end
if state == "missing" then return string.format("|cffff8080%d missing|r", count) end
return string.format("|cffffd100%d swap%s|r", count, count == 1 and "" or "s")
end
--- The line the row tooltip falls back to when the plan has no moves to list.
---
--- Only ever reached when `Core.Explain` produced nothing, which is the case for all three no-op
--- states at once — and they are three different answers.
function UI.TooltipNote(plan)
local state = Core.Readiness(plan).state
if state == "blank" then return "Empty — nothing in it yet.", 0.6, 0.6, 0.6 end
if state == "worn" then return "Already worn.", 0.4, 1, 0.4 end
return "Nothing to do.", 0.4, 1, 0.4
end
--- One line under the inspector's doll for what stands between you and wearing this.
function UI.InspectorNote(plan)
local verdict = Core.Readiness(plan)
local state, count = verdict.state, verdict.count
if state == "unknown" then return "" end
if state == "blank" then return "|cff808080Empty — click a slot to say what goes there.|r" end
if state == "worn" then return "|cff40ff40You are wearing this.|r" end
if state == "bags" then
return string.format("|cffff5050Bags full — needs %d free slot(s).|r", count)
end
if state == "bank" or state == "missing" then
return string.format("|cffff8080%d piece%s not to hand.|r", count, count == 1 and "" or "s")
end
return string.format("%d swap%s to go.", count, count == 1 and "" or "s")
end
-- Item level and the weakest piece, in the little space a row has (CORE-4).
--
-- "≈" when the client has not cached every item yet: the number is real but computed over part of
-- the set, and quietly showing a partial average as a firm one is how a raid set reads as green
-- trash for the first ten seconds after a login. Durability is only shown once it is worth acting
-- on — a bar at 96% is noise, one at 15% is a trip to the vendor.
local function rowTotals(totals)
if not totals or not totals.level then return "" end
local text = string.format("%silvl %d",
totals.complete and "" or "≈", math.floor(totals.level + 0.5))
if totals.broken > 0 then
text = text .. " |cffff4040broken|r"
elseif totals.durability and totals.durability < 0.25 then
text = text .. string.format(" |cffff8080%d%%|r", math.floor(totals.durability * 100))
end
return text
end
-- The name of an item key, or an honest stand-in. GetItemInfo returns nil for anything the client
-- has not cached, which is routine for the first seconds after a login — so a line degrades rather
-- than collapsing to nothing.
local function itemName(key)
return (key and GetItemInfo(Core.ItemId(key))) or "an item"
end
-- ---------------------------------------------------------------------------
-- The set list
-- ---------------------------------------------------------------------------
-- The exact moves the Equip button would make, on hover (UI-6).
--
-- Read out of the plan itself rather than re-derived from the set, so the tooltip cannot promise
-- something different from what the driver does — it is the same list the driver is about to walk.
local function onRowEnter(self)
local name = self.setName
if not name then return end
local plan, totals = self.data.plan, self.data.totals
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:AddLine(name, 1, 0.82, 0)
local inherits = Sets.ParentOf(name)
if inherits then
GameTooltip:AddLine("inherits from " .. inherits, 0.6, 0.6, 0.6)
end
if totals and totals.level then
GameTooltip:AddLine(string.format("%d items, average item level %s%d",
totals.items, totals.complete and "" or "about ", math.floor(totals.level + 0.5)),
0.6, 0.6, 0.6)
end
local lines = Core.Explain(plan)
if #lines == 0 then
GameTooltip:AddLine(UI.TooltipNote(plan))
else
GameTooltip:AddLine(" ")
for _, line in ipairs(lines) do
local what = itemName(line.key)
local text
if line.missing then
text = string.format("%s: %s — %s", line.slot, what, line.verb)
elseif line.from then
text = string.format("%s: move %s from %s", line.slot, what, line.from)
else
text = string.format("%s: %s %s", line.slot, line.verb, what)
end
if line.missing then
GameTooltip:AddLine(text, 1, 0.5, 0.5)
else
GameTooltip:AddLine(text, 0.9, 0.9, 0.9)
end
end
end
GameTooltip:AddLine(" ")
GameTooltip:AddLine("Click to inspect it. Click the icon to change it, or drag it to a bar.",
0.5, 0.5, 0.5)
if plan and plan.blocked == "bags" then
GameTooltip:AddLine(string.format("Bags full — needs %d free slot(s).", plan.needsBagSlots),
1, 0.3, 0.3)
end
GameTooltip:Show()
end
local function onRowLeave()
GameTooltip:Hide()
end
--- Show `name` in the inspector. The one path by which anything CHOOSES a set.
---
--- Equip and Delete read `selected` rather than a set named on the row they sit in (UI-13 moved them
--- out of the rows), so "which set is selected" decides what a destructive button destroys. That
--- makes a second place that chooses a set a real hazard rather than a tidiness question, and it is
--- why the row click, a freshly created set and `/kit verify` all come through here.
---
--- `UI.Refresh` also assigns `selected`, and deliberately does not come through here: it is repairing
--- a selection whose set has been deleted or renamed, not choosing one, and routing a repair through
--- a function that refreshes would recurse.
function UI.Select(name)
if not name then return end
selected = name
-- The picker is bound to one slot of one set. Leaving it open over a different set would offer
-- a click that edits the set you just navigated away from.
Kitbag.Picker.Close()
UI.Refresh()
end
--- Which set the inspector is showing, or nil. Exposed so the addon can check itself (VERIFY-8):
--- from outside, a file-local selection is indistinguishable from the buttons reading a stale one.
function UI.Selected()
return selected
end
local function onRowClick(self)
if not self.setName then return end
UI.Select(self.setName)
end
local function createRow(parent, index)
-- Named, so a check can measure them. Thirteen rows serve any number of sets, so a row is only
-- meaningful together with the `setName` it is currently showing — and the pair is what the
-- Equip and Delete buttons ultimately act through, which is the one unrecoverable act in the
-- addon pointed at a variable (VERIFY-8). A handle is what lets that be driven in a test.
local row = CreateFrame("Button", "KitbagSetRow" .. index, parent)
row:SetHeight(ROW_HEIGHT)
-- Per-row DATA lives in its own table, never as loose fields on the frame. A frame is a live
-- namespace of widgets and Blizzard methods, and `row.totals = <the totals table>` silently
-- replaced the FontString of the same name — the crash reads as "SetText is nil", ten lines
-- from the assignment that caused it. One subtable makes that collision impossible.
row.data = {}
row:SetScript("OnEnter", onRowEnter)
row:SetScript("OnLeave", onRowLeave)
row:SetScript("OnClick", onRowClick)
row:SetPoint("TOPLEFT", parent, "TOPLEFT", 0, -(index - 1) * ROW_HEIGHT)
row:SetPoint("TOPRIGHT", parent, "TOPRIGHT", 0, -(index - 1) * ROW_HEIGHT)
-- Which row the inspector is showing. A highlight rather than a separate "selected" column: the
-- list is narrow and one more glyph per row would cost more than it says.
row.selection = row:CreateTexture(nil, "BACKGROUND")
row.selection:SetAllPoints()
row.selection:SetTexture("Interface\\Buttons\\WHITE8X8")
row.selection:SetVertexColor(1, 0.82, 0, 0.18)
row.selection:Hide()
row:SetHighlightTexture("Interface\\Buttons\\WHITE8X8")
local hl = row:GetHighlightTexture()
if hl then hl:SetVertexColor(1, 1, 1, 0.07) end
-- The icon doubles as the picker button. A separate "change icon" control would need a column
-- of its own on a row that has none to spare, and clicking the icon is where anyone would try.
row.icon = CreateFrame("Button", nil, row)
row.icon:SetSize(20, 20)
row.icon:SetPoint("LEFT", row, "LEFT", 4, 0)
row.icon.texture = row.icon:CreateTexture(nil, "ARTWORK")
row.icon.texture:SetAllPoints()
row.icon:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square")
row.icon:SetScript("OnClick", function(self) Kitbag.Icons.Open(self:GetParent().setName) end)
-- Drag the icon to the action bar (UI-8). Click still opens the picker; the client distinguishes
-- the two, so the icon can be both without either getting in the way.
row.icon:RegisterForDrag("LeftButton")
row.icon:SetScript("OnDragStart", function(self)
Sets.PickupMacro(self:GetParent().setName)
end)
row.name = row:CreateFontString(nil, "OVERLAY", "GameFontNormal")
row.name:SetPoint("LEFT", row.icon, "RIGHT", 6, 0)
row.name:SetJustifyH("LEFT")
row.name:SetWidth(130)
row.state = row:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
row.state:SetPoint("LEFT", row.name, "RIGHT", 6, 0)
row.state:SetJustifyH("LEFT")
row.state:SetWidth(76)
row.totals = row:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
row.totals:SetPoint("LEFT", row.state, "RIGHT", 6, 0)
row.totals:SetJustifyH("LEFT")
row.totals:SetWidth(56)
return row
end
-- ---------------------------------------------------------------------------
-- The inspector — one set as a paperdoll (UI-13)
-- ---------------------------------------------------------------------------
local function onCellEnter(self)
local cell = self.data.cell
if not cell then return end
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
if cell.key then
-- The real item tooltip where there is a real item, so stats and enchants read exactly as
-- they do everywhere else in the game.
GameTooltip:SetHyperlink(Core.ItemLink(cell.key))
GameTooltip:AddLine(" ")
else
GameTooltip:AddLine(cell.slot.label, 1, 0.82, 0)
end
local state = STATE[cell.state] or STATE.unset
GameTooltip:AddLine(string.format("%s — %s", cell.slot.label, state.text),
state[1], state[2], state[3])
GameTooltip:AddLine(" ")
GameTooltip:AddLine("Click to choose what this set puts here.", 0.5, 0.5, 0.5)
if cell.state ~= "unset" then
GameTooltip:AddLine("Shift-click to drop the slot from the set.", 0.5, 0.5, 0.5)
end
GameTooltip:Show()
end
local function onCellLeave()
GameTooltip:Hide()
end
-- Click a slot to say what the set should put in it (UI-14).
--
-- Shift-click is the shortcut for the one choice worth reaching in a single gesture: dropping the
-- slot out of the set entirely, so it keeps whatever you happen to be wearing. It is also the only
-- destructive one, which is why it is behind a modifier — and why an untouched slot does not offer
-- it, since there is nothing there to drop.
local function onCellClick(self)
local cell = self.data.cell
if not selected or not cell then return end
if IsShiftKeyDown() then
if cell.state ~= "unset" then Sets.SetSlot(selected, cell.slot.id, nil) end
return
end
Kitbag.Picker.Open(selected, cell.slot.id, self)
end
local function createCell(parent, x, y)
-- A Button rather than a Frame: the cells were read-only when the inspector was built (UI-13)
-- and this is the pass that makes them the way a set is edited.
local cell = CreateFrame("Button", nil, parent)
cell:SetSize(CELL, CELL)
cell:SetPoint("TOPLEFT", parent, "TOPLEFT", x, y)
cell:EnableMouse(true)
cell.data = {}
-- The border IS the state: a tinted plate one pixel proud of the cell, with the cell's own dark
-- ground over it. Cheaper than a backdrop and identical on every flavour.
cell.border = cell:CreateTexture(nil, "BACKGROUND")
cell.border:SetPoint("TOPLEFT", -1, 1)
cell.border:SetPoint("BOTTOMRIGHT", 1, -1)
cell.border:SetTexture("Interface\\Buttons\\WHITE8X8")
cell.ground = cell:CreateTexture(nil, "BORDER")
cell.ground:SetAllPoints()
cell.ground:SetTexture("Interface\\Buttons\\WHITE8X8")
cell.ground:SetVertexColor(0.06, 0.06, 0.06, 1)
cell.empty = cell:CreateTexture(nil, "ARTWORK")
cell.empty:SetAllPoints()
cell.empty:SetAlpha(0.45)
cell.icon = cell:CreateTexture(nil, "OVERLAY")
cell.icon:SetAllPoints()
-- Something clickable has to look clickable. The highlight is the only affordance a bare cell
-- has, and without it the doll reads as a picture of the set rather than as the way to edit it.
cell:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square")
cell:SetScript("OnEnter", onCellEnter)
cell:SetScript("OnLeave", onCellLeave)
cell:SetScript("OnClick", onCellClick)
return cell
end
-- Light a model frame.
--
-- `SetLight` is one of the few WoW API calls whose *signature* changed rather than its name: modern
-- clients take (enabled, lightTable), older ones take thirteen positional numbers. Getting it wrong
-- is not a visible error — it is an invisible model — so both are tried and the first that does not
-- throw wins. The table form goes first because every flavour Kitbag targets is built on the modern
-- code base; the positional form is the belt-and-braces.
local function lightModel(model)
if not model.SetLight then return end
local ok = pcall(model.SetLight, model, true, {
omnidirectional = false,
point = CreateVector3D and CreateVector3D(0, 0, 0) or nil,
ambientIntensity = 1.0,
ambientColor = CreateColor and CreateColor(1, 1, 1) or nil,
diffuseIntensity = 1.0,
diffuseColor = CreateColor and CreateColor(1, 1, 1) or nil,
})
if not ok then
pcall(model.SetLight, model, true, false, 0, 0, -1, 1.0, 1, 1, 1, 1.0, 1, 1, 1)
end
end
-- Which set this one is a delta on (UI-11).
--
-- Inheritance has existed since CORE-3, but `/kit inherit Raid Fire from Raid` was the only way to
-- declare it and the row tooltip the only place it showed — so the feature was invisible to anyone
-- who had not read the slash-command help. It belongs in the inspector because that is where the
-- consequence is visible: the pieces coming from the parent are already drawn in the doll.
--
-- The list comes from Core.ParentChoices, so the menu never offers a set that Sets.Inherit would then
-- refuse. A menu that has to apologise after the click is worse than a shorter menu.
local function initParentMenu(self, level)
if not selected then return end
local current = Sets.ParentOf(selected)
local info = UIDropDownMenu_CreateInfo()
info.text = "Inherit from"
info.isTitle = true
info.notCheckable = true
UIDropDownMenu_AddButton(info, level)
info = UIDropDownMenu_CreateInfo()
info.text = "Nothing"
info.checked = current == nil
info.func = function()
-- Only when it would change something: Sets.Inherit(name, nil) on a set that inherits from
-- nothing prints a correction, and picking the option already ticked should be silent.
if current then Sets.Inherit(selected, nil) end
CloseDropDownMenus()
end
UIDropDownMenu_AddButton(info, level)
for _, name in ipairs(Sets.ParentChoices(selected)) do
info = UIDropDownMenu_CreateInfo()
info.text = name
info.checked = current == name
info.func = function()
if current ~= name then Sets.Inherit(selected, name) end
CloseDropDownMenus()
end
UIDropDownMenu_AddButton(info, level)
end
end
local function onParentEnter(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:AddLine("Inheritance", 1, 0.82, 0)
GameTooltip:AddLine("A set with a parent stores only what differs from it, so a shared piece " ..
"lives in one place and re-enchanting it updates every set that wears it.", 1, 1, 1, true)
GameTooltip:AddLine("A slot this set does not name is taken from its parent.", 0.6, 0.6, 0.6,
true)
GameTooltip:Show()
end
-- Send this set to another character (UI-20).
--
-- CORE-7 shipped the whole mechanism and `/kit copy Tank to Alt - Realm` was the only door to it,
-- which is UI-11's problem again: a feature nobody finds is a feature nobody has. The menu is built
-- from Sets.CopyChoices for the same reason the inherit menu comes from Core.ParentChoices — the
-- window must not form its own opinion of who can be copied to and then be corrected by Sets.
--
-- The clash is the part a menu has to do that the command does not. `CopyTo` refuses a name the
-- target already uses and says so in chat, which is right for something typed and wrong for
-- something clicked: the player picks a character and is told no afterwards. Here they are greyed,
-- with the reason on the entry, so the refusal never arrives.
local function initCopyMenu(self, level)
if not selected then return end
-- The name the menu is ABOUT, captured rather than re-read on click. The list on the left stays
-- live while a menu is up, so a row clicked in between would otherwise send a different set than
-- the one the menu is headed with — the same reason the delete popup carries its name as `data`
-- (BUG-8). A copy is not unrecoverable the way a delete is, but "I copied the wrong set" is
-- discovered on another character, days later.
local name = selected
local info = UIDropDownMenu_CreateInfo()
info.text = "Copy " .. name .. " to"
info.isTitle = true
info.notCheckable = true
UIDropDownMenu_AddButton(info, level)
for _, choice in ipairs(Sets.CopyChoices(name)) do
info = UIDropDownMenu_CreateInfo()
-- The reason rides on the entry rather than only in a tooltip: a greyed line with no
-- explanation is the puzzle UI-11 was written about, and this one is easily mistaken for
-- "that character cannot take sets at all".
info.text = choice.taken
and (choice.key .. " |cff808080(has a set called " .. name .. ")|r")
or choice.key
info.notCheckable = true
info.disabled = choice.taken
info.func = function()
Sets.CopyTo(name, choice.key)
CloseDropDownMenus()
end
UIDropDownMenu_AddButton(info, level)
end
end
local function onCopyEnter(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:AddLine("Copy to another character", 1, 0.82, 0)
GameTooltip:AddLine("The set is written into that character's own list. They keep it after " ..
"you log out — nothing of theirs is touched, and nothing here changes.", 1, 1, 1, true)
-- Said before the copy rather than discovered after it: the alt has no parent set to inherit
-- from, so what travels is the whole outfit. Re-saving it over there will not behave the way
-- re-saving this one does.
GameTooltip:AddLine("The copy arrives flat: a set that inherits here is one whole outfit " ..
"there.", 0.6, 0.6, 0.6, true)
GameTooltip:Show()
end
-- ---------------------------------------------------------------------------
-- The keybinding button (UI-12)
-- ---------------------------------------------------------------------------
--
-- `Bindings.Set` and `Bindings.Apply` have existed since COMPAT-5 and the ItemRack import has been
-- filling `set.key` all along; there was simply no way to assign one without importing. This is the
-- door.
--
-- Capturing is a mode rather than a dialog: the button says what it is waiting for, and the next
-- keystroke either becomes the binding or leaves the mode. A dialog would need its own frame, its
-- own escape handling and its own answer to "what if the window closes while it is up", all to ask
-- a question that fits on the button already there.
--- True while the button is swallowing keystrokes. File-local rather than on the frame so the
--- refresh path can see it without reaching through a widget that may not exist yet.
local capturing = false
local pendingBinding = nil
local pendingRefusal = nil
local function keyLabel()
if pendingRefusal then
return Core.BindingRefusalCaption()
end
local current = selected and Sets.KeyOf(selected) or nil
local impact
if pendingBinding and selected then
impact = Core.BindingImpact(Kitbag.char.sets, selected, pendingBinding)
end
return Core.BindingLabel(current, pendingBinding, impact)
end
--- Repaint the button and, when a refusal stands, the line that carries its reason (BUG-16).
--
-- Always both, and always through here. A refusal is prose and belongs on the 316px status line,
-- not on a one-row button whose FontString is centred and unclipped — written there the sentence
-- spilled out both sides of the control and landed on top of Inherit and the doll cells either
-- side. UI-34 widened this button to the full gap; that buys a longer CHORD, not a sentence, so
-- the division stands. Painting the pair in one place is also what stops the two from disagreeing.
--- True while `status` is showing a capture refusal rather than describing the list, so the line
--- can be handed back exactly once instead of on every keystroke of a capture that never refused.
local refusalOnLine = false
local function paintKey(button)
button:SetText(keyLabel())
if not status then return end
if pendingRefusal then
status:SetText(Core.BindingRefusalLabel(pendingRefusal.key, pendingRefusal))
refusalOnLine = true
elseif refusalOnLine then
-- The refusal has been answered, so the line goes back to describing the list. A full
-- redraw rather than a second copy of the wording: `UI.Refresh` already owns what this
-- line says, and duplicating it here is how the two would come to disagree.
refusalOnLine = false
UI.Refresh()
end
end
local function stopCapture(button)
capturing = false
pendingBinding = nil
pendingRefusal = nil
button:EnableKeyboard(false)
-- Restored, not merely turned off. While capturing, this frame is the only thing in the game
-- receiving keys — including the ones that open the menu and the ones that close this window —
-- so leaving it clamped would be indistinguishable from the client having locked up.
pcall(button.SetPropagateKeyboardInput, button, true)
UI.Refresh()
end
local function onKeyCaptured(button, key)
-- Escape always cancels, whether there is a proposal already or the player has only just
-- entered capture. It reaches here rather than closing the window because propagation is off.
if key == "ESCAPE" then
stopCapture(button)
return
end
-- Enter is deliberately handled before BindingKey: once a chord is proposed it is the second
-- act that changes stored state, rather than another chord that silently replaces the proposal.
if key == "ENTER" and pendingBinding then
if selected then Kitbag.Bindings.Set(selected, pendingBinding) end
stopCapture(button)
return
end
-- Core owns which raw keystrokes can form chords; Compat then asks the client whether the
-- completed chord already belongs to the player. A capture that cannot prove the key is free
-- must not take it — the button names the action rather than silently appearing to ignore it.
local binding, why = Core.BindingKey(key, IsShiftKeyDown(), IsControlKeyDown(), IsAltKeyDown())
if not binding then
pendingBinding = nil
pendingRefusal = { why = why, key = key }
paintKey(button)
return
end
local candidate = Core.BindingCandidate(binding, Compat.BindingAction(binding))
if not candidate.ok then
pendingBinding = nil
pendingRefusal = candidate
paintKey(button)
return
end
-- The press is only a proposal. Replacing it costs nothing; only Enter reaches Bindings.Set.
pendingBinding = binding
pendingRefusal = nil
paintKey(button)
end
local function onKeyEnter(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:AddLine("Keybinding", 1, 0.82, 0)
if capturing then
GameTooltip:AddLine(pendingBinding
and "Press Enter to keep this key, or Escape to cancel."
or (pendingRefusal and "Choose an unbound key. Escape cancels."
or "Press the key you want. Escape cancels."), 1, 1, 1, true)
else
GameTooltip:AddLine("Click, then press a key to bind this set. " ..
"Right-click to clear it.", 1, 1, 1, true)
end
-- Both halves of the promise, because both surprise people. A key another set holds is taken
-- from it — the alternative is a binding that silently loses an arbitration it never mentioned
-- — and none of this is written into the player's own bindings, so uninstalling Kitbag gives
-- every key back rather than leaving a set of dead ones behind.
GameTooltip:AddLine("A key another set already uses is taken from it.", 0.6, 0.6, 0.6, true)
GameTooltip:AddLine("Kitbag re-applies these each login and never writes them into your " ..
"saved bindings.", 0.6, 0.6, 0.6, true)
GameTooltip:Show()
end
local function buildKeyButton(panel, gapWidth)
panel.key = CreateFrame("Button", "KitbagKeyButton", panel, "UIPanelButtonTemplate")
panel.key:SetSize(gapWidth, 20)
panel.key:SetPoint("TOPLEFT", panel, "TOP", -gapWidth / 2, KEY_Y)
panel.key:RegisterForClicks("LeftButtonUp", "RightButtonUp")
panel.key:SetScript("OnClick", function(self, button)
if not selected then return end
if capturing then
stopCapture(self)
return
end
-- No redraw here: Bindings.Set changes stored state and goes through Kitbag.Refresh itself,
-- which is what repaints the set that lost the key as well as the one that gained it.
if button == "RightButton" then
Kitbag.Bindings.Set(selected, nil)
return
end
capturing = true
pendingBinding = nil
pendingRefusal = nil
self:SetText("Press…")
self:EnableKeyboard(true)
-- Without this the keystroke reaches the game as well as this button, so binding "B" would
-- also open the bags and binding Escape would close the window out from under the mode.
-- Feature-detected: it is not on every flavour, and CreateFrame gives no warning for a
-- method that is simply absent.
pcall(self.SetPropagateKeyboardInput, self, false)
end)
panel.key:SetScript("OnKeyDown", onKeyCaptured)
panel.key:SetScript("OnEnter", onKeyEnter)
panel.key:SetScript("OnLeave", onCellLeave)
-- Nothing should be able to leave the game deaf. If the window goes away mid-capture — Escape
-- on a different frame, /reload, the close button — the mode has to end with it.
panel.key:SetScript("OnHide", function(self)
if capturing then stopCapture(self) end
end)
end
local function buildDoll(parent)
-- Named, like every other region the addon draws (UI-22): a panel nobody can name is a panel no
-- check and no test can ask about. It went unnamed while the copy button stood in for it — a
-- check reached the panel through `KitbagCopyButton:GetParent()` — and UI-28 moved that button
-- into a row of its own, which is exactly how a stand-in stops standing for the thing.
local panel = CreateFrame("Frame", "KitbagInspector", parent)
panel:SetPoint("TOPLEFT", parent, "TOPLEFT", 344, -34)
panel:SetSize(PANEL_WIDTH, 392)
-- Named, unlike the panel's other strings, because it is the one piece of the inspector that says
-- WHICH set is being shown — so it is the evidence that the doll followed the selection rather
-- than merely that both exist (VERIFY-8).
panel.title = panel:CreateFontString("KitbagInspectorTitle", "OVERLAY", "GameFontNormalLarge")
panel.title:SetPoint("TOP", panel, "TOP", 0, 0)
panel.title:SetWidth(PANEL_WIDTH)
local cells = {}
local right = PANEL_WIDTH - 4 - CELL
-- The layout is Core's, not this file's, so the one place that could lose a slot is the one
-- place with a test asserting all nineteen are present exactly once.
for i, slotId in ipairs(Core.DOLL_LAYOUT.left) do
cells[slotId] = createCell(panel, 4, -24 - (i - 1) * PITCH)
end
for i, slotId in ipairs(Core.DOLL_LAYOUT.right) do
cells[slotId] = createCell(panel, right, -24 - (i - 1) * PITCH)
end
-- The weapons in a row of their own beneath, centred, as the character sheet has them. Its
-- position is measured off the columns rather than off a hardcoded eight — the layout is data,
-- so nothing here should quietly disagree with it if it ever changes.
local columnRows = math.max(#Core.DOLL_LAYOUT.left, #Core.DOLL_LAYOUT.right)
local weaponsWidth = #Core.DOLL_LAYOUT.bottom * PITCH - CELL_GAP
local weaponsX = math.floor((PANEL_WIDTH - weaponsWidth) / 2)
local weaponsY = -24 - columnRows * PITCH
for i, slotId in ipairs(Core.DOLL_LAYOUT.bottom) do
cells[slotId] = createCell(panel, weaponsX + (i - 1) * PITCH, weaponsY)
end
-- The gap between the two columns is the only real space the window has; the set's headline
-- numbers go there, where the eye already is, with the character beneath them.
local gapWidth = PANEL_WIDTH - 2 * (8 + CELL)
panel.summary = panel:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
panel.summary:SetPoint("TOP", panel, "TOP", 0, -24)
panel.summary:SetWidth(gapWidth)
panel.summary:SetJustifyH("CENTER")
panel.note = panel:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
panel.note:SetPoint("TOP", panel.summary, "BOTTOM", 0, -6)
panel.note:SetWidth(gapWidth)
panel.note:SetJustifyH("CENTER")
-- The parent, and the way to change it (UI-11). Anchored to the panel at a fixed height rather
-- than under the note, because the note is one line or two depending on what the plan says and a
-- control that moves is a control you have to look for.
--
-- "MENU" is what makes UIDropDownMenuTemplate act as a bare pop-up menu: Blizzard's own
-- initialiser hides the template's dropdown art in that mode, so the frame is only a host for the
-- list and nothing of it is drawn in the panel.
local menu = CreateFrame("Frame", "KitbagParentMenu", panel, "UIDropDownMenuTemplate")
UIDropDownMenu_Initialize(menu, initParentMenu, "MENU")
-- The two controls each take a whole row. They shared one until UI-34, the keybinding button
-- squeezed into 82px on the right — which was never enough for the label it has to carry, since
-- a chord is spelled out in full and "CTRL-NUMPAD9" alone overruns it. UIPanelButtonTemplate
-- does not shrink a label that does not fit, it lets it out under its own edge, so the cost of
-- the narrow button was a key name spilling across the panel. A row costs 24px of the character
-- model, which has it to give; a clipped binding is unreadable at any size. Both are named so
-- `/kit verify` can measure the clearance between them — a measurement needs both edges, and
-- this one varies, because the upper button's label is a set name.
panel.inherit = CreateFrame("Button", "KitbagInheritButton", panel, "UIPanelButtonTemplate")
panel.inherit:SetSize(gapWidth, 20)
panel.inherit:SetPoint("TOPLEFT", panel, "TOP", -gapWidth / 2, PARENT_Y)
panel.inherit:SetScript("OnClick", function(self)
ToggleDropDownMenu(1, nil, menu, self, 0, 0)
end)
panel.inherit:SetScript("OnEnter", onParentEnter)
panel.inherit:SetScript("OnLeave", onCellLeave)
-- A set name is as long as the player made it. With a width and no wrapping the client truncates
-- it for us; without them a long name runs out over the doll's icons on both sides.
local label = panel.inherit:GetFontString()
if label then
label:SetWidth(gapWidth - 16)
pcall(label.SetWordWrap, label, false)
end
buildKeyButton(panel, gapWidth)
-- The character itself, filling what is left of the gap: the icons say WHICH items, the model
-- says what wearing them looks like, and neither answer was available before without equipping
-- the set to find out. It is a preview, so it dresses the player in the set's items over what
-- they already have on rather than undressing them — a slot the set does not name keeps showing
-- the piece that will still be there afterwards. A slot the plan will EMPTY still shows its old
-- piece, since the model can only add: the cell beside it already says "will be emptied", and a
-- naked preview would be the more misleading of the two answers.
--
-- Guarded: `DressUpModel` and `TryOn` are ancient, but a flavour that lacks either would take
-- the whole window down at build time, and the panel reads perfectly well without a model.
local modelTop = KEY_Y - 26
-- The well the preview sits in. Every other thing this panel draws sits in something — each of
-- the nineteen cells has a tinted edge over a dark ground — and the model had neither, so the one
-- region of the paperdoll that is not made of squares read as a hole between two columns of them.
-- Recessed by the shared skin, which is the same recess every doll cell around it has and the
-- same one the set list opposite has — the region is a panel, and it now says so in the words
-- the rest of the window uses.
--
-- It is the model's PARENT rather than a plate behind it. A decorative sibling looks the same in
-- a screenshot and behaves differently in every way that matters — it would not hide with the
-- model and would draw over or under it depending on creation order.
local well = Skin.Inset(CreateFrame("Frame", "KitbagPreviewFrame", panel))
well:SetSize(gapWidth, modelTop - weaponsY - 8)
well:SetPoint("TOP", panel, "TOP", 0, modelTop)
panel.well = well
-- Named, unlike every other frame here: a model that renders nothing looks identical to a model
-- that was never created, and a name is the only way to tell the two apart from a `/run` line.
local ok, model = pcall(CreateFrame, "DressUpModel", "KitbagPreviewModel", well)
if ok and model and model.TryOn then
model:SetPoint("TOPLEFT", well, "TOPLEFT", 1, -1)
model:SetPoint("BOTTOMRIGHT", well, "BOTTOMRIGHT", -1, 1)
model:EnableMouse(true)
model:SetScript("OnMouseDown", function(self) self.dragX = GetCursorPosition() end)
model:SetScript("OnMouseUp", function(self) self.dragX = nil end)
-- Drag to turn them around, as the dressing-room does. Kept on the frame rather than in a
-- file-local so a redress can restore the angle the player chose.
model:SetScript("OnUpdate", function(self)
if not self.dragX then return end
local x = GetCursorPosition()
self.facing = (self.facing or 0) + (x - self.dragX) * 0.012
self.dragX = x
self:SetFacing(self.facing)
end)
-- A model frame built in Lua has no lighting and no camera of its own — the dressing room
-- gets both from XML this addon does not have — and an unlit model draws as nothing at all
-- against a dark panel. Re-applied on every show because a model can also come back blank
-- after the frame has been hidden.
model:SetScript("OnShow", function(self)
lightModel(self)
-- Clearing the signature is enough to force a redress: OnShow fires from inside
-- refreshDoll, before the pass reaches dressModel.
self.dressed = nil
end)
panel.model = model
else
-- A bordered box with nothing in it is worse than no box: on a flavour without DressUpModel
-- the well would read as a preview that failed rather than as a panel that never offered one.
well:Hide()
end
panel.cells = cells
return panel
end
-- ---------------------------------------------------------------------------
-- Renaming a set in place (UI-29)
-- ---------------------------------------------------------------------------
--
-- An edit box over the row rather than a popup with an OK button, because the clash is the whole of
-- the risk here. `Sets.Rename` refuses a name another set already holds, but a refusal that arrives
-- in chat AFTER the press is a control that appeared to work — the same failure BUG-8 fixed for
-- Delete from the other direction. `Core.RenameLabel` answers on every keystroke, so "that name is
-- taken" is on screen while the name is still being typed.
--
-- The box is one widget moved onto whichever row is being renamed, for the reason there are twelve
-- rows and not one per set: a per-row control would cost a column the 316-wide list does not have,
-- and a control that only exists while it is being used costs none.
--- Close the box without redrawing. The half that is safe to call from inside `UI.Refresh`.
local function closeRenameBox()
if not renaming then return end
-- Cleared first: ClearFocus fires OnEditFocusLost, which comes back through here.
renaming = nil
renameBox:ClearFocus()
renameBox:Hide()
end
--- Close the box and put the window back the way it was.
local function stopRename()
if not renaming then return end
closeRenameBox()
UI.Refresh()
end
--- What the box currently proposes, and the line that says so. Returns the impact so the commit and
--- the line cannot form two opinions of whether the name is allowed.
local function renameProposal()
if not renaming then return nil end
local impact = Core.RenameImpact(Kitbag.char.sets, Kitbag.char.rules, renaming,
renameBox:GetText())
status:SetText(Core.RenameLabel(renaming, impact))
return impact
end
--- Open the box on `name`.
--
-- Brings the set into view first. Selection does not only come from clicking a row — `/kit verify`
-- and a freshly created set both go through `UI.Select` — so the set being renamed can be scrolled
-- out of sight, and a box anchored to a row that is not drawing it would open over another set
-- entirely. Scrolling is the honest answer: refusing would make the control unreliable for reasons
-- the player cannot see.
local function startRename(name)
if not name or not Kitbag.char.sets[name] then return end
local names = Sets.Names()
local index
for i, candidate in ipairs(names) do
if candidate == name then index = i break end
end
if not index then return end
local offset = Core.ScrollOffset(#names, MAX_ROWS, FauxScrollFrame_GetOffset(scroll))
if index <= offset or index > offset + MAX_ROWS then
FauxScrollFrame_SetOffset(scroll, Core.ScrollOffset(#names, MAX_ROWS, index - 1))
end
-- Both set before the redraw. The refresh blanks the row's name so the box is not typed over a
-- FontString still showing the old one, and it also re-asks for the line under the list — which
-- would otherwise be answered about whatever the box still held from the last rename.
renaming = name
renameBox:SetText(name)
UI.Refresh()
local target
for _, row in ipairs(rows) do
if row.setName == name then target = row end
end
if not target then
closeRenameBox()
return
end
-- Over the name column only. The readiness and item level beside it stay readable, which is
-- worth keeping: renaming a set is one of the moments you are looking at the list to tell two
-- of them apart.
renameBox:ClearAllPoints()
renameBox:SetPoint("LEFT", target.icon, "RIGHT", 2, 0)
renameBox:SetSize(130, ROW_HEIGHT - 6)
renameBox:Show()
renameBox:SetFocus()
-- Selected, so the commonest rename — a different name entirely — is one gesture rather than a
-- press, a select-all and then the typing.
renameBox:HighlightText()
end
--- The action bar: one action and two tools (UI-23), all three drawn rather than spelled (UI-26).
---