vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 Auctioneer Addon for World of Warcraft(tm).
3 Version: 3.9.0.1000 (Kangaroo)
4 Revision: $Id: AuctionFramePost.lua 993 2006-09-03 12:59:33Z norganna $
5  
6 Auctioneer Post Auctions tab
7  
8 License:
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13  
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18  
19 You should have received a copy of the GNU General Public License
20 along with this program(see GPL.txt); if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 --]]
23  
24 -------------------------------------------------------------------------------
25 -------------------------------------------------------------------------------
26 function AuctionFramePost_OnLoad()
27 -- Methods
28 this.CalculateAuctionDeposit = AuctionFramePost_CalculateAuctionDeposit;
29 this.UpdateDeposit = AuctionFramePost_UpdateDeposit;
30 this.GetItemID = AuctionFramePost_GetItemID;
31 this.GetItemSignature = AuctionFramePost_GetItemSignature;
32 this.GetItemName = AuctionFramePost_GetItemName;
33 this.SetNoteText = AuctionFramePost_SetNoteText;
34 this.GetSavePrice = AuctionFramePost_GetSavePrice;
35 this.GetStartPrice = AuctionFramePost_GetStartPrice;
36 this.SetStartPrice = AuctionFramePost_SetStartPrice;
37 this.GetBuyoutPrice = AuctionFramePost_GetBuyoutPrice;
38 this.SetBuyoutPrice = AuctionFramePost_SetBuyoutPrice;
39 this.GetStackSize = AuctionFramePost_GetStackSize;
40 this.SetStackSize = AuctionFramePost_SetStackSize;
41 this.GetStackCount = AuctionFramePost_GetStackCount;
42 this.SetStackCount = AuctionFramePost_SetStackCount;
43 this.GetDuration = AuctionFramePost_GetDuration;
44 this.SetDuration = AuctionFramePost_SetDuration;
45 this.GetDeposit = AuctionFramePost_GetDeposit;
46 this.SetAuctionItem = AuctionFramePost_SetAuctionItem;
47 this.ValidateAuction = AuctionFramePost_ValidateAuction;
48 this.UpdateAuctionList = AuctionFramePost_UpdateAuctionList;
49 this.UpdatePriceModels = AuctionFramePost_UpdatePriceModels;
50  
51 -- Data Members
52 this.itemID = nil;
53 this.itemSignature = nil;
54 this.itemName = nil;
55 this.updating = false;
56 this.prices = {};
57  
58 -- Controls
59 this.auctionList = getglobal(this:GetName().."List");
60 this.bidMoneyInputFrame = getglobal(this:GetName().."StartPrice");
61 this.buyoutMoneyInputFrame = getglobal(this:GetName().."BuyoutPrice");
62 this.stackSizeEdit = getglobal(this:GetName().."StackSize");
63 this.stackSizeCount = getglobal(this:GetName().."StackCount");
64 this.depositMoneyFrame = getglobal(this:GetName().."DepositMoneyFrame");
65 this.depositErrorLabel = getglobal(this:GetName().."UnknownDepositText");
66  
67 -- Setup the tab order for the money input frames.
68 MoneyInputFrame_SetPreviousFocus(this.bidMoneyInputFrame, this.stackSizeCount);
69 MoneyInputFrame_SetNextFocus(this.bidMoneyInputFrame, getglobal(this.buyoutMoneyInputFrame:GetName().."Gold"));
70 MoneyInputFrame_SetPreviousFocus(this.buyoutMoneyInputFrame, getglobal(this.bidMoneyInputFrame:GetName().."Copper"));
71 MoneyInputFrame_SetNextFocus(this.buyoutMoneyInputFrame, this.stackSizeEdit);
72  
73 -- Configure the logical columns
74 this.logicalColumns =
75 {
76 Quantity =
77 {
78 title = _AUCT("UiQuantityHeader");
79 dataType = "Number";
80 valueFunc = (function(record) return record.quantity end);
81 alphaFunc = AuctionFramePost_GetItemAlpha;
82 compareAscendingFunc = (function(record1, record2) return record1.quantity < record2.quantity end);
83 compareDescendingFunc = (function(record1, record2) return record1.quantity > record2.quantity end);
84 },
85 Name =
86 {
87 title = _AUCT("UiNameHeader");
88 dataType = "String";
89 valueFunc = (function(record) return record.name end);
90 colorFunc = AuctionFramePost_GetItemColor;
91 alphaFunc = AuctionFramePost_GetItemAlpha;
92 compareAscendingFunc = (function(record1, record2) return record1.name < record2.name end);
93 compareDescendingFunc = (function(record1, record2) return record1.name > record2.name end);
94 },
95 TimeLeft =
96 {
97 title = _AUCT("UiTimeLeftHeader");
98 dataType = "String";
99 valueFunc = (function(record) return Auctioneer.Util.GetTimeLeftString(record.timeLeft) end);
100 alphaFunc = AuctionFramePost_GetItemAlpha;
101 compareAscendingFunc = (function(record1, record2) return record1.timeLeft < record2.timeLeft end);
102 compareDescendingFunc = (function(record1, record2) return record1.timeLeft > record2.timeLeft end);
103 },
104 Bid =
105 {
106 title = _AUCT("UiBidHeader");
107 dataType = "Money";
108 valueFunc = (function(record) return record.bid end);
109 alphaFunc = AuctionFramePost_GetItemAlpha;
110 compareAscendingFunc = (function(record1, record2) return record1.bid < record2.bid end);
111 compareDescendingFunc = (function(record1, record2) return record1.bid > record2.bid end);
112 },
113 BidPer =
114 {
115 title = _AUCT("UiBidPerHeader");
116 dataType = "Money";
117 valueFunc = (function(record) return record.bidPer end);
118 alphaFunc = AuctionFramePost_GetItemAlpha;
119 compareAscendingFunc = (function(record1, record2) return record1.bidPer < record2.bidPer end);
120 compareDescendingFunc = (function(record1, record2) return record1.bidPer > record2.bidPer end);
121 },
122 Buyout =
123 {
124 title = _AUCT("UiBuyoutHeader");
125 dataType = "Money";
126 valueFunc = (function(record) return record.buyout end);
127 alphaFunc = AuctionFramePost_GetItemAlpha;
128 compareAscendingFunc = (function(record1, record2) return record1.buyout < record2.buyout end);
129 compareDescendingFunc = (function(record1, record2) return record1.buyout > record2.buyout end);
130 },
131 BuyoutPer =
132 {
133 title = _AUCT("UiBuyoutPerHeader");
134 dataType = "Money";
135 valueFunc = (function(record) return record.buyoutPer end);
136 alphaFunc = AuctionFramePost_GetItemAlpha;
137 compareAscendingFunc = (function(record1, record2) return record1.buyoutPer < record2.buyoutPer end);
138 compareDescendingFunc = (function(record1, record2) return record1.buyoutPer > record2.buyoutPer end);
139 },
140 };
141  
142 -- Configure the physical columns
143 this.physicalColumns =
144 {
145 {
146 width = 50;
147 logicalColumn = this.logicalColumns.Quantity;
148 logicalColumns = { this.logicalColumns.Quantity };
149 sortAscending = true;
150 },
151 {
152 width = 210;
153 logicalColumn = this.logicalColumns.Name;
154 logicalColumns = { this.logicalColumns.Name };
155 sortAscending = true;
156 },
157 {
158 width = 90;
159 logicalColumn = this.logicalColumns.TimeLeft;
160 logicalColumns = { this.logicalColumns.TimeLeft };
161 sortAscending = true;
162 },
163 {
164 width = 130;
165 logicalColumn = this.logicalColumns.Bid;
166 logicalColumns =
167 {
168 this.logicalColumns.Bid,
169 this.logicalColumns.BidPer
170 };
171 sortAscending = true;
172 },
173 {
174 width = 130;
175 logicalColumn = this.logicalColumns.Buyout;
176 logicalColumns =
177 {
178 this.logicalColumns.Buyout,
179 this.logicalColumns.BuyoutPer
180 };
181 sortAscending = true;
182 },
183 };
184  
185 this.auctions = {};
186 ListTemplate_Initialize(this.auctionList, this.physicalColumns, this.logicalColumns);
187 ListTemplate_SetContent(this.auctionList, this.auctions);
188  
189 this:ValidateAuction();
190 end
191  
192 -------------------------------------------------------------------------------
193 -------------------------------------------------------------------------------
194 AuctionFramePost_AdditionalPricingModels = {
195 }
196 function AuctionFramePost_UpdatePriceModels(frame)
197 if (not frame.updating) then
198 frame.prices = {};
199  
200 local name = frame:GetItemName();
201 local count = frame:GetStackSize();
202 if (name and count) then
203 local bag, slot, id, rprop, enchant, uniq = EnhTooltip.FindItemInBags(name);
204 local itemKey = id..":"..rprop..":"..enchant;
205 local hsp, histCount, market, warn, nexthsp, nextwarn = Auctioneer.Statistic.GetHSP(itemKey, Auctioneer.Util.GetAuctionKey());
206  
207 -- Get the fixed price
208 if (Auctioneer.Storage.GetFixedPrice(itemKey)) then
209 local startPrice, buyPrice = Auctioneer.Storage.GetFixedPrice(itemKey, count);
210 local fixedPrice = {};
211 fixedPrice.text = _AUCT('UiPriceModelFixed');
212 fixedPrice.note = "";
213 fixedPrice.bid = startPrice;
214 fixedPrice.buyout = buyPrice;
215 table.insert(frame.prices, fixedPrice);
216 end
217  
218 -- Add any pricing models from external addons
219 for pos, priceFunc in AuctionFramePost_AdditionalPricingModels do
220 local priceModel = priceFunc(id, rprop, enchant, name, count)
221 if (type(priceModel) == "table") then
222 table.insert(frame.prices, priceModel)
223 end
224 end
225  
226 -- Get the last sale price if BeanCounter is loaded.
227 if (IsAddOnLoaded("BeanCounter")) then
228 -- TODO: Support should be added to BeanCounter for looking
229 -- up itemKey (itemId:suffixId:enchantID) instead of by name.
230 local lastSale = BeanCounter.Sales.GetLastSaleForItem(name);
231 if (lastSale and lastSale.bid and lastSale.buyout) then
232 local lastPrice = {};
233 lastPrice.text = _AUCT('UiPriceModelLastSold');
234 lastPrice.note = string.format(_AUCT('FrmtLastSoldOn'), date("%x", lastSale.time));
235 lastPrice.bid = (lastSale.bid / lastSale.quantity) * count;
236 lastPrice.buyout = (lastSale.buyout / lastSale.quantity) * count;
237 table.insert(frame.prices, lastPrice);
238 end
239 end
240  
241 -- Calculate auctioneer's suggested resale price.
242 if (hsp == 0) then
243 local auctionPriceItem = Auctioneer.Core.GetAuctionPriceItem(itemKey, Auctioneer.Util.GetAuctionKey());
244 local aCount,minCount,minPrice,bidCount,bidPrice,buyCount,buyPrice = Auctioneer.Core.GetAuctionPrices(auctionPriceItem.data);
245 hsp = math.floor(buyPrice / buyCount); -- use mean buyout if median not available
246 end
247 local discountBidPercent = tonumber(Auctioneer.Command.GetFilterVal('pct-bidmarkdown'));
248 local auctioneerPrice = {};
249 auctioneerPrice.text = _AUCT('UiPriceModelAuctioneer');
250 auctioneerPrice.note = warn;
251 auctioneerPrice.buyout = Auctioneer.Statistic.RoundDownTo95(Auctioneer.Util.NullSafe(hsp) * count);
252 auctioneerPrice.bid = Auctioneer.Statistic.RoundDownTo95(Auctioneer.Statistic.SubtractPercent(auctioneerPrice.buyout, discountBidPercent));
253 table.insert(frame.prices, auctioneerPrice);
254  
255 -- Add the fallback custom price
256 local customPrice = {}
257 customPrice.text = _AUCT('UiPriceModelCustom');
258 customPrice.note = "";
259 customPrice.bid = nil;
260 customPrice.buyout = nil;
261 table.insert(frame.prices, customPrice);
262  
263 -- Update the price model combo.
264 local dropdown = getglobal(frame:GetName().."PriceModelDropDown");
265 local index = UIDropDownMenu_GetSelectedID(dropdown);
266 if (index == nil) then
267 index = 1;
268 end
269 AuctionFramePost_PriceModelDropDownItem_SetSelectedID(dropdown, index);
270 else
271 -- Update the price model combo.
272 local dropdown = getglobal(frame:GetName().."PriceModelDropDown");
273 AuctionFramePost_PriceModelDropDownItem_SetSelectedID(dropdown, nil);
274 end
275 end
276 end
277  
278 -------------------------------------------------------------------------------
279 -- Updates the content of the auction list based on the current auction item.
280 -------------------------------------------------------------------------------
281 function AuctionFramePost_UpdateAuctionList(frame)
282 frame.auctions = {};
283 local itemSignature = frame:GetItemSignature();
284 if (itemSignature) then
285 local auctions = Auctioneer.Filter.QuerySnapshot(AuctionFramePost_ItemSignatureFilter, itemSignature);
286 if (auctions) then
287 for _,a in pairs(auctions) do
288 local id,rprop,enchant,name,count,min,buyout,uniq = Auctioneer.Core.GetItemSignature(a.signature);
289 local auction = {};
290 auction.item = string.format("item:%s:%s:%s:0", id, enchant, rprop);
291 auction.quantity = count;
292 auction.name = name;
293 auction.owner = a.owner;
294 auction.timeLeft = a.timeLeft;
295 auction.bid = Auctioneer.Statistic.GetCurrentBid(a.signature);
296 auction.bidPer = math.floor(auction.bid / auction.quantity);
297 auction.buyout = buyout;
298 auction.buyoutPer = math.floor(auction.buyout / auction.quantity);
299 table.insert(frame.auctions, auction);
300 end
301 end
302 end
303 ListTemplate_SetContent(frame.auctionList, frame.auctions);
304 ListTemplate_Sort(frame.auctionList, 5);
305 end
306  
307 -------------------------------------------------------------------------------
308 -- Updates the deposit value.
309 -------------------------------------------------------------------------------
310 function AuctionFramePost_UpdateDeposit(frame)
311 if (not frame.updating) then
312 local itemID = frame:GetItemID();
313 local duration = frame:GetDuration();
314 local stackSize = frame:GetStackSize();
315 local stackCount = frame:GetStackCount();
316 if (itemID) then
317 local deposit = AuctionFramePost_CalculateAuctionDeposit(itemID, stackSize, duration);
318 if (deposit) then
319 MoneyFrame_Update(frame.depositMoneyFrame:GetName(), deposit * stackCount);
320 frame.depositMoneyFrame:Show();
321 frame.depositErrorLabel:Hide();
322 else
323 MoneyFrame_Update(frame.depositMoneyFrame:GetName(), 0);
324 frame.depositMoneyFrame:Hide();
325 frame.depositErrorLabel:Show();
326 end
327 else
328 MoneyFrame_Update(frame.depositMoneyFrame:GetName(), 0);
329 frame.depositMoneyFrame:Hide();
330 frame.depositErrorLabel:Hide();
331 end
332 end
333 end
334  
335 -------------------------------------------------------------------------------
336 -- Gets the item ID.
337 -------------------------------------------------------------------------------
338 function AuctionFramePost_GetItemID(frame)
339 return frame.itemID;
340 end
341  
342 -------------------------------------------------------------------------------
343 -- Gets the item signature.
344 -------------------------------------------------------------------------------
345 function AuctionFramePost_GetItemSignature(frame)
346 return frame.itemSignature;
347 end
348  
349 -------------------------------------------------------------------------------
350 -- Gets the item name.
351 -------------------------------------------------------------------------------
352 function AuctionFramePost_GetItemName(frame)
353 return frame.itemName;
354 end
355  
356 -------------------------------------------------------------------------------
357 -- Sets the price model note (i.e. "Undercutting 5%")
358 -------------------------------------------------------------------------------
359 function AuctionFramePost_SetNoteText(frame, text, colorize)
360 getglobal(frame:GetName().."PriceModelNoteText"):SetText(text);
361 if (colorize) then
362 local cHex, cRed, cGreen, cBlue = Auctioneer.Util.GetWarnColor(text);
363 getglobal(frame:GetName().."PriceModelNoteText"):SetTextColor(cRed, cGreen, cBlue);
364 else
365 getglobal(frame:GetName().."PriceModelNoteText"):SetTextColor(1.0, 1.0, 1.0);
366 end
367 end
368  
369 -------------------------------------------------------------------------------
370 -- Gets whether or not to save the current price information as the fixed
371 -- price.
372 -------------------------------------------------------------------------------
373 function AuctionFramePost_GetSavePrice(frame)
374 local checkbox = getglobal(frame:GetName().."SavePriceCheckBox");
375 return (checkbox and checkbox:IsVisible() and checkbox:GetChecked());
376 end
377  
378 -------------------------------------------------------------------------------
379 -- Gets the starting price.
380 -------------------------------------------------------------------------------
381 function AuctionFramePost_GetStartPrice(frame)
382 return MoneyInputFrame_GetCopper(getglobal(frame:GetName().."StartPrice"));
383 end
384  
385 -------------------------------------------------------------------------------
386 -- Sets the starting price.
387 -------------------------------------------------------------------------------
388 function AuctionFramePost_SetStartPrice(frame, price)
389 frame.ignoreStartPriceChange = true;
390 MoneyInputFrame_SetCopper(getglobal(frame:GetName().."StartPrice"), price);
391 frame:ValidateAuction();
392 end
393  
394 -------------------------------------------------------------------------------
395 -- Gets the buyout price.
396 -------------------------------------------------------------------------------
397 function AuctionFramePost_GetBuyoutPrice(frame)
398 return MoneyInputFrame_GetCopper(getglobal(frame:GetName().."BuyoutPrice"));
399 end
400  
401 -------------------------------------------------------------------------------
402 -- Sets the buyout price.
403 -------------------------------------------------------------------------------
404 function AuctionFramePost_SetBuyoutPrice(frame, price)
405 frame.ignoreBuyoutPriceChange = true;
406 MoneyInputFrame_SetCopper(getglobal(frame:GetName().."BuyoutPrice"), price);
407 frame:ValidateAuction();
408 end
409  
410 -------------------------------------------------------------------------------
411 -- Gets the stack size.
412 -------------------------------------------------------------------------------
413 function AuctionFramePost_GetStackSize(frame)
414 return getglobal(frame:GetName().."StackSize"):GetNumber();
415 end
416  
417 -------------------------------------------------------------------------------
418 -- Sets the stack size.
419 -------------------------------------------------------------------------------
420 function AuctionFramePost_SetStackSize(frame, size)
421 -- Update the stack size.
422 getglobal(frame:GetName().."StackSize"):SetNumber(size);
423  
424 -- Update the deposit cost.
425 frame:UpdateDeposit();
426 frame:UpdatePriceModels();
427 frame:ValidateAuction();
428 end
429  
430 -------------------------------------------------------------------------------
431 -- Gets the stack count.
432 -------------------------------------------------------------------------------
433 function AuctionFramePost_GetStackCount(frame)
434 return getglobal(frame:GetName().."StackCount"):GetNumber();
435 end
436  
437 -------------------------------------------------------------------------------
438 -- Sets the stack count.
439 -------------------------------------------------------------------------------
440 function AuctionFramePost_SetStackCount(frame, count)
441 -- Update the stack count.
442 getglobal(frame:GetName().."StackCount"):SetNumber(count);
443  
444 -- Update the deposit cost.
445 frame:UpdateDeposit();
446 frame:ValidateAuction();
447 end
448  
449 -------------------------------------------------------------------------------
450 -- Gets the duration.
451 -------------------------------------------------------------------------------
452 function AuctionFramePost_GetDuration(frame)
453 if (getglobal(frame:GetName().."ShortAuctionRadio"):GetChecked()) then
454 return 120;
455 elseif(getglobal(frame:GetName().."MediumAuctionRadio"):GetChecked()) then
456 return 480;
457 else
458 return 1440;
459 end
460 end
461  
462 -------------------------------------------------------------------------------
463 -- Sets the duration.
464 -------------------------------------------------------------------------------
465 function AuctionFramePost_SetDuration(frame, duration)
466 local shortRadio = getglobal(frame:GetName().."ShortAuctionRadio");
467 local mediumRadio = getglobal(frame:GetName().."MediumAuctionRadio");
468 local longRadio = getglobal(frame:GetName().."LongAuctionRadio");
469  
470 -- Figure out radio to set as checked.
471 if (duration == 120) then
472 shortRadio:SetChecked(1);
473 mediumRadio:SetChecked(nil);
474 longRadio:SetChecked(nil);
475 elseif (duration == 480) then
476 shortRadio:SetChecked(nil);
477 mediumRadio:SetChecked(1);
478 longRadio:SetChecked(nil);
479 else
480 shortRadio:SetChecked(nil);
481 mediumRadio:SetChecked(nil);
482 longRadio:SetChecked(1);
483 end
484  
485 -- Update the deposit cost.
486 frame:UpdateDeposit();
487 frame:ValidateAuction();
488 end
489  
490 -------------------------------------------------------------------------------
491 -- Gets the deposit amount required to post.
492 -------------------------------------------------------------------------------
493 function AuctionFramePost_GetDeposit(frame)
494 return getglobal(frame:GetName().."DepositMoneyFrame").staticMoney;
495 end
496  
497 -------------------------------------------------------------------------------
498 -- Sets the item to display in the create auction frame.
499 -------------------------------------------------------------------------------
500 function AuctionFramePost_SetAuctionItem(frame, bag, item, count)
501 -- Prevent validation while updating.
502 frame.updating = true;
503  
504 -- Update the controls with the item.
505 local button = getglobal(frame:GetName().."AuctionItem");
506 if (bag and item) then
507 -- Get the item's information.
508 local itemLink = GetContainerItemLink(bag, item);
509 local itemID, randomProp, enchant, uniqueId, name = EnhTooltip.BreakLink(itemLink);
510 local itemTexture, itemCount = GetContainerItemInfo(bag, item);
511 if (count == nil) then
512 count = itemCount;
513 end
514  
515 -- Save the item's information.
516 frame.itemID = itemID;
517 frame.itemSignature = AucPostManager.CreateItemSignature(itemID, randomProp, enchant);
518 frame.itemName = name;
519  
520 -- Show the item
521 getglobal(button:GetName().."Name"):SetText(name);
522 getglobal(button:GetName().."Name"):Show();
523 getglobal(button:GetName().."IconTexture"):SetTexture(itemTexture);
524 getglobal(button:GetName().."IconTexture"):Show();
525  
526 -- Set the defaults.
527 local duration = Auctioneer.Command.GetFilterVal('auction-duration')
528 if duration == 1 then
529 -- 2h
530 frame:SetDuration(120)
531 elseif duration == 2 then
532 -- 8h
533 frame:SetDuration(480)
534 elseif duration == 3 then
535 -- 24h
536 frame:SetDuration(1440)
537 else
538 -- last
539 frame:SetDuration(Auctioneer.Command.GetFilterVal('last-auction-duration'))
540 end
541 frame:SetStackSize(count);
542 frame:SetStackCount(1);
543  
544 -- Clear the current pricing model so that the default one gets selected.
545 local dropdown = getglobal(frame:GetName().."PriceModelDropDown");
546 AuctionFramePost_PriceModelDropDownItem_SetSelectedID(dropdown, nil);
547  
548 -- Update the Transactions tab if BeanCounter is loaded.
549 if (AuctionFrameTransactions) then
550 AuctionFrameTransactions:SearchTransactions(name, true, nil);
551 end
552 else
553 -- Clear the item's information.
554 frame.itemID = nil;
555 frame.itemSignature = nil;
556 frame.itemName = nil;
557  
558 -- Hide the item
559 getglobal(button:GetName().."Name"):Hide();
560 getglobal(button:GetName().."IconTexture"):Hide();
561  
562 -- Clear the defaults.
563 frame:SetStackSize(1);
564 frame:SetStackCount(1);
565 end
566  
567 -- Update the deposit cost and validate the auction.
568 frame.updating = false;
569 frame:UpdateDeposit();
570 frame:UpdatePriceModels();
571 frame:UpdateAuctionList();
572 frame:ValidateAuction();
573 end
574  
575 -------------------------------------------------------------------------------
576 -- Validates the current auction.
577 -------------------------------------------------------------------------------
578 function AuctionFramePost_ValidateAuction(frame)
579 -- Only validate if its not turned off.
580 if (not frame.updating) then
581 -- Check that we have an item.
582 local valid = false;
583 if (frame.itemID) then
584 valid = (frame.itemID ~= nil);
585 end
586  
587 -- Check that there is a starting price.
588 local startPrice = frame:GetStartPrice();
589 local startErrorText = getglobal(frame:GetName().."StartPriceInvalidText");
590 if (startPrice == 0) then
591 valid = false;
592 startErrorText:Show();
593 else
594 startErrorText:Hide();
595 end
596  
597 -- Check that the starting price is less than or equal to the buyout.
598 local buyoutPrice = frame:GetBuyoutPrice();
599 local buyoutErrorText = getglobal(frame:GetName().."BuyoutPriceInvalidText");
600 if (buyoutPrice > 0 and buyoutPrice < startPrice) then
601 valid = false;
602 buyoutErrorText:Show();
603 else
604 buyoutErrorText:Hide();
605 end
606  
607 -- Check that the item stacks to the amount specified and that the player
608 -- has enough of the item.
609 local stackSize = frame:GetStackSize();
610 local stackCount = frame:GetStackCount();
611 local quantityErrorText = getglobal(frame:GetName().."QuantityInvalidText");
612 if (frame.itemID and frame.itemSignature) then
613 local quantity = AucPostManager.GetItemQuantityBySignature(frame.itemSignature);
614 local maxStackSize = AuctionFramePost_GetMaxStackSize(frame.itemID);
615 if (stackSize == 0) then
616 valid = false;
617 quantityErrorText:SetText(_AUCT('UiStackTooSmallError'));
618 quantityErrorText:SetTextColor(RED_FONT_COLOR.r, RED_FONT_COLOR.g, RED_FONT_COLOR.b);
619 quantityErrorText:Show();
620 elseif (stackSize > 1 and (maxStackSize == nil or stackSize > maxStackSize)) then
621 valid = false;
622 quantityErrorText:SetText(_AUCT('UiStackTooBigError'));
623 quantityErrorText:SetTextColor(RED_FONT_COLOR.r, RED_FONT_COLOR.g, RED_FONT_COLOR.b);
624 quantityErrorText:Show();
625 elseif (quantity < (stackSize * stackCount)) then
626 valid = false;
627 quantityErrorText:SetText(_AUCT('UiNotEnoughError'));
628 quantityErrorText:SetTextColor(RED_FONT_COLOR.r, RED_FONT_COLOR.g, RED_FONT_COLOR.b);
629 quantityErrorText:Show();
630 else
631 local msg = string.format(_AUCT('UiMaxError'), quantity);
632 quantityErrorText:SetText(msg);
633 quantityErrorText:SetTextColor(GRAY_FONT_COLOR.r, GRAY_FONT_COLOR.g, GRAY_FONT_COLOR.b);
634 quantityErrorText:Show();
635 end
636 else
637 quantityErrorText:Hide();
638 end
639  
640 -- TODO: Check that the player can afford the deposit cost.
641 local deposit = frame:GetDeposit();
642  
643 -- Update the state of the Create Auction button.
644 local button = getglobal(frame:GetName().."CreateAuctionButton");
645 if (valid) then
646 button:Enable();
647 else
648 button:Disable();
649 end
650  
651 -- Update the price model to reflect bid and buyout prices.
652 local dropdown = getglobal(frame:GetName().."PriceModelDropDown");
653 local index = UIDropDownMenu_GetSelectedID(dropdown);
654 if (index and frame.prices and index <= table.getn(frame.prices)) then
655 -- Check if the current selection matches
656 local currentPrice = frame.prices[index];
657 if ((currentPrice.bid and currentPrice.bid ~= startPrice) or
658 (currentPrice.buyout and currentPrice.buyout ~= buyoutPrice)) then
659 -- Nope, find one that does.
660 for index,price in pairs(frame.prices) do
661 if ((price.bid == nil or price.bid == startPrice) and (price.buyout == nil or price.buyout == buyoutPrice)) then
662 if (UIDropDownMenu_GetSelectedID(dropdown) ~= index) then
663 AuctionFramePost_PriceModelDropDownItem_SetSelectedID(dropdown, index);
664 end
665 break;
666 end
667 end
668 end
669 end
670 end
671 end
672  
673 -------------------------------------------------------------------------------
674 -------------------------------------------------------------------------------
675 function AuctionFramePost_AuctionItem_OnClick(button)
676 local frame = button:GetParent();
677  
678 -- If the cursor has an item, get it and put it back down in its container.
679 local item = AuctioneerUI_GetCursorContainerItem();
680 if (item) then
681 PickupContainerItem(item.bag, item.slot);
682 end
683  
684 -- Update the current item displayed
685 if (item) then
686 local itemLink = GetContainerItemLink(item.bag, item.slot)
687 local _, _, _, _, itemName = EnhTooltip.BreakLink(itemLink);
688 local _, count = GetContainerItemInfo(item.bag, item.slot);
689 frame:SetAuctionItem(item.bag, item.slot, count);
690 else
691 frame:SetAuctionItem(nil, nil, nil);
692 end
693 end
694  
695 -------------------------------------------------------------------------------
696 -------------------------------------------------------------------------------
697 function AuctionFramePost_DurationRadioButton_OnClick(button, index)
698 local frame = button:GetParent();
699 if (index == 1) then
700 Auctioneer.Command.SetFilter('last-auction-duration', 120)
701 frame:SetDuration(120);
702 elseif (index == 2) then
703 Auctioneer.Command.SetFilter('last-auction-duration', 480)
704 frame:SetDuration(480);
705 else
706 Auctioneer.Command.SetFilter('last-auction-duration', 1440)
707 frame:SetDuration(1440);
708 end
709 end
710  
711 -------------------------------------------------------------------------------
712 -------------------------------------------------------------------------------
713 function AuctionFramePost_StartPrice_OnChanged()
714 local frame = this:GetParent():GetParent();
715 if (not frame.ignoreStartPriceChange and not updating) then
716 frame:ValidateAuction();
717 end
718 frame.ignoreStartPriceChange = false;
719 end
720  
721 -------------------------------------------------------------------------------
722 -------------------------------------------------------------------------------
723 function AuctionFramePost_BuyoutPrice_OnChanged()
724 local frame = this:GetParent():GetParent();
725 if (not frame.ignoreBuyoutPriceChange and not frame.updating) then
726 local updatePrice = Auctioneer.Command.GetFilter('update-price');
727 if (updatePrice) then
728 frame.updating = true;
729 local discountBidPercent = tonumber(Auctioneer.Command.GetFilterVal('pct-bidmarkdown'));
730 local bidPrice = Auctioneer.Statistic.SubtractPercent(frame:GetBuyoutPrice(), discountBidPercent);
731 frame:SetStartPrice(bidPrice);
732 frame.updating = false;
733 end
734 frame:ValidateAuction();
735 end
736 frame.ignoreBuyoutPriceChange = false;
737 end
738  
739 -------------------------------------------------------------------------------
740 -------------------------------------------------------------------------------
741 function AuctionFramePost_StackSize_OnTextChanged()
742 local frame = this:GetParent();
743  
744 -- Update the stack size displayed on the graphic.
745 local itemID = frame:GetItemID();
746 local stackSize = frame:GetStackSize();
747 if (itemID and stackSize > 1) then
748 getglobal(frame:GetName().."AuctionItemCount"):SetText(stackSize);
749 getglobal(frame:GetName().."AuctionItemCount"):Show();
750 else
751 getglobal(frame:GetName().."AuctionItemCount"):Hide();
752 end
753  
754 -- Update the deposit and validate the auction.
755 frame:UpdateDeposit();
756 frame:UpdatePriceModels();
757 frame:ValidateAuction();
758 end
759  
760 -------------------------------------------------------------------------------
761 -------------------------------------------------------------------------------
762 function AuctionFramePost_StackCount_OnTextChanged()
763 local frame = this:GetParent();
764 frame:UpdateDeposit();
765 frame:ValidateAuction();
766 end
767  
768 -------------------------------------------------------------------------------
769 -------------------------------------------------------------------------------
770 function AuctionFramePost_CreateAuctionButton_OnClick(button)
771 local frame = button:GetParent();
772 local itemSignature = frame:GetItemSignature();
773 local name = frame:GetItemName();
774 local startPrice = frame:GetStartPrice();
775 local buyoutPrice = frame:GetBuyoutPrice();
776 local stackSize = frame:GetStackSize();
777 local stackCount = frame:GetStackCount();
778 local duration = frame:GetDuration();
779 local deposit = frame:GetDeposit();
780  
781 -- Check if we should save the pricing information.
782 if (frame:GetSavePrice()) then
783 local bag, slot, id, rprop, enchant, uniq = EnhTooltip.FindItemInBags(name);
784 local itemKey = id..":"..rprop..":"..enchant;
785 Auctioneer.Storage.SetFixedPrice(itemKey, startPrice, buyoutPrice, duration, stackSize, Auctioneer.Util.GetAuctionKey());
786 end
787  
788 -- Post the auction.
789 AucPostManager.PostAuction(itemSignature, stackSize, stackCount, startPrice, buyoutPrice, duration);
790  
791 -- Clear the current auction item.
792 frame:SetAuctionItem(nil, nil, nil);
793 end
794  
795 -------------------------------------------------------------------------------
796 -------------------------------------------------------------------------------
797 function AuctionFramePost_PriceModelDropDown_Initialize()
798 local dropdown = this:GetParent();
799 local frame = dropdown:GetParent();
800 if (frame.prices) then
801 for index, value in pairs(frame.prices) do
802 local price = value;
803 local info = {};
804 info.text = price.text;
805 info.func = AuctionFramePost_PriceModelDropDownItem_OnClick;
806 info.owner = dropdown;
807 UIDropDownMenu_AddButton(info);
808 end
809 end
810 end
811  
812 -------------------------------------------------------------------------------
813 -------------------------------------------------------------------------------
814 function AuctionFramePost_PriceModelDropDownItem_OnClick()
815 local index = this:GetID();
816 local dropdown = this.owner;
817 local frame = dropdown:GetParent();
818 if (frame.prices) then
819 AuctionFramePost_PriceModelDropDownItem_SetSelectedID(dropdown, index);
820 end
821 end
822  
823 -------------------------------------------------------------------------------
824 -------------------------------------------------------------------------------
825 function AuctionFramePost_PriceModelDropDownItem_SetSelectedID(dropdown, index)
826 local frame = dropdown:GetParent();
827 frame.updating = true;
828 if (index) then
829 local price = frame.prices[index]
830 if (price.note) then
831 frame:SetNoteText(price.note, (price.text == _AUCT('UiPriceModelAuctioneer')));
832 end
833 if (price.buyout) then
834 frame:SetBuyoutPrice(price.buyout);
835 end
836 if (price.bid) then
837 frame:SetStartPrice(price.bid);
838 end
839  
840 if (price.text == _AUCT('UiPriceModelCustom')) then
841 getglobal(frame:GetName().."SavePriceText"):Show();
842 getglobal(frame:GetName().."SavePriceCheckBox"):Show();
843 getglobal(frame:GetName().."PriceModelNoteText"):Hide();
844 elseif (price.text == _AUCT('UiPriceModelAuctioneer')) then
845 getglobal(frame:GetName().."SavePriceText"):Hide();
846 getglobal(frame:GetName().."SavePriceCheckBox"):Hide();
847 getglobal(frame:GetName().."PriceModelNoteText"):Show();
848 elseif (price.text == _AUCT('UiPriceModelLastSold')) then
849 getglobal(frame:GetName().."SavePriceText"):Hide();
850 getglobal(frame:GetName().."SavePriceCheckBox"):Hide();
851 getglobal(frame:GetName().."PriceModelNoteText"):Show();
852 else
853 getglobal(frame:GetName().."SavePriceText"):Hide();
854 getglobal(frame:GetName().."SavePriceCheckBox"):Hide();
855 getglobal(frame:GetName().."PriceModelNoteText"):Hide();
856 end
857  
858 AuctioneerDropDownMenu_Initialize(dropdown, AuctionFramePost_PriceModelDropDown_Initialize);
859 AuctioneerDropDownMenu_SetSelectedID(dropdown, index);
860 else
861 frame:SetNoteText("");
862 frame:SetStartPrice(0);
863 frame:SetBuyoutPrice(0);
864 getglobal(frame:GetName().."SavePriceText"):Hide();
865 getglobal(frame:GetName().."SavePriceCheckBox"):Hide();
866 getglobal(frame:GetName().."PriceModelNoteText"):Hide();
867 UIDropDownMenu_ClearAll(dropdown);
868 end
869 frame.updating = false;
870 frame:ValidateAuction();
871 end
872  
873 -------------------------------------------------------------------------------
874 -- Calculate the deposit required for the specified item.
875 -------------------------------------------------------------------------------
876 function AuctionFramePost_CalculateAuctionDeposit(itemID, count, duration)
877 local price = Auctioneer.API.GetVendorSellPrice(itemID);
878 if (price) then
879 local base = math.floor(count * price * GetAuctionHouseDepositRate() / 100);
880 return base * duration / 120;
881 end
882 end
883  
884 -------------------------------------------------------------------------------
885 -- Calculate the maximum stack size for an item based on the information returned by GetItemInfo()
886 -------------------------------------------------------------------------------
887 function AuctionFramePost_GetMaxStackSize(itemID)
888 local _, _, _, _, _, _, itemStackCount = GetItemInfo(itemID);
889 return itemStackCount;
890 end
891  
892 -------------------------------------------------------------------------------
893 -- Filter for Auctioneer.Filter.QuerySnapshot that filters on item name.
894 -------------------------------------------------------------------------------
895 function AuctionFramePost_ItemSignatureFilter(item, signature)
896 local id,rprop,enchant,name,count,min,buyout,uniq = Auctioneer.Core.GetItemSignature(signature);
897 if (item == AucPostManager.CreateItemSignature(id, rprop, enchant)) then
898 return false;
899 end
900 return true;
901 end
902  
903 -------------------------------------------------------------------------------
904 -- Returns 1.0 for player auctions and 0.4 for competing auctions
905 -------------------------------------------------------------------------------
906 function AuctionFramePost_GetItemAlpha(record)
907 if (record.owner ~= UnitName("player")) then
908 return 0.4;
909 end
910 return 1.0;
911 end
912  
913 -------------------------------------------------------------------------------
914 -- Returns the item color for the specified result
915 -------------------------------------------------------------------------------
916 function AuctionFramePost_GetItemColor(auction)
917 _, _, rarity = GetItemInfo(auction.item);
918 if (rarity) then
919 return ITEM_QUALITY_COLORS[rarity];
920 end
921 return { r = 1.0, g = 1.0, b = 1.0 };
922 end