12.07.2015 Views

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 13 ■ Responding to Game Events 253event. Although the reasons <strong>for</strong> this weren’t discussed in the previous section,that is why initialization is delayed until ADDON_LOADED.Using Items from BagBuddyFinding items in your inventory is great, but it would be nicer to be able toclick to use them once you’ve found them. This can be accomplished usingsecure templates, which are discussed in Chapter 15. For now, you can make thefollowing changes to your code to enable that functionality.In BagBuddy_OnLoad(), change the loop that creates item slots to register <strong>for</strong>right-clicks (change is highlighted):-- Create the item slotsself.items = {}<strong>for</strong> idx = 1, 24 dolocal item = CreateFrame(“Button“, “BagBuddy_Item“ .. idx, self, i“BagBuddyItemTemplate“)item:RegisterForClicks(“RightButtonUp“)self.items[idx] = itemif idx == 1 thenitem:SetPoint(“TOPLEFT“, 40, -73)elseif idx == 7 or idx == 13 or idx == 19 thenitem:SetPoint(“TOPLEFT“, self.items[idx-6], “BOTTOMLEFT“, 0, -7)elseitem:SetPoint(“TOPLEFT“, self.items[idx-1], “TOPRIGHT“, 12, 0)endendIn BagBuddy_Update(), add the following highlighted line in the conditionalthat indicates there is an item in the slot. This sets the button up to use thenamed item when it is right-clicked.if entry then-- There is an item in this slotbutton:SetAttribute(“item2“, entry.name)button.link = entry.linkbutton.icon:SetTexture(entry.texture)The last two changes must be made in BagBuddy.xml. First, change theopening tag <strong>for</strong> BagBuddyItemTemplate from

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!