-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSellFrame.lua
More file actions
993 lines (818 loc) · 28.8 KB
/
SellFrame.lua
File metadata and controls
993 lines (818 loc) · 28.8 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
-------------------------------------------------------------------------------
-- SellFrame.lua
--
-- Implements the "Sell" tab.
-------------------------------------------------------------------------------
local L = LibStub("AceLocale-3.0"):GetLocale("AuctionLite", false)
-- Constants for display elements.
local SELL_DISPLAY_SIZE = 16;
-- Pricing methods.
local METHOD_PER_ITEM = 1;
local METHOD_PER_STACK = 2;
-- Durations.
local DURATION_SHORT = 1;
local DURATION_MEDIUM = 2;
local DURATION_LONG = 3;
-- Current sorting state.
local SellSort = {
sort = "BuyoutEach",
flipped = false,
justFlipped = false,
sorted = false,
};
-- Info about data to be shown in scrolling pane.
local SellLink = nil;
local SellData = {};
-- Value of item currently in "Sell" tab.
local ItemValue = nil;
-- User-specified bid and buyout values for current item.
local ItemBid = nil;
local ItemBuyout = nil;
-- Can we undercut the current item value?
local AllowUndercut = nil;
-- Status shown in auction posting frame.
local StatusMessage = "";
local StatusError = false;
-- Number of times the user has edited the size box.
local ChangedSize = 0;
-- Previous prices set by the user.
local SavedPrices = {};
-- Add a money type that updates the deposit correctly.
MoneyTypeInfo["AUCTIONLITE_DEPOSIT"] = {
UpdateFunc = function() return AuctionLite:CalculateDeposit() end,
collapse = 1,
}
-- Determine the correct deposit for a single item.
function AuctionLite:CalculateDeposit()
local time = self:GetDuration();
local _, _, _, _, _, _, link = self:GetAuctionSellItemInfoAndLink();
local numItems = self:CountItems(link);
local stacks = SellStacks:GetNumber();
local size = SellSize:GetNumber();
local numPosted = math.min(numItems, stacks * size);
local _, _, count = GetAuctionSellItemInfo();
return math.floor(CalculateAuctionDeposit(time) * numPosted / count);
end
-- Update the deposit field.
function AuctionLite:UpdateDeposit()
MoneyFrame_Update("SellDepositMoneyFrame", self:CalculateDeposit());
end
-- Generate a suggested bid and buyout from the market value. We undercut
-- and round prices according to the user's settings.
function AuctionLite:GeneratePrice(value, allowUndercut)
-- Find out how to round prices.
local granularity = 1;
if self.db.profile.roundPrices > 0 then
granularity = math.pow(10, math.floor(math.log10(value))) *
self.db.profile.roundPrices;
end
-- How much do we undercut?
-- Bid undercut applies all the time; buyout only when allowed.
local bidUndercut = self.db.profile.bidUndercut;
local buyoutUndercut = self.db.profile.buyoutUndercut;
if not allowUndercut then
buyoutUndercut = 0;
end
-- Undercut bid and buyout as specified.
local generate = function(value, undercut, granularity)
return math.floor((value * (1 - undercut)) / granularity) * granularity;
end
local bid = generate(value, bidUndercut, granularity);
local buyout = generate(value, buyoutUndercut, granularity);
return bid, buyout;
end
-- Generate price, and dump some data to the console.
function AuctionLite:ShowPriceData(itemLink, itemValue, stackSize)
local hist = self:GetHistoricalPrice(itemLink);
local stackValue = itemValue * stackSize;
local _, _, count, _, _, vendor = GetAuctionSellItemInfo();
local itemVendor = vendor / count;
self:Print(L["|cff8080ffData for %s x%d|r"]:format(itemLink, stackSize));
self:Print(L["Vendor: %s"]:format(self:PrintMoney(itemVendor * stackSize)));
if hist ~= nil and hist.scans > 0 and hist.price > 0 then
self:Print(L["Historical: %s (%d |4listing:listings;/scan, %d |4item:items;/scan)"]:
format(self:PrintMoney(hist.price * stackSize),
math.floor(0.5 + hist.listings / hist.scans),
math.floor(0.5 + hist.items / hist.scans)));
if itemVendor > 0 then
self:Print(L["Current: %s (%.2fx historical, %.2fx vendor)"]:
format(self:PrintMoney(stackValue),
math.floor(100 * itemValue / hist.price) / 100,
math.floor(100 * itemValue / itemVendor) / 100));
else
self:Print(L["Current: %s (%.2fx historical)"]:
format(self:PrintMoney(stackValue),
math.floor(100 * itemValue / hist.price) / 100));
end
elseif itemVendor > 0 then
self:Print(L["Current: %s (%.2fx vendor)"]:
format(self:PrintMoney(stackValue),
math.floor(100 * itemValue / itemVendor) / 100));
end
return bid, buyout;
end
-- Set the market value for the current item.
function AuctionLite:SetItemValue(value, allowUndercut)
ItemValue = value;
AllowUndercut = allowUndercut;
ItemBid = nil;
ItemBuyout = nil;
end
-- Set the user-specified bid and buyout.
function AuctionLite:SetItemBidBuyout(bid, buyout)
if bid ~= nil then
ItemBid = bid;
end
if buyout ~= nil then
ItemBuyout = buyout;
end
end
-- Indicate that the user has messed with the stack size.
function AuctionLite:UserChangedSize()
ChangedSize = ChangedSize + 1;
self:UpdateDeposit();
self:UpdatePrices();
self:ValidateAuction();
end
-- Update the stack size based on a change in the number of stacks.
function AuctionLite:UserChangedStacks()
-- If the user hasn't already specified a size, adjust the size to
-- fit the number of stacks entered.
if ChangedSize <= 0 then
local _, _, _, _, _, _, link = self:GetAuctionSellItemInfoAndLink();
if link ~= nil then
local size = SellSize:GetNumber();
local stacks = SellStacks:GetNumber();
local numItems = self:CountItems(link);
-- If we don't have enough items to fill the order, then we need to
-- modify the stack size. (The funny math here accounts for the fact
-- that the final stack may be a partial stack.)
if size * stacks - numItems >= size then
-- Get our new stack size, and round up since we might want to sell
-- the excess as a partial stack.
local newSize = math.ceil(numItems / stacks);
-- If the excess is more than a single stack, then reduce by one,
-- which is the same thing as taking floor instead of ceil above.
if newSize * stacks - numItems >= newSize and newSize > 1 then
newSize = newSize - 1;
end
-- Make sure the stack is not too large.
local _, _, _, _, _, _, _, maxSize = GetItemInfo(link);
if maxSize < newSize then
newSize = maxSize;
end
-- Update the size.
if newSize ~= size then
ChangedSize = ChangedSize - 1;
SellSize:SetText(newSize);
end
end
end
end
self:UpdateDeposit();
self:ValidateAuction();
end
-- Fill in suggested prices based on a query result or a change in the
-- stack size.
function AuctionLite:UpdatePrices()
if ItemValue ~= nil then
local bid, buyout = self:GeneratePrice(ItemValue, AllowUndercut);
if ItemBid ~= nil then
bid = ItemBid;
end
if ItemBuyout ~= nil then
buyout = ItemBuyout;
end
-- If we're pricing by stack, multiply by our stack size.
if self.db.profile.method == METHOD_PER_STACK then
local stackSize = SellSize:GetNumber();
bid = bid * stackSize;
buyout = buyout * stackSize;
end
MoneyInputFrame_SetCopper(SellBidPrice, math.floor(bid + 0.5));
SellBidPrice.expectChanges = SellBidPrice.expectChanges + 1;
MoneyInputFrame_SetCopper(SellBuyoutPrice, math.floor(buyout + 0.5));
SellBuyoutPrice.expectChanges = SellBuyoutPrice.expectChanges + 1;
-- Validate auction and enable create button.
self:ValidateAuction();
end
end
-- Check whether there are any errors in the auction.
function AuctionLite:ValidateAuction()
local name, _, count, _, _, vendor, link =
self:GetAuctionSellItemInfoAndLink();
if name ~= nil and not self:QueryInProgress() then
local bid = MoneyInputFrame_GetCopper(SellBidPrice);
local buyout = MoneyInputFrame_GetCopper(SellBuyoutPrice);
local stacks = SellStacks:GetNumber();
local size = SellSize:GetNumber();
local numItems = self:CountItems(link);
local _, _, _, _, _, _, _, maxSize = GetItemInfo(link);
-- If we're pricing by item, get the full stack price.
if self.db.profile.method == METHOD_PER_ITEM then
bid = bid * size;
buyout = buyout * size;
end
-- Now perform our checks.
if stacks * size <= 0 then
StatusError = true;
SellStatusText:SetText(L["|cffff0000Invalid stack size/count.|r"]);
SellCreateAuctionButton:Disable();
elseif maxSize < size then
StatusError = true;
SellStatusText:SetText(L["|cffff0000Stack size too large.|r"]);
SellCreateAuctionButton:Disable();
elseif stacks > math.ceil(numItems / size) then
StatusError = true;
SellStatusText:SetText(L["|cffff0000Not enough items available.|r"]);
SellCreateAuctionButton:Disable();
elseif bid == 0 then
StatusError = true;
SellStatusText:SetText(L["|cffff0000No bid price set.|r"]);
SellCreateAuctionButton:Disable();
elseif 0 < buyout and buyout < bid then
StatusError = true;
SellStatusText:SetText(L["|cffff0000Buyout less than bid.|r"]);
SellCreateAuctionButton:Disable();
elseif GetMoney() < self:CalculateDeposit() then
StatusError = true;
SellStatusText:SetText(L["|cffff0000Not enough cash for deposit.|r"]);
SellCreateAuctionButton:Disable();
elseif 0 < buyout and buyout <= (vendor * size / count) then
StatusError = true;
SellStatusText:SetText(L["|cffff7030Buyout less than vendor price.|r"]);
SellCreateAuctionButton:Enable();
elseif numItems < size * stacks then
StatusError = true;
SellStatusText:SetText(
L["|cffff7030Stack %d will have %d |4item:items;.|r"]:
format(stacks, numItems % size));
SellCreateAuctionButton:Enable();
else
StatusError = false;
SellStatusText:SetText(StatusMessage);
SellCreateAuctionButton:Enable();
end
end
end
-- There's been a click on the auction sell item slot.
function AuctionLite:ClickAuctionSellItemButton_Hook()
-- Ignore clicks that we generated ourselves.
if AuctionFrameSell:IsShown() and not self:CreateInProgress() then
-- Clear everything first.
self:ClearSellFrame();
-- If we've got a new item in the auction slot, fill out the fields.
local name, texture, count, _, _, _, link =
self:GetAuctionSellItemInfoAndLink();
if name ~= nil then
local _, _, _, _, _, _, _, maxSize = GetItemInfo(link);
SellItemButton:SetNormalTexture(texture);
SellItemButtonName:SetText(name);
if count > 1 then
SellItemButtonCount:SetText(count);
SellItemButtonCount:Show();
else
SellItemButtonCount:Hide();
end
local total = self:CountItems(link);
local prefs = self:GetSavedPrices(link);
local size = count;
if prefs ~= nil and prefs.stackSize ~= nil then
size = prefs.stackSize;
elseif self.db.profile.defaultSize == "a_one" then
size = 1;
elseif self.db.profile.defaultSize == "b_stack" then
size = count;
elseif self.db.profile.defaultSize == "c_full" then
size = maxSize;
if size > total then
size = total;
end
end
local stacks = 1;
if prefs ~= nil and prefs.stackCount ~= nil then
stacks = prefs.stackCount;
elseif self.db.profile.defaultStacks == "a_one" then
stacks = 1;
elseif self.db.profile.defaultStacks == "b_full" then
stacks = math.floor(total / size);
elseif self.db.profile.defaultStacks == "c_excess" then
stacks = math.ceil(total / size);
end
if size ~= SellSize:GetNumber() then
ChangedSize = ChangedSize - 1;
end
SellStacks:SetText(stacks);
SellSize:SetText(size);
SellStacks:SetFocus();
SellStackText:SetText(
L["Number of Items |cff808080(max %d)|r"]:format(total));
self:UpdateDeposit();
if IsControlKeyDown() then
-- Just pretend the scan finished.
self:Print(L["Auction scan skipped (control key is down)"]);
self:SetSellData({}, link);
else
-- Start the scan.
local query = {
link = link,
update = function(pct) AuctionLite:UpdateProgressSell(pct) end,
finish = function(data, link) AuctionLite:SetSellData(data, link) end,
};
self:StartQuery(query);
end
end
end
end
-- Forget all our saved prices.
function AuctionLite:ClearSavedPrices()
SavedPrices = {};
end
-- Clean up the "Sell" tab.
function AuctionLite:ClearSellFrame()
self:CancelQuery();
SellSort = {
sort = "BuyoutEach",
flipped = false,
justFlipped = false,
sorted = false,
};
SellLink = nil;
SellData = {};
ItemValue = nil;
ItemBid = nil;
ItemBuyout = nil;
AllowUndercut = nil;
ChangedSize = 0;
SellItemButton:SetNormalTexture(nil);
SellItemButtonName:SetText("");
SellItemButtonCount:Hide();
SellStackText:SetText(L["Number of Items"]);
SellStacks:SetText("");
SellSize:SetText("");
MoneyInputFrame_ResetMoney(SellBidPrice);
MoneyInputFrame_ResetMoney(SellBuyoutPrice);
SellCreateAuctionButton:Disable();
SellRememberButton:Disable();
StatusError = false;
self:SetStatus("");
self:UpdateDeposit();
FauxScrollFrame_SetOffset(SellScrollFrame, 0);
self:AuctionFrameSell_Update();
end
-- Set the status line.
function AuctionLite:SetStatus(message)
StatusMessage = message;
if not StatusError then
SellStatusText:SetText(message);
end
end
-- Get our query results.
function AuctionLite:SetSellData(results, link)
-- Set the competing auction display.
local result = results[link];
if result ~= nil then
local filtered = {};
local i;
for _, listing in ipairs(result.data) do
if listing.buyout > 0 then
table.insert(filtered, listing);
end
end
SellLink = link;
SellData = filtered;
SellSort = {
sort = "BuyoutEach",
flipped = false,
justFlipped = false,
sorted = false,
};
end
-- Get our recommended item value.
local itemValue = 0;
local allowUndercut = true;
if result ~= nil and result.price > 0 then
itemValue = result.price;
if result.priceIsMine then
allowUndercut = false;
end
if self.db.profile.printPriceData then
self:ShowPriceData(link, itemValue, SellSize:GetNumber());
end
self:SetStatus(L["|cff00ff00Scanned %d listings.|r"]:
format(result.listings));
else
local hist = self:GetHistoricalPrice(link);
if hist ~= nil and hist.price > 0 then
itemValue = hist.price;
self:SetStatus(L["|cffffd000Using historical data.|r"]);
else
local _, _, count, _, _, vendor = GetAuctionSellItemInfo();
local mult = self.db.profile.vendorMultiplier;
itemValue = mult * vendor / count;
self:SetStatus(L["|cffff0000Using %.3gx vendor price.|r"]:
format(mult));
end
allowUndercut = false;
end
self:SetItemValue(itemValue, allowUndercut);
-- Load the user's saved price, if it exists.
local saved = SavedPrices[link];
if saved ~= nil then
self:SetStatus(L["|cff00ff00Using previous price.|r"]);
self:SetItemBidBuyout(saved.bid, saved.buyout);
end
-- Load long-term saved prices.
local prefs = self:GetSavedPrices(link);
if prefs ~= nil then
self:SetItemBidBuyout(prefs.bid, prefs.buyout);
end
-- Active the remember menu.
SellRememberButton:Enable();
-- Update the UI.
self:UpdatePrices();
self:AuctionFrameSell_Update();
end
-- Save the current prices for later use.
function AuctionLite:RecordSellPrices()
if ItemBid ~= nil and ItemBuyout ~= nil then
local _, _, _, _, _, _, link = self:GetAuctionSellItemInfoAndLink();
if link then
SavedPrices[link] = { bid = ItemBid, buyout = ItemBuyout };
end
end
end
-- Static popup warning for clearing data.
StaticPopupDialogs["AL_VENDOR_WARNING"] = {
text = L["VENDOR_WARNING"],
button1 = L["Do it!"],
button2 = L["Cancel"],
OnAccept = function(self)
AuctionLite:RecordSellPrices();
AuctionLite:CreateAuctions();
end,
showAlert = 1,
timeout = 0,
exclusive = 1,
hideOnEscape = 1
};
-- We've clicked the "Create" button (or pressed enter).
function AuctionLite:SellCreateAuctionButton_OnClick()
local _, _, count, _, _, vendor = GetAuctionSellItemInfo();
local buyout = MoneyInputFrame_GetCopper(SellBuyoutPrice);
local size = SellSize:GetNumber();
-- If we're pricing by item, get the full stack price.
if self.db.profile.method == METHOD_PER_ITEM then
buyout = buyout * size;
end
-- If we're below vendor price, warn; otherwise, sell.
if 0 < buyout and buyout <= (vendor * size / count) then
StaticPopup_Show("AL_VENDOR_WARNING");
else
self:RecordSellPrices();
self:CreateAuctions();
end
end
-- Handles clicks on buttons in the "Competing Auctions" display.
-- Get the appropriate auction and undercut it!
function AuctionLite:SellButton_OnClick(id)
local offset = FauxScrollFrame_GetOffset(SellScrollFrame);
local item = SellData[offset + id];
if item ~= nil then
if item.owner == UnitName("player") then
self:SetItemBidBuyout(item.bid / item.count, item.buyout / item.count);
else
self:SetItemValue(item.price, true);
end
self:UpdatePrices();
end
end
-- Mouse has entered a row in the scrolling frame.
function AuctionLite:SellButton_OnEnter(widget)
-- Get our index into the current display data.
local offset = FauxScrollFrame_GetOffset(SellScrollFrame);
local id = widget:GetID();
-- If there's an item at this location, create a tooltip for it.
local item = SellData[offset + id];
local _, _, _, _, _, _, link = self:GetAuctionSellItemInfoAndLink();
if item ~= nil and link ~= nil then
local shift = SellButton1Name:GetLeft() - SellButton1Count:GetLeft();
self:SetHyperlinkTooltips(false);
GameTooltip:SetOwner(widget, "ANCHOR_TOPLEFT", shift);
GameTooltip:SetHyperlink(link);
self:AddTooltipData(GameTooltip, link, item.count);
self:SetHyperlinkTooltips(true);
end
end
-- Mouse has left a row in the scrolling frame.
function AuctionLite:SellButton_OnLeave(widget)
GameTooltip:Hide();
end
-- Handles clicks on "Remember" button.
function AuctionLite:SellRememberButton_OnClick(widget)
local _, _, _, _, _, _, link = self:GetAuctionSellItemInfoAndLink();
if link ~= nil then
local prefs = self:GetSavedPrices(link);
local menuList = {
{
text = L["Saved Item Settings"],
isTitle = true,
},
};
-- Add items for each of our saved variables, including the
-- current saved value if there is one.
local addMenuItem = function(name, field, isMoney, fn)
local value = prefs[field];
if value ~= nil then
if isMoney then
if self.db.profile.method == METHOD_PER_STACK then
local stackSize = SellSize:GetNumber();
value = value * stackSize;
end
value = self:PrintMoney(value);
end
else
value = "|cffc0c0c0" .. L["(none set)"] .. "|r";
end
local menuItem = {
text = name .. ": " .. value,
func = function()
if prefs[field] ~= nil then
prefs[field] = nil;
else
local newValue = fn();
if isMoney and self.db.profile.method == METHOD_PER_STACK then
local stackSize = SellSize:GetNumber();
newValue = newValue / stackSize;
end
prefs[field] = newValue;
end
self:SetSavedPrices(link, prefs);
end,
};
if prefs[field] ~= nil then
menuItem.checked = true;
end
table.insert(menuList, menuItem);
end
addMenuItem(L["Stack Count"], "stackCount", false, function()
return SellStacks:GetNumber();
end);
addMenuItem(L["Stack Size"], "stackSize", false, function()
return SellSize:GetNumber();
end);
addMenuItem(L["Bid Price"], "bid", true, function()
return MoneyInputFrame_GetCopper(SellBidPrice);
end);
addMenuItem(L["Buyout Price"], "buyout", true, function()
return MoneyInputFrame_GetCopper(SellBuyoutPrice);
end);
-- Add the save/clear all items.
table.insert(menuList, {
text = "",
});
table.insert(menuList, {
text = L["Save All"],
func = function()
local i;
for i = 2, 5 do
local item = menuList[i];
if not item.checked then
item.func();
end
end
end,
});
table.insert(menuList, {
text = L["Clear All"],
func = function()
local i;
for i = 2, 5 do
local item = menuList[i];
if item.checked then
item.func();
end
end
end,
});
-- Now show/hide the menu.
SellRememberDropDown.displayMode = "MENU";
SellRememberDropDown.initialize = EasyMenu_Initialize;
SellRememberDropDown.point = "TOPRIGHT";
SellRememberDropDown.relativeTo = "SellRememberButton";
SellRememberDropDown.relativePoint = "BOTTOMRIGHT";
ToggleDropDownMenu(1, nil, SellRememberDropDown,
"SellRememberButton", 0, 0, menuList);
end
end
-- Get the auction duration.
function AuctionLite:GetDuration()
local time = 0;
if SellShortAuctionButton:GetChecked() then
time = 1;
elseif SellMediumAuctionButton:GetChecked() then
time = 2;
elseif SellLongAuctionButton:GetChecked() then
time = 3;
end
return time;
end
-- Handle updates to the auction duration.
function AuctionLite:ChangeAuctionDuration(value)
self.db.profile.duration = value;
SellShortAuctionButton:SetChecked(nil);
SellMediumAuctionButton:SetChecked(nil);
SellLongAuctionButton:SetChecked(nil);
if value == DURATION_SHORT then
SellShortAuctionButton:SetChecked(true);
elseif value == DURATION_MEDIUM then
SellMediumAuctionButton:SetChecked(true);
elseif value == DURATION_LONG then
SellLongAuctionButton:SetChecked(true);
end
self:UpdateDeposit();
end
-- Handle updates to the pricing method.
function AuctionLite:ChangePricingMethod(value)
local prevValue = self.db.profile.method;
self.db.profile.method = value;
local stackSize = SellSize:GetNumber();
-- Clear everything.
SellPerItemButton:SetChecked(nil);
SellPerStackButton:SetChecked(nil);
-- Now update the UI based on the new value.
if value == METHOD_PER_ITEM then
SellPerItemButton:SetChecked(true);
SellBidStackText:SetText(L["|cff808080(per item)|r"]);
SellBuyoutStackText:SetText(L["|cff808080(per item)|r"]);
elseif value == METHOD_PER_STACK then
SellPerStackButton:SetChecked(true);
SellBidStackText:SetText(L["|cff808080(per stack)|r"]);
SellBuyoutStackText:SetText(L["|cff808080(per stack)|r"]);
end
-- Update the listed prices based on the new pricing method.
self:UpdatePrices();
end
-- User changed the prices manually.
function AuctionLite:UserChangedPrices()
-- Get the user's values.
local bid = MoneyInputFrame_GetCopper(SellBidPrice);
local buyout = MoneyInputFrame_GetCopper(SellBuyoutPrice);
-- If we're pricing by stack, divide by our stack size.
if self.db.profile.method == METHOD_PER_STACK then
local stackSize = SellSize:GetNumber();
bid = bid / stackSize;
buyout = buyout / stackSize;
end
-- Set our new state.
self:SetItemBidBuyout(bid, buyout);
end
-- Update query progress.
function AuctionLite:UpdateProgressSell(pct)
self:SetStatus(L["|cffffff00Scanning: %d%%|r"]:format(pct));
end
-- Apply the current sort.
function AuctionLite:ApplySellSort()
local info = SellSort;
local data = SellData;
local cmp;
if info.sort == "ItemName" then
cmp = function(a, b) return a.count < b.count end;
elseif info.sort == "BuyoutEach" then
cmp = function(a, b) return a.buyout / a.count < b.buyout / b.count end;
elseif info.sort == "BuyoutAll" then
cmp = function(a, b) return a.buyout < b.buyout end;
else
assert(false);
end
self:ApplySort(info, data, cmp);
end
-- Set a new sort type for the "Sell" tab.
function AuctionLite:SellSortButton_OnClick(sort)
assert(sort == "ItemName" or sort == "BuyoutEach" or sort == "BuyoutAll");
self:SortButton_OnClick(SellSort, sort);
self:AuctionFrameSell_Update();
end
-- Paint the scroll frame on the right-hand side with competing auctions.
function AuctionLite:AuctionFrameSell_Update()
if not SellSort.sorted then
self:ApplySellSort();
end
local sort;
for _, sort in ipairs({ "ItemName", "BuyoutEach", "BuyoutAll" }) do
self:UpdateSortArrow("Sell", sort, SellSort.sort, SellSort.flipped);
end
local offset = FauxScrollFrame_GetOffset(SellScrollFrame);
local name, color, enchant, jewel1, jewel2, jewel3, jewel4;
local showPlus;
if SellLink ~= nil then
name, color, _, _, enchant, jewel1, jewel2, jewel3, jewel4 =
self:SplitLink(SellLink);
showPlus = enchant ~= 0 or
jewel1 ~= 0 or jewel2 ~= 0 or
jewel3 ~= 0 or jewel4 ~= 0;
end
local i;
for i = 1, SELL_DISPLAY_SIZE do
local item = SellData[offset + i];
local buttonName = "SellButton" .. i;
local button = _G[buttonName];
if item ~= nil then
local countText = _G[buttonName .. "Count"];
local nameText = _G[buttonName .. "Name"];
local plusText = _G[buttonName .. "Plus"];
local buyoutEachFrame = _G[buttonName .. "BuyoutEachFrame"];
local buyoutFrame = _G[buttonName .. "BuyoutFrame"];
local alpha;
if item.owner ~= UnitName("player") and not item.keep then
alpha = 0.5;
else
alpha = 1.0;
end
local countColor;
local nameColor;
if item.owner == UnitName("player") then
countColor = "ffffff00";
nameColor = "ffffff00";
else
countColor = "ffffffff";
nameColor = color;
end
countText:SetText("|c" .. countColor .. item.count .. "x|r");
countText:SetAlpha(alpha);
nameText:SetText("|c" .. nameColor .. name .. "|r");
nameText:SetAlpha(alpha);
if showPlus then
plusText:SetPoint("LEFT", nameText, "LEFT",
nameText:GetStringWidth(), 0);
plusText:Show();
else
plusText:Hide();
end
MoneyFrame_Update(buyoutEachFrame, math.floor(item.buyout / item.count + 0.5));
buyoutEachFrame:SetAlpha(alpha);
MoneyFrame_Update(buyoutFrame, math.floor(item.buyout + 0.5));
buyoutFrame:SetAlpha(alpha);
button:Show();
else
button:Hide();
end
end
FauxScrollFrame_Update(SellScrollFrame, table.getn(SellData),
SELL_DISPLAY_SIZE, SellButton1:GetHeight());
end
-- Handle clicks on the scroll bar.
function AuctionLite:SellScrollFrame_OnVerticalScroll(offset)
FauxScrollFrame_OnVerticalScroll(
SellScrollFrame, offset, SellButton1:GetHeight(),
function() AuctionLite:AuctionFrameSell_Update() end);
end
-- Handle bag item clicks by dropping the item into the sell tab.
function AuctionLite:BagClickSell(container, slot)
if GetContainerItemLink(container, slot) ~= nil then
ClearCursor();
ClickAuctionSellItemButton();
ClearCursor();
PickupContainerItem(container, slot);
ClickAuctionSellItemButton();
end
end
-- Create the "Sell" tab.
function AuctionLite:CreateSellFrame()
-- Create our tab.
local index = self:CreateTab(L["Sell"], AuctionFrameSell);
-- Set all localizable strings in the UI.
SellTitle:SetText(L["Sell"]);
SellStackText:SetText(L["Number of Items"]);
SellStacksOfText:SetText(L["stacks of"]);
SellBuyoutText:SetText(L["Buyout Price"]);
SellMethodText:SetText(L["Pricing Method"]);
SellPerItemButtonText:SetText(L["per item"]);
SellPerStackButtonText:SetText(L["per stack"]);
SellShortAuctionButtonText:SetText(L["%dh"]:format(12));
SellMediumAuctionButtonText:SetText(L["%dh"]:format(24));
SellLongAuctionButtonText:SetText(L["%dh"]:format(48));
-- Set button text and adjust arrows.
SellItemNameButton:SetText(L["Competing Auctions"]);
self:UpdateSortButton("Sell", "BuyoutEach", L["Buyout Per Item"]);
self:UpdateSortButton("Sell", "BuyoutAll", L["Buyout Total"]);
-- Set our constants.
SellPerItemButton:SetID(METHOD_PER_ITEM);
SellPerStackButton:SetID(METHOD_PER_STACK);
SellShortAuctionButton:SetID(DURATION_SHORT);
SellMediumAuctionButton:SetID(DURATION_MEDIUM);
SellLongAuctionButton:SetID(DURATION_LONG);
-- Set up tabbing between fields.
MoneyInputFrame_SetNextFocus(SellBidPrice, SellBuyoutPriceGold);
MoneyInputFrame_SetPreviousFocus(SellBidPrice, SellSize);
MoneyInputFrame_SetNextFocus(SellBuyoutPrice, SellStacks);
MoneyInputFrame_SetPreviousFocus(SellBuyoutPrice, SellBidPriceCopper);
-- Miscellaneous additional setup.
MoneyFrame_SetType(SellDepositMoneyFrame, "AUCTIONLITE_DEPOSIT");
-- Make sure it's pristine.
self:ClearSellFrame();
-- Set preferences.
self:ChangeAuctionDuration(self.db.profile.duration);
self:ChangePricingMethod(self.db.profile.method);
return index;
end