2f107db...5202af9

This commit is contained in:
Joonas Rikkonen
2019-03-18 21:42:26 +02:00
parent 58c92888b7
commit 044fd3344b
395 changed files with 27417 additions and 19754 deletions
@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
namespace Barotrauma
@@ -19,7 +20,14 @@ namespace Barotrauma
static bool allowInput;
static bool wasWindowActive;
#if LINUX || OSX
static readonly Keys[] manuallyHandledTextInputKeys = { Keys.Left, Keys.Right, Keys.Up, Keys.Down };
const float AutoRepeatDelay = 0.5f;
const float AutoRepeatRate = 25;
static Dictionary<Keys, float> autoRepeatTimer = new Dictionary<Keys, float>();
#endif
public static Vector2 MousePosition
{
get { return new Vector2(mouseState.Position.X, mouseState.Position.Y); }
@@ -30,15 +38,6 @@ namespace Barotrauma
get { return new Vector2(latestMouseState.Position.X, latestMouseState.Position.Y); }
}
//public static MouseState GetMouseState
//{
// get { return mouseState; }
//}
//public static MouseState GetOldMouseState
//{
// get { return oldMouseState; }
//}
public static bool MouseInsideWindow
{
get { return new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight).Contains(MousePosition); }
@@ -124,6 +123,40 @@ namespace Barotrauma
return AllowInput && mouseState.MiddleButton == ButtonState.Pressed;
}
public static bool Mouse4ButtonClicked()
{
return (AllowInput &&
oldMouseState.XButton1 == ButtonState.Pressed
&& mouseState.XButton1 == ButtonState.Released);
}
public static bool Mouse4ButtonHeld()
{
return AllowInput && mouseState.XButton1 == ButtonState.Pressed;
}
public static bool Mouse5ButtonClicked()
{
return (AllowInput &&
oldMouseState.XButton2 == ButtonState.Pressed
&& mouseState.XButton2 == ButtonState.Released);
}
public static bool Mouse5ButtonHeld()
{
return AllowInput && mouseState.XButton2 == ButtonState.Pressed;
}
public static bool MouseWheelUpClicked()
{
return (AllowInput && ScrollWheelSpeed > 0);
}
public static bool MouseWheelDownClicked()
{
return (AllowInput && ScrollWheelSpeed < 0);
}
public static bool DoubleClicked()
{
return AllowInput && doubleClicked;
@@ -199,7 +232,36 @@ namespace Barotrauma
}
lastClickPosition = mouseState.Position;
timeSinceClick = 0.0;
}
}
#if LINUX || OSX
//arrow keys cannot be received using window.TextInput on Linux (see https://github.com/MonoGame/MonoGame/issues/5808)
//so lets do it manually here and pass to the KeyboardDispatcher:
foreach (Keys key in manuallyHandledTextInputKeys)
{
if (!autoRepeatTimer.ContainsKey(key))
{
autoRepeatTimer[key] = 0.0f;
}
if (KeyDown(key))
{
if (autoRepeatTimer[key] <= 0.0f)
{
GUI.KeyboardDispatcher.EventInput_KeyDown(null, new EventInput.KeyEventArgs(key));
}
else if (autoRepeatTimer[key] > AutoRepeatDelay)
{
GUI.KeyboardDispatcher.EventInput_KeyDown(null, new EventInput.KeyEventArgs(key));
autoRepeatTimer[key] -= 1.0f / AutoRepeatRate;
}
autoRepeatTimer[key] += (float)deltaTime;
}
else
{
autoRepeatTimer[key] = 0.0f;
}
}
#endif
}
public static void UpdateVariable()