00001
00002
00003
00004
00005
00006 namespace GravityChooser
00007 {
00008 using System;
00009 using System.Threading;
00010 using System.Collections.Generic;
00011
00012 using Microsoft.Xna.Framework;
00013 using Microsoft.Xna.Framework.Content;
00014 using Microsoft.Xna.Framework.Graphics;
00015 using Microsoft.Xna.Framework.Input;
00016
00017 using NewGamePhysics.StateManager;
00018 using NewGamePhysics.Utilities;
00019 using NewGamePhysics.GraphicalElements;
00020 using NewGamePhysics.PhysicalElements;
00021
00025 class GravityChooserHelpScreen : GameScreen
00026 {
00030 private ContentManager contentManager;
00031
00032
00033 private List<string> messages;
00034
00038 private int numRows;
00039
00043 private int currentRow;
00044
00048 private float fadeSpeed = 0.1f;
00049
00053 private float[] textAlpha;
00054
00055 #region Initialization
00056
00061 public GravityChooserHelpScreen(string[] screenMessage)
00062 {
00063
00064 this.messages = new List<string>();
00065
00066
00067 this.messages.AddRange(screenMessage);
00068
00069
00070 string[] exitMessage = { "", "", "[Key] or (Button) to return to Main Menu" };
00071 this.messages.AddRange(exitMessage);
00072
00073 TransitionOnTime = TimeSpan.FromSeconds(0.5);
00074 TransitionOffTime = TimeSpan.FromSeconds(0.5);
00075 }
00076
00080 public override void LoadContent()
00081 {
00082 if (this.contentManager == null)
00083 {
00084 this.contentManager = new ContentManager(ScreenManager.Game.Services, "Content");
00085 }
00086
00087
00088 numRows = messages.Count;
00089 currentRow = 0;
00090 textAlpha = new float[numRows];
00091 for (int i = 0; i < numRows; i++)
00092 {
00093 textAlpha[i] = 0.0f;
00094 }
00095
00096
00097 ScreenManager.Game.ResetElapsedTime();
00098 }
00099
00103 public override void UnloadContent()
00104 {
00105 this.contentManager.Unload();
00106 }
00107
00108 #endregion
00109
00110 #region Update and Draw
00111
00115 public override void Update(GameTime gameTime, bool otherScreenHasFocus,
00116 bool coveredByOtherScreen)
00117 {
00118 base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
00119
00120 if (IsActive)
00121 {
00122
00123 if (currentRow < numRows)
00124 {
00125 textAlpha[currentRow] += fadeSpeed;
00126 if (string.IsNullOrEmpty(messages[currentRow]) ||
00127 (textAlpha[currentRow] >= 1.0f))
00128 {
00129 textAlpha[currentRow] = 1.0f;
00130 currentRow++;
00131 }
00132 }
00133 }
00134 }
00135
00140 public override void HandleInput(InputState input)
00141 {
00142 if (input == null)
00143 {
00144 throw new ArgumentNullException("input");
00145 }
00146
00147
00148 PlayerIndex playerIndex = ControllingPlayer.Value;
00149
00150 KeyboardState keyboardState = input.CurrentKeyboardStates[(int)playerIndex];
00151 GamePadState gamePadState = input.CurrentGamePadStates[(int)playerIndex];
00152
00153
00154
00155
00156
00157 bool gamePadDisconnected = !gamePadState.IsConnected &&
00158 input.GamePadWasConnected[(int)playerIndex];
00159
00160
00161 if (input.IsMenuSelect(ControllingPlayer, out playerIndex))
00162 {
00163 GravityChooserLoadingScreen.Load(ScreenManager, false, null, new GravityChooserBackgroundScreen(),
00164 new GravityChooserMainMenuScreen());
00165 }
00166 }
00167
00171 public override void Draw(GameTime gameTime)
00172 {
00173
00174 PrimitiveBatch primitiveBatch = ScreenManager.PrimitiveBatch;
00175 SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
00176 Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
00177 SpriteFont font = ScreenManager.Fonts["game"];
00178
00179
00180 Color color = Color.White;
00181 Vector2 origin = new Vector2(0, 0);
00182 Vector2 position = new Vector2(viewport.Width * 0.05f, viewport.Height * 0.05f);
00183 float scale = 0.5f;
00184 spriteBatch.Begin();
00185 for (int i = 0; i < numRows; i++)
00186 {
00187 string message = messages[i];
00188 if (textAlpha[i] > 0.0f)
00189 {
00190 if (string.IsNullOrEmpty(message))
00191 {
00192
00193 position.Y += ((float)font.LineSpacing * 0.5f * scale);
00194 }
00195 else
00196 {
00197 color = new Color(Color.White, MathHelper.SmoothStep(0.0f, 1.0f, textAlpha[i]));
00198 spriteBatch.DrawString(
00199 font,
00200 message,
00201 position,
00202 color,
00203 0,
00204 origin,
00205 scale,
00206 SpriteEffects.None,
00207 0);
00208 position.Y += ((float)font.LineSpacing * 1.2f * scale);
00209 }
00210 }
00211 }
00212 spriteBatch.End();
00213
00214
00215 if (TransitionPosition > 0)
00216 {
00217 ScreenManager.FadeBackBufferToBlack(255 - TransitionAlpha);
00218 }
00219
00220 base.Draw(gameTime);
00221 }
00222
00223 #endregion
00224 }
00225 }
00226