vanilla-wow-addons – Blame information for rev 1
?pathlinks?
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: AucUtil.lua 980 2006-08-31 05:29:48Z mentalpower $ |
||
5 | |||
6 | Auctioneer utility functions. |
||
7 | Functions to maniuplate items keys, signatures etc |
||
8 | |||
9 | License: |
||
10 | This program is free software; you can redistribute it and/or |
||
11 | modify it under the terms of the GNU General Public License |
||
12 | as published by the Free Software Foundation; either version 2 |
||
13 | of the License, or (at your option) any later version. |
||
14 | |||
15 | This program is distributed in the hope that it will be useful, |
||
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
18 | GNU General Public License for more details. |
||
19 | |||
20 | You should have received a copy of the GNU General Public License |
||
21 | along with this program(see GPL.txt); if not, write to the Free Software |
||
22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||
23 | ]] |
||
24 | |||
25 | --Local function prototypes |
||
26 | local getTimeLeftString, getSecondsLeftString, unpackSeconds, getGSC, getTextGSC, nilSafeString, colorTextWhite, getWarnColor, nullSafe, sanifyAHSnapshot, getAuctionKey, getOppositeKey, getNeutralKey, getHomeKey, isValidAlso, breakItemKey, split, findClass, getCatName, getCatNumberByName, getCatForKey, getKeyFromSig, getCatForSig, getItemLinks, getItems, getItemHyperlinks, loadCategories, loadCategoryClasses, loadCategorySubClasses, chatPrint, setFilterDefaults, protectAuctionFrame, priceForOne, round, delocalizeFilterVal, localizeFilterVal, getLocalizedFilterVal, delocalizeCommand, localizeCommand, findEmptySlot, containerFrameItemButtonOnClick |
||
27 | |||
28 | -- return the string representation of the given timeLeft constant |
||
29 | function getTimeLeftString(timeLeft) |
||
30 | local timeLeftString = ""; |
||
31 | |||
32 | if timeLeft == Auctioneer.Core.Constants.TimeLeft.Short then |
||
33 | timeLeftString = _AUCT('TimeShort'); |
||
34 | |||
35 | elseif timeLeft == Auctioneer.Core.Constants.TimeLeft.Medium then |
||
36 | timeLeftString = _AUCT('TimeMed'); |
||
37 | |||
38 | elseif timeLeft == Auctioneer.Core.Constants.TimeLeft.Long then |
||
39 | timeLeftString = _AUCT('TimeLong'); |
||
40 | |||
41 | elseif timeLeft == Auctioneer.Core.Constants.TimeLeft.VeryLong then |
||
42 | timeLeftString = _AUCT('TimeVlong'); |
||
43 | end |
||
44 | |||
45 | return timeLeftString; |
||
46 | end |
||
47 | |||
48 | function getSecondsLeftString(secondsLeft) |
||
49 | local timeLeft = nil; |
||
50 | |||
51 | for i = table.getn(Auctioneer.Core.Constants.TimeLeft.Seconds), 1, -1 do |
||
52 | |||
53 | if (secondsLeft >= Auctioneer.Core.Constants.TimeLeft.Seconds[i]) then |
||
54 | timeLeft = i; |
||
55 | break |
||
56 | end |
||
57 | end |
||
58 | |||
59 | return getTimeLeftString(timeLeft); |
||
60 | end |
||
61 | |||
62 | function unpackSeconds(seconds) |
||
63 | seconds = tonumber(seconds) |
||
64 | if (not seconds) then |
||
65 | return |
||
66 | end |
||
67 | |||
68 | local weeks |
||
69 | local days |
||
70 | local hours |
||
71 | local minutes |
||
72 | |||
73 | seconds = math.floor(seconds) |
||
74 | |||
75 | if (seconds > 604800) then |
||
76 | weeks = math.floor(seconds / 604800) |
||
77 | seconds = math.floor(seconds - (weeks * 604800)) |
||
78 | end |
||
79 | if (seconds > 86400) then |
||
80 | days = math.floor(seconds / 86400) |
||
81 | seconds = math.floor(seconds - (days * 86400)) |
||
82 | end |
||
83 | if (seconds > 3600) then |
||
84 | hours = math.floor(seconds / 3600) |
||
85 | seconds = math.floor(seconds - (hours * 3600)) |
||
86 | end |
||
87 | if (seconds >= 60) then |
||
88 | minutes = math.floor(seconds / 60) |
||
89 | seconds = math.floor(seconds - (minutes * 60)) |
||
90 | end |
||
91 | |||
92 | return (weeks or 0), (days or 0), (hours or 0), (minutes or 0), (seconds or 0) |
||
93 | end |
||
94 | |||
95 | function getGSC(money) |
||
96 | local g,s,c = EnhTooltip.GetGSC(money); |
||
97 | return g,s,c; |
||
98 | end |
||
99 | |||
100 | function getTextGSC(money) |
||
101 | return EnhTooltip.GetGSC(money); |
||
102 | end |
||
103 | |||
104 | -- return an empty string if str is nil |
||
105 | function nilSafeString(str) |
||
106 | return str or ""; |
||
107 | end |
||
108 | |||
109 | function colorTextWhite(text) |
||
110 | if (not text) then text = ""; end |
||
111 | |||
112 | local COLORING_START = "|cff%s%s|r"; |
||
113 | local WHITE_COLOR = "e6e6e6"; |
||
114 | |||
115 | return string.format(COLORING_START, WHITE_COLOR, ""..text); |
||
116 | end |
||
117 | |||
118 | function getWarnColor(warn) |
||
119 | --Make "warn" a required parameter and verify that its a string |
||
120 | if (not (type(warn) == "string")) then |
||
121 | return nil |
||
122 | end |
||
123 | |||
124 | local cHex, cRed, cGreen, cBlue; |
||
125 | |||
126 | if (Auctioneer.Command.GetFilter('warn-color')) then |
||
127 | local FrmtWarnAbovemkt, FrmtWarnUndercut, FrmtWarnNocomp, FrmtWarnAbovemkt, FrmtWarnMarkup, FrmtWarnUser, FrmtWarnNodata, FrmtWarnMyprice |
||
128 | |||
129 | FrmtWarnToolow = _AUCT('FrmtWarnToolow'); |
||
130 | FrmtWarnNocomp = _AUCT('FrmtWarnNocomp'); |
||
131 | FrmtWarnAbovemkt = _AUCT('FrmtWarnAbovemkt'); |
||
132 | FrmtWarnUser = _AUCT('FrmtWarnUser'); |
||
133 | FrmtWarnNodata = _AUCT('FrmtWarnNodata'); |
||
134 | FrmtWarnMyprice = _AUCT('FrmtWarnMyprice'); |
||
135 | |||
136 | FrmtWarnUndercut = string.format(_AUCT('FrmtWarnUndercut'), tonumber(Auctioneer.Command.GetFilterVal('pct-underlow'))); |
||
137 | FrmtWarnMarkup = string.format(_AUCT('FrmtWarnMarkup'), tonumber(Auctioneer.Command.GetFilterVal('pct-markup'))); |
||
138 | |||
139 | if (warn == FrmtWarnToolow) then |
||
140 | --Color Red |
||
141 | cHex = "ffff0000"; |
||
142 | cRed = 1.0; |
||
143 | cGreen = 0.0; |
||
144 | cBlue = 0.0; |
||
145 | |||
146 | elseif (warn == FrmtWarnUndercut) then |
||
147 | --Color Yellow |
||
148 | cHex = "ffffff00"; |
||
149 | cRed = 1.0; |
||
150 | cGreen = 1.0; |
||
151 | cBlue = 0.0; |
||
152 | |||
153 | elseif ((warn == FrmtWarnNocomp) or (warn == FrmtWarnAbovemkt)) then |
||
154 | --Color Green |
||
155 | cHex = "ff00ff00"; |
||
156 | cRed = 0.0; |
||
157 | cGreen = 1.0; |
||
158 | cBlue = 0.0; |
||
159 | |||
160 | elseif ((warn == FrmtWarnMarkup) or (warn == FrmtWarnUser) or (warn == FrmtWarnNodata) or (warn == FrmtWarnMyprice)) then |
||
161 | --Color Gray |
||
162 | cHex = "ff999999"; |
||
163 | cRed = 0.6; |
||
164 | cGreen = 0.6; |
||
165 | cBlue = 0.6; |
||
166 | end |
||
167 | |||
168 | else |
||
169 | --Color Orange |
||
170 | cHex = "ffe66600"; |
||
171 | cRed = 0.9; |
||
172 | cGreen = 0.4; |
||
173 | cBlue = 0.0; |
||
174 | end |
||
175 | |||
176 | return cHex, cRed, cGreen, cBlue |
||
177 | end |
||
178 | |||
179 | -- Used to convert variables that should be numbers but are nil to 0 |
||
180 | function nullSafe(val) |
||
181 | return tonumber(val) or 0; |
||
182 | end |
||
183 | |||
184 | -- Returns the current faction's auction signature, depending on location |
||
185 | function getAuctionKey() |
||
186 | local serverName = GetCVar("realmName"); |
||
187 | local currentZone = GetMinimapZoneText(); |
||
188 | local factionGroup; |
||
189 | |||
190 | --Added the ability to record Neutral AH auctions in its own tables. |
||
191 | if ((currentZone == "Gadgetzan") or (currentZone == "Everlook") or (currentZone == "Booty Bay")) then |
||
192 | factionGroup = "Neutral" |
||
193 | |||
194 | else |
||
195 | factionGroup = UnitFactionGroup("player"); |
||
196 | end |
||
197 | return serverName.."-"..factionGroup; |
||
198 | end |
||
199 | |||
200 | -- Returns the current faction's opposing faction's auction signature |
||
201 | function getOppositeKey() |
||
202 | local serverName = GetCVar("realmName"); |
||
203 | local factionGroup = UnitFactionGroup("player"); |
||
204 | |||
205 | if (factionGroup == "Alliance") then factionGroup="Horde"; else factionGroup="Alliance"; end |
||
206 | return serverName.."-"..factionGroup; |
||
207 | end |
||
208 | |||
209 | -- Returns the current server's neutral auction signature |
||
210 | function getNeutralKey() |
||
211 | local serverName = GetCVar("realmName"); |
||
212 | |||
213 | return serverName.."-Neutral"; |
||
214 | end |
||
215 | |||
216 | -- Returns the current faction's auction signature |
||
217 | function getHomeKey() |
||
218 | local serverName = GetCVar("realmName"); |
||
219 | local factionGroup = UnitFactionGroup("player"); |
||
220 | |||
221 | return serverName.."-"..factionGroup; |
||
222 | end |
||
223 | |||
224 | -- function returns true, if the given parameter is a valid option for the also command, false otherwise |
||
225 | function isValidAlso(also) |
||
226 | if (type(also) ~= "string") then |
||
227 | return false |
||
228 | end |
||
229 | |||
230 | if ((also == 'opposite') or (also == 'off') or (also == 'neutral') or (also == 'home')) then |
||
231 | return true -- allow special keywords |
||
232 | end |
||
233 | |||
234 | -- check if string matches: "[realm]-[faction]" |
||
235 | local s, e, r, f = string.find(also, "^(.+)-(.+)$") |
||
236 | if (s == nil) then |
||
237 | return false -- invalid string |
||
238 | end |
||
239 | |||
240 | -- check if faction = "Horde" or "Alliance" |
||
241 | if (f == 'Horde') or (f == 'Alliance')or (f == 'Neutral') then |
||
242 | return true |
||
243 | end |
||
244 | |||
245 | return true |
||
246 | end |
||
247 | |||
248 | -- Given an item key, breaks it into its itemID, randomProperty and enchantProperty |
||
249 | function breakItemKey(itemKey) |
||
250 | local i,j, itemID, randomProp, enchant = string.find(itemKey, "(%d+):(%d+):(%d+)"); |
||
251 | return tonumber(itemID or 0), tonumber(randomProp or 0), tonumber(enchant or 0); |
||
252 | end |
||
253 | |||
254 | function split(str, at) |
||
255 | local splut = {}; |
||
256 | |||
257 | if (type(str) ~= "string") then return nil end |
||
258 | if (not str) then str = "" end |
||
259 | |||
260 | if (not at) |
||
261 | then table.insert(splut, str) |
||
262 | |||
263 | else |
||
264 | for n, c in string.gfind(str, '([^%'..at..']*)(%'..at..'?)') do |
||
265 | table.insert(splut, n); |
||
266 | |||
267 | if (c == '') then break end |
||
268 | end |
||
269 | end |
||
270 | return splut; |
||
271 | end |
||
272 | |||
273 | function findClass(cName, sName) |
||
274 | |||
275 | if (AuctionConfig and AuctionConfig.classes) then |
||
276 | |||
277 | for class, cData in pairs(AuctionConfig.classes) do |
||
278 | |||
279 | if (cData.name == cName) then |
||
280 | if (sName == nil) then return class, 0; end |
||
281 | |||
282 | for sClass, sData in pairs(cData) do |
||
283 | if (sClass ~= "name") and (sData == sName) then |
||
284 | return class, sClass; |
||
285 | end |
||
286 | end |
||
287 | return class, 0; |
||
288 | end |
||
289 | end |
||
290 | end |
||
291 | return 0,0; |
||
292 | end |
||
293 | |||
294 | function getCatName(number) |
||
295 | if (number == 0) then return "" end; |
||
296 | |||
297 | if (AuctionConfig.classes[number]) then |
||
298 | return AuctionConfig.classes[number].name; |
||
299 | end |
||
300 | return nil; |
||
301 | end |
||
302 | |||
303 | function getCatNumberByName(name) |
||
304 | if (not name) then return 0 end |
||
305 | if (AuctionConfig and AuctionConfig.classes) then |
||
306 | |||
307 | for cat, class in pairs(AuctionConfig.classes) do |
||
308 | if (name == class.name) then |
||
309 | return cat; |
||
310 | end |
||
311 | end |
||
312 | end |
||
313 | return 0; |
||
314 | end |
||
315 | |||
316 | function getCatForKey(itemKey) |
||
317 | local info = Auctioneer.Core.GetInfo(itemKey); |
||
318 | return info.category; |
||
319 | end |
||
320 | |||
321 | function getKeyFromSig(auctSig) |
||
322 | local id, rprop, enchant = Auctioneer.Core.GetItemSignature(auctSig); |
||
323 | return id..":"..rprop..":"..enchant; |
||
324 | end |
||
325 | |||
326 | function getCatForSig(auctSig) |
||
327 | local itemKey = getKeyFromSig(auctSig); |
||
328 | return getCatForKey(itemKey); |
||
329 | end |
||
330 | |||
331 | |||
332 | function getItemLinks(str) |
||
333 | if (not (type(str) == "string")) then |
||
334 | return |
||
335 | end |
||
336 | local itemList = {}; |
||
337 | |||
338 | for link, item in string.gfind(str, "|Hitem:([^|]+)|h[[]([^]]+)[]]|h") do |
||
339 | table.insert(itemList, item.." = "..link) |
||
340 | end |
||
341 | return itemList; |
||
342 | end |
||
343 | |||
344 | function getItems(str) |
||
345 | if (not (type(str) == "string")) then |
||
346 | return |
||
347 | end |
||
348 | local itemList = {}; |
||
349 | local itemKey; |
||
350 | |||
351 | for itemID, randomProp, enchant, uniqID in string.gfind(str, "|Hitem:(%d+):(%d+):(%d+):(%d+)|h") do |
||
352 | itemKey = itemID..":"..randomProp..":"..enchant; |
||
353 | table.insert(itemList, itemKey) |
||
354 | end |
||
355 | return itemList; |
||
356 | end |
||
357 | |||
358 | --Many thanks to the guys at irc://irc.datavertex.com/cosmostesters for their help in creating this function |
||
359 | function getItemHyperlinks(str) |
||
360 | if (not (type(str) == "string")) then |
||
361 | return |
||
362 | end |
||
363 | local itemList = {}; |
||
364 | |||
365 | for color, item, name in string.gfind(str, "|c(%x+)|Hitem:(%d+:%d+:%d+:%d+)|h%[(.-)%]|h|r") do |
||
366 | table.insert(itemList, "|c"..color.."|Hitem:"..item.."|h["..name.."]|h|r") |
||
367 | end |
||
368 | return itemList; |
||
369 | end |
||
370 | |||
371 | function loadCategories() |
||
372 | if (not AuctionConfig.classes) then AuctionConfig.classes = {} end |
||
373 | loadCategoryClasses(GetAuctionItemClasses()); |
||
374 | end |
||
375 | |||
376 | function loadCategoryClasses(...) |
||
377 | for c=1, arg.n, 1 do |
||
378 | AuctionConfig.classes[c] = {}; |
||
379 | AuctionConfig.classes[c].name = arg[c]; |
||
380 | loadCategorySubClasses(c, GetAuctionItemSubClasses(c)); |
||
381 | end |
||
382 | end |
||
383 | |||
384 | function loadCategorySubClasses(c, ...) |
||
385 | for s=1, arg.n, 1 do |
||
386 | AuctionConfig.classes[c][s] = arg[s]; |
||
387 | end |
||
388 | end |
||
389 | |||
390 | function chatPrint(text, cRed, cGreen, cBlue, cAlpha, holdTime) |
||
391 | local frameIndex = Auctioneer.Command.GetFrameIndex(); |
||
392 | |||
393 | if (cRed and cGreen and cBlue) then |
||
394 | if getglobal("ChatFrame"..frameIndex) then |
||
395 | getglobal("ChatFrame"..frameIndex):AddMessage(text, cRed, cGreen, cBlue, cAlpha, holdTime); |
||
396 | |||
397 | elseif (DEFAULT_CHAT_FRAME) then |
||
398 | DEFAULT_CHAT_FRAME:AddMessage(text, cRed, cGreen, cBlue, cAlpha, holdTime); |
||
399 | end |
||
400 | |||
401 | else |
||
402 | if getglobal("ChatFrame"..frameIndex) then |
||
403 | getglobal("ChatFrame"..frameIndex):AddMessage(text, 0.0, 1.0, 0.25); |
||
404 | |||
405 | elseif (DEFAULT_CHAT_FRAME) then |
||
406 | DEFAULT_CHAT_FRAME:AddMessage(text, 0.0, 1.0, 0.25); |
||
407 | end |
||
408 | end |
||
409 | end |
||
410 | |||
411 | function setFilterDefaults() |
||
412 | if (not AuctionConfig.filters) then |
||
413 | AuctionConfig.filters = {}; |
||
414 | end |
||
415 | |||
416 | for k,v in ipairs(Auctioneer.Core.Constants.FilterDefaults) do |
||
417 | if (AuctionConfig.filters[k] == nil) then |
||
418 | AuctionConfig.filters[k] = v; |
||
419 | end |
||
420 | end |
||
421 | end |
||
422 | |||
423 | -- Pass true to protect the Auction Frame from being undesireably closed, not true to disable this |
||
424 | function protectAuctionFrame(enable) |
||
425 | --Make sure we have an AuctionFrame before doing anything |
||
426 | if (AuctionFrame) then |
||
427 | --Handle enabling of protection |
||
428 | |||
429 | if (enable and not Auctioneer_ProtectionEnabled and AuctionFrame:IsShown()) then |
||
430 | --Remember that we are now protecting the frame |
||
431 | Auctioneer_ProtectionEnabled = true; |
||
432 | --If the frame is the current doublewide frame, then clear the doublewide |
||
433 | |||
434 | if ( GetDoublewideFrame() == AuctionFrame ) then |
||
435 | SetDoublewideFrame(nil) |
||
436 | end |
||
437 | --Remove the frame from the UI frame handling system |
||
438 | UIPanelWindows["AuctionFrame"] = nil |
||
439 | --If mobile frames is around, then remove AuctionFrame from Mobile Frames handling system |
||
440 | |||
441 | if (MobileFrames_UIPanelWindowBackup) then |
||
442 | MobileFrames_UIPanelWindowBackup.AuctionFrame = nil; |
||
443 | end |
||
444 | |||
445 | if (MobileFrames_UIPanelsVisible) then |
||
446 | MobileFrames_UIPanelsVisible.AuctionFrame = nil; |
||
447 | end |
||
448 | --Hook the function to show the WorldMap, WorldMap has internal code that forces all these frames to close |
||
449 | --so for it, we have to prevent it from showing at all |
||
450 | |||
451 | if (not Auctioneer_ToggleWorldMap) then |
||
452 | Auctioneer_ToggleWorldMap = ToggleWorldMap; |
||
453 | end |
||
454 | ToggleWorldMap = function () |
||
455 | |||
456 | if ( ( not Auctioneer_ProtectionEnabled ) or ( not ( AuctionFrame and AuctionFrame:IsVisible() ) ) ) then |
||
457 | Auctioneer_ToggleWorldMap(); |
||
458 | |||
459 | else |
||
460 | UIErrorsFrame:AddMessage(_AUCT('GuiNoWorldMap'), 0, 1, 0, 1.0, UIERRORS_HOLD_TIME) |
||
461 | end |
||
462 | end |
||
463 | |||
464 | elseif (Auctioneer_ProtectionEnabled) then |
||
465 | --Handle disabling of protection |
||
466 | Auctioneer_ProtectionEnabled = nil; |
||
467 | --If Mobile Frames is around, then put the frame back under its control if it is proper to do so |
||
468 | |||
469 | if ( MobileFrames_UIPanelWindowBackup and MobileFrames_MasterEnableList and MobileFrames_MasterEnableList["AuctionFrame"] ) then |
||
470 | MobileFrames_UIPanelWindowBackup.AuctionFrame = { area = "doublewide", pushable = 0 }; |
||
471 | |||
472 | if ( MobileFrames_UIPanelsVisible and AuctionFrame:IsVisible() ) then |
||
473 | MobileFrames_UIPanelsVisible.AuctionFrame = 0; |
||
474 | end |
||
475 | |||
476 | else |
||
477 | --Put the frame back into the UI frame handling system |
||
478 | UIPanelWindows["AuctionFrame"] = { area = "doublewide", pushable = 0 }; |
||
479 | |||
480 | if ( AuctionFrame:IsVisible() ) then |
||
481 | SetDoublewideFrame(AuctionFrame) |
||
482 | end |
||
483 | end |
||
484 | end |
||
485 | end |
||
486 | end |
||
487 | |||
488 | function priceForOne(price, count) |
||
489 | price = nullSafe(price) |
||
490 | count = math.max(nullSafe(count), 1) |
||
491 | return math.ceil(price / count) |
||
492 | end |
||
493 | |||
494 | function round(x) |
||
495 | local y = math.floor(x); |
||
496 | |||
497 | if (x - y >= 0.5) then |
||
498 | return y + 1; |
||
499 | end |
||
500 | return y; |
||
501 | end |
||
502 | |||
503 | ------------------------------------------------------------------------------- |
||
504 | -- Localization functions |
||
505 | ------------------------------------------------------------------------------- |
||
506 | |||
507 | Auctioneer.Command.CommandMap = nil; |
||
508 | Auctioneer.Command.CommandMapRev = nil; |
||
509 | |||
510 | function delocalizeFilterVal(value) |
||
511 | if (value == _AUCT('CmdOn')) then |
||
512 | return 'on'; |
||
513 | |||
514 | elseif (value == _AUCT('CmdOff')) then |
||
515 | return 'off'; |
||
516 | |||
517 | elseif (value == _AUCT('CmdDefault')) then |
||
518 | return 'default'; |
||
519 | |||
520 | elseif (value == _AUCT('CmdToggle')) then |
||
521 | return 'toggle'; |
||
522 | |||
523 | else |
||
524 | return value; |
||
525 | end |
||
526 | end |
||
527 | |||
528 | function localizeFilterVal(value) |
||
529 | local result |
||
530 | |||
531 | if (value == 'on') then |
||
532 | result = _AUCT('CmdOn'); |
||
533 | |||
534 | elseif (value == 'off') then |
||
535 | result = _AUCT('CmdOff'); |
||
536 | |||
537 | elseif (value == 'default') then |
||
538 | result = _AUCT('CmdDefault'); |
||
539 | |||
540 | elseif (value == 'toggle') then |
||
541 | result = _AUCT('CmdToggle'); |
||
542 | end |
||
543 | |||
544 | if (result) then return result; else return value; end |
||
545 | end |
||
546 | |||
547 | function getLocalizedFilterVal(key) |
||
548 | return localizeFilterVal(Auctioneer.Command.GetFilterVal(key)) |
||
549 | end |
||
550 | |||
551 | -- Turns a localized slash command into the generic English version of the command |
||
552 | function delocalizeCommand(cmd) |
||
553 | if (not Auctioneer.Command.CommandMap) then Auctioneer.Command.BuildCommandMap();end |
||
554 | local result = Auctioneer.Command.CommandMap[cmd]; |
||
555 | |||
556 | if (result) then return result; else return cmd; end |
||
557 | end |
||
558 | |||
559 | -- Translate a generic English slash command to the localized version, if available |
||
560 | function localizeCommand(cmd) |
||
561 | if (not Auctioneer.Command.CommandMapRev) then Auctioneer.Command.BuildCommandMap(); end |
||
562 | local result = Auctioneer.Command.CommandMapRev[cmd]; |
||
563 | |||
564 | if (result) then return result; else return cmd; end |
||
565 | end |
||
566 | |||
567 | ------------------------------------------------------------------------------- |
||
568 | -- Inventory modifying functions |
||
569 | ------------------------------------------------------------------------------- |
||
570 | |||
571 | function findEmptySlot() |
||
572 | local name, i |
||
573 | for bag = 0, 4 do |
||
574 | name = GetBagName(bag) |
||
575 | i = string.find(name, '(Quiver|Ammo|Bandolier)') |
||
576 | if not i then |
||
577 | for slot = 1, GetContainerNumSlots(bag),1 do |
||
578 | if not (GetContainerItemInfo(bag,slot)) then |
||
579 | return bag, slot; |
||
580 | end |
||
581 | end |
||
582 | end |
||
583 | end |
||
584 | end |
||
585 | |||
586 | |||
587 | function containerFrameItemButtonOnClick(hookParams, returnValue, button, ignoreShift) --Auctioneer_ContainerFrameItemButton_OnClick |
||
588 | local bag = this:GetParent():GetID() |
||
589 | local slot = this:GetID() |
||
590 | |||
591 | local texture, count, noSplit = GetContainerItemInfo(bag, slot) |
||
592 | local link = GetContainerItemLink(bag, slot) |
||
593 | if (count and count > 1 and not noSplit) then |
||
594 | if (button == "RightButton") and (IsControlKeyDown()) then |
||
595 | local splitCount = math.floor(count / 2) |
||
596 | local emptyBag, emptySlot = findEmptySlot() |
||
597 | if (emptyBag) then |
||
598 | SplitContainerItem(bag, slot, splitCount) |
||
599 | PickupContainerItem(emptyBag, emptySlot) |
||
600 | else |
||
601 | chatPrint("Can't split, all bags are full") |
||
602 | end |
||
603 | return "abort"; |
||
604 | end |
||
605 | end |
||
606 | |||
607 | if (AuctionFrame and AuctionFrame:IsVisible()) then |
||
608 | if (link) then |
||
609 | if (button == "RightButton") and (IsAltKeyDown()) then |
||
610 | AuctionFrameTab_OnClick(1) |
||
611 | local itemID = EnhTooltip.BreakLink(link) |
||
612 | if (itemID) then |
||
613 | local itemName = GetItemInfo(tostring(itemID)) |
||
614 | if (itemName) then |
||
615 | BrowseName:SetText(itemName) |
||
616 | BrowseMinLevel:SetText("") |
||
617 | BrowseMaxLevel:SetText("") |
||
618 | AuctionFrameBrowse.selectedInvtype = nil |
||
619 | AuctionFrameBrowse.selectedInvtypeIndex = nil |
||
620 | AuctionFrameBrowse.selectedClass = nil |
||
621 | AuctionFrameBrowse.selectedClassIndex = nil |
||
622 | AuctionFrameBrowse.selectedSubclass = nil |
||
623 | AuctionFrameBrowse.selectedSubclassIndex = nil |
||
624 | AuctionFrameFilters_Update() |
||
625 | IsUsableCheckButton:SetChecked(0) |
||
626 | UIDropDownMenu_SetSelectedValue(BrowseDropDown, -1) |
||
627 | AuctionFrameBrowse_Search() |
||
628 | BrowseNoResultsText:SetText(BROWSE_NO_RESULTS) |
||
629 | end |
||
630 | end |
||
631 | return "abort"; |
||
632 | end |
||
633 | end |
||
634 | end |
||
635 | |||
636 | if (not CursorHasItem() and AuctionFrameAuctions and AuctionFrameAuctions:IsVisible() and IsAltKeyDown()) then |
||
637 | PickupContainerItem(bag, slot) |
||
638 | if (CursorHasItem() and Auctioneer.Command.GetFilter('auction-click')) then |
||
639 | ClickAuctionSellItemButton() |
||
640 | AuctionsFrameAuctions_ValidateAuction() |
||
641 | local start = MoneyInputFrame_GetCopper(StartPrice) |
||
642 | local buy = MoneyInputFrame_GetCopper(BuyoutPrice) |
||
643 | local duration = AuctionFrameAuctions.duration |
||
644 | local warn = AuctionInfoWarnText:GetText() |
||
645 | if (AuctionsCreateAuctionButton:IsEnabled() and IsShiftKeyDown()) then |
||
646 | local cHex, cRed, cGreen, cBlue = getWarnColor(warn) |
||
647 | warn = ("|c"..cHex..warn.."|r") |
||
648 | StartAuction(start, buy, duration); |
||
649 | chatPrint(string.format(_AUCT('FrmtAutostart'), link, EnhTooltip.GetTextGSC(start), EnhTooltip.GetTextGSC(buy), duration/60, warn)); |
||
650 | end |
||
651 | return "abort"; |
||
652 | end |
||
653 | end |
||
654 | |||
655 | if (not CursorHasItem() and AuctionFramePost and AuctionFramePost:IsVisible() and button == "LeftButton" and IsAltKeyDown()) then |
||
656 | local _, count = GetContainerItemInfo(bag, slot); |
||
657 | if (count) then |
||
658 | if (count > 1 and IsShiftKeyDown()) then |
||
659 | this.SplitStack = function(button, split) |
||
660 | local _, _, _, _, name = EnhTooltip.BreakLink(link); |
||
661 | AuctionFramePost:SetAuctionItem(bag, slot, split); |
||
662 | end |
||
663 | OpenStackSplitFrame(count, this, "BOTTOMRIGHT", "TOPRIGHT"); |
||
664 | else |
||
665 | local _, _, _, _, name = EnhTooltip.BreakLink(link); |
||
666 | AuctionFramePost:SetAuctionItem(bag, slot, 1); |
||
667 | end |
||
668 | return "abort"; |
||
669 | end |
||
670 | end |
||
671 | end |
||
672 | |||
673 | Auctioneer.Util = { |
||
674 | GetTimeLeftString = getTimeLeftString, |
||
675 | GetSecondsLeftString = getSecondsLeftString, |
||
676 | UnpackSeconds = unpackSeconds, |
||
677 | GetGSC = getGSC, |
||
678 | GetTextGSC = getTextGSC, |
||
679 | NilSafeString = nilSafeString, |
||
680 | ColorTextWhite = colorTextWhite, |
||
681 | GetWarnColor = getWarnColor, |
||
682 | NullSafe = nullSafe, |
||
683 | SanifyAHSnapshot = sanifyAHSnapshot, |
||
684 | GetAuctionKey = getAuctionKey, |
||
685 | GetOppositeKey = getOppositeKey, |
||
686 | GetNeutralKey = getNeutralKey, |
||
687 | GetHomeKey = getHomeKey, |
||
688 | IsValidAlso = isValidAlso, |
||
689 | BreakItemKey = breakItemKey, |
||
690 | Split = split, |
||
691 | FindClass = findClass, |
||
692 | GetCatName = getCatName, |
||
693 | GetCatNumberByName = getCatNumberByName, |
||
694 | GetCatForKey = getCatForKey, |
||
695 | GetKeyFromSig = getKeyFromSig, |
||
696 | GetCatForSig = getCatForSig, |
||
697 | GetItemLinks = getItemLinks, |
||
698 | GetItems = getItems, |
||
699 | GetItemHyperlinks = getItemHyperlinks, |
||
700 | LoadCategories = loadCategories, |
||
701 | LoadCategoryClasses = loadCategoryClasses, |
||
702 | LoadCategorySubClasses = loadCategorySubClasses, |
||
703 | ChatPrint = chatPrint, |
||
704 | SetFilterDefaults = setFilterDefaults, |
||
705 | ProtectAuctionFrame = protectAuctionFrame, |
||
706 | PriceForOne = priceForOne, |
||
707 | Round = round, |
||
708 | DelocalizeFilterVal = delocalizeFilterVal, |
||
709 | LocalizeFilterVal = localizeFilterVal, |
||
710 | GetLocalizedFilterVal = getLocalizedFilterVal, |
||
711 | DelocalizeCommand = delocalizeCommand, |
||
712 | LocalizeCommand = localizeCommand, |
||
713 | FindEmptySlot = findEmptySlot, |
||
714 | ContainerFrameItemButtonOnClick = containerFrameItemButtonOnClick, |
||
715 | } |