This is a bug in the Turbine.UI.Lotro.TextBox class. Mouse events are being handled by the control and are not passed on to Lua. In fact, if you use SetMouseVisible(false) on a Turbine.UI.Lotro.TextBox, the mouse events do not pass through the control either making it impossible to handle mouse events other than MouseEnter and MouseLeave with a Turbine.UI.Lotro.TextBox. One possible workaround is to put a transparent text control (it has to be a textbox to get and pass on focus) in front of the textbox and use the :FocusGained event to set focus to the textbox effectively allowing you to catch mouse events.
Consider the sample below with three textboxes, the standard Turbine.UI.TextBox, a Turbine.UI.Lotro.TextBox (demonstrating the bug) and a Turbine.UI.Lotro.TextBox with a mouse masking Turbine.UI.TextBox showing the work around. If you execute the code, you will see that the third textbox displays exactly as you desire as well as handling mouse events.
Code:
testWindow=Turbine.UI.Lotro.Window()
testWindow:SetSize(300,175)
testWindow:SetPosition(0,0)
testWindow:SetZOrder(1)
testWindow:SetVisible(true)
label1=Turbine.UI.Label()
label1:SetParent(testWindow)
label1:SetSize(100,25)
label1:SetPosition(10,45)
label1:SetText("Box 1:")
testBox1=Turbine.UI.TextBox()
testBox1:SetParent(testWindow)
testBox1:SetSize(175,25)
testBox1:SetPosition(115,45)
testBox1:SetText("test box 1")
label2=Turbine.UI.Label()
label2:SetParent(testWindow)
label2:SetSize(100,25)
label2:SetPosition(10,75)
label2:SetText("Box 2:")
testBox2=Turbine.UI.Lotro.TextBox()
testBox2:SetParent(testWindow)
testBox2:SetSize(175,25)
testBox2:SetPosition(115,75)
testBox2:SetText("test box 2")
label3=Turbine.UI.Label()
label3:SetParent(testWindow)
label3:SetSize(100,25)
label3:SetPosition(10,105)
label3:SetText("Box 3:")
testBox3=Turbine.UI.Lotro.TextBox()
testBox3:SetParent(testWindow)
testBox3:SetSize(175,25)
testBox3:SetPosition(115,105)
testBox3:SetText("test box 3")
testBox3:SetMouseVisible(false)
testBox3Mouse=Turbine.UI.TextBox()
testBox3Mouse:SetParent(testWindow)
testBox3Mouse:SetSize(175,25)
testBox3Mouse:SetPosition(115,105)
testBox3Mouse.FocusGained=function(sender,args)
testBox3:Focus(testBox3,args)
end
-- box 1 mouse events
testBox1.MouseEnter=function(sender,args)
Turbine.Shell.WriteLine("test 1 mouse enter")
end
testBox1.MouseDown=function(sender,args)
Turbine.Shell.WriteLine("test 1 mouse down")
end
testBox1.MouseUp=function(sender,args)
Turbine.Shell.WriteLine("test 1 mouse up")
end
testBox1.MouseLeave=function()
Turbine.Shell.WriteLine("test 1 mouse leave")
end
-- box 2 mouse events
testBox2.MouseEnter=function(sender,args)
Turbine.Shell.WriteLine("test 2 mouse enter")
end
testBox2.MouseDown=function(sender,args)
Turbine.Shell.WriteLine("test 2 mouse down")
end
testBox2.MouseUp=function(sender,args)
Turbine.Shell.WriteLine("test 2 mouse up")
end
testBox2.MouseLeave=function()
Turbine.Shell.WriteLine("test 2 mouse leave")
end
testBox2.MouseMove=function()
Turbine.Shell.WriteLine("test 2 mouse move")
end
-- box3mouse events that are then sent to box 3
testBox3Mouse.MouseEnter=function(sender,args)
testBox3.MouseEnter(testBox3,args)
end
testBox3Mouse.MouseDown=function(sender,args)
testBox3.MouseDown(testBox3,args)
end
testBox3Mouse.MouseUp=function(sender,args)
testBox3.MouseUp(testBox3,args)
end
testBox3Mouse.MouseLeave=function(sender,args)
testBox3.MouseLeave(testBox3,args)
end
testBox3Mouse.MouseMove=function(sender,args)
testBox3.MouseMove(testBox3,args)
end
-- actual box 3 events
testBox3.MouseEnter=function(sender,args)
Turbine.Shell.WriteLine("test 3 mouse enter")
end
testBox3.MouseDown=function(sender,args)
Turbine.Shell.WriteLine("test 3 mouse down")
end
testBox3.MouseUp=function(sender,args)
Turbine.Shell.WriteLine("test 3 mouse up")
end
testBox3.MouseLeave=function(sender,args)
Turbine.Shell.WriteLine("test 3 mouse leave")
end
testBox3.MouseMove=function(sender,args)
Turbine.Shell.WriteLine("test 3 mouse move (args.X:"..tostring(args.X)..")")
end
The testBox3Mouse control exists solely to handle mouse events and to pass focus to the underlying testBox3 control.
When dissecting the code, pay close attention to how the mouse events are captured and passed on, specifically the difference in the "." and ":" calling conventions. For example, in the MouseDown handler for the masking textbox,
Code:
testBox3Mouse.MouseDown=function(sender,args)
testBox3.MouseDown(testBox3,args)
end
the underlying control's MouseDown event is fired using the "." convention since we pass the underlying control as the "source" of the event to mask the fact that it is actually handled by our mask. You could simply handle the event in the mask without calling the underlying control's event handler but I wanted to show an example of how to make the underlying control function as it should.
FWIW, the seemingly extraneous "MouseLeave" and "MouseEnter" events that occur on right clicking happen on both types of control and seem to be tied to the fact that while the right mouse is down, control reverts to moving the character so effectively the mouse has left your control and is interacting with the game UI and is then returned to your control once you lift the right mouse button.