bool ProcessInputMessageBefore(UIControl playScreen, InputMessage message) { //input enabled changed { var m = message as InputMessageInputEnabledChanged; if (m != null) { inputEnabled = m.Value; } } //key down { var m = message as InputMessageKeyDown; if (m != null) { //lock( lockerKeysMouse ) //{ if (keys == null) { keys = new bool[GetEKeysMaxIndex() + 1]; } keys[(int)m.Key] = true; //} } } //key up { var m = message as InputMessageKeyUp; if (m != null) { //lock( lockerKeysMouse ) //{ if (keys == null) { keys = new bool[GetEKeysMaxIndex() + 1]; } if (keys[(int)m.Key]) { keys[(int)m.Key] = false; } //} } } //mouse button down { var m = message as InputMessageMouseButtonDown; if (m != null) { //lock( lockerKeysMouse ) //{ mouseButtons[(int)m.Button] = true; //} } } //mouse button up { var m = message as InputMessageMouseButtonUp; if (m != null) { //lock( lockerKeysMouse ) //{ mouseButtons[(int)m.Button] = false; //} } } //mouse move { var m = message as InputMessageMouseMove; if (m != null) { //lock( lockerKeysMouse ) //{ mousePosition = m.Position; //} } } //mouse relative mode { var m = message as InputMessageMouseRelativeModeChanged; if (m != null) { mouseRelativeMode = m.Value; } } var keyDown = message as InputMessageKeyDown; if (keyDown != null && FreeCameraHotKey && FreeCameraHotKeyValue.Value == keyDown.Key) { //all keys and mouse buttons up var viewport = playScreen.ParentContainer.Viewport; viewport.KeysAndMouseButtonUpAll(); //change free camera FreeCamera = !FreeCamera; //show screen message if (FreeCamera) { ScreenMessages.Add($"Free camera is activated."); } else { ScreenMessages.Add($"Free camera is deactivated."); } return(true); } var mouseDown = message as InputMessageMouseButtonDown; if (mouseDown != null) { //free camera rotating if (mouseDown.Button == EMouseButtons.Right && FreeCamera) { freeCameraMouseRotating = true; freeCameraMouseRotatingActivated = false; freeCameraRotatingStartPos = MousePosition; } } var mouseUp = message as InputMessageMouseButtonUp; if (mouseUp != null) { //free camera rotating if (mouseUp.Button == EMouseButtons.Right && freeCameraMouseRotating) { var viewport = playScreen.ParentContainer.Viewport; //viewport.MouseRelativeMode = false; freeCameraMouseRotating = false; freeCameraMouseRotatingActivated = false; } } var mouseMove = message as InputMessageMouseMove; if (mouseMove != null) { //free camera rotating if (FreeCamera && freeCameraMouseRotating) { var viewport = playScreen.ParentContainer.Viewport; if (!viewport.MouseRelativeMode) { var diffPixels = (MousePosition - freeCameraRotatingStartPos) * viewport.SizeInPixels.ToVector2(); if (Math.Abs(diffPixels.X) >= 3 || Math.Abs(diffPixels.Y) >= 3) { freeCameraMouseRotatingActivated = true; //viewport.MouseRelativeMode = true; } } else { var dir = freeCameraDirection; dir.Horizontal -= MousePosition.X; // * cameraRotateSensitivity; dir.Vertical -= MousePosition.Y; // * cameraRotateSensitivity; dir.Horizontal = MathEx.RadianNormalize360(dir.Horizontal); const double vlimit = Math.PI / 2 - .01f; if (dir.Vertical > vlimit) { dir.Vertical = vlimit; } if (dir.Vertical < -vlimit) { dir.Vertical = -vlimit; } freeCameraDirection = dir; } } } if (FreeCamera && !EngineConsole.Active && InputEnabled) { //key down { var m = message as InputMessageKeyDown; if (m != null) { if (m.Key == EKeys.W || m.Key == EKeys.Up || m.Key == EKeys.S || m.Key == EKeys.Down || m.Key == EKeys.A || m.Key == EKeys.Left || m.Key == EKeys.D || m.Key == EKeys.Right || m.Key == EKeys.E || m.Key == EKeys.Q) { return(true); } } } //up down { var m = message as InputMessageKeyUp; if (m != null) { if (m.Key == EKeys.W || m.Key == EKeys.Up || m.Key == EKeys.S || m.Key == EKeys.Down || m.Key == EKeys.A || m.Key == EKeys.Left || m.Key == EKeys.D || m.Key == EKeys.Right || m.Key == EKeys.E || m.Key == EKeys.Q) { return(true); } } } } return(false); }