my problem is that while my keyboard input works fine, my mouseinput doesnt. first i had the problem that all mouseclicks for example get posted twice, or better said, that the code concerning leftmouse-click is executed twice, which is, well, kinda stupid ^^
i noticed that if i simply returned true right after that code, the mouse-click-code only was executed once.
but now i have the problem that if i do it this way, all gui-events arent passed anymore. they only work if i take out that return true after my mouse-click-code. but then again, these events are processed twice, although i only clicked once for example.
maybe i'm missing something here? could someone post his mouse-handling eventcode here that works? or is it a bug in irrlicht.net? i cant find the solution here...
code:
Code: Select all
namespace Game.Events
{
/// <summary>
/// Takes care of all Irrlicht related events and forwards them, if needed, into the game engine.
/// </summary>
class IrrEventHandler : IEventReceiver
{
public bool OnEvent(Irrlicht.Event evt)
{
if (evt.Type == Irrlicht.EventType.GUIEvent)
{
if (evt.GUIEventType == Irrlicht.GUI.GUIEvent.BUTTON_CLICKED)
{
Console.WriteLine("buttonclicked, id: " + evt.GUIEventCaller.ID);
switch (evt.GUIEventCaller.ID)
{
// LeaveMission-Dialog - YES!
case 100:
EventManager.QueueEvent(new Evt_LeaveMission());
break;
case 101:
break;
}
}
}
// handle keyinput!
else if (evt.Type == Irrlicht.EventType.KeyInput)
{
if (evt.KeyPressedDown)
{
switch (evt.Key)
{
case KeyCode.KEY_RETURN:
EventManager.Trigger(new Evt_EntityCreated(new EvtData_EntityCreated(-1, EntityType.Environment_Static, new Vector3D())));
break;
case KeyCode.KEY_ESCAPE:
EventManager.QueueEvent(new Evt_ESCPressed());
break;
}
}
}
else if (evt.Type == Irrlicht.EventType.MouseInput)
{
switch (evt.MouseInputType)
{
case MouseInputEvent.PressedDownLeft:
Console.WriteLine("mouse pressed!");
// send the mouseclicked-event into the game engine event system
EventManager.QueueEvent(new Evt_MouseClicked(
new EvtData_MouseClicked(evt.MousePos)));
// entitySelection:
ISceneNode node = GameApplication.SceneMgr.SceneCollisionManager.GetSceneNodeFromScreenCoordinatesBB(evt.MousePos, 0, false);
if (node != null)
{
node.DebugDataVisible = !node.DebugDataVisible;
}
break;
case MouseInputEvent.MouseWheel:
if (GameApplication.Game.State == GameState.Running)
{
// update cam-position via wheel-movement
Vector3D camPos = GameApplication.Device.SceneManager.ActiveCamera.Position;
Vector3D camTarget = GameApplication.Device.SceneManager.ActiveCamera.Rotation;
camPos.Y += evt.MouseWheelDelta * 100.0f;
GameApplication.Device.SceneManager.ActiveCamera.Position = camPos;
}
break;
}
}
return false;
}
}
}