Removed monogame based input listener setup.
This commit is contained in:
parent
005d66840d
commit
45deae140c
@ -1,23 +0,0 @@
|
|||||||
|
|
||||||
namespace RecrownedAthenaeum.Input
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Input listener for <see cref="InputUtilities"/>.
|
|
||||||
/// </summary>
|
|
||||||
public interface IInputListener
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Called when the state of the keyboard has changed.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="state">The new state.</param>
|
|
||||||
/// <returns>True to continue calling other listeners.</returns>
|
|
||||||
bool KeyboardStateChanged(KeyboardState state);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called when the state of the mouse has changed.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="state">The new state.</param>
|
|
||||||
/// <returns>True to continue calling other listeners.</returns>
|
|
||||||
bool MouseStateChanged(MouseState state);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
using Microsoft.Xna.Framework.Input;
|
|
||||||
|
|
||||||
namespace RecrownedAthenaeum.Input
|
|
||||||
{
|
|
||||||
class InputListener : IInputListener
|
|
||||||
{
|
|
||||||
public bool KeyboardStateChanged(KeyboardState state)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool MouseStateChanged(MouseState state)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,87 +0,0 @@
|
|||||||
using Microsoft.Xna.Framework;
|
|
||||||
using Microsoft.Xna.Framework.Input;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace RecrownedAthenaeum.Input
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Utilities to better manage input for the game.
|
|
||||||
/// </summary>
|
|
||||||
public static class InputUtilities
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Listeners for changes in input.
|
|
||||||
/// </summary>
|
|
||||||
public static List<IInputListener> InputListeners;
|
|
||||||
static KeyboardState keyboardState;
|
|
||||||
static MouseState mouseState;
|
|
||||||
|
|
||||||
static InputUtilities()
|
|
||||||
{
|
|
||||||
InputListeners = new List<IInputListener>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Updates inputs.
|
|
||||||
/// Should be called once every game update to be up to date with new states of inputs.
|
|
||||||
/// </summary>
|
|
||||||
public static void Update()
|
|
||||||
{
|
|
||||||
KeyboardState updatedKeyboardState = Keyboard.GetState();
|
|
||||||
MouseState updatedMouseState = Mouse.GetState();
|
|
||||||
bool disableKeyboard = false;
|
|
||||||
bool disableMouse = false;
|
|
||||||
foreach (IInputListener inputListener in InputListeners)
|
|
||||||
{
|
|
||||||
if (!disableKeyboard && keyboardState != updatedKeyboardState)
|
|
||||||
{
|
|
||||||
disableKeyboard = inputListener.KeyboardStateChanged(updatedKeyboardState);
|
|
||||||
}
|
|
||||||
if (!disableMouse && mouseState != updatedMouseState)
|
|
||||||
{
|
|
||||||
disableMouse = inputListener.MouseStateChanged(updatedMouseState);
|
|
||||||
}
|
|
||||||
if (disableKeyboard && disableMouse)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
UpdateStates();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Poll used to check if mouse was clicked.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>True if clicked.</returns>
|
|
||||||
public static bool MouseClicked()
|
|
||||||
{
|
|
||||||
if (mouseState.LeftButton == ButtonState.Pressed)
|
|
||||||
{
|
|
||||||
return Mouse.GetState().LeftButton != ButtonState.Pressed;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void UpdateStates()
|
|
||||||
{
|
|
||||||
keyboardState = Keyboard.GetState();
|
|
||||||
mouseState = Mouse.GetState();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Checks whether mouse is within boundaries.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="bounds">Boundaries to check.</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static bool MouseWithinBoundries(Rectangle bounds)
|
|
||||||
{
|
|
||||||
MouseState mouseState = Mouse.GetState();
|
|
||||||
if (mouseState.X >= bounds.X && mouseState.X <= (bounds.X + bounds.Width) && mouseState.Y >= bounds.Y && mouseState.Y <= (bounds.Y + bounds.Height))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user