aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Frontend/ShiftOS.cs
diff options
context:
space:
mode:
authorphath0m <[email protected]>2017-08-05 16:05:08 -0700
committerphath0m <[email protected]>2017-08-05 16:05:08 -0700
commit01b4c19c02f3228a400c187cdf66a9776bc41822 (patch)
tree285ccf3c87e436144c9ed418b67b7ce074794fdd /ShiftOS.Frontend/ShiftOS.cs
parentcda0c91ee4e47c0187ebf0e0316db136475f4fcc (diff)
downloadshiftos_thereturn-01b4c19c02f3228a400c187cdf66a9776bc41822.tar.gz
shiftos_thereturn-01b4c19c02f3228a400c187cdf66a9776bc41822.tar.bz2
shiftos_thereturn-01b4c19c02f3228a400c187cdf66a9776bc41822.zip
Added MonoGame.Extended.Input nuget package, thus, replacing the existing method used by ShiftOS to obtain keyboard input.
Diffstat (limited to 'ShiftOS.Frontend/ShiftOS.cs')
-rw-r--r--ShiftOS.Frontend/ShiftOS.cs82
1 files changed, 31 insertions, 51 deletions
diff --git a/ShiftOS.Frontend/ShiftOS.cs b/ShiftOS.Frontend/ShiftOS.cs
index 5c897d3..cda7558 100644
--- a/ShiftOS.Frontend/ShiftOS.cs
+++ b/ShiftOS.Frontend/ShiftOS.cs
@@ -5,6 +5,7 @@ using System.Runtime.InteropServices;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
+using MonoGame.Extended.Input.InputListeners;
using Newtonsoft.Json;
using ShiftOS.Engine;
using ShiftOS.Frontend.GraphicsSubsystem;
@@ -30,6 +31,8 @@ namespace ShiftOS.Frontend
private bool DisplayDebugInfo = false;
+ private KeyboardListener keyboardListener = new KeyboardListener ();
+
public ShiftOS()
{
Story.FailureRequested += (message) =>
@@ -68,11 +71,36 @@ namespace ShiftOS.Frontend
//Fullscreen
graphicsDevice.IsFullScreen = uconf.Fullscreen;
+
+ // keyboard events
+ keyboardListener.KeyPressed += KeyboardListener_KeyPressed;
+
UIManager.Init(this);
}
- private Keys lastKey = Keys.None;
+ private void KeyboardListener_KeyPressed(object sender, KeyboardEventArgs e)
+ {
+ if (e.Key == Keys.F11)
+ {
+ UIManager.Fullscreen = !UIManager.Fullscreen;
+ }
+ else if (e.Modifiers.HasFlag(KeyboardModifiers.Control) && e.Key == Keys.D)
+ {
+ DisplayDebugInfo = !DisplayDebugInfo;
+ }
+ else if (e.Modifiers.HasFlag(KeyboardModifiers.Control) && e.Key == Keys.E)
+ {
+ UIManager.ExperimentalEffects = !UIManager.ExperimentalEffects;
+ }
+ else
+ {
+ // Notice: I would personally recommend just using KeyboardEventArgs instead of KeyEvent
+ // from now on, but what ever. -phath0m
+ UIManager.ProcessKeyEvent(new KeyEvent(e));
+ }
+ }
+
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
@@ -160,8 +188,7 @@ namespace ShiftOS.Frontend
MouseTexture = null;
// TODO: Unload any non ContentManager content here
}
-
- private double kb_elapsedms = 0;
+
private double mouseMS = 0;
private MouseState LastMouseState;
@@ -244,55 +271,8 @@ namespace ShiftOS.Frontend
//Let's see how keyboard input works.
- //Hmmm... just like the mouse...
- var keystate = Keyboard.GetState();
-
- //Simple... just iterate through this list and generate some key events?
- var keys = keystate.GetPressedKeys();
- if (keys.Length > 0)
- {
- var key = keys.FirstOrDefault(x => x != Keys.LeftControl && x != Keys.RightControl && x != Keys.LeftShift && x != Keys.RightShift && x != Keys.LeftAlt && x != Keys.RightAlt);
- if (lastKey != key)
- {
- kb_elapsedms = 0;
- lastKey = key;
- }
- }
- if (keystate.IsKeyDown(lastKey))
- {
- if (kb_elapsedms == 0 || kb_elapsedms >= 500)
- {
- if (lastKey == Keys.F11)
- {
- UIManager.Fullscreen = !UIManager.Fullscreen;
- }
- else
- {
- var shift = keystate.IsKeyDown(Keys.LeftShift) || keystate.IsKeyDown(Keys.RightShift);
- var alt = keystate.IsKeyDown(Keys.LeftAlt) || keystate.IsKeyDown(Keys.RightAlt);
- var control = keystate.IsKeyDown(Keys.LeftControl) || keystate.IsKeyDown(Keys.RightControl);
+ keyboardListener.Update(gameTime);
- if (control && lastKey == Keys.D)
- {
- DisplayDebugInfo = !DisplayDebugInfo;
- }
- else if (control && lastKey == Keys.E)
- {
- UIManager.ExperimentalEffects = !UIManager.ExperimentalEffects;
- }
- else
- {
- var e = new KeyEvent(control, alt, shift, lastKey);
- UIManager.ProcessKeyEvent(e);
- }
- }
- }
- kb_elapsedms += gameTime.ElapsedGameTime.TotalMilliseconds;
- }
- else
- {
- kb_elapsedms = 0;
- }
//Cause layout update on all elements
UIManager.LayoutUpdate(gameTime);