- Main Page
- Classes
- Files

- File List

# C:/Users/Andreas Schiffler/Desktop/SVN/NewGamePhysics/GravityChooser/Screens/GravityChooserOptionsMenuScreen.cs

    00001 //-----------------------------------------------------------------------------
    00002 // GravityChooserOptionsMenuScreen.cs
    00003 // (A. Schiffler, 2009-2011)
    00004 //-----------------------------------------------------------------------------
    00005
    00006 namespace GravityChooser
    00007 {
    00008     using System;
    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
    00020     class GravityChooserOptionsMenuScreen : MenuScreen
    00021     {
    00025         private ScrollingText scrollingInfoText;
    00026
    00030         private MenuEntry celestialObjectMenuEntry;
    00031
    00035         private MenuEntry earthGravityModelMenuEntry;
    00036
    00037         #region constructor
    00038
    00042         public GravityChooserOptionsMenuScreen()
    00043             : base("Gravity Chooser Options")
    00044         {
    00045             // Create our menu entries
    00046             celestialObjectMenuEntry = new MenuEntry(string.Empty);
    00047             celestialObjectMenuEntry.Selected += CelestialObjectMenuEntrySelected;
    00048             MenuEntries.Add(celestialObjectMenuEntry);
    00049
    00050             earthGravityModelMenuEntry = new MenuEntry(string.Empty);
    00051             earthGravityModelMenuEntry.Selected += EarthGravityModelMenuEntrySelected;
    00052             MenuEntries.Add(earthGravityModelMenuEntry);
    00053
    00054             MenuEntry backMenuEntry = new MenuEntry("Back to Main Menu");
    00055             backMenuEntry.Selected += OnCancel;
    00056             MenuEntries.Add(backMenuEntry);
    00057         }
    00058
    00059         #endregion
    00060
    00064         public override void LoadContent()
    00065         {
    00066             base.LoadContent();
    00067
    00068             // Create scroller
    00069             SpriteFont font = ScreenManager.Fonts["menu"];
    00070             int width = ScreenManager.GraphicsDevice.Viewport.Width;
    00071             scrollingInfoText = new ScrollingText("-", font, width, 400); // text will be set later
    00072             scrollingInfoText.ScrollerSpeed = 200.0f;
    00073         }
    00074
    00085         public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
    00086         {
    00087             if (WaitForUncover)
    00088             {
    00089                 if ((!coveredByOtherScreen) || (!otherScreenHasFocus))
    00090                 {
    00091                     // Update the texts
    00092                     UpdateAllTexts();
    00093
    00094                     // Update menu text
    00095                     WaitForUncover = false;
    00096                 }
    00097             }
    00098
    00099             // Update scrollers
    00100             scrollingInfoText.Update(gameTime);
    00101
    00102             base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
    00103         }
    00104
    00109         public override void Draw(GameTime gameTime)
    00110         {
    00111             base.Draw(gameTime);
    00112
    00113             // Draw scroller
    00114             SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
    00115             scrollingInfoText.Draw(gameTime, spriteBatch);
    00116         }
    00117
    00118         #region private_methods
    00119
    00123         private void UpdateAllTexts()
    00124         {
    00125             UpdateMenuText();
    00126             UpdateInfoText();
    00127         }
    00128
    00132         private void UpdateMenuText()
    00133         {
    00134             // Menu text
    00135             celestialObjectMenuEntry.Text =
    00136                 "Celestial Object: " + GravityChooser.state.CurrentCelestialObject.ToString();
    00137
    00138             earthGravityModelMenuEntry.Text =
    00139                     "Gravity Model: ";
    00140             if (GravityChooser.state.CurrentCelestialObject == CelestialObject.Earth)
    00141             {
    00142                 earthGravityModelMenuEntry.Text +=
    00143                     GravityChooser.state.CurrentEarthGravityModel.ToString();
    00144             }
    00145             else
    00146             {
    00147                 earthGravityModelMenuEntry.Text +=
    00148                     "- not available -";
    00149             }
    00150         }
    00151
    00155         private void UpdateInfoText()
    00156         {
    00157             // Scroller text
    00158             if (null != scrollingInfoText)
    00159             {
    00160                 CelestialBody celestialBody = new CelestialBody(GravityChooser.state.CurrentCelestialObject);
    00161                 string infoText =
    00162                     GravityChooser.state.CurrentCelestialObject.ToString() +
    00163                     ": " +
    00164                     celestialBody.GetBodyInfo();
    00165                 infoText = infoText.Replace("\n", "  *  ");
    00166                 scrollingInfoText.Text = infoText;
    00167             }
    00168         }
    00169
    00170         #endregion
    00171
    00172         #region event_handlers
    00173
    00179         private void CelestialObjectMenuEntrySelected(object sender, PlayerIndexEventArgs e)
    00180         {
    00181             // Select next item form the celestial body enumeration
    00182             int currentIndex = EnumConvert.ChangeTo<int>(GravityChooser.state.CurrentCelestialObject);
    00183             int maxIndex = Enum.GetValues(typeof(CelestialObject)).Length;
    00184             currentIndex++;
    00185             if (currentIndex == maxIndex)
    00186             {
    00187                 currentIndex = 0;
    00188             }
    00189
    00190             GravityChooser.state.CurrentCelestialObject = EnumConvert.ChangeTo<CelestialObject>(currentIndex);
    00191
    00192             // Reset gravity selection
    00193             GravityChooser.state.CurrentGravity = 0.0;
    00194
    00195             // Update menu
    00196             UpdateAllTexts();
    00197         }
    00198
    00204         private void EarthGravityModelMenuEntrySelected(object sender, PlayerIndexEventArgs e)
    00205         {
    00206             // Select next item form the celestial body enumeration
    00207             int currentIndex = EnumConvert.ChangeTo<int>(GravityChooser.state.CurrentEarthGravityModel);
    00208             int maxIndex = Enum.GetValues(typeof(EarthGravityModel)).Length;
    00209             currentIndex++;
    00210             if (currentIndex == maxIndex)
    00211             {
    00212                 currentIndex = 0;
    00213             }
    00214
    00215             GravityChooser.state.CurrentEarthGravityModel = EnumConvert.ChangeTo<EarthGravityModel>(currentIndex);
    00216
    00217             // Reset gravity selection
    00218             GravityChooser.state.CurrentGravity = 0.0;
    00219
    00220             // Update menu
    00221             UpdateMenuText();
    00222         }
    00223
    00224         #endregion
    00225     }
    00226 }