diff -r 5fd5ebaa2dbb6258c64690b66494cfad1b333944 -r 2fa541edd9646af44c28b3eaef617e35805ca642 axios/Axios_Windows.csproj.user
--- a/axios/Axios_Windows.csproj.user Thu Apr 12 22:20:50 2012 -0500
+++ b/axios/Axios_Windows.csproj.user Sun Apr 15 19:17:34 2012 -0500
@@ -1,6 +1,6 @@
- ShowAllFiles
+ ProjectFiles
\ No newline at end of file
diff -r 5fd5ebaa2dbb6258c64690b66494cfad1b333944 -r 2fa541edd9646af44c28b3eaef617e35805ca642 axios/Engine/AxiosGameObject.cs
--- a/axios/Engine/AxiosGameObject.cs Thu Apr 12 22:20:50 2012 -0500
+++ b/axios/Engine/AxiosGameObject.cs Sun Apr 15 19:17:34 2012 -0500
@@ -2,6 +2,7 @@
using FarseerPhysics.Dynamics;
using FarseerPhysics.SamplesFramework;
using Microsoft.Xna.Framework;
+using GameStateManagement;
namespace Axios.Engine
{
@@ -46,12 +47,12 @@
}
- public virtual void HandleInput(AxiosGameScreen gameScreen, InputHelper input, GameTime gameTime)
+ public virtual void HandleInput(AxiosGameScreen gameScreen, InputState input, GameTime gameTime)
{
}
- public virtual void HandleCursor(AxiosGameScreen gameScreen, InputHelper input)
+ public virtual void HandleCursor(AxiosGameScreen gameScreen, InputState input)
{
}
diff -r 5fd5ebaa2dbb6258c64690b66494cfad1b333944 -r 2fa541edd9646af44c28b3eaef617e35805ca642 axios/Engine/AxiosGameScreen.cs
--- a/axios/Engine/AxiosGameScreen.cs Thu Apr 12 22:20:50 2012 -0500
+++ b/axios/Engine/AxiosGameScreen.cs Sun Apr 15 19:17:34 2012 -0500
@@ -210,7 +210,7 @@
}
- public override void HandleCursor(InputHelper input)
+ public override void HandleCursor(InputState input)
{
base.HandleCursor(input);
HandleMouseEvents(input);
@@ -219,7 +219,7 @@
g.HandleCursor(this, input);
}
- private void HandleMouseEvents(InputHelper input)
+ private void HandleMouseEvents(InputState input)
{
Vector2 position = this.Camera.ConvertScreenToWorld(input.Cursor);
Fixture fix = this.World.TestPoint(position);
diff -r 5fd5ebaa2dbb6258c64690b66494cfad1b333944 -r 2fa541edd9646af44c28b3eaef617e35805ca642 axios/ScreenSystem/InputState.cs
--- a/axios/ScreenSystem/InputState.cs Thu Apr 12 22:20:50 2012 -0500
+++ b/axios/ScreenSystem/InputState.cs Sun Apr 15 19:17:34 2012 -0500
@@ -9,12 +9,27 @@
using System.Collections.Generic;
using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using FarseerPhysics.SamplesFramework;
+using Microsoft.Xna.Framework.Graphics;
namespace GameStateManagement
{
+
+ ///
+ /// an enum of all available mouse buttons.
+ ///
+ public enum MouseButtons
+ {
+ LeftButton,
+ MiddleButton,
+ RightButton,
+ ExtraButton1,
+ ExtraButton2
+ }
+
///
/// Helper for reading input from keyboard, gamepad, and touch input. This class
/// tracks both the current and previous state of the input devices, and implements
@@ -47,12 +62,13 @@
/*
- *
- *
- *
- *
+ * Adding variables for the cursor
+ * -- Nathan Adams [adamsna@datanethost.net] - 4/15/2012
*
*/
+ private MouseState _currentMouseState;
+ private MouseState _lastMouseState;
+
private Vector2 _cursor;
private bool _cursorIsValid;
private bool _cursorIsVisible;
@@ -68,13 +84,17 @@
public TouchCollection TouchState;
public readonly List Gestures = new List();
+
+ private ScreenManager _manager;
+ private Viewport _viewport;
///
/// Constructs a new input state.
///
- public InputState()
+ public InputState(ScreenManager manager)
{
+ _manager = manager;
CurrentKeyboardStates = new KeyboardState[MaxInputs];
CurrentGamePadStates = new GamePadState[MaxInputs];
@@ -82,6 +102,146 @@
LastGamePadStates = new GamePadState[MaxInputs];
GamePadWasConnected = new bool[MaxInputs];
+ _currentVirtualState = new GamePadState();
+ _lastVirtualState = new GamePadState();
+
+ _cursorIsVisible = false;
+ _cursorMoved = false;
+#if WINDOWS_PHONE
+ _cursorIsValid = false;
+#else
+ _cursorIsValid = true;
+#endif
+ _cursor = Vector2.Zero;
+
+ _handleVirtualStick = false;
+ }
+
+ public MouseState MouseState
+ {
+ get { return _currentMouseState; }
+ }
+
+ public GamePadState VirtualState
+ {
+ get { return _currentVirtualState; }
+ }
+
+ public MouseState PreviousMouseState
+ {
+ get { return _lastMouseState; }
+ }
+
+ public GamePadState PreviousVirtualState
+ {
+ get { return _lastVirtualState; }
+ }
+
+ public bool ShowCursor
+ {
+ get { return _cursorIsVisible && _cursorIsValid; }
+ set { _cursorIsVisible = value; }
+ }
+
+ public bool EnableVirtualStick
+ {
+ get { return _handleVirtualStick; }
+ set { _handleVirtualStick = value; }
+ }
+
+ public Vector2 Cursor
+ {
+ get { return _cursor; }
+ }
+
+ public bool IsCursorMoved
+ {
+ get { return _cursorMoved; }
+ }
+
+ public bool IsCursorValid
+ {
+ get { return _cursorIsValid; }
+ }
+
+ public void LoadContent()
+ {
+ ContentManager man = new ContentManager(_manager.Game.Services, "Content");
+ _cursorSprite = new Sprite(man.Load("Common/cursor"));
+#if WINDOWS_PHONE
+ // virtual stick content
+ _phoneStick = new VirtualStick(man.Load("Common/socket"),
+ man.Load("Common/stick"), new Vector2(80f, 400f));
+
+ Texture2D temp = man.Load("Common/buttons");
+ _phoneA = new VirtualButton(temp, new Vector2(695f, 380f), new Rectangle(0, 0, 40, 40), new Rectangle(0, 40, 40, 40));
+ _phoneB = new VirtualButton(temp, new Vector2(745f, 360f), new Rectangle(40, 0, 40, 40), new Rectangle(40, 40, 40, 40));
+#endif
+ _viewport = _manager.GraphicsDevice.Viewport;
+ }
+
+ private GamePadState HandleVirtualStickWin()
+ {
+ Vector2 _leftStick = Vector2.Zero;
+ List _buttons = new List();
+ PlayerIndex pout;
+ if (IsNewKeyPress(Keys.A, PlayerIndex.One, out pout))
+ {
+ _leftStick.X -= 1f;
+ }
+ if (IsNewKeyPress(Keys.S, PlayerIndex.One, out pout))
+ {
+ _leftStick.Y -= 1f;
+ }
+ if (IsNewKeyPress(Keys.D, PlayerIndex.One, out pout))
+ {
+ _leftStick.X += 1f;
+ }
+ if (IsNewKeyPress(Keys.W, PlayerIndex.One, out pout))
+ {
+ _leftStick.Y += 1f;
+ }
+ if (IsNewKeyPress(Keys.Space, PlayerIndex.One, out pout))
+ {
+ _buttons.Add(Buttons.A);
+ }
+ if (IsNewKeyPress(Keys.LeftControl, PlayerIndex.One, out pout))
+ {
+ _buttons.Add(Buttons.B);
+ }
+ if (_leftStick != Vector2.Zero)
+ {
+ _leftStick.Normalize();
+ }
+
+ return new GamePadState(_leftStick, Vector2.Zero, 0f, 0f, _buttons.ToArray());
+ }
+
+ private GamePadState HandleVirtualStickWP7()
+ {
+ List _buttons = new List();
+ Vector2 _stick = Vector2.Zero;
+#if WINDOWS_PHONE
+ _phoneA.Pressed = false;
+ _phoneB.Pressed = false;
+ TouchCollection touchLocations = TouchPanel.GetState();
+ foreach (TouchLocation touchLocation in touchLocations)
+ {
+ _phoneA.Update(touchLocation);
+ _phoneB.Update(touchLocation);
+ _phoneStick.Update(touchLocation);
+ }
+ if (_phoneA.Pressed)
+ {
+ _buttons.Add(Buttons.A);
+ }
+ if (_phoneB.Pressed)
+ {
+ _buttons.Add(Buttons.B);
+ }
+ _stick = _phoneStick.StickPosition;
+#endif
+ return new GamePadState(_stick, Vector2.Zero, 0f, 0f, _buttons.ToArray());
}
///
@@ -89,6 +249,31 @@
///
public void Update()
{
+ _lastMouseState = _currentMouseState;
+ if (_handleVirtualStick)
+ {
+ _lastVirtualState = _currentVirtualState;
+ }
+
+ _currentMouseState = Mouse.GetState();
+
+ if (_handleVirtualStick)
+ {
+#if XBOX
+ _currentVirtualState= GamePad.GetState(PlayerIndex.One);
+#elif WINDOWS
+ if (GamePad.GetState(PlayerIndex.One).IsConnected)
+ {
+ _currentVirtualState = GamePad.GetState(PlayerIndex.One);
+ }
+ else
+ {
+ _currentVirtualState = HandleVirtualStickWin();
+ }
+#elif WINDOWS_PHONE
+ _currentVirtualState = HandleVirtualStickWP7();
+#endif
+ }
for (int i = 0; i < MaxInputs; i++)
{
LastKeyboardStates[i] = CurrentKeyboardStates[i];
@@ -229,5 +414,17 @@
IsNewButtonPress(button, PlayerIndex.Four, out playerIndex));
}
}
+
+ public bool IsNewVirtualButtonPress(Buttons button)
+ {
+ return (_lastVirtualState.IsButtonUp(button) &&
+ _currentVirtualState.IsButtonDown(button));
+ }
+
+ public bool IsNewVirtualButtonRelease(Buttons button)
+ {
+ return (_lastVirtualState.IsButtonDown(button) &&
+ _currentVirtualState.IsButtonUp(button));
+ }
}
}