# NewGamePhysics.StateManager.MenuScreen Class Reference

Base class for screens that contain a menu of options. The user can move up and down to select an entry, or cancel to back out of the screen. More...

Inheritance diagram for NewGamePhysics.StateManager.MenuScreen:

List of all members.

## Public Member Functions
| MenuScreen (string menuTitle)
| Constructor.
override void | HandleInput (InputState input)
| Responds to user input, changing the selected entry and accepting or cancelling the menu.
override void | Update (GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
| Updates the menu.
override void | Draw (GameTime gameTime)
| Draws the menu.
## Protected Member Functions
virtual void | OnSelectEntry (int entryIndex, PlayerIndex playerIndex)
| Handler for when the user has chosen a menu entry.
virtual void | OnCancel (PlayerIndex playerIndex)
| Handler for when the user has cancelled the menu.
void | OnCancel (object sender, PlayerIndexEventArgs e)
| Helper overload makes it easy to use OnCancel as a MenuEntry event handler.
## Properties
IList< MenuEntry > | MenuEntries`[get]`
| Gets the list of menu entries, so derived classes can add or change the menu contents.
int | SelectedEntry`[get, set]`
| Gets or sets the currently selected menu entry.
bool | WaitForUncover`[get, set]`
| Gets the list of menu entries, so derived classes can add or change the menu contents.

## Detailed Description

Base class for screens that contain a menu of options. The user can move up and down to select an entry, or cancel to back out of the screen.

Definition at line 18 of file MenuScreen.cs.

## Constructor & Destructor Documentation

NewGamePhysics.StateManager.MenuScreen.MenuScreen | ( | string | menuTitle | ) |

Constructor.

Definition at line 86 of file MenuScreen.cs.

    00087         {
    00088             this.menuTitle = menuTitle;
    00089
    00090             TransitionOnTime = TimeSpan.FromSeconds(0.5);
    00091             TransitionOffTime = TimeSpan.FromSeconds(0.5);
    00092         }

## Member Function Documentation

override void NewGamePhysics.StateManager.MenuScreen.Draw | ( | GameTime | gameTime | ) | `[virtual]`

Draws the menu.

Parameters:

  | gameTime |

Reimplemented from NewGamePhysics.StateManager.GameScreen.

Reimplemented in GravityChooser.GravityChooserMainMenuScreen, GravityChooser.GravityChooserOptionsMenuScreen, GravityChooser.GravityChooserPauseMenuScreen, MontyHallGame.MontyHallGameOverScreen, MontyHallGame.MontyHallMainMenuScreen, MontyHallGame.MontyHallOptionsMenuScreen, MontyHallGame.MontyHallPauseMenuScreen, PendulumGame.PendulumGameOverScreen, PendulumGame.PendulumOptionsMenuScreen, and PendulumGame.PendulumPauseMenuScreen.

Definition at line 196 of file MenuScreen.cs.

    00197         {
    00198             SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
    00199             SpriteFont font = ScreenManager.Fonts["menu"];
    00200             Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
    00201
    00202             // Measure size of menu stack
    00203             float menuSize = 0.0f;
    00204             for (int i = 0; i < menuEntries.Count; i++)
    00205             {
    00206                 MenuEntry menuEntry = menuEntries[i];
    00207                 menuSize += (menuEntry.GetHeight(this) + 5);
    00208             }
    00209
    00210             // Center menu vertically
    00211             Vector2 position = new Vector2(
    00212                 viewport.Width / 2 - 200,
    00213                 (viewport.Height - menuSize) / 2);
    00214
    00215             // Make the menu slide into place during transitions, using a
    00216             // power curve to make things look more interesting (this makes
    00217             // the movement slow down as it nears the end).
    00218             float transitionOffset = (float)Math.Pow(TransitionPosition, 2);
    00219
    00220             if (ScreenState == ScreenState.TransitionOn)
    00221             {
    00222                 position.X -= transitionOffset * 256;
    00223             }
    00224             else
    00225             {
    00226                 position.X += transitionOffset * 512;
    00227             }
    00228
    00229             spriteBatch.Begin();
    00230
    00231             // Draw each menu entry in turn.
    00232             for (int i = 0; i < menuEntries.Count; i++)
    00233             {
    00234                 MenuEntry menuEntry = menuEntries[i];
    00235
    00236                 bool isSelected = IsActive && (i == selectedEntry);
    00237
    00238                 menuEntry.Draw(this, position, isSelected, gameTime);
    00239
    00240
    00241                 position.Y += (menuEntry.GetHeight(this) + 5);
    00242             }
    00243
    00244             // Create translucent pane rectangle
    00245             if (this.paneTexture == null)
    00246             {
    00247                 // New background texture
    00248                 this.paneTexture = TextureHelpers.Create(ScreenManager.GraphicsDevice, new Color(64, 64, 64));
    00249             }
    00250
    00251             // Draw the menu title.
    00252             float titleScale = 1.5f;
    00253             Vector2 titlePosition = new Vector2(position.X, viewport.Height/2);
    00254             Vector2 titleSize = font.MeasureString(menuTitle);
    00255             Vector2 titleOrigin = titleSize / 2;
    00256             Color titleColor = new Color(255, 255, 255, TransitionAlpha);
    00257             titlePosition.X -= titleSize.Y * titleScale;
    00258             titlePosition.Y -= transitionOffset * 100;
    00259             Color paneColor = new Color(4, 4, 4);
    00260             Rectangle backgroundPane =
    00261                 new Rectangle(
    00262                     (int)(titlePosition.X - titleOrigin.Y), 0, (int)titleSize.Y, viewport.Height);
    00263             spriteBatch.Draw(this.paneTexture, backgroundPane, new Color(paneColor, 128));
    00264
    00265             spriteBatch.DrawString(font, menuTitle, titlePosition, titleColor, 3.0f*(float)Math.PI/2.0f,
    00266                                    titleOrigin, titleScale, SpriteEffects.None, 0);
    00267
    00268             spriteBatch.End();
    00269         }

override void NewGamePhysics.StateManager.MenuScreen.HandleInput | ( | InputState | input | ) | `[virtual]`

Responds to user input, changing the selected entry and accepting or cancelling the menu.

Reimplemented from NewGamePhysics.StateManager.GameScreen.

Definition at line 102 of file MenuScreen.cs.

    00103         {
    00104             // Move to the previous menu entry?
    00105             if (input.IsNewInputUp(ControllingPlayer))
    00106             {
    00107                 this.selectedEntry--;
    00108
    00109                 if (this.selectedEntry < 0)
    00110                 {
    00111                     this.selectedEntry = this.menuEntries.Count - 1;
    00112                 }
    00113             }
    00114
    00115             // Move to the next menu entry?
    00116             if (input.IsNewInputDown(ControllingPlayer))
    00117             {
    00118                 this.selectedEntry++;
    00119
    00120                 if (this.selectedEntry >= this.menuEntries.Count)
    00121                 {
    00122                     this.selectedEntry = 0;
    00123                 }
    00124             }
    00125
    00126             // Accept or cancel the menu? We pass in our ControllingPlayer, which may
    00127             // either be null (to accept input from any player) or a specific index.
    00128             // If we pass a null controlling player, the InputState helper returns to
    00129             // us which player actually provided the input. We pass that through to
    00130             // OnSelectEntry and OnCancel, so they can tell which player triggered them.
    00131             PlayerIndex playerIndex;
    00132
    00133             if (input.IsMenuSelect(ControllingPlayer, out playerIndex))
    00134             {
    00135                 OnSelectEntry(this.selectedEntry, playerIndex);
    00136             }
    00137             else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
    00138             {
    00139                 OnCancel(playerIndex);
    00140             }
    00141         }

void NewGamePhysics.StateManager.MenuScreen.OnCancel | ( | object | sender,
|  | PlayerIndexEventArgs | e |
| ) |  |  | `[protected]`

Helper overload makes it easy to use OnCancel as a MenuEntry event handler.

Definition at line 162 of file MenuScreen.cs.

    00163         {
    00164             OnCancel(e.PlayerIndex);
    00165         }

virtual void NewGamePhysics.StateManager.MenuScreen.OnCancel | ( | PlayerIndex | playerIndex | ) | `[protected, virtual]`

Handler for when the user has cancelled the menu.

Reimplemented in GravityChooser.GravityChooserMainMenuScreen, MontyHallGame.MontyHallMainMenuScreen, and PendulumGame.PendulumMainMenuScreen.

Definition at line 154 of file MenuScreen.cs.

    00155         {
    00156             ExitScreen();
    00157         }

virtual void NewGamePhysics.StateManager.MenuScreen.OnSelectEntry | ( | int | entryIndex,
|  | PlayerIndex | playerIndex |
| ) |  |  | `[protected, virtual]`

Handler for when the user has chosen a menu entry.

Definition at line 146 of file MenuScreen.cs.

    00147         {
    00148             menuEntries[this.selectedEntry].OnSelectEntry(playerIndex);
    00149         }

override void NewGamePhysics.StateManager.MenuScreen.Update | ( | GameTime | gameTime,
|  | bool | otherScreenHasFocus,
|  | bool | coveredByOtherScreen |
| ) |  |  | `[virtual]`

Updates the menu.

Parameters:

  | gameTime |
  | coveredByOtherScreen |
  | otherScreenHasFocus |

Reimplemented from NewGamePhysics.StateManager.GameScreen.

Reimplemented in GravityChooser.GravityChooserMainMenuScreen, GravityChooser.GravityChooserOptionsMenuScreen, MontyHallGame.MontyHallMainMenuScreen, MontyHallGame.MontyHallOptionsMenuScreen, PendulumGame.PendulumGameOverScreen, and PendulumGame.PendulumOptionsMenuScreen.

Definition at line 177 of file MenuScreen.cs.

    00179         {
    00180             base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
    00181
    00182             // Update each nested MenuEntry object.
    00183             for (int i = 0; i < menuEntries.Count; i++)
    00184             {
    00185                 bool isSelected = IsActive && (i == selectedEntry);
    00186
    00187                 menuEntries[i].Update(this, isSelected, gameTime);
    00188             }
    00189         }

## Property Documentation

IList<MenuEntry> NewGamePhysics.StateManager.MenuScreen.MenuEntries`[get, protected]`

Gets the list of menu entries, so derived classes can add or change the menu contents.

Definition at line 56 of file MenuScreen.cs.

int NewGamePhysics.StateManager.MenuScreen.SelectedEntry`[get, set]`

Gets or sets the currently selected menu entry.

Definition at line 64 of file MenuScreen.cs.

bool NewGamePhysics.StateManager.MenuScreen.WaitForUncover`[get, set, protected]`

Gets the list of menu entries, so derived classes can add or change the menu contents.

Definition at line 74 of file MenuScreen.cs.

The documentation for this class was generated from the following file:

- C:/Users/Andreas Schiffler/Desktop/SVN/NewGamePhysics/NewGamePhysics/StateManager/MenuScreen.cs