vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 ADDON INFORMATION
3 Name: AuctionFilterPlus
4 Purpose: Adds flyout filters and a reset button to the auction house.
5 Command-line: NONE
6 Author: Dsanai of The Crimson Knights on Whisperwind
7  
8 Thank you to the authors of AuctionFilterRL (Joshaze), AH_Reset (AnduinLothar), and AH_Wipe (Neriak), as these mods formed the base for this extension.
9  
10 I've added a few more filters that I always wished I'd had when shopping (such as only-20-piece stacks, and exact search), changed it to a low-clutter Flyout display, added the ability to clear and save one's filter settings, merged the two mods into one, and added tooltips so users have more information about what each filter does.
11  
12 FEATURES
13 -- Adds a Filter button and a Reset button to the AuctionHouse frame.
14 -- Pressing the Filter button will cause a Flyout menu to appear.
15 -- The filter checkboxes on the flyout allow you to limit your AH results or change the display of certain information.
16 -- You can clear your filter settings with a single click.
17 -- You can clear your Auction House search boxes with a single click.
18 -- You can save your filter settings as your default setup, which will persist across sessions, characters, and servers.
19 -- You can clear your settings temporarily and then reload them without relogging.
20 -- Each of the filter checkboxes has an explanatory tooltip.
21 -- Ready for localization (please help do so, if you are German- or French-speaking). You will be credited!
22 -- Compatible with Auctioneer.
23  
24 NOT DONE YET
25 -- Fixed Dressing Room bug. Should now show the correct item even if filters are turned on.
26 -- Fixed Chat Link bug. Should now link the correct item in chat.
27  
28 VERSION HISTORY
29  
30 v10900-1
31 -- Fixed slash command (courtesy Aingnale@WorldOfWar)
32 -- Added "Grey Out Unbid Items" option. Will grey out the prices for items that have not been bid on yet. (idea courtesy myShowBid by mhsin)
33 -- Show Best Deals now takes into account Greater Essences (will be valued as 3 items when competing against Lesser Essences)
34 -- Fixed so that Auctioneer Beta will also be supported (variable name courtesy barryj@Curse)
35  
36 v1800-6
37 -- Added AuctionSort functionality (courtesy Abraha)
38 -- Added Show Best Deals, which will evaluate prices and tell you how an item fares against the average for the search results.
39 -- Show Best Deals will also take into account how many pieces of cloth were used to create bolts of cloth, when rating its value.
40  
41 v1800-5
42 -- DE translation reworked (courtesy dan2507@Curse)
43 -- Increased the width of the flyout panel, and of the Clear button, so localized strings should fit.
44 -- Can be set to color known recipes, plans, schematics, etc. (courtesy LeisureLarry@Curse)
45 -- Added command-line to open flyout panel, if the button is unclickable due to other mods.
46  
47 v1800-4
48 -- Really disables itself when KC_Items is scanning. Thanks, Sharky@Curse.
49 -- Globalized the "Already Known" string, so all clients should now be able to use that filter. Thanks, Olivier@Curse.
50  
51 v1800-3
52 -- Disables itself when KC_Items is scanning.
53 -- German localization completed (courtesy Dan2507 and Naboradd)
54 -- Localized checkbox description text.
55 -- Attempt to fix the occasional tooltip error on line 492. Let me know if tooltips show the wrong item.
56  
57 v1800-2
58 -- Disables itself when Auctioneer is scanning.
59  
60 v1800-1
61 -- Initial release
62  
63 POTENTIAL FUTURE ADDITIONS (Subject to change)
64 -- Filter: Don't show auctions listed by people I've Ignored. (Don't fund the idiots.)
65 -- Filter: Only show items that haven't been bid on yet. (Try to find ones I can snag at a bargain, without a bidding war.)
66 -- Filter: Only show XX quality items. (Blizzard quality filter shows that level AND higher.) NOTE: Read Blizzard dropdown.
67  
68 ]]
69  
70 afp_OriginalAuctionFrameBrowse_Update = nil;
71 afp_BrowseList = {};
72 local afp_OldSetWidth = nil;
73  
74 function AuctionFilterPlus_OnLoad()
75 this:RegisterEvent("AUCTION_ITEM_LIST_UPDATE");
76 this:RegisterEvent("VARIABLES_LOADED");
77 this:RegisterEvent("AUCTION_HOUSE_SHOW");
78 -- Set localization for buttons (NOW DONE INTERNALLY)
79 -- if (afp_FlyoutButton) then afp_FlyoutButton:SetText(AFP_BUTTON_TEXT_FILTER); end
80 SlashCmdList["AUCTIONFILTERPLUS"] = afp_SlashHandler;
81 SLASH_AUCTIONFILTERPLUS1 = "/auctionfilterplus"; -- Fixed by Aingnale@WorldOfWar
82 SLASH_AUCTIONFILTERPLUS2 = "/afp";
83 end
84  
85 function AuctionFilterPlus_OnEvent()
86  
87 if (event == "AUCTION_ITEM_LIST_UPDATE") then
88 afp_AuctionFrameBrowse_Update();
89  
90 elseif event == "VARIABLES_LOADED" then
91 afp_FlyoutLoad_OnClick();
92  
93 elseif (event == "AUCTION_HOUSE_SHOW" and IsAddOnLoaded("Blizzard_AuctionUI")) then
94 if (not afp_OriginalAuctionFrameBrowse_Update) then
95 afp_OriginalAuctionFrameBrowse_Update = AuctionFrameBrowse_Update;
96 AuctionFrameBrowse_Update = afp_AuctionFrameBrowse_Update;
97  
98 afp_OriginalBrowseButton_OnClick = BrowseButton_OnClick;
99 BrowseButton_OnClick = afp_BrowseButton_OnClick;
100  
101 afp_OriginalAuctionFrameItem_OnEnter = AuctionFrameItem_OnEnter;
102 AuctionFrameItem_OnEnter = afp_AuctionFrameItem_OnEnter;
103  
104 afp_OptionButton_PricePerUnit:SetParent(afp_FlyoutFrame);
105 afp_OptionButton_HideNoBuyout:SetParent(afp_FlyoutFrame);
106 afp_OptionButton_HideUnaffordable:SetParent(afp_FlyoutFrame);
107 afp_OptionButton_HideKnown:SetParent(afp_FlyoutFrame);
108 afp_OptionButton_StacksOf20:SetParent(afp_FlyoutFrame);
109 afp_OptionButton_StacksOf10:SetParent(afp_FlyoutFrame);
110 afp_OptionButton_StacksOf5:SetParent(afp_FlyoutFrame);
111 afp_OptionButton_ExactName:SetParent(afp_FlyoutFrame);
112 afp_OptionButton_ColorKnown:SetParent(afp_FlyoutFrame);
113 afp_OptionButton_ShowBestDeals:SetParent(afp_FlyoutFrame);
114 afp_OptionButton_GreyUnbid:SetParent(afp_FlyoutFrame);
115  
116 afp_FlyoutButton:ClearAllPoints()
117 afp_FlyoutButton:SetParent(AuctionFrameBrowse);
118 afp_FlyoutButton:SetPoint("TOPRIGHT","AuctionFrameBrowse","TOPRIGHT",-13,-14);
119 afp_FlyoutButton:Show();
120  
121 if (AH_ResetButton and AH_ResetButton:IsVisible()) then
122 AH_ResetButton:Hide();
123 end
124 afp_ResetButton:ClearAllPoints()
125 afp_ResetButton:SetParent(afp_FlyoutButton);
126 afp_ResetButton:SetPoint("LEFT","afp_FlyoutButton","RIGHT",-1,0);
127 afp_ResetButton:Show();
128 end
129  
130 -- AuctionSort
131 if (not afp_OldSetWidth and BrowseCurrentBidSort) then
132 BrowseBuyoutSort:ClearAllPoints();
133 BrowseBuyoutSort:SetParent(AuctionFrameBrowse);
134 BrowseBuyoutSort:SetPoint("LEFT","BrowseCurrentBidSort","RIGHT",-2,0);
135 BrowseBuyoutSort:Show();
136  
137 BrowseNameSort:ClearAllPoints();
138 BrowseNameSort:SetParent(AuctionFrameBrowse);
139 BrowseNameSort:SetPoint("TOPLEFT", "AuctionFrameBrowse", "TOPLEFT", 186, -82);
140 BrowseNameSort:Show();
141  
142 BrowseQualitySort:ClearAllPoints();
143 BrowseQualitySort:SetPoint("LEFT","BrowseNameSort","RIGHT",-2,0);
144 BrowseQualitySort:Show();
145  
146 afp_OldSetWidth = BrowseCurrentBidSort.SetWidth;
147  
148 BrowseCurrentBidSort.SetWidth = afp_SetWidth;
149 BrowseCurrentBidSort:SetWidth(207);
150 BrowseQualitySort:SetWidth(BrowseQualitySort:GetWidth() - BrowseNameSort:GetWidth());
151 end
152 end
153  
154 end
155  
156 function afp_SetWidth(obj, width)
157 if (width >= 184) then
158 width = width - BrowseBuyoutSort:GetWidth() + 2;
159 end
160 afp_OldSetWidth(obj, width);
161 end
162  
163 function SortBuyoutButton_UpdateArrow(button, type, sort)
164 if ( not IsAuctionSortReversed(type, sort) ) then
165 getglobal(button:GetName().."Arrow"):SetTexCoord(0, 0.5625, 1.0, 0);
166 else
167 getglobal(button:GetName().."Arrow"):SetTexCoord(0, 0.5625, 0, 1.0);
168 end
169 end
170  
171 function afp_FixParents()
172 afp_OptionText_HideUnaffordable:ClearAllPoints()
173 afp_OptionText_HideKnown:ClearAllPoints()
174 afp_OptionText_HideNoBuyout:ClearAllPoints()
175 afp_OptionText_PricePerUnit:ClearAllPoints()
176 afp_OptionText_StacksOf20:ClearAllPoints()
177 afp_OptionText_StacksOf10:ClearAllPoints()
178 afp_OptionText_StacksOf5:ClearAllPoints()
179 afp_OptionText_ExactName:ClearAllPoints()
180 afp_OptionText_ColorKnown:ClearAllPoints()
181 afp_OptionText_ShowBestDeals:ClearAllPoints()
182 afp_OptionText_GreyUnbid:ClearAllPoints()
183  
184 afp_OptionText_HideUnaffordable:SetPoint("LEFT","afp_OptionButton_HideUnaffordable","RIGHT",2,1);
185 afp_OptionText_HideKnown:SetPoint("LEFT","afp_OptionButton_HideKnown","RIGHT",2,1);
186 afp_OptionText_HideNoBuyout:SetPoint("LEFT","afp_OptionButton_HideNoBuyout","RIGHT",2,1);
187 afp_OptionText_PricePerUnit:SetPoint("LEFT","afp_OptionButton_PricePerUnit","RIGHT",2,1);
188 afp_OptionText_StacksOf20:SetPoint("LEFT","afp_OptionButton_StacksOf20","RIGHT",2,1);
189 afp_OptionText_StacksOf10:SetPoint("LEFT","afp_OptionButton_StacksOf10","RIGHT",2,1);
190 afp_OptionText_StacksOf5:SetPoint("LEFT","afp_OptionButton_StacksOf5","RIGHT",2,1);
191 afp_OptionText_ExactName:SetPoint("LEFT","afp_OptionButton_ExactName","RIGHT",2,1);
192 afp_OptionText_ColorKnown:SetPoint("LEFT","afp_OptionButton_ColorKnown","RIGHT",2,1);
193 afp_OptionText_ShowBestDeals:SetPoint("LEFT","afp_OptionButton_ShowBestDeals","RIGHT",2,1);
194 afp_OptionText_GreyUnbid:SetPoint("LEFT","afp_OptionButton_GreyUnbid","RIGHT",2,1);
195 end
196  
197 function afp_Tooltip(arg1,arg2,arg3,arg4,arg5,arg6)
198 if (not arg3) then arg3 = "ANCHOR_LEFT"; end
199 if (not arg4) then arg4 = 0; end
200 if (not arg5) then arg5 = -40; end
201 if (not arg6) then arg6 = afp_FlyoutFrame; end -- can use the reserved word "this" as arg6 if you want
202 GameTooltip:SetOwner(arg6, arg3, arg4, arg5);
203 GameTooltip:SetText(arg1);
204 GameTooltip:AddLine("\n"..arg2, .75, .75, .75, 1);
205 GameTooltip:Show();
206 end
207  
208 function afp_AuctionFrameBrowse_OnEnter()
209 local frame = this:GetName();
210 if (not frame) then return; end
211 if (frame == "afp_OptionButton_HideUnaffordable") then
212 afp_Tooltip(AFP_TOOLTIP_TITLE_UNAFFORD, AFP_TOOLTIP_TEXT_UNAFFORD);
213 elseif (frame == "afp_OptionButton_HideKnown") then
214 afp_Tooltip(AFP_TOOLTIP_TITLE_HIDEKNOWN, AFP_TOOLTIP_TEXT_HIDEKNOWN);
215 elseif (frame == "afp_OptionButton_HideNoBuyout") then
216 afp_Tooltip(AFP_TOOLTIP_TITLE_NOBUYOUT, AFP_TOOLTIP_TEXT_NOBUYOUT);
217 elseif (frame == "afp_OptionButton_PricePerUnit") then
218 afp_Tooltip(AFP_TOOLTIP_TITLE_PERUNIT, AFP_TOOLTIP_TEXT_PERUNIT);
219 elseif (frame == "afp_OptionButton_StacksOf20") then
220 afp_Tooltip(AFP_TOOLTIP_TITLE_STACK20, AFP_TOOLTIP_TEXT_STACK20);
221 elseif (frame == "afp_OptionButton_StacksOf10") then
222 afp_Tooltip(AFP_TOOLTIP_TITLE_STACK10, AFP_TOOLTIP_TEXT_STACK10);
223 elseif (frame == "afp_OptionButton_StacksOf5") then
224 afp_Tooltip(AFP_TOOLTIP_TITLE_STACK5, AFP_TOOLTIP_TEXT_STACK5);
225 elseif (frame == "afp_OptionButton_ExactName") then
226 afp_Tooltip(AFP_TOOLTIP_TITLE_EXACTNAME, AFP_TOOLTIP_TEXT_EXACTNAME);
227 elseif (frame == "afp_OptionButton_ColorKnown") then
228 afp_Tooltip(AFP_TOOLTIP_TITLE_COLORKNOWN, AFP_TOOLTIP_TEXT_COLORKNOWN);
229 elseif (frame == "afp_OptionButton_ShowBestDeals") then
230 afp_Tooltip(AFP_TOOLTIP_TITLE_SHOWBESTDEALS, AFP_TOOLTIP_TEXT_SHOWBESTDEALS);
231 elseif (frame == "afp_OptionButton_GreyUnbid") then
232 afp_Tooltip(AFP_TOOLTIP_TITLE_GREYUNBID, AFP_TOOLTIP_TEXT_GREYUNBID);
233 end
234 end
235  
236 function afp_Reset_OnClick()
237 PlaySound("igMainMenuOptionCheckBoxOn")
238 IsUsableCheckButton:SetChecked()
239 UIDropDownMenu_SetSelectedValue(BrowseDropDown, -1)
240 AuctionFrameBrowse.selectedClass = nil
241 AuctionFrameBrowse.selectedClassIndex = nil
242 AuctionFrameFilters_Update()
243 BrowseName:SetText("")
244 --BrowseName:SetFocus()
245 BrowseMinLevel:SetText("")
246 BrowseMaxLevel:SetText("")
247 AuctionDressUpModel:Dress()
248 if (false) then
249 ShowOnPlayerCheckButton:SetChecked()
250 SHOW_ON_CHAR = "0"
251 HideUIPanel(AuctionDressUpFrame)
252 end
253 afp_Print(AFP_OPTEXT_RESET);
254 end
255  
256 function afp_FlyoutClear_OnClick()
257 afp_OptionButton_PricePerUnit:SetChecked(0);
258 afp_OptionButton_HideNoBuyout:SetChecked(0);
259 afp_OptionButton_HideUnaffordable:SetChecked(0);
260 afp_OptionButton_HideKnown:SetChecked(0);
261 afp_OptionButton_StacksOf20:SetChecked(0);
262 afp_OptionButton_StacksOf10:SetChecked(0);
263 afp_OptionButton_StacksOf5:SetChecked(0);
264 afp_OptionButton_ExactName:SetChecked(0);
265 afp_OptionButton_ColorKnown:SetChecked(0);
266 afp_OptionButton_ShowBestDeals:SetChecked(0);
267 afp_OptionButton_GreyUnbid:SetChecked(0);
268 afp_Print(AFP_OPTEXT_CLEARED);
269 end
270  
271 function afp_FlyoutSave_OnClick()
272 afp_SavedSettings = {};
273 afp_SavedSettings["afp_OptionButton_PricePerUnit"] = afp_OptionButton_PricePerUnit:GetChecked();
274 afp_SavedSettings["afp_OptionButton_HideNoBuyout"] = afp_OptionButton_HideNoBuyout:GetChecked();
275 afp_SavedSettings["afp_OptionButton_HideUnaffordable"] = afp_OptionButton_HideUnaffordable:GetChecked();
276 afp_SavedSettings["afp_OptionButton_HideKnown"] = afp_OptionButton_HideKnown:GetChecked();
277 afp_SavedSettings["afp_OptionButton_StacksOf20"] = afp_OptionButton_StacksOf20:GetChecked();
278 afp_SavedSettings["afp_OptionButton_StacksOf10"] = afp_OptionButton_StacksOf10:GetChecked();
279 afp_SavedSettings["afp_OptionButton_StacksOf5"] = afp_OptionButton_StacksOf5:GetChecked();
280 afp_SavedSettings["afp_OptionButton_ExactName"] = afp_OptionButton_ExactName:GetChecked();
281 afp_SavedSettings["afp_OptionButton_ColorKnown"] = afp_OptionButton_ColorKnown:GetChecked();
282 afp_SavedSettings["afp_OptionButton_ShowBestDeals"] = afp_OptionButton_ShowBestDeals:GetChecked();
283 afp_SavedSettings["afp_OptionButton_GreyUnbid"] = afp_OptionButton_GreyUnbid:GetChecked();
284 afp_Print(AFP_OPTEXT_SAVED);
285 end
286  
287 function afp_FlyoutLoad_OnClick()
288 if (afp_SavedSettings) then
289 if (afp_SavedSettings["afp_OptionButton_PricePerUnit"]) then
290 afp_OptionButton_PricePerUnit:SetChecked(afp_SavedSettings["afp_OptionButton_PricePerUnit"]);
291 end
292 if (afp_SavedSettings["afp_OptionButton_HideNoBuyout"]) then
293 afp_OptionButton_HideNoBuyout:SetChecked(afp_SavedSettings["afp_OptionButton_HideNoBuyout"]);
294 end
295 if (afp_SavedSettings["afp_OptionButton_HideUnaffordable"]) then
296 afp_OptionButton_HideUnaffordable:SetChecked(afp_SavedSettings["afp_OptionButton_HideUnaffordable"]);
297 end
298 if (afp_SavedSettings["afp_OptionButton_HideKnown"]) then
299 afp_OptionButton_HideKnown:SetChecked(afp_SavedSettings["afp_OptionButton_HideKnown"]);
300 end
301 if (afp_SavedSettings["afp_OptionButton_StacksOf20"]) then
302 afp_OptionButton_StacksOf20:SetChecked(afp_SavedSettings["afp_OptionButton_StacksOf20"]);
303 end
304 if (afp_SavedSettings["afp_OptionButton_StacksOf10"]) then
305 afp_OptionButton_StacksOf10:SetChecked(afp_SavedSettings["afp_OptionButton_StacksOf10"]);
306 end
307 if (afp_SavedSettings["afp_OptionButton_StacksOf5"]) then
308 afp_OptionButton_StacksOf5:SetChecked(afp_SavedSettings["afp_OptionButton_StacksOf5"]);
309 end
310 if (afp_SavedSettings["afp_OptionButton_ExactName"]) then
311 afp_OptionButton_ExactName:SetChecked(afp_SavedSettings["afp_OptionButton_ExactName"]);
312 end
313 if (afp_SavedSettings["afp_OptionButton_ColorKnown"]) then
314 afp_OptionButton_ColorKnown:SetChecked(afp_SavedSettings["afp_OptionButton_ColorKnown"]);
315 end
316 if (afp_SavedSettings["afp_OptionButton_ShowBestDeals"]) then
317 afp_OptionButton_ShowBestDeals:SetChecked(afp_SavedSettings["afp_OptionButton_ShowBestDeals"]);
318 end
319 if (afp_SavedSettings["afp_OptionButton_GreyUnbid"]) then
320 afp_OptionButton_GreyUnbid:SetChecked(afp_SavedSettings["afp_OptionButton_GreyUnbid"]);
321 end
322 end
323 end
324  
325 function afp_AuctionFrameBrowse_Update()
326  
327 -- Trap for, and prevent, filters from doing anything while Auctioneer is scanning.
328 if ((Auctioneer_isScanningRequested and Auctioneer_isScanningRequested==true) or (Auctioneer and Auctioneer.Scanning and Auctioneer.Scanning.IsScanningRequested and Auctioneer.Scanning.IsScanningRequested==true)) then
329 return;
330 end
331 -- Trap for, and prevent, filters from doing anything while KCI is scanning.
332 if (KC_ItemsAuction and KC_ItemsAuction.scanning) then
333 return;
334 end
335  
336 local numBatchAuctions, totalAuctions = GetNumAuctionItems("list");
337 local button, buttonName, iconTexture, itemName, color, itemCount, moneyFrame, buyoutMoneyFrame, buyoutText, buttonHighlight;
338 local offset = FauxScrollFrame_GetOffset(BrowseScrollFrame);
339 local index;
340 local isLastSlotEmpty;
341 local name, texture, count, quality, canUse, minBid, minIncrement, buyoutPrice, duration, bidAmount, highBidder, owner;
342 BrowseBidButton:Disable();
343 BrowseBuyoutButton:Disable();
344 -- Update sort arrows
345 SortButton_UpdateArrow(BrowseQualitySort, "list", "quality");
346 SortButton_UpdateArrow(BrowseLevelSort, "list", "level");
347 SortButton_UpdateArrow(BrowseDurationSort, "list", "duration");
348 SortButton_UpdateArrow(BrowseHighBidderSort, "list", "status");
349 SortButton_UpdateArrow(BrowseCurrentBidSort, "list", "bid");
350  
351 -- Show the no results text if no items found
352 if ( numBatchAuctions == 0 ) then
353 BrowseNoResultsText:Show();
354 else
355 BrowseNoResultsText:Hide();
356 end
357  
358 local baseAve = 0; bestAve = 0; worstAve = 0;
359 local baseAveTable = {};
360 -- Get the highest non-outlier value (only when Exact Name is turned on)
361 if (afp_OptionButton_ShowBestDeals:GetChecked()) then
362 --if (afp_OptionButton_ExactName:GetChecked() and BrowseName and BrowseName:GetText() ~= "") then
363 for i=1, NUM_BROWSE_TO_DISPLAY do
364 --for n=1,NUM_AUCTION_ITEMS_PER_PAGE do
365 name,_,count,_,_,_,minBid,_,buyoutPrice,bidAmount,_,_ = GetAuctionItemInfo("list", i); -- name, texture, count, quality, canUse, level, minBid, minIncrement, buyoutPrice, bidAmount, highBidder, owner
366 if (name and BrowseName and string.lower(name) == string.lower(BrowseName:GetText())) or not afp_OptionButton_ExactName:GetChecked() then
367 -- Account for crafted Bolts of Cloth
368 if (name==AFP_ITEM_BOLT_LINEN) then
369 count = count * 2;
370 elseif (name==AFP_ITEM_BOLT_WOOL) then
371 count = count * 3;
372 elseif (name==AFP_ITEM_BOLT_SILK) then
373 count = count * 4;
374 elseif (name==AFP_ITEM_BOLT_MAGEWEAVE) then
375 count = count * 5;
376 elseif (name==AFP_ITEM_BOLT_RUNECLOTH) then
377 count = count * 5;
378 elseif (name==AFP_ITEM_ESSENCE_ETERNAL) then
379 count = count * 3;
380 elseif (name==AFP_ITEM_ESSENCE_NETHER) then
381 count = count * 3;
382 elseif (name==AFP_ITEM_ESSENCE_MYSTIC) then
383 count = count * 3;
384 elseif (name==AFP_ITEM_ESSENCE_ASTRAL) then
385 count = count * 3;
386 elseif (name==AFP_ITEM_ESSENCE_MAGIC) then
387 count = count * 3;
388 end
389 if ( buyoutPrice > 0 ) then
390 table.insert(baseAveTable, buyoutPrice/count);
391 elseif (not afp_OptionButton_HideNoBuyout:GetChecked()) then
392 -- Don't use bids if HideNoBuyout is on!
393 if ( bidAmount == 0 ) then
394 table.insert(baseAveTable, minBid/count);
395 else
396 table.insert(baseAveTable, bidAmount/count);
397 end
398 end
399 end
400 --end
401 end
402 --end
403 end
404 if (table.getn(baseAveTable) > 0) then
405 table.sort(baseAveTable);
406 baseAve = baseAveTable[math.floor(table.getn(baseAveTable)/2)];
407 bestAve = baseAveTable[1];
408 worstAve = baseAveTable[table.getn(baseAveTable)];
409 --afp_Print("baseAveTable rows="..table.getn(baseAveTable)..", baseAve="..baseAve..", bestAve="..bestAve..", worstAve="..worstAve);
410 end
411 if (not baseAve) then baseAve = 0; end
412  
413 for i=1, NUM_BROWSE_TO_DISPLAY do
414 if (afp_OptionButton_HideKnown:GetChecked() or afp_OptionButton_HideNoBuyout:GetChecked() or afp_OptionButton_HideUnaffordable:GetChecked() or afp_OptionButton_StacksOf20:GetChecked() or afp_OptionButton_StacksOf10:GetChecked() or afp_OptionButton_StacksOf5:GetChecked() or afp_OptionButton_ExactName:GetChecked() or afp_OptionButton_ColorKnown:GetChecked() or afp_OptionButton_GreyUnbid:GetChecked()) then
415 local skipItem;
416 for n=1,NUM_AUCTION_ITEMS_PER_PAGE do
417 AFHiddenTooltip:ClearLines();
418 name,_,count,quality,_,_,_,_,buyoutPrice,_,_,owner = GetAuctionItemInfo("list", offset + i); -- name, texture, count, quality, canUse, level, minBid, minIncrement, buyoutPrice, bidAmount, highBidder, owner
419 AFHiddenTooltip:SetAuctionItem("list", offset + i);
420 skipItem = 0;
421 if (afp_OptionButton_HideKnown:GetChecked()) then
422 if ((AFHiddenTooltipTextLeft3:GetText() == ITEM_SPELL_KNOWN) and (AFHiddenTooltip:NumLines() >= 3)) then
423 skipItem = 1;
424 elseif ((AFHiddenTooltipTextLeft4:GetText() == ITEM_SPELL_KNOWN) and (AFHiddenTooltip:NumLines() >= 4)) then
425 skipItem = 1;
426 end
427 end
428 if ((buyoutPrice == 0) and (afp_OptionButton_HideNoBuyout:GetChecked())) then
429 skipItem = 1;
430 end
431 if ((GetMoney() < buyoutPrice) and (afp_OptionButton_HideUnaffordable:GetChecked())) then
432 skipItem = 1;
433 end
434 if (count ~= 20 and afp_OptionButton_StacksOf20:GetChecked()) then
435 skipItem = 1;
436 end
437 if (count ~= 10 and afp_OptionButton_StacksOf10:GetChecked()) then
438 skipItem = 1;
439 end
440 if (count ~= 5 and afp_OptionButton_StacksOf5:GetChecked()) then
441 skipItem = 1;
442 end
443 if (BrowseName and name and BrowseName:GetText() and string.lower(name) ~= string.lower(BrowseName:GetText()) and afp_OptionButton_ExactName:GetChecked()) then
444 skipItem = 1;
445 end
446 if (skipItem == 1) then
447 offset = offset + 1;
448 else
449 afp_BrowseList[i] = offset;
450 end
451 end
452 else
453 for n=1,NUM_BROWSE_TO_DISPLAY do
454 afp_BrowseList[n] = offset;
455 end
456 end
457 index = offset + i + (NUM_AUCTION_ITEMS_PER_PAGE * AuctionFrameBrowse.page);
458 button = getglobal("BrowseButton"..i);
459 -- Show or hide auction buttons
460 if ( index > (numBatchAuctions + (NUM_AUCTION_ITEMS_PER_PAGE * AuctionFrameBrowse.page)) ) then
461 button:Hide();
462 --button:SetVertexColor(0,0,0);
463 -- If the last button is empty then set isLastSlotEmpty var
464 if ( i == NUM_BROWSE_TO_DISPLAY ) then
465 isLastSlotEmpty = 1;
466 end
467 else -- EMERALD: BlackOut (if skipItem==1 then BlackOut)
468 button:Show();
469 buttonName = "BrowseButton"..i;
470 name, texture, count, quality, canUse, level, minBid, minIncrement, buyoutPrice, bidAmount, highBidder, owner = GetAuctionItemInfo("list", offset + i);
471 duration = GetAuctionItemTimeLeft("list", offset + i);
472 -- Resize button if there isn't a scrollbar
473 buttonHighlight = getglobal("BrowseButton"..i.."Highlight");
474 if ( numBatchAuctions <= NUM_BROWSE_TO_DISPLAY ) then
475 button:SetWidth(625);
476 buttonHighlight:SetWidth(589);
477 BrowseCurrentBidSort:SetWidth(207);
478 elseif ( numBatchAuctions == NUM_BROWSE_TO_DISPLAY and totalAuctions <= NUM_BROWSE_TO_DISPLAY ) then
479 button:SetWidth(625);
480 buttonHighlight:SetWidth(589);
481 BrowseCurrentBidSort:SetWidth(207);
482 else
483 button:SetWidth(600);
484 buttonHighlight:SetWidth(562);
485 BrowseCurrentBidSort:SetWidth(184);
486 end
487 -- Set name and quality color
488 color = ITEM_QUALITY_COLORS[quality];
489 itemName = getglobal(buttonName.."Name");
490 local newName;
491 local thisPrice = 0;
492 local thisCount = 0;
493 newName = GetHex(color.r,color.g,color.b)..name..FONT_COLOR_CODE_CLOSE;
494 if (afp_OptionButton_ShowBestDeals:GetChecked()) then
495 if (baseAve ~= 0) then
496 -- Account for crafted Bolts of Cloth
497 if (name==AFP_ITEM_BOLT_LINEN) then
498 thisCount = count * 2;
499 elseif (name==AFP_ITEM_BOLT_WOOL) then
500 thisCount = count * 3;
501 elseif (name==AFP_ITEM_BOLT_SILK) then
502 thisCount = count * 4;
503 elseif (name==AFP_ITEM_BOLT_MAGEWEAVE) then
504 thisCount = count * 5;
505 elseif (name==AFP_ITEM_BOLT_RUNECLOTH) then
506 thisCount = count * 5;
507 else
508 thisCount = count;
509 end
510 if ( buyoutPrice > 0 ) then
511 thisPrice = afp_Round(buyoutPrice/thisCount);
512 else
513 if ( bidAmount == 0 ) then
514 thisPrice = afp_Round(minBid/thisCount);
515 else
516 thisPrice = afp_Round(bidAmount/thisCount);
517 end
518 end
519 newName = newName.." ";
520 --afp_Print("thisPrice="..thisPrice..", best="..(bestAve * 1.2)..", worst="..(worstAve / 1.2)..", base="..baseAve);
521 --afp_Print("thisPrice="..thisPrice..", base="..baseAve);
522 --if (thisPrice <= bestAve * 1.05) then -- Best Price
523 --if (thisPrice <= bestAve) then -- Best Price
524 if (thisPrice <= (baseAve / 2.2) or thisPrice <= bestAve) then -- Best Price
525 newName = newName..GetHex(0.6,1,0.6).."(Best)";
526 --elseif (thisPrice >= worstAve / 1.05) then -- Worst Price
527 --elseif (thisPrice >= worstAve) then -- Worst Price
528 elseif (thisPrice) >= (baseAve * 2.5) then -- Worst Price
529 newName = newName..GetHex(1,0,0).."(Worst)+"..math.floor((thisPrice/baseAve)*100).."%";
530 elseif (thisPrice) >= (baseAve * 1.8) then -- Bad Price
531 newName = newName..GetHex(1,0.3,0.3).."(Worse)+"..math.floor((thisPrice/baseAve)*100).."%";
532 elseif (thisPrice) >= (baseAve * 1.4) then -- Bad Price
533 newName = newName..GetHex(1,0.6,0.6).."(Bad)+"..math.floor((thisPrice/baseAve)*100).."%";
534 elseif (thisPrice <= (baseAve / 1.5)) then -- Great Price
535 newName = newName..GetHex(0.3,1,0.3).."(Great)";
536 elseif (thisPrice < baseAve) then -- Good Price
537 newName = newName..GetHex(0,1,0).."(Good)";
538 else -- Median Price
539 newName = newName..GetHex(1,1,0).."(Average)";
540 end
541 newName = newName..FONT_COLOR_CODE_CLOSE;
542 end
543 end
544 itemName:SetText(newName);
545 --itemName:SetVertexColor(color.r, color.g, color.b);
546 --if (skipItem==1) then itemName:SetVertexColor(0,0,0); end
547 -- Set level
548 if ( level > UnitLevel("player") ) then
549 getglobal(buttonName.."Level"):SetText(RED_FONT_COLOR_CODE..level..FONT_COLOR_CODE_CLOSE);
550 else
551 getglobal(buttonName.."Level"):SetText(level);
552 end
553 --if (skipItem==1) then getglobal(buttonName.."Level"):SetVertexColor(0,0,0); end
554 -- Set closing time
555 getglobal(buttonName.."ClosingTimeText"):SetText(AuctionFrame_GetTimeLeftText(duration));
556 getglobal(buttonName.."ClosingTime").tooltip = AuctionFrame_GetTimeLeftTooltipText(duration);
557 --if (skipItem==1) then getglobal(buttonName.."ClosingTimeText"):SetVertexColor(0,0,0); end
558 --if (skipItem==1) then getglobal(buttonName.."ClosingTime"):SetVertexColor(0,0,0); end
559 -- Set item texture, count, and usability
560 iconTexture = getglobal(buttonName.."ItemIconTexture");
561 iconTexture:SetTexture(texture);
562 if ( not canUse ) then
563 iconTexture:SetVertexColor(1.0, 0.1, 0.1);
564 else
565 iconTexture:SetVertexColor(1.0, 1.0, 1.0);
566 end
567 itemCount = getglobal(buttonName.."ItemCount");
568 if ( count > 1 ) then
569 itemCount:SetText(count);
570 itemCount:Show();
571 else
572 itemCount:Hide();
573 end
574 -- Color known recipe (courtesy LeisureLarry@Curse)
575 if (afp_OptionButton_ColorKnown:GetChecked() and (AFHiddenTooltip:NumLines() >= 3)) then
576 if (AFHiddenTooltipTextLeft3:GetText() == ITEM_SPELL_KNOWN) then
577 -- Set color of icon to blue to make it easy to see that you already know it.
578 iconTexture = getglobal("BrowseButton"..i.."ItemIconTexture");
579 iconTexture:SetVertexColor(0, 0, 0.8);
580 elseif ((AFHiddenTooltip:NumLines() >= 4) and (AFHiddenTooltipTextLeft4:GetText() == ITEM_SPELL_KNOWN)) then
581 -- Set color of icon to blue to make it easy to see that you already know it.
582 iconTexture = getglobal("BrowseButton"..i.."ItemIconTexture");
583 iconTexture:SetVertexColor(0, 0, 0.8);
584 end
585 end
586 --if (skipItem==1) then iconTexture:SetVertexColor(0,0,0); end
587 -- Set high bid
588 moneyFrame = getglobal(buttonName.."MoneyFrame");
589 yourBidText = getglobal(buttonName.."YourBidText");
590 buyoutMoneyFrame = getglobal(buttonName.."BuyoutMoneyFrame");
591 buyoutText = getglobal(buttonName.."BuyoutText");
592 -- If not bidAmount set the bid amount to the min bid
593 if ( bidAmount == 0 ) then
594 if (afp_OptionButton_PricePerUnit:GetChecked()) then
595 MoneyFrame_Update(moneyFrame:GetName(), afp_Round(minBid/count));
596 else
597 MoneyFrame_Update(moneyFrame:GetName(), minBid);
598 end
599 else
600 if (afp_OptionButton_PricePerUnit:GetChecked()) then
601 MoneyFrame_Update(moneyFrame:GetName(), afp_Round(bidAmount/count));
602 else
603 MoneyFrame_Update(moneyFrame:GetName(), bidAmount);
604 end
605 if (afp_OptionButton_GreyUnbid:GetChecked()) then -- myShowBid functionality
606 moneyFrame:SetAlpha(0.5);
607 else
608 moneyFrame:SetAlpha(1.0);
609 end
610 end
611 --if (skipItem==1) then moneyFrame:Hide(); end
612 if ( highBidder ) then
613 yourBidText:Show();
614 else
615 yourBidText:Hide();
616 end
617 --if (skipItem==1) then yourBidText:Hide(); end
618 if ( buyoutPrice > 0 ) then
619 moneyFrame:SetPoint("RIGHT", buttonName, "RIGHT", 10, 10);
620 if (afp_OptionButton_PricePerUnit:GetChecked()) then
621 MoneyFrame_Update(buyoutMoneyFrame:GetName(), afp_Round(buyoutPrice/count));
622 else
623 MoneyFrame_Update(buyoutMoneyFrame:GetName(), buyoutPrice);
624 end
625 buyoutMoneyFrame:Show();
626 buyoutText:Show();
627 else
628 moneyFrame:SetPoint("RIGHT", buttonName, "RIGHT", 10, 3);
629 buyoutMoneyFrame:Hide();
630 buyoutText:Hide();
631 end
632 --if (skipItem==1) then buyoutMoneyFrame:Hide(); buyoutText:Hide(); end
633 -- Set high bidder
634 --if ( not highBidder ) then
635 -- highBidder = RED_FONT_COLOR_CODE..NO_BIDS..FONT_COLOR_CODE_CLOSE;
636 --end
637 getglobal(buttonName.."HighBidder"):SetText(owner);
638 --if (skipItem==1) then getglobal(buttonName.."HighBidder"):SetVertexColor(0,0,0); end
639 -- Set highlight
640 if ( GetSelectedAuctionItem("list") and (offset + i) == GetSelectedAuctionItem("list") ) then
641 button:LockHighlight();
642  
643 if ( buyoutPrice > 0 and buyoutPrice >= minBid and GetMoney() >= buyoutPrice ) then
644 BrowseBuyoutButton:Enable();
645 AuctionFrame.buyoutPrice = buyoutPrice;
646 else
647 AuctionFrame.buyoutPrice = nil;
648 end
649 -- Set bid
650 if ( bidAmount > 0 ) then
651 bidAmount = bidAmount + minIncrement ;
652 MoneyInputFrame_SetCopper(BrowseBidPrice, bidAmount);
653 else
654 MoneyInputFrame_SetCopper(BrowseBidPrice, minBid);
655 end
656  
657 if ( not highBidder and GetMoney() >= MoneyInputFrame_GetCopper(BrowseBidPrice) ) then
658 BrowseBidButton:Enable();
659 end
660 else
661 button:UnlockHighlight();
662 end
663  
664 end
665 end
666  
667 -- Update scrollFrame
668 -- If more than one page of auctions show the next and prev arrows when the scrollframe is scrolled all the way down
669 if ( totalAuctions > NUM_AUCTION_ITEMS_PER_PAGE ) then
670 if ( isLastSlotEmpty ) then
671 BrowsePrevPageButton:Show();
672 BrowseNextPageButton:Show();
673 BrowseSearchCountText:Show();
674 local itemsMin = AuctionFrameBrowse.page * NUM_AUCTION_ITEMS_PER_PAGE + 1;
675 local itemsMax = itemsMin + numBatchAuctions - 1;
676 BrowseSearchCountText:SetText(format(NUMBER_OF_RESULTS_TEMPLATE, itemsMin, itemsMax, totalAuctions ));
677 if ( AuctionFrameBrowse.page == 0 ) then
678 BrowsePrevPageButton.isEnabled = nil;
679 else
680 BrowsePrevPageButton.isEnabled = 1;
681 end
682 if ( AuctionFrameBrowse.page == (ceil(totalAuctions/NUM_AUCTION_ITEMS_PER_PAGE) - 1) ) then
683 BrowseNextPageButton.isEnabled = nil;
684 else
685 BrowseNextPageButton.isEnabled = 1;
686 end
687 else
688 BrowsePrevPageButton:Hide();
689 BrowseNextPageButton:Hide();
690 BrowseSearchCountText:Hide();
691 end
692  
693 -- Artifically inflate the number of results so the scrollbar scrolls one extra row
694 numBatchAuctions = numBatchAuctions + 1;
695 else
696 BrowsePrevPageButton:Hide();
697 BrowseNextPageButton:Hide();
698 BrowseSearchCountText:Hide();
699 end
700 FauxScrollFrame_Update(BrowseScrollFrame, numBatchAuctions, NUM_BROWSE_TO_DISPLAY, AUCTIONS_BUTTON_HEIGHT);
701 end
702  
703 function afp_BrowseButton_OnClick(button)
704 if ( not button ) then
705 button = this;
706 end
707 --afp_Print("OnClick");
708 --if ( IsControlKeyDown() ) then -- Dressing Room (THIS DOESN'T WORK, and I don't know why)
709 --DressUpItemLink(GetAuctionItemLink("list", button:GetID() + afp_BrowseList[button:GetID()]));
710 --afp_Print("DressUpItemLink");
711 --elseif ( IsShiftKeyDown() ) then -- Text link
712 --if ( ChatFrameEditBox:IsVisible() ) then
713 --ChatFrameEditBox:Insert(GetAuctionItemLink("list", button:GetID() + afp_BrowseList[button:GetID()]));
714 --afp_Print("ChatFrameEditBox");
715 --end
716 --else
717 SetSelectedAuctionItem("list", button:GetID() + afp_BrowseList[button:GetID()]);
718 afp_AuctionFrameBrowse_Update();
719 --afp_Print("Else");
720 --end
721 end
722  
723 function afp_AuctionFrameItem_OnEnter(type, index)
724 if (this:GetParent():GetID()) then -- EMERALD: Test
725 index = this:GetParent():GetID();
726 end
727 if (afp_BrowseList and afp_BrowseList[this:GetParent():GetID()]) then
728 index = index + afp_BrowseList[this:GetParent():GetID()];
729 end
730 afp_OriginalAuctionFrameItem_OnEnter(type, index)
731 end
732  
733 function afp_FlyoutButton_OnClick()
734 if (afp_FlyoutButton and afp_FlyoutButton:IsVisible()) then
735 if (afp_FlyoutFrame and afp_FlyoutFrame:IsVisible()) then
736 afp_FlyoutFrame:Hide();
737 afp_FlyoutClear:Hide();
738 afp_FlyoutSave:Hide();
739 --afp_Print("afDEBUG: Hiding Flyout");
740 elseif (afp_FlyoutFrame) then
741 --CHANGE SIZE BASED ON NUMBER OF VISIBLE LINES (height=lines*19)
742 afp_FlyoutFrame:SetHeight(13*19); -- Currently: 13 Lines
743 afp_FlyoutFrame:SetParent(AuctionFrameBrowse);
744 --afp_FlyoutFrame:SetPoint("TOPLEFT","AuctionFrameBrowse","TOPRIGHT",70,40);
745 afp_FlyoutFrame:SetPoint("TOPLEFT","AuctionFrame","TOPRIGHT",4,-9);
746 afp_FlyoutFrame:Show();
747 afp_FlyoutClear:SetParent(afp_FlyoutFrame);
748 afp_FlyoutClear:SetPoint("TOPLEFT","afp_FlyoutFrame","BOTTOMLEFT",1,0);
749 afp_FlyoutClear:Show();
750 afp_FlyoutSave:SetParent(afp_FlyoutFrame);
751 afp_FlyoutSave:SetPoint("TOPRIGHT","afp_FlyoutFrame","BOTTOMRIGHT",-1,0);
752 afp_FlyoutSave:Show();
753 afp_FlyoutLoad:SetParent(afp_FlyoutFrame);
754 afp_FlyoutLoad:SetPoint("TOPRIGHT","afp_FlyoutSave","BOTTOMRIGHT",0,0);
755 afp_FlyoutLoad:Show();
756 --afp_Print("afDEBUG: Showing Flyout");
757 else
758 --afp_Print("afDEBUG: ERROR: NO STATE!");
759 end
760 end
761 end
762  
763 --[[ COMMON FUNCTIONS ]]
764  
765 function afp_SlashHandler(msg)
766 if (msg=="show" or msg=="hide") then msg = ""; end
767 if (not msg or msg=="") then
768 --Base command
769 if (afp_FlyoutButton and afp_FlyoutButton:IsVisible()) then
770 afp_FlyoutButton_OnClick();
771 else
772 afp_Print("The Flyout cannot be shown if the Auction window is not on the Browse tab.");
773 end
774 end
775 end
776  
777 function afp_Print(message) -- Send Message to Chat Frame
778 DEFAULT_CHAT_FRAME:AddMessage("[AuctionFilterPlus] "..message, 1.0, 1.0, 1.0);
779 end
780  
781 function afp_PrintError(message) -- Send Error to Chat Frame
782 DEFAULT_CHAT_FRAME:AddMessage("[AuctionFilterPlus] ERROR: "..message, 1.0, 0, 0);
783 end
784  
785 function afp_Round(x)
786 if (x - math.floor(x) > 0.5) then
787 x = x + 0.5;
788 end
789 return math.floor(x);
790 end
791  
792 --courtesy watchdog:
793 function GetHex(r,g,b)
794  
795 if g then
796 return string.format("|cFF%02X%02X%02X", (255*r), (255*g), (255*b));
797 elseif r then
798 return string.format("|cFF%02X%02X%02X", (255*r.r), (255*r.g), (255*r.b));
799 else
800 return "";
801 end
802  
803 end