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...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

472 Part III ■ Advanced Addon Techniqueslocal blessings = BlessedMenu(“BlessedMenusBlessings“,“Blessing <strong>of</strong> Might“,“Blessing <strong>of</strong> Kings“,“Blessing <strong>of</strong> Wisdom“)Now that you’ve defined the menus, it’s time to start preparing the codethat will drive the secure behaviors. Add the following:local openSpellList = [[local menu = IsAltKeyDown() <strong>and</strong> “blessings“or IsControlKeyDown() <strong>and</strong> “heals“or IsShiftKeyDown() <strong>and</strong> “h<strong>and</strong>s“menu = menu <strong>and</strong> self:GetFrameRef(menu)if menu <strong>and</strong> menu:IsShown() <strong>and</strong> menu:GetParent() == self thenmenu:Hide()returnendif menu thenmenu:Hide()menu:SetParent(self)menu:SetPoint(“TOPLEFT“, “$cursor“)menu:SetFrameLevel(self:GetFrameLevel() + 2)menu:Show()end]]This is the snippet code that the party <strong>and</strong> player buttons will run whenclicked with certain modifiers, which you add in a moment. It uses in<strong>for</strong>mationabout the current modifiers to determine which frame reference to retrieve<strong>and</strong> open. If that menu is already open on the unit frame in question, it hidesit <strong>and</strong> takes no further action; if the menu is not open (hidden), or is open onanother unit frame, it is re-parented to the frame that was clicked, making sureit appears above the frame clicked, <strong>and</strong> opened. It is also moved to appearby the point clicked, using an arguments to SetPoint(), $cursor, thatplacesthe point anchored by the mouse’s current location (it will not automaticallyfollow the mouse). But <strong>of</strong> course, the code will never run unless it is attachedto some frames; add the load-time code to do so just after the snippet:<strong>for</strong> i, frame in ipairs{PlayerFrame, PartyMemberFrame1, iPartyMemberFrame2, PartyMemberFrame3, PartyMemberFrame4} d<strong>of</strong>rame:SetAttribute(“shift-type1“, “spelllist“)frame:SetAttribute(“ctrl-type1“, “spelllist“)frame:SetAttribute(“alt-type1“, “spelllist“)frame:SetAttribute(“_spelllist“, openSpellList)SecureH<strong>and</strong>lerSetFrameRef(frame, “blessings“, BlessedMenusBlessings)SecureH<strong>and</strong>lerSetFrameRef(frame, “heals“, BlessedMenusHeals)SecureH<strong>and</strong>lerSetFrameRef(frame, “h<strong>and</strong>s“, BlessedMenusH<strong>and</strong>s)end

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

Saved successfully!

Ooh no, something went wrong!