-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcore.lua
1579 lines (1320 loc) · 43.7 KB
/
core.lua
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
------------------------------------------------------------
-- DressUp by Sonaza (https://sonaza.com)
-- Licensed under MIT License
-- See attached license text in file LICENSE
------------------------------------------------------------
local ADDON_NAME = ...;
local Addon = LibStub("AceAddon-3.0"):NewAddon(select(2, ...), ADDON_NAME, "AceEvent-3.0", "AceHook-3.0");
_G[ADDON_NAME] = Addon;
local AceDB = LibStub("AceDB-3.0");
local _;
-- A bunch of evil trickery, sorry!
BlizzDressUpFrame = DressUpFrame;
BlizzDressUpModel = DressUpModel;
BlizzDressUpFrameResetButton = DressUpFrameResetButton;
BlizzDressUpFrameCancelButton = DressUpFrameCancelButton;
BlizzDressUpFrameOutfitDropDown = DressUpFrameOutfitDropDown;
DressUpFrame = CustomDressUpFrame;
DressUpModel = CustomDressUpModel;
DressUpFrameResetButton = CustomDressUpFrameResetButton;
DressUpFrameCancelButton = CustomDressUpFrameCancelButton;
DressUpFrameOutfitDropDown = CustomDressUpFrameOutfitDropDown;
DRESSUP_WHISPER_TUTORIAL_TEXT = "Click here to whisper your previewed outfit to other players.|n|nNote: For the feature to work they must also have an up to date version of DressUp.";
tinsert(UISpecialFrames, "CustomDressUpFrame");
UIPanelWindows["CustomDressUpFrame"] = { area = "left", pushable = 2 };
local paperDollSlots = {
["CharacterHeadSlot"] = 1,
["CharacterNeckSlot"] = 2,
["CharacterShoulderSlot"] = 3,
["CharacterBackSlot"] = 15,
["CharacterChestSlot"] = 5,
["CharacterWristSlot"] = 9,
["CharacterHandsSlot"] = 10,
["CharacterWaistSlot"] = 6,
["CharacterLegsSlot"] = 7,
["CharacterFeetSlot"] = 8,
["CharacterFinger0Slot"] = 11,
["CharacterFinger1Slot"] = 12,
["CharacterTrinket0Slot"] = 13,
["CharacterTrinket1Slot"] = 14,
["CharacterMainHandSlot"] = 16,
["CharacterSecondaryHandSlot"] = 17,
};
local INVENTORY_SLOTS = {
["INVTYPE_HEAD"] = 1,
["INVTYPE_NECK"] = nil,
["INVTYPE_SHOULDER"] = 3,
["INVTYPE_BODY"] = 4,
["INVTYPE_CHEST"] = 5,
["INVTYPE_ROBE"] = 5,
["INVTYPE_WAIST"] = 6,
["INVTYPE_LEGS"] = 7,
["INVTYPE_FEET"] = 8,
["INVTYPE_WRIST"] = 9,
["INVTYPE_HAND"] = 10,
["INVTYPE_FINGER"] = nil,
["INVTYPE_TRINKET"] = nil,
["INVTYPE_CLOAK"] = 15,
["INVTYPE_WEAPON"] = 16,-- offhand 17,
["INVTYPE_SHIELD"] = 17,
["INVTYPE_2HWEAPON"] = 16,
["INVTYPE_WEAPONMAINHAND"] = 16,
["INVTYPE_WEAPONOFFHAND"] = 17,
["INVTYPE_HOLDABLE"] = 17,
["INVTYPE_RANGED"] = 16,
["INVTYPE_THROWN"] = nil,
["INVTYPE_RANGEDRIGHT"] = 16,
["INVTYPE_RELIC"] = nil,
["INVTYPE_TABARD"] = 19,
};
local INVENTORY_SLOT_NAMES = {
[1] = "HEADSLOT",
[3] = "SHOULDERSLOT",
[4] = "SHIRTSLOT",
[5] = "CHESTSLOT",
[6] = "WAISTSLOT",
[7] = "LEGSSLOT",
[8] = "FEETSLOT",
[9] = "WRISTSLOT",
[10] = "HANDSSLOT",
[15] = "BACKSLOT",
[16] = "MAINHANDSLOT",
[17] = "SECONDARYHANDSLOT",
[19] = "TABARDSLOT",
["HEADSLOT"] = 1,
["SHOULDERSLOT"] = 3,
["SHIRTSLOT"] = 4,
["CHESTSLOT"] = 5,
["WAISTSLOT"] = 6,
["LEGSSLOT"] = 7,
["FEETSLOT"] = 8,
["WRISTSLOT"] = 9,
["HANDSSLOT"] = 10,
["BACKSLOT"] = 15,
["MAINHANDSLOT"] = 16,
["SECONDARYHANDSLOT"] = 17,
["TABARDSLOT"] = 19,
};
local VISIBLE_SLOTS = {
1, 3, 4, 5, 6, 7, 8, 9, 10, 15, 16, 17, 19,
};
local HIDDEN_SOURCES_LIST = {
[77343] = true, -- Shoulder
[77344] = true, -- Helm
[77345] = true, -- Cloak
};
-- 1 - Human
-- 2 - Orc
-- 3 - Dwarf
-- 4 - Nightelf
-- 5 - Undead
-- 6 - Tauren
-- 7 - Gnome
-- 8 - Troll
-- 9 - Goblin
-- 10 - Bloodelf
-- 11 - Draenei
-- 22 - Worgen
-- 24 - Pandaren
-- 25 - Alliance Pandaren
-- 26 - Horde Pandaren
-- 27 - Nightborne
-- 28 - Highmountain Tauren
-- 29 - Void Elf
-- 30 - Lightforged Draenei
-- 31 - Zandalari Troll
-- 32 - Kultiran
-- 34 - Dark Iron Dwarf
-- 36 - Mag'har Orc
local RACES = {
"Human", "Dwarf", "Night Elf", "Gnome", "Draenei", "Worgen", "Void Elf", "Lightforged Draenei", "Dark Iron Dwarf", "Kultiran",
"Orc", "Undead", "Tauren", "Troll", "Blood Elf", "Goblin", "Nightborne", "Highmountain Tauren", "Mag'har Orc", "Zandalari Troll",
"Pandaren",
};
local RACE_IDS = {
1, 3, 4, 7, 11, 22, 29, 30, 34, 32,
2, 5, 6, 8, 10, 9, 27, 28, 36, 31,
24,
};
local NUM_RACE_IDS = 21;
local NUM_ALLIANCE_RACES = 10;
local NUM_HORDE_RACES = 10;
local CLASS_BACKGROUNDS = {
"Interface\\DRESSUPFRAME\\DressingRoomPaladin",
"Interface\\DRESSUPFRAME\\DressingRoomWarrior",
"Interface\\DRESSUPFRAME\\DressingRoomMonk",
"Interface\\DRESSUPFRAME\\DressingRoomDeathKnight",
"Interface\\DRESSUPFRAME\\DressingRoomShaman",
"Interface\\DRESSUPFRAME\\DressingRoomRogue",
"Interface\\DRESSUPFRAME\\DressingRoomWarlock",
"Interface\\DRESSUPFRAME\\DressingRoomPriest",
"Interface\\DRESSUPFRAME\\DressingRoomMage",
"Interface\\DRESSUPFRAME\\DressingRoomHunter",
"Interface\\DRESSUPFRAME\\DressingRoomDruid",
"Interface\\DRESSUPFRAME\\DressingRoomDemonHunter",
};
local NUM_CLASS_BACKGROUNDS = 11;
local NUM_MAX_BACKGROUNDS = NUM_RACE_IDS + NUM_CLASS_BACKGROUNDS;
local RACE_NAMES = {
[1] = "Human",
[3] = "Dwarf",
[4] = "NightElf",
[7] = "Gnome",
[11] = "Draenei",
[22] = "Worgen",
[2] = "Orc",
[5] = "Scourge",
[6] = "Tauren",
[8] = "Troll",
[10] = "BloodElf",
[9] = "Goblin",
[24] = "Pandaren",
[0] = "Pet",
[27] = "Nightborne",
[28] = "HighmountainTauren",
[29] = "VoidElf",
[30] = "LightforgedDraenei",
[31] = "ZandalariTroll",
[32] = "Kultiran",
[34] = "DarkIronDwarf",
[36] = "MagharOrc",
["Human"] = 1,
["Dwarf"] = 3,
["NightElf"] = 4,
["Gnome"] = 7,
["Draenei"] = 11,
["Worgen"] = 22,
["Orc"] = 2,
["Scourge"] = 5,
["Tauren"] = 6,
["Troll"] = 8,
["BloodElf"] = 10,
["Goblin"] = 9,
["Pandaren"] = 24,
["Pet"] = 0,
["Nightborne"] = 27,
["HighmountainTauren"] = 28,
["VoidElf"] = 29,
["LightforgedDraenei"] = 30,
["ZandalariTroll"] = 31,
["Kultiran"] = 32,
["DarkIronDwarf"] = 34,
["MagharOrc"] = 36,
}
function DressUpRaceDropdown_OnEnter(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
GameTooltip:AddLine("Change Preview Race");
GameTooltip:AddLine("Do note there are limitations to the previews and some races may look very wrong like having missing textures or 3D armor pieces not working correctly.", 1, 1, 1, true);
GameTooltip:AddLine("There is nothing that can be done about it so please just deal with it.", 1, 1, 1, true);
GameTooltip:AddLine("|nPatch 8.2.5 seems to have broken the model changing even further and a horror show awaits if you dare try changing the preview options here :)", 1, 1, 1, true);
GameTooltip:Show();
end
function DressUpRaceDropdown_OnLeave(self)
GameTooltip:Hide();
end
local tooltip = nil;
function Addon:GetRealItemLevel(itemLink, itemSlotId)
if (not itemLink) then return 0, 0; end
if (not DressUpInternalTooltip) then
tooltip = CreateFrame("GameTooltip", "DressUpInternalTooltip", UIParent, "GameTooltipTemplate");
end
tooltip:SetOwner(UIParent, "ANCHOR_NONE");
if (itemSlotId) then
tooltip:SetInventoryItem("player", itemSlotId);
else
tooltip:SetHyperlink(itemLink);
end
tooltip:Show();
local _, _, _, itemLevel = GetItemInfo(itemLink);
local numLines = math.min(5, tooltip:NumLines());
for row_index = 2, numLines do
local left = _G[tooltip:GetName() .. "TextLeft" .. row_index];
if (left) then
local currentItemLevel, defaultItemLevel = string.match(strtrim(left:GetText() or ""), "Item Level (%d+) ?%(?(%d*)%)?");
if (currentItemLevel ~= nil) then
currentItemLevel, defaultItemLevel = tonumber(currentItemLevel), tonumber(defaultItemLevel);
return currentItemLevel, defaultItemLevel or itemLevel;
end
end
end
return itemLevel, itemLevel;
end
local ILVL_MIN_COLOR = {255, 191, 116};
local ILVL_MAX_COLOR = {147, 231, 255};
local ILVL_COLOR_DIFF = {
ILVL_MAX_COLOR[1] - ILVL_MIN_COLOR[1],
ILVL_MAX_COLOR[2] - ILVL_MIN_COLOR[2],
ILVL_MAX_COLOR[3] - ILVL_MIN_COLOR[3],
};
function Addon:GetRangeColor(value, minvalue, maxvalue)
if (not value) then return "ffffff" end
local progress = (value - minvalue) / math.max(1, maxvalue - minvalue);
return string.format("%02x%02x%02x",
ILVL_MIN_COLOR[1] + ILVL_COLOR_DIFF[1] * progress,
ILVL_MIN_COLOR[2] + ILVL_COLOR_DIFF[2] * progress,
ILVL_MIN_COLOR[3] + ILVL_COLOR_DIFF[3] * progress
);
end
local MESSAGE_PATTERN = "|cffffae12DressUp|r %s";
function Addon:AddMessage(pattern, ...)
DEFAULT_CHAT_FRAME:AddMessage(MESSAGE_PATTERN:format(string.format(pattern, ...)));
end
function Addon:GetArtifactItemLevel()
local mainhand = GetInventoryItemLink("player", 16);
local offhand = GetInventoryItemLink("player", 17);
if (not mainhand) then return end
local _, _, quality = GetItemInfo(mainhand);
if (quality ~= 6) then return end
local mainhandItemLevel = Addon:GetRealItemLevel(mainhand, 16);
local offhandItemLevel = Addon:GetRealItemLevel(offhand, 17);
return math.max(mainhandItemLevel, offhandItemLevel or 0);
end
function Addon:UpdatePaperDollItemLevels()
local itemlevels = {};
local lowest = 999999;
local highest = 0;
for slotName, slotId in pairs(paperDollSlots) do
local realSlotId = slotId;
local artifactItemLevel;
if (realSlotId == 16 or realSlotId == 17) then
artifactItemLevel = Addon:GetArtifactItemLevel();
end
local link = GetInventoryItemLink("player", slotId);
if (link) then
if (artifactItemLevel) then
itemlevels[realSlotId] = artifactItemLevel;
lowest = math.min(lowest, artifactItemLevel or 1);
highest = math.max(highest, artifactItemLevel or 1);
else
local itemLevel, defaultItemLevel = Addon:GetRealItemLevel(link, realSlotId);
if (itemLevel) then
itemlevels[realSlotId] = itemLevel;
lowest = math.min(lowest, itemLevel or 1);
highest = math.max(highest, itemLevel or 1);
end
end
end
end
for slotName, slotId in pairs(paperDollSlots) do
local frame = _G[slotName .. "ItemLevel"];
local itemLevel = itemlevels[slotId];
if (itemLevel) then
if (self.db.global.ColorizedItemLevels) then
frame.value:SetText(("|cff%s%d|r"):format(Addon:GetRangeColor(itemLevel, lowest, highest), itemLevel));
else
frame.value:SetText(("%d"):format(itemLevel));
end
else
frame.value:SetText("");
end
end
end
local HEART_OF_AZEROTH_ITEM_ID = 158075;
function Addon:ShowItemLevels()
for slotName, slotId in pairs(paperDollSlots) do
local frame = _G[slotName .. "ItemLevel"];
frame:Show();
end
if (Addon:GetItemID(GetInventoryItemLink("player", 2)) == HEART_OF_AZEROTH_ITEM_ID) then
if (CharacterNeckSlot ~= nil and CharacterNeckSlot.RankFrame ~= nil) then
CharacterNeckSlot.RankFrame:ClearAllPoints();
CharacterNeckSlot.RankFrame:SetPoint("CENTER", CharacterNeckSlot, "TOP", 0, -5);
end
end
end
function Addon:HideItemLevels()
for slotName, slotId in pairs(paperDollSlots) do
local frame = _G[slotName .. "ItemLevel"];
frame:Hide();
end
if (Addon:GetItemID(GetInventoryItemLink("player", 2)) == HEART_OF_AZEROTH_ITEM_ID) then
if (CharacterNeckSlot ~= nil and CharacterNeckSlot.RankFrame ~= nil) then
CharacterNeckSlot.RankFrame:ClearAllPoints();
CharacterNeckSlot.RankFrame:SetPoint("CENTER", CharacterNeckSlot, "BOTTOM", 0, 5);
end
end
end
local ITEMLEVEL_VISIBILITY_HIDE = 0;
local ITEMLEVEL_VISIBILITY_ONALT = 1;
local ITEMLEVEL_VISIBILITY_SHOW = 2;
function Addon:MODIFIER_STATE_CHANGED()
if (self.db.global.ItemLevelVisibility == ITEMLEVEL_VISIBILITY_HIDE) then
Addon:HideItemLevels();
return;
end
if (self.db.global.ItemLevelVisibility == ITEMLEVEL_VISIBILITY_SHOW) then
Addon:ShowItemLevels();
return;
end
if (self.db.global.ItemLevelVisibility == ITEMLEVEL_VISIBILITY_ONALT) then
if (IsAltKeyDown()) then
Addon:ShowItemLevels();
else
Addon:HideItemLevels();
end
end
end
function Addon:OnInitialize()
local defaults = {
global = {
DimBackground = true,
HideGizmo = true,
DisableSidePanel = true,
ItemLevelVisibility = ITEMLEVEL_VISIBILITY_ONALT,
ColorizedItemLevels = true,
HideTabard = false,
HideWeapons = false,
HideShirt = false,
StartUndressed = false,
SaveCustomBackground = false,
CustomBackground = nil,
WhisperAlertShown = false,
ShowPanelButtons = true,
PromptForPreviews = true,
Size = {
Width = 384,
Height = 474,
},
},
};
self.db = AceDB:New("DressupDB", defaults);
if (self.db.global.HideItemLevel == true) then
self.db.global.ItemLevelVisibility = ITEMLEVEL_VISIBILITY_HIDE;
self.db.global.HideItemLevel = nil;
end
if (self.db.global.ItemLevelVisibility == ITEMLEVEL_VISIBILITY_SHOW) then
Addon:ShowItemLevels();
elseif (self.db.global.ItemLevelVisibility == ITEMLEVEL_VISIBILITY_HIDE) then
Addon:HideItemLevels();
end
if (not Addon.db.global.WhisperAlertShown) then
DressUpPreviewWhisperButton.Alert:Show();
end
if (not Addon.InitializeComms) then
error("You have updated the addon but only reloaded the interface. Please restart the game.", 1);
end
Addon:InitializeComms();
end
function DressUpPreviewWhisperButtonAlertCloseButton_OnClick(self)
DressUpPreviewWhisperButton.Alert:Hide();
Addon.db.global.WhisperAlertShown = true;
end
local DressUpModelOnEnter;
local DressUpModelOnLeave;
SLASH_DRESSUP1 = "/dressup";
SLASH_DRESSUP2 = "/dressingroom";
SlashCmdList["DRESSUP"] = function(msg)
local msg = strtrim(strlower(msg or ""));
if (msg == "reset" or msg == "resetsize") then
Addon:ResetWindowSize();
end
DressUpFrame_Show();
end
function Addon:OnEnable()
DressUpFrame:SetClampedToScreen(true);
DressUpFrame:SetMinResize(384, 474);
DressUpFrame:SetMaxResize(
min(GetScreenWidth() - 50, 950),
min(GetScreenHeight() - 50, 950)
);
local maxWidth, maxHeight = DressUpFrame:GetMaxResize();
if (self.db.global.Size.Width > maxWidth or self.db.global.Size.Height > maxHeight) then
Addon:ResetWindowSize();
else
DressUpFrame:SetSize(self.db.global.Size.Width, self.db.global.Size.Height);
end
DressUpModelOnEnter = DressUpModel:GetScript("OnEnter");
DressUpModelOnLeave = DressUpModel:GetScript("OnLeave");
Addon:RegisterEvent("PLAYER_EQUIPMENT_CHANGED");
Addon:RegisterEvent("MODIFIER_STATE_CHANGED");
Addon.ItemButtons = {};
Addon:InitializeItemButtons();
Addon:ResetItemButtons(true);
Addon:InitializeRaceMenu();
Addon:ToggleGizmo();
Addon:UpdateBackgroundDim();
-- Initialize hooks
Addon:HookScript(PaperDollFrame, "OnShow", function()
Addon:PAPERDOLL_OPENED()
end);
DressUpModel:SetScript("OnMouseWheel", function(self, delta)
if (not IsControlKeyDown()) then
Model_OnMouseWheel(self, delta);
else
Addon:SwitchBackground(delta);
end
end);
Addon:HookScript(DressUpModel, "OnMouseDown", function(self, button)
if (IsControlKeyDown() and button == "MiddleButton") then
Addon:SwitchBackground(0);
end
end);
Addon:HookScript(DressUpFrame, "OnShow", function()
Addon:ResetRaceSelect();
Addon:ResetItemButtons(true);
end);
Addon:HookScript(DressUpFrameResetButton, "OnClick", function()
Addon:ResetItemButtons(true);
Addon:ResetRaceSelect();
end);
hooksecurefunc(DressUpModel, "TryOn", function(self, ...) Addon:TryOn(...) end);
hooksecurefunc(DressUpModel, "Dress", function()
Addon:HideConditionalSlots();
end);
end
function Addon:UpdateButtonsVisibility()
if (Addon.db.global.ShowPanelButtons) then
DressupCharacterPanelSettingsButton:Show();
DressUpCharacterPanelWhisperButton:Show();
else
DressupCharacterPanelSettingsButton:Hide();
DressUpCharacterPanelWhisperButton:Hide();
end
end
function CustomDressUpFrameResize_OnEnter(self)
self.handle:SetTexCoord(0.5, 1, 0, 1);
SetCursor("Interface\\Cursor\\UI-Cursor-SizeRight");
end
function CustomDressUpFrameResize_OnLeave(self)
self.handle:SetTexCoord(0, 0.5, 0, 1);
SetCursor(nil);
end
function CustomDressUpFrameResize_OnUpdate(self, elapsed)
if (CustomDressUpFrame.sizing) then
Addon:UpdateBackgroundTexCoords();
end
end
function CustomDressUpFrameResize_OnMouseDown(self, button)
CustomDressUpFrame:StartSizing();
CustomDressUpFrame.sizing = true;
end
function CustomDressUpFrameResize_OnMouseUp(self, button)
CustomDressUpFrame:StopMovingOrSizing();
CustomDressUpFrame.sizing = false;
local width, height = CustomDressUpFrame:GetSize();
Addon.db.global.Size.Width = width;
Addon.db.global.Size.Height = height;
end
function Addon:ResetWindowSize()
CustomDressUpFrame:SetSize(384, 474);
local width, height = CustomDressUpFrame:GetSize();
Addon.db.global.Size.Width = width;
Addon.db.global.Size.Height = height;
end
function Addon:ToggleGizmo()
if (self.db.global.HideGizmo) then
DressUpModel:SetScript("OnEnter", nil);
DressUpModel:SetScript("OnLeave", nil);
if (DressUpModelControlFrame) then
DressUpModelControlFrame:Hide();
end
else
DressUpModel:SetScript("OnEnter", DressUpModelOnEnter);
DressUpModel:SetScript("OnLeave", DressUpModelOnLeave);
end
end
function DressupSettingsButton_OnLoad(self)
self:SetFrameLevel(self:GetParent():GetFrameLevel()+2);
end
function DressupSettingsButton_OnClick(self)
if (not Addon.ContextMenu) then
Addon.ContextMenu = CreateFrame("Frame", ADDON_NAME .. "ContextMenuFrame", UIParent, "UIDropDownMenuTemplate");
end
local contextMenuData = {
{
text = "DressUp Options", isTitle = true, notCheckable = true,
},
{
text = "Dim the preview background",
func = function()
Addon.db.global.DimBackground = not Addon.db.global.DimBackground;
Addon:UpdateBackgroundDim();
end,
checked = function() return Addon.db.global.DimBackground end,
isNotRadio = true,
},
{
text = "Save custom background",
func = function()
Addon.db.global.SaveCustomBackground = not Addon.db.global.SaveCustomBackground;
if (not Addon.db.global.SaveCustomBackground) then
Addon.db.global.CustomBackground = nil;
elseif (Addon.CustomBackground) then
Addon.db.global.CustomBackground = Addon.CustomBackground;
end
end,
checked = function() return Addon.db.global.SaveCustomBackground end,
isNotRadio = true,
},
{
text = "Hide model control gizmo",
func = function() Addon.db.global.HideGizmo = not Addon.db.global.HideGizmo; Addon:ToggleGizmo(); end,
checked = function() return Addon.db.global.HideGizmo end,
isNotRadio = true,
},
{
text = "Disable side panel preview (can't be toggled)",
--func = function() Addon.db.global.DisableSidePanel = not Addon.db.global.DisableSidePanel; end,
--checked = function() return Addon.db.global.DisableSidePanel end,
func = function() end,
checked = true,
isNotRadio = true,
disabled = true,
},
{
text = "Prompt when receiving preview whisper",
func = function() Addon.db.global.PromptForPreviews = not Addon.db.global.PromptForPreviews; end,
checked = function() return Addon.db.global.PromptForPreviews end,
isNotRadio = true,
},
{
text = " ", isTitle = true, notCheckable = true,
},
{
text = "Slot visibility", isTitle = true, notCheckable = true,
},
{
text = "Always start undressed",
func = function() Addon.db.global.StartUndressed = not Addon.db.global.StartUndressed; end,
checked = function() return Addon.db.global.StartUndressed end,
isNotRadio = true,
},
{
text = "Always hide tabard",
func = function() Addon.db.global.HideTabard = not Addon.db.global.HideTabard; end,
checked = function() return Addon.db.global.HideTabard end,
isNotRadio = true,
},
{
text = "Always hide weapons",
func = function() Addon.db.global.HideWeapons = not Addon.db.global.HideWeapons; end,
checked = function() return Addon.db.global.HideWeapons end,
isNotRadio = true,
},
{
text = "Always hide shirt",
func = function() Addon.db.global.HideShirt = not Addon.db.global.HideShirt; end,
checked = function() return Addon.db.global.HideShirt end,
isNotRadio = true,
},
{
text = " ", isTitle = true, notCheckable = true,
},
{
text = "Character Panel", isTitle = true, notCheckable = true,
},
{
text = "Show buttons on character panel",
func = function()
Addon.db.global.ShowPanelButtons = not Addon.db.global.ShowPanelButtons;
Addon:UpdateButtonsVisibility();
end,
isNotRadio = true,
checked = function() return Addon.db.global.ShowPanelButtons end,
},
{
text = "Always hide item levels",
func = function()
Addon.db.global.ItemLevelVisibility = ITEMLEVEL_VISIBILITY_HIDE;
Addon:HideItemLevels();
end,
checked = function() return Addon.db.global.ItemLevelVisibility == ITEMLEVEL_VISIBILITY_HIDE end,
},
{
text = "Show item level when holding alt",
func = function()
Addon.db.global.ItemLevelVisibility = ITEMLEVEL_VISIBILITY_ONALT;
Addon:MODIFIER_STATE_CHANGED();
end,
checked = function() return Addon.db.global.ItemLevelVisibility == ITEMLEVEL_VISIBILITY_ONALT end,
},
{
text = "Always show item levels",
func = function()
Addon.db.global.ItemLevelVisibility = ITEMLEVEL_VISIBILITY_SHOW;
Addon:ShowItemLevels();
end,
checked = function() return Addon.db.global.ItemLevelVisibility == ITEMLEVEL_VISIBILITY_SHOW end,
},
{
text = "Colorize item level numbers",
func = function()
Addon.db.global.ColorizedItemLevels = not Addon.db.global.ColorizedItemLevels;
Addon:UpdatePaperDollItemLevels()
end,
checked = function() return Addon.db.global.ColorizedItemLevels end,
isNotRadio = true,
},
{
text = " ", isTitle = true, notCheckable = true,
},
{
text = "Reset window size",
func = function()
Addon:ResetWindowSize()
end,
notCheckable = true,
},
};
Addon.ContextMenu:SetPoint("TOPLEFT", self, "TOPLEFT", 0, 0);
EasyMenu(contextMenuData, Addon.ContextMenu, "cursor", 0, 0, "MENU");
DropDownList1:ClearAllPoints();
DropDownList1:SetPoint("TOPLEFT", self, "BOTTOMLEFT", 0, 0);
DropDownList1:SetClampedToScreen(true);
end
function Addon:SetDressUpBackground(frame, fileName, classBackground)
local imageWidth = 318;
local imageHeight = 332;
if (not classBackground) then
fileName = fileName or "Orc";
frame.background:SetTexture("Interface\\AddOns\\DressUp\\media\\Background-" .. fileName);
else
imageWidth = 480;
imageHeight = 502;
frame.background:SetTexture(fileName);
end
Addon:UpdateBackgroundTexCoords(imageWidth, imageHeight);
Addon:UpdateBackgroundDim();
end
function Addon:UpdateBackgroundTexCoords(imageWidth, imageHeight)
if (imageWidth) then Addon.CurrentImageWidth = imageWidth end
if (imageHeight) then Addon.CurrentImageHeight = imageHeight end
if (not Addon.CurrentImageWidth or not Addon.CurrentImageHeight) then return end
local width, height = CustomDressUpModel:GetSize();
local ratio = width / height;
local left = Addon.CurrentImageWidth / 512;
local right = Addon.CurrentImageHeight / 512;
local origRatio = left / right;
local ow = left / 2;
local oh = right / 2;
local x, y = 1, 1;
if (ratio <= origRatio) then
x = ratio / origRatio;
else
y = origRatio / ratio;
end
local l, r, t, b = math.max(ow - ow * x, 0),
math.min(ow + ow * x, left),
math.max(oh - oh * y, 0),
math.min(oh + oh * y, right);
CustomDressUpBackground:SetTexCoord(l, r, t, b);
end
function Addon:UpdateBackgroundDim()
if (self.db.global.DimBackground) then
CustomDressUpBackground:SetVertexColor(0.52, 0.52, 0.52);
else
CustomDressUpBackground:SetVertexColor(1.0, 1.0, 1.0);
end
end
function Addon:ResetRaceSelect()
local _, raceID = UnitRace("player");
Addon.CustomBackground = nil;
Addon.SelectedRace = -1;
Addon.SelectedGender = UnitSex("player")-2;
if (Addon.SelectedGender == 0) then
DressUpGenderButtonMale:SetChecked(true);
DressUpGenderButtonFemale:SetChecked(false);
elseif (Addon.SelectedGender == 1) then
DressUpGenderButtonMale:SetChecked(false);
DressUpGenderButtonFemale:SetChecked(true);
end
DressUpModel:SetUnit("player");
if (self.db.global.SaveCustomBackground and self.db.global.CustomBackground) then
Addon.CustomBackground = self.db.global.CustomBackground;
Addon:SetCustomBackground(self.db.global.CustomBackground);
else
Addon:SetDressUpBackground(DressUpFrame, raceID);
end
UIDropDownMenu_SetText(DressUpRaceDropdown, "Change Preview Race");
end
function Addon:GetRaceIndex(raceID)
for k, id in ipairs(RACE_IDS) do
if (id == raceID) then return k end
end
return nil;
end
function Addon:SetCustomBackground(background_id)
if (not background_id) then return end
if (background_id == 0) then
Addon:SetDressUpBackground(DressUpFrame, "Pet");
elseif (background_id > 0 and background_id <= NUM_RACE_IDS) then
Addon:SetDressUpBackground(DressUpFrame, RACE_NAMES[RACE_IDS[background_id]]);
elseif (background_id > NUM_RACE_IDS) then
Addon:SetDressUpBackground(DressUpFrame, CLASS_BACKGROUNDS[background_id - NUM_RACE_IDS], true);
end
end
function Addon:SwitchBackground(dir)
if (dir == 0) then
Addon.CustomBackground = 0;
else
if (Addon.CustomBackground == nil or Addon.CustomBackground == 0) then
local id;
if (Addon.SelectedRace == -1) then
local _, raceId = UnitRace("player");
id = RACE_NAMES[raceId];
else
id = Addon.SelectedRace;
end
Addon.CustomBackground = Addon:GetRaceIndex(id);
dir = 0;
end
Addon.CustomBackground = Addon.CustomBackground - dir;
if (Addon.CustomBackground > NUM_MAX_BACKGROUNDS) then Addon.CustomBackground = 1 end
if (Addon.CustomBackground < 1) then Addon.CustomBackground = NUM_MAX_BACKGROUNDS end
end
if (self.db.global.SaveCustomBackground) then
self.db.global.CustomBackground = Addon.CustomBackground;
end
Addon:SetCustomBackground(Addon.CustomBackground);
end
function SetDressUpAlpha(alpha, brightness, desaturate)
local b = brightness;
if (DressUpFrame.BGTopLeft) then
DressUpFrame.BGTopLeft:SetVertexColor(b, b, b, alpha);
DressUpFrame.BGTopLeft:SetDesaturated(desaturate);
end
if (DressUpFrame.BGTopRight) then
DressUpFrame.BGTopRight:SetVertexColor(b, b, b, alpha);
DressUpFrame.BGTopRight:SetDesaturated(desaturate);
end
if (DressUpFrame.BGBottomLeft) then
DressUpFrame.BGBottomLeft:SetVertexColor(b, b, b, alpha);
DressUpFrame.BGBottomLeft:SetDesaturated(desaturate);
end
if (DressUpFrame.BGBottomRight) then
DressUpFrame.BGBottomRight:SetVertexColor(b, b, b, alpha);
DressUpFrame.BGBottomRight:SetDesaturated(desaturate);
end
end
function DressUpGenderButton_OnClick(self)
local gender = self:GetID();
CloseMenus();
if (Addon.SelectedGender ~= gender) then
DressUpModel:SetCustomRace(Addon.SelectedRace, gender);
Addon:ReapplyPreviewItems();
end
if (gender == 0) then
DressUpGenderButtonMale:SetChecked(true);
DressUpGenderButtonFemale:SetChecked(false);
elseif (gender == 1) then
DressUpGenderButtonMale:SetChecked(false);
DressUpGenderButtonFemale:SetChecked(true);
end
Addon.SelectedGender = gender;
end
function DressUpRaceDropdown_SelectOption(self)
Addon.SelectedRace = self.value.id;
DressUpModel:SetCustomRace(self.value.id, Addon.SelectedGender);
if (Addon.CustomBackground == nil) then
Addon:SetDressUpBackground(DressUpFrame, RACE_NAMES[self.value.id]);
end
UIDropDownMenu_SetText(DressUpRaceDropdown, self.value.name);
Addon:ReapplyPreviewItems();
end
function Addon:GenerateRaceMenu()
local menu = {};
local HordeThreshold = 1 + NUM_ALLIANCE_RACES;
local NeutralThreshold = HordeThreshold + NUM_HORDE_RACES;
local factions = {
[1] = "Alliance",
[HordeThreshold] = "Horde",
[NeutralThreshold] = "Neutral",
};
for k, v in ipairs(RACES) do
if (factions[k] ~= nil) then
if (k > 1) then
tinsert(menu, {
text = " ", isTitle = true, notCheckable = true,
});
end
tinsert(menu, {
text = factions[k], isTitle = true, notCheckable = true,
});
end
tinsert(menu, {
text = v,
value = {
id = RACE_IDS[k],
name = v,
},
func = DressUpRaceDropdown_SelectOption,
notCheckable = true,
});
end
return menu;
end
function DressUpRaceDropdown_OnClick()
if (DropDownList1:IsVisible()) then
CloseMenus();
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_OFF);
return end