View Single Post
10-08-15, 11:23 PM   #11
Nikita S. Doroshenko
A Cyclonian
 
Nikita S. Doroshenko's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2015
Posts: 45
Thank you SDPhantom, semlar and Phanx, you saved my day, I very appreciate your help.
Thank you for this addition:
Originally Posted by Phanx View Post
Code:
local button=CreateFrame("Button", name, UIParent, "ActionButtonTemplate,SecureActionButtonTemplate")
Originally Posted by SDPhantom View Post
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);
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:
  1. local Offset=60
  2.         for i=0,(24*4)-1 do -- Written this way to make it easier to understand (Also zero-based indices to make math easier)
  3.             local key=(i%2==1 and "CTRL-" or "")..(i%4>1 and "SHIFT-" or "").."F"..(math.floor(i/4)+1);
  4.             --print(key)
  5.             local name="FunctionButton_"..key:gsub("%-","_");
  6.             local name = "FunctionButton_"..i
  7.             --print(name)
  8.             local button=CreateFrame("Button",name,UIParent,"ActionButtonTemplate, SecureActionButtonTemplate")
  9.             --button:SetSize(12,12)
  10.             if i == 0 then
  11.                 button:SetPoint("CENTER", UIParent, 0,0)
  12.             else
  13.                 button:SetPoint("CENTER", "FunctionButton_"..i-1, 0,48)
  14.             end
  15.             button:EnableMouse(true);-- Enable mouse events
  16.             button:SetScript("OnReceiveDrag",function(self)
  17.                 print("hi")
  18.                 local ctype,arg2,arg3,arg4=GetCursorInfo();--  Get cursor item info (arg2 has MacroID for macros, arg5 has SpellID for spells)
  19.                 if not InCombatLockdown() and (ctype=="macro" or ctype=="spell") then-- Need to be out of combat to set attributes
  20.                 --      Might want to visually indicate macro/spell has been set here
  21.  
  22.                     --self:SetAttribute("type",ctype);
  23.                     --self:SetAttribute(ctype,ctype=="macro" and macroid or spellid);
  24.                    
  25.                     local name, rank, icon, castTime, minRange, maxRange = GetSpellInfo(arg4)
  26.                
  27.                     print(ctype,arg2,arg3,arg4)
  28.                     print(ctype)
  29.                     print(spellid)
  30.                     print(name, icon)
  31.                     _G["FunctionButton_"..i.."Icon"]:SetTexture(icon)
  32.                     self:SetAttribute(name,ctype);
  33.                     button = SetBinding("CTRL-SHIFT-F1","SITORSTAND");
  34.                     button = SetBinding("CTRL-SHIFT-F2","SITORSTAND");
  35.                     -- ClearCursor(GetCursorInfo());
  36.                 end
  37.             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:
  1. 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:
  1. 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:
  1. key1, key2 = GetBinding(ADVANCEDLAYOUTBUTTON1ACTION1);
  2. -- return key1 = CTRL+F1
  3. -- return key2 = ALT+CTRL+F1
  4. FunctionButton_1 = SetBinding(key1,"SITORSTAND");
  5. FunctionButton_1 = SetBinding(key2,"SITORSTAND");
  6.  
  7. -- If i run this again key1, key2 = GetBinding(ADVANCEDLAYOUTBUTTON1ACTION1);
  8. -- 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.
  Reply With Quote