View Single Post
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