vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --[[-------------------------------------------------------------------------------- |
2 | ItemSyncCore BagView Framework |
||
3 | |||
4 | Author: Derkyle |
||
5 | Website: http://www.manaflux.com |
||
6 | -----------------------------------------------------------------------------------]] |
||
7 | |||
8 | local ISync_BVList = { }; |
||
9 | |||
10 | --------------------------------------------------- |
||
11 | -- ISync:BV_Load |
||
12 | --------------------------------------------------- |
||
13 | function ISync:BV_Load() |
||
14 | --------------------------------------------------- |
||
15 | -- Register our slash command |
||
16 | SLASH_ISYNCBAGVIEW1 = "/bagview"; |
||
17 | SLASH_ISYNCBAGVIEW2 = "/bv"; |
||
18 | SLASH_ISYNCBAGVIEW3 = "/bagv"; |
||
19 | SlashCmdList["ISYNCBAGVIEW"] = function(msg) |
||
20 | |||
21 | if(ISYNC_LOADYES == 1) then |
||
22 | if ( ISync_BV_Frame:IsVisible() ) then ISync_BV_Frame:Hide(); else ISync_BV_Frame:Show(); end |
||
23 | end |
||
24 | end |
||
25 | tinsert(UISpecialFrames, "ISync_BV_Frame"); |
||
26 | end |
||
27 | |||
28 | --------------------------------------------------- |
||
29 | -- ISync:BV_Binding |
||
30 | --------------------------------------------------- |
||
31 | function ISync:BV_Unload() |
||
32 | ISync_BVList = nil; |
||
33 | end |
||
34 | |||
35 | |||
36 | --------------------------------------------------- |
||
37 | -- ISync:BV_Binding |
||
38 | --------------------------------------------------- |
||
39 | function ISync:BV_Binding() |
||
40 | if(ISYNC_LOADYES == 1) then |
||
41 | if ( ISync_BV_Frame:IsVisible() ) then ISync_BV_Frame:Hide(); else ISync_BV_Frame:Show(); end |
||
42 | end |
||
43 | end |
||
44 | |||
45 | |||
46 | --------------------------------------------------- |
||
47 | -- ISync:BV_Refresh() |
||
48 | --------------------------------------------------- |
||
49 | function ISync:BV_Refresh() |
||
50 | |||
51 | ISync_BVList = nil; --reset |
||
52 | |||
53 | local offset = FauxScrollFrame_GetOffset(ISync_IC_ScrollFrame); |
||
54 | |||
55 | if( offset ) then |
||
56 | --set to last offset |
||
57 | FauxScrollFrame_SetOffset(ISync_IC_ScrollFrame, offset); |
||
58 | else |
||
59 | --set to zero offset |
||
60 | FauxScrollFrame_SetOffset(ISync_IC_ScrollFrame, 0); |
||
61 | end |
||
62 | |||
63 | ISync:BV_BuildIndex(); |
||
64 | ISync:BV_UpdateScrollFrame(); |
||
65 | |||
66 | end |
||
67 | |||
68 | |||
69 | --------------------------------------------------- |
||
70 | -- ISync:BV_BuildIndex() |
||
71 | --------------------------------------------------- |
||
72 | function ISync:BV_BuildIndex() |
||
73 | |||
74 | if(not ISyncDB) then return nil; end |
||
75 | if(not ISyncDB[ISYNC_REALM_NUM]) then return nil; end |
||
76 | |||
77 | --reset inven array |
||
78 | ISync_BVList = nil; |
||
79 | ISync_BVList = { }; |
||
80 | |||
81 | local iNew = 1; |
||
82 | local costOfItem, sColor, sParseLink; |
||
83 | |||
84 | --do the loops through all the bags |
||
85 | for bag=0,NUM_BAG_FRAMES do |
||
86 | for slot=1,GetContainerNumSlots(bag) do |
||
87 | local link = GetContainerItemLink(bag, slot); |
||
88 | |||
89 | if (link) then |
||
90 | |||
91 | local sID = ISync:GetCoreID(link); |
||
92 | local name = ISync:NameFromLink(link); |
||
93 | local link = ISync:GetItemID(link); |
||
94 | |||
95 | if(ISync:FetchDB(sID, "price")) then |
||
96 | |||
97 | --grab the item information from the bag, slot |
||
98 | local texture, itemCount, locked, quality, readable = GetContainerItemInfo(bag, slot); |
||
99 | |||
100 | --we have to have an item count |
||
101 | if(itemCount) then |
||
102 | |||
103 | costOfItem = 0; |
||
104 | costOfItem = tonumber(ISync:FetchDB(sID, "price")); |
||
105 | |||
106 | --show stacked |
||
107 | if(costOfItem > 0 and itemCount > 0 and ISync:SetVar({"BAGVIEW","SHOWSTACKED"}, 1, "COMPARE")) then |
||
108 | costOfItem = floor(tonumber(costOfItem) * tonumber(itemCount)); |
||
109 | end |
||
110 | |||
111 | if(not costOfItem or costOfItem < 1 and ISync:SetVar({"BAGVIEW","SHOWNIL"}, 1, "COMPARE")) then |
||
112 | --do nothing cause we want to hide value for this item |
||
113 | else |
||
114 | if(not costOfItem or costOfItem < 1) then costOfItem = 0; end |
||
115 | --insert into table |
||
116 | ISync_BVList[iNew] = { }; |
||
117 | ISync_BVList[iNew].name = name; |
||
118 | ISync_BVList[iNew].money = costOfItem; |
||
119 | ISync_BVList[iNew].bag = bag; |
||
120 | ISync_BVList[iNew].slot = slot; |
||
121 | ISync_BVList[iNew].count = itemCount; |
||
122 | ISync_BVList[iNew].quality = tonumber(ISync:FetchDB(sID, "quality")); |
||
123 | ISync_BVList[iNew].texture = texture; |
||
124 | ISync_BVList[iNew].link = link; |
||
125 | ISync_BVList[iNew].coreID = sID; |
||
126 | |||
127 | iNew = iNew + 1; |
||
128 | |||
129 | end |
||
130 | |||
131 | |||
132 | end--if(itemCount) then |
||
133 | |||
134 | end--if(name and name ~= "") then |
||
135 | |||
136 | |||
137 | end--if (link and link ~= "") then |
||
138 | |||
139 | end--end for |
||
140 | end--end for |
||
141 | |||
142 | |||
143 | ISync_BVList.onePastEnd = iNew; |
||
144 | |||
145 | ISync:BV_Sort(); |
||
146 | |||
147 | |||
148 | end |
||
149 | |||
150 | |||
151 | --------------------------------------------------- |
||
152 | -- ISync:BV_Sort() |
||
153 | --------------------------------------------------- |
||
154 | function ISync:BV_Sort() |
||
155 | |||
156 | if not ISync_BVList then return; end |
||
157 | |||
158 | if(ISync:SetVar({"BAGVIEW","SORT_VALUE"}, 1, "COMPARE")) then |
||
159 | table.sort(ISync_BVList, ISync_BV_SortByValue); |
||
160 | elseif(ISync:SetVar({"BAGVIEW","SORT_RARITY"}, 1, "COMPARE")) then |
||
161 | table.sort(ISync_BVList, ISync_BV_SortByRarity); |
||
162 | else |
||
163 | table.sort(ISync_BVList, ISync_BV_SortByName); |
||
164 | end |
||
165 | |||
166 | end |
||
167 | |||
168 | |||
169 | --------------------------------------------------- |
||
170 | -- ISync_BV_SortByName |
||
171 | --------------------------------------------------- |
||
172 | function ISync_BV_SortByName(a,b) |
||
173 | |||
174 | return a.name < b.name; |
||
175 | |||
176 | end |
||
177 | |||
178 | --------------------------------------------------- |
||
179 | -- ISync_BV_SortByValue |
||
180 | --------------------------------------------------- |
||
181 | function ISync_BV_SortByValue(a,b) |
||
182 | |||
183 | if(a.money and b.money) then |
||
184 | return b.money < a.money; |
||
185 | end |
||
186 | |||
187 | end |
||
188 | |||
189 | --------------------------------------------------- |
||
190 | -- ISync_BV_SortByRarity |
||
191 | --------------------------------------------------- |
||
192 | function ISync_BV_SortByRarity(elem1, elem2) |
||
193 | |||
194 | local color1, color2; |
||
195 | |||
196 | --get the corresponding quality |
||
197 | color1 = elem1.quality; |
||
198 | color2 = elem2.quality |
||
199 | |||
200 | if(color1 and color2) then |
||
201 | |||
202 | if( color1 == color2 ) then |
||
203 | return elem1.name < elem2.name; |
||
204 | end |
||
205 | |||
206 | return color2 < color1; |
||
207 | |||
208 | else |
||
209 | return nil; |
||
210 | end |
||
211 | |||
212 | end |
||
213 | |||
214 | |||
215 | --------------------------------------------------- |
||
216 | -- ISync:BV_UpdateScrollFrame() |
||
217 | --------------------------------------------------- |
||
218 | function ISync:BV_UpdateScrollFrame() |
||
219 | |||
220 | local iItem; |
||
221 | |||
222 | if (not ISync_BV_Frame:IsVisible()) then return; end |
||
223 | if (not ISync_BVList) then ISync:BV_BuildIndex(); end --make sure |
||
224 | if (not ISync_BVList or not ISync_BVList.onePastEnd) then return nil; end |
||
225 | |||
226 | --start the scroll process |
||
227 | --15 items and height of 16 each |
||
228 | FauxScrollFrame_Update(ISync_IC_ScrollFrame, ISync_BVList.onePastEnd - 1, 15, 16); |
||
229 | |||
230 | --loop through the 15 frames |
||
231 | for iItem = 1, 15, 1 do |
||
232 | |||
233 | --grab the current item index and then get the itembar object itself |
||
234 | local itemIndex = iItem + FauxScrollFrame_GetOffset(ISync_IC_ScrollFrame); |
||
235 | local ISyncItemObj = getglobal("ISync_BrowseButton"..iItem); |
||
236 | |||
237 | --if it's still within boundaries then procezz |
||
238 | if( itemIndex < ISync_BVList.onePastEnd ) then |
||
239 | |||
240 | --make sure the item is even in the array and that it has an sID |
||
241 | if(ISync_BVList[itemIndex] and ISync_BVList[itemIndex].link) then |
||
242 | |||
243 | ISyncItemObj.storeID = ISync_BVList[itemIndex].link; |
||
244 | |||
245 | if(ISync_BVList[itemIndex].name) then |
||
246 | getglobal("ISync_BrowseButton"..iItem.."Name"):SetText(ISync_BVList[itemIndex].name); |
||
247 | end |
||
248 | |||
249 | --set color |
||
250 | local color = { }; |
||
251 | if(ISync_BVList[itemIndex].quality) then |
||
252 | color = ITEM_QUALITY_COLORS[tonumber(ISync_BVList[itemIndex].quality)]; |
||
253 | getglobal("ISync_BrowseButton"..iItem.."Name"):SetTextColor(color.r, color.g, color.b); |
||
254 | getglobal("ISync_BrowseButton"..iItem.."Name").r = color.r; |
||
255 | getglobal("ISync_BrowseButton"..iItem.."Name").g = color.g; |
||
256 | getglobal("ISync_BrowseButton"..iItem.."Name").b = color.b; |
||
257 | else |
||
258 | getglobal("ISync_BrowseButton"..iItem.."Name").r = 0; |
||
259 | getglobal("ISync_BrowseButton"..iItem.."Name").g = 0; |
||
260 | getglobal("ISync_BrowseButton"..iItem.."Name").b = 0; |
||
261 | end |
||
262 | |||
263 | |||
264 | local moneyFrame = getglobal("ISync_BrowseButton"..iItem.."MoneyFrame"); |
||
265 | |||
266 | --set price if available |
||
267 | if(ISync_BVList[itemIndex].money and moneyFrame) then |
||
268 | |||
269 | MoneyFrame_Update(moneyFrame:GetName(), ISync_BVList[itemIndex].money); |
||
270 | moneyFrame:Show(); |
||
271 | end |
||
272 | |||
273 | |||
274 | --set texture |
||
275 | if(ISync_BVList[itemIndex].texture) then |
||
276 | getglobal("ISync_BrowseButton"..iItem.."ItemIconTexture"):SetTexture(ISync_BVList[itemIndex].texture); |
||
277 | end |
||
278 | |||
279 | --show stacked items |
||
280 | if(ISync_BVList[itemIndex].count > 1 and ISync:SetVar({"BAGVIEW","SHOWSTACKED"}, 1, "COMPARE") == 1) then |
||
281 | getglobal("ISync_BrowseButton"..iItem.."ItemCount"):SetText(ISync_BVList[itemIndex].count); |
||
282 | getglobal("ISync_BrowseButton"..iItem.."ItemCount"):Show(); |
||
283 | |||
284 | --store the count |
||
285 | ISyncItemObj.storeCount = ISync_BVList[itemIndex].count; |
||
286 | |||
287 | else |
||
288 | getglobal("ISync_BrowseButton"..iItem.."ItemCount"):Hide(); |
||
289 | ISyncItemObj.storeCount = 1; --default |
||
290 | end |
||
291 | |||
292 | |||
293 | --store the item array in both the item bar and texture |
||
294 | ISyncItemObj.itemInfo = ISync_BVList[itemIndex]; |
||
295 | |||
296 | |||
297 | --show the item |
||
298 | ISyncItemObj:Show(); |
||
299 | |||
300 | else |
||
301 | --nothing to show then hide it |
||
302 | ISyncItemObj:Hide(); |
||
303 | |||
304 | |||
305 | end |
||
306 | |||
307 | else |
||
308 | --error occured hide it |
||
309 | ISyncItemObj:Hide(); |
||
310 | |||
311 | end |
||
312 | |||
313 | end --end for |
||
314 | |||
315 | |||
316 | end |
||
317 | |||
318 | |||
319 | |||
320 | -------------------------------------------------------------------------------------------------------------------------------- |
||
321 | -------------------------------------------------------------------------------------------------------------------------------- |
||
322 | -------------------------------------------------------------------------------------------------------------------------------- |
||
323 | -------------------------------------------------------------------------------------------------------------------------------- |
||
324 | -------------------------------------------------------------------------------------------------------------------------------- |
||
325 | -------------------------------------------------------------------------------------------------------------------------------- |
||
326 | |||
327 | |||
328 | --------------------------------------------------- |
||
329 | -- ISync:BV_ItemEnter() |
||
330 | --------------------------------------------------- |
||
331 | function ISync:BV_ItemEnter() |
||
332 | local iItem; |
||
333 | |||
334 | if(not ISyncDB) then return nil; end |
||
335 | if(not ISyncDB[ISYNC_REALM_NUM]) then return nil; end |
||
336 | |||
337 | local storeID; |
||
338 | local sFrame; |
||
339 | |||
340 | --get the item info |
||
341 | if(this.itemInfo) then |
||
342 | iItem = this.itemInfo; |
||
343 | storeID = this.storeID; |
||
344 | sFrame = this; |
||
345 | elseif(this:GetParent():GetName()) then |
||
346 | iItem = getglobal(this:GetParent():GetName()).itemInfo; |
||
347 | storeID = getglobal(this:GetParent():GetName()).storeID; |
||
348 | sFrame = getglobal(this:GetParent():GetName()); |
||
349 | else |
||
350 | return nil; |
||
351 | end |
||
352 | |||
353 | if(not iItem) then return; end |
||
354 | |||
355 | if(storeID) then |
||
356 | |||
357 | local name_X, link_X, quality_X, minLevel_X, class_X, subclass_X, maxStack_X = GetItemInfo("item:"..storeID); |
||
358 | |||
359 | if(link_X) then |
||
360 | |||
361 | --show the sell cursor |
||
362 | if(MerchantFrame:IsVisible() and not InRepairMode()) then |
||
363 | ShowContainerSellCursor(iItem.bag, iItem.slot); |
||
364 | elseif(not MerchantFrame:IsVisible() and InRepairMode()) then |
||
365 | ResetCursor(); |
||
366 | end |
||
367 | |||
368 | ISync_BV_Frame.TooltipButton = sFrame:GetID(); |
||
369 | GameTooltip:SetOwner(sFrame, "ANCHOR_RIGHT"); |
||
370 | GameTooltip:SetHyperlink(link_X); |
||
371 | |||
372 | --update the search information |
||
373 | ISync:Do_Parse(UIParent, ISyncTooltip, iItem.coreID, "item:"..storeID); |
||
374 | |||
375 | --check counter |
||
376 | if(ISync_AddTooltip and sFrame.storeCount) then |
||
377 | |||
378 | --update another mod if available |
||
379 | ISync:SendtoMods(GameTooltip, name_X, "item:"..storeID, sFrame.storeCount, quality_X); |
||
380 | ISync:AddTooltipInfo(GameTooltip, "item:"..storeID, sFrame.storeCount, 1); |
||
381 | else |
||
382 | --update another mod if available |
||
383 | ISync:SendtoMods(GameTooltip, name_X, "item:"..storeID, 1, quality_X); |
||
384 | ISync:AddTooltipInfo(GameTooltip, "item:"..storeID, 1, 1); |
||
385 | end |
||
386 | |||
387 | end |
||
388 | |||
389 | end--end |
||
390 | |||
391 | end |
||
392 | |||
393 | |||
394 | |||
395 | --------------------------------------------------- |
||
396 | -- ISync:BV_ItemClick() |
||
397 | --------------------------------------------------- |
||
398 | function ISync:BV_ItemClick(sButton) |
||
399 | local iItem; |
||
400 | |||
401 | if(not ISyncDB) then return nil; end |
||
402 | if(not ISyncDB[ISYNC_REALM_NUM]) then return nil; end |
||
403 | |||
404 | --get the item info |
||
405 | if(this.itemInfo) then |
||
406 | iItem = this.itemInfo; |
||
407 | elseif(this:GetParent():GetName()) then |
||
408 | iItem = getglobal(this:GetParent():GetName()).itemInfo; |
||
409 | else |
||
410 | iItem = nil; |
||
411 | end |
||
412 | |||
413 | if(not iItem) then return; end |
||
414 | |||
415 | --special thanks to Axu for the code :) Support for AxuItemMenus |
||
416 | if (AxuItemMenus_EvocationTest and AxuItemMenus_EvocationTest(sButton, "isync")) then |
||
417 | |||
418 | AxuItemMenus_FillFromLink(GetContainerItemLink(iItem.bag, iItem.slot)); |
||
419 | AxuItemMenus_OpenMenu(); |
||
420 | |||
421 | elseif sButton == "LeftButton" then |
||
422 | |||
423 | if IsShiftKeyDown() then |
||
424 | |||
425 | if ChatFrameEditBox:IsVisible() then |
||
426 | local link = GetContainerItemLink(iItem.bag, iItem.slot); |
||
427 | if link then ChatFrameEditBox:Insert(link); end |
||
428 | end |
||
429 | |||
430 | elseif( IsControlKeyDown()) then |
||
431 | |||
432 | DressUpItemLink(GetContainerItemLink(iItem.bag, iItem.slot)); |
||
433 | else |
||
434 | PickupContainerItem(iItem.bag, iItem.slot); |
||
435 | end |
||
436 | |||
437 | elseif sButton == "RightButton" then |
||
438 | UseContainerItem(iItem.bag, iItem.slot); |
||
439 | end |
||
440 | |||
441 | end |