diff --git a/axios.suo b/axios.suo
index e10df79..3ca7ae9 100644
Binary files a/axios.suo and b/axios.suo differ
diff --git a/axios/Axios_Windows.csproj.user b/axios/Axios_Windows.csproj.user
index 566c009..76fe5a5 100644
--- a/axios/Axios_Windows.csproj.user
+++ b/axios/Axios_Windows.csproj.user
@@ -1,6 +1,6 @@
- ShowAllFiles
+ ProjectFiles
\ No newline at end of file
diff --git a/axios/ScreenSystem/GameScreen.cs b/axios/ScreenSystem/GameScreen.cs
index 654b6ff..9d58f55 100644
--- a/axios/ScreenSystem/GameScreen.cs
+++ b/axios/ScreenSystem/GameScreen.cs
@@ -41,7 +41,7 @@ namespace GameStateManagement
HasVirtualStick = false;
HasCursor = false;
}
- protected bool HasCursor = false;
+ public bool HasCursor = false;
///
/// Normally when one screen is brought up over the top of another,
/// the first screen will transition off to make room for the new
diff --git a/axios/ScreenSystem/InputState.cs b/axios/ScreenSystem/InputState.cs
index a553459..06ab122 100644
--- a/axios/ScreenSystem/InputState.cs
+++ b/axios/ScreenSystem/InputState.cs
@@ -14,6 +14,7 @@ using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using FarseerPhysics.SamplesFramework;
using Microsoft.Xna.Framework.Graphics;
+using System;
namespace GameStateManagement
{
@@ -244,11 +245,32 @@ namespace GameStateManagement
return new GamePadState(_stick, Vector2.Zero, 0f, 0f, _buttons.ToArray());
}
+ public void Draw()
+ {
+ if (_cursorIsVisible && _cursorIsValid)
+ {
+ _manager.SpriteBatch.Begin();
+ _manager.SpriteBatch.Draw(_cursorSprite.Texture, _cursor, null, Color.White, 0f, _cursorSprite.Origin, 1f, SpriteEffects.None, 0f);
+ _manager.SpriteBatch.End();
+ }
+#if WINDOWS_PHONE
+ if (_handleVirtualStick)
+ {
+ _manager.SpriteBatch.Begin();
+ _phoneA.Draw(_manager.SpriteBatch);
+ _phoneB.Draw(_manager.SpriteBatch);
+ _phoneStick.Draw(_manager.SpriteBatch);
+ _manager.SpriteBatch.End();
+ }
+#endif
+ }
+
///
/// Reads the latest state user input.
///
public void Update(GameTime gameTime)
{
+ PlayerIndex p;
_lastMouseState = _currentMouseState;
if (_handleVirtualStick)
{
@@ -297,8 +319,10 @@ namespace GameStateManagement
Gestures.Clear();
while (TouchPanel.IsGestureAvailable)
{
+ //System.Diagnostics.Debugger.Break();
Gestures.Add(TouchPanel.ReadGesture());
}
+ //System.Diagnostics.Debugger.Break();
// Update cursor
Vector2 oldCursor = _cursor;
@@ -314,9 +338,16 @@ namespace GameStateManagement
_cursor.X = _currentMouseState.X;
_cursor.Y = _currentMouseState.Y;
}
+
+ if (this.IsNewKeyPress(Keys.P, PlayerIndex.One, out p))
+ Console.WriteLine(_cursor.ToString());
+
_cursor.X = MathHelper.Clamp(_cursor.X, 0f, _viewport.Width);
_cursor.Y = MathHelper.Clamp(_cursor.Y, 0f, _viewport.Height);
+ if (this.IsNewKeyPress(Keys.P, PlayerIndex.One, out p))
+ Console.WriteLine(_cursor.ToString());
+
if (_cursorIsValid && oldCursor != _cursor)
{
_cursorMoved = true;
@@ -345,6 +376,9 @@ namespace GameStateManagement
_cursorIsValid = false;
}
#endif
+
+ if (this.IsNewKeyPress(Keys.P, PlayerIndex.One, out p))
+ Console.WriteLine(_viewport.ToString());
}
diff --git a/axios/ScreenSystem/MenuScreen.cs b/axios/ScreenSystem/MenuScreen.cs
index 771e77d..bc578d8 100644
--- a/axios/ScreenSystem/MenuScreen.cs
+++ b/axios/ScreenSystem/MenuScreen.cs
@@ -27,6 +27,9 @@ namespace GameStateManagement
{
#region Fields
+ // the number of pixels to pad above and below menu entries for touch input
+ const int menuEntryPadding = 10;
+
private List menuEntries = new List();
int selectedEntry = 0;
string menuTitle;
@@ -62,6 +65,8 @@ namespace GameStateManagement
public MenuScreen(string menuTitle)
{
this.menuTitle = menuTitle;
+ // menus generally only need Tap for menu selection
+ EnabledGestures = GestureType.Tap;
TransitionOnTime = TimeSpan.FromSeconds(0.5);
TransitionOffTime = TimeSpan.FromSeconds(0.5);
@@ -95,6 +100,19 @@ namespace GameStateManagement
#region Handle Input
+ ///
+ /// Allows the screen to create the hit bounds for a particular menu entry.
+ ///
+ protected virtual Rectangle GetMenuEntryHitBounds(MenuEntry entry)
+ {
+ // the hit bounds are the entire width of the screen, and the height of the entry
+ // with some additional padding above and below.
+ return new Rectangle(
+ 0,
+ (int)entry.Position.Y - menuEntryPadding,
+ ScreenManager.GraphicsDevice.Viewport.Width,
+ entry.GetHeight(this) + (menuEntryPadding * 2));
+ }
///
/// Responds to user input, changing the selected entry and accepting
@@ -107,8 +125,10 @@ namespace GameStateManagement
// If we pass a null controlling player, the InputState helper returns to
// us which player actually provided the input. We pass that through to
// OnSelectEntry and OnCancel, so they can tell which player triggered them.
- PlayerIndex playerIndex;
+
+#if WINDOWS || XBOX360
+ PlayerIndex playerIndex;
// Move to the previous menu entry?
if (menuUp.Evaluate(input, ControllingPlayer, out playerIndex))
{
@@ -135,6 +155,42 @@ namespace GameStateManagement
{
OnCancel(playerIndex);
}
+#endif
+
+#if WINDOWS_PHONE
+ //selectedEntry = 1;
+
+ PlayerIndex player;
+ if (input.IsNewButtonPress(Buttons.Back, ControllingPlayer, out player))
+ {
+ OnCancel(player);
+ }
+
+ // look for any taps that occurred and select any entries that were tapped
+ foreach (GestureSample gesture in input.Gestures)
+ {
+ //System.Diagnostics.Debugger.Break();
+ if (gesture.GestureType == GestureType.Tap)
+ {
+ // convert the position to a Point that we can test against a Rectangle
+ Point tapLocation = new Point((int)gesture.Position.X, (int)gesture.Position.Y);
+
+ // iterate the entries to see if any were tapped
+ for (int i = 0; i < menuEntries.Count; i++)
+ {
+ MenuEntry menuEntry = menuEntries[i];
+
+ if (GetMenuEntryHitBounds(menuEntry).Contains(tapLocation))
+ {
+ // select the entry. since gestures are only available on Windows Phone,
+ // we can safely pass PlayerIndex.One to all entries since there is only
+ // one player on Windows Phone.
+ OnSelectEntry(i, PlayerIndex.One);
+ }
+ }
+ }
+ }
+#endif
}
diff --git a/axios/ScreenSystem/ScreenManager.cs b/axios/ScreenSystem/ScreenManager.cs
index 6912ebe..dcd2545 100644
--- a/axios/ScreenSystem/ScreenManager.cs
+++ b/axios/ScreenSystem/ScreenManager.cs
@@ -144,7 +144,7 @@ namespace GameStateManagement
spriteBatch = new SpriteBatch(GraphicsDevice);
font = content.Load("menufont");
blankTexture = Game.Content.Load("Materials/blank");
-
+ input.LoadContent();
// Tell each of the screens to load their content.
foreach (GameScreen screen in screens)
{
@@ -207,6 +207,8 @@ namespace GameStateManagement
// give it a chance to handle input.
if (!otherScreenHasFocus)
{
+ input.ShowCursor = screen.HasCursor;
+ input.EnableVirtualStick = screen.HasVirtualStick;
screen.HandleInput(gameTime, input);
otherScreenHasFocus = true;
@@ -244,6 +246,7 @@ namespace GameStateManagement
///
public override void Draw(GameTime gameTime)
{
+
foreach (GameScreen screen in screens)
{
if (screen.ScreenState == ScreenState.Hidden)
@@ -251,6 +254,7 @@ namespace GameStateManagement
screen.Draw(gameTime);
}
+ input.Draw();
}