Final commits for new GSM.
--HG-- branch : axios-newgsm extra : close : 1
This commit is contained in:
parent
bf3950b0c5
commit
de79e014ad
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<ProjectView>ShowAllFiles</ProjectView>
|
<ProjectView>ProjectFiles</ProjectView>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
@ -41,7 +41,7 @@ namespace GameStateManagement
|
|||||||
HasVirtualStick = false;
|
HasVirtualStick = false;
|
||||||
HasCursor = false;
|
HasCursor = false;
|
||||||
}
|
}
|
||||||
protected bool HasCursor = false;
|
public bool HasCursor = false;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Normally when one screen is brought up over the top of another,
|
/// Normally when one screen is brought up over the top of another,
|
||||||
/// the first screen will transition off to make room for the new
|
/// the first screen will transition off to make room for the new
|
||||||
|
@ -14,6 +14,7 @@ using Microsoft.Xna.Framework.Input;
|
|||||||
using Microsoft.Xna.Framework.Input.Touch;
|
using Microsoft.Xna.Framework.Input.Touch;
|
||||||
using FarseerPhysics.SamplesFramework;
|
using FarseerPhysics.SamplesFramework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace GameStateManagement
|
namespace GameStateManagement
|
||||||
{
|
{
|
||||||
@ -244,11 +245,32 @@ namespace GameStateManagement
|
|||||||
return new GamePadState(_stick, Vector2.Zero, 0f, 0f, _buttons.ToArray());
|
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
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads the latest state user input.
|
/// Reads the latest state user input.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Update(GameTime gameTime)
|
public void Update(GameTime gameTime)
|
||||||
{
|
{
|
||||||
|
PlayerIndex p;
|
||||||
_lastMouseState = _currentMouseState;
|
_lastMouseState = _currentMouseState;
|
||||||
if (_handleVirtualStick)
|
if (_handleVirtualStick)
|
||||||
{
|
{
|
||||||
@ -297,8 +319,10 @@ namespace GameStateManagement
|
|||||||
Gestures.Clear();
|
Gestures.Clear();
|
||||||
while (TouchPanel.IsGestureAvailable)
|
while (TouchPanel.IsGestureAvailable)
|
||||||
{
|
{
|
||||||
|
//System.Diagnostics.Debugger.Break();
|
||||||
Gestures.Add(TouchPanel.ReadGesture());
|
Gestures.Add(TouchPanel.ReadGesture());
|
||||||
}
|
}
|
||||||
|
//System.Diagnostics.Debugger.Break();
|
||||||
|
|
||||||
// Update cursor
|
// Update cursor
|
||||||
Vector2 oldCursor = _cursor;
|
Vector2 oldCursor = _cursor;
|
||||||
@ -314,9 +338,16 @@ namespace GameStateManagement
|
|||||||
_cursor.X = _currentMouseState.X;
|
_cursor.X = _currentMouseState.X;
|
||||||
_cursor.Y = _currentMouseState.Y;
|
_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.X = MathHelper.Clamp(_cursor.X, 0f, _viewport.Width);
|
||||||
_cursor.Y = MathHelper.Clamp(_cursor.Y, 0f, _viewport.Height);
|
_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)
|
if (_cursorIsValid && oldCursor != _cursor)
|
||||||
{
|
{
|
||||||
_cursorMoved = true;
|
_cursorMoved = true;
|
||||||
@ -345,6 +376,9 @@ namespace GameStateManagement
|
|||||||
_cursorIsValid = false;
|
_cursorIsValid = false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (this.IsNewKeyPress(Keys.P, PlayerIndex.One, out p))
|
||||||
|
Console.WriteLine(_viewport.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,6 +27,9 @@ namespace GameStateManagement
|
|||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
|
|
||||||
|
// the number of pixels to pad above and below menu entries for touch input
|
||||||
|
const int menuEntryPadding = 10;
|
||||||
|
|
||||||
private List<MenuEntry> menuEntries = new List<MenuEntry>();
|
private List<MenuEntry> menuEntries = new List<MenuEntry>();
|
||||||
int selectedEntry = 0;
|
int selectedEntry = 0;
|
||||||
string menuTitle;
|
string menuTitle;
|
||||||
@ -62,6 +65,8 @@ namespace GameStateManagement
|
|||||||
public MenuScreen(string menuTitle)
|
public MenuScreen(string menuTitle)
|
||||||
{
|
{
|
||||||
this.menuTitle = menuTitle;
|
this.menuTitle = menuTitle;
|
||||||
|
// menus generally only need Tap for menu selection
|
||||||
|
EnabledGestures = GestureType.Tap;
|
||||||
|
|
||||||
TransitionOnTime = TimeSpan.FromSeconds(0.5);
|
TransitionOnTime = TimeSpan.FromSeconds(0.5);
|
||||||
TransitionOffTime = TimeSpan.FromSeconds(0.5);
|
TransitionOffTime = TimeSpan.FromSeconds(0.5);
|
||||||
@ -95,6 +100,19 @@ namespace GameStateManagement
|
|||||||
|
|
||||||
#region Handle Input
|
#region Handle Input
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Allows the screen to create the hit bounds for a particular menu entry.
|
||||||
|
/// </summary>
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Responds to user input, changing the selected entry and accepting
|
/// 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
|
// If we pass a null controlling player, the InputState helper returns to
|
||||||
// us which player actually provided the input. We pass that through to
|
// us which player actually provided the input. We pass that through to
|
||||||
// OnSelectEntry and OnCancel, so they can tell which player triggered them.
|
// OnSelectEntry and OnCancel, so they can tell which player triggered them.
|
||||||
PlayerIndex playerIndex;
|
|
||||||
|
|
||||||
|
#if WINDOWS || XBOX360
|
||||||
|
PlayerIndex playerIndex;
|
||||||
// Move to the previous menu entry?
|
// Move to the previous menu entry?
|
||||||
if (menuUp.Evaluate(input, ControllingPlayer, out playerIndex))
|
if (menuUp.Evaluate(input, ControllingPlayer, out playerIndex))
|
||||||
{
|
{
|
||||||
@ -135,6 +155,42 @@ namespace GameStateManagement
|
|||||||
{
|
{
|
||||||
OnCancel(playerIndex);
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ namespace GameStateManagement
|
|||||||
spriteBatch = new SpriteBatch(GraphicsDevice);
|
spriteBatch = new SpriteBatch(GraphicsDevice);
|
||||||
font = content.Load<SpriteFont>("menufont");
|
font = content.Load<SpriteFont>("menufont");
|
||||||
blankTexture = Game.Content.Load<Texture2D>("Materials/blank");
|
blankTexture = Game.Content.Load<Texture2D>("Materials/blank");
|
||||||
|
input.LoadContent();
|
||||||
// Tell each of the screens to load their content.
|
// Tell each of the screens to load their content.
|
||||||
foreach (GameScreen screen in screens)
|
foreach (GameScreen screen in screens)
|
||||||
{
|
{
|
||||||
@ -207,6 +207,8 @@ namespace GameStateManagement
|
|||||||
// give it a chance to handle input.
|
// give it a chance to handle input.
|
||||||
if (!otherScreenHasFocus)
|
if (!otherScreenHasFocus)
|
||||||
{
|
{
|
||||||
|
input.ShowCursor = screen.HasCursor;
|
||||||
|
input.EnableVirtualStick = screen.HasVirtualStick;
|
||||||
screen.HandleInput(gameTime, input);
|
screen.HandleInput(gameTime, input);
|
||||||
|
|
||||||
otherScreenHasFocus = true;
|
otherScreenHasFocus = true;
|
||||||
@ -244,6 +246,7 @@ namespace GameStateManagement
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public override void Draw(GameTime gameTime)
|
public override void Draw(GameTime gameTime)
|
||||||
{
|
{
|
||||||
|
|
||||||
foreach (GameScreen screen in screens)
|
foreach (GameScreen screen in screens)
|
||||||
{
|
{
|
||||||
if (screen.ScreenState == ScreenState.Hidden)
|
if (screen.ScreenState == ScreenState.Hidden)
|
||||||
@ -251,6 +254,7 @@ namespace GameStateManagement
|
|||||||
|
|
||||||
screen.Draw(gameTime);
|
screen.Draw(gameTime);
|
||||||
}
|
}
|
||||||
|
input.Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user