00001
00002
00003
00004
00005 namespace PendulumGame
00006 {
00007 using System;
00008 using System.Text;
00009 using Microsoft.Xna.Framework;
00010 using Microsoft.Xna.Framework.Graphics;
00011
00012 using NewGamePhysics.StateManager;
00013 using NewGamePhysics.Utilities;
00014 using NewGamePhysics.Physics;
00015 using NewGamePhysics.GraphicalElements;
00016 using NewGamePhysics.PhysicalElements;
00017 using NewGamePhysics.Networking;
00018
00022 class PendulumOptionsMenuScreen : MenuScreen
00023 {
00027 private ScrollingText scrollingInfoText;
00028
00032 private MenuEntry chooseGravityMenuEntry;
00033
00037 private MenuEntry celestialObjectMenuEntry;
00038
00042 private MenuEntry gravityModelMenuEntry;
00043
00047 private MenuEntry rotationalFrictionTypeMenuEntry;
00048
00052 private MenuEntry entropySourceTypeMenuEntry;
00053
00054 #region constructor
00055
00059 public PendulumOptionsMenuScreen()
00060 : base("Game Options")
00061 {
00062 this.chooseGravityMenuEntry = new MenuEntry("*");
00063 this.chooseGravityMenuEntry.Selected += ChooseGravityMenuEntrySelected;
00064 MenuEntries.Add(this.chooseGravityMenuEntry);
00065
00066 this.celestialObjectMenuEntry = new MenuEntry(string.Empty);
00067 this.celestialObjectMenuEntry.Selected += CelestialObjectMenuEntrySelected;
00068 MenuEntries.Add(this.celestialObjectMenuEntry);
00069
00070 this.gravityModelMenuEntry = new MenuEntry(string.Empty);
00071 this.gravityModelMenuEntry.Selected += GravityModelMenuEntrySelected;
00072 MenuEntries.Add(this.gravityModelMenuEntry);
00073
00074 this.rotationalFrictionTypeMenuEntry = new MenuEntry(string.Empty);
00075 this.rotationalFrictionTypeMenuEntry.Selected += RotationalFrictionTypeMenuEntrySelected;
00076 MenuEntries.Add(this.rotationalFrictionTypeMenuEntry);
00077
00078 this.entropySourceTypeMenuEntry = new MenuEntry(string.Empty);
00079 this.entropySourceTypeMenuEntry.Selected += EntropySourceTypeMenuEntrySelected;
00080 MenuEntries.Add(this.entropySourceTypeMenuEntry);
00081
00082 MenuEntry backMenuEntry = new MenuEntry("Back to Main Menu");
00083 backMenuEntry.Selected += OnCancel;
00084 MenuEntries.Add(backMenuEntry);
00085
00086
00087 UpdateAllTexts();
00088 }
00089
00093 public override void LoadContent()
00094 {
00095
00096 base.LoadContent();
00097
00098
00099 SpriteFont font = ScreenManager.Fonts["game"];
00100 int width = ScreenManager.GraphicsDevice.Viewport.Width;
00101 int yPos = ScreenManager.GraphicsDevice.Viewport.Height - 32;
00102
00103
00104 scrollingInfoText = new ScrollingText("-", font, width, yPos);
00105 scrollingInfoText.TextScale = 0.5f;
00106 scrollingInfoText.ScrollerSpeed = 200.0f;
00107
00108
00109 Program.Game.SendRandomInfoLink("Gravity");
00110 }
00111
00115 public override void UnloadContent()
00116 {
00117
00118 base.UnloadContent();
00119 }
00120
00131 public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
00132 {
00133 if (WaitForUncover)
00134 {
00135 if ((!coveredByOtherScreen) || (!otherScreenHasFocus))
00136 {
00137
00138 UpdateAllTexts();
00139
00140
00141 WaitForUncover = false;
00142 }
00143 }
00144
00145
00146 scrollingInfoText.Update(gameTime);
00147
00148 base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
00149 }
00150
00155 public override void Draw(GameTime gameTime)
00156 {
00157 base.Draw(gameTime);
00158
00159
00160 SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
00161 scrollingInfoText.Draw(gameTime, spriteBatch);
00162 }
00163
00164 #endregion
00165
00166 #region private_methods
00167
00171 private void UpdateAllTexts()
00172 {
00173 UpdateMenuText();
00174 UpdateInfoText();
00175 }
00176
00180 private void UpdateMenuText()
00181 {
00182
00183 this.chooseGravityMenuEntry.Text =
00184 "Choose Gravity and Play on " + PendulumGame.State.CurrentCelestialObject.ToString();
00185
00186
00187 celestialObjectMenuEntry.Text =
00188 "Celestial Object: " + PendulumGame.State.CurrentCelestialObject.ToString();
00189
00190 gravityModelMenuEntry.Text =
00191 "Gravity Model: ";
00192 if (PendulumGame.State.CurrentCelestialObject == CelestialObject.Earth)
00193 {
00194 gravityModelMenuEntry.Text +=
00195 PendulumGame.State.CurrentEarthGravityModel.ToString();
00196 }
00197 else if (PendulumGame.State.CurrentCelestialObject == CelestialObject.Mars)
00198 {
00199 gravityModelMenuEntry.Text +=
00200 PendulumGame.State.CurrentMarsGravityModel.ToString();
00201 }
00202 else
00203 {
00204 gravityModelMenuEntry.Text +=
00205 "-not applicable-";
00206 }
00207
00208 this.rotationalFrictionTypeMenuEntry.Text =
00209 "Rotational Friction Model: " + PendulumGame.State.CurrentRotationalFrictionType.ToString();
00210
00211 this.entropySourceTypeMenuEntry.Text =
00212 "Entropy Source: " + PendulumGame.State.CurrentEntropySourceType.ToString();
00213 }
00214
00218 private void UpdateInfoText()
00219 {
00220
00221 if (null != scrollingInfoText)
00222 {
00223 string infoText =
00224 "Current Gravity: g = " + PendulumGame.State.CurrentGravity.ToString() + " m/s^-2\n";
00225
00226 CelestialBody celestialBody = new CelestialBody(PendulumGame.State.CurrentCelestialObject);
00227 infoText +=
00228 PendulumGame.State.CurrentCelestialObject.ToString() +
00229 " Info: " +
00230 celestialBody.GetBodyInfo() +
00231 "\n";
00232 infoText = infoText.Replace("\n", " * ");
00233 scrollingInfoText.Text = infoText;
00234 }
00235 }
00236
00240 private void UpdateGravity()
00241 {
00242
00243 GravityCalculator gravityCalculator = new GravityCalculator(PendulumGame.State.CurrentCelestialObject);
00244 gravityCalculator.EarthGravityModel = PendulumGame.State.CurrentEarthGravityModel;
00245 PendulumGame.State.CurrentGravity = gravityCalculator.Value;
00246 }
00247
00248 #endregion
00249
00250 #region event_handlers
00251
00257 void ChooseGravityMenuEntrySelected(object sender, PlayerIndexEventArgs e)
00258 {
00259 PendulumLoadingScreen.Load(
00260 ScreenManager,
00261 true,
00262 e.PlayerIndex,
00263 new PendulumGravityChooserScreen());
00264
00265
00266 WaitForUncover = true;
00267 }
00268
00272 private void CelestialObjectMenuEntrySelected(object sender, PlayerIndexEventArgs e)
00273 {
00274
00275 int currentIndex = EnumConvert.ChangeTo<int>(PendulumGame.State.CurrentCelestialObject);
00276 int maxIndex = Enum.GetValues(typeof(CelestialObject)).Length;
00277 currentIndex++;
00278 if (currentIndex == maxIndex)
00279 {
00280 currentIndex = 0;
00281 }
00282
00283 PendulumGame.State.CurrentCelestialObject = EnumConvert.ChangeTo<CelestialObject>(currentIndex);
00284
00285
00286 UpdateGravity();
00287
00288
00289 UpdateAllTexts();
00290 }
00291
00297 private void GravityModelMenuEntrySelected(object sender, PlayerIndexEventArgs e)
00298 {
00299
00300 int currentIndex;
00301 int maxIndex;
00302 if (PendulumGame.State.CurrentCelestialObject == CelestialObject.Earth)
00303 {
00304 currentIndex = EnumConvert.ChangeTo<int>(PendulumGame.State.CurrentEarthGravityModel);
00305 maxIndex = Enum.GetValues(typeof(EarthGravityModel)).Length;
00306
00307
00308 maxIndex -= 2;
00309
00310 currentIndex = (currentIndex + 1) % maxIndex;
00311 PendulumGame.State.CurrentEarthGravityModel = EnumConvert.ChangeTo<EarthGravityModel>(currentIndex);
00312 }
00313 else if (PendulumGame.State.CurrentCelestialObject == CelestialObject.Mars)
00314 {
00315 currentIndex = EnumConvert.ChangeTo<int>(PendulumGame.State.CurrentMarsGravityModel);
00316 maxIndex = Enum.GetValues(typeof(MarsGravityModel)).Length;
00317 currentIndex = (currentIndex + 1) % maxIndex;
00318 PendulumGame.State.CurrentMarsGravityModel = EnumConvert.ChangeTo<MarsGravityModel>(currentIndex);
00319 }
00320 else
00321 {
00322 currentIndex = 0;
00323 }
00324
00325
00326 UpdateGravity();
00327
00328
00329 UpdateAllTexts();
00330 }
00331
00335 private void RotationalFrictionTypeMenuEntrySelected(object sender, PlayerIndexEventArgs e)
00336 {
00337
00338 int currentIndex = EnumConvert.ChangeTo<int>(PendulumGame.State.CurrentRotationalFrictionType);
00339 int maxIndex = Enum.GetValues(typeof(RotationalFrictionType)).Length;
00340 currentIndex++;
00341 if (currentIndex == maxIndex)
00342 {
00343 currentIndex = 0;
00344 }
00345
00346 PendulumGame.State.CurrentRotationalFrictionType = EnumConvert.ChangeTo<RotationalFrictionType>(currentIndex);
00347
00348
00349 UpdateMenuText();
00350 }
00351
00355 private void EntropySourceTypeMenuEntrySelected(object sender, PlayerIndexEventArgs e)
00356 {
00357
00358 int currentIndex = EnumConvert.ChangeTo<int>(PendulumGame.State.CurrentEntropySourceType);
00359 int maxIndex = Enum.GetValues(typeof(EntropySourceType)).Length;
00360 currentIndex++;
00361 if (currentIndex == maxIndex)
00362 {
00363 currentIndex = 0;
00364 }
00365
00366 PendulumGame.State.CurrentEntropySourceType = EnumConvert.ChangeTo<EntropySourceType>(currentIndex);
00367 PendulumGame.State.PhysicalRandomNumberGenerator.EntropySource = PendulumGame.State.CurrentEntropySourceType;
00368
00369
00370 UpdateMenuText();
00371 }
00372
00373 #endregion
00374 }
00375 }