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:
button:EnableMouse(true);-- Enable mouse events
button:SetScript("OnReceiveDrag",function(self)
local ctype,macroid,_,_,spellid=GetCursorInfo();-- Get cursor item info (arg2 has MacroID for macros, arg5 has SpellID for spells)
if not InCombatLockdown() and (ctype=="macro" or ctype=="spell") then-- Need to be out of combat to set attributes
-- Might want to visually indicate macro/spell has been set here
self:SetAttribute("type",ctype);
self:SetAttribute(ctype,ctype=="macro" and macroid or spellid);
ClearCursor();
end
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.