Thread Tools Display Modes
05/18/14, 08:43 AM   #1
Loaf
Join Date: May 2014
Posts: 4
Button right-click

Hi all, I am new to addon development and as a learning aid I am creating a simple addon to store and display some mail recipient favourites. Favs are added by editBox OnEnter and stored in addons savedVariables, then buttons are created dynamically when the addon is loaded. LMB sets the mail to: field and I would like RMB to remove the buttons associated savedVar field. I can not however get the UI to respond to RMB at all.

Have this to create buttons..

Code:
local function MA_CreateButtons()
	
	if MA_SavedVars.Count > 0 then
	
		for i = 1, MA_SavedVars.Count do
			
			local MA_BC = WinMan:CreateControlFromVirtual("MA_Button" .. i, MyAddonControl, "MA_ButtonTemplate", i)
					
			MA_BC:SetHandler("OnClicked", function(self,button)
				if button == 1 then
					ZO_MailSendToField:SetText(MA_SavedVars[i])
				elseif button == 2 then
					d("Right Clicked")
				end
			end)
			
			MA_BC:SetSimpleAnchorParent(10,10+(30*i))
			
			MA_BC:SetText(MA_SavedVars[i])
			
		end
	end
end
Tried OnMouseDown and with and without registering for EVENT_GLOBAL_MOUSE_DOWN. When registered every mouse down in game seemed to be captured and triggered an error.
Despite best search efforts I am coming up empty, any help would be mucho appreciated.

UPDATE: Thanks for the responses so far, most helpful. From d(self, button) it seems that buttons have no inherent right-click detection. Adding in EVENT_GLOBAL_MOUSE_DOWN this time didn't error everything out (assuming I made some error previously) and d() shows that button 2 fires, but obviously has no effect on the buttons I have made. I recall seeing a function on here somewhere that got the name of item beneath mouse.
Will have a further play around today and see where I get.

Last edited by Loaf : 05/19/14 at 12:42 AM. Reason: UPDATE:
  Reply With Quote
05/18/14, 10:40 AM   #2
zgrssd
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 280
Have you checked wich value button actually has when the event is called (via left or rightklick)?
Try just dumping it's value into the d() function:
Code:
MA_BC:SetHandler("OnClicked", function(self,button)
	d(self)
	d(button)
	if button == 1 then
		ZO_MailSendToField:SetText(MA_SavedVars[i])
	elseif button == 2 then
		d("Right Clicked")
	end
end)
Either there is no rightclick detection at all (the design is aimed at a console port) or the ID of the button is just very differently from what you expect.
  Reply With Quote
05/18/14, 10:41 AM   #3
Tar000un
 
Tar000un's Avatar
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 47
Perhaps you should have a look to the "OnKeyDown" xml event.
I m new too and that's how i ve planed to add a key binded on my addon. ^^'

Last edited by Tar000un : 05/18/14 at 10:45 AM.
  Reply With Quote
05/18/14, 11:19 AM   #4
zgrssd
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 280
Originally Posted by Tar000un View Post
Perhaps you should have a look to the "OnKeyDown" xml event.
I m new too and that's how i ve planed to add a key binded on my addon. ^^'
True. "Clicked" always what righthanders would call a leftclick.
It is easy to switch the mousbuttons meaning around in Windows. So that leftclick opens the context menues and rightlick fires the "Clicked" events. That way lefthanders just have to change one setting in Windows and can work normally.

Knowing the button might not be that helpfull. You need the meaning of the button based on local UI layout. Try to find a "Rightclicked "or maybe "Context Menu" related event. It is better then trying to parse those things manually.
Those events would also cover odd cases (like the user hitting the old Context Menu button instead of the right/left mouse button as normal).
  Reply With Quote
05/18/14, 02:47 PM   #5
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
Originally Posted by zgrssd View Post
Code:
	d(self)
	d(button)
By the way, you can just do
Lua Code:
  1. d(self, button)
  Reply With Quote
05/18/14, 03:37 PM   #6
katkat42
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 155
Originally Posted by zgrssd View Post
True. "Clicked" always what righthanders would call a leftclick.
It is easy to switch the mousbuttons meaning around in Windows. So that leftclick opens the context menues and rightlick fires the "Clicked" events. That way lefthanders just have to change one setting in Windows and can work normally.
THANK YOU for understanding this simple concept, unlike, say, the people at Bethesda Softworks! I have to adjust the way I hold the mouse whenever I play Morrowind, Oblivion, or Skyrim!
  Reply With Quote
05/19/14, 05:27 AM   #7
Loaf
Join Date: May 2014
Posts: 4
Update 2: HALP PLS! :D

As the button wasn't inherently supporting RMB, tried adding registration for EVENT_GLOBAL_MOUSE_DOWN and a function to handle the event. Seems that the function fires even when the addon main window is hidden.
I toggle hidden by parenting addon to ZO_MailSend when addon is loaded, thought that would mean that when the ZO_MailSend window is hidden my addon would not be listening for any events firing. Anyone can shed some light on the reason for this?

Maybe I need to rethink my design?

The only thing I am really missing at the minute is the ability to simply remove a single entry from the favourites list. Clear button works, but as you can see in the picture I tried a reloadUI via /rl and as the editBox had focus I added /rl to favourites list meaning it made a button so I could send rl a mail. Removal without clearing all is needed. How would you guys go about that generally?
  Reply With Quote
05/19/14, 06:17 AM   #8
Loaf
Join Date: May 2014
Posts: 4
Update 3:

Ok so after playing about a bit further I got right-click to work by adding the code below to the dynamic buttons virtual XML template which meant I could scrap the use of EVENT_GLOBAL_MOUSE_DOWN.
Code:
<MouseButton button="2" enabled="true"/>
Now the button does respond to RMB and I managed to alter the CreateButtons function so the associated savedVariable is removed.

One final question though (for now :P ), is it possible to have the dynamic buttons update without a /reloadUI or relog? to reflect the changes.
  Reply With Quote
05/19/14, 09:13 AM   #9
Tar000un
 
Tar000un's Avatar
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 47
Like a Element:SetText(), you can update an attribute with a function on event.
  Reply With Quote
05/19/14, 12:53 PM   #10
katkat42
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 155
Originally Posted by Loaf View Post
As the button wasn't inherently supporting RMB, tried adding registration for EVENT_GLOBAL_MOUSE_DOWN and a function to handle the event. Seems that the function fires even when the addon main window is hidden.
I toggle hidden by parenting addon to ZO_MailSend when addon is loaded, thought that would mean that when the ZO_MailSend window is hidden my addon would not be listening for any events firing. Anyone can shed some light on the reason for this?
I know you said you resolved this using another method, but I figure I might as well shed some light anyway, for future reference.

Yes, when you register for an event, your callback will run every time the event fires. You can, however, register your callback to the event when ZO_MailSend opens, and unregister it when ZO_MailSend closes. I use this trick in Feed An Army, because I only need to know when a Provisioning item is finished crafting, not any other type of item. So I register for EVENT_CRAFT_COMPLETE when the provisioning window opens, and unregister when the provisioning window closes.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Button right-click


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