Branching starting code for the new GSM

--HG--
branch : axios-newgsm
master
nathan@daedalus 2012-04-12 22:09:49 -05:00
parent 40b67fb6e8
commit 4057123b6e
16 changed files with 758 additions and 577 deletions

View File

@ -190,18 +190,32 @@
<Compile Include="PrimitiveBatch.cs" /> <Compile Include="PrimitiveBatch.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ScreenSystem\BackgroundScreen.cs" /> <Compile Include="ScreenSystem\BackgroundScreen.cs" />
<Compile Include="ScreenSystem\Button.cs" />
<Compile Include="ScreenSystem\Camera2D.cs" /> <Compile Include="ScreenSystem\Camera2D.cs" />
<Compile Include="ScreenSystem\ConvertUnits.cs" /> <Compile Include="ScreenSystem\ConvertUnits.cs" />
<Compile Include="ScreenSystem\FramerateCounterComponent.cs" /> <Compile Include="ScreenSystem\FramerateCounterComponent.cs" />
<Compile Include="ScreenSystem\GameplayScreen.cs" />
<Compile Include="ScreenSystem\GameScreen.cs" /> <Compile Include="ScreenSystem\GameScreen.cs" />
<Compile Include="ScreenSystem\IDemoScreen.cs" /> <Compile Include="ScreenSystem\IDemoScreen.cs" />
<Compile Include="ScreenSystem\InputAction.cs" />
<Compile Include="ScreenSystem\InputHelper.cs" /> <Compile Include="ScreenSystem\InputHelper.cs" />
<Compile Include="ScreenSystem\InputState.cs" />
<Compile Include="ScreenSystem\IScreenFactory.cs" />
<Compile Include="ScreenSystem\LoadingScreen.cs" />
<Compile Include="ScreenSystem\LogoScreen.cs" /> <Compile Include="ScreenSystem\LogoScreen.cs" />
<Compile Include="ScreenSystem\MainMenuScreen.cs" />
<Compile Include="ScreenSystem\MenuButton.cs" /> <Compile Include="ScreenSystem\MenuButton.cs" />
<Compile Include="ScreenSystem\MenuEntry.cs" /> <Compile Include="ScreenSystem\MenuEntry.cs" />
<Compile Include="ScreenSystem\MenuScreen.cs" /> <Compile Include="ScreenSystem\MenuScreen.cs" />
<Compile Include="ScreenSystem\MessageBoxScreen.cs" /> <Compile Include="ScreenSystem\MessageBoxScreen.cs" />
<Compile Include="ScreenSystem\OptionsMenuScreen.cs" />
<Compile Include="ScreenSystem\PauseMenuScreen.cs" />
<Compile Include="ScreenSystem\PhoneMainMenuScreen.cs" />
<Compile Include="ScreenSystem\PhoneMenuScreen.cs" />
<Compile Include="ScreenSystem\PhonePauseScreen.cs" />
<Compile Include="ScreenSystem\PhysicsGameScreen.cs" /> <Compile Include="ScreenSystem\PhysicsGameScreen.cs" />
<Compile Include="ScreenSystem\PlayerIndexEventArgs.cs" />
<Compile Include="ScreenSystem\ScreenManager.cs" />
<Compile Include="ScreenSystem\ScreenManagerComponent.cs" /> <Compile Include="ScreenSystem\ScreenManagerComponent.cs" />
<Compile Include="ScreenSystem\SpriteFonts.cs" /> <Compile Include="ScreenSystem\SpriteFonts.cs" />
<Compile Include="ScreenSystem\VirtualButton.cs" /> <Compile Include="ScreenSystem\VirtualButton.cs" />

View File

@ -234,19 +234,33 @@
<Compile Include="PrimitiveBatch.cs" /> <Compile Include="PrimitiveBatch.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ScreenSystem\BackgroundScreen.cs" /> <Compile Include="ScreenSystem\BackgroundScreen.cs" />
<Compile Include="ScreenSystem\Button.cs" />
<Compile Include="ScreenSystem\Camera2D.cs" /> <Compile Include="ScreenSystem\Camera2D.cs" />
<Compile Include="ScreenSystem\ConvertUnits.cs" /> <Compile Include="ScreenSystem\ConvertUnits.cs" />
<Compile Include="ScreenSystem\FramerateCounterComponent.cs" /> <Compile Include="ScreenSystem\FramerateCounterComponent.cs" />
<Compile Include="ScreenSystem\GameplayScreen.cs" />
<Compile Include="ScreenSystem\GameScreen.cs" /> <Compile Include="ScreenSystem\GameScreen.cs" />
<Compile Include="ScreenSystem\IDemoScreen.cs" /> <Compile Include="ScreenSystem\IDemoScreen.cs" />
<Compile Include="ScreenSystem\InputAction.cs" />
<Compile Include="ScreenSystem\InputHelper.cs" /> <Compile Include="ScreenSystem\InputHelper.cs" />
<Compile Include="Engine\AxiosGameScreen.cs" /> <Compile Include="Engine\AxiosGameScreen.cs" />
<Compile Include="ScreenSystem\InputState.cs" />
<Compile Include="ScreenSystem\IScreenFactory.cs" />
<Compile Include="ScreenSystem\LoadingScreen.cs" />
<Compile Include="ScreenSystem\LogoScreen.cs" /> <Compile Include="ScreenSystem\LogoScreen.cs" />
<Compile Include="ScreenSystem\MainMenuScreen.cs" />
<Compile Include="ScreenSystem\MenuButton.cs" /> <Compile Include="ScreenSystem\MenuButton.cs" />
<Compile Include="ScreenSystem\MenuEntry.cs" /> <Compile Include="ScreenSystem\MenuEntry.cs" />
<Compile Include="ScreenSystem\MenuScreen.cs" /> <Compile Include="ScreenSystem\MenuScreen.cs" />
<Compile Include="ScreenSystem\MessageBoxScreen.cs" /> <Compile Include="ScreenSystem\MessageBoxScreen.cs" />
<Compile Include="ScreenSystem\OptionsMenuScreen.cs" />
<Compile Include="ScreenSystem\PauseMenuScreen.cs" />
<Compile Include="ScreenSystem\PhoneMainMenuScreen.cs" />
<Compile Include="ScreenSystem\PhoneMenuScreen.cs" />
<Compile Include="ScreenSystem\PhonePauseScreen.cs" />
<Compile Include="ScreenSystem\PhysicsGameScreen.cs" /> <Compile Include="ScreenSystem\PhysicsGameScreen.cs" />
<Compile Include="ScreenSystem\PlayerIndexEventArgs.cs" />
<Compile Include="ScreenSystem\ScreenManager.cs" />
<Compile Include="ScreenSystem\ScreenManagerComponent.cs" /> <Compile Include="ScreenSystem\ScreenManagerComponent.cs" />
<Compile Include="ScreenSystem\SpriteFonts.cs" /> <Compile Include="ScreenSystem\SpriteFonts.cs" />
<Compile Include="ScreenSystem\VirtualButton.cs" /> <Compile Include="ScreenSystem\VirtualButton.cs" />

View File

@ -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>ProjectFiles</ProjectView> <ProjectView>ShowAllFiles</ProjectView>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View File

@ -183,18 +183,32 @@
<Compile Include="PrimitiveBatch.cs" /> <Compile Include="PrimitiveBatch.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ScreenSystem\BackgroundScreen.cs" /> <Compile Include="ScreenSystem\BackgroundScreen.cs" />
<Compile Include="ScreenSystem\Button.cs" />
<Compile Include="ScreenSystem\Camera2D.cs" /> <Compile Include="ScreenSystem\Camera2D.cs" />
<Compile Include="ScreenSystem\ConvertUnits.cs" /> <Compile Include="ScreenSystem\ConvertUnits.cs" />
<Compile Include="ScreenSystem\FramerateCounterComponent.cs" /> <Compile Include="ScreenSystem\FramerateCounterComponent.cs" />
<Compile Include="ScreenSystem\GameplayScreen.cs" />
<Compile Include="ScreenSystem\GameScreen.cs" /> <Compile Include="ScreenSystem\GameScreen.cs" />
<Compile Include="ScreenSystem\IDemoScreen.cs" /> <Compile Include="ScreenSystem\IDemoScreen.cs" />
<Compile Include="ScreenSystem\InputAction.cs" />
<Compile Include="ScreenSystem\InputHelper.cs" /> <Compile Include="ScreenSystem\InputHelper.cs" />
<Compile Include="ScreenSystem\InputState.cs" />
<Compile Include="ScreenSystem\IScreenFactory.cs" />
<Compile Include="ScreenSystem\LoadingScreen.cs" />
<Compile Include="ScreenSystem\LogoScreen.cs" /> <Compile Include="ScreenSystem\LogoScreen.cs" />
<Compile Include="ScreenSystem\MainMenuScreen.cs" />
<Compile Include="ScreenSystem\MenuButton.cs" /> <Compile Include="ScreenSystem\MenuButton.cs" />
<Compile Include="ScreenSystem\MenuEntry.cs" /> <Compile Include="ScreenSystem\MenuEntry.cs" />
<Compile Include="ScreenSystem\MenuScreen.cs" /> <Compile Include="ScreenSystem\MenuScreen.cs" />
<Compile Include="ScreenSystem\MessageBoxScreen.cs" /> <Compile Include="ScreenSystem\MessageBoxScreen.cs" />
<Compile Include="ScreenSystem\OptionsMenuScreen.cs" />
<Compile Include="ScreenSystem\PauseMenuScreen.cs" />
<Compile Include="ScreenSystem\PhoneMainMenuScreen.cs" />
<Compile Include="ScreenSystem\PhoneMenuScreen.cs" />
<Compile Include="ScreenSystem\PhonePauseScreen.cs" />
<Compile Include="ScreenSystem\PhysicsGameScreen.cs" /> <Compile Include="ScreenSystem\PhysicsGameScreen.cs" />
<Compile Include="ScreenSystem\PlayerIndexEventArgs.cs" />
<Compile Include="ScreenSystem\ScreenManager.cs" />
<Compile Include="ScreenSystem\ScreenManagerComponent.cs" /> <Compile Include="ScreenSystem\ScreenManagerComponent.cs" />
<Compile Include="ScreenSystem\SpriteFonts.cs" /> <Compile Include="ScreenSystem\SpriteFonts.cs" />
<Compile Include="ScreenSystem\VirtualButton.cs" /> <Compile Include="ScreenSystem\VirtualButton.cs" />

View File

@ -8,7 +8,9 @@ using Axios.Engine.UI;
using FarseerPhysics.Dynamics; using FarseerPhysics.Dynamics;
using FarseerPhysics.SamplesFramework; using FarseerPhysics.SamplesFramework;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using GameStateManagement;
namespace Axios.Engine namespace Axios.Engine
{ {
@ -158,19 +160,16 @@ namespace Axios.Engine
AxiosLog.Instance.AddLine("Memory usage after cleanup: ", LoggingFlag.DEBUG); AxiosLog.Instance.AddLine("Memory usage after cleanup: ", LoggingFlag.DEBUG);
} }
public override void ExitScreen() public override void Activate(bool instancePreserved)
{ {
base.ExitScreen(); base.Activate(instancePreserved);
}
public override void LoadContent()
{
base.LoadContent();
#if DEBUG #if DEBUG
if (!Axios.Settings.ScreenSaver) if (!Axios.Settings.ScreenSaver)
this.DebugSpriteFont = this.ScreenManager.Content.Load<SpriteFont>(this.DebugTextFont); {
ContentManager man = new ContentManager(ScreenManager.Game.Services, "Content");
this.DebugSpriteFont = man.Load<SpriteFont>(this.DebugTextFont);
}
#endif #endif
} }

View File

@ -1,24 +1,38 @@
using System; #region File Description
using Microsoft.Xna.Framework; //-----------------------------------------------------------------------------
using Microsoft.Xna.Framework.Graphics; // BackgroundScreen.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion
namespace FarseerPhysics.SamplesFramework #region Using Statements
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using GameStateManagement;
#endregion
namespace GameStateManagement
{ {
/// <summary> /// <summary>
/// The background screen sits behind all the other menu screens. /// The background screen sits behind all the other menu screens.
/// It draws a background image that remains fixed in place regardless /// It draws a background image that remains fixed in place regardless
/// of whatever transitions the screens on top of it may be doing. /// of whatever transitions the screens on top of it may be doing.
/// </summary> /// </summary>
public class BackgroundScreen : GameScreen class BackgroundScreen : GameScreen
{ {
private const float LogoScreenHeightRatio = 0.25f; #region Fields
private const float LogoScreenBorderRatio = 0.0375f;
private const float LogoWidthHeightRatio = 1.4f; ContentManager content;
Texture2D backgroundTexture;
#endregion
#region Initialization
private Texture2D _backgroundTexture;
private Rectangle _logoDestination;
//private Texture2D _logoTexture;
private Rectangle _viewport;
/// <summary> /// <summary>
/// Constructor. /// Constructor.
@ -29,24 +43,40 @@ namespace FarseerPhysics.SamplesFramework
TransitionOffTime = TimeSpan.FromSeconds(0.5); TransitionOffTime = TimeSpan.FromSeconds(0.5);
} }
public override void LoadContent()
/// <summary>
/// Loads graphics content for this screen. The background texture is quite
/// big, so we use our own local ContentManager to load it. This allows us
/// to unload before going from the menus into the game itself, wheras if we
/// used the shared ContentManager provided by the Game class, the content
/// would remain loaded forever.
/// </summary>
public override void Activate(bool instancePreserved)
{ {
//_logoTexture = ScreenManager.Content.Load<Texture2D>("Common/logo"); if (!instancePreserved)
_backgroundTexture = ScreenManager.Content.Load<Texture2D>("Common/gradient"); {
if (content == null)
content = new ContentManager(ScreenManager.Game.Services, "Content");
Viewport viewport = ScreenManager.GraphicsDevice.Viewport; backgroundTexture = content.Load<Texture2D>("background");
Vector2 logoSize = new Vector2(); }
logoSize.Y = viewport.Height * LogoScreenHeightRatio;
logoSize.X = logoSize.Y * LogoWidthHeightRatio;
float border = viewport.Height * LogoScreenBorderRatio;
Vector2 logoPosition = new Vector2(viewport.Width - border - logoSize.X,
viewport.Height - border - logoSize.Y);
_logoDestination = new Rectangle((int)logoPosition.X, (int)logoPosition.Y, (int)logoSize.X,
(int)logoSize.Y);
_viewport = viewport.Bounds;
} }
/// <summary>
/// Unloads graphics content for this screen.
/// </summary>
public override void Unload()
{
content.Unload();
}
#endregion
#region Update and Draw
/// <summary> /// <summary>
/// Updates the background screen. Unlike most screens, this should not /// Updates the background screen. Unlike most screens, this should not
/// transition off even if it has been covered by another screen: it is /// transition off even if it has been covered by another screen: it is
@ -55,20 +85,30 @@ namespace FarseerPhysics.SamplesFramework
/// Update method wanting to transition off. /// Update method wanting to transition off.
/// </summary> /// </summary>
public override void Update(GameTime gameTime, bool otherScreenHasFocus, public override void Update(GameTime gameTime, bool otherScreenHasFocus,
bool coveredByOtherScreen) bool coveredByOtherScreen)
{ {
base.Update(gameTime, otherScreenHasFocus, false); base.Update(gameTime, otherScreenHasFocus, false);
} }
/// <summary> /// <summary>
/// Draws the background screen. /// Draws the background screen.
/// </summary> /// </summary>
public override void Draw(GameTime gameTime) public override void Draw(GameTime gameTime)
{ {
ScreenManager.SpriteBatch.Begin(); SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
ScreenManager.SpriteBatch.Draw(_backgroundTexture, _viewport, Color.White); Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
//ScreenManager.SpriteBatch.Draw(_logoTexture, _logoDestination, Color.White * 0.6f); Rectangle fullscreen = new Rectangle(0, 0, viewport.Width, viewport.Height);
ScreenManager.SpriteBatch.End();
spriteBatch.Begin();
spriteBatch.Draw(backgroundTexture, fullscreen,
new Color(TransitionAlpha, TransitionAlpha, TransitionAlpha));
spriteBatch.End();
} }
#endregion
} }
} }

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Globalization; using System.Globalization;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using GameStateManagement;
namespace FarseerPhysics.SamplesFramework namespace FarseerPhysics.SamplesFramework
{ {

View File

@ -1,19 +1,18 @@
#region File Description #region File Description
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// PlayerIndexEventArgs.cs // GameScreen.cs
// //
// XNA Community Game Platform // Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved. // Copyright (C) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#endregion #endregion
using System; using System;
using System.IO;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input.Touch; using Microsoft.Xna.Framework.Input.Touch;
namespace FarseerPhysics.SamplesFramework namespace GameStateManagement
{ {
/// <summary> /// <summary>
/// Enum describes the screen transition state. /// Enum describes the screen transition state.
@ -26,6 +25,7 @@ namespace FarseerPhysics.SamplesFramework
Hidden, Hidden,
} }
/// <summary> /// <summary>
/// A screen is a single layer that has update and draw logic, and which /// A screen is a single layer that has update and draw logic, and which
/// can be combined with other layers to build up a complex menu system. /// can be combined with other layers to build up a complex menu system.
@ -35,23 +35,6 @@ namespace FarseerPhysics.SamplesFramework
/// </summary> /// </summary>
public abstract class GameScreen public abstract class GameScreen
{ {
private GestureType _enabledGestures = GestureType.None;
private bool _otherScreenHasFocus;
public GameScreen()
{
ScreenState = ScreenState.TransitionOn;
TransitionPosition = 1;
TransitionOffTime = TimeSpan.Zero;
TransitionOnTime = TimeSpan.Zero;
HasCursor = false;
HasVirtualStick = false;
}
public bool HasCursor { get; set; }
public bool HasVirtualStick { get; set; }
/// <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
@ -59,26 +42,54 @@ namespace FarseerPhysics.SamplesFramework
/// popup, in which case screens underneath it do not need to bother /// popup, in which case screens underneath it do not need to bother
/// transitioning off. /// transitioning off.
/// </summary> /// </summary>
public bool IsPopup { get; protected set; } public bool IsPopup
{
get { return isPopup; }
protected set { isPopup = value; }
}
bool isPopup = false;
/// <summary> /// <summary>
/// Indicates how long the screen takes to /// Indicates how long the screen takes to
/// transition on when it is activated. /// transition on when it is activated.
/// </summary> /// </summary>
public TimeSpan TransitionOnTime { get; protected set; } public TimeSpan TransitionOnTime
{
get { return transitionOnTime; }
protected set { transitionOnTime = value; }
}
TimeSpan transitionOnTime = TimeSpan.Zero;
/// <summary> /// <summary>
/// Indicates how long the screen takes to /// Indicates how long the screen takes to
/// transition off when it is deactivated. /// transition off when it is deactivated.
/// </summary> /// </summary>
public TimeSpan TransitionOffTime { get; protected set; } public TimeSpan TransitionOffTime
{
get { return transitionOffTime; }
protected set { transitionOffTime = value; }
}
TimeSpan transitionOffTime = TimeSpan.Zero;
/// <summary> /// <summary>
/// Gets the current position of the screen transition, ranging /// Gets the current position of the screen transition, ranging
/// from zero (fully active, no transition) to one (transitioned /// from zero (fully active, no transition) to one (transitioned
/// fully off to nothing). /// fully off to nothing).
/// </summary> /// </summary>
public float TransitionPosition { get; protected set; } public float TransitionPosition
{
get { return transitionPosition; }
protected set { transitionPosition = value; }
}
float transitionPosition = 1;
/// <summary> /// <summary>
/// Gets the current alpha of the screen transition, ranging /// Gets the current alpha of the screen transition, ranging
@ -90,10 +101,18 @@ namespace FarseerPhysics.SamplesFramework
get { return 1f - TransitionPosition; } get { return 1f - TransitionPosition; }
} }
/// <summary> /// <summary>
/// Gets the current screen transition state. /// Gets the current screen transition state.
/// </summary> /// </summary>
public ScreenState ScreenState { get; protected set; } public ScreenState ScreenState
{
get { return screenState; }
protected set { screenState = value; }
}
ScreenState screenState = ScreenState.TransitionOn;
/// <summary> /// <summary>
/// There are two possible reasons why a screen might be transitioning /// There are two possible reasons why a screen might be transitioning
@ -103,9 +122,14 @@ namespace FarseerPhysics.SamplesFramework
/// if set, the screen will automatically remove itself as soon as the /// if set, the screen will automatically remove itself as soon as the
/// transition finishes. /// transition finishes.
/// </summary> /// </summary>
public bool IsExiting { get; protected internal set; } public bool IsExiting
{
get { return isExiting; }
protected internal set { isExiting = value; }
}
bool isExiting = false;
public bool AlwaysHasFocus = false;
/// <summary> /// <summary>
/// Checks whether this screen is active and can respond to user input. /// Checks whether this screen is active and can respond to user input.
@ -114,16 +138,43 @@ namespace FarseerPhysics.SamplesFramework
{ {
get get
{ {
return !_otherScreenHasFocus && return !otherScreenHasFocus &&
(ScreenState == ScreenState.TransitionOn || (screenState == ScreenState.TransitionOn ||
ScreenState == ScreenState.Active); screenState == ScreenState.Active);
} }
} }
bool otherScreenHasFocus;
/// <summary> /// <summary>
/// Gets the manager that this screen belongs to. /// Gets the manager that this screen belongs to.
/// </summary> /// </summary>
public ScreenManager ScreenManager { get; internal set; } public ScreenManager ScreenManager
{
get { return screenManager; }
internal set { screenManager = value; }
}
ScreenManager screenManager;
/// <summary>
/// Gets the index of the player who is currently controlling this screen,
/// or null if it is accepting input from any player. This is used to lock
/// the game to a specific player profile. The main menu responds to input
/// from any connected gamepad, but whichever player makes a selection from
/// this menu is given control over all subsequent screens, so other gamepads
/// are inactive until the controlling player returns to the main menu.
/// </summary>
public PlayerIndex? ControllingPlayer
{
get { return controllingPlayer; }
internal set { controllingPlayer = value; }
}
PlayerIndex? controllingPlayer;
/// <summary> /// <summary>
/// Gets the gestures the screen is interested in. Screens should be as specific /// Gets the gestures the screen is interested in. Screens should be as specific
@ -134,10 +185,10 @@ namespace FarseerPhysics.SamplesFramework
/// </summary> /// </summary>
public GestureType EnabledGestures public GestureType EnabledGestures
{ {
get { return _enabledGestures; } get { return enabledGestures; }
protected set protected set
{ {
_enabledGestures = value; enabledGestures = value;
// the screen manager handles this during screen changes, but // the screen manager handles this during screen changes, but
// if this screen is active and the gesture types are changing, // if this screen is active and the gesture types are changing,
@ -149,36 +200,62 @@ namespace FarseerPhysics.SamplesFramework
} }
} }
/// <summary> GestureType enabledGestures = GestureType.None;
/// Load graphics content for the screen.
/// </summary>
public virtual void LoadContent()
{
}
/// <summary> /// <summary>
/// Unload content for the screen. /// Gets whether or not this screen is serializable. If this is true,
/// the screen will be recorded into the screen manager's state and
/// its Serialize and Deserialize methods will be called as appropriate.
/// If this is false, the screen will be ignored during serialization.
/// By default, all screens are assumed to be serializable.
/// </summary> /// </summary>
public virtual void UnloadContent() public bool IsSerializable
{ {
get { return isSerializable; }
protected set { isSerializable = value; }
} }
bool isSerializable = true;
/// <summary>
/// Activates the screen. Called when the screen is added to the screen manager or if the game resumes
/// from being paused or tombstoned.
/// </summary>
/// <param name="instancePreserved">
/// True if the game was preserved during deactivation, false if the screen is just being added or if the game was tombstoned.
/// On Xbox and Windows this will always be false.
/// </param>
public virtual void Activate(bool instancePreserved) { }
/// <summary>
/// Deactivates the screen. Called when the game is being deactivated due to pausing or tombstoning.
/// </summary>
public virtual void Deactivate() { }
/// <summary>
/// Unload content for the screen. Called when the screen is removed from the screen manager.
/// </summary>
public virtual void Unload() { }
/// <summary> /// <summary>
/// Allows the screen to run logic, such as updating the transition position. /// Allows the screen to run logic, such as updating the transition position.
/// Unlike HandleInput, this method is called regardless of whether the screen /// Unlike HandleInput, this method is called regardless of whether the screen
/// is active, hidden, or in the middle of a transition. /// is active, hidden, or in the middle of a transition.
/// </summary> /// </summary>
public virtual void Update(GameTime gameTime, bool otherScreenHasFocus, public virtual void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
bool coveredByOtherScreen)
{ {
_otherScreenHasFocus = otherScreenHasFocus; this.otherScreenHasFocus = otherScreenHasFocus;
if (IsExiting) if (isExiting)
{ {
// If the screen is going away to die, it should transition off. // If the screen is going away to die, it should transition off.
ScreenState = ScreenState.TransitionOff; screenState = ScreenState.TransitionOff;
if (!UpdateTransition(gameTime, TransitionOffTime, 1)) if (!UpdateTransition(gameTime, transitionOffTime, 1))
{ {
// When the transition finishes, remove the screen. // When the transition finishes, remove the screen.
ScreenManager.RemoveScreen(this); ScreenManager.RemoveScreen(this);
@ -187,59 +264,55 @@ namespace FarseerPhysics.SamplesFramework
else if (coveredByOtherScreen) else if (coveredByOtherScreen)
{ {
// If the screen is covered by another, it should transition off. // If the screen is covered by another, it should transition off.
if (UpdateTransition(gameTime, TransitionOffTime, 1)) if (UpdateTransition(gameTime, transitionOffTime, 1))
{ {
// Still busy transitioning. // Still busy transitioning.
ScreenState = ScreenState.TransitionOff; screenState = ScreenState.TransitionOff;
} }
else else
{ {
// Transition finished! // Transition finished!
ScreenState = ScreenState.Hidden; screenState = ScreenState.Hidden;
} }
} }
else else
{ {
// Otherwise the screen should transition on and become active. // Otherwise the screen should transition on and become active.
if (UpdateTransition(gameTime, TransitionOnTime, -1)) if (UpdateTransition(gameTime, transitionOnTime, -1))
{ {
// Still busy transitioning. // Still busy transitioning.
ScreenState = ScreenState.TransitionOn; screenState = ScreenState.TransitionOn;
} }
else else
{ {
// Transition finished! // Transition finished!
ScreenState = ScreenState.Active; screenState = ScreenState.Active;
} }
} }
} }
/// <summary> /// <summary>
/// Helper for updating the screen transition position. /// Helper for updating the screen transition position.
/// </summary> /// </summary>
private bool UpdateTransition(GameTime gameTime, TimeSpan time, int direction) bool UpdateTransition(GameTime gameTime, TimeSpan time, int direction)
{ {
// How much should we move by? // How much should we move by?
float transitionDelta; float transitionDelta;
if (time == TimeSpan.Zero) if (time == TimeSpan.Zero)
{ transitionDelta = 1;
transitionDelta = 1f;
}
else else
{ transitionDelta = (float)(gameTime.ElapsedGameTime.TotalMilliseconds / time.TotalMilliseconds);
transitionDelta = (float)(gameTime.ElapsedGameTime.TotalMilliseconds /
time.TotalMilliseconds);
}
// Update the transition position. // Update the transition position.
TransitionPosition += transitionDelta * direction; transitionPosition += transitionDelta * direction;
// Did we reach the end of the transition? // Did we reach the end of the transition?
if (((direction < 0) && (TransitionPosition <= 0)) || if (((direction < 0) && (transitionPosition <= 0)) ||
((direction > 0) && (TransitionPosition >= 1))) ((direction > 0) && (transitionPosition >= 1)))
{ {
TransitionPosition = MathHelper.Clamp(TransitionPosition, 0, 1); transitionPosition = MathHelper.Clamp(transitionPosition, 0, 1);
return false; return false;
} }
@ -247,30 +320,29 @@ namespace FarseerPhysics.SamplesFramework
return true; return true;
} }
/// <summary> /// <summary>
/// Allows the screen to handle user input. Unlike Update, this method /// Allows the screen to handle user input. Unlike Update, this method
/// is only called when the screen is active, and not when some other /// is only called when the screen is active, and not when some other
/// screen has taken the focus. /// screen has taken the focus.
/// </summary> /// </summary>
public virtual void HandleInput(InputHelper input, GameTime gameTime) public virtual void HandleInput(GameTime gameTime, InputState input) { }
{
}
/// <summary> /// <summary>
/// This is called when the screen should draw itself. /// This is called when the screen should draw itself.
/// </summary> /// </summary>
public virtual void Draw(GameTime gameTime) public virtual void Draw(GameTime gameTime) { }
{
}
/// <summary> /// <summary>
/// Tells the screen to go away. Unlike ScreenManager.RemoveScreen, which /// Tells the screen to go away. Unlike ScreenManager.RemoveScreen, which
/// instantly kills the screen, this method respects the transition timings /// instantly kills the screen, this method respects the transition timings
/// and will give the screen a chance to gradually transition off. /// and will give the screen a chance to gradually transition off.
/// </summary> /// </summary>
public virtual void ExitScreen() public void ExitScreen()
{ {
if (TransitionOffTime == TimeSpan.Zero && this.TransitionPosition == 0 && this.TransitionAlpha == 1) if (TransitionOffTime == TimeSpan.Zero)
{ {
// If the screen has a zero transition time, remove it immediately. // If the screen has a zero transition time, remove it immediately.
ScreenManager.RemoveScreen(this); ScreenManager.RemoveScreen(this);
@ -278,8 +350,8 @@ namespace FarseerPhysics.SamplesFramework
else else
{ {
// Otherwise flag that it should transition off and then exit. // Otherwise flag that it should transition off and then exit.
IsExiting = true; isExiting = true;
} }
} }
} }
} }

View File

@ -3,6 +3,7 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch; using Microsoft.Xna.Framework.Input.Touch;
using GameStateManagement;
namespace FarseerPhysics.SamplesFramework namespace FarseerPhysics.SamplesFramework
{ {

View File

@ -3,8 +3,9 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
using FarseerPhysics.SamplesFramework;
namespace FarseerPhysics.SamplesFramework namespace GameStateManagement
{ {
public class LogoScreen : GameScreen public class LogoScreen : GameScreen
{ {
@ -29,34 +30,38 @@ namespace FarseerPhysics.SamplesFramework
/// used the shared ContentManager provided by the Game class, the content /// used the shared ContentManager provided by the Game class, the content
/// would remain loaded forever. /// would remain loaded forever.
/// </summary> /// </summary>
public override void LoadContent() public override void Activate(bool instancePreserved)
{ {
if (_content == null) if (!instancePreserved)
{ {
_content = new ContentManager(ScreenManager.Game.Services, "Content"); if (_content == null)
{
_content = new ContentManager(ScreenManager.Game.Services, "Content");
}
_farseerLogoTexture = _content.Load<Texture2D>("Common/logo");
Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
int rectHeight = (int)(viewport.Height * LogoScreenHeightRatio);
int rectWidth = (int)(rectHeight * LogoWidthHeightRatio);
int posX = viewport.Bounds.Center.X - rectWidth / 2;
int posY = viewport.Bounds.Center.Y - rectHeight / 2;
_destination = new Rectangle(posX, posY, rectWidth, rectHeight);
} }
_farseerLogoTexture = _content.Load<Texture2D>("Common/logo");
Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
int rectHeight = (int)(viewport.Height * LogoScreenHeightRatio);
int rectWidth = (int)(rectHeight * LogoWidthHeightRatio);
int posX = viewport.Bounds.Center.X - rectWidth / 2;
int posY = viewport.Bounds.Center.Y - rectHeight / 2;
_destination = new Rectangle(posX, posY, rectWidth, rectHeight);
} }
/// <summary> /// <summary>
/// Unloads graphics content for this screen. /// Unloads graphics content for this screen.
/// </summary> /// </summary>
public override void UnloadContent() public override void Unload()
{ {
_content.Unload(); _content.Unload();
} }
public override void HandleInput(InputHelper input, GameTime gameTime) public override void HandleInput(GameTime gameTime, InputState input)
{ {
//input.
if (input.KeyboardState.GetPressedKeys().Length > 0 || if (input.KeyboardState.GetPressedKeys().Length > 0 ||
input.GamePadState.IsButtonDown(Buttons.A | Buttons.Start | Buttons.Back) || input.GamePadState.IsButtonDown(Buttons.A | Buttons.Start | Buttons.Back) ||
input.MouseState.LeftButton == ButtonState.Pressed) input.MouseState.LeftButton == ButtonState.Pressed)

View File

@ -2,7 +2,7 @@
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
namespace FarseerPhysics.SamplesFramework namespace GameStateManagement
{ {
/// <summary> /// <summary>
/// Helper class represents a single entry in a MenuScreen. By default this /// Helper class represents a single entry in a MenuScreen. By default this

View File

@ -1,39 +1,35 @@
using System; #region File Description
//-----------------------------------------------------------------------------
// MenuEntry.cs
//
// XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion
#region Using Statements
using System;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using GameStateManagement;
#endregion
namespace FarseerPhysics.SamplesFramework namespace GameStateManagement
{ {
public enum EntryType
{
Screen,
Separator,
ExitItem,
BackItem
}
/// <summary> /// <summary>
/// Helper class represents a single entry in a MenuScreen. By default this /// Helper class represents a single entry in a MenuScreen. By default this
/// just draws the entry text string, but it can be customized to display menu /// just draws the entry text string, but it can be customized to display menu
/// entries in different ways. This also provides an event that will be raised /// entries in different ways. This also provides an event that will be raised
/// when the menu entry is selected. /// when the menu entry is selected.
/// </summary> /// </summary>
public sealed class MenuEntry class MenuEntry
{ {
private float _alpha; #region Fields
private Vector2 _baseOrigin;
private float _height;
private MenuScreen _menu;
/// <summary> /// <summary>
/// The position at which the entry is drawn. This is set by the MenuScreen /// The text rendered for this entry.
/// each frame in Update.
/// </summary> /// </summary>
private Vector2 _position; string text;
private float _scale;
private GameScreen _screen;
/// <summary> /// <summary>
/// Tracks a fading selection effect on the entry. /// Tracks a fading selection effect on the entry.
@ -41,28 +37,17 @@ namespace FarseerPhysics.SamplesFramework
/// <remarks> /// <remarks>
/// The entries transition out of the selection effect when they are deselected. /// The entries transition out of the selection effect when they are deselected.
/// </remarks> /// </remarks>
private float _selectionFade; float selectionFade;
/// <summary> /// <summary>
/// The text rendered for this entry. /// The position at which the entry is drawn. This is set by the MenuScreen
/// each frame in Update.
/// </summary> /// </summary>
private string _text; Vector2 position;
private EntryType _type; #endregion
private float _width;
/// <summary> #region Properties
/// Constructs a new menu entry with the specified text.
/// </summary>
public MenuEntry(MenuScreen menu, string text, EntryType type, GameScreen screen)
{
_text = text;
_screen = screen;
_type = type;
_menu = menu;
_scale = 0.9f;
_alpha = 1.0f;
}
/// <summary> /// <summary>
@ -70,124 +55,138 @@ namespace FarseerPhysics.SamplesFramework
/// </summary> /// </summary>
public string Text public string Text
{ {
get { return _text; } get { return text; }
set { _text = value; } set { text = value; }
} }
/// <summary> /// <summary>
/// Gets or sets the position at which to draw this menu entry. /// Gets or sets the position at which to draw this menu entry.
/// </summary> /// </summary>
public Vector2 Position public Vector2 Position
{ {
get { return _position; } get { return position; }
set { _position = value; } set { position = value; }
} }
public float Alpha
#endregion
#region Events
/// <summary>
/// Event raised when the menu entry is selected.
/// </summary>
public event EventHandler<PlayerIndexEventArgs> Selected;
/// <summary>
/// Method for raising the Selected event.
/// </summary>
protected internal virtual void OnSelectEntry(PlayerIndex playerIndex)
{ {
get { return _alpha; } if (Selected != null)
set { _alpha = value; } Selected(this, new PlayerIndexEventArgs(playerIndex));
} }
public GameScreen Screen
#endregion
#region Initialization
/// <summary>
/// Constructs a new menu entry with the specified text.
/// </summary>
public MenuEntry(string text)
{ {
get { return _screen; } this.text = text;
} }
public void Initialize()
{
SpriteFont font = _menu.ScreenManager.Fonts.MenuSpriteFont;
_baseOrigin = new Vector2(font.MeasureString(Text).X, font.MeasureString("M").Y) * 0.5f; #endregion
_width = font.MeasureString(Text).X * 0.8f; #region Update and Draw
_height = font.MeasureString("M").Y * 0.8f;
}
public bool IsExitItem()
{
return _type == EntryType.ExitItem;
}
public bool IsSelectable()
{
return _type != EntryType.Separator;
}
public bool IsBackItem()
{
return _type == EntryType.BackItem;
}
/// <summary> /// <summary>
/// Updates the menu entry. /// Updates the menu entry.
/// </summary> /// </summary>
public void Update(bool isSelected, GameTime gameTime) public virtual void Update(MenuScreen screen, bool isSelected, GameTime gameTime)
{ {
// there is no such thing as a selected item on Windows Phone, so we always // there is no such thing as a selected item on Windows Phone, so we always
// force isSelected to be false // force isSelected to be false
#if WINDOWS_PHONE #if WINDOWS_PHONE
isSelected = false; isSelected = false;
#endif #endif
// When the menu selection changes, entries gradually fade between // When the menu selection changes, entries gradually fade between
// their selected and deselected appearance, rather than instantly // their selected and deselected appearance, rather than instantly
// popping to the new state. // popping to the new state.
if (_type != EntryType.Separator) float fadeSpeed = (float)gameTime.ElapsedGameTime.TotalSeconds * 4;
{
float fadeSpeed = (float)gameTime.ElapsedGameTime.TotalSeconds * 4; if (isSelected)
if (isSelected) selectionFade = Math.Min(selectionFade + fadeSpeed, 1);
{ else
_selectionFade = Math.Min(_selectionFade + fadeSpeed, 1f); selectionFade = Math.Max(selectionFade - fadeSpeed, 0);
}
else
{
_selectionFade = Math.Max(_selectionFade - fadeSpeed, 0f);
}
_scale = 0.7f + 0.1f * _selectionFade;
}
} }
/// <summary> /// <summary>
/// Draws the menu entry. This can be overridden to customize the appearance. /// Draws the menu entry. This can be overridden to customize the appearance.
/// </summary> /// </summary>
public void Draw() public virtual void Draw(MenuScreen screen, bool isSelected, GameTime gameTime)
{ {
SpriteFont font = _menu.ScreenManager.Fonts.MenuSpriteFont; // there is no such thing as a selected item on Windows Phone, so we always
SpriteBatch batch = _menu.ScreenManager.SpriteBatch; // force isSelected to be false
#if WINDOWS_PHONE
isSelected = false;
#endif
Color color; // Draw the selected entry in yellow, otherwise white.
if (_type == EntryType.Separator) Color color = isSelected ? Color.Yellow : Color.White;
{
color = Color.DarkOrange; // Pulsate the size of the selected menu entry.
} double time = gameTime.TotalGameTime.TotalSeconds;
else
{ float pulsate = (float)Math.Sin(time * 6) + 1;
// Draw the selected entry in yellow, otherwise white
color = Color.Lerp(Color.White, new Color(255, 210, 0), _selectionFade); float scale = 1 + pulsate * 0.05f * selectionFade;
}
color *= _alpha; // Modify the alpha to fade text out during transitions.
color *= screen.TransitionAlpha;
// Draw text, centered on the middle of each line. // Draw text, centered on the middle of each line.
batch.DrawString(font, _text, _position - _baseOrigin * _scale + Vector2.One, ScreenManager screenManager = screen.ScreenManager;
Color.DarkSlateGray * _alpha * _alpha, 0, Vector2.Zero, _scale, SpriteEffects.None, 0); SpriteBatch spriteBatch = screenManager.SpriteBatch;
batch.DrawString(font, _text, _position - _baseOrigin * _scale, color, 0, Vector2.Zero, _scale, SpriteFont font = screenManager.Font;
SpriteEffects.None, 0);
Vector2 origin = new Vector2(0, font.LineSpacing / 2);
spriteBatch.DrawString(font, text, position, color, 0,
origin, scale, SpriteEffects.None, 0);
} }
/// <summary> /// <summary>
/// Queries how much space this menu entry requires. /// Queries how much space this menu entry requires.
/// </summary> /// </summary>
public int GetHeight() public virtual int GetHeight(MenuScreen screen)
{ {
return (int)_height; return screen.ScreenManager.Font.LineSpacing;
} }
/// <summary> /// <summary>
/// Queries how wide the entry is, used for centering on the screen. /// Queries how wide the entry is, used for centering on the screen.
/// </summary> /// </summary>
public int GetWidth() public virtual int GetWidth(MenuScreen screen)
{ {
return (int)_width; return (int)screen.ScreenManager.Font.MeasureString(Text).X;
} }
#endregion
} }
} }

View File

@ -1,235 +1,169 @@
#region File Description
//-----------------------------------------------------------------------------
// MenuScreen.cs
//
// XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion
#region Using Statements
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Input;
using FarseerPhysics.SamplesFramework;
#endregion
namespace FarseerPhysics.SamplesFramework namespace GameStateManagement
{ {
/// <summary> /// <summary>
/// Base class for screens that contain a menu of options. The user can /// Base class for screens that contain a menu of options. The user can
/// move up and down to select an entry, or cancel to back out of the screen. /// move up and down to select an entry, or cancel to back out of the screen.
/// </summary> /// </summary>
public class MenuScreen : GameScreen abstract class MenuScreen : GameScreen
{ {
#if WINDOWS || XBOX #region Fields
protected const float NumEntries = 15;
#elif WINDOWS_PHONE
protected const float NumEntries = 9;
#endif
protected List<MenuEntry> _menuEntries = new List<MenuEntry>();
protected string _menuTitle;
protected Vector2 _titlePosition;
protected Vector2 _titleOrigin;
protected int _selectedEntry;
protected float _menuBorderTop;
protected float _menuBorderBottom;
protected float _menuBorderMargin;
protected float _menuOffset;
protected float _maxOffset;
protected Texture2D _texScrollButton; List<MenuEntry> menuEntries = new List<MenuEntry>();
protected Texture2D _texSlider; int selectedEntry = 0;
string menuTitle;
InputAction menuUp;
InputAction menuDown;
InputAction menuSelect;
InputAction menuCancel;
#endregion
#region Properties
/// <summary>
/// Gets the list of menu entries, so derived classes can add
/// or change the menu contents.
/// </summary>
protected IList<MenuEntry> MenuEntries
{
get { return menuEntries; }
}
#endregion
#region Initialization
protected MenuButton _scrollUp;
protected MenuButton _scrollDown;
protected MenuButton _scrollSlider;
protected bool _scrollLock;
/// <summary> /// <summary>
/// Constructor. /// Constructor.
/// </summary> /// </summary>
public MenuScreen(string menuTitle) public MenuScreen(string menuTitle)
{ {
_menuTitle = menuTitle; this.menuTitle = menuTitle;
TransitionOnTime = TimeSpan.FromSeconds(0.7); TransitionOnTime = TimeSpan.FromSeconds(0.5);
TransitionOffTime = TimeSpan.FromSeconds(0.7); TransitionOffTime = TimeSpan.FromSeconds(0.5);
HasCursor = true;
menuUp = new InputAction(
new Buttons[] { Buttons.DPadUp, Buttons.LeftThumbstickUp },
new Keys[] { Keys.Up },
true);
menuDown = new InputAction(
new Buttons[] { Buttons.DPadDown, Buttons.LeftThumbstickDown },
new Keys[] { Keys.Down },
true);
menuSelect = new InputAction(
new Buttons[] { Buttons.A, Buttons.Start },
new Keys[] { Keys.Enter, Keys.Space },
true);
menuCancel = new InputAction(
new Buttons[] { Buttons.B, Buttons.Back },
new Keys[] { Keys.Escape },
true);
} }
public void AddMenuItem(string name, EntryType type, GameScreen screen)
{
MenuEntry entry = new MenuEntry(this, name, type, screen);
_menuEntries.Add(entry);
}
public void AddMenuItem(MenuEntry me) #endregion
{
_menuEntries.Add(me);
}
public override void LoadContent() #region Handle Input
{
base.LoadContent();
_texScrollButton = ScreenManager.Content.Load<Texture2D>("Common/arrow");
_texSlider = ScreenManager.Content.Load<Texture2D>("Common/slider");
//Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
//float scrollBarPos = viewport.Width / 2f;
//scrollBarPos -= _texScrollButton.Width + 2f;
InitMenu();
}
public void InitMenu()
{
Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
SpriteFont font = ScreenManager.Fonts.MenuSpriteFont;
float scrollBarPos = viewport.Width / 2f;
for (int i = 0; i < _menuEntries.Count; ++i)
{
_menuEntries[i].Initialize();
scrollBarPos = Math.Min(scrollBarPos,
(viewport.Width - _menuEntries[i].GetWidth()) / 2f);
}
_titleOrigin = font.MeasureString(_menuTitle) / 2f;
_titlePosition = new Vector2(viewport.Width / 2f, font.MeasureString("M").Y / 2f + 10f);
_menuBorderMargin = font.MeasureString("M").Y * 0.8f;
_menuBorderTop = (viewport.Height - _menuBorderMargin * (NumEntries - 1)) / 2f;
_menuBorderBottom = (viewport.Height + _menuBorderMargin * (NumEntries - 1)) / 2f;
_menuOffset = 0f;
_maxOffset = Math.Max(0f, (_menuEntries.Count - NumEntries) * _menuBorderMargin);
_scrollUp = new MenuButton(_texScrollButton, false,
new Vector2(scrollBarPos, _menuBorderTop - _texScrollButton.Height), this);
_scrollDown = new MenuButton(_texScrollButton, true,
new Vector2(scrollBarPos, _menuBorderBottom + _texScrollButton.Height), this);
_scrollSlider = new MenuButton(_texSlider, false, new Vector2(scrollBarPos, _menuBorderTop), this);
_scrollLock = false;
}
/// <summary>
/// Returns the index of the menu entry at the position of the given mouse state.
/// </summary>
/// <returns>Index of menu entry if valid, -1 otherwise</returns>
private int GetMenuEntryAt(Vector2 position)
{
if (this.TransitionPosition == 0f && this.ScreenState == SamplesFramework.ScreenState.Active)
{
int index = 0;
foreach (MenuEntry entry in _menuEntries)
{
float width = entry.GetWidth();
float height = entry.GetHeight();
Rectangle rect = new Rectangle((int)(entry.Position.X - width / 2f),
(int)(entry.Position.Y - height / 2f),
(int)width, (int)height);
if (rect.Contains((int)position.X, (int)position.Y) && entry.Alpha > 0.1f)
{
return index;
}
++index;
}
}
return -1;
}
/// <summary> /// <summary>
/// Responds to user input, changing the selected entry and accepting /// Responds to user input, changing the selected entry and accepting
/// or cancelling the menu. /// or cancelling the menu.
/// </summary> /// </summary>
public override void HandleInput(InputHelper input, GameTime gameTime) public override void HandleInput(GameTime gameTime, InputState input)
{ {
// Mouse or touch on a menu item // For input tests we pass in our ControllingPlayer, which may
int hoverIndex = GetMenuEntryAt(input.Cursor); // either be null (to accept input from any player) or a specific index.
if (hoverIndex > -1 && _menuEntries[hoverIndex].IsSelectable() && !_scrollLock) // 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;
// Move to the previous menu entry?
if (menuUp.Evaluate(input, ControllingPlayer, out playerIndex))
{ {
_selectedEntry = hoverIndex; selectedEntry--;
}
else if (selectedEntry < 0)
{ selectedEntry = menuEntries.Count - 1;
_selectedEntry = -1;
} }
_scrollSlider.Hover = false; // Move to the next menu entry?
if (input.IsCursorValid) if (menuDown.Evaluate(input, ControllingPlayer, out playerIndex))
{ {
_scrollUp.Collide(input.Cursor); selectedEntry++;
_scrollDown.Collide(input.Cursor);
_scrollSlider.Collide(input.Cursor); if (selectedEntry >= menuEntries.Count)
} selectedEntry = 0;
else
{
_scrollUp.Hover = false;
_scrollDown.Hover = false;
_scrollLock = false;
} }
// Accept or cancel the menu? if (menuSelect.Evaluate(input, ControllingPlayer, out playerIndex))
if (input.IsMenuSelect() && _selectedEntry != -1)
{ {
if (_menuEntries[_selectedEntry].IsExitItem()) OnSelectEntry(selectedEntry, playerIndex);
{
ScreenManager.Game.Exit();
}
else if (_menuEntries[_selectedEntry].IsBackItem())
{
this.ExitScreen();
}
else if (_menuEntries[_selectedEntry].Screen != null)
{
ScreenManager.AddScreen(_menuEntries[_selectedEntry].Screen);
if (_menuEntries[_selectedEntry].Screen is IDemoScreen)
{
ScreenManager.AddScreen(
new MessageBoxScreen((_menuEntries[_selectedEntry].Screen as IDemoScreen).GetDetails()));
}
}
} }
else if (input.IsMenuCancel()) else if (menuCancel.Evaluate(input, ControllingPlayer, out playerIndex))
{ {
if (this.ScreenState == SamplesFramework.ScreenState.Active && this.TransitionPosition == 0 && this.TransitionAlpha == 1) OnCancel(playerIndex);
{
//GameScreen[] screens = ScreenManager.GetScreens();
//if (screens[screens.Length - 1] is BackgroundScreen ||| screens.Length )
// ScreenManager.Game.Exit();
//if (ScreenManager.GetScreens().Length == 2)
// ScreenManager.Game.Exit();
//else
this.ExitScreen();
}
//ScreenManager.Game.Exit();
}
if (input.IsMenuPressed())
{
if (_scrollUp.Hover)
{
_menuOffset = Math.Max(_menuOffset - 200f * (float)gameTime.ElapsedGameTime.TotalSeconds, 0f);
_scrollLock = false;
}
if (_scrollDown.Hover)
{
_menuOffset = Math.Min(_menuOffset + 200f * (float)gameTime.ElapsedGameTime.TotalSeconds, _maxOffset);
_scrollLock = false;
}
if (_scrollSlider.Hover)
{
_scrollLock = true;
}
}
if (input.IsMenuReleased())
{
_scrollLock = false;
}
if (_scrollLock)
{
_scrollSlider.Hover = true;
_menuOffset = Math.Max(Math.Min(((input.Cursor.Y - _menuBorderTop) / (_menuBorderBottom - _menuBorderTop)) * _maxOffset, _maxOffset), 0f);
} }
} }
/// <summary>
/// Handler for when the user has chosen a menu entry.
/// </summary>
protected virtual void OnSelectEntry(int entryIndex, PlayerIndex playerIndex)
{
menuEntries[entryIndex].OnSelectEntry(playerIndex);
}
/// <summary>
/// Handler for when the user has cancelled the menu.
/// </summary>
protected virtual void OnCancel(PlayerIndex playerIndex)
{
ExitScreen();
}
/// <summary>
/// Helper overload makes it easy to use OnCancel as a MenuEntry event handler.
/// </summary>
protected void OnCancel(object sender, PlayerIndexEventArgs e)
{
OnCancel(e.PlayerIndex);
}
#endregion
#region Update and Draw
/// <summary> /// <summary>
/// Allows the screen the chance to position the menu entries. By default /// Allows the screen the chance to position the menu entries. By default
/// all menu entries are lined up in a vertical list, centered on the screen. /// all menu entries are lined up in a vertical list, centered on the screen.
@ -241,69 +175,49 @@ namespace FarseerPhysics.SamplesFramework
// the movement slow down as it nears the end). // the movement slow down as it nears the end).
float transitionOffset = (float)Math.Pow(TransitionPosition, 2); float transitionOffset = (float)Math.Pow(TransitionPosition, 2);
Vector2 position = Vector2.Zero; // start at Y = 175; each X value is generated per entry
position.Y = _menuBorderTop - _menuOffset; Vector2 position = new Vector2(0f, 175f);
// update each menu entry's location in turn // update each menu entry's location in turn
for (int i = 0; i < _menuEntries.Count; ++i) for (int i = 0; i < menuEntries.Count; i++)
{ {
position.X = ScreenManager.GraphicsDevice.Viewport.Width / 2f; MenuEntry menuEntry = menuEntries[i];
// each entry is to be centered horizontally
position.X = ScreenManager.GraphicsDevice.Viewport.Width / 2 - menuEntry.GetWidth(this) / 2;
if (ScreenState == ScreenState.TransitionOn) if (ScreenState == ScreenState.TransitionOn)
{
position.X -= transitionOffset * 256; position.X -= transitionOffset * 256;
}
else else
{ position.X += transitionOffset * 512;
position.X += transitionOffset * 256;
}
// set the entry's position // set the entry's position
_menuEntries[i].Position = position; menuEntry.Position = position;
if (position.Y < _menuBorderTop)
{
_menuEntries[i].Alpha = 1f -
Math.Min(_menuBorderTop - position.Y, _menuBorderMargin) / _menuBorderMargin;
}
else if (position.Y > _menuBorderBottom)
{
_menuEntries[i].Alpha = 1f -
Math.Min(position.Y - _menuBorderBottom, _menuBorderMargin) /
_menuBorderMargin;
}
else
{
_menuEntries[i].Alpha = 1f;
}
// move down for the next entry the size of this entry // move down for the next entry the size of this entry
position.Y += _menuEntries[i].GetHeight(); position.Y += menuEntry.GetHeight(this);
} }
Vector2 scrollPos = _scrollSlider.Position;
scrollPos.Y = MathHelper.Lerp(_menuBorderTop, _menuBorderBottom, _menuOffset / _maxOffset);
_scrollSlider.Position = scrollPos;
} }
/// <summary> /// <summary>
/// Updates the menu. /// Updates the menu.
/// </summary> /// </summary>
public override void Update(GameTime gameTime, bool otherScreenHasFocus, public override void Update(GameTime gameTime, bool otherScreenHasFocus,
bool coveredByOtherScreen) bool coveredByOtherScreen)
{ {
base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
// Update each nested MenuEntry object. // Update each nested MenuEntry object.
for (int i = 0; i < _menuEntries.Count; ++i) for (int i = 0; i < menuEntries.Count; i++)
{ {
bool isSelected = IsActive && (i == _selectedEntry); bool isSelected = IsActive && (i == selectedEntry);
_menuEntries[i].Update(isSelected, gameTime);
}
_scrollUp.Update(gameTime); menuEntries[i].Update(this, isSelected, gameTime);
_scrollDown.Update(gameTime); }
_scrollSlider.Update(gameTime);
} }
/// <summary> /// <summary>
/// Draws the menu. /// Draws the menu.
/// </summary> /// </summary>
@ -312,30 +226,42 @@ namespace FarseerPhysics.SamplesFramework
// make sure our entries are in the right place before we draw them // make sure our entries are in the right place before we draw them
UpdateMenuEntryLocations(); UpdateMenuEntryLocations();
GraphicsDevice graphics = ScreenManager.GraphicsDevice;
SpriteBatch spriteBatch = ScreenManager.SpriteBatch; SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
SpriteFont font = ScreenManager.Fonts.MenuSpriteFont; SpriteFont font = ScreenManager.Font;
spriteBatch.Begin(); spriteBatch.Begin();
// Draw each menu entry in turn. // Draw each menu entry in turn.
for (int i = 0; i < _menuEntries.Count; ++i) for (int i = 0; i < menuEntries.Count; i++)
{ {
bool isSelected = IsActive && (i == _selectedEntry); MenuEntry menuEntry = menuEntries[i];
_menuEntries[i].Draw();
bool isSelected = IsActive && (i == selectedEntry);
menuEntry.Draw(this, isSelected, gameTime);
} }
// Make the menu slide into place during transitions, using a // Make the menu slide into place during transitions, using a
// power curve to make things look more interesting (this makes // power curve to make things look more interesting (this makes
// the movement slow down as it nears the end). // the movement slow down as it nears the end).
Vector2 transitionOffset = new Vector2(0f, (float)Math.Pow(TransitionPosition, 2) * 100f); float transitionOffset = (float)Math.Pow(TransitionPosition, 2);
// Draw the menu title centered on the screen
Vector2 titlePosition = new Vector2(graphics.Viewport.Width / 2, 80);
Vector2 titleOrigin = font.MeasureString(menuTitle) / 2;
Color titleColor = new Color(192, 192, 192) * TransitionAlpha;
float titleScale = 1.25f;
titlePosition.Y -= transitionOffset * 100;
spriteBatch.DrawString(font, menuTitle, titlePosition, titleColor, 0,
titleOrigin, titleScale, SpriteEffects.None, 0);
spriteBatch.DrawString(font, _menuTitle, _titlePosition - transitionOffset + Vector2.One * 2f, Color.Black, 0,
_titleOrigin, 1f, SpriteEffects.None, 0);
spriteBatch.DrawString(font, _menuTitle, _titlePosition - transitionOffset, new Color(255, 210, 0), 0,
_titleOrigin, 1f, SpriteEffects.None, 0);
_scrollUp.Draw();
_scrollSlider.Draw();
_scrollDown.Draw();
spriteBatch.End(); spriteBatch.End();
} }
#endregion
} }
} }

View File

@ -1,36 +1,87 @@
using System; #region File Description
//-----------------------------------------------------------------------------
// MessageBoxScreen.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion
#region Using Statements
using System;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using GameStateManagement;
#endregion
namespace FarseerPhysics.SamplesFramework namespace GameStateManagement
{ {
/// <summary> /// <summary>
/// A popup message box screen, used to display "are you sure?" /// A popup message box screen, used to display "are you sure?"
/// confirmation messages. /// confirmation messages.
/// </summary> /// </summary>
public class MessageBoxScreen : GameScreen class MessageBoxScreen : GameScreen
{ {
protected Rectangle _backgroundRectangle; #region Fields
protected Texture2D _gradientTexture;
protected string _message;
protected Vector2 _textPosition;
string message;
Texture2D gradientTexture;
InputAction menuSelect;
InputAction menuCancel;
#endregion
#region Events
public event EventHandler<PlayerIndexEventArgs> Accepted;
public event EventHandler<PlayerIndexEventArgs> Cancelled;
#endregion
#region Initialization
/// <summary>
/// Constructor automatically includes the standard "A=ok, B=cancel"
/// usage text prompt.
/// </summary>
public MessageBoxScreen(string message) public MessageBoxScreen(string message)
: this(message, true)
{ }
/// <summary>
/// Constructor lets the caller specify whether to include the standard
/// "A=ok, B=cancel" usage text prompt.
/// </summary>
public MessageBoxScreen(string message, bool includeUsageText)
{ {
_message = message; const string usageText = "\nA button, Space, Enter = ok" +
"\nB button, Esc = cancel";
if (includeUsageText)
this.message = message + usageText;
else
this.message = message;
IsPopup = true; IsPopup = true;
HasCursor = true;
TransitionOnTime = TimeSpan.FromSeconds(0.4); TransitionOnTime = TimeSpan.FromSeconds(0.2);
TransitionOffTime = TimeSpan.FromSeconds(0.4); TransitionOffTime = TimeSpan.FromSeconds(0.2);
menuSelect = new InputAction(
new Buttons[] { Buttons.A, Buttons.Start },
new Keys[] { Keys.Space, Keys.Enter },
true);
menuCancel = new InputAction(
new Buttons[] { Buttons.B, Buttons.Back },
new Keys[] { Keys.Escape, Keys.Back },
true);
} }
public MessageBoxScreen()
{
IsPopup = true;
}
/// <summary> /// <summary>
/// Loads graphics content for this screen. This uses the shared ContentManager /// Loads graphics content for this screen. This uses the shared ContentManager
@ -38,62 +89,98 @@ namespace FarseerPhysics.SamplesFramework
/// Whenever a subsequent MessageBoxScreen tries to load this same content, /// Whenever a subsequent MessageBoxScreen tries to load this same content,
/// it will just get back another reference to the already loaded data. /// it will just get back another reference to the already loaded data.
/// </summary> /// </summary>
public override void LoadContent() public override void Activate(bool instancePreserved)
{ {
SpriteFont font = ScreenManager.Fonts.DetailsFont; if (!instancePreserved)
ContentManager content = ScreenManager.Game.Content; {
_gradientTexture = content.Load<Texture2D>("Common/popup"); ContentManager content = ScreenManager.Game.Content;
gradientTexture = content.Load<Texture2D>("gradient");
// Center the message text in the viewport. }
Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
Vector2 viewportSize = new Vector2(viewport.Width, viewport.Height);
Vector2 textSize = font.MeasureString(_message);
_textPosition = (viewportSize - textSize) / 2;
// The background includes a border somewhat larger than the text itself.
const int hPad = 32;
const int vPad = 16;
_backgroundRectangle = new Rectangle((int)_textPosition.X - hPad,
(int)_textPosition.Y - vPad,
(int)textSize.X + hPad * 2,
(int)textSize.Y + vPad * 2);
} }
#endregion
#region Handle Input
/// <summary> /// <summary>
/// Responds to user input, accepting or cancelling the message box. /// Responds to user input, accepting or cancelling the message box.
/// </summary> /// </summary>
public override void HandleInput(InputHelper input, GameTime gameTime) public override void HandleInput(GameTime gameTime, InputState input)
{ {
PlayerIndex playerIndex;
if (input.IsMenuSelect() || input.IsMenuCancel() || // We pass in our ControllingPlayer, which may either be null (to
input.IsNewMouseButtonPress(MouseButtons.LeftButton)) // accept input from any player) or a specific index. If we pass a null
// controlling player, the InputState helper returns to us which player
// actually provided the input. We pass that through to our Accepted and
// Cancelled events, so they can tell which player triggered them.
if (menuSelect.Evaluate(input, ControllingPlayer, out playerIndex))
{ {
// Raise the accepted event, then exit the message box.
if (Accepted != null)
Accepted(this, new PlayerIndexEventArgs(playerIndex));
ExitScreen();
}
else if (menuCancel.Evaluate(input, ControllingPlayer, out playerIndex))
{
// Raise the cancelled event, then exit the message box.
if (Cancelled != null)
Cancelled(this, new PlayerIndexEventArgs(playerIndex));
ExitScreen(); ExitScreen();
} }
} }
#endregion
#region Draw
/// <summary> /// <summary>
/// Draws the message box. /// Draws the message box.
/// </summary> /// </summary>
public override void Draw(GameTime gameTime) public override void Draw(GameTime gameTime)
{ {
SpriteBatch spriteBatch = ScreenManager.SpriteBatch; SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
SpriteFont font = ScreenManager.Fonts.DetailsFont; SpriteFont font = ScreenManager.Font;
// Darken down any other screens that were drawn beneath the popup.
ScreenManager.FadeBackBufferToBlack(TransitionAlpha * 2 / 3);
// Center the message text in the viewport.
Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
Vector2 viewportSize = new Vector2(viewport.Width, viewport.Height);
Vector2 textSize = font.MeasureString(message);
Vector2 textPosition = (viewportSize - textSize) / 2;
// The background includes a border somewhat larger than the text itself.
const int hPad = 32;
const int vPad = 16;
Rectangle backgroundRectangle = new Rectangle((int)textPosition.X - hPad,
(int)textPosition.Y - vPad,
(int)textSize.X + hPad * 2,
(int)textSize.Y + vPad * 2);
// Fade the popup alpha during transitions. // Fade the popup alpha during transitions.
Color color = Color.White * TransitionAlpha * (2f / 3f); Color color = Color.White * TransitionAlpha;
spriteBatch.Begin(); spriteBatch.Begin();
// Draw the background rectangle. // Draw the background rectangle.
spriteBatch.Draw(_gradientTexture, _backgroundRectangle, color); spriteBatch.Draw(gradientTexture, backgroundRectangle, color);
// Draw the message box text. // Draw the message box text.
spriteBatch.DrawString(font, _message, _textPosition + Vector2.One, Color.Black); spriteBatch.DrawString(font, message, textPosition, color);
spriteBatch.DrawString(font, _message, _textPosition, Color.White);
spriteBatch.End(); spriteBatch.End();
} }
#endregion
} }
} }

View File

@ -6,9 +6,10 @@ using FarseerPhysics.Dynamics.Joints;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
using FarseerPhysics.SamplesFramework;
using Axios.Engine; using Axios.Engine;
namespace FarseerPhysics.SamplesFramework namespace GameStateManagement
{ {
public class PhysicsGameScreen : GameScreen public class PhysicsGameScreen : GameScreen
{ {
@ -47,48 +48,51 @@ namespace FarseerPhysics.SamplesFramework
_agentTorque = torque; _agentTorque = torque;
} }
public override void LoadContent()
public override void Activate(bool instancePreserved)
{ {
base.LoadContent(); if (!instancePreserved)
//We enable diagnostics to show get values for our performance counters.
Settings.EnableDiagnostics = true;
if (World == null)
{ {
World = new World(Vector2.Zero); base.Activate(instancePreserved);
}
else
{
World.Clear();
}
if (DebugView == null) //We enable diagnostics to show get values for our performance counters.
{ Settings.EnableDiagnostics = true;
if (!Axios.Settings.ScreenSaver)
if (World == null)
{ {
DebugView = new DebugViewXNA(World); World = new World(Vector2.Zero);
DebugView.RemoveFlags(DebugViewFlags.Shape); }
DebugView.RemoveFlags(DebugViewFlags.Joint); else
DebugView.DefaultShapeColor = Color.White; {
DebugView.SleepingShapeColor = Color.LightGray; World.Clear();
DebugView.LoadContent(ScreenManager.GraphicsDevice, ScreenManager.Content);
} }
}
if (Camera == null) if (DebugView == null)
{ {
Camera = new Camera2D(ScreenManager.GraphicsDevice); if (!Axios.Settings.ScreenSaver)
} {
else DebugView = new DebugViewXNA(World);
{ DebugView.RemoveFlags(DebugViewFlags.Shape);
Camera.ResetCamera(); DebugView.RemoveFlags(DebugViewFlags.Joint);
} DebugView.DefaultShapeColor = Color.White;
DebugView.SleepingShapeColor = Color.LightGray;
DebugView.LoadContent(ScreenManager.GraphicsDevice, ScreenManager.Content);
}
}
// Loading may take a while... so prevent the game from "catching up" once we finished loading if (Camera == null)
ScreenManager.Game.ResetElapsedTime(); {
Camera = new Camera2D(ScreenManager.GraphicsDevice);
}
else
{
Camera.ResetCamera();
}
// Loading may take a while... so prevent the game from "catching up" once we finished loading
ScreenManager.Game.ResetElapsedTime();
}
} }
public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
@ -110,12 +114,13 @@ namespace FarseerPhysics.SamplesFramework
{ {
} }
public override void HandleInput(InputHelper input, GameTime gameTime) public override void HandleInput(GameTime gameTime, InputState input)
{ {
#if DEBUG #if DEBUG
// Control debug view // Control debug view
if (input.IsNewButtonPress(Buttons.Start)) PlayerIndex player;
if (input.IsNewButtonPress(Buttons.Start, ControllingPlayer.Value, out player))
{ {
EnableOrDisableFlag(DebugViewFlags.Shape); EnableOrDisableFlag(DebugViewFlags.Shape);
EnableOrDisableFlag(DebugViewFlags.DebugPanel); EnableOrDisableFlag(DebugViewFlags.DebugPanel);
@ -126,37 +131,37 @@ namespace FarseerPhysics.SamplesFramework
EnableOrDisableFlag(DebugViewFlags.Controllers); EnableOrDisableFlag(DebugViewFlags.Controllers);
} }
if (input.IsNewKeyPress(Keys.F1)) if (input.IsNewKeyPress(Keys.F1, ControllingPlayer.Value, out player))
{ {
EnableOrDisableFlag(DebugViewFlags.Shape); EnableOrDisableFlag(DebugViewFlags.Shape);
} }
if (input.IsNewKeyPress(Keys.F2)) if (input.IsNewKeyPress(Keys.F2, ControllingPlayer.Value, out player))
{ {
EnableOrDisableFlag(DebugViewFlags.DebugPanel); EnableOrDisableFlag(DebugViewFlags.DebugPanel);
EnableOrDisableFlag(DebugViewFlags.PerformanceGraph); EnableOrDisableFlag(DebugViewFlags.PerformanceGraph);
} }
if (input.IsNewKeyPress(Keys.F3)) if (input.IsNewKeyPress(Keys.F3, ControllingPlayer.Value, out player))
{ {
EnableOrDisableFlag(DebugViewFlags.Joint); EnableOrDisableFlag(DebugViewFlags.Joint);
} }
if (input.IsNewKeyPress(Keys.F4)) if (input.IsNewKeyPress(Keys.F4, ControllingPlayer.Value, out player))
{ {
EnableOrDisableFlag(DebugViewFlags.ContactPoints); EnableOrDisableFlag(DebugViewFlags.ContactPoints);
EnableOrDisableFlag(DebugViewFlags.ContactNormals); EnableOrDisableFlag(DebugViewFlags.ContactNormals);
} }
if (input.IsNewKeyPress(Keys.F5)) if (input.IsNewKeyPress(Keys.F5, ControllingPlayer.Value, out player))
{ {
EnableOrDisableFlag(DebugViewFlags.PolygonPoints); EnableOrDisableFlag(DebugViewFlags.PolygonPoints);
} }
if (input.IsNewKeyPress(Keys.F6)) if (input.IsNewKeyPress(Keys.F6, ControllingPlayer.Value, out player))
{ {
EnableOrDisableFlag(DebugViewFlags.Controllers); EnableOrDisableFlag(DebugViewFlags.Controllers);
} }
if (input.IsNewKeyPress(Keys.F7)) if (input.IsNewKeyPress(Keys.F7, ControllingPlayer.Value, out player))
{ {
EnableOrDisableFlag(DebugViewFlags.CenterOfMass); EnableOrDisableFlag(DebugViewFlags.CenterOfMass);
} }
if (input.IsNewKeyPress(Keys.F8)) if (input.IsNewKeyPress(Keys.F8, ControllingPlayer.Value, out player))
{ {
EnableOrDisableFlag(DebugViewFlags.AABB); EnableOrDisableFlag(DebugViewFlags.AABB);
} }
@ -181,7 +186,7 @@ namespace FarseerPhysics.SamplesFramework
if (input.IsNewButtonPress(Buttons.Back) || input.IsNewKeyPress(Keys.Escape)) if (input.IsNewButtonPress(Buttons.Back) || input.IsNewKeyPress(Keys.Escape))
{ {
if (this.ScreenState == SamplesFramework.ScreenState.Active && this.TransitionPosition == 0 && this.TransitionAlpha == 1) if (this.ScreenState == GameStateManagement.ScreenState.Active && this.TransitionPosition == 0 && this.TransitionAlpha == 1)
{ //Give the screens a chance to transition { //Give the screens a chance to transition
CleanUp(); CleanUp();
@ -191,9 +196,10 @@ namespace FarseerPhysics.SamplesFramework
} }
base.HandleInput(input, gameTime); base.HandleInput(input, gameTime);
} }
public virtual void HandleCursor(InputHelper input) public virtual void HandleCursor(InputState input)
{ {
PlayerIndex player;
Vector2 position = Camera.ConvertScreenToWorld(input.Cursor); Vector2 position = Camera.ConvertScreenToWorld(input.Cursor);
if ((input.IsNewButtonPress(Buttons.A) || if ((input.IsNewButtonPress(Buttons.A) ||
@ -211,8 +217,9 @@ namespace FarseerPhysics.SamplesFramework
} }
} }
if ((input.IsNewButtonRelease(Buttons.A) ||
input.IsNewMouseButtonRelease(MouseButtons.LeftButton)) && if ((input.IsNewButtonRelease(Buttons.A, ControllingPlayer.Value, out player) ||
input.IsNewMouseButtonRelease(MouseButtons.LeftButton, ControllingPlayer.Value, out player)) &&
_fixedMouseJoint != null) _fixedMouseJoint != null)
{ {
World.RemoveJoint(_fixedMouseJoint); World.RemoveJoint(_fixedMouseJoint);

View File

@ -3,9 +3,11 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input.Touch; using Microsoft.Xna.Framework.Input.Touch;
using FarseerPhysics.SamplesFramework;
namespace FarseerPhysics.SamplesFramework namespace GameStateManagement
{ {
/*
/// <summary> /// <summary>
/// The screen manager is a component which manages one or more GameScreen /// The screen manager is a component which manages one or more GameScreen
/// instances. It maintains a stack of screens, calls their Update and Draw /// instances. It maintains a stack of screens, calls their Update and Draw
@ -299,5 +301,5 @@ namespace FarseerPhysics.SamplesFramework
{ {
return _screens.ToArray(); return _screens.ToArray();
} }
} }*/
} }