View Single Post
10-06-15, 09:02 PM   #7
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
I'm assuming you know about setting anchors, size, and textures to make your buttons visible at the very least. After taking care of that, you need to make sure the button can receive mouse events by calling button:EnableMouse(true). Next, you need to register a function to the button's OnReceiveDrag handler. From there, you need to check GetCursorInfo() for what the cursor is holding. Be sure to use ClearCursor() to reset the cursor if you applied the item dragged on the button.

Lua Code:
  1. button:EnableMouse(true);-- Enable mouse events
  2. button:SetScript("OnReceiveDrag",function(self)
  3.     local ctype,macroid,_,_,spellid=GetCursorInfo();--  Get cursor item info (arg2 has MacroID for macros, arg5 has SpellID for spells)
  4.     if not InCombatLockdown() and (ctype=="macro" or ctype=="spell") then-- Need to be out of combat to set attributes
  5. --      Might want to visually indicate macro/spell has been set here
  6.  
  7.         self:SetAttribute("type",ctype);
  8.         self:SetAttribute(ctype,ctype=="macro" and macroid or spellid);
  9.         ClearCursor();
  10.     end
  11. end);
Note: If you plan on applying this handler to many buttons, you may want to define the function elsewhere as a local and give button:SetScript() a reference to it. This means you'll have only one function in memory instead of 96 copies of it.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 10-06-15 at 09:24 PM.
  Reply With Quote