Mercurial > wow > reagentmaker
comparison SecureMenu.lua @ 34:0af9cb8a79f0
Manage items not ready (not in cache ?) when opening the external frame. Can potentially conflict with BAG_UPDATE event.
author | contrebasse |
---|---|
date | Fri, 29 Apr 2011 21:26:19 +0200 |
parents | 218e1dd1b821 |
children | 5394c492850e |
comparison
equal
deleted
inserted
replaced
33:218e1dd1b821 | 34:0af9cb8a79f0 |
---|---|
1 local addonName, A = ... | 1 local addonName, A = ... |
2 | 2 |
3 -- Create the menu frame | 3 -- Create the menu frame |
4 local MenuFrame = CreateFrame("Frame","ReagentMaker_ExternalFrame",UIParent) --, "ReagentMakerDropDownMenu"); -- Needs a global name ? | 4 local MenuFrame = CreateFrame("Frame","ReagentMaker_ExternalFrame",UIParent) |
5 MenuFrame:Hide() | 5 MenuFrame:Hide() |
6 MenuFrame:SetSize(192,256) | 6 MenuFrame:SetSize(192,256) |
7 MenuFrame:SetFrameStrata("DIALOG") | 7 MenuFrame:SetFrameStrata("DIALOG") |
8 MenuFrame:EnableMouse(true) | 8 MenuFrame:EnableMouse(true) |
9 MenuFrame:SetPoint("CENTER") | 9 MenuFrame:SetPoint("CENTER") |
231 else | 231 else |
232 btn = menuEntries[numActiveEntries+1] | 232 btn = menuEntries[numActiveEntries+1] |
233 end | 233 end |
234 | 234 |
235 -- Set text and icon | 235 -- Set text and icon |
236 local name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(reagent[1]) | 236 local name, _, _, _, _, _, _, _, _, texture = GetItemInfo(reagent[1]) |
237 if name then | 237 if name then |
238 btn.itemName:SetText(name) | 238 btn.itemName:SetText(name) |
239 else | 239 else |
240 A.DEBUG("No item name : "..reagent[1]) | 240 --A.DEBUG("No item name : "..reagent[1]) |
241 return | 241 return |
242 end | 242 end |
243 | 243 |
244 if texture then | 244 if texture then |
245 btn.icon:SetTexture(texture) | 245 btn.icon:SetTexture(texture) |
246 else | 246 else |
247 A.DEBUG("No item texture : "..reagent[1]) | 247 --A.DEBUG("No item texture : "..reagent[1]) |
248 return | 248 return |
249 end | 249 end |
250 | 250 |
251 -- Set chance to have the item or the number of items created | 251 -- Set chance to have the item or the number of items created |
252 if reagent[3] then | 252 if reagent[3] then |
279 | 279 |
280 btn:Show() | 280 btn:Show() |
281 | 281 |
282 -- Increase the entry number | 282 -- Increase the entry number |
283 numActiveEntries = numActiveEntries + 1 | 283 numActiveEntries = numActiveEntries + 1 |
284 | |
285 -- Everything went well | |
286 return true | |
284 end -- function | 287 end -- function |
288 | |
289 -- Function used on OnUpdate tu update the frame if there were errors the previous time | |
290 local function reopen() | |
291 -- Release OnUpdate frame (could conflict with BAG_UPDATE) | |
292 MenuFrame:SetScript("OnUpdate",nil) | |
293 | |
294 -- reopen | |
295 A.externalCraftWindow(MenuFrame.itemID,MenuFrame.superItemID) | |
296 end | |
285 | 297 |
286 -- Fill the window and open it | 298 -- Fill the window and open it |
287 function A.externalCraftWindow(itemID,superItemID) | 299 function A.externalCraftWindow(itemID,superItemID) |
288 -- Do not open during combat | 300 -- Do not open during combat |
289 if InCombatLockdown() then return end | 301 if InCombatLockdown() then return end |
297 menuEntries[i]:Hide() | 309 menuEntries[i]:Hide() |
298 end | 310 end |
299 numActiveEntries = 0 | 311 numActiveEntries = 0 |
300 | 312 |
301 -- Fill the info of the reagent to make | 313 -- Fill the info of the reagent to make |
302 local name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(itemID) | 314 local name, _, quality, _, _, _, _, _, _, texture = GetItemInfo(itemID) |
303 SetPortraitToTexture(itemIcon, texture) | 315 SetPortraitToTexture(itemIcon, texture) |
304 TitleText:SetText(name) | 316 TitleText:SetText(name) |
305 local color = ITEM_QUALITY_COLORS[quality] | 317 local color = ITEM_QUALITY_COLORS[quality] |
306 TitleText:SetTextColor(color.r, color.g, color.b) | 318 TitleText:SetTextColor(color.r, color.g, color.b) |
307 | 319 |
308 -- Save vars to show the tooltip later | 320 -- Save vars to show the tooltip later |
309 MenuFrame.reagentLink = link | 321 MenuFrame.reagentLink = link |
310 MenuFrame.spellLink = A.data[itemID].spellLink | 322 MenuFrame.spellLink = A.data[itemID].spellLink |
311 MenuFrame.itemID = itemID | 323 MenuFrame.itemID = itemID |
312 MenuFrame.superItemID = superItemID -- optional | 324 MenuFrame.superItemID = superItemID -- optional |
313 | 325 |
314 -- Loop over the available recipes | 326 -- Loop over the available recipes |
327 MenuFrame.state = true | |
315 for _,reagent in ipairs(A.data[itemID]) do | 328 for _,reagent in ipairs(A.data[itemID]) do |
316 if A.data[itemID].spell then | 329 if A.data[itemID].spell then |
317 -- Special spell | 330 -- Special spell |
318 menuAddItem(A.data[itemID].spell,itemID,reagent,A.data[itemID].spellLink) | 331 MenuFrame.state = menuAddItem(A.data[itemID].spell,itemID,reagent,A.data[itemID].spellLink) and state |
319 else | 332 else |
320 -- Standard tradeskill spell UNTESTED | 333 -- Standard tradeskill spell UNTESTED |
321 menuAddItem(A.craft,itemID,reagent) | 334 MenuFrame.state = menuAddItem(A.craft,itemID,reagent) and state |
322 end -- if | 335 end -- if |
323 end -- for | 336 end -- for |
324 | 337 |
325 MenuFrame:SetHeight(89 + numActiveEntries*(MENU_ENTRY_HEIGHT+2)) | 338 MenuFrame:SetHeight(89 + numActiveEntries*(MENU_ENTRY_HEIGHT+2)) |
326 | 339 |
328 MenuFrame:SetPoint("TOPLEFT",TradeSkillFrame,"TOPRIGHT",-2,14) | 341 MenuFrame:SetPoint("TOPLEFT",TradeSkillFrame,"TOPRIGHT",-2,14) |
329 | 342 |
330 MenuFrame.updateCounts() | 343 MenuFrame.updateCounts() |
331 | 344 |
332 MenuFrame:Show() | 345 MenuFrame:Show() |
333 end | 346 |
347 if not MenuFrame.state then | |
348 MenuFrame:SetScript("OnUpdate",reopen) | |
349 end | |
350 end |