Thread Tools Display Modes
04-01-09, 03:00 PM   #1
kneeki
A Flamescale Wyrmkin
 
kneeki's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 134
Click and drag a spell from a custom button

by 'custom button' I mean:
Code:
local button = CreateFrame("Button", "GenericButtonName", UIParent, "SecureActionButtonTemplate, SecureHandlerDragTemplate")

-- Set the spell attributes on the button
button:SetAttribute("type", "spell")
button:SetAttribute("spell", theSpell)
button:RegisterForDrag("LeftButton", "RightButton")
button:EnableMouse(true)

-- ###################
-- SET THE BUTTONS TEXTURE
-- ###################				
local t = button:CreateTexture(nil, "BACKGROUND")
	t:SetTexture(GetSpellTexture(theSpell))
	t:SetAllPoints(button)
	button.IconFrameIcon = t
I excluded some of the OnEnter mouse over tool tip stuffs, but I'm sure ya'll get the idea. But my problem is when I would like to add the ability to Shift-Click & Drag the spell off the button, so it can be replaced. Now, the above button is a permanent thing, so it cannot be 'picked up', so to do it, I used the following:
Code:
button:SetScript("PreClick", function()
	-- For shift-clicking a spell off the bar
	if IsShiftKeyDown() then				
		if UnitAffectingCombat("player") then
			print("You cannot do that while in combat due to restrictions in the WoW UI.")
			return
		else
			PickupSpell(tostring(theSpell or ""))
		end
	end				
end)
Unfortunately, it does not work. Well, the picking up the spell part works, but if the above code is enabled, then the button loses it's click to cast ability. And is rendered to be just a square with a spell icon that can be picked up with a shift-click. Anyone with any experience to the above care to chime in what I'm doing wrong?
  Reply With Quote
04-01-09, 03:12 PM   #2
kneeki
A Flamescale Wyrmkin
 
kneeki's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 134
Got it working thanks to IRC!
Code:
-- Set the spell attributes on the button
button:SetAttribute("type", "spell")
button:SetAttribute("spell", theSpell)
button:RegisterForDrag("LeftButton", "RightButton")
button:RegisterForClicks("AnyUp")
button:EnableMouse(true)

-- ###################
-- SET THE BUTTONS TEXTURE
-- ###################				
local t = button:CreateTexture(nil, "BACKGROUND")
	t:SetTexture(GetSpellTexture(theSpell))
	t:SetAllPoints(button)
	button.IconFrameIcon = t

-- ############
-- Pickup spell to cursor
-- ############

button:SetScript("OnDragStart", function()
	-- For shift-clicking a spell off the bar
	-- Except, it works without clicking... Just hold Shift
	if IsShiftKeyDown() then				
		if InCombatLockdown() then
			print("You cannot do that while in combat due to restrictions in the WoW UI.")
			return
		else
			PickupSpell(tostring(theSpell or ""))
		end
	end				
end)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Click and drag a spell from a custom button


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off