vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | |
2 | TITAN_ITEMDED_ID = "ItemDed"; |
||
3 | |||
4 | ITEMDED_WARN_THRESHOLD = 4; |
||
5 | |||
6 | -- Local variables |
||
7 | local TitanItemDed_isLoaded = false; |
||
8 | local TitanItemDed_ignored = {}; |
||
9 | local TitanItemDed_ItemList = {}; |
||
10 | local PlayerIdent = GetCVar("RealmName").. UnitName("player"); |
||
11 | local TPID_Color = { |
||
12 | {"ff9d9d9d", "Junk"}, -- gray |
||
13 | {"ffffffff", "Common"}, -- white |
||
14 | {"ff1eff00", "Uncommon"}, -- green |
||
15 | {"ff0070dd", "Rare"}, -- blue |
||
16 | {"ffa335ee", "Epic"}, -- purple |
||
17 | }; |
||
18 | |||
19 | function TitanItemDed_OnLoad() |
||
20 | this.registry = { |
||
21 | id = TITAN_ITEMDED_ID, |
||
22 | menuText = TITAN_ITEMDED_MENU_TEXT, |
||
23 | buttonTextFunction = "TitanPanelItemDedButton_GetButtonText", |
||
24 | tooltipTitle = TITAN_ITEMDED_TOOLTIP_TITLE, |
||
25 | tooltipTextFunction = "TitanPanelItemDedButton_GetTooltipText", |
||
26 | icon = "", |
||
27 | iconWidth = 16, |
||
28 | savedVariables = { |
||
29 | ShowIcon = 1, |
||
30 | ShowLabelText = 1, |
||
31 | ShowChatFeedback = 1 |
||
32 | } |
||
33 | }; |
||
34 | |||
35 | this:RegisterEvent("VARIABLES_LOADED"); |
||
36 | this:RegisterEvent("BAG_UPDATE"); |
||
37 | this:RegisterEvent("MERCHANT_SHOW"); |
||
38 | end |
||
39 | |||
40 | function TitanPanelItemDedButton_UpdateIcon() |
||
41 | TitanItemDed_MakeList(); |
||
42 | |||
43 | local button = TitanUtils_GetButton(TITAN_ITEMDED_ID, true); |
||
44 | |||
45 | if (TitanItemDed_ItemList[1]) then |
||
46 | button.registry.icon = TitanItemDed_ItemList[1].tex; |
||
47 | else |
||
48 | button.registry.icon = ""; |
||
49 | end |
||
50 | |||
51 | TitanPanelButton_UpdateButton(TITAN_ITEMDED_ID); |
||
52 | end |
||
53 | |||
54 | function TitanPanelItemDedButton_GetButtonText(id) |
||
55 | local numempty = TitanItemDed_GetEmpties(); |
||
56 | local itemtext; |
||
57 | local numtxt = "(".. numempty.. ")"; |
||
58 | |||
59 | if (TitanItemDed_ItemList[1]) then |
||
60 | itemtext = TitanItemDed_ItemList[1].fullname.. " "; |
||
61 | else |
||
62 | itemtext = "No Item "; |
||
63 | end |
||
64 | |||
65 | if (numempty < ITEMDED_WARN_THRESHOLD) then |
||
66 | numtxt = TitanUtils_GetRedText(numtxt); |
||
67 | else |
||
68 | numtxt = TitanUtils_GetNormalText(numtxt); |
||
69 | end |
||
70 | |||
71 | return itemtext, numtxt; |
||
72 | end |
||
73 | |||
74 | function TitanPanelItemDedButton_GetTooltipText() |
||
75 | local retstr = TITAN_ITEMDED_TOOLTIP_BAGS; |
||
76 | |||
77 | if (TitanItemDed_ItemList[1]) then |
||
78 | if (MerchantFrame:IsVisible()) then |
||
79 | retstr = retstr.. TITAN_ITEMDED_TOOLTIP_SELL; |
||
80 | retstr = retstr.. TITAN_ITEMDED_TOOLTIP_IGNORE; |
||
81 | else |
||
82 | retstr = retstr.. TITAN_ITEMDED_TOOLTIP_DESTROY; |
||
83 | retstr = retstr.. TITAN_ITEMDED_TOOLTIP_IGNORE; |
||
84 | end |
||
85 | |||
86 | for i,entry in TitanItemDed_ItemList do |
||
87 | retstr = retstr.. entry.fullname.. "\t".. TitanItemDed_GetTextGSC(entry.price).. "\n"; |
||
88 | end |
||
89 | else |
||
90 | retstr = retstr.. TITAN_ITEMDED_NOITEMDESTROY; |
||
91 | end |
||
92 | |||
93 | return retstr; |
||
94 | end |
||
95 | |||
96 | function TitanItemDed_OnEvent() |
||
97 | if (event == "VARIABLES_LOADED") then |
||
98 | TitanItemDed_Init(); |
||
99 | TitanItemDed_isLoaded = true; |
||
100 | TitanPanelItemDedButton_UpdateIcon(); |
||
101 | end |
||
102 | if (event == "BAG_UPDATE") then |
||
103 | TitanPanelItemDedButton_UpdateIcon(); |
||
104 | end |
||
105 | end |
||
106 | |||
107 | function TitanPanelRightClickMenu_PrepareItemDedMenu() |
||
108 | if (not TitanItemDed_isLoaded) then return; end |
||
109 | |||
110 | local info; |
||
111 | |||
112 | TitanPanelRightClickMenu_AddTitle(TitanPlugins[TITAN_ITEMDED_ID].menuText); |
||
113 | TitanPanelRightClickMenu_AddSpacer(); |
||
114 | |||
115 | if (MerchantFrame:IsVisible() and (not IsAddOnLoaded("Sell-O-Matic"))) then |
||
116 | info = {}; |
||
117 | info.text = "Sell All Junk"; |
||
118 | info.func = TitanItemDed_SellJunk; |
||
119 | UIDropDownMenu_AddButton(info); |
||
120 | end |
||
121 | |||
122 | info = {}; |
||
123 | if (MerchantFrame:IsVisible()) then info.text = "Sell Item"; |
||
124 | else info.text = "Drop Item"; end |
||
125 | info.func = TitanItemDed_Listman; |
||
126 | info.value = "t"; |
||
127 | UIDropDownMenu_AddButton(info); |
||
128 | |||
129 | TitanPanelRightClickMenu_AddSpacer(); |
||
130 | |||
131 | info = {}; |
||
132 | info.text = "Ignore"; |
||
133 | info.value = "i"; |
||
134 | info.func = TitanItemDed_Listman; |
||
135 | UIDropDownMenu_AddButton(info); |
||
136 | |||
137 | info = {}; |
||
138 | info.text = "Ignore Always"; |
||
139 | info.value = "ia"; |
||
140 | info.func = TitanItemDed_Listman; |
||
141 | UIDropDownMenu_AddButton(info); |
||
142 | |||
143 | TitanPanelRightClickMenu_AddSpacer(); |
||
144 | |||
145 | info = {}; |
||
146 | info.text = "Reset Current"; |
||
147 | info.value = "r"; |
||
148 | info.func = TitanItemDed_Listman; |
||
149 | UIDropDownMenu_AddButton(info); |
||
150 | |||
151 | info = {}; |
||
152 | info.text = "Reset All"; |
||
153 | info.value = "ra"; |
||
154 | info.func = TitanItemDed_Listman; |
||
155 | UIDropDownMenu_AddButton(info); |
||
156 | |||
157 | TitanPanelRightClickMenu_AddSpacer(); |
||
158 | |||
159 | local i; |
||
160 | local a = {"Junk", "Common", "Uncommon", "Rare", "Epic"}; |
||
161 | TitanPanelRightClickMenu_AddTitle("Threshold"); |
||
162 | for i=1,5 do |
||
163 | info = {}; |
||
164 | info.text = "|c".. TPID_Color[i][1].. TPID_Color[i][2]; |
||
165 | info.value = i; |
||
166 | info.func = TitanItemDed_SetThreshold; |
||
167 | info.checked = (i == TitanItemDedSettings[PlayerIdent].Threshold); |
||
168 | UIDropDownMenu_AddButton(info); |
||
169 | end |
||
170 | |||
171 | TitanPanelRightClickMenu_AddSpacer(); |
||
172 | TitanPanelRightClickMenu_AddToggleIcon(TITAN_ITEMDED_ID); |
||
173 | TitanPanelRightClickMenu_AddToggleLabelText(TITAN_ITEMDED_ID); |
||
174 | |||
175 | info = {}; |
||
176 | info.text = "Chat Feedback"; |
||
177 | info.value = "ShowChatFeedback"; |
||
178 | info.func = TitanItemDed_ToggleChatback; |
||
179 | info.checked = TitanGetVar(TITAN_ITEMDED_ID, "ShowChatFeedback"); |
||
180 | UIDropDownMenu_AddButton(info); |
||
181 | |||
182 | TitanPanelRightClickMenu_AddSpacer(); |
||
183 | TitanPanelRightClickMenu_AddCommand(TITAN_PANEL_MENU_HIDE, TITAN_ITEMDED_ID, TITAN_PANEL_MENU_FUNC_HIDE); |
||
184 | end |
||
185 | |||
186 | |||
187 | function TitanItemDed_ToggleChatback() |
||
188 | TitanToggleVar(TITAN_ITEMDED_ID, "ShowChatFeedback"); |
||
189 | end |
||
190 | |||
191 | function TitanItemDed_OnClick(button) |
||
192 | if (button == "LeftButton") then |
||
193 | if(IsShiftKeyDown()) then |
||
194 | TitanItemDed_Listman("t"); |
||
195 | else |
||
196 | OpenAllBags(); |
||
197 | end |
||
198 | end |
||
199 | end |
||
200 | |||
201 | function TitanItemDed_OnDoubleClick(button) |
||
202 | if (button == "LeftButton") then |
||
203 | if(IsAltKeyDown()) then |
||
204 | TitanItemDed_Listman("ia"); |
||
205 | else |
||
206 | TitanItemDed_Listman("i"); |
||
207 | end |
||
208 | end |
||
209 | end |
||
210 | |||
211 | function TitanItemDed_SetThreshold() |
||
212 | local t = { |
||
213 | ["Junk"] = 5, |
||
214 | ["Common"] = 4, |
||
215 | ["Uncommon"] = 3, |
||
216 | ["Rare"] = 2, |
||
217 | ["Epic"] = 1, |
||
218 | }; |
||
219 | TitanItemDedSettings[PlayerIdent].Threshold = this.value; |
||
220 | |||
221 | local str = "|c".. TPID_Color[this.value][1].. TPID_Color[this.value][2]; |
||
222 | TitanItemDed_Chatback("Threshold set to ".. str); |
||
223 | |||
224 | TitanPanelItemDedButton_UpdateIcon(); |
||
225 | end |
||
226 | |||
227 | function TitanItemDed_Chatback(str) |
||
228 | if (TitanGetVar(TITAN_ITEMDED_ID, "ShowChatFeedback")) then |
||
229 | DEFAULT_CHAT_FRAME:AddMessage("<ItemDed> ".. str); |
||
230 | end |
||
231 | end |
||
232 | |||
233 | function TitanItemDed_GetFullName(name, qual) |
||
234 | return "|c".. TPID_Color[qual][1].. |
||
235 | "[".. name.. "]".. FONT_COLOR_CODE_CLOSE; |
||
236 | end |
||
237 | |||
238 | function TitanItemDed_MakeList() |
||
239 | TitanItemDed_ItemList = {}; |
||
240 | |||
241 | for bag=0,NUM_BAG_FRAMES do |
||
242 | for slot=1,GetContainerNumSlots(bag) do |
||
243 | local price = nil; |
||
244 | local item_name = TitanItemDed_GetItemName(bag, slot); |
||
245 | local item_texture, stackCount = GetContainerItemInfo(bag, slot); |
||
246 | |||
247 | if (item_name and stackCount) then |
||
248 | if (TitanItemDed_items[item_name]) then |
||
249 | price = TitanItemDed_items[item_name]; |
||
250 | end |
||
251 | |||
252 | if (price) then price = price * stackCount; end |
||
253 | |||
254 | if (price) then |
||
255 | if TitanItemDed_IsDroppable(bag, slot) then |
||
256 | local qual = TitanItemDed_GetQuality(bag, slot); |
||
257 | |||
258 | local n = {}; |
||
259 | n.price = price; |
||
260 | n.name = item_name; |
||
261 | n.fullname = TitanItemDed_GetFullName(item_name, qual).. " x".. stackCount; |
||
262 | n.stack = stackCount; |
||
263 | n.bag = bag; |
||
264 | n.slot = slot; |
||
265 | n.tex = item_texture; |
||
266 | table.insert(TitanItemDed_ItemList, n); |
||
267 | end |
||
268 | end |
||
269 | end |
||
270 | |||
271 | if (ID_Debug and item_name and item_isGray and price) then debug_message(item_name, price.." Gray"); end |
||
272 | if (ID_Debug and item_name and item_isGray == false and price) then debug_message(item_name, price); end |
||
273 | end |
||
274 | end |
||
275 | |||
276 | table.sort(TitanItemDed_ItemList, function(a,b) return a.price<b.price end); |
||
277 | end |
||
278 | |||
279 | function TitanItemDed_Init() |
||
280 | if (TitanItemDed_alwaysIgnored == nil) then TitanItemDed_alwaysIgnored = {}; end |
||
281 | if (TitanItemDed_newItems == nil) then TitanItemDed_newItems = {}; end |
||
282 | TitanItemDed_CleanSaved(); |
||
283 | |||
284 | if (TitanItemDedSettings == nil) then |
||
285 | TitanItemDedSettings = {}; |
||
286 | end |
||
287 | |||
288 | if (TitanItemDedSettings[PlayerIdent] == nil) then |
||
289 | TitanItemDedSettings[PlayerIdent] = {}; |
||
290 | TitanItemDedSettings[PlayerIdent].Ignored = {}; |
||
291 | TitanItemDedSettings[PlayerIdent].Threshold = 1; |
||
292 | end |
||
293 | |||
294 | if (TitanItemDedSettings[PlayerIdent].Ignored == nil) then |
||
295 | TitanItemDedSettings[PlayerIdent].Ignored = {}; |
||
296 | end |
||
297 | |||
298 | if (TitanItemDedSettings[PlayerIdent].Threshold == nil) then |
||
299 | TitanItemDedSettings[PlayerIdent].Threshold = 1; |
||
300 | end |
||
301 | |||
302 | if (not TitanItemDed_unknowns) then |
||
303 | TitanItemDed_unknowns = {}; |
||
304 | end |
||
305 | |||
306 | TitanPanelItemDedButton_UpdateIcon(); |
||
307 | |||
308 | return; |
||
309 | end |
||
310 | |||
311 | function TitanItemDed_Listman(cmd, itemidx) |
||
312 | local act = cmd; |
||
313 | local item = TitanItemDed_ItemList[itemidx]; |
||
314 | if (not act) then act = this.value; end |
||
315 | if (not item) then item = TitanItemDed_ItemList[1]; end |
||
316 | |||
317 | if (act == "i") then |
||
318 | if item then TitanItemDed_ignored[item.name] = 1; end |
||
319 | if item then TitanItemDed_Chatback(item.name.." is now ignored."); |
||
320 | else TitanItemDed_Chatback("Nothing to ignore!"); end |
||
321 | end |
||
322 | if (act == "ia") then |
||
323 | if item then TitanItemDedSettings[PlayerIdent]["Ignored"][item.name] = 1; end |
||
324 | if item then TitanItemDed_Chatback(item.name.." is now always ignored."); |
||
325 | else TitanItemDed_Chatback("Nothing to ignore!"); end |
||
326 | end |
||
327 | if (act == "r") then |
||
328 | TitanItemDed_ignored = {}; |
||
329 | TitanItemDed_Chatback("Current ignored items reset."); |
||
330 | end |
||
331 | if (act == "ra") then |
||
332 | TitanItemDed_ignored = {}; |
||
333 | TitanItemDedSettings[PlayerIdent]["Ignored"] = {}; |
||
334 | TitanItemDed_Chatback("Always ignored items reset."); |
||
335 | end |
||
336 | if (act == "t") then |
||
337 | if item then |
||
338 | if (MerchantFrame:IsVisible()) then |
||
339 | UseContainerItem(item.bag, item.slot); |
||
340 | else |
||
341 | TitanItemDed_Chatback("Deleting "..item.fullname.." worth "..item.price); |
||
342 | PickupContainerItem(item.bag, item.slot); |
||
343 | DeleteCursorItem(); |
||
344 | end |
||
345 | else |
||
346 | TitanItemDed_Chatback(TITAN_ITEMDED_NOITEMDESTROY); |
||
347 | end |
||
348 | end |
||
349 | |||
350 | TitanPanelItemDedButton_UpdateIcon(); |
||
351 | end |
||
352 | |||
353 | function TitanItemDed_SellJunk() |
||
354 | for bag=0,NUM_BAG_FRAMES do |
||
355 | for slot=1,GetContainerNumSlots(bag) do |
||
356 | local qual = TitanItemDed_GetQuality(bag, slot); |
||
357 | |||
358 | if (qual) then |
||
359 | if ((qual == 1) and (MerchantFrame:IsVisible())) then |
||
360 | UseContainerItem(bag, slot); |
||
361 | end |
||
362 | end |
||
363 | end |
||
364 | end |
||
365 | end |
||
366 | |||
367 | ------------------------------------------------------------------------------- |
||
368 | -- Bag Search functions |
||
369 | ------------------------------------------------------------------------------- |
||
370 | |||
371 | function TitanItemDed_GetItemName(bag, slot) |
||
372 | local linktext = nil; |
||
373 | |||
374 | if (bag == -1) then |
||
375 | linktext = GetInventoryItemLink("player", slot); |
||
376 | else |
||
377 | linktext = GetContainerItemLink(bag, slot); |
||
378 | end |
||
379 | |||
380 | if linktext then |
||
381 | local _,_,name = string.find(linktext, "^.*%[(.*)%].*$"); |
||
382 | return name; |
||
383 | else |
||
384 | return nil; |
||
385 | end |
||
386 | end |
||
387 | |||
388 | function TitanItemDed_GetQuality(bag, slot) |
||
389 | local link = nil; |
||
390 | local color = nil; |
||
391 | |||
392 | if (bag == -1) then |
||
393 | link = GetInventoryItemLink("player", slot); |
||
394 | else |
||
395 | link = GetContainerItemLink(bag, slot); |
||
396 | end |
||
397 | |||
398 | if (link) then |
||
399 | for color, _, _ in string.gfind(link, "|c(%x+)|Hitem:(%d+:%d+:%d+:%d+)|h%[(.-)%]|h|r") do |
||
400 | for i,c in TPID_Color do |
||
401 | if (c[1] == color) then |
||
402 | return i; |
||
403 | end |
||
404 | end |
||
405 | end |
||
406 | end |
||
407 | |||
408 | return nil; |
||
409 | end |
||
410 | |||
411 | function TitanItemDed_IsDroppable(bag, slot) |
||
412 | local itemname = TitanItemDed_GetItemName(bag, slot); |
||
413 | |||
414 | if TitanItemDed_ignored[itemname] then return false; end; |
||
415 | if TitanItemDedSettings[PlayerIdent]["Ignored"][itemname] then return false; end; |
||
416 | if (TitanItemDed_GetQuality(bag, slot) > TitanItemDedSettings[PlayerIdent].Threshold) then return false; end; |
||
417 | |||
418 | return true; |
||
419 | end |
||
420 | |||
421 | function TitanItemDed_GetEmpties() |
||
422 | local numempty = 0; |
||
423 | |||
424 | for bag=0,NUM_BAG_FRAMES do |
||
425 | if (TitanItemDed_IsAmmoBag(bag)) then |
||
426 | -- Do Nothing |
||
427 | else |
||
428 | for slot=1,GetContainerNumSlots(bag) do |
||
429 | local item_name = TitanItemDed_GetItemName(bag, slot); |
||
430 | if (not item_name) then numempty = numempty+1; end |
||
431 | end |
||
432 | end |
||
433 | end |
||
434 | |||
435 | return numempty; |
||
436 | end |
||
437 | |||
438 | function TitanItemDed_IsAmmoBag(bag) |
||
439 | local bagname = GetBagName(bag); |
||
440 | |||
441 | if (bagname) then |
||
442 | if (string.find(bagname, "Quiver") or string.find(bagname, "Ammo") or string.find(bagname, "Bandolier")) then |
||
443 | return true; |
||
444 | end |
||
445 | end |
||
446 | |||
447 | return false; |
||
448 | end |
||
449 | |||
450 | ------------------------------------------------------------------------------- |
||
451 | -- Gold formatting code, shamelessly "borrowed" from Auctioneer |
||
452 | ------------------------------------------------------------------------------- |
||
453 | |||
454 | function TitanItemDed_GetGSC(money) |
||
455 | if (money == nil) then money = 0; end |
||
456 | local g = math.floor(money / 10000); |
||
457 | local s = math.floor((money - (g*10000)) / 100); |
||
458 | local c = math.floor(money - (g*10000) - (s*100)); |
||
459 | return g,s,c; |
||
460 | end |
||
461 | |||
462 | GSC_GOLD="ffd100"; |
||
463 | GSC_SILVER="e6e6e6"; |
||
464 | GSC_COPPER="c8602c"; |
||
465 | GSC_START="|cff%s%d|r"; |
||
466 | GSC_PART=".|cff%s%02d|r"; |
||
467 | GSC_NONE="|cffa0a0a0none|r"; |
||
468 | |||
469 | function TitanItemDed_GetTextGSC(money) |
||
470 | local g, s, c = TitanItemDed_GetGSC(money); |
||
471 | local gsc = ""; |
||
472 | if (g > 0) then |
||
473 | gsc = format(GSC_START, GSC_GOLD, g); |
||
474 | if ((s > 0) or (c > 0)) then |
||
475 | if (c > 50) then s = s+1; end |
||
476 | gsc = gsc..format(GSC_PART, GSC_SILVER, s); |
||
477 | end |
||
478 | elseif (s > 0) then |
||
479 | gsc = format(GSC_START, GSC_SILVER, s); |
||
480 | if (c > 0) then |
||
481 | gsc = gsc..format(GSC_PART, GSC_COPPER, c); |
||
482 | end |
||
483 | elseif (c > 0) then |
||
484 | gsc = gsc..format(GSC_START, GSC_COPPER, c); |
||
485 | else |
||
486 | gsc = GSC_NONE; |
||
487 | end |
||
488 | |||
489 | return gsc; |
||
490 | end |
||
491 | |||
492 | ------------------------------------------------------------------------------- |
||
493 | -- External Mod search functions |
||
494 | ------------------------------------------------------------------------------- |
||
495 | |||
496 | function TitanItemDed_GetEconPrice(item_name) |
||
497 | if (WOWEcon_Prices[item_name]) then return WOWEcon_Prices[item_name][1]; end |
||
498 | return nil; |
||
499 | end |
||
500 | |||
501 | function TitanItemDed_CmdScan() |
||
502 | -- Scan WoWEcon's list, if it exists |
||
503 | if (WOWEcon_Prices) then |
||
504 | for item in WOWEcon_Prices do |
||
505 | if ( (WOWEcon_Prices[item][1]) and (TitanItemDed_newItems[item] == nil) and (TitanItemDed_items[item] == nil) ) then |
||
506 | if (WOWEcon_Prices[item][1] > 0) then |
||
507 | TitanItemDed_newItems[item] = WOWEcon_Prices[item][1]; |
||
508 | end |
||
509 | end |
||
510 | end |
||
511 | end |
||
512 | end |
||
513 | |||
514 | function TitanItemDed_CleanSaved() |
||
515 | local oldNews = TitanItemDed_newItems; |
||
516 | TitanItemDed_newItems = {}; |
||
517 | |||
518 | for item in oldNews do |
||
519 | if (not TitanItemDed_items[item]) then |
||
520 | TitanItemDed_newItems[item] = oldNews[item]; |
||
521 | end |
||
522 | end |
||
523 | end |
||
524 |