moved utilities for rhythmbullet to separate project for a better custom content loaders for the monogame pipeline as well as for future projects and of course learning how things work.
This commit is contained in:
16
Recrowned-Athenaeum/Input/IInputListener.cs
Normal file
16
Recrowned-Athenaeum/Input/IInputListener.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RhythmBullet.Utilities.Input
|
||||
{
|
||||
public interface IInputListener
|
||||
{
|
||||
bool KeyboardStateChanged(KeyboardState state);
|
||||
|
||||
bool MouseStateChanged(MouseState state);
|
||||
}
|
||||
}
|
22
Recrowned-Athenaeum/Input/InputListener.cs
Normal file
22
Recrowned-Athenaeum/Input/InputListener.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
|
||||
namespace RhythmBullet.Utilities.Input
|
||||
{
|
||||
class InputListener : IInputListener
|
||||
{
|
||||
public bool KeyboardStateChanged(KeyboardState state)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool MouseStateChanged(MouseState state)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
73
Recrowned-Athenaeum/Input/InputUtilities.cs
Normal file
73
Recrowned-Athenaeum/Input/InputUtilities.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using RhythmBullet.Utilities.Input;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RhythmBullet.Utilities.Input
|
||||
{
|
||||
public static class InputUtilities
|
||||
{
|
||||
public static List<IInputListener> InputListeners;
|
||||
static KeyboardState keyboardState;
|
||||
static MouseState mouseState;
|
||||
|
||||
static InputUtilities()
|
||||
{
|
||||
InputListeners = new List<IInputListener>();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user