-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathTransmogCleanup.lua
863 lines (734 loc) · 25.8 KB
/
TransmogCleanup.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
--------------------------------------------------------------------------------
-- TransmogCleanup by Elvador
--
-- GLOBALS: TransmogCleanup, SLASH_TRANSMOGCLEANUP_SLASHCMD1, CanIMogIt, SellJunk
-- GLOBALS: MerchantFrame, MerchantFramePortrait
-- GLOBALS: TransmogCleanupDB, UIParent
--
local folder, ns = ...
TransmogCleanup = CreateFrame("Frame")
local addon = TransmogCleanup
TransmogCleanupDB = {}
addon.db = TransmogCleanupDB
local version = "@project-version@"
local debug = false
--@debug@
version = "(git)"
debug = true
--@end-debug@
--------------------------------------------------------------------------------
-- Upvalues
--
local _G = _G
local orgPrint = print
local cimi = CanIMogIt
local ItemUpgradeInfo = LibStub("LibItemUpgradeInfo-1.0")
local C_Timer = C_Timer
local CreateFrame = CreateFrame
local GetCoinTextureString = GetCoinTextureString
local GetContainerItemLink = C_Container.GetContainerItemLink
local GetContainerNumSlots = C_Container.GetContainerNumSlots
local GetContainerItemPurchaseInfo = C_Container.GetContainerItemPurchaseInfo
local GetItemInfo = GetItemInfo
local GetItemSpell = GetItemSpell
local SecondsToTime = SecondsToTime
local select = select
local tonumber = tonumber
local UseContainerItem = C_Container.UseContainerItem
local unpack = unpack
local GameFontHighlightSmall = GameFontHighlightSmall
local floor = math.floor
local max = math.max
local sort = table.sort
local pairs = pairs
local GameTooltip = GameTooltip
local SetUpSideDressUpFrame = SetUpSideDressUpFrame
local IsControlKeyDown = IsControlKeyDown
local DressUpItemLink = DressUpItemLink
local SideDressUpFrame = SideDressUpFrame
local CloseSideDressUpFrame = CloseSideDressUpFrame
local ITEM_SOULBOUND = ITEM_SOULBOUND
local ITEM_BNETACCOUNTBOUND = ITEM_BNETACCOUNTBOUND
local ITEM_BIND_ON_EQUIP = ITEM_BIND_ON_EQUIP
local IsAddOnLoaded = IsAddOnLoaded
local GetTime = GetTime
local type = type
--------------------------------------------------------------------------------
-- Variables
--
local enabled = true -- changed via checkForDependencies
local merchantButton = nil
local sellWindow = nil
local scanningTooltip = nil
local updateItemListThrottle = nil
local lastWindowState = nil
local maxIlvl = 450
local itemQualities = {
[0] = {0.62, 0.62, 0.62}, -- poor, force index to 0
{ 1, 1, 1}, -- common
{0.12, 1, 0}, -- uncommon
{ 0, 0.44, 0.87}, -- rare
{0.64, 0.21, 0.93}, -- epic
{ 1, 0.50, 0}, -- legendary
}
local bindOn = {
{"BoE", "Bind on Equip"},
{"BoP", "Bind on Pickup"},
{"BoA", "Bind to Account"},
}
local learnedTypes = {
{"Learned", "Sell items learned by any char"},
{"Can't be learned", "Sell items which are non transmoggable (like trinkets and rings)"},
{"Can be learned by another char", "Sell items which can be learned by another character"},
}
--------------------------------------------------------------------------------
-- Debug Functions
--
local function print(...)
orgPrint("|cffec7600TransmogCleanup|r:", ...)
end
local function dbg(...)
if debug then
orgPrint("|cffec7600TC|cff00ffff(debug)|r:", ...)
end
end
--------------------------------------------------------------------------------
-- Functions
--
local function checkForDependencies()
if not CanIMogIt then
print("Dependency missing! Download |cff93c763Can I Mog It?|r from Curse: |cff72aacahttp://mods.curse.com/addons/wow/can-i-mog-it|r")
enabled = false
end
end
local function isTransmogable(link)
return link and cimi:IsTransmogable(link)
end
local function getTransmogStatus(link)
local mogStatus = cimi:GetTooltipText(link)
if not mogStatus or type(mogStatus) ~= "string" then
dbg(("Couldn't determine status of item %s."):format(link))
return
end
-- if cimi:TextIsKnown(mogStatus) then -- < Could just use this, but let's be independent
if mogStatus == cimi.KNOWN or
mogStatus == cimi.KNOWN_FROM_ANOTHER_ITEM or
mogStatus == cimi.KNOWN_BY_ANOTHER_CHARACTER or
mogStatus == cimi.KNOWN_BUT_TOO_LOW_LEVEL or
mogStatus == cimi.KNOWN_FROM_ANOTHER_ITEM_BUT_TOO_LOW_LEVEL or
mogStatus == cimi.KNOWN_FROM_ANOTHER_ITEM_AND_CHARACTER then
return 1
elseif mogStatus == cimi.NOT_TRANSMOGABLE or
mogStatus:find(cimi.UNKNOWABLE_SOULBOUND) then
return 2
elseif mogStatus:find(cimi.UNKNOWABLE_BY_CHARACTER) then
return 3
end
return nil
end
local function getItemIdByLink(itemLink)
return tonumber(select(3, itemLink:find("item:(%d+)")))
end
local function isItemIgnored(itemLink)
local id = getItemIdByLink(itemLink)
return addon.db.ignoredItems[id]
end
local function getItemBind(bag, slot)
local name = "TransmogCleanupTT"
scanningTooltip = scanningTooltip or CreateFrame("GameTooltip", name, nil, "GameTooltipTemplate") -- TODO
local r = nil
scanningTooltip:SetOwner(UIParent, "ANCHOR_NONE")
scanningTooltip:SetBagItem(bag, slot)
scanningTooltip:Show()
for i = 1,scanningTooltip:NumLines() do
if(_G[name.."TextLeft"..i]:GetText() == ITEM_BIND_ON_EQUIP) then
r = 1
elseif(_G[name.."TextLeft"..i]:GetText() == ITEM_SOULBOUND) then
r = 2
elseif(_G[name.."TextLeft"..i]:GetText() == ITEM_BNETACCOUNTBOUND) then
r = 3
end
end
scanningTooltip:Hide()
return r
end
local function iterateBagItems()
local itemList = {}
for bag = 0,4 do
for slot = 1,GetContainerNumSlots(bag) do
local link = GetContainerItemLink(bag, slot)
if link then
local ilvl = ItemUpgradeInfo:GetUpgradedItemLevel(link)
--local transmoggable = isTransmogable(link)
local bind = getItemBind(bag, slot)
local _, _, quality = GetItemInfo(link)
local vendorPrice = select(11, GetItemInfo(link))
local hasOnUseEffect = GetItemSpell(link)
local status = getTransmogStatus(link)
if status ~= nil then
if status and status > 0 then -- check if Can I Mog It checks the itemList
if addon.db.filters.onuse or not hasOnUseEffect then -- not (not addon.db.filters.onuse and hasOnUseEffect)
if ilvl <= addon.db.filters.ilvl then
if addon.db.filters.quality[quality] then
if addon.db.filters.bind[bind] then
if addon.db.filters.learned[status] then
itemList[#itemList+1] = {link = link, ilvl = ilvl, bag = bag, slot = slot, status = status, price = vendorPrice}
else
--dbg(link, "learned", status)
end
else
--dbg(link, "bind", bind)
end
else
--dbg(link, "quality", quality)
end
else
--dbg(link, "ilvl", ilvl, addon.db.filters.ilvl, ilvl < addon.db.filters.ilvl)
end
else
--dbg(link, "hasOnUseEffect", hasOnUseEffect)
end
else
--dbg(link, "status", status)
end
else
--dbg(link, "status ~= nil", status)
end
end
end
end
return itemList
end
local function sortItemList(itemList)
sort(itemList, function(a,b)
return a.ilvl == b.ilvl and a.link < b.link or a.ilvl < b.ilvl -- sort by ilvl, then by itemlink (should be item id)
end)
return itemList
end
local function isSafeModeEnabled()
return addon.db.sellMode.safe
end
local function isVerboseModeEnabled()
return addon.db.sellMode.verbose
end
local function sellItems()
local itemList = sellWindow.scrollframe.content.itemList
local itemsSold = 0
local itemsSoldValue = 0
for i = 1, #itemList do
local item = itemList[i]
if not isItemIgnored(item.link) then
if item.price > 0 then
local _, _, refundSec = GetContainerItemPurchaseInfo(item.bag, item.slot, false)
if refundSec then
print(("Not selling %s because it is still refundable. Please wait %s before selling it."):format(item.link, SecondsToTime(refundSec, true, true)))
else
if isVerboseModeEnabled() then
print(("Selling item %s for %s."):format(item.link, GetCoinTextureString(item.price)))
end
UseContainerItem(item.bag, item.slot)
itemsSold = itemsSold + 1
itemsSoldValue = itemsSoldValue + item.price
if isSafeModeEnabled() and i > 11 then
print(("Stopped selling items after %d items due to safe mode. Press the sell button again to continue selling %d items."):format(i, #itemList - i))
break
end
end
else
if isVerboseModeEnabled() then
print(("Not selling %s because has no price."):format(item.link))
end
end
else
if isVerboseModeEnabled() then
print(("Not selling %s because it is ignored."):format(item.link))
end
end
end
if itemsSold > 0 then
print(("You earned %s by selling %d items."):format(GetCoinTextureString(itemsSoldValue), itemsSold))
else
print("No items to sell.")
end
end
local function onIgnoredCheckedChange(self, ...)
if IsControlKeyDown() then
DressUpItemLink(self.item.link)
self:SetChecked(not self:GetChecked()) -- hack it to the limit!
if GameTooltip:GetOwner() == sellWindow then
GameTooltip:SetPoint("TOPLEFT", SideDressUpFrame, "TOPRIGHT")
end
else
addon.db.ignoredItems[self.itemId] = self:GetChecked()
end
end
local function updateItemList(frame)
local content = frame.scrollframe.content
content.lines = content.lines or {}
local itemList = iterateBagItems()
itemList = sortItemList(itemList)
for i = #content.lines+1, #itemList do
local cb = CreateFrame("CheckButton", "parentCB"..i, content, "InterfaceOptionsCheckButtonTemplate")
cb:SetPoint("TOPLEFT", content, "TOPLEFT", 8, -1 - 16 * (i-1))
cb:SetHitRectInsets(0, -300, 0, 0)
cb:SetHeight(20)
cb:SetWidth(20)
cb:SetScript("OnClick", onIgnoredCheckedChange)
cb:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(frame, "ANCHOR_NONE")
if SideDressUpFrame:IsShown() then
GameTooltip:SetPoint("TOPLEFT", SideDressUpFrame, "TOPRIGHT")
else
GameTooltip:SetPoint("TOPLEFT", frame, "TOPRIGHT")
end
GameTooltip:SetBagItem(self.item.bag, self.item.slot)
end)
cb:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
local itemString = content:CreateFontString("$parentItem"..i, nil, "GameFontNormal")
itemString:SetPoint("TOPLEFT", content, "TOPLEFT", 35, -5 - 16 * (i-1))
itemString:SetFont("Fonts\\ARIALN.TTF", 12)
itemString:SetWidth(125)
itemString:SetWordWrap(false)
itemString:SetJustifyH("LEFT")
local ilvlString = content:CreateFontString("$parentIlvl"..i, nil, "GameFontNormal")
ilvlString:SetPoint("TOPLEFT", content, "TOPLEFT", 160, -5 - 16 * (i-1))
ilvlString:SetFont("Fonts\\ARIALN.TTF", 12)
ilvlString:SetTextColor(1, 1, 1)
ilvlString:SetJustifyH("CENTER")
ilvlString:SetWidth(35)
local statusString = content:CreateFontString("$parentStatus"..i, nil, "GameFontNormal")
statusString:SetPoint("TOPLEFT", content, "TOPLEFT", 195, -5 - 16 * (i-1))
statusString:SetFont("Fonts\\ARIALN.TTF", 12)
statusString:SetTextColor(1, 1, 1)
statusString:SetJustifyH("LEFT")
content.lines[#content.lines + 1] = {cb = cb, item = itemString, ilvl = ilvlString, status = statusString}
end
for i = 1, #itemList do
local line = content.lines[i]
line.cb:Show()
line.item:Show()
line.ilvl:Show()
line.status:Show()
end
for i = #itemList+1, #content.lines do
local line = content.lines[i]
line.cb:Hide()
line.cb.itemId = nil
line.cb.item = nil
line.item:Hide()
line.ilvl:Hide()
line.status:Hide()
end
for i = 1, #itemList do
local line = content.lines[i]
local item = itemList[i]
line.cb:SetChecked(isItemIgnored(item.link))
line.cb.itemId = getItemIdByLink(item.link)
line.cb.item = item
line.item:SetText(item.link)
line.ilvl:SetText(item.ilvl)
line.status:SetText(learnedTypes[item.status][1])
end
content.itemList = itemList
content:SetWidth(300)
content:SetHeight(#itemList * 16 + 5)
frame.scrollbar:SetMinMaxValues(1, max(1, content:GetHeight() - (frame:GetHeight() - (180+35)))) -- scrollframe points
end
local function onFilterCheckedChange(self, ...)
if self.type=="onuse" then
addon.db.filters[self.type] = self:GetChecked()
else
addon.db.filters[self.type][self.id] = self:GetChecked()
end
updateItemList(sellWindow)
end
local function onSellModeCheckedChange(self, ...)
addon.db.sellMode[self.type] = self:GetChecked()
end
local function ilvlSliderValueChanged(self, value)
local newValue = floor(value + 0.5)
self:SetValue(newValue)
self.editbox:SetText(newValue)
addon.db.filters.ilvl = newValue
if updateItemListThrottle then
updateItemListThrottle:Cancel()
end
updateItemListThrottle = C_Timer.NewTimer(0.2, function()
updateItemList(sellWindow)
end)
end
local function createSellWindow()
-- Main Window
local frame = CreateFrame("Frame", "TCSellWindow", MerchantFrame)
frame:SetWidth(MerchantFrame:GetWidth())
frame:SetHeight(MerchantFrame:GetHeight())
frame:SetPoint("TOPLEFT", MerchantFrame, "TOPRIGHT", 5, 0)
local tex = frame:CreateTexture("$parentBg","BACKGROUND")
tex:SetColorTexture(0, 0, 0, 0.4)
tex:SetAllPoints(frame)
-- Header Text
local header = frame:CreateFontString("$parentHeaderText", nil, "GameFontNormal")
header:SetPoint("TOP", frame, "TOP", 0, -5)
header:SetFont("Fonts\\ARIALN.TTF", 14, "OUTLINE")
header:SetTextColor(1, 1, 1)
header:SetText("TransmogCleanup " .. version)
local filterText = frame:CreateFontString("$parentDescText", nil, "GameFontNormal")
filterText:SetPoint("TOPLEFT", frame, "TOPLEFT", 5, -10 - header:GetStringHeight())
filterText:SetFont("Fonts\\ARIALN.TTF", 12, "OUTLINE")
filterText:SetTextColor(1, 1, 1)
filterText:SetJustifyH("left")
filterText:SetText("Sell filters")
local qualityCBs = {}
for i = 0, #itemQualities do
local cb = CreateFrame("CheckButton", "TCSellWindowQualityCB"..i, frame, "InterfaceOptionsCheckButtonTemplate")
cb:SetPoint("LEFT", frame, "TOPLEFT", 5, -51 - 17 * i)
_G["TCSellWindowQualityCB"..i.."Text"]:SetText(_G["ITEM_QUALITY"..i.."_DESC"])
_G["TCSellWindowQualityCB"..i.."Text"]:SetTextColor(unpack(itemQualities[i]))
cb:SetHitRectInsets(0, -80, 0, 0)
cb.type = "quality"
cb.id = i
cb:SetScript("OnClick", onFilterCheckedChange)
qualityCBs[#qualityCBs + 1] = cb
end
frame.qualityCBs = qualityCBs
local bindCBs = {}
for i = 1, #bindOn do
local cb = CreateFrame("CheckButton", "TCSellWindowBindCB"..i, frame, "InterfaceOptionsCheckButtonTemplate")
cb:SetPoint("LEFT", frame, "TOPLEFT", 120, -34 - 17 * i)
_G["TCSellWindowBindCB"..i.."Text"]:SetText(bindOn[i][1])
cb:SetHitRectInsets(0, -35, 0, 0)
cb.type = "bind"
cb.id = i
cb:SetScript("OnClick", onFilterCheckedChange)
bindCBs[#bindCBs + 1] = cb
end
frame.bindCBs = bindCBs
local learnedCBs = {}
for i = 1, #learnedTypes do
local cb = CreateFrame("CheckButton", "TCSellWindowLearnedCB"..i, frame, "InterfaceOptionsCheckButtonTemplate")
cb:SetPoint("LEFT", frame, "TOPLEFT", 180, -34 - 17 * i)
_G["TCSellWindowLearnedCB"..i.."Text"]:SetText(learnedTypes[i][1])
_G["TCSellWindowLearnedCB"..i.."Text"]:SetWidth(120)
cb:SetHitRectInsets(0, -110, 0, 0)
cb.type = "learned"
cb.id = i
cb:SetScript("OnClick", onFilterCheckedChange)
learnedCBs[#learnedCBs + 1] = cb
end
frame.learnedCBs = learnedCBs
-- some shenanigans for the long text CheckButton
-- this will break with localization
_G["TCSellWindowLearnedCB3Text"]:SetPoint("TOPLEFT", "TCSellWindowLearnedCB3", "TOPRIGHT", 2, 1)
_G["TCSellWindowLearnedCB3Text"]:SetHeight(37)
_G["TCSellWindowLearnedCB3Text"]:SetWordWrap(true)
_G["TCSellWindowLearnedCB3Text"]:SetJustifyV("MIDDLE")
-- On Use Filter
local cb = CreateFrame("CheckButton", "TCSellWindowOnUseCB", frame, "InterfaceOptionsCheckButtonTemplate")
cb:SetPoint("LEFT", frame, "TOPLEFT", 120, -102)
_G["TCSellWindowOnUseCBText"]:SetText("On Use")
cb:SetHitRectInsets(0, -35, 0, 0)
cb.type = "onuse"
cb:SetScript("OnClick", onFilterCheckedChange)
frame.onUseCB = cb
-- Safe mode selling
local safeModeCB = CreateFrame("CheckButton", "TCSellWindowSafeModeCB", frame, "InterfaceOptionsCheckButtonTemplate")
safeModeCB:SetPoint("LEFT", frame, "BOTTOMLEFT", 120, 24)
safeModeCB:SetHeight(20)
safeModeCB:SetWidth(20)
_G["TCSellWindowSafeModeCBText"]:SetText("Safe Mode")
_G["TCSellWindowSafeModeCBText"]:SetFont("Fonts\\ARIALN.TTF", 12)
safeModeCB:SetHitRectInsets(0, -50, 0, 0)
safeModeCB.type = "safe"
safeModeCB:SetScript("OnClick", onSellModeCheckedChange)
frame.safeModeCB = safeModeCB
-- Verbose selling
local verboseModeCB = CreateFrame("CheckButton", "TCSellWindowVerboseModeCB", frame, "InterfaceOptionsCheckButtonTemplate")
verboseModeCB:SetPoint("TOPLEFT", safeModeCB, "BOTTOMLEFT", 0, 7)
verboseModeCB:SetHeight(20)
verboseModeCB:SetWidth(20)
_G["TCSellWindowVerboseModeCBText"]:SetText("Verbose Mode")
_G["TCSellWindowVerboseModeCBText"]:SetFont("Fonts\\ARIALN.TTF", 12)
verboseModeCB:SetHitRectInsets(0, -50, 0, 0)
verboseModeCB.type = "verbose"
verboseModeCB:SetScript("OnClick", onSellModeCheckedChange)
frame.verboseModeCB = verboseModeCB
-- Item level slider
local ilvlSlider = CreateFrame("Slider", "TCSellWindowIlvlSlider", frame, "OptionsSliderTemplate")
ilvlSlider:SetPoint("TOPLEFT", frame, "TOPLEFT", 125, -120)
ilvlSlider:SetWidth(190)
_G["TCSellWindowIlvlSliderText"]:SetText("Max Item level")
_G["TCSellWindowIlvlSliderLow"]:SetText("1")
_G["TCSellWindowIlvlSliderHigh"]:SetText(maxIlvl)
ilvlSlider:SetMinMaxValues(1, maxIlvl)
ilvlSlider:SetValue(maxIlvl-50)
ilvlSlider:SetValueStep(1)
ilvlSlider:SetHitRectInsets(0, 0, 0, 0) -- default from OptionsSliderTemplate: 0,0,-10,-10
local editbox = CreateFrame("EditBox", nil, frame, "BackdropTemplate")
editbox:SetAutoFocus(false)
editbox:SetFontObject(GameFontHighlightSmall)
editbox:SetPoint("TOP", ilvlSlider, "BOTTOM")
editbox:SetHeight(14)
editbox:SetWidth(70)
editbox:SetJustifyH("CENTER")
editbox:EnableMouse(true)
editbox:SetBackdrop({
bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
edgeFile = "Interface\\ChatFrame\\ChatFrameBackground",
tile = true, edgeSize = 1, tileSize = 5,
})
editbox:SetBackdropColor(0, 0, 0, 0.5)
editbox:SetBackdropBorderColor(0.3, 0.3, 0.30, 0.80)
editbox:SetText(ilvlSlider:GetValue())
editbox.slider = ilvlSlider
ilvlSlider.editbox = editbox
frame.ilvlSlider = ilvlSlider
ilvlSlider:SetScript("OnValueChanged", ilvlSliderValueChanged)
editbox:SetScript("OnEnterPressed", function(self)
self.slider:SetValue(tonumber(self:GetText()))
end)
editbox:SetScript("OnEscapePressed", function(self)
self:SetText(self.slider:GetValue())
end)
local ignoredHeaderText = frame:CreateFontString("$parentIgnoredHeaderText", nil, "GameFontNormal")
ignoredHeaderText:SetPoint("TOPLEFT", frame, "TOPLEFT", 6, -165)
ignoredHeaderText:SetFont("Fonts\\ARIALN.TTF", 12, "OUTLINE")
ignoredHeaderText:SetTextColor(1, 1, 1)
ignoredHeaderText:SetText("Ignored")
local itemHeaderText = frame:CreateFontString("$parentItemHeaderText", nil, "GameFontNormal")
itemHeaderText:SetPoint("TOPLEFT", frame, "TOPLEFT", 95, -165)
itemHeaderText:SetFont("Fonts\\ARIALN.TTF", 12, "OUTLINE")
itemHeaderText:SetTextColor(1, 1, 1)
itemHeaderText:SetText("Item")
local ilvlHeaderText = frame:CreateFontString("$parentIlvlHeaderText", nil, "GameFontNormal")
ilvlHeaderText:SetPoint("TOPLEFT", frame, "TOPLEFT", 176, -165)
ilvlHeaderText:SetFont("Fonts\\ARIALN.TTF", 12, "OUTLINE")
ilvlHeaderText:SetTextColor(1, 1, 1)
ilvlHeaderText:SetText("ilvl")
local statusHeaderText = frame:CreateFontString("$parentStatusHeaderText", nil, "GameFontNormal")
statusHeaderText:SetPoint("TOPLEFT", frame, "TOPLEFT", 235, -165)
statusHeaderText:SetFont("Fonts\\ARIALN.TTF", 12, "OUTLINE")
statusHeaderText:SetTextColor(1, 1, 1)
statusHeaderText:SetText("Status")
--scrollframe
local scrollframe = CreateFrame("ScrollFrame", nil, frame)
scrollframe:SetPoint("TOPLEFT", 5, -180)
scrollframe:SetPoint("BOTTOMRIGHT", -26, 35)
scrollframe:SetScript("OnMouseWheel", function(self, value)
local scrollbar = self:GetParent().scrollbar
local scrollStep = scrollbar.scrollStep or scrollbar:GetHeight() / 2
if ( value > 0 ) then
scrollbar:SetValue(scrollbar:GetValue() - scrollStep)
else
scrollbar:SetValue(scrollbar:GetValue() + scrollStep)
end
end)
local texture = scrollframe:CreateTexture()
texture:SetAllPoints()
texture:SetColorTexture(0, 0, 0, 0.4)
frame.scrollframe = scrollframe
--scrollbar
local scrollbar = CreateFrame("Slider", nil, scrollframe, "UIPanelScrollBarTemplate")
scrollbar:SetPoint("TOPLEFT", scrollframe, "TOPRIGHT", 2, -16)
scrollbar:SetPoint("BOTTOMLEFT", scrollframe, "BOTTOMRIGHT", 2, 16)
scrollbar:SetMinMaxValues(1, 200)
scrollbar:SetValueStep(1)
scrollbar:SetValue(0)
scrollbar:SetWidth(16)
scrollbar:SetScript("OnValueChanged", function (self, value)
self:GetParent():SetVerticalScroll(value)
end)
local scrollbg = scrollbar:CreateTexture(nil, "BACKGROUND")
scrollbg:SetAllPoints(scrollbar)
scrollbg:SetColorTexture(0, 0, 0, 0.4)
frame.scrollbar = scrollbar
--content frame
local content = CreateFrame("Frame", nil, scrollframe)
scrollbar.scrollStep = 16
scrollframe.content = content
scrollframe:SetScrollChild(content)
local sellButton = CreateFrame("Button", "TCSellWindowSellButton", frame, "UIPanelButtonTemplate")
sellButton:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -5, 5)
sellButton:SetWidth(105)
sellButton:SetHeight(26)
sellButton:SetText("Sell the items!")
sellButton:SetScript("OnClick", function(self) sellItems() end)
local hideButton = CreateFrame("Button", "TCSellWindowSellButton", frame, "UIPanelButtonTemplate")
hideButton:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 5, 5)
hideButton:SetWidth(105)
hideButton:SetHeight(26)
hideButton:SetText("Hide")
hideButton:SetScript("OnClick", function(self) self:GetParent():Hide() end)
frame:Hide()
sellWindow = frame
end
local function updateSellSettings(sellWindow)
for i =1,#sellWindow.qualityCBs do
sellWindow.qualityCBs[i]:SetChecked(addon.db.filters.quality[i])
end
for i =1,#sellWindow.bindCBs do
sellWindow.bindCBs[i]:SetChecked(addon.db.filters.bind[i])
end
for i =1,#sellWindow.learnedCBs do
sellWindow.learnedCBs[i]:SetChecked(addon.db.filters.learned[i])
end
sellWindow.onUseCB:SetChecked(addon.db.filters.onuse)
sellWindow.ilvlSlider:SetValue(addon.db.filters.ilvl)
sellWindow.safeModeCB:SetChecked(addon.db.sellMode.safe)
sellWindow.verboseModeCB:SetChecked(addon.db.sellMode.verbose)
end
local function displaySellWindow()
dbg("displaySellWindow:", sellWindow and "window already created" or "creating window")
if not sellWindow then createSellWindow() end
updateSellSettings(sellWindow)
updateItemList(sellWindow)
SetUpSideDressUpFrame(sellWindow, 400, 600, "TOPLEFT", "TOPRIGHT", -5, 0)
sellWindow:Show()
end
local function hideSellWindow()
dbg("sellWindow()", sellWindow, lastWindowState)
if sellWindow then
lastWindowState = sellWindow:IsShown()
sellWindow:Hide()
CloseSideDressUpFrame(sellWindow)
end
end
local function toggleSellWindows()
if sellWindow and sellWindow:IsShown() then
hideSellWindow()
else
displaySellWindow()
end
end
local function fixButtonPosition()
local fixPosition, fixFramelevel = nil, nil
-- Addons which use the space our button should be
if SellJunk then
fixPosition = true
end
if IsAddOnLoaded("GnomishVendorShrinker") then
fixPosition = true
fixFramelevel = true
end
if IsAddOnLoaded("ElvUI_SLE") then --ElvUI plugin Shadow and Light
fixPosition = true
fixFramelevel = true
end
-- different solutions for whatever is needed
if fixPosition then
merchantButton:SetPoint("BOTTOMLEFT", MerchantFramePortrait, "BOTTOMRIGHT", 5, -12)
merchantButton:SetHeight(16)
end
if fixFramelevel then
merchantButton:SetFrameLevel(merchantButton:GetFrameLevel()+2)
end
end
local function createMerchantButton()
if not merchantButton then
merchantButton = CreateFrame("Button", "TCMerchantButton", MerchantFrame, "UIPanelButtonTemplate")
merchantButton:SetWidth(110)
merchantButton:SetHeight(26)
merchantButton:SetPoint("BOTTOMLEFT", MerchantFramePortrait, "BOTTOMRIGHT", 2, -2)
merchantButton:SetText("Sell Transmog")
merchantButton:SetScript("OnClick", function(self) toggleSellWindows() end)
end
fixButtonPosition() -- dirty hack to avoid overlapping buttons with other addons
C_Timer.NewTicker(0.2, function() -- give lod addons some time to load
fixButtonPosition()
end, 5)
end
--------------------------------------------------------------------------------
-- Event Handler
--
local events = {}
function events:PLAYER_ENTERING_WORLD(...)
C_Timer.After(10, function()
checkForDependencies()
end)
end
function events:ADDON_LOADED(...)
if select(1, ...) == "TransmogCleanup" then
addon:UnregisterEvent("ADDON_LOADED")
addon.db = TransmogCleanupDB
local db = addon.db
if not db.filters then
db.filters = {
["quality"] = {
[0] = true,
[1] = true,
[2] = true,
[3] = true,
[4] = true,
},
["bind"] = {
[1] = true,
[2] = true,
[3] = true,
},
["learned"] = {
[1] = true,
[2] = true,
},
["ilvl"] = maxIlvl-50,
}
end
if not db.filters.onuse and db.filters.onuse ~= false then
db.filters.onuse = true
end
if not db.ignoredItems then
db.ignoredItems = {}
end
for k,v in pairs(addon:getDefaultIgnoredItems()) do
if not db.ignoredItems[k] and db.ignoredItems[k] ~= false then
db.ignoredItems[k] = v
end
end
if not db.sellMode then
db.sellMode = {
["safe"] = true,
["verbose"] = false,
}
end
end
end
function events:MERCHANT_SHOW(...)
if enabled then
createMerchantButton()
end
if sellWindow and lastWindowState then
displaySellWindow()
end
end
local prev = 0 -- Throttle because MERCHANT_CLOSED fires twice
function events:MERCHANT_CLOSED(...)
local t = GetTime()
if t - prev > 1 then
prev = t
hideSellWindow()
end
end
function events:BAG_UPDATE(...)
if sellWindow and sellWindow:IsShown() then
if updateItemListThrottle then
updateItemListThrottle:Cancel()
end
updateItemListThrottle = C_Timer.NewTimer(0.2, function()
updateItemList(sellWindow)
end)
end
end
addon:SetScript("OnEvent", function(self, event, ...)
events[event](self, ...)
end)
for k,_ in pairs(events) do
addon:RegisterEvent(k)
end
--------------------------------------------------------------------------------
-- Slash Command Handler
--
local function slashCmdHandler(msg)
print("Go to a merchant and click Sell Transmog!")
end
SlashCmdList['TRANSMOGCLEANUP_SLASHCMD'] = slashCmdHandler
SLASH_TRANSMOGCLEANUP_SLASHCMD1 = '/transmogcleanup'