axiosengine 

axiosengine Commit Details


Date:2012-04-12 22:09:49 (12 years 6 months ago)
Author:nathan@daedalus
Branch:master
Commit:4057123b6e00212e0ecb590cffbe424bcb2f8a1c
Parents: 40b67fb6e8caae127ffae4f64a844a4ad6e2a328
Message:Branching starting code for the new GSM

--HG--
branch : axios-newgsm
Changes:

File differences

axios/Axios_WP7.csproj
190190
191191
192192
193
193194
194195
195196
197
196198
197199
200
198201
202
203
204
199205
206
200207
201208
202209
203210
211
212
213
214
215
204216
217
218
205219
206220
207221
<Compile Include="PrimitiveBatch.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ScreenSystem\BackgroundScreen.cs" />
<Compile Include="ScreenSystem\Button.cs" />
<Compile Include="ScreenSystem\Camera2D.cs" />
<Compile Include="ScreenSystem\ConvertUnits.cs" />
<Compile Include="ScreenSystem\FramerateCounterComponent.cs" />
<Compile Include="ScreenSystem\GameplayScreen.cs" />
<Compile Include="ScreenSystem\GameScreen.cs" />
<Compile Include="ScreenSystem\IDemoScreen.cs" />
<Compile Include="ScreenSystem\InputAction.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\MainMenuScreen.cs" />
<Compile Include="ScreenSystem\MenuButton.cs" />
<Compile Include="ScreenSystem\MenuEntry.cs" />
<Compile Include="ScreenSystem\MenuScreen.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\PlayerIndexEventArgs.cs" />
<Compile Include="ScreenSystem\ScreenManager.cs" />
<Compile Include="ScreenSystem\ScreenManagerComponent.cs" />
<Compile Include="ScreenSystem\SpriteFonts.cs" />
<Compile Include="ScreenSystem\VirtualButton.cs" />
axios/Axios_Windows.csproj
234234
235235
236236
237
237238
238239
239240
241
240242
241243
244
242245
243246
247
248
249
244250
251
245252
246253
247254
248255
256
257
258
259
260
249261
262
263
250264
251265
252266
<Compile Include="PrimitiveBatch.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ScreenSystem\BackgroundScreen.cs" />
<Compile Include="ScreenSystem\Button.cs" />
<Compile Include="ScreenSystem\Camera2D.cs" />
<Compile Include="ScreenSystem\ConvertUnits.cs" />
<Compile Include="ScreenSystem\FramerateCounterComponent.cs" />
<Compile Include="ScreenSystem\GameplayScreen.cs" />
<Compile Include="ScreenSystem\GameScreen.cs" />
<Compile Include="ScreenSystem\IDemoScreen.cs" />
<Compile Include="ScreenSystem\InputAction.cs" />
<Compile Include="ScreenSystem\InputHelper.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\MainMenuScreen.cs" />
<Compile Include="ScreenSystem\MenuButton.cs" />
<Compile Include="ScreenSystem\MenuEntry.cs" />
<Compile Include="ScreenSystem\MenuScreen.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\PlayerIndexEventArgs.cs" />
<Compile Include="ScreenSystem\ScreenManager.cs" />
<Compile Include="ScreenSystem\ScreenManagerComponent.cs" />
<Compile Include="ScreenSystem\SpriteFonts.cs" />
<Compile Include="ScreenSystem\VirtualButton.cs" />
axios/Axios_Windows.csproj.user
11
22
33
4
4
55
66
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ProjectFiles</ProjectView>
<ProjectView>ShowAllFiles</ProjectView>
</PropertyGroup>
</Project>
axios/Axios_Xbox_360.csproj
183183
184184
185185
186
186187
187188
188189
190
189191
190192
193
191194
195
196
197
192198
199
193200
194201
195202
196203
204
205
206
207
208
197209
210
211
198212
199213
200214
<Compile Include="PrimitiveBatch.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ScreenSystem\BackgroundScreen.cs" />
<Compile Include="ScreenSystem\Button.cs" />
<Compile Include="ScreenSystem\Camera2D.cs" />
<Compile Include="ScreenSystem\ConvertUnits.cs" />
<Compile Include="ScreenSystem\FramerateCounterComponent.cs" />
<Compile Include="ScreenSystem\GameplayScreen.cs" />
<Compile Include="ScreenSystem\GameScreen.cs" />
<Compile Include="ScreenSystem\IDemoScreen.cs" />
<Compile Include="ScreenSystem\InputAction.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\MainMenuScreen.cs" />
<Compile Include="ScreenSystem\MenuButton.cs" />
<Compile Include="ScreenSystem\MenuEntry.cs" />
<Compile Include="ScreenSystem\MenuScreen.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\PlayerIndexEventArgs.cs" />
<Compile Include="ScreenSystem\ScreenManager.cs" />
<Compile Include="ScreenSystem\ScreenManagerComponent.cs" />
<Compile Include="ScreenSystem\SpriteFonts.cs" />
<Compile Include="ScreenSystem\VirtualButton.cs" />
axios/Engine/AxiosGameScreen.cs
88
99
1010
11
1112
13
1214
1315
1416
......
158160
159161
160162
161
163
162164
163
164
165
166
167
168
169
165
170166
171167
172168
173
169
170
171
172
174173
175174
176175
using FarseerPhysics.Dynamics;
using FarseerPhysics.SamplesFramework;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using GameStateManagement;
namespace Axios.Engine
{
AxiosLog.Instance.AddLine("Memory usage after cleanup: ", LoggingFlag.DEBUG);
}
public override void ExitScreen()
public override void Activate(bool instancePreserved)
{
base.ExitScreen();
}
public override void LoadContent()
{
base.LoadContent();
base.Activate(instancePreserved);
#if DEBUG
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
}
axios/ScreenSystem/BackgroundScreen.cs
1
1
2
3
4
5
6
7
8
9
10
11
212
13
314
15
16
417
5
18
619
720
821
922
1023
1124
12
25
1326
14
15
16
27
28
29
30
31
32
33
34
1735
18
19
20
21
2236
2337
2438
......
2943
3044
3145
32
46
47
48
49
50
51
52
53
54
3355
34
35
56
57
58
59
3660
37
38
39
40
41
42
43
44
45
46
47
61
62
4863
4964
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
5080
5181
5282
......
5585
5686
5787
58
88
5989
6090
6191
6292
93
6394
6495
6596
6697
6798
68
69
70
71
99
100
101
102
103
104
105
106
107
108
72109
110
111
112
73113
74
114
using System;
#region File Description
//-----------------------------------------------------------------------------
// BackgroundScreen.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.Content;
using Microsoft.Xna.Framework.Graphics;
using GameStateManagement;
#endregion
namespace FarseerPhysics.SamplesFramework
namespace GameStateManagement
{
/// <summary>
/// The background screen sits behind all the other menu screens.
/// It draws a background image that remains fixed in place regardless
/// of whatever transitions the screens on top of it may be doing.
/// </summary>
public class BackgroundScreen : GameScreen
class BackgroundScreen : GameScreen
{
private const float LogoScreenHeightRatio = 0.25f;
private const float LogoScreenBorderRatio = 0.0375f;
private const float LogoWidthHeightRatio = 1.4f;
#region Fields
ContentManager content;
Texture2D backgroundTexture;
#endregion
#region Initialization
private Texture2D _backgroundTexture;
private Rectangle _logoDestination;
//private Texture2D _logoTexture;
private Rectangle _viewport;
/// <summary>
/// Constructor.
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");
_backgroundTexture = ScreenManager.Content.Load<Texture2D>("Common/gradient");
if (!instancePreserved)
{
if (content == null)
content = new ContentManager(ScreenManager.Game.Services, "Content");
Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
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;
backgroundTexture = content.Load<Texture2D>("background");
}
}
/// <summary>
/// Unloads graphics content for this screen.
/// </summary>
public override void Unload()
{
content.Unload();
}
#endregion
#region Update and Draw
/// <summary>
/// Updates the background screen. Unlike most screens, this should not
/// transition off even if it has been covered by another screen: it is
/// Update method wanting to transition off.
/// </summary>
public override void Update(GameTime gameTime, bool otherScreenHasFocus,
bool coveredByOtherScreen)
bool coveredByOtherScreen)
{
base.Update(gameTime, otherScreenHasFocus, false);
}
/// <summary>
/// Draws the background screen.
/// </summary>
public override void Draw(GameTime gameTime)
{
ScreenManager.SpriteBatch.Begin();
ScreenManager.SpriteBatch.Draw(_backgroundTexture, _viewport, Color.White);
//ScreenManager.SpriteBatch.Draw(_logoTexture, _logoDestination, Color.White * 0.6f);
ScreenManager.SpriteBatch.End();
SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
Rectangle fullscreen = new Rectangle(0, 0, viewport.Width, viewport.Height);
spriteBatch.Begin();
spriteBatch.Draw(backgroundTexture, fullscreen,
new Color(TransitionAlpha, TransitionAlpha, TransitionAlpha));
spriteBatch.End();
}
#endregion
}
}
}
axios/ScreenSystem/FramerateCounterComponent.cs
11
22
33
4
45
56
67
using System;
using System.Globalization;
using Microsoft.Xna.Framework;
using GameStateManagement;
namespace FarseerPhysics.SamplesFramework
{
axios/ScreenSystem/GameScreen.cs
11
2
32
4
3
54
6
5
76
87
9
108
119
1210
11
1312
1413
1514
16
15
1716
1817
1918
......
2625
2726
2827
28
2929
3030
3131
......
3535
3636
3737
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
5538
5639
5740
......
5942
6043
6144
62
45
46
47
48
49
50
51
52
6353
6454
6555
6656
6757
68
58
59
60
61
62
63
64
65
6966
7067
7168
7269
7370
74
71
72
73
74
75
76
77
78
7579
7680
7781
7882
7983
8084
81
85
86
87
88
89
90
91
92
8293
8394
8495
......
90101
91102
92103
104
93105
94106
95107
96
108
109
110
111
112
113
114
115
97116
98117
99118
......
103122
104123
105124
106
125
126
127
128
129
130
131
107132
108
109133
110134
111135
......
114138
115139
116140
117
118
119
141
142
143
120144
121145
122146
147
148
149
123150
124151
125152
126
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
127178
128179
129180
......
134185
135186
136187
137
188
138189
139190
140
191
141192
142193
143194
......
149200
150201
151202
203
204
152205
153
206
207
208
209
210
154211
155
212
156213
214
215
157216
158217
218
219
220
159221
160
222
223
161224
162
163
164
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
165243
166244
167245
168246
169247
170248
171
172
249
173250
174
251
175252
176
253
177254
178255
179
256
180257
181
258
182259
183260
184261
......
187264
188265
189266
190
267
191268
192269
193
270
194271
195272
196273
197274
198
275
199276
200277
201278
202279
203280
204
281
205282
206283
207
284
208285
209286
210287
211288
212
289
213290
214291
215292
216293
294
217295
218296
219297
220
298
221299
222300
223301
224302
225303
226
227
228
304
229305
230
231
232
233
306
234307
235308
236
309
237310
238311
239
240
312
313
241314
242
315
243316
244317
245318
......
247320
248321
249322
323
250324
251325
252326
253327
254328
255
256
257
329
330
258331
259332
260333
261334
262
263
264
335
336
265337
266338
267339
268340
269341
270342
271
343
272344
273
345
274346
275347
276348
......
278350
279351
280352
281
353
282354
283355
284356
285
357
#region File Description
//-----------------------------------------------------------------------------
// PlayerIndexEventArgs.cs
// GameScreen.cs
//
// XNA Community Game Platform
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion
using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input.Touch;
namespace FarseerPhysics.SamplesFramework
namespace GameStateManagement
{
/// <summary>
/// Enum describes the screen transition state.
Hidden,
}
/// <summary>
/// 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.
/// </summary>
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>
/// Normally when one screen is brought up over the top of another,
/// the first screen will transition off to make room for the new
/// popup, in which case screens underneath it do not need to bother
/// transitioning off.
/// </summary>
public bool IsPopup { get; protected set; }
public bool IsPopup
{
get { return isPopup; }
protected set { isPopup = value; }
}
bool isPopup = false;
/// <summary>
/// Indicates how long the screen takes to
/// transition on when it is activated.
/// </summary>
public TimeSpan TransitionOnTime { get; protected set; }
public TimeSpan TransitionOnTime
{
get { return transitionOnTime; }
protected set { transitionOnTime = value; }
}
TimeSpan transitionOnTime = TimeSpan.Zero;
/// <summary>
/// Indicates how long the screen takes to
/// transition off when it is deactivated.
/// </summary>
public TimeSpan TransitionOffTime { get; protected set; }
public TimeSpan TransitionOffTime
{
get { return transitionOffTime; }
protected set { transitionOffTime = value; }
}
TimeSpan transitionOffTime = TimeSpan.Zero;
/// <summary>
/// Gets the current position of the screen transition, ranging
/// from zero (fully active, no transition) to one (transitioned
/// fully off to nothing).
/// </summary>
public float TransitionPosition { get; protected set; }
public float TransitionPosition
{
get { return transitionPosition; }
protected set { transitionPosition = value; }
}
float transitionPosition = 1;
/// <summary>
/// Gets the current alpha of the screen transition, ranging
get { return 1f - TransitionPosition; }
}
/// <summary>
/// Gets the current screen transition state.
/// </summary>
public ScreenState ScreenState { get; protected set; }
public ScreenState ScreenState
{
get { return screenState; }
protected set { screenState = value; }
}
ScreenState screenState = ScreenState.TransitionOn;
/// <summary>
/// There are two possible reasons why a screen might be transitioning
/// if set, the screen will automatically remove itself as soon as the
/// transition finishes.
/// </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>
/// Checks whether this screen is active and can respond to user input.
{
get
{
return !_otherScreenHasFocus &&
(ScreenState == ScreenState.TransitionOn ||
ScreenState == ScreenState.Active);
return !otherScreenHasFocus &&
(screenState == ScreenState.TransitionOn ||
screenState == ScreenState.Active);
}
}
bool otherScreenHasFocus;
/// <summary>
/// Gets the manager that this screen belongs to.
/// </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>
/// Gets the gestures the screen is interested in. Screens should be as specific
/// </summary>
public GestureType EnabledGestures
{
get { return _enabledGestures; }
get { return enabledGestures; }
protected set
{
_enabledGestures = value;
enabledGestures = value;
// the screen manager handles this during screen changes, but
// if this screen is active and the gesture types are changing,
}
}
GestureType enabledGestures = GestureType.None;
/// <summary>
/// Load graphics 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>
public virtual void LoadContent()
public bool IsSerializable
{
get { return isSerializable; }
protected set { isSerializable = value; }
}
bool isSerializable = true;
/// <summary>
/// Unload content for the screen.
/// Activates the screen. Called when the screen is added to the screen manager or if the game resumes
/// from being paused or tombstoned.
/// </summary>
public virtual void UnloadContent()
{
}
/// <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>
/// Allows the screen to run logic, such as updating the transition position.
/// Unlike HandleInput, this method is called regardless of whether the screen
/// is active, hidden, or in the middle of a transition.
/// </summary>
public virtual void Update(GameTime gameTime, bool otherScreenHasFocus,
bool coveredByOtherScreen)
public virtual void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
{
_otherScreenHasFocus = otherScreenHasFocus;
this.otherScreenHasFocus = otherScreenHasFocus;
if (IsExiting)
if (isExiting)
{
// 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.
ScreenManager.RemoveScreen(this);
else if (coveredByOtherScreen)
{
// If the screen is covered by another, it should transition off.
if (UpdateTransition(gameTime, TransitionOffTime, 1))
if (UpdateTransition(gameTime, transitionOffTime, 1))
{
// Still busy transitioning.
ScreenState = ScreenState.TransitionOff;
screenState = ScreenState.TransitionOff;
}
else
{
// Transition finished!
ScreenState = ScreenState.Hidden;
screenState = ScreenState.Hidden;
}
}
else
{
// Otherwise the screen should transition on and become active.
if (UpdateTransition(gameTime, TransitionOnTime, -1))
if (UpdateTransition(gameTime, transitionOnTime, -1))
{
// Still busy transitioning.
ScreenState = ScreenState.TransitionOn;
screenState = ScreenState.TransitionOn;
}
else
{
// Transition finished!
ScreenState = ScreenState.Active;
screenState = ScreenState.Active;
}
}
}
/// <summary>
/// Helper for updating the screen transition position.
/// </summary>
private bool UpdateTransition(GameTime gameTime, TimeSpan time, int direction)
bool UpdateTransition(GameTime gameTime, TimeSpan time, int direction)
{
// How much should we move by?
float transitionDelta;
if (time == TimeSpan.Zero)
{
transitionDelta = 1f;
}
transitionDelta = 1;
else
{
transitionDelta = (float)(gameTime.ElapsedGameTime.TotalMilliseconds /
time.TotalMilliseconds);
}
transitionDelta = (float)(gameTime.ElapsedGameTime.TotalMilliseconds / time.TotalMilliseconds);
// Update the transition position.
TransitionPosition += transitionDelta * direction;
transitionPosition += transitionDelta * direction;
// Did we reach the end of the transition?
if (((direction < 0) && (TransitionPosition <= 0)) ||
((direction > 0) && (TransitionPosition >= 1)))
if (((direction < 0) && (transitionPosition <= 0)) ||
((direction > 0) && (transitionPosition >= 1)))
{
TransitionPosition = MathHelper.Clamp(TransitionPosition, 0, 1);
transitionPosition = MathHelper.Clamp(transitionPosition, 0, 1);
return false;
}
return true;
}
/// <summary>
/// Allows the screen to handle user input. Unlike Update, this method
/// is only called when the screen is active, and not when some other
/// screen has taken the focus.
/// </summary>
public virtual void HandleInput(InputHelper input, GameTime gameTime)
{
}
public virtual void HandleInput(GameTime gameTime, InputState input) { }
/// <summary>
/// This is called when the screen should draw itself.
/// </summary>
public virtual void Draw(GameTime gameTime)
{
}
public virtual void Draw(GameTime gameTime) { }
/// <summary>
/// Tells the screen to go away. Unlike ScreenManager.RemoveScreen, which
/// instantly kills the screen, this method respects the transition timings
/// and will give the screen a chance to gradually transition off.
/// </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.
ScreenManager.RemoveScreen(this);
else
{
// Otherwise flag that it should transition off and then exit.
IsExiting = true;
isExiting = true;
}
}
}
}
}
axios/ScreenSystem/InputHelper.cs
33
44
55
6
67
78
89
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using GameStateManagement;
namespace FarseerPhysics.SamplesFramework
{
axios/ScreenSystem/LogoScreen.cs
33
44
55
6
67
7
8
89
910
1011
......
2930
3031
3132
32
33
3334
34
35
3536
36
37
37
38
39
40
3841
39
42
4043
41
42
43
44
45
44
45
46
47
48
4649
47
50
51
4852
4953
5054
5155
5256
53
57
5458
5559
5660
5761
58
62
5963
64
6065
6166
6267
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using FarseerPhysics.SamplesFramework;
namespace FarseerPhysics.SamplesFramework
namespace GameStateManagement
{
public class LogoScreen : GameScreen
{
/// used the shared ContentManager provided by the Game class, the content
/// would remain loaded forever.
/// </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");
_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;
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);
_destination = new Rectangle(posX, posY, rectWidth, rectHeight);
}
}
/// <summary>
/// Unloads graphics content for this screen.
/// </summary>
public override void UnloadContent()
public override void 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 ||
input.GamePadState.IsButtonDown(Buttons.A | Buttons.Start | Buttons.Back) ||
input.MouseState.LeftButton == ButtonState.Pressed)
axios/ScreenSystem/MenuButton.cs
22
33
44
5
5
66
77
88
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace FarseerPhysics.SamplesFramework
namespace GameStateManagement
{
/// <summary>
/// Helper class represents a single entry in a MenuScreen. By default this
axios/ScreenSystem/MenuEntry.cs
1
1
2
3
4
5
6
7
8
9
10
11
212
313
14
15
416
5
17
618
7
8
9
10
11
12
13
14
1519
1620
1721
1822
1923
2024
21
25
2226
23
24
25
26
27
27
2828
2929
30
31
30
3231
33
34
35
36
32
3733
3834
3935
......
4137
4238
4339
44
40
4541
4642
47
43
44
4845
49
46
5047
51
52
48
5349
54
55
56
57
58
59
60
61
62
63
64
65
50
6651
6752
6853
......
7055
7156
7257
73
74
58
59
7560
7661
62
7763
7864
7965
8066
8167
82
83
68
69
8470
8571
86
87
88
89
90
9172
92
93
94
95
73
9674
97
98
99
75
10076
101
10277
103
104
105
78
79
80
81
10682
107
108
109
110
11183
112
84
85
86
87
11388
114
89
90
11591
11692
117
93
94
95
96
97
98
99
100
101
102
118103
119
104
120105
121106
107
108
109
110
111
112
122113
123114
124115
125
116
126117
127118
128119
129120
130121
131122
123
132124
133125
134126
135
136
137
138
139
140
141
142
143
144
145
146
147
127
128
129
130
131
132
148133
149134
135
150136
151137
152138
153
139
154140
155
156
157
158
159
160
161
162
163
164
165
166
167
168
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
169159
170160
171
172
173
174
161
162
163
164
165
166
167
168
175169
176170
171
177172
178173
179174
180
175
181176
182
177
183178
184179
180
185181
186182
187183
188
184
189185
190
186
191187
188
189
190
192191
193
192
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.Graphics;
using GameStateManagement;
#endregion
namespace FarseerPhysics.SamplesFramework
namespace GameStateManagement
{
public enum EntryType
{
Screen,
Separator,
ExitItem,
BackItem
}
/// <summary>
/// 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
/// entries in different ways. This also provides an event that will be raised
/// when the menu entry is selected.
/// </summary>
public sealed class MenuEntry
class MenuEntry
{
private float _alpha;
private Vector2 _baseOrigin;
private float _height;
private MenuScreen _menu;
#region Fields
/// <summary>
/// The position at which the entry is drawn. This is set by the MenuScreen
/// each frame in Update.
/// The text rendered for this entry.
/// </summary>
private Vector2 _position;
private float _scale;
private GameScreen _screen;
string text;
/// <summary>
/// Tracks a fading selection effect on the entry.
/// <remarks>
/// The entries transition out of the selection effect when they are deselected.
/// </remarks>
private float _selectionFade;
float selectionFade;
/// <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>
private string _text;
Vector2 position;
private EntryType _type;
private float _width;
#endregion
/// <summary>
/// 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;
}
#region Properties
/// <summary>
/// </summary>
public string Text
{
get { return _text; }
set { _text = value; }
get { return text; }
set { text = value; }
}
/// <summary>
/// Gets or sets the position at which to draw this menu entry.
/// </summary>
public Vector2 Position
{
get { return _position; }
set { _position = value; }
get { return position; }
set { position = value; }
}
public float Alpha
{
get { return _alpha; }
set { _alpha = value; }
}
public GameScreen Screen
{
get { return _screen; }
}
#endregion
public void Initialize()
{
SpriteFont font = _menu.ScreenManager.Fonts.MenuSpriteFont;
#region Events
_baseOrigin = new Vector2(font.MeasureString(Text).X, font.MeasureString("M").Y) * 0.5f;
_width = font.MeasureString(Text).X * 0.8f;
_height = font.MeasureString("M").Y * 0.8f;
}
/// <summary>
/// Event raised when the menu entry is selected.
/// </summary>
public event EventHandler<PlayerIndexEventArgs> Selected;
public bool IsExitItem()
{
return _type == EntryType.ExitItem;
}
public bool IsSelectable()
/// <summary>
/// Method for raising the Selected event.
/// </summary>
protected internal virtual void OnSelectEntry(PlayerIndex playerIndex)
{
return _type != EntryType.Separator;
if (Selected != null)
Selected(this, new PlayerIndexEventArgs(playerIndex));
}
public bool IsBackItem()
#endregion
#region Initialization
/// <summary>
/// Constructs a new menu entry with the specified text.
/// </summary>
public MenuEntry(string text)
{
return _type == EntryType.BackItem;
this.text = text;
}
#endregion
#region Update and Draw
/// <summary>
/// Updates the menu entry.
/// </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
// force isSelected to be false
#if WINDOWS_PHONE
isSelected = false;
#endif
// When the menu selection changes, entries gradually fade between
// their selected and deselected appearance, rather than instantly
// popping to the new state.
if (_type != EntryType.Separator)
{
float fadeSpeed = (float)gameTime.ElapsedGameTime.TotalSeconds * 4;
if (isSelected)
{
_selectionFade = Math.Min(_selectionFade + fadeSpeed, 1f);
}
else
{
_selectionFade = Math.Max(_selectionFade - fadeSpeed, 0f);
}
_scale = 0.7f + 0.1f * _selectionFade;
}
float fadeSpeed = (float)gameTime.ElapsedGameTime.TotalSeconds * 4;
if (isSelected)
selectionFade = Math.Min(selectionFade + fadeSpeed, 1);
else
selectionFade = Math.Max(selectionFade - fadeSpeed, 0);
}
/// <summary>
/// Draws the menu entry. This can be overridden to customize the appearance.
/// </summary>
public void Draw()
public virtual void Draw(MenuScreen screen, bool isSelected, GameTime gameTime)
{
SpriteFont font = _menu.ScreenManager.Fonts.MenuSpriteFont;
SpriteBatch batch = _menu.ScreenManager.SpriteBatch;
Color color;
if (_type == EntryType.Separator)
{
color = Color.DarkOrange;
}
else
{
// Draw the selected entry in yellow, otherwise white
color = Color.Lerp(Color.White, new Color(255, 210, 0), _selectionFade);
}
color *= _alpha;
// there is no such thing as a selected item on Windows Phone, so we always
// force isSelected to be false
#if WINDOWS_PHONE
isSelected = false;
#endif
// Draw the selected entry in yellow, otherwise white.
Color color = isSelected ? Color.Yellow : Color.White;
// Pulsate the size of the selected menu entry.
double time = gameTime.TotalGameTime.TotalSeconds;
float pulsate = (float)Math.Sin(time * 6) + 1;
float scale = 1 + pulsate * 0.05f * selectionFade;
// Modify the alpha to fade text out during transitions.
color *= screen.TransitionAlpha;
// Draw text, centered on the middle of each line.
batch.DrawString(font, _text, _position - _baseOrigin * _scale + Vector2.One,
Color.DarkSlateGray * _alpha * _alpha, 0, Vector2.Zero, _scale, SpriteEffects.None, 0);
batch.DrawString(font, _text, _position - _baseOrigin * _scale, color, 0, Vector2.Zero, _scale,
SpriteEffects.None, 0);
ScreenManager screenManager = screen.ScreenManager;
SpriteBatch spriteBatch = screenManager.SpriteBatch;
SpriteFont font = screenManager.Font;
Vector2 origin = new Vector2(0, font.LineSpacing / 2);
spriteBatch.DrawString(font, text, position, color, 0,
origin, scale, SpriteEffects.None, 0);
}
/// <summary>
/// Queries how much space this menu entry requires.
/// </summary>
public int GetHeight()
public virtual int GetHeight(MenuScreen screen)
{
return (int)_height;
return screen.ScreenManager.Font.LineSpacing;
}
/// <summary>
/// Queries how wide the entry is, used for centering on the screen.
/// </summary>
public int GetWidth()
public virtual int GetWidth(MenuScreen screen)
{
return (int)_width;
return (int)screen.ScreenManager.Font.MeasureString(Text).X;
}
#endregion
}
}
}
axios/ScreenSystem/MenuScreen.cs
1
2
3
4
5
6
7
8
9
10
111
212
313
414
15
16
17
18
519
6
20
721
822
923
1024
1125
12
26
1327
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
3743
3844
39
45
46
4047
41
48
4249
43
44
45
46
47
50
4851
4952
50
51
52
53
54
5553
56
57
58
59
54
55
56
6057
61
58
59
60
61
62
6263
63
64
65
66
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
6786
68
69
70
7187
72
88
7389
74
75
90
7691
77
78
7992
80
93
94
95
96
97
8198
82
83
84
85
86
99
100
101
102
103
104
105
106
107
87108
88
89
90
109
110
111
112
91113
92114
93
94
115
116
117
118
95119
96
97
98
120
121
122
99123
100
101
124
125
126
127
128
129
130
131
132
102133
103
104
105
106
107
108134
109
135
136
137
138
139
140
110141
111142
143
112144
113
145
114146
115
116
147
117148
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
149
136150
137151
152
138153
139
140
154
141155
142
156
143157
144
145
146
147
148
149
150
151
152
153
158
159
154160
155
156
157
158
159
160
161
162
163
164
165
166
167
168161
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
162
163
164
204165
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232166
233167
234168
......
241175
242176
243177
244
245
178
179
246180
247181
248
182
249183
250
184
185
186
187
188
251189
252
253190
254
255191
256
257
258
192
259193
260194
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
195
278196
279197
280
198
281199
282
283
284
285200
286201
202
287203
288204
289205
290206
291
207
292208
293209
294210
295211
296
212
297213
298
299
300
214
301215
302
303
304
216
217
305218
306219
220
307221
308222
309223
......
312226
313227
314228
229
315230
316
231
317232
318233
234
319235
320
236
321237
322
323
238
239
240
241
242
324243
325244
326245
327246
328247
329
330
331
332
333
334
335
336
337
248
249
250
251
252
253
254
255
256
257
258
259
260
338261
339262
263
264
265
340266
341
267
#region File Description
//-----------------------------------------------------------------------------
// MenuScreen.cs
//
// XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion
#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
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>
/// 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.
/// </summary>
public class MenuScreen : GameScreen
abstract class MenuScreen : GameScreen
{
#if WINDOWS || XBOX
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;
protected Texture2D _texSlider;
protected MenuButton _scrollUp;
protected MenuButton _scrollDown;
protected MenuButton _scrollSlider;
protected bool _scrollLock;
#region Fields
List<MenuEntry> menuEntries = new List<MenuEntry>();
int selectedEntry = 0;
string menuTitle;
InputAction menuUp;
InputAction menuDown;
InputAction menuSelect;
InputAction menuCancel;
#endregion
#region Properties
/// <summary>
/// Constructor.
/// Gets the list of menu entries, so derived classes can add
/// or change the menu contents.
/// </summary>
public MenuScreen(string menuTitle)
protected IList<MenuEntry> MenuEntries
{
_menuTitle = menuTitle;
TransitionOnTime = TimeSpan.FromSeconds(0.7);
TransitionOffTime = TimeSpan.FromSeconds(0.7);
HasCursor = true;
get { return menuEntries; }
}
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)
{
_menuEntries.Add(me);
}
#endregion
#region Initialization
public override void LoadContent()
/// <summary>
/// Constructor.
/// </summary>
public MenuScreen(string menuTitle)
{
base.LoadContent();
_texScrollButton = ScreenManager.Content.Load<Texture2D>("Common/arrow");
_texSlider = ScreenManager.Content.Load<Texture2D>("Common/slider");
this.menuTitle = menuTitle;
TransitionOnTime = TimeSpan.FromSeconds(0.5);
TransitionOffTime = TimeSpan.FromSeconds(0.5);
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);
}
//Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
//float scrollBarPos = viewport.Width / 2f;
//scrollBarPos -= _texScrollButton.Width + 2f;
#endregion
InitMenu();
#region Handle Input
}
public void InitMenu()
/// <summary>
/// Responds to user input, changing the selected entry and accepting
/// or cancelling the menu.
/// </summary>
public override void HandleInput(GameTime gameTime, InputState input)
{
Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
SpriteFont font = ScreenManager.Fonts.MenuSpriteFont;
float scrollBarPos = viewport.Width / 2f;
for (int i = 0; i < _menuEntries.Count; ++i)
// For input tests we pass in our ControllingPlayer, which may
// either be null (to 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
// 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))
{
_menuEntries[i].Initialize();
scrollBarPos = Math.Min(scrollBarPos,
(viewport.Width - _menuEntries[i].GetWidth()) / 2f);
selectedEntry--;
if (selectedEntry < 0)
selectedEntry = menuEntries.Count - 1;
}
_titleOrigin = font.MeasureString(_menuTitle) / 2f;
_titlePosition = new Vector2(viewport.Width / 2f, font.MeasureString("M").Y / 2f + 10f);
// Move to the next menu entry?
if (menuDown.Evaluate(input, ControllingPlayer, out playerIndex))
{
selectedEntry++;
_menuBorderMargin = font.MeasureString("M").Y * 0.8f;
_menuBorderTop = (viewport.Height - _menuBorderMargin * (NumEntries - 1)) / 2f;
_menuBorderBottom = (viewport.Height + _menuBorderMargin * (NumEntries - 1)) / 2f;
if (selectedEntry >= menuEntries.Count)
selectedEntry = 0;
}
_menuOffset = 0f;
_maxOffset = Math.Max(0f, (_menuEntries.Count - NumEntries) * _menuBorderMargin);
if (menuSelect.Evaluate(input, ControllingPlayer, out playerIndex))
{
OnSelectEntry(selectedEntry, playerIndex);
}
else if (menuCancel.Evaluate(input, ControllingPlayer, out playerIndex))
{
OnCancel(playerIndex);
}
}
_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>
/// Handler for when the user has chosen a menu entry.
/// </summary>
protected virtual void OnSelectEntry(int entryIndex, PlayerIndex playerIndex)
{
menuEntries[entryIndex].OnSelectEntry(playerIndex);
}
/// <summary>
/// Returns the index of the menu entry at the position of the given mouse state.
/// Handler for when the user has cancelled the menu.
/// </summary>
/// <returns>Index of menu entry if valid, -1 otherwise</returns>
private int GetMenuEntryAt(Vector2 position)
protected virtual void OnCancel(PlayerIndex playerIndex)
{
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;
ExitScreen();
}
/// <summary>
/// Responds to user input, changing the selected entry and accepting
/// or cancelling the menu.
/// Helper overload makes it easy to use OnCancel as a MenuEntry event handler.
/// </summary>
public override void HandleInput(InputHelper input, GameTime gameTime)
protected void OnCancel(object sender, PlayerIndexEventArgs e)
{
// Mouse or touch on a menu item
int hoverIndex = GetMenuEntryAt(input.Cursor);
if (hoverIndex > -1 && _menuEntries[hoverIndex].IsSelectable() && !_scrollLock)
{
_selectedEntry = hoverIndex;
}
else
{
_selectedEntry = -1;
}
OnCancel(e.PlayerIndex);
}
_scrollSlider.Hover = false;
if (input.IsCursorValid)
{
_scrollUp.Collide(input.Cursor);
_scrollDown.Collide(input.Cursor);
_scrollSlider.Collide(input.Cursor);
}
else
{
_scrollUp.Hover = false;
_scrollDown.Hover = false;
_scrollLock = false;
}
// Accept or cancel the menu?
if (input.IsMenuSelect() && _selectedEntry != -1)
{
if (_menuEntries[_selectedEntry].IsExitItem())
{
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())
{
if (this.ScreenState == SamplesFramework.ScreenState.Active && this.TransitionPosition == 0 && this.TransitionAlpha == 1)
{
//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();
}
#endregion
#region Update and Draw
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>
/// Allows the screen the chance to position the menu entries. By default
// the movement slow down as it nears the end).
float transitionOffset = (float)Math.Pow(TransitionPosition, 2);
Vector2 position = Vector2.Zero;
position.Y = _menuBorderTop - _menuOffset;
// start at Y = 175; each X value is generated per entry
Vector2 position = new Vector2(0f, 175f);
// 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)
{
position.X -= transitionOffset * 256;
}
else
{
position.X += transitionOffset * 256;
}
position.X += transitionOffset * 512;
// set the entry's position
_menuEntries[i].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;
}
menuEntry.Position = position;
// 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>
/// Updates the menu.
/// </summary>
public override void Update(GameTime gameTime, bool otherScreenHasFocus,
bool coveredByOtherScreen)
bool coveredByOtherScreen)
{
base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
// 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);
_menuEntries[i].Update(isSelected, gameTime);
}
bool isSelected = IsActive && (i == selectedEntry);
_scrollUp.Update(gameTime);
_scrollDown.Update(gameTime);
_scrollSlider.Update(gameTime);
menuEntries[i].Update(this, isSelected, gameTime);
}
}
/// <summary>
/// Draws the menu.
/// </summary>
// make sure our entries are in the right place before we draw them
UpdateMenuEntryLocations();
GraphicsDevice graphics = ScreenManager.GraphicsDevice;
SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
SpriteFont font = ScreenManager.Fonts.MenuSpriteFont;
SpriteFont font = ScreenManager.Font;
spriteBatch.Begin();
// 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);
_menuEntries[i].Draw();
MenuEntry menuEntry = menuEntries[i];
bool isSelected = IsActive && (i == selectedEntry);
menuEntry.Draw(this, isSelected, gameTime);
}
// Make the menu slide into place during transitions, using a
// power curve to make things look more interesting (this makes
// the movement slow down as it nears the end).
Vector2 transitionOffset = new Vector2(0f, (float)Math.Pow(TransitionPosition, 2) * 100f);
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();
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.End();
}
#endregion
}
}
}
axios/ScreenSystem/MessageBoxScreen.cs
1
1
2
3
4
5
6
7
8
9
10
11
212
313
414
15
16
17
518
6
19
720
821
922
1023
1124
12
25
1326
14
15
16
17
27
1828
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
1951
52
53
54
55
56
57
58
59
60
2061
21
62
63
64
65
66
67
68
2269
2370
24
2571
26
27
72
73
74
75
76
77
78
79
80
81
82
2883
2984
30
31
32
33
3485
3586
3687
......
3889
3990
4091
41
92
4293
43
44
45
94
95
96
97
98
99
46100
47
48
49
50
51
52101
53
54
55
102
103
104
56105
57
58
59
60
61
62106
63107
64108
65109
66
110
67111
112
113
114
115
116
117
118
119
120
121
122
123
68124
69
70
125
126
127
71128
129
130
131
132
72133
73134
74135
75136
137
138
139
140
141
142
76143
77144
78145
79146
80147
81148
82
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
83168
84169
85
170
86171
87172
88173
89174
90
175
91176
92177
93
94
178
95179
96180
97181
182
183
184
98185
99
186
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.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using GameStateManagement;
#endregion
namespace FarseerPhysics.SamplesFramework
namespace GameStateManagement
{
/// <summary>
/// A popup message box screen, used to display "are you sure?"
/// confirmation messages.
/// </summary>
public class MessageBoxScreen : GameScreen
class MessageBoxScreen : GameScreen
{
protected Rectangle _backgroundRectangle;
protected Texture2D _gradientTexture;
protected string _message;
protected Vector2 _textPosition;
#region Fields
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)
: 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;
HasCursor = true;
TransitionOnTime = TimeSpan.FromSeconds(0.4);
TransitionOffTime = TimeSpan.FromSeconds(0.4);
TransitionOnTime = TimeSpan.FromSeconds(0.2);
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>
/// Loads graphics content for this screen. This uses the shared ContentManager
/// Whenever a subsequent MessageBoxScreen tries to load this same content,
/// it will just get back another reference to the already loaded data.
/// </summary>
public override void LoadContent()
public override void Activate(bool instancePreserved)
{
SpriteFont font = ScreenManager.Fonts.DetailsFont;
ContentManager content = ScreenManager.Game.Content;
_gradientTexture = content.Load<Texture2D>("Common/popup");
if (!instancePreserved)
{
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;
#endregion
#region Handle Input
_backgroundRectangle = new Rectangle((int)_textPosition.X - hPad,
(int)_textPosition.Y - vPad,
(int)textSize.X + hPad * 2,
(int)textSize.Y + vPad * 2);
}
/// <summary>
/// Responds to user input, accepting or cancelling the message box.
/// </summary>
public override void HandleInput(InputHelper input, GameTime gameTime)
public override void HandleInput(GameTime gameTime, InputState input)
{
PlayerIndex playerIndex;
// We pass in our ControllingPlayer, which may either be null (to
// 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));
if (input.IsMenuSelect() || input.IsMenuCancel() ||
input.IsNewMouseButtonPress(MouseButtons.LeftButton))
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();
}
}
#endregion
#region Draw
/// <summary>
/// Draws the message box.
/// </summary>
public override void Draw(GameTime gameTime)
{
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.
Color color = Color.White * TransitionAlpha * (2f / 3f);
Color color = Color.White * TransitionAlpha;
spriteBatch.Begin();
// Draw the background rectangle.
spriteBatch.Draw(_gradientTexture, _backgroundRectangle, color);
spriteBatch.Draw(gradientTexture, backgroundRectangle, color);
// Draw the message box text.
spriteBatch.DrawString(font, _message, _textPosition + Vector2.One, Color.Black);
spriteBatch.DrawString(font, _message, _textPosition, Color.White);
spriteBatch.DrawString(font, message, textPosition, color);
spriteBatch.End();
}
#endregion
}
}
}
axios/ScreenSystem/PhysicsGameScreen.cs
66
77
88
9
910
1011
11
12
1213
1314
1415
......
4748
4849
4950
50
5151
52
52
53
5354
54
55
56
57
5558
56
57
59
60
5861
59
60
61
62
63
64
65
66
62
63
64
65
66
67
68
69
6770
68
69
70
71
7172
72
73
74
75
76
77
73
74
75
76
77
78
79
80
81
7882
79
8083
81
82
83
84
85
86
87
88
84
85
86
87
88
89
90
91
8992
90
91
93
94
95
9296
9397
9498
......
110114
111115
112116
113
117
114118
115119
116120
117121
118
122
123
119124
120125
121126
......
126131
127132
128133
129
134
130135
131136
132137
133
138
134139
135140
136141
137142
138
143
139144
140145
141146
142
147
143148
144149
145150
146151
147
152
148153
149154
150155
151
156
152157
153158
154159
155
160
156161
157162
158163
159
164
160165
161166
162167
......
181186
182187
183188
184
189
185190
186191
187192
......
191196
192197
193198
194
195
199
200
196201
202
197203
198204
199205
......
211217
212218
213219
214
215
220
221
222
216223
217224
218225
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;
using FarseerPhysics.SamplesFramework;
using Axios.Engine;
namespace FarseerPhysics.SamplesFramework
namespace GameStateManagement
{
public class PhysicsGameScreen : GameScreen
{
_agentTorque = torque;
}
public override void LoadContent()
public override void Activate(bool instancePreserved)
{
base.LoadContent();
if (!instancePreserved)
{
base.Activate(instancePreserved);
//We enable diagnostics to show get values for our performance counters.
Settings.EnableDiagnostics = true;
//We enable diagnostics to show get values for our performance counters.
Settings.EnableDiagnostics = true;
if (World == null)
{
World = new World(Vector2.Zero);
}
else
{
World.Clear();
}
if (World == null)
{
World = new World(Vector2.Zero);
}
else
{
World.Clear();
}
if (DebugView == null)
{
if (!Axios.Settings.ScreenSaver)
if (DebugView == null)
{
DebugView = new DebugViewXNA(World);
DebugView.RemoveFlags(DebugViewFlags.Shape);
DebugView.RemoveFlags(DebugViewFlags.Joint);
DebugView.DefaultShapeColor = Color.White;
DebugView.SleepingShapeColor = Color.LightGray;
DebugView.LoadContent(ScreenManager.GraphicsDevice, ScreenManager.Content);
if (!Axios.Settings.ScreenSaver)
{
DebugView = new DebugViewXNA(World);
DebugView.RemoveFlags(DebugViewFlags.Shape);
DebugView.RemoveFlags(DebugViewFlags.Joint);
DebugView.DefaultShapeColor = Color.White;
DebugView.SleepingShapeColor = Color.LightGray;
DebugView.LoadContent(ScreenManager.GraphicsDevice, ScreenManager.Content);
}
}
}
if (Camera == null)
{
Camera = new Camera2D(ScreenManager.GraphicsDevice);
}
else
{
Camera.ResetCamera();
}
if (Camera == null)
{
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();
// 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 HandleInput(InputHelper input, GameTime gameTime)
public override void HandleInput(GameTime gameTime, InputState input)
{
#if DEBUG
// Control debug view
if (input.IsNewButtonPress(Buttons.Start))
PlayerIndex player;
if (input.IsNewButtonPress(Buttons.Start, ControllingPlayer.Value, out player))
{
EnableOrDisableFlag(DebugViewFlags.Shape);
EnableOrDisableFlag(DebugViewFlags.DebugPanel);
EnableOrDisableFlag(DebugViewFlags.Controllers);
}
if (input.IsNewKeyPress(Keys.F1))
if (input.IsNewKeyPress(Keys.F1, ControllingPlayer.Value, out player))
{
EnableOrDisableFlag(DebugViewFlags.Shape);
}
if (input.IsNewKeyPress(Keys.F2))
if (input.IsNewKeyPress(Keys.F2, ControllingPlayer.Value, out player))
{
EnableOrDisableFlag(DebugViewFlags.DebugPanel);
EnableOrDisableFlag(DebugViewFlags.PerformanceGraph);
}
if (input.IsNewKeyPress(Keys.F3))
if (input.IsNewKeyPress(Keys.F3, ControllingPlayer.Value, out player))
{
EnableOrDisableFlag(DebugViewFlags.Joint);
}
if (input.IsNewKeyPress(Keys.F4))
if (input.IsNewKeyPress(Keys.F4, ControllingPlayer.Value, out player))
{
EnableOrDisableFlag(DebugViewFlags.ContactPoints);
EnableOrDisableFlag(DebugViewFlags.ContactNormals);
}
if (input.IsNewKeyPress(Keys.F5))
if (input.IsNewKeyPress(Keys.F5, ControllingPlayer.Value, out player))
{
EnableOrDisableFlag(DebugViewFlags.PolygonPoints);
}
if (input.IsNewKeyPress(Keys.F6))
if (input.IsNewKeyPress(Keys.F6, ControllingPlayer.Value, out player))
{
EnableOrDisableFlag(DebugViewFlags.Controllers);
}
if (input.IsNewKeyPress(Keys.F7))
if (input.IsNewKeyPress(Keys.F7, ControllingPlayer.Value, out player))
{
EnableOrDisableFlag(DebugViewFlags.CenterOfMass);
}
if (input.IsNewKeyPress(Keys.F8))
if (input.IsNewKeyPress(Keys.F8, ControllingPlayer.Value, out player))
{
EnableOrDisableFlag(DebugViewFlags.AABB);
}
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
CleanUp();
}
base.HandleInput(input, gameTime);
}
public virtual void HandleCursor(InputHelper input)
public virtual void HandleCursor(InputState input)
{
PlayerIndex player;
Vector2 position = Camera.ConvertScreenToWorld(input.Cursor);
if ((input.IsNewButtonPress(Buttons.A) ||
}
}
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)
{
World.RemoveJoint(_fixedMouseJoint);
axios/ScreenSystem/ScreenManagerComponent.cs
33
44
55
6
67
7
8
89
10
911
1012
1113
......
299301
300302
301303
302
304
303305
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input.Touch;
using FarseerPhysics.SamplesFramework;
namespace FarseerPhysics.SamplesFramework
namespace GameStateManagement
{
/*
/// <summary>
/// The screen manager is a component which manages one or more GameScreen
/// instances. It maintains a stack of screens, calls their Update and Draw
{
return _screens.ToArray();
}
}
}*/
}

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.22056s using 13 queries.