Repository navigation
Expand file tree
/
Copy pathUI.lua
More file actions
5376 lines (5093 loc) · 181 KB
/
Copy pathUI.lua
File metadata and controls
5376 lines (5093 loc) · 181 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
-- DMorph for OctoWoW: the morph window.
--
-- Left: your character in a dressing room (your race's dress-up backdrop),
-- with the morphable slots around it. Right: tabs to browse every creature
-- model (a grid of 3D previews, or a list), skins for your mount, favourites, races and NPC looks,
-- weapon glows, items per slot, item sets and a wardrobe of saved outfits. Everything goes
-- through the DmorphOcto.* functions in DmorphOcto.lua, the same ones the chat
-- commands use.
--
-- No white flashes: a model frame draws its model white until the textures
-- have loaded. So every model here loads out of sight first, below an opaque
-- layer, and is raised above it once it has had time to finish. The character
-- preview keeps two PlayerModels for this and swaps them, and never reloads
-- one that is still loading.
--
-- 1.12 API: scripts read `this`/`arg1` instead of taking arguments, there is
-- no SetSize, lists use FauxScrollFrameTemplate, and regions that share a draw
-- layer have no fixed order, so whatever must stack sits on child frames with
-- explicit frame levels. 3D previews by display ID need ClassicAPI's
-- Model:SetDisplayInfo; without it the Models tab shows a list.
local M = DmorphOcto
local W, H = 1002, 610
local ART_W, ART_H, PLATE_H = 318, 383, 44
local PAGE_X, PAGE_Y, PAGE_W, PAGE_H = 352, -180, 630, 382
local ROW_HEIGHT, LIST_ROWS, LIST_WIDTH = 18, 15, 590
-- Every list tab (2.21.0, user: "all tabs with lists should have this same
-- layout"): the list on the left, a preview box on the right.
local BOX_W, LIST_W = 178, 410
local TILE_W, TILE_H, TILE_GAP, GRID_COLS = 128, 132, 6, 4
-- ClassicAPI dresses at most 8 NPC preview models at a time, so 8 tiles.
local PAGE_SIZE = 8
-- How long a model loads out of sight before it's shown.
local REVEAL = 0.45
-- The least time between two model changes in one preview (see LoadView).
local SETTLE = 0.6
-- After a morph the game rebuilds your character; a second change before it
-- has finished can mix the two looks' textures. Clicks closer than this wait.
local GATE = 0.35
local MIN_SCALE, MAX_SCALE = 0.6, 1.6
-- Zooming the character: how far it comes towards you (model units, about a
-- yard each), per mouse wheel notch and at most.
local ZOOM_STEP, ZOOM_MIN, ZOOM_MAX = 0.3, -1.5, 3
local MENU_ROWS, MENU_WIDTH = 20, 170
local WHITE = "Interface\\Buttons\\WHITE8X8"
local RACE_ICONS_FILE = "Interface\\Glues\\CharacterCreate\\UI-CharacterCreate-Races"
-- GetInventorySlotInfo() names, for the empty-slot icons.
local SLOT_KEYS = {
[1] = "HeadSlot", [3] = "ShoulderSlot", [4] = "ShirtSlot", [5] = "ChestSlot",
[6] = "WaistSlot", [7] = "LegsSlot", [8] = "FeetSlot", [9] = "WristSlot",
[10] = "HandsSlot", [15] = "BackSlot", [16] = "MainHandSlot",
[17] = "SecondaryHandSlot", [18] = "RangedSlot", [19] = "TabardSlot",
}
-- Paper-doll layout: slots down the left and right of the model.
local LEFT_SLOTS = { 1, 3, 15, 5, 4, 19 }
local RIGHT_SLOTS = { 9, 10, 6, 7, 8 }
-- Per race ID (DmorphOcto.RACES): the dress-up backdrop, and the male icon's
-- cell { left, right, top } in the character-create race icons, from the
-- client's CharacterCreate.lua. The female icon sits half the sheet lower.
local RACE_ART = { "Human", "Orc", "Dwarf", "NightElf", "Scourge", "Tauren", "Gnome", "Troll", "Goblin", "BloodElf" }
local RACE_ICONS = {
{ 0, 0.125, 0 }, { 0.375, 0.5, 0.25 }, { 0.125, 0.25, 0 }, { 0.375, 0.5, 0 }, { 0.125, 0.25, 0.25 },
{ 0, 0.125, 0.25 }, { 0.25, 0.375, 0 }, { 0.25, 0.375, 0.25 }, { 0.5, 0.625, 0 }, { 0.5, 0.625, 0.25 },
}
-- UnitRace() tokens whose dress-up backdrop has another name.
local ART_TOKENS = { HighElf = "BloodElf" }
-- Creature model entries by kind (DmorphOcto.KIND_*). Items and sets use 0 and 2.
local KIND_COLORS = { [0] = { 1, 1, 1 }, [1] = { 0.62, 0.76, 0.92 }, [2] = { 0.45, 1, 0.6 }, [3] = { 0.45, 1, 0.6 }, [4] = { 1, 0.82, 0.3 } }
local KIND_NOTES = {
[0] = "A creature from the world database.",
[1] = "No creature has this look, so it's named after its model file.",
[2] = "New in OctoWoW: a creature from Turtle WoW's database.",
[3] = "New in OctoWoW, named after its model file.",
[4] = "Ported from a later expansion: only on this PC (patch-Z.mpq), others see your own look.",
}
-- The top row, in order (3.0, user: "more professional, tidier"). A tab with `group` sits
-- in a smaller row under its parent, shown while that group is open. `name` keeps
-- the frame names of the old tab labels.
local TABS = {
{ key = "home", text = "My look", name = "Home" },
{ key = "sets", text = "Sets" },
{ key = "items", text = "Items" },
{ key = "slutmog", text = "Slutmog", group = "items" },
{ key = "extra", text = "Extras", name = "Extrawear" },
{ key = "glows", text = "Glows" },
{ key = "models", text = "Models" },
{ key = "races", text = "Races" },
{ key = "favourites", text = "Favourites", group = "models" },
{ key = "mounts", text = "Mounts" },
{ key = "wardrobe", text = "Loadouts", name = "Wardrobe" },
{ key = "weather", text = "World", name = "Weather" },
}
local TAB_GAP = 3
-- The gold star of the raid target icons marks favourites.
local STAR = "Interface\\TargetingFrame\\UI-RaidTargetingIcons"
local FAV_FILTERS = {
{ text = "All favourites" },
{ text = "Models", mount = false },
{ text = "Mounts", mount = true },
}
local frame -- the window, built the first time it opens
local ui = {
tabs = {}, pages = {}, slots = {}, raceButtons = {}, raceCells = {}, tiles = {}, page = 1,
creator = {}, creatorRows = {}, mountRows = {}, glowSlots = {}, iconAsked = {}, boxes = {},
}
-- Helpers of the preview boxes and the list tabs (one table: Lua 5.0 allows
-- 200 locals in a chunk and 32 upvalues in a function).
local P = {}
local currentTab = "home"
local itemSlot = 1 -- the slot the Items tab is browsing
local selectedOutfit
local pendingDelete
local buttonCount = 0
local function SetStatus(ok, message)
if not frame then
return
end
ui.status:SetText(message or "")
if ok then
ui.status:SetTextColor(0.6, 1, 0.6)
else
ui.status:SetTextColor(1, 0.4, 0.4)
end
end
-- 16296 -> "16,296"
local function Commas(n)
local text, out = tostring(n), ""
while strlen(text) > 3 do
out = "," .. strsub(text, -3) .. out
text = strsub(text, 1, -4)
end
return text .. out
end
-- 1 -> "1 item", 1234 -> "1,234 items"
local function Count(n, word)
if n == 1 then
return "1 " .. word
end
return Commas(n) .. " " .. word .. "s"
end
-- Steps through n positions, wrapping round.
local function Wrap(pos, step, n)
return math.mod(pos - 1 + step + n * 4, n) + 1
end
-- Window settings shared by all characters: views, filters, sorting, size.
local function Prefs()
local account = M.GetAccount()
if type(account.ui) ~= "table" then
account.ui = {}
end
local p = account.ui
if not M.MODEL_FILTERS[p.filter] then
p.filter = 1
end
if not M.ITEM_FILTERS[p.itemFilter] then
p.itemFilter = 1
end
if not M.SET_FILTERS[p.setFilter] then
p.setFilter = 1
end
if not M.QUALITY_FILTERS[p.itemQuality] then
p.itemQuality = 1
end
if not M.QUALITY_FILTERS[p.setQuality] then
p.setQuality = 1
end
-- The item kind per slot (cloth, dagger, ...), and the sets' armour.
if type(p.itemTypes) ~= "table" then
p.itemTypes = {}
end
for slot, kind in pairs(p.itemTypes) do
if not (M.SLOT_NAMES[slot] and M.ITEM_TYPE_NAMES[kind]) then
p.itemTypes[slot] = nil
end
end
if not M.ITEM_TYPE_NAMES[p.setType or 0] then
p.setType = nil
end
if not FAV_FILTERS[p.favFilter] then
p.favFilter = 1
end
if type(p.scale) ~= "number" or p.scale < MIN_SCALE or p.scale > MAX_SCALE then
p.scale = 1
end
return p
end
-- The look -------------------------------------------------------------------
-- 2.21.0, user: "neat like OctoBG and ShootyEPGP, but more vibrant". Flat dark
-- panels with 1 px borders (OctoBG's flat style, seen working in game),
-- DMorph's purple (the project page's #b46bff) for what's picked and hovered,
-- gold for what you have on, and Roboto once the client says it loaded.
local C = {
bg = { 0.05, 0.05, 0.06 }, panel = { 0.075, 0.075, 0.09 }, card = { 0.1, 0.095, 0.125 },
field = { 0.045, 0.045, 0.055 }, btn = { 0.15, 0.13, 0.2 }, line = { 0.25, 0.22, 0.32 },
lineHi = { 0.5, 0.38, 0.7 }, text = { 0.94, 0.93, 0.96 }, dim = { 0.62, 0.6, 0.68 },
accent = { 0.71, 0.42, 1 }, deep = { 0.29, 0.15, 0.5 }, gold = { 1, 0.82, 0.3 },
}
local FONTS = { friz = "Fonts\\FRIZQT__.TTF", roboto = "Interface\\AddOns\\DmorphOcto\\media\\fonts\\FiraSansCondensed-Regular.ttf",
semi = "Interface\\AddOns\\DmorphOcto\\media\\fonts\\FiraSansCondensed-SemiBold.ttf", title = "Fonts\\MORPHEUS.TTF" }
-- A failed SetFont keeps the old font, so GetFont tells whether Fira loaded
-- (a font file added while the game runs needs a game restart).
local function UIFont()
if not FONTS.ui then
FONTS.ui = FONTS.friz
FONTS.bold = FONTS.friz
local probe = UIParent:CreateFontString(nil, "OVERLAY")
probe:SetFont(FONTS.roboto, 12, "")
local now = probe:GetFont()
if type(now) == "string" and strlower(string.gsub(now, "/", "\\")) == strlower(FONTS.roboto) then
FONTS.ui = FONTS.roboto
FONTS.bold = FONTS.semi
end
end
return FONTS.ui
end
-- Fira Condensed is narrow: one point up everywhere reads better and still fits.
local function Font(fs, size, col, bold)
local face = UIFont()
fs:SetFont(bold and FONTS.bold or face, (size or 11) + 1, "")
fs:SetShadowColor(0, 0, 0, 0.85)
fs:SetShadowOffset(1, -1)
col = col or C.text
fs:SetTextColor(col[1], col[2], col[3])
return fs
end
-- A frame drawn flat: a colour inside a 1 px line.
local function Flat(f, col, line, alpha)
f:SetBackdrop({ bgFile = WHITE, edgeFile = WHITE, tile = false, tileSize = 0, edgeSize = 1,
insets = { left = 1, right = 1, top = 1, bottom = 1 } })
col, line = col or C.panel, line or C.line
f:SetBackdropColor(col[1], col[2], col[3], alpha or 1)
f:SetBackdropBorderColor(line[1], line[2], line[3], 1)
end
-- A purple wash that shows on hover and while locked (LockHighlight).
local function Hover(f, alpha)
local hl = f:CreateTexture(nil, "HIGHLIGHT")
hl:SetTexture(WHITE)
hl:SetVertexColor(C.accent[1], C.accent[2], C.accent[3], alpha or 0.22)
hl:SetPoint("TOPLEFT", f, "TOPLEFT", 1, -1)
hl:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -1, 1)
return hl
end
-- Widget helpers --------------------------------------------------------------
-- The template names are only for the size and colour they imply.
local LABEL_LOOK = {
GameFontNormalLarge = { 15, C.accent }, GameFontNormal = { 12, C.gold },
GameFontHighlight = { 12, C.text }, GameFontHighlightSmall = { 11, C.text },
GameFontNormalSmall = { 11, C.gold }, GameFontDisableSmall = { 10, C.dim },
GameFontRedSmall = { 11, { 1, 0.42, 0.42 } },
}
local function Label(parent, text, font, x, y, name)
local label = parent:CreateFontString(name, "OVERLAY", font or "GameFontNormalSmall")
local look = LABEL_LOOK[font or "GameFontNormalSmall"]
if look then
Font(label, look[1], look[2], font == "GameFontNormal" or font == "GameFontNormalLarge")
end
label:SetPoint("TOPLEFT", parent, "TOPLEFT", x, y)
label:SetJustifyH("LEFT")
label:SetText(text)
return label
end
-- A flat button; b:SetText works (its own font string), LockHighlight keeps
-- the purple wash on (the picked one of a row of buttons).
local function FlatButton(button, text, size)
Flat(button, C.btn, C.line)
local label = button:CreateFontString(nil, "OVERLAY")
Font(label, size or 11, nil, true)
label:SetPoint("LEFT", button, "LEFT", 3, 0)
label:SetPoint("RIGHT", button, "RIGHT", -3, 0)
button:SetFontString(label)
button.label = label
Hover(button)
button:SetScript("OnMouseDown", function()
this:SetBackdropBorderColor(C.accent[1], C.accent[2], C.accent[3], 1)
end)
button:SetScript("OnMouseUp", function()
this:SetBackdropBorderColor(C.line[1], C.line[2], C.line[3], 1)
end)
button:SetText(text)
return button
end
local function Button(parent, text, width, x, y, onClick, name)
buttonCount = buttonCount + 1
local button = CreateFrame("Button", name or ("DmorphOctoButton" .. buttonCount), parent)
button:SetWidth(width)
button:SetHeight(22)
button:SetPoint("TOPLEFT", parent, "TOPLEFT", x, y)
FlatButton(button, text)
button:SetScript("OnClick", onClick)
return button
end
-- Greys a flat button out (it still shows its tooltip).
local function SetEnabled(button, on)
if on then
button:Enable()
button.label:SetTextColor(C.text[1], C.text[2], C.text[3])
else
button:Disable()
button.label:SetTextColor(0.4, 0.38, 0.45)
end
end
local function EditBox(parent, name, width, x, y, maxLetters)
local box = CreateFrame("EditBox", name, parent)
box:SetWidth(width)
box:SetHeight(20)
box:SetPoint("TOPLEFT", parent, "TOPLEFT", x, y)
Flat(box, C.field, C.line)
box:SetTextInsets(6, 6, 0, 0)
box:SetFont(UIFont(), 11, "")
box:SetTextColor(C.text[1], C.text[2], C.text[3])
box:EnableMouse(true)
box:SetAutoFocus(false)
box:SetMaxLetters(maxLetters or 40)
box:SetScript("OnEscapePressed", function()
this:ClearFocus()
end)
box:SetScript("OnEditFocusGained", function()
this:SetBackdropBorderColor(C.accent[1], C.accent[2], C.accent[3], 1)
end)
box:SetScript("OnEditFocusLost", function()
this:SetBackdropBorderColor(C.line[1], C.line[2], C.line[3], 1)
end)
return box
end
-- A flat panel in a colour (r, g, b), else the card colour.
local function Panel(f, r, g, b)
Flat(f, r and { r, g, b } or C.card, C.line)
end
-- A FauxScrollFrame's bar made flat: no arrow buttons, a thin track to the
-- right of the list and a purple thumb (OctoBG's FlatScroll). The mouse
-- wheel still scrolls.
local function FlatScroll(scroll)
local name = scroll:GetName()
local bar = getglobal(name .. "ScrollBar")
getglobal(name .. "ScrollBarScrollUpButton"):Hide()
getglobal(name .. "ScrollBarScrollDownButton"):Hide()
bar:ClearAllPoints()
bar:SetPoint("TOPLEFT", scroll, "TOPRIGHT", 6, 0)
bar:SetPoint("BOTTOMLEFT", scroll, "BOTTOMRIGHT", 6, 0)
bar:SetWidth(6)
local track = bar:CreateTexture(nil, "BACKGROUND")
track:SetTexture(WHITE)
track:SetVertexColor(C.field[1], C.field[2], C.field[3], 1)
track:SetAllPoints(bar)
bar:SetThumbTexture(WHITE)
local thumb = bar:GetThumbTexture()
if thumb then
thumb:SetWidth(6)
thumb:SetHeight(36)
thumb:SetVertexColor(C.accent[1], C.accent[2], C.accent[3], 0.85)
end
end
-- A texture with a vertical gradient, bottom colour first.
local function Gradient(parent, layer, r1, g1, b1, a1, r2, g2, b2, a2)
local texture = parent:CreateTexture(nil, layer)
texture:SetTexture(WHITE)
texture:SetGradientAlpha("VERTICAL", r1, g1, b1, a1, r2, g2, b2, a2)
return texture
end
-- A child frame at a fixed level above its parent (see the header).
local function Layer(parent, level)
local f = CreateFrame("Frame", nil, parent)
f:SetFrameLevel(parent:GetFrameLevel() + level)
return f
end
local function Tooltip(owner, title, line1, line2, line3)
GameTooltip:SetOwner(owner, "ANCHOR_TOP")
GameTooltip:SetText(title)
if line1 then
GameTooltip:AddLine(line1, 1, 1, 1)
end
if line2 then
GameTooltip:AddLine(line2, 0.8, 0.8, 0.8)
end
if line3 then
GameTooltip:AddLine(line3, 0.2, 1, 0.6)
end
GameTooltip:Show()
end
local function HideTooltip()
GameTooltip:Hide()
end
-- Runs fn once typing has paused, so long lists aren't filtered per key.
local function Debounce(timer, delay, fn)
timer.wait = delay
timer.callback = fn
timer:Show()
end
local function NewTimer()
local timer = CreateFrame("Frame", nil, frame)
timer:Hide()
timer:SetScript("OnUpdate", function()
this.wait = this.wait - arg1
if this.wait <= 0 then
this:Hide()
this.callback()
end
end)
return timer
end
-- Every morph from the window goes through here. The game rebuilds your
-- character after each change, and a change that lands while it is still
-- rebuilding can leave the earlier look's textures on it. So a click within
-- GATE seconds of the last one waits, and only the latest waiting one runs.
local function Morph(fn, a1, a2)
if ui.gateBusy then
ui.gateNext = { fn, a1, a2 }
return
end
ui.gateBusy = true
SetStatus(fn(a1, a2))
Debounce(ui.gateTimer, GATE, function()
ui.gateBusy = nil
local nextCall = ui.gateNext
ui.gateNext = nil
if nextCall then
Morph(nextCall[1], nextCall[2], nextCall[3])
end
end)
end
-- A drop-down menu shared by every filter button. options: a list of
-- { text = ..., checked = true/nil, header = true/nil }; pick(option) runs when
-- one is clicked. Clicking the same button again closes it.
local function OpenMenu(anchor, options, pick, above)
local menu = ui.menu
if menu:IsShown() and menu.anchor == anchor then
menu:Hide()
return
end
menu.anchor, menu.pick = anchor, pick
local count = math.min(table.getn(options), MENU_ROWS)
for i = 1, MENU_ROWS do
local row, option = menu.rows[i], options[i]
if option then
row.option = option
row.label:SetText(option.text)
if option.header then
row.label:SetTextColor(C.accent[1], C.accent[2], C.accent[3])
row:Disable()
else
row.label:SetTextColor(C.text[1], C.text[2], C.text[3])
row:Enable()
end
if option.checked then
row.check:Show()
else
row.check:Hide()
end
row:Show()
else
row:Hide()
end
end
menu:SetHeight(count * 18 + 12)
menu:ClearAllPoints()
if above then
menu:SetPoint("BOTTOMLEFT", anchor, "TOPLEFT", 0, 2)
else
menu:SetPoint("TOPLEFT", anchor, "BOTTOMLEFT", 0, -2)
end
menu:Show()
end
local function BuildMenu()
local menu = CreateFrame("Frame", "DmorphOctoMenu", frame)
menu:Hide()
menu:SetFrameLevel(frame:GetFrameLevel() + 40)
menu:SetWidth(MENU_WIDTH)
menu:EnableMouse(true)
Flat(menu, C.panel, C.accent)
menu.rows = {}
for i = 1, MENU_ROWS do
local row = CreateFrame("Button", "DmorphOctoMenuRow" .. i, menu)
row:SetFrameLevel(menu:GetFrameLevel() + 1)
row:SetWidth(MENU_WIDTH - 12)
row:SetHeight(18)
row:SetPoint("TOPLEFT", menu, "TOPLEFT", 6, -6 - (i - 1) * 18)
Hover(row, 0.3)
row.check = row:CreateTexture(nil, "ARTWORK")
row.check:SetTexture("Interface\\Buttons\\UI-CheckBox-Check")
row.check:SetWidth(16)
row.check:SetHeight(16)
row.check:SetPoint("LEFT", row, "LEFT", 0, 0)
row.label = Font(row:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall"), 11)
row.label:SetPoint("LEFT", row, "LEFT", 18, 0)
row:SetScript("OnClick", function()
ui.menu:Hide()
ui.menu.pick(this.option)
end)
menu.rows[i] = row
end
return menu
end
-- A scrolling list of LIST_ROWS rows over a FauxScrollFrame. fill(row, index)
-- draws entry `index` (row.text, row.info), click(index, mouseButton) handles
-- a click, enter(index, row) a hover. infoWidth is the right-hand column.
local function List(parent, name, x, y, infoWidth, fill, click, enter, width, rows)
local list = { rows = {}, count = 0 }
local LIST_ROWS = rows or LIST_ROWS
width = width or LIST_WIDTH
local scroll = CreateFrame("ScrollFrame", name, parent, "FauxScrollFrameTemplate")
scroll:SetPoint("TOPLEFT", parent, "TOPLEFT", x, y)
scroll:SetWidth(width)
scroll:SetHeight(LIST_ROWS * ROW_HEIGHT)
FlatScroll(scroll)
-- The list sits on a dark well, a line round it.
local well = CreateFrame("Frame", nil, parent)
well:SetPoint("TOPLEFT", scroll, "TOPLEFT", -1, 1)
well:SetPoint("BOTTOMRIGHT", scroll, "BOTTOMRIGHT", 1, -1)
well:SetFrameLevel(scroll:GetFrameLevel())
Flat(well, C.field, C.line)
function list.Refresh()
local offset = FauxScrollFrame_GetOffset(scroll) or 0
for i = 1, LIST_ROWS do
local row = list.rows[i]
local index = offset + i
if index <= list.count then
row.index = index
row:UnlockHighlight()
row.star:Hide()
row.tick:Hide()
row.text:SetTextColor(C.text[1], C.text[2], C.text[3])
fill(row, index)
row:Show()
else
row:Hide()
end
end
FauxScrollFrame_Update(scroll, list.count, LIST_ROWS, ROW_HEIGHT)
end
-- Scrolls so that entry `index` is the top row.
function list.ScrollTo(index)
local offset = index - 1
if offset > list.count - LIST_ROWS then
offset = list.count - LIST_ROWS
end
if offset < 0 then
offset = 0
end
FauxScrollFrame_SetOffset(scroll, offset)
getglobal(name .. "ScrollBar"):SetValue(offset * ROW_HEIGHT)
list.Refresh()
end
-- Scrolls entry `index` into view (about the middle) if it isn't.
function list.Show(index)
local top = list.GetOffset() + 1
if index < top or index > top + LIST_ROWS - 1 then
list.ScrollTo(index - math.floor(LIST_ROWS / 2))
else
list.Refresh()
end
end
-- New contents: back to the top, unless keep is set.
function list.SetCount(count, keep)
list.count = count
if keep then
list.Refresh()
else
list.ScrollTo(1)
end
end
function list.GetOffset()
return FauxScrollFrame_GetOffset(scroll) or 0
end
scroll:SetScript("OnVerticalScroll", function()
FauxScrollFrame_OnVerticalScroll(ROW_HEIGHT, list.Refresh)
end)
for i = 1, LIST_ROWS do
local row = CreateFrame("Button", name .. "Row" .. i, parent)
-- Above the scroll frame, so clicks reach the rows.
row:SetFrameLevel(scroll:GetFrameLevel() + 1)
row:SetWidth(width)
row:SetHeight(ROW_HEIGHT)
row:SetPoint("TOPLEFT", parent, "TOPLEFT", x, y - (i - 1) * ROW_HEIGHT)
row:RegisterForClicks("LeftButtonUp", "RightButtonUp")
if math.mod(i, 2) == 0 then
local stripe = row:CreateTexture(nil, "BACKGROUND")
stripe:SetTexture(WHITE)
stripe:SetVertexColor(1, 1, 1, 0.03)
stripe:SetAllPoints(row)
end
Hover(row, 0.24)
row.text = Font(row:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall"), 11)
row.text:SetPoint("LEFT", row, "LEFT", 6, 0)
row.text:SetWidth(width - infoWidth - 14)
row.text:SetHeight(ROW_HEIGHT)
row.text:SetJustifyH("LEFT")
row.info = Font(row:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall"), 10, C.dim)
row.info:SetPoint("RIGHT", row, "RIGHT", -6, 0)
row.info:SetWidth(infoWidth)
row.info:SetHeight(ROW_HEIGHT)
row.info:SetJustifyH("RIGHT")
row.star = row:CreateTexture(nil, "OVERLAY")
row.star:SetTexture(STAR)
row.star:SetTexCoord(0, 0.25, 0, 0.25)
row.star:SetWidth(12)
row.star:SetHeight(12)
row.star:SetPoint("RIGHT", row, "RIGHT", -infoWidth - 10, 0)
row.star:Hide()
-- The tick marks the entry you have on (the Mounts tab's skin).
row.tick = row:CreateTexture(nil, "OVERLAY")
row.tick:SetTexture("Interface\\Buttons\\UI-CheckBox-Check")
row.tick:SetWidth(16)
row.tick:SetHeight(16)
row.tick:SetPoint("RIGHT", row, "RIGHT", -infoWidth - 24, 0)
row.tick:Hide()
row:EnableMouseWheel(true)
row:SetScript("OnMouseWheel", function()
local bar = getglobal(name .. "ScrollBar")
bar:SetValue(bar:GetValue() - arg1 * ROW_HEIGHT * 3)
end)
row:SetScript("OnClick", function()
click(this.index, arg1)
end)
if enter then
row:SetScript("OnEnter", function()
enter(this.index, this)
end)
-- The preview box keeps the last row hovered, so the mouse can go over
-- to it (user, 19 Oct: it went back as soon as the mouse left the row).
-- It shows what you have on again after a change (list.leave).
row:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
end
list.rows[i] = row
end
return list
end
-- Sorting by name or by ID: a toggle button for every list that has one.
local function SortButton(page, name, x, y, key, refilter)
local button = Button(page, "", 92, x, y, function()
local prefs = Prefs()
prefs[key] = not prefs[key]
this:SetText(prefs[key] and "Sort: ID" or "Sort: A-Z")
refilter()
end, name)
button:SetText(Prefs()[key] and "Sort: ID" or "Sort: A-Z")
button:SetScript("OnEnter", function()
Tooltip(this, "Sort order", "Click to list by name (A-Z) or by ID.")
end)
button:SetScript("OnLeave", HideTooltip)
return button
end
-- Creature previews -------------------------------------------------------------
-- A view is a Model that shows a display ID. It loads at level `low`, below
-- an opaque layer, and moves up to `high` once REVEAL has passed. aspect:
-- the model frame's width / height. zoom (steps), panX / panY (parts of the
-- view's height) are the user's (preview boxes).
-- 2.21.8 (user: "I can't drag the model around or zoom in myself, use the
-- same controls as the character window"): a plain Model with a camera set
-- ignores SetPosition and SetFacing, the dressing room's PlayerModel moves
-- and turns. So views are PlayerModels when ClassicAPI's SetDisplayInfo works
-- on one (ui.playerViews, checked once), else Models as before.
local function NewView(parent, name, low, high, aspect)
local model = CreateFrame(ui.playerViews and "PlayerModel" or "Model", name, parent)
model:SetFrameLevel(low)
return { model = model, low = low, high = high, facing = 0, aspect = aspect or 1, zoom = 0, panX = 0, panY = 0,
player = ui.playerViews }
end
-- Turns a view (PlayerModels turn with SetRotation, Models with SetFacing).
function P.TurnView(view)
if view.player then
view.model:SetRotation(view.facing or 0)
else
view.model:SetFacing(view.facing or 0)
end
end
-- The whole model in view (2.21.0; user: the previews were "zoomed in too
-- much"). Seen in game with /dmorph frametest (19 Oct): while a model camera
-- is set, this client draws the model where the camera says and ignores
-- SetPosition and SetFacing (only the scale shows), so 2.21.0-2.21.6's
-- "scale to fit and move the middle to the camera" left models cut off or
-- out of view. Now nothing is moved: a model with a full-body camera
-- ("character info", type 1, Blizzard's own framing of the whole model:
-- 2,918 of 2,984 ported models, 389 of 679 stock ones, Data/ModelFrames.lua)
-- is shown through it; the rest keep the portrait camera (the head), as
-- before 2.21. Zoom is the scale on top. While a model loads (view.fresh)
-- the camera and the scale (a hair off every other frame) are sent again:
-- the client seems to drop them when loading ends.
P.ZOOM_FACTOR = 1.25
-- The client's trig functions take degrees or radians depending on its build.
P.ANGLE = math.sin(math.pi / 2) > 0.99 and 1 or 180 / math.pi
-- The camera a display is shown through: 1 (full body) if it has one, else 0.
function P.ViewCamera(displayID)
local _, _, _, _, _, _, _, _, _, full = M.GetModelFrame(displayID)
return full and 1 or 0
end
P.PLAYER_SIZE = 2.2 -- about a player's height in model units
local function FrameView(view)
local zoom = math.pow(P.ZOOM_FACTOR, view.zoom or 0)
if view.fresh then
view.flip = not view.flip
if view.flip then
zoom = zoom * 1.001
end
end
-- 2.21.9 (user: still no drag or zoom with 2.21.8): a PlayerModel gets no
-- camera of the model's (an explicit SetCamera locks it, as in the frame
-- test); like the dressing room it keeps its own player-sized view, where
-- moving and turning work. The model is scaled to a player's height
-- (P.PLAYER_SIZE) from Data/ModelFrames.lua, so it fits that view as you do
-- (a big creature morph filled the dressing room before), then zoom and
-- pan move it as the dressing room does.
if view.player then
local _, _, _, _, _, _, _, height, width = M.GetModelFrame(view.loaded)
local fit = 1
if height then
fit = P.PLAYER_SIZE / math.max(height, width * 0.75)
end
view.model:SetModelScale(fit * ((view.fresh and view.flip) and 1.001 or 1))
view.model:SetPosition((view.zoom or 0) * 0.3, (view.panX or 0) * 2, (view.panY or 0) * 2)
return
end
view.model:SetModelScale(zoom)
end
local function StartView(view, displayID)
local model = view.model
view.loaded = displayID
view.settle = SETTLE
-- Seconds the framing is pushed through while the model loads (FrameView).
view.fresh = 4
-- Drop the old model and its skins first, so none carry over to the new one.
pcall(model.ClearModel, model)
model:SetDisplayInfo(displayID)
-- Its full-body camera if it has one, else the portrait camera (P.ViewCamera);
-- a Model has no light of its own.
if not view.player then
view.camera = P.ViewCamera(displayID)
pcall(model.SetCamera, model, view.camera)
end
pcall(model.SetLight, model, 1, 0, 0, -0.7, -0.7, 0.7, 1, 1, 1, 0.8, 1, 1, 1)
P.TurnView(view)
FrameView(view)
end
-- Clearing a model whose textures are still loading frees them twice (the
-- game's Texture.cpp "Memory Invalid Block" crash, from ClearModel, when
-- hovering or paging fast). So a view changes model at most once per SETTLE;
-- a newer ID waits, and only the latest one is loaded.
local function LoadView(view, displayID)
view.displayID = displayID
if not view.manual then
view.facing = 0
end
view.wait = REVEAL
view.model:SetFrameLevel(view.low)
if view.settle then
view.pending = displayID
return
end
view.pending = nil
StartView(view, displayID)
end
-- Per frame: start a waiting model once the last one has settled, reveal a
-- loaded model, and turn it slowly while `spin` is set.
-- (Plain Model frames turn with SetFacing; SetRotation is PlayerModel's.)
local function TickView(view, elapsed, spin)
if view.settle then
view.settle = view.settle - elapsed
if view.settle <= 0 then
view.settle = nil
local pending = view.pending
view.pending = nil
if pending and pending ~= view.loaded then
view.wait = REVEAL
StartView(view, pending)
end
end
end
if view.settle and view.pending then
return
end
if view.wait then
view.wait = view.wait - elapsed
if view.wait <= 0 then
view.wait = nil
view.model:SetFrameLevel(view.high)
end
end
if not view.loaded then
return
end
-- A loading model forgets its scale, place and camera, so they go on every
-- frame, and are pushed through while it is fresh.
if view.fresh then
view.fresh = view.fresh - elapsed
if view.fresh <= 0 then
view.fresh = nil
end
if not view.player then
pcall(view.model.SetCamera, view.model, view.camera or 0)
end
end
FrameView(view)
if spin and view.displayID and not view.manual then
view.facing = view.facing + elapsed * 1.6
end
P.TurnView(view)
end
local function KindColor(kind)
return KIND_COLORS[kind] or KIND_COLORS[0]
end
local function QualityColor(quality)
local color = ITEM_QUALITY_COLORS[quality or 1] or ITEM_QUALITY_COLORS[1]
return color.r, color.g, color.b
end
-- Character preview ---------------------------------------------------------------
-- The dress-up backdrop of the race you look like: your race morph, else your own.
local function ShowArt()
local state = M.GetState()
local art = state.race and RACE_ART[state.race]
if not art then
local _, token = UnitRace("player")
art = ART_TOKENS[token or ""] or token or "Human"
end
if art ~= ui.artName then
ui.artName = art
for i = 1, 4 do
ui.art[i]:SetTexture("Interface\\DressUpFrame\\DressUpBackground-" .. art .. i)
end
end
end
local function UpdatePlate()
local state = M.GetState()
local title, info
if state.display then
title = M.GetDisplayName(state.display) or "Unlisted model"
info = "Display ID " .. state.display
elseif state.race then
title = M.DescribeBody(state.race, state.gender)
info = "Race morph"
else
title = UnitName("player") or "Your character"
info = "Not morphed"
end
local count = 0
for _ in pairs(state.items) do
count = count + 1
end
-- Short words: the line wrapped into the name above it (user, 18 Oct).
if count == 1 then
info = info .. " - 1 item"
elseif count > 1 then
info = info .. " - " .. count .. " items"
end
if state.mount then
info = info .. " - mount skin"
end
if state.scale then
info = info .. " - size " .. math.floor(state.scale * 100 + 0.5) .. "%"
end
P.RefreshQuick()
ui.plateTitle:SetText(title)
ui.plateInfo:SetText(info)
-- The size slider shows the picked size without picking it again.
if ui.sizeSlider then
ui.sizeSync = true
ui.sizeSlider:SetValue(state.scale or 1)
ui.sizeSync = nil
ui.sizeBox:SetText(math.floor((state.scale or 1) * 100 + 0.5))
end
end
local RequestPreview
-- The new look has loaded behind the backdrop: bring it to the front.
-- Puts a preview model where the zoom and the panning say. Closer also means
-- a little lower, so zooming in heads for the face rather than the belt.
local function ApplyView(model)
local p = ui.preview
model:SetPosition(p.zoom, p.panX, p.panY - p.zoom * 0.28)
-- The creature view (P.StageCreature) follows the same zoom, turn and pan.
local v = ui.stageView
if v then
v.zoom, v.facing, v.manual = p.zoom / ZOOM_STEP, p.rotation, true
v.panX, v.panY = p.panX / 3, p.panY / 3
end
end
-- 2.21.3 (user's screenshots: a big creature morph filled the dressing room):
-- morphed into a creature with frame data, the stage shows that display in a
-- creature view framed like the preview boxes, not your character (item
-- morphs don't show on creatures anyway).
function P.StageCreature()
local display = M.GetState().display
if ui.canPreview and ui.stageView and display and M.GetModelFrame(display) then
return display
end
end
local function Zoom(step)
local p = ui.preview
p.zoom = math.max(ZOOM_MIN, math.min(ZOOM_MAX, p.zoom + step * ZOOM_STEP))
ApplyView(p.models[p.front])
end
local function ResetView()
local p = ui.preview
p.zoom, p.panX, p.panY = 0, 0, 0
ApplyView(p.models[p.front])
end
local function SwapPreview()
local p = ui.preview
p.front = 3 - p.front
local front, back = p.models[p.front], p.models[3 - p.front]
front:SetRotation(p.rotation)
ApplyView(front)
front:SetFrameLevel(p.high)
back:SetFrameLevel(p.low)
back:Hide()
p.loading = nil
if p.again then
p.again = nil
RequestPreview()
end
end
-- A model is only reloaded once it has finished loading: changes made while
-- it loads are picked up by one more load afterwards. Reloading it half way
-- can leave textures from the earlier look on it.
local function LoadPreview()
local p = ui.preview
local creature = P.StageCreature()
local v = ui.stageView
if creature then
p.models[1]:Hide()
p.models[2]:Hide()
v.model:Show()
ApplyView(v.model)
if v.displayID ~= creature then
LoadView(v, creature)
end
return
end
if v then
v.model:Hide()
v.displayID = nil
end
if p.loading then
p.again = true
return
end
p.loading = true
local back = p.models[3 - p.front]
back:SetFrameLevel(p.low)
back:Show()