Thank you
SDPhantom,
semlar and
Phanx, you saved my day, I very appreciate your help.
Thank you for this addition:
Originally Posted by Phanx
Code:
local button=CreateFrame("Button", name, UIParent, "ActionButtonTemplate,SecureActionButtonTemplate")
|
Originally Posted by SDPhantom
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);
|
Unfortunately I was not able to
GetCursorInfo() with
"OnReceiveDrag", nothing was happening, and SetScript code never executed at all, then I changed
"OnReceiveDrag" to
"OnClick", and it started to works, I read about this handler
here:
"OnReceiveDrag"
Called whenever the user has released the cursor over the frame while dragging something.
The widget must be mouse-enabled to receive drag events.
You can use GetCursorInfo to find out whether it was an item, spell, macro, or amount of money, and the specifics thereof.
The cursor is not automatically cleared; call ClearCursor if that behaviour is desired.
The handler also fires when dragging widgets onto other widgets, in which case GetCursorInfo provides no relevant information.
|
So I don't know why
"OnReceiveDrag" not working, this is code example that I used, it's very-very messy, it's just for testing:
Lua Code:
local Offset=60
for i=0,(24*4)-1 do -- Written this way to make it easier to understand (Also zero-based indices to make math easier)
local key=(i%2==1 and "CTRL-" or "")..(i%4>1 and "SHIFT-" or "").."F"..(math.floor(i/4)+1);
--print(key)
local name="FunctionButton_"..key:gsub("%-","_");
local name = "FunctionButton_"..i
--print(name)
local button=CreateFrame("Button",name,UIParent,"ActionButtonTemplate, SecureActionButtonTemplate")
--button:SetSize(12,12)
if i == 0 then
button:SetPoint("CENTER", UIParent, 0,0)
else
button:SetPoint("CENTER", "FunctionButton_"..i-1, 0,48)
end
button:EnableMouse(true);-- Enable mouse events
button:SetScript("OnReceiveDrag",function(self)
print("hi")
local ctype,arg2,arg3,arg4=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);
local name, rank, icon, castTime, minRange, maxRange = GetSpellInfo(arg4)
print(ctype,arg2,arg3,arg4)
print(ctype)
print(spellid)
print(name, icon)
_G["FunctionButton_"..i.."Icon"]:SetTexture(icon)
self:SetAttribute(name,ctype);
button = SetBinding("CTRL-SHIFT-F1","SITORSTAND");
button = SetBinding("CTRL-SHIFT-F2","SITORSTAND");
-- ClearCursor(GetCursorInfo());
end
end)
With "OnReceiveDrag" nothing works, but if I change it to "OnClick" everything works, it would be nice to know why it's so, I was not able to understand why it's not working.
Also i changed:
Lua Code:
local ctype,macroid,_,_,spellid=GetCursorInfo();
in to this, according to
this source, because it looks like now this function return only 4 arguments.
Lua Code:
local ctype, data, subType, subData = GetCursorInfo()
I got one more thing that I can't figure out by myself, it's about binding. I would like to use bindings.xml with my AddOn, to control Binding keys with Blizzards UI. (I know that i can build my own binding UI or make binding with lua another way, but i would like to make this happen with Blizzards binding UI window)
So I build a file bindings.xml:
Code:
<Bindings>
<Binding name="ADVANCEDLAYOUTBUTTON1ACTION1" runOnUp="true" category="BINDING_HEADER_TEST">
</Binding>
<Binding name="ADVANCEDLAYOUTBUTTON1ACTION2" runOnUp="true" category="BINDING_HEADER_TEST">
</Binding>
<Binding name="ADVANCEDLAYOUTBUTTON1ACTION3" runOnUp="true" category="BINDING_HEADER_TEST">
</Binding>
<Binding name="ADVANCEDLAYOUTBUTTON1ACTION4" runOnUp="true" category="BINDING_HEADER_TEST">
</Binding>
<Binding name="ADVANCEDLAYOUTBUTTON2ACTION1" runOnUp="true" header="BLANK" category="BINDING_HEADER_TEST">
</Binding>
<Binding name="ADVANCEDLAYOUTBUTTON2ACTION2" runOnUp="true" category="BINDING_HEADER_TEST">
</Binding>
<Binding name="ADVANCEDLAYOUTBUTTON2ACTION3" runOnUp="true" category="BINDING_HEADER_TEST">
</Binding>
<Binding name="ADVANCEDLAYOUTBUTTON2ACTION4" runOnUp="true" category="BINDING_HEADER_TEST">
</Binding>
and so on...
</Bindings>
And I would like my button names to be linked with this bindings. For example, button with frame name: "FunctionButton_1" linked to ADVANCEDLAYOUTBUTTON1ACTION1.
ADVANCEDLAYOUTBUTTON1ACTION1 got for example 2 keys: CTRL+F1 and ALT+CTRL+F1
So i think the code should looks like this:
Lua Code:
key1, key2 = GetBinding(ADVANCEDLAYOUTBUTTON1ACTION1);
-- return key1 = CTRL+F1
-- return key2 = ALT+CTRL+F1
FunctionButton_1 = SetBinding(key1,"SITORSTAND");
FunctionButton_1 = SetBinding(key2,"SITORSTAND");
-- If i run this again key1, key2 = GetBinding(ADVANCEDLAYOUTBUTTON1ACTION1);
-- key1,key2 will be nil (this is problem)
And I tested, this code works, but when I apply binding to FunctionButton_1, then if i open Blizzard's BindingUI, and look to ADVANCEDLAYOUTBUTTON1ACTION1 binding, it's empty, so if i run this code again, key1 and key2 for ADVANCEDLAYOUTBUTTON1ACTION1 will be nil,nil.
Looks like I got problem with logic and doing something wrong, could you please point me.