00001
00002
00003
00004
00005
00006 namespace GravityChooser
00007 {
00008 using Microsoft.Xna.Framework;
00009 using Microsoft.Xna.Framework.Graphics;
00010 using NewGamePhysics.StateManager;
00011 using NewGamePhysics.Physics;
00012 using NewGamePhysics.GraphicalElements;
00013 using System;
00014 using System.IO;
00015 using System.Text;
00016
00020 class GravityChooserMainMenuScreen : MenuScreen
00021 {
00025 private ScrollingText scrollingInfoText;
00026
00030 private MenuEntry chooseValueMenuEntry;
00031
00035 public GravityChooserMainMenuScreen()
00036 : base("Gravity Chooser")
00037 {
00038
00039 this.chooseValueMenuEntry = new MenuEntry("*");
00040 MenuEntry optionsMenuEntry = new MenuEntry("Change Celestial Body");
00041 MenuEntry helpMenuEntry = new MenuEntry("Module Controls Help");
00042 MenuEntry infoMenuEntry = new MenuEntry("Module Information");
00043 MenuEntry doneMenuEntry = new MenuEntry("Done");
00044
00045
00046 chooseValueMenuEntry.Selected += ChooseValueMenuEntrySelected;
00047 optionsMenuEntry.Selected += OptionsMenuEntrySelected;
00048 infoMenuEntry.Selected += InfoMenuEntrySelected;
00049 helpMenuEntry.Selected += HelpMenuEntrySelected;
00050 doneMenuEntry.Selected += OnCancel;
00051
00052
00053 MenuEntries.Add(chooseValueMenuEntry);
00054 MenuEntries.Add(optionsMenuEntry);
00055 MenuEntries.Add(infoMenuEntry);
00056 MenuEntries.Add(helpMenuEntry);
00057 MenuEntries.Add(doneMenuEntry);
00058 }
00059
00060 public override void LoadContent()
00061 {
00062
00063 SpriteFont font = ScreenManager.Fonts["menu"];
00064 GravityChooser game = (GravityChooser)ScreenManager.Game;
00065 int width = game.GraphicsDevice.Viewport.Width;
00066 scrollingInfoText = new ScrollingText("-", font, width, 400);
00067
00068 base.LoadContent();
00069 }
00070
00071
00082 public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
00083 {
00084 if (WaitForUncover)
00085 {
00086 if ((!coveredByOtherScreen) || (!otherScreenHasFocus))
00087 {
00088
00089 UpdateAllTexts();
00090
00091
00092 WaitForUncover = false;
00093 }
00094 }
00095
00096
00097 scrollingInfoText.Update(gameTime);
00098
00099 base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
00100 }
00101
00106 public override void Draw(GameTime gameTime)
00107 {
00108 base.Draw(gameTime);
00109
00110
00111 SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
00112 scrollingInfoText.Draw(gameTime, spriteBatch);
00113 }
00114
00115 #region Handle Input
00116
00122 void ChooseValueMenuEntrySelected(object sender, PlayerIndexEventArgs e)
00123 {
00124 GravityChooserLoadingScreen.Load(ScreenManager, true, e.PlayerIndex,
00125 new GravityChooserGameplayScreen());
00126
00127
00128 WaitForUncover = true;
00129 }
00130
00136 void OptionsMenuEntrySelected(object sender, PlayerIndexEventArgs e)
00137 {
00138 ScreenManager.AddScreen(new GravityChooserOptionsMenuScreen(), null);
00139
00140
00141 this.SelectedEntry = 0;
00142
00143
00144 WaitForUncover = true;
00145 }
00146
00152 protected override void OnCancel(PlayerIndex playerIndex)
00153 {
00154
00155 string batchCode = "set GRAVITY=" + GravityChooser.state.CurrentGravity.ToString();
00156 File.WriteAllText("gravity.bat", batchCode);
00157
00158 ScreenManager.Game.Exit();
00159 }
00160
00161 #endregion
00162
00168 void InfoMenuEntrySelected(object sender, PlayerIndexEventArgs e)
00169 {
00170
00171 string[] messages = {
00172 "Information on The Gravity Chooser",
00173 "",
00174 "The Gravity Chooser is an implementation of a hypothetical game",
00175 "component which allows players to select gravity (hence the name).",
00176 "",
00177 "The gravity is not a constant value, but specific to the location",
00178 "due to the non-uniform shape and density of any celestial body.",
00179 "",
00180 "Geodesy research has generated very high quality models of the",
00181 "gravity of earth, some of which are available through the chooser.",
00182 "Other celestial bodies have significant different gravitatation",
00183 "which can be explored with the gravity chooser.",
00184 "",
00185 "The chooser returns the selected gravity for use by another game.",
00186 };
00187
00188 ScreenManager.AddScreen(new GravityChooserHelpScreen(messages), null);
00189
00190
00191 this.SelectedEntry = 0;
00192
00193
00194 WaitForUncover = true;
00195 }
00196
00202 void HelpMenuEntrySelected(object sender, PlayerIndexEventArgs e)
00203 {
00204
00205 string[] messages = {
00206 "Controls for The Gravity Chooser",
00207 "",
00208 " [Up]/[Down] cursor/pad",
00209 " [Left]/[Right] cursor/pad",
00210 " rotate the celestial body",
00211 " [Space] or (A)",
00212 " continue or select in menu, game or help screens",
00213 " [Escape] or (Back)",
00214 " pause game or quit to main menu",
00215 };
00216
00217 ScreenManager.AddScreen(new GravityChooserHelpScreen(messages), null);
00218
00219
00220 this.SelectedEntry = 0;
00221
00222
00223 WaitForUncover = true;
00224 }
00225
00229 private void UpdateAllTexts()
00230 {
00231
00232 chooseValueMenuEntry.Text =
00233 "Choose Your Gravity on " + GravityChooser.state.CurrentCelestialObject.ToString();
00234
00235
00236 if (null != scrollingInfoText)
00237 {
00238 scrollingInfoText.Text =
00239 "Your selected gravity on " + GravityChooser.state.CurrentCelestialObject.ToString() + ": ";
00240 if (GravityChooser.state.CurrentGravity > 0.0)
00241 {
00242 scrollingInfoText.Text = scrollingInfoText.Text +
00243 "g = " + GravityChooser.state.CurrentGravity.ToString() + " m/s^-2";
00244 }
00245 else
00246 {
00247 scrollingInfoText.Text = scrollingInfoText.Text +
00248 "not set yet.";
00249 }
00250 }
00251 }
00252 }
00253 }