00001 #region File Description
00002
00003
00004
00005
00006 #endregion
00007
00008 namespace MontyHallGame
00009 {
00010 using System;
00011 using Microsoft.Xna.Framework;
00012 using Microsoft.Xna.Framework.Content;
00013 using Microsoft.Xna.Framework.Graphics;
00014 using NewGamePhysics.StateManager;
00015
00020 class MontyHallMessageBoxScreen : GameScreen
00021 {
00022 #region Fields
00023
00024 string message;
00025 Texture2D gradientTexture;
00026
00027 #endregion
00028
00029 #region Events
00030
00031 public event EventHandler<PlayerIndexEventArgs> Accepted;
00032 public event EventHandler<PlayerIndexEventArgs> Cancelled;
00033
00034 #endregion
00035
00036 #region Initialization
00037
00038
00043 public MontyHallMessageBoxScreen(string message)
00044 : this(message, true)
00045 { }
00046
00047
00052 public MontyHallMessageBoxScreen(string message, bool includeUsageText)
00053 {
00054 const string usageText = "\nOK : (A) button or [Enter]" +
00055 "\nCancel : (B) button or [Esc]";
00056
00057 if (includeUsageText)
00058 {
00059 this.message = message + usageText;
00060 }
00061 else
00062 {
00063 this.message = message;
00064 }
00065
00066 IsPopup = true;
00067
00068 TransitionOnTime = TimeSpan.FromSeconds(0.2);
00069 TransitionOffTime = TimeSpan.FromSeconds(0.2);
00070 }
00071
00072
00079 public override void LoadContent()
00080 {
00081 ContentManager content = ScreenManager.Game.Content;
00082
00083 gradientTexture = content.Load<Texture2D>(@"Sprites\gradient");
00084 }
00085
00086
00087 #endregion
00088
00089 #region Handle Input
00090
00091
00095 public override void HandleInput(InputState input)
00096 {
00097 PlayerIndex playerIndex;
00098
00099
00100
00101
00102
00103
00104 if (input.IsMenuSelect(ControllingPlayer, out playerIndex))
00105 {
00106
00107 if (Accepted != null)
00108 Accepted(this, new PlayerIndexEventArgs(playerIndex));
00109
00110 ExitScreen();
00111 }
00112 else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
00113 {
00114
00115 if (Cancelled != null)
00116 Cancelled(this, new PlayerIndexEventArgs(playerIndex));
00117
00118 ExitScreen();
00119 }
00120 }
00121
00122
00123 #endregion
00124
00125 #region Draw
00126
00130 public override void Draw(GameTime gameTime)
00131 {
00132 SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
00133 SpriteFont font = ScreenManager.Fonts["menu"];
00134
00135
00136 ScreenManager.FadeBackBufferToBlack(TransitionAlpha * 2 / 3);
00137
00138
00139 Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
00140 Vector2 viewportSize = new Vector2(viewport.Width, viewport.Height);
00141 Vector2 textSize = font.MeasureString(message);
00142 Vector2 textPosition = (viewportSize - textSize) / 2;
00143
00144
00145 const int hPad = 32;
00146 const int vPad = 16;
00147
00148 Rectangle backgroundRectangle = new Rectangle((int)textPosition.X - hPad,
00149 (int)textPosition.Y - vPad,
00150 (int)textSize.X + hPad * 2,
00151 (int)textSize.Y + vPad * 2);
00152
00153
00154 Color color = new Color(255, 255, 255, TransitionAlpha);
00155
00156 spriteBatch.Begin();
00157
00158
00159 spriteBatch.Draw(gradientTexture, backgroundRectangle, color);
00160
00161
00162 spriteBatch.DrawString(font, message, textPosition, color);
00163
00164 spriteBatch.End();
00165 }
00166
00167
00168 #endregion
00169 }
00170 }