Thread Tools Display Modes
08-26-15, 10:56 AM   #1
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Question SetOverrideBindingClick and unnamed buttons

Was curious if it's possible to override a binding to an unnamed button, using the click method.

Here are the arguments:
SetOverrideBindingClick(owner, isPriority, "key", "buttonName" [, "mouseButton"])

Since it doesn't actually take a frame reference but rather the name of the frame that should be clicked, this causes problem in dynamic environments where the buttons don't have names. Examples are plenty, but to name a few: quest log entries, POIs on the world map, garrison plots, etc. These buttons are indeed clickable, but lack names due to being dynamically added.

My idea was to add global references to these buttons, since I was hoping that the function uses the global namespace to find the button objects, but that doesn't seem to be the case. Dumping the reference node once it's been assigned does return the button in question, but it does not work in the override function as a name replacement.
This code runs fine on all buttons that are named when created. Is it possible to name these buttons post-creation?

Here's the code I'm using that doesn't work:
Lua Code:
  1. local addOn, db = ...
  2.  
  3. local function AddReference(node)
  4.     local reference = addOn.."ReferenceNode"
  5.     _G[reference] = node
  6.     return reference
  7. end
  8.  
  9. local function EnterNode(self, node)
  10.     if node:IsEnabled() then
  11.         local name = node:GetName() or AddReference(node)
  12.         self:OverrideBindingClick(Cursor, "CP_R_RIGHT", name, "LeftButton")
  13.         self:OverrideBindingClick(Cursor, "CP_R_LEFT", name, "RightButton")
  14.         local enter = node:GetScript("OnEnter")
  15.         node:LockHighlight()
  16.         if enter then
  17.             enter(node)
  18.         end
  19.     end
  20. end
And here's the function wrapper that overrides the bindings:
Lua Code:
  1. function ConsolePort:OverrideBindingClick(owner, old, button, mouseClick)
  2.     if not InCombatLockdown() then
  3.         local key1, key2 = GetBindingKey(old)
  4.         if key1 then SetOverrideBindingClick(owner, true, key1, button, mouseClick) end
  5.         if key2 then SetOverrideBindingClick(owner, true, key2, button, mouseClick) end
  6.     end
  7. end

Edit: Adding image, demonstrating the issue.
__________________

Last edited by MunkDev : 08-26-15 at 06:29 PM. Reason: Added image for demonstration purpose
  Reply With Quote
08-26-15, 12:35 PM   #2
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Not sure about retroactively specifying names. I doubt it.

Maybe you could make your own secure button wrappers, and have them click the unnamed buttons. The clickbutton attribute should work with frame references.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
08-26-15, 12:54 PM   #3
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Originally Posted by Lombra View Post
Not sure about retroactively specifying names. I doubt it.

Maybe you could make your own secure button wrappers, and have them click the unnamed buttons. The clickbutton attribute should work with frame references.
Yup, this is what I do currently. The problem is the damn HybridScrollFrames. SecureActionButtonTemplate doesn't seem to send both key states to the clickbutton, regardless of specifying runOnUp="true" in bindings.xml or using btn:RegisterForClicks("LeftButtonUp", "LeftButtonDown") on a secure action button.

The clickbutton action only seems to run on button up, meaning the scroll buttons on HybridScrollFrames only receive the key release. A quick glance in game will show you that the scrolling happens when you press down on the buttons, not up. I also can't replace or mess with the functions provided by the templated HybridScrollFrame because it will taint things, such as the GlyphFrame.

Lua Code:
  1. function HybridScrollFrame_OnMouseWheel (self, delta, stepSize)
  2.     if ( not self.scrollBar:IsVisible() ) then
  3.         return;
  4.     end
  5.    
  6.     local minVal, maxVal = 0, self.range;
  7.     stepSize = stepSize or self.stepSize or self.buttonHeight;
  8.     if ( delta == 1 ) then
  9.         self.scrollBar:SetValue(max(minVal, self.scrollBar:GetValue() - stepSize));
  10.     else
  11.         self.scrollBar:SetValue(min(maxVal, self.scrollBar:GetValue() + stepSize));
  12.     end
  13. end
  14.  
  15. function HybridScrollFrameScrollButton_OnClick (self, button, down)
  16.     local parent = self.parent or self:GetParent():GetParent();
  17.    
  18.     if ( down ) then
  19.         self.timeSinceLast = (self.timeToStart or -0.2);
  20.         self:SetScript("OnUpdate", HybridScrollFrameScrollButton_OnUpdate);
  21.         HybridScrollFrame_OnMouseWheel (parent, self.direction);
  22.         PlaySound("UChatScrollButton");
  23.     else
  24.         self:SetScript("OnUpdate", nil);
  25.     end
  26. end
__________________

Last edited by MunkDev : 08-26-15 at 01:00 PM.
  Reply With Quote
08-26-15, 02:34 PM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,324
I'm not sure if it would work, but have you tried assigning a reference to the button to a global, then giving SetOverideBindingClick() the name of the global?
__________________
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)
  Reply With Quote
08-26-15, 06:02 PM   #5
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Originally Posted by SDPhantom View Post
I'm not sure if it would work, but have you tried assigning a reference to the button to a global, then giving SetOverideBindingClick() the name of the global?
I thought that's what I was attempting to do?

I thought that would work, too, but it fails silently. Even if it does technically work, the binding still does nothing as opposed to binding a named button.
__________________

Last edited by MunkDev : 08-26-15 at 06:10 PM.
  Reply With Quote
08-26-15, 06:41 PM   #6
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,324
You keep overwriting it, which might be what's messing up the binding. You need a unique global for each button.
__________________
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)
  Reply With Quote
08-26-15, 06:52 PM   #7
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Originally Posted by SDPhantom View Post
You keep overwriting it, which might be what's messing up the binding. You need a unique global for each button.
Tried adding an incremental integer at the end of the name, but to no avail. Using a compromise between overriding when it comes to scrollbuttons but using the clickbutton attribute sure works, but I'd rather make the override work since I won't have to fake up/down states with that.

Here's what that compromise looks like:
Lua Code:
  1. local function EnterNode(self, node)
  2.     if node:IsEnabled() then
  3.         local name = node:GetName() or AddReference(node)
  4.         -- randomly picked direction because it seems to uniquely exist on scrollbuttons
  5.         if node.direction then
  6.             self:OverrideBindingClick(Cursor, "CP_R_RIGHT", name, "LeftButton")
  7.             self:OverrideBindingClick(Cursor, "CP_R_LEFT", name, "RightButton")
  8.         else
  9.             self:SetClickButton(CP_R_RIGHT_NOMOD, node)
  10.             -- right click will never work on unnamed frames using this approach
  11.             self:OverrideBindingClick(Cursor, "CP_R_LEFT", name, "RightButton")
  12.         end
  13.         local enter = node:GetScript("OnEnter")
  14.         node:LockHighlight()
  15.         if enter then
  16.             enter(node)
  17.         end
  18.     else
  19.         self:SetClickButton(CP_R_RIGHT_NOMOD, doNothing)
  20.     end
  21. end
Lua Code:
  1. function ConsolePort:SetClickButton (button, clickbutton)
  2.     button:SetAttribute("type", "click")
  3.     button:SetAttribute("clickbutton", clickbutton)
  4. end
CP_R_RIGHT_NOMOD is a secure action button.
__________________

Last edited by MunkDev : 08-26-15 at 06:59 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » SetOverrideBindingClick and unnamed buttons


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