-
Notifications
You must be signed in to change notification settings - Fork 24
/
OutfitterBar.lua
1694 lines (1308 loc) · 48.2 KB
/
OutfitterBar.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
-- Global Backdrops
BACKDROP_OUTFITTER_DIALOG_32_32 = {
bgFile = "Interface\\Addons\\Outfitter\\Textures\\DialogBox-Background",
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
tile = true,
tileSize = 32,
edgeSize = 32,
insets = { left = 11, right = 12, top = 12, bottom = 11 },
}
----------------------------------------
Outfitter.OutfitBar = {}
----------------------------------------
Outfitter.OutfitBar.UniqueNameIndex = 1
Outfitter.OutfitBar.cWildcardIcon = 134400
Outfitter.OutfitBar.cDefaultScriptIcons =
{
ArgentDawn = "INV_Jewelry_Talisman_07",
Riding = 132261,
Fishing = 136245,
Swimming = 136148,
City = 135022,
Battleground = 1376041,
AB = 1376041,
AV = 1376041,
WSG = 1376041,
EotS = 1376041,
Arena = 1376041,
Battle = 132355,
Defensive = 132341,
Berserker = 132347,
Bear = 132276,
Cat = 132115,
Aquatic = 132144,
Flight = 132144,
Travel = 132144,
Moonkin = 136096,
Tree = 136041,
Prowl = 132089,
Stealth = 132320,
Shadowform = 136200,
GhostWolf = 136095,
Cheetah = 132242,
Wild = 136074,
Feigning = 132293,
Evocate = 136075,
Solo = 132132,
LOW_HEALTH = 132293,
HAS_BUFF = 135826,
Dining = 134062,
Spirit = 135934,
Caster = 135157,
HERBALISM = 136246,
MINING = 134708,
SKINNING = 134366,
LOCKPICKING = 136058,
COOKING = 133971,
[Outfitter.cNakedOutfit] = 237360,
}
function Outfitter.OutfitBar:Construct()
self.Settings = Outfitter.Settings
if not self.Settings.OutfitBar then
self.Settings.OutfitBar = {}
end
-- Keep the default position handy in one place
self.DefaultPosition = {
RelativePoint = "TOPLEFT",
x = 200,
y = -200,
}
-- Set the default position if it's missing
if not self.Settings.OutfitBar.Position then
self.Settings.OutfitBar.Position = self.DefaultPosition
end
if self.Initialized
or not self.CanInitialize
or not self.Settings.OutfitBar.ShowOutfitBar then
return
end
if Outfitter.LBF and not Outfitter.LBFGroup then
Outfitter.LBFGroup = Outfitter.LBF:Group("Outfitter")
Outfitter.LBF:RegisterSkinCallback("Outfitter", Outfitter.LBFSkinCallback, Outfitter)
if self.Settings.LBFSettings then
Outfitter.LBFGroup:Skin(self.Settings.LBFSettings.SkinID, self.Settings.LBFSettings.Gloss, self.Settings.LBFSettings.Backdrop, self.Settings.LBFSettings.Colors)
end
end
self.Bars = {}
self.DragBar1 = Outfitter.OutfitBar._DragBar:New(self)
self.DragBar2 = Outfitter.OutfitBar._DragBar:New(self)
self:SetScale(self.Settings.OutfitBar.Scale or 1) -- This also sets the position
Outfitter:RegisterOutfitEvent("WEAR_OUTFIT", function () Outfitter.OutfitBar:ChangedOutfits() end)
Outfitter:RegisterOutfitEvent("UNWEAR_OUTFIT", function () Outfitter.OutfitBar:ChangedOutfits() end)
Outfitter:RegisterOutfitEvent("ADD_OUTFIT", function () Outfitter.OutfitBar:ChangedOutfits() end)
Outfitter:RegisterOutfitEvent("DELETE_OUTFIT", function () Outfitter.OutfitBar:ChangedOutfits() end)
Outfitter:RegisterOutfitEvent("EDIT_OUTFIT", function () Outfitter.OutfitBar:ChangedOutfits() end)
self.Initialized = true
self:Show()
end
function Outfitter.OutfitBar:InitializeSettings()
self.Settings = Outfitter.Settings
self.Settings.OutfitBar =
{
ShowOutfitBar = false,
Position = self.DefaultPosition
}
end
function Outfitter.OutfitBar:ResetPosition()
-- Set the position to the default
self.Settings.OutfitBar.Position = self.DefaultPosition
-- If the bar has been initialized then update it to reflect the new position
if self.Initialized then
self:UpdateBars2()
end
end
function Outfitter.OutfitBar:UpdateDragBarOrientation()
self.DragBar1:SetVerticalOrientation(self.Settings.OutfitBar.Vertical)
self.DragBar2:SetVerticalOrientation(self.Settings.OutfitBar.Vertical)
end
function Outfitter.OutfitBar:Show()
if not self.Initialized then
self:Construct()
end
if self.IsShown then
return
end
self.IsShown = true
self.DragBar1:Show()
self.DragBar2:Show()
self:ChangedOutfits()
end
function Outfitter.OutfitBar:Hide()
if not self.IsShown then
return
end
self.IsShown = false
self.DragBar1:Hide()
self.DragBar2:Hide()
for vIndex = 1, #self.Bars do
self.Bars[vIndex]:Hide()
end
end
function Outfitter.OutfitBar:AdjustAlpha()
if not self.Initialized then
return
end
self:SetAlpha(Outfitter.InCombat and self.Settings.OutfitBar.CombatAlpha or self.Settings.OutfitBar.Alpha or 1)
end
function Outfitter.OutfitBar:SetAlpha(pAlpha)
if self.LockedAlpha then
pAlpha = self.LockedAlpha
end
for vIndex = 1, #self.Bars do
self.Bars[vIndex]:SetAlpha(pAlpha)
end
end
function Outfitter.OutfitBar:SetLockedAlpha(pAlpha)
self.LockedAlpha = pAlpha
self:AdjustAlpha()
end
function Outfitter.OutfitBar:ShowBackground(pShow)
for vIndex = 1, #self.Bars do
self.Bars[vIndex]:ShowBackground(pShow)
end
end
function Outfitter.OutfitBar:SetScale(pScale)
self.DragBar1:SetScale(pScale)
self.DragBar2:SetScale(pScale)
for vIndex = 1, #self.Bars do
self.Bars[vIndex]:SetScale(pScale)
end
self:UpdateBars2()
end
function Outfitter.OutfitBar:DragBar_OnClick(button)
if button == "RightButton" then
if not self.SettingsDialog then
self.SettingsDialog = Outfitter.OutfitBar._SettingsDialog:New()
end
if self.SettingsDialog:IsVisible() then
self.SettingsDialog:HideDialog()
else
self.SettingsDialog:ShowDialog()
end
elseif self.SettingsDialog then
self.SettingsDialog:HideDialog()
end
end
function Outfitter.OutfitBar:SetShowOutfitBar(pShowBar)
self.Settings.OutfitBar.ShowOutfitBar = pShowBar
if pShowBar then
self:Show()
else
self:Hide()
end
end
function Outfitter.OutfitBar:GetOutfitSettings(pOutfit)
if not pOutfit.OutfitBar then
pOutfit.OutfitBar = {}
end
return pOutfit.OutfitBar
end
function Outfitter.OutfitBar:IsOutfitShown(pOutfit)
return not self:GetOutfitSettings(pOutfit).Hide
end
function Outfitter.OutfitBar:StartFrameFades(pForceDragBars)
if pForceDragBars or not self.Settings.OutfitBar.LockPosition then
UIFrameFadeOut(self.DragBar1, 0.3, 1, 0)
UIFrameFadeOut(self.DragBar2, 0.3, 1, 0)
end
if self.Settings.OutfitBar.Alpha and self.Settings.OutfitBar.Alpha ~= 1 then
for vIndex = 1, #self.Bars do
UIFrameFadeOut(self.Bars[vIndex], 0.5, 1, self.Settings.OutfitBar.Alpha)
end
end
end
function Outfitter.OutfitBar:StopFrameFades(pForceDragBars)
if pForceDragBars or not self.Settings.OutfitBar.LockPosition then
UIFrameFadeRemoveFrame(self.DragBar1)
UIFrameFadeRemoveFrame(self.DragBar2)
end
for vIndex = 1, #self.Bars do
UIFrameFadeRemoveFrame(self.Bars[vIndex])
end
end
function Outfitter.OutfitBar:ShowDragBars(pForceShow)
if pForceShow or not self.Settings.OutfitBar.LockPosition then
self.DragBar1:SetAlpha(1)
self.DragBar2:SetAlpha(1)
end
self:StopFrameFades(pForceShow)
self:SetLockedAlpha(1)
end
function Outfitter.OutfitBar:HideDragBars(pForceHide)
self.LockedAlpha = nil
self:StartFrameFades(pForceHide)
end
function Outfitter.OutfitBar:PositionChanged()
if not self.Settings.OutfitBar.Position then
self.Settings.OutfitBar.Position = {}
end
local vBarScale = self.Bars[1]:GetEffectiveScale()
local vUIScale = UIParent:GetEffectiveScale()
local vUILeft = UIParent:GetLeft() * vUIScale
local vUIRight = UIParent:GetRight() * vUIScale
local vUITop = UIParent:GetTop() * vUIScale
local vUIBottom = UIParent:GetBottom() * vUIScale
local vTopLeftBar = self.DidStackBackwards and self.Bars[#self.Bars] or self.Bars[1]
local vBottomRightBar = self.DidStackBackwards and self.Bars[1] or self.Bars[#self.Bars]
local vBarLeft = vTopLeftBar:GetLeft() * vBarScale
local vBarRight = vBottomRightBar:GetRight() * vBarScale
local vBarTop = vTopLeftBar:GetTop() * vBarScale
local vBarBottom = vBottomRightBar:GetBottom() * vBarScale
local vIsAnchorBottom = 0.5 * (vBarTop + vBarBottom) < 0.5 * (vUITop + vUIBottom)
local vIsAnchorRight = 0.5 * (vBarLeft + vBarRight) < 0.5 * (vUILeft + vUIRight)
if vIsAnchorBottom then
self.Settings.OutfitBar.Position.RelativePoint = "BOTTOM"
self.Settings.OutfitBar.Position.y = vBarBottom - vUIBottom
else
self.Settings.OutfitBar.Position.RelativePoint = "TOP"
self.Settings.OutfitBar.Position.y = vBarTop - vUITop
end
if vIsAnchorRight then
self.Settings.OutfitBar.Position.RelativePoint = self.Settings.OutfitBar.Position.RelativePoint.."LEFT"
self.Settings.OutfitBar.Position.x = vBarLeft - vUILeft
else
self.Settings.OutfitBar.Position.RelativePoint = self.Settings.OutfitBar.Position.RelativePoint.."RIGHT"
self.Settings.OutfitBar.Position.x = vBarRight - vUIRight
end
end
function Outfitter.OutfitBar:NewBar(pNumColumns, pNumRows)
local vName = "OutfitterOutfitBar"..self.UniqueNameIndex
self.UniqueNameIndex = self.UniqueNameIndex + 1
local vBar = CreateFrame("Frame", vName)
Outfitter.InitializeFrame(vBar, Outfitter._ButtonBar, self._Bar)
vBar:Construct(vName, pNumColumns, pNumRows)
vBar:SetScale(self.Settings.OutfitBar.Scale or 1)
vBar:ShowBackground(not self.Settings.OutfitBar.HideBackground)
return vBar
end
function Outfitter.OutfitBar:GetDefaultIcons(pOutfit)
local iconIDs = {}
local usedIconIDs = {}
-- See if the script has a default icon
local iconID = Outfitter.OutfitBar.cDefaultScriptIcons[pOutfit.ScriptID]
if iconID then
table.insert(iconIDs, iconID)
usedIconIDs[iconID] = true
end
-- See if the optimization has a default icon
iconID = Outfitter.OutfitBar.cDefaultScriptIcons[pOutfit.StatID]
if iconID and not usedIconIDs[iconID] then
table.insert(iconIDs, iconID)
end
-- See if the name has a default icon
iconID = Outfitter.OutfitBar.cDefaultScriptIcons[pOutfit:GetName()]
if iconID and not usedIconIDs[iconID] then
table.insert(iconIDs, iconID)
end
-- Done
return iconIDs
end
function Outfitter.OutfitBar:GetOutfitTexture(pOutfit)
if not pOutfit then
return 132662
end
-- If the icon specifies the texture then just use it
local vTexture = pOutfit:GetIcon()
if vTexture then
return vTexture
end
-- See if the outfit has a default icon
local vIcons = self:GetDefaultIcons(pOutfit)
if #vIcons > 0 then
return vIcons[1]
end
-- If it's a single-item outfit, use that item as the icon
local vOutfitItem
local vItems = pOutfit:GetItems()
for vInventorySlot, vItem in pairs(vItems) do
if not vOutfitItem then
vOutfitItem = vItem
else
vOutfitItem = nil
break
end
end
if vOutfitItem then
local vTexture = GetItemIcon(vOutfitItem.Code)
if vTexture then
return vTexture
end
end
-- Use a plain icon
return 132662
end
function Outfitter.OutfitBar:GetCursorTexture()
local vType, vParam1, vParam2 = GetCursorInfo()
if not vType then
return
end
if vType == "spell" then
return GetSpellTexture(vParam1, vParam2)
elseif vType == "item" then
for _, vInventorySlot in ipairs(Outfitter.cSlotNames) do
local vSlotID = Outfitter.cSlotIDs[vInventorySlot]
local vItemLink = Outfitter:GetInventorySlotIDLink(vSlotID)
if vItemLink == vParam2 then
return GetInventoryItemTexture("player", vSlotID)
end
end
local vNumBags, vFirstBagIndex = Outfitter:GetNumBags()
for vBagIndex = vFirstBagIndex, vNumBags do
local vNumBagSlots = C_Container.GetContainerNumSlots(vBagIndex)
for vBagSlotIndex = 1, vNumBagSlots do
local vItemLink = C_Container.GetContainerItemLink(vBagIndex, vBagSlotIndex)
if vItemLink == vParam2 then
local itemInfo = C_Container.GetContainerItemInfo(vBagIndex, vBagSlotIndex)
local vTexture = itemInfo.iconFileID
return vTexture
end
end
end
else
Outfitter:DebugMessage("OutfitBar: Unknown cursor type %s param1 %s param2 %s", vType, vParam1 or "nil", vParam2 or "nil")
end
end
function Outfitter.OutfitBar:ChangedOutfits()
self:UpdateBars()
end
function Outfitter.OutfitBar:PetBattleStarted()
self:Hide()
end
function Outfitter.OutfitBar:PetBattleFinished()
if self.Settings.OutfitBar.ShowOutfitBar then
self:Show()
end
end
function Outfitter.OutfitBar:UpdateBars()
if not self.IsShown then
return
end
-- Use a delayed task to update the bar to ensure performance
-- is not affected when there are multiple outfits being changed
-- simultaneously
Outfitter.SchedulerLib:ScheduleUniqueTask(0.01, self.UpdateBars2, self)
end
function Outfitter.OutfitBar:xor(a, b)
return (a or b) and not (a and b)
end
function Outfitter.OutfitBar:UpdateBars2()
Outfitter.SchedulerLib:UnscheduleTask(self.UpdateBars2, self)
-- Update the title bar orientation
self:UpdateDragBarOrientation()
--
local vIsAnchorBottom = string.sub(self.Settings.OutfitBar.Position.RelativePoint, 1, 6) == "BOTTOM"
local vIsAnchorRight = string.sub(self.Settings.OutfitBar.Position.RelativePoint, -5) == "RIGHT"
local vStackBackwards = (self.Settings.OutfitBar.Vertical and vIsAnchorBottom)
or (not self.Settings.OutfitBar.Vertical and vIsAnchorRight)
local vDragBarAnchor = (self:xor(self.Settings.OutfitBar.Vertical, vIsAnchorBottom) and "BOTTOM" or "TOP")..
(self:xor(self.Settings.OutfitBar.Vertical, vIsAnchorRight) and "LEFT" or "RIGHT")
self.DidStackBackwards = vStackBackwards
--
self.DragBar1:ClearAllPoints()
self.DragBar1:SetPoint(
vDragBarAnchor,
UIParent,
self.Settings.OutfitBar.Position.RelativePoint,
self.Settings.OutfitBar.Position.x / self.DragBar1:GetEffectiveScale(),
self.Settings.OutfitBar.Position.y / self.DragBar1:GetEffectiveScale())
-- Update the bars
local vBarIndex = 1
local vPreviousBar = self.DragBar1
local vCategoryOrder = Outfitter:GetCategoryOrder()
if vStackBackwards then
for vCategoryIndex = #vCategoryOrder, 1, -1 do
local vCategoryID = vCategoryOrder[vCategoryIndex]
if self:UpdateBar(vBarIndex, vCategoryID) then
local vBar = self.Bars[vBarIndex]
vBar:ClearAllPoints()
if self.Settings.OutfitBar.Vertical then
vBar:SetPoint("BOTTOMLEFT", vPreviousBar, "TOPLEFT")
else
vBar:SetPoint("TOPRIGHT", vPreviousBar, "TOPLEFT")
end
vAnchorOffsetX, vAnchorOffsetY = nil, nil
vBar:Show()
vBarIndex = vBarIndex + 1
vPreviousBar = vBar
end
end
self.DragBar2:ClearAllPoints()
if self.Settings.OutfitBar.Vertical then
self.DragBar2:SetPoint("BOTTOMLEFT", vPreviousBar, "TOPLEFT")
else
self.DragBar2:SetPoint("TOPRIGHT", vPreviousBar, "TOPLEFT")
end
else
for vCategoryIndex, vCategoryID in ipairs(vCategoryOrder) do
if self:UpdateBar(vBarIndex, vCategoryID) then
local vBar = self.Bars[vBarIndex]
vBar:ClearAllPoints()
if self.Settings.OutfitBar.Vertical then
vBar:SetPoint("TOPLEFT", vPreviousBar, "BOTTOMLEFT")
else
vBar:SetPoint("TOPLEFT", vPreviousBar, "TOPRIGHT")
end
vAnchorOffsetX, vAnchorOffsetY = nil, nil
vBar:Show()
vBarIndex = vBarIndex + 1
vPreviousBar = vBar
end
end
self.DragBar2:ClearAllPoints()
if self.Settings.OutfitBar.Vertical then
self.DragBar2:SetPoint("TOPLEFT", vPreviousBar, "BOTTOMLEFT", 0, 6)
else
self.DragBar2:SetPoint("TOPLEFT", vPreviousBar, "TOPRIGHT", -1, 0)
end
end
-- Hide unused bars
for vIndex = vBarIndex, #self.Bars do
self.Bars[vIndex]:Hide()
end
-- Fudge the drag bars so they look nice against the edges of the frame
local vBar1OffsetX, vBar1OffsetY = 0, 0
local vBar2OffsetX, vBar2OffsetY = 0, 0
if self.Settings.OutfitBar.Vertical then
if vIsAnchorBottom then
vBar1OffsetY = 4
vBar2OffsetY = 1
else
vBar1OffsetY = 1
vBar2OffsetY = -2
end
else
if vIsAnchorRight then
vBar1OffsetX = -1
vBar2OffsetX = -2
else
vBar1OffsetX = -2
end
end
self.DragBar1:SetTextureOffset(vBar1OffsetX, vBar1OffsetY)
self.DragBar2:SetTextureOffset(vBar2OffsetX, vBar2OffsetY)
end
function Outfitter.OutfitBar:AnchorDragBar(pBar)
pBar:ClearAllPoints()
pBar:SetPoint(
self.Settings.OutfitBar.Position.RelativePoint,
UIParent,
self.Settings.OutfitBar.Position.RelativePoint,
self.Settings.OutfitBar.Position.x / self.DragBar1:GetEffectiveScale(),
self.Settings.OutfitBar.Position.y / self.DragBar1:GetEffectiveScale())
end
function Outfitter.OutfitBar:UpdateBar(pBarIndex, pCategoryID)
local vOutfits = Outfitter:GetOutfitsByCategoryID(pCategoryID)
if not vOutfits then
return false
end
local vNumShown = 0
for vOutfitIndex, vOutfit in ipairs(vOutfits) do
if Outfitter.OutfitBar:IsOutfitShown(vOutfit) then
vNumShown = vNumShown + 1
end
end
if vNumShown == 0 then
return false
end
local vBar = self.Bars[pBarIndex]
local vNumColumns, vNumRows
if self.Settings.OutfitBar.Vertical then
vNumColumns = 1
vNumRows = vNumShown
else
vNumColumns = vNumShown
vNumRows = 1
end
if not vBar then
vBar = self:NewBar(vNumColumns, vNumRows)
table.insert(self.Bars, vBar)
else
vBar:SetDimensions(vNumColumns, vNumRows)
end
local vButtonIndex = 1
for vOutfitIndex, vOutfit in ipairs(vOutfits) do
if Outfitter.OutfitBar:IsOutfitShown(vOutfit) then
vBar:SetButtonOutfit(vButtonIndex, vOutfit)
vButtonIndex = vButtonIndex + 1
end
end
return true
end
----------------------------------------
Outfitter.OutfitBar._Bar = {}
----------------------------------------
function Outfitter.OutfitBar._Bar:Construct(pName, pNumColumns, pNumRows)
Outfitter._ButtonBar.Construct(self, pName, pNumColumns, pNumRows, Outfitter.OutfitBar._Button, "ActionButtonTemplate")
self:SetScript("OnEnter", function () Outfitter.OutfitBar:ShowDragBars() end)
self:SetScript("OnLeave", function () Outfitter.OutfitBar:HideDragBars() end)
end
function Outfitter.OutfitBar._Bar:SetButtonOutfit(pButtonIndex, pOutfit)
local vButton = self:GetIndexedButton(pButtonIndex)
if not vButton then
return
end
vButton:SetOutfit(pOutfit)
end
function Outfitter.OutfitBar._Bar:Update()
for vIndex = 1, self.NumButtons do
self:GetIndexedButton(vIndex):Update()
end
end
----------------------------------------
Outfitter.OutfitBar._Button = {}
----------------------------------------
Outfitter.OutfitBar._Button.Widgets =
{
"Icon",
}
function Outfitter.OutfitBar._Button:Construct()
self:SetWidth(Outfitter.Style.ButtonBar.ButtonWidth)
self:SetHeight(Outfitter.Style.ButtonBar.ButtonHeight)
self:SetScript("OnClick", function (button, ...) button:OnClick(...) end)
self:SetScript("OnEnter", function (button, ...) button:OnEnter(...) end)
self:SetScript("OnLeave", function (button, ...) button:OnLeave(...) end)
self:RegisterForClicks("LeftButtonUp", "RightButtonUp")
if Outfitter.LBFGroup then
Outfitter.LBFGroup:AddButton(self)
end
end
function Outfitter.OutfitBar._Button:SetOutfit(pOutfit)
self.Outfit = pOutfit
self:Update()
end
function Outfitter.OutfitBar._Button:Update()
local vTexture = Outfitter.OutfitBar:GetOutfitTexture(self.Outfit)
self.Widgets.Icon:SetTexture(vTexture)
if Outfitter:WearingOutfit(self.Outfit) then
self:SetChecked(true)
self.Widgets.Icon:SetVertexColor(1, 1, 1)
else
self:SetChecked(false)
self.Widgets.Icon:SetVertexColor(0.9, 0.9, 0.9)
end
end
function Outfitter.OutfitBar._Button:OnClick(pMouseButton)
if pMouseButton == "LeftButton" then
local vType, vParam1, vParam2 = GetCursorInfo()
if vType then
-- Set the icon if they're holding an item and
-- the alt key is down
if IsAltKeyDown() then
local vTexture = Outfitter.OutfitBar:GetCursorTexture()
if vTexture then
if not self.Outfit.OutfitBar then
self.Outfit.OutfitBar = {}
end
self.Outfit:SetIcon(vTexture)
self:Update()
ClearCursor()
end
-- Otherwise create an outfit from the item being held
elseif vType == "item" then
local vItem = Outfitter:GetItemInfoFromLink(vParam2)
if not vItem then
Outfitter:ErrorMessage("Outfitter.OutfitBar: Couldn't get information about the item being dropped")
return
end
if not vItem.ItemSlotName then
Outfitter:ErrorMessage("Outfitter.OutfitBar: Couldn't make an outfit from "..vItem.Name.." because it isn't equippable")
return
end
-- Create a new outfit containing the item and equip it
local vOutfit = Outfitter:NewEmptyOutfit(vItem.Name)
vOutfit:AddItem(vItem.ItemSlotName, vItem)
Outfitter:AddOutfit(vOutfit)
Outfitter:WearOutfit(vOutfit)
end
-- If there are no modifiers down, then just equip or unequip the outfit
else
Outfitter.HasHWEvent = true
if self.Outfit.CategoryID == "Complete"
or not Outfitter:WearingOutfit(self.Outfit) then
Outfitter:WearOutfit(self.Outfit)
else
Outfitter:RemoveOutfit(self.Outfit)
end
Outfitter.HasHWEvent = false
end
else -- if pButton == "RightButton" then
-- If the menu is already up then hide it
if self.menuFrame then
self.menuFrame:Hide()
return
end
-- Create the menu
local items = Outfitter:New(Outfitter.UIElementsLib._DropDownMenuItems, function ()
Outfitter.SchedulerLib:ScheduleTask(0.2, function () self.menuFrame:Hide() end)
end)
Outfitter:AddOutfitMenu(items, self.Outfit)
-- Get the cursor's position
local cursorX, cursorY = GetCursorPosition()
local uiScale = UIParent:GetScale()
cursorX = cursorX / uiScale
cursorY = cursorY / uiScale
-- Get the nearest and opposite edges
local nearestVert, nearestHoriz, oppositeVert, oppositeHoriz = Outfitter:GetNearestFrameEdgesFromCoordinates(UIParent, cursorX, cursorY)
local anchorPoint = nearestVert..nearestHoriz
local relativePoint = oppositeVert..nearestHoriz
-- Show the menu
self.menuFrame = LibStub("LibDropdownMC-1.0"):OpenAce3Menu(items)
self.menuFrame:SetPoint(anchorPoint, self, relativePoint, 0, 0)
self.menuFrame.cleanup = function ()
self.menuFrame = nil
self:Update()
end
end
end
function Outfitter.OutfitBar._Button:OnEnter()
local vMissingItems, vBankedItems = Outfitter:GetInventoryCache():GetMissingItems(self.Outfit)
Outfitter:ShowOutfitTooltip(self.Outfit, self, vMissingItems, vBankedItems, true)
Outfitter.OutfitBar:ShowDragBars()
end
function Outfitter.OutfitBar._Button:OnLeave()
GameTooltip:Hide()
Outfitter.OutfitBar:HideDragBars()
end
----------------------------------------
Outfitter.OutfitBar._ChooseIconDialog = {}
----------------------------------------
Outfitter.OutfitBar._ChooseIconDialog.Widgets =
{
"ScrollFrame",
"IconSetMenu",
"FilterEditBox",
"Title"
}
function Outfitter.OutfitBar._ChooseIconDialog:Construct()
-- Create the icon buttons
self.IconButtons = {}
self.NumRows = 5
self.NumColumns = 6
local vPrevRowFirstButton
for vRow = 1, self.NumRows do
local vPrevButton
for vColumn = 1, self.NumColumns do
local vButton = self:NewIconButton()
table.insert(self.IconButtons, vButton)
if vPrevButton then
vButton:SetPoint("LEFT", vPrevButton, "RIGHT", 10, 0)
else
if vPrevRowFirstButton then
vButton:SetPoint("TOPLEFT", vPrevRowFirstButton, "BOTTOMLEFT", 0, -8)
else
vButton:SetPoint("TOPLEFT", self.Widgets.ScrollFrame, "TOPLEFT", 0, 0)
end
vPrevRowFirstButton = vButton
end
vPrevButton = vButton
end
end
-- Hook into the UIMenus list when the dialog is up to capture the escape key presses
self:SetScript("OnShow", function(self)
Outfitter:BeginMenu(self)
end)
self:SetScript("OnHide", function(self)
Outfitter:EndMenu(self)
if self.Outfit then
self:Close()
end
end)
-- Icon sets
self.iconSets = {
{id = "Recommend", name = Outfitter.cSuggestedIcons},
{id = "Spellbook", name = Outfitter.cSpellbookIcons},
{id = "Inventory", name = Outfitter.cYourItemIcons},
{id = "All", name = Outfitter.cEveryIcon},
{id = "Items", name = Outfitter.cItemIcons},
{id = "Abilities", name = Outfitter.cAbilityIcons},
}
-- Set the default icon set
self.IconSetID = self.iconSets[1].id
end
function Outfitter.OutfitBar._ChooseIconDialog:Open(pOutfit)
self.Outfit = pOutfit
self.SelectedTexture = self.Outfit:GetIcon()
if not self.SelectedTexture then
self.SelectedTexture = Outfitter.OutfitBar.cWildcardIcon
end
self.Widgets.Title:SetText(string.format(Outfitter.cChooseIconTitle, pOutfit:GetName()))
self.Widgets.FilterEditBox:SetText("")
self:SetIconSetID(self.IconSetID)
self:Show()
end
function Outfitter.OutfitBar._ChooseIconDialog:Save()
if self.SelectedTexture == Outfitter.OutfitBar.cWildcardIcon then
self.Outfit:SetIcon(nil)
else
self.Outfit:SetIcon(self.SelectedTexture)
end
Outfitter:DispatchOutfitEvent("EDIT_OUTFIT", self.Outfit:GetName(), self.Outfit)
end
function Outfitter.OutfitBar._ChooseIconDialog:Close()
if self.TextureSet and self.TextureSet.Deactivate then
self.TextureSet:Deactivate()
self.TextureSet = nil
end
self.Outfit = nil
self:Hide()
end
function Outfitter.OutfitBar._ChooseIconDialog:SetIconSetID(pIconSetID)
self.IconSetID = pIconSetID
self.TextureList = nil
-- Find the name
for _, iconSet in ipairs(self.iconSets) do
if iconSet.id == pIconSetID then
self.Widgets.IconSetMenu:SetCurrentValueText(iconSet.name)
break
end
end
self:SetIconFilter(self.Widgets.FilterEditBox:GetText())
end
function Outfitter.OutfitBar._ChooseIconDialog:SetIconFilter(pText)
local vTextureSet = Outfitter.OutfitBar.TextureSets[self.IconSetID]
-- Activate the set if it's changing
if vTextureSet ~= self.TextureSet then
if self.TextureSet and self.TextureSet.Deactivate then
self.TextureSet:Deactivate()
end
self.TextureSet = vTextureSet
if self.TextureSet.Activate then
self.TextureSet:Activate(self.Outfit)
end
end
--
if pText and pText ~= "" then
self.DisplayTextureSet = Outfitter.OutfitBar.TextureSets.Filtered
self.DisplayTextureSet:SetFilter(vTextureSet, pText)
else
if self.DisplayTextureSet == Outfitter.OutfitBar.TextureSets.Filtered then
self.DisplayTextureSet:Deactivate()
end
self.DisplayTextureSet = self.TextureSet
end