#region File Description //----------------------------------------------------------------------------- // MainMenuScreen.cs // // Microsoft XNA Community Game Platform // Copyright (C) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- #endregion #region Using Statements using Microsoft.Xna.Framework; using GameStateManagementSample; #endregion namespace GameStateManagement { /// /// The main menu screen is the first thing displayed when the game starts up. /// class MainMenuScreen : MenuScreen { #region Initialization /// /// Constructor fills in the menu contents. /// public MainMenuScreen() : base("Main Menu") { // Create our menu entries. MenuEntry playGameMenuEntry = new MenuEntry("Play Game"); MenuEntry optionsMenuEntry = new MenuEntry("Options"); MenuEntry exitMenuEntry = new MenuEntry("Exit"); // Hook up menu event handlers. playGameMenuEntry.Selected += PlayGameMenuEntrySelected; optionsMenuEntry.Selected += OptionsMenuEntrySelected; exitMenuEntry.Selected += OnCancel; // Add entries to the menu. MenuEntries.Add(playGameMenuEntry); MenuEntries.Add(optionsMenuEntry); MenuEntries.Add(exitMenuEntry); } #endregion #region Handle Input /// /// Event handler for when the Play Game menu entry is selected. /// void PlayGameMenuEntrySelected(object sender, PlayerIndexEventArgs e) { LoadingScreen.Load(ScreenManager, true, e.PlayerIndex, new GameplayScreen()); } /// /// Event handler for when the Options menu entry is selected. /// void OptionsMenuEntrySelected(object sender, PlayerIndexEventArgs e) { ScreenManager.AddScreen(new OptionsMenuScreen(), e.PlayerIndex); } /// /// When the user cancels the main menu, ask if they want to exit the sample. /// protected override void OnCancel(PlayerIndex playerIndex) { const string message = "Are you sure you want to exit this sample?"; MessageBoxScreen confirmExitMessageBox = new MessageBoxScreen(message); confirmExitMessageBox.Accepted += ConfirmExitMessageBoxAccepted; ScreenManager.AddScreen(confirmExitMessageBox, playerIndex); } /// /// Event handler for when the user selects ok on the "are you sure /// you want to exit" message box. /// void ConfirmExitMessageBoxAccepted(object sender, PlayerIndexEventArgs e) { ScreenManager.Game.Exit(); } #endregion } }