vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --PriceEach version 0.02
2 --Released 10/33/05
3 --
4 --originally based off of code in ShowBid (which, unless updated for 1.8, probably doesn't work anymore)
5 --also, BIG thanks to the author of AuctionSort, for showing me how to make this work under 1.8 before the patch hit :)
6 --credit to other authors in the several functions
7 --
8 --todo: load on demand
9 --
10 --Hangar of Silvermoon
11  
12 PRICEEACH_VERSION="0.02";
13  
14 local orig_AuctionFrameBrowse_Update;
15  
16 function PriceEach_OnLoad()
17  
18 local name,title,notes,enabled,loadable,reason,security
19  
20 name,title,notes,enabled,loadable,reason,security = GetAddOnInfo("PriceEach");
21  
22 this:RegisterEvent("AUCTION_ITEM_LIST_UPDATE");
23 this:RegisterEvent("VARIABLES_LOADED");
24  
25 orig_AuctionFrameBrowse_Update = AuctionFrameBrowse_Update;
26  
27 AuctionFrameBrowse_Update = PriceEach_AuctionFrameBrowse_Update;
28  
29 DEFAULT_CHAT_FRAME:AddMessage(GREEN_FONT_COLOR_CODE..title.." "..PRICEEACH_VERSION.." loaded"..FONT_COLOR_CODE_CLOSE);
30  
31 SLASH_PRICEEACHSLASH1 = "/pe";
32 SlashCmdList["PRICEEACHSLASH"] = PriceEach_Enable_ChatCommandHandler;
33  
34 end
35  
36 function PriceEach_Enable_ChatCommandHandler(text)
37  
38 local msg = TextParse(text); --take a string and return a table with each word from the string in each entry
39  
40 msg[1] = strlower(msg[1]);
41  
42 if msg[1] == "warn" and msg[2] and tonumber(msg[2]) then
43  
44 DickThreshold = tonumber(msg[2]);
45 DEFAULT_CHAT_FRAME:AddMessage(LIGHTYELLOW_FONT_COLOR_CODE.."PriceEach warning threshold is now set to: "..FONT_COLOR_CODE_CLOSE..HIGHLIGHT_FONT_COLOR_CODE..msg[2]..FONT_COLOR_CODE_CLOSE);
46  
47 elseif msg[1] == "warn" then
48  
49  
50 SetDick(); --in case they /pe warn before they've loaded the AH
51  
52 DEFAULT_CHAT_FRAME:AddMessage(LIGHTYELLOW_FONT_COLOR_CODE.."PriceEach warning threshold is currently set to: "..FONT_COLOR_CODE_CLOSE..HIGHLIGHT_FONT_COLOR_CODE..DickThreshold..FONT_COLOR_CODE_CLOSE);
53  
54 else
55  
56 DEFAULT_CHAT_FRAME:AddMessage(LIGHTYELLOW_FONT_COLOR_CODE.."PriceEach: Invalid option. Please use: /pe warn [#], where # is the amount of gold you want to be warned if price each is greater than. Omit the # for current threshold."..FONT_COLOR_CODE_CLOSE);
57  
58 end
59  
60 end
61  
62 function PriceEach_OnEvent(event, arg1, arg2, arg3)
63  
64 if (event == "VARIABLES_LOADED") then
65  
66 SetDick(); --make sure a good value coming from variables
67  
68 end
69  
70 end
71  
72 function SetDick()
73 --i'm sorry, but anyone who's selling a citrine for 90g IS a dick :p
74  
75 if (DickThreshold == nil) then
76  
77 DickThreshold = 5;
78 DEFAULT_CHAT_FRAME:AddMessage(LIGHTYELLOW_FONT_COLOR_CODE.."PriceEach warning threshold set to the default: "..FONT_COLOR_CODE_CLOSE..HIGHLIGHT_FONT_COLOR_CODE..DickThreshold..FONT_COLOR_CODE_CLOSE);
79  
80 end
81  
82 end
83  
84 function PriceEach_AuctionFrameBrowse_Update()
85  
86 SetDick(); --set in case they haven't /pe warned yet or opened ah
87  
88 local offset = FauxScrollFrame_GetOffset(BrowseScrollFrame);
89 local index;
90 local button, buttonName;
91  
92 orig_AuctionFrameBrowse_Update();
93  
94 for i=1, NUM_BROWSE_TO_DISPLAY do
95  
96 index = offset + i + (NUM_AUCTION_ITEMS_PER_PAGE * AuctionFrameBrowse.page);
97  
98 button = getglobal("BrowseButton"..i);
99  
100 buttonName = "BrowseButton"..i;
101  
102 local name, texture, count, quality, canUse, level, minBid, minIncrement, buyoutPrice, bidAmount, highBidder, owner = GetAuctionItemInfo("list", offset + i);
103  
104 if (name ~= nil) then
105  
106 local aiLink = GetAuctionItemLink("list", offset + i); --get clicky-link
107 local aiItemID, aiRandomProp, aiEnchant, aiUniqID = breakLink(aiLink); --extract itemID from clicky-link
108  
109 local sName, sLink, iQuality, iLevel, sType, sSubType, iCount, iEquipLoc = GetItemInfo(aiItemID); --
110  
111 if (buyoutPrice > 0 ) and (iCount > 1) then --~= nil) then
112  
113 itemName = getglobal(buttonName.."Name");
114  
115 local oldtext = itemName:GetText();
116  
117 local pereach = floor(buyoutPrice / count);
118 local g,s,c = ConvertMoney(pereach);
119 local gt,st,ct;
120 local peText;
121  
122 peText = " ("
123  
124 if (g > 0) then
125  
126 if (g >= DickThreshold) then --5
127  
128 peText = peText..RED_FONT_COLOR_CODE..g.."g"..FONT_COLOR_CODE_CLOSE;
129  
130 else
131  
132 peText = peText..NORMAL_FONT_COLOR_CODE..g.."g"..FONT_COLOR_CODE_CLOSE;
133  
134 end
135  
136 end
137  
138 if (s > 0) then
139  
140 if (g > 0) then
141  
142 peText = peText.." ";
143  
144 end
145  
146 if (g >= DickThreshold) then --5
147  
148 peText = peText..GetHex(0.8,0.8,0.8)..s.."s"..FONT_COLOR_CODE_CLOSE;
149  
150 else
151  
152 peText = peText..GetHex(0.8,0.8,0.8)..s.."s"..FONT_COLOR_CODE_CLOSE;
153  
154 end
155  
156 end
157  
158 if (c > 0) then
159  
160 if (g > 0) or (s > 0) then
161  
162 peText = peText.." ";
163  
164 end
165  
166 if (g >= DickThreshold) then --5
167  
168 peText = peText..GetHex(0.8,0.5,0.4)..c.."c"..FONT_COLOR_CODE_CLOSE;
169  
170 else
171  
172 peText = peText..GetHex(0.8,0.5,0.4)..c.."c"..FONT_COLOR_CODE_CLOSE;
173  
174 end
175  
176 end
177  
178 peText = peText..")"
179  
180 itemName:SetText(oldtext..peText);
181  
182 end --if (buyoutPrice > 0 ) and (iCount ~= nil) then
183  
184 end --if (name ~= nil) then
185  
186 end --for
187  
188 end --function
189  
190 --courtesy EnhTooltip:
191 function ConvertMoney(copper)
192  
193 if (copper == nil) then copper = 0; end
194  
195 local g = math.floor(copper / 10000);
196 local s = math.floor((copper - (g*10000)) / 100);
197 local c = math.floor(copper - (g*10000) - (s*100));
198  
199 return g,s,c;
200  
201 end
202  
203 --courtesy EnhTooltip:
204 function breakLink(link)
205  
206 if (type(link) ~= 'string') then return end
207  
208 local i,j, itemID, enchant, randomProp, uniqID, name = string.find(link, "|Hitem:(%d+):(%d+):(%d+):(%d+)|h[[]([^]]+)[]]|h")
209  
210 return tonumber(itemID or 0), tonumber(randomProp or 0), tonumber(enchant or 0), tonumber(uniqID or 0), name
211  
212 end
213  
214 --courtesy watchdog:
215 function GetHex(r,g,b)
216  
217 local TehHaxx0r;
218  
219 if g then
220  
221 return string.format("|cFF%02X%02X%02X", (255*r), (255*g), (255*b))
222  
223 elseif r then
224  
225 return string.format("|cFF%02X%02X%02X", (255*r.r), (255*r.g), (255*r.b))
226  
227 else
228  
229 return ""
230  
231 end
232  
233 end
234  
235 --Text Parsing. Yay!
236 function TextParse(InputString)
237 --[[ By FERNANDO!
238 This function should take a string and return a table with each word from the string in
239 each entry. IE, "Linoleum is teh awesome" returns {"Linoleum", "is", "teh", "awesome"}
240 Some good should come of this, I've been avoiding writing a text parser for a while, and
241 I need one I understand completely. ^_^
242  
243 If you want to gank this function and use it for whatever, feel free. Just give me props
244 somewhere. This function, as far as I can tell, is fairly foolproof. It's hard to get it
245 to screw up. It's also completely self-contained. Just cut and paste.]]
246 local Text = InputString;
247 local TextLength = 1;
248 local OutputTable = {};
249 local OTIndex = 1;
250 local StartAt = 1;
251 local StopAt = 1;
252 local TextStart = 1;
253 local TextStop = 1;
254 local TextRemaining = 1;
255 local NextSpace = 1;
256 local Chunk = "";
257 local Iterations = 1;
258 local EarlyError = false;
259  
260 if ((Text ~= nil) and (Text ~= "")) then
261 -- ... Yeah. I'm not even going to begin without checking to make sure Im not getting
262 -- invalid data. The big ol crashes I got with my color functions taught me that. ^_^
263  
264 -- First, it's time to strip out any extra spaces, ie any more than ONE space at a time.
265 while (string.find(Text, " ") ~= nil) do
266 Text = string.gsub(Text, " ", " ");
267 end
268  
269 -- Now, what if text consisted of only spaces, for some ungodly reason? Well...
270 if (string.len(Text) <= 1) then
271 EarlyError = true;
272 end
273  
274 -- Now, if there is a leading or trailing space, we nix them.
275 if EarlyError ~= true then
276 TextStart = 1;
277 TextStop = string.len(Text);
278  
279 if (string.sub(Text, TextStart, TextStart) == " ") then
280 TextStart = TextStart+1;
281 end
282  
283 if (string.sub(Text, TextStop, TextStop) == " ") then
284 TextStop = TextStop-1;
285 end
286  
287 Text = string.sub(Text, TextStart, TextStop);
288 end
289  
290 -- Finally, on to breaking up the goddamn string.
291  
292 OTIndex = 1;
293 TextRemaining = string.len(Text);
294  
295 while (StartAt <= TextRemaining) and (EarlyError ~= true) do
296  
297 -- NextSpace is the index of the next space in the string...
298 NextSpace = string.find(Text, " ",StartAt);
299 -- if there isn't another space, then StopAt is the length of the rest of the
300 -- string, otherwise it's just before the next space...
301 if (NextSpace ~= nil) then
302 StopAt = (NextSpace - 1);
303 else
304 StopAt = string.len(Text);
305 LetsEnd = true;
306 end
307  
308 Chunk = string.sub(Text, StartAt, StopAt);
309 OutputTable[OTIndex] = Chunk;
310 OTIndex = OTIndex + 1;
311  
312 StartAt = StopAt + 2;
313  
314 end
315 else
316 OutputTable[1] = "Error: Bad value passed to TextParse!";
317 end
318  
319 if (EarlyError ~= true) then
320 return OutputTable;
321 else
322 return {"Error: Bad value passed to TextParse!"};
323 end
324  
325 end