MainMenuScreen.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // MainMenuScreen.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. #if IPHONE
  11. using Microsoft.Xna.Framework;
  12. #else
  13. using Microsoft.Xna.Framework;
  14. #endif
  15. #endregion
  16. namespace Microsoft.Xna.Samples.GameStateManagement
  17. {
  18. /// <summary>
  19. /// The main menu screen is the first thing displayed when the game starts up.
  20. /// </summary>
  21. class MainMenuScreen : MenuScreen
  22. {
  23. #region Initialization
  24. /// <summary>
  25. /// Constructor fills in the menu contents.
  26. /// </summary>
  27. public MainMenuScreen()
  28. : base("Main Menu")
  29. {
  30. // Create our menu entries.
  31. MenuEntry playGameMenuEntry = new MenuEntry("Play Game");
  32. MenuEntry optionsMenuEntry = new MenuEntry("Options");
  33. MenuEntry exitMenuEntry = new MenuEntry("Exit");
  34. // Hook up menu event handlers.
  35. playGameMenuEntry.Selected += PlayGameMenuEntrySelected;
  36. optionsMenuEntry.Selected += OptionsMenuEntrySelected;
  37. exitMenuEntry.Selected += OnCancel;
  38. // Add entries to the menu.
  39. MenuEntries.Add(playGameMenuEntry);
  40. MenuEntries.Add(optionsMenuEntry);
  41. MenuEntries.Add(exitMenuEntry);
  42. }
  43. #endregion
  44. #region Handle Input
  45. /// <summary>
  46. /// Event handler for when the Play Game menu entry is selected.
  47. /// </summary>
  48. void PlayGameMenuEntrySelected(object sender, PlayerIndexEventArgs e)
  49. {
  50. LoadingScreen.Load(ScreenManager, true, e.PlayerIndex,
  51. new GameplayScreen());
  52. }
  53. /// <summary>
  54. /// Event handler for when the Options menu entry is selected.
  55. /// </summary>
  56. void OptionsMenuEntrySelected(object sender, PlayerIndexEventArgs e)
  57. {
  58. ScreenManager.AddScreen(new OptionsMenuScreen(), e.PlayerIndex);
  59. }
  60. /// <summary>
  61. /// When the user cancels the main menu, ask if they want to exit the sample.
  62. /// </summary>
  63. protected override void OnCancel(PlayerIndex playerIndex)
  64. {
  65. const string message = "Are you sure you want to exit?";
  66. MessageBoxScreen confirmExitMessageBox = new MessageBoxScreen(message);
  67. confirmExitMessageBox.Accepted += ConfirmExitMessageBoxAccepted;
  68. ScreenManager.AddScreen(confirmExitMessageBox, playerIndex);
  69. }
  70. /// <summary>
  71. /// Event handler for when the user selects ok on the "are you sure
  72. /// you want to exit" message box.
  73. /// </summary>
  74. void ConfirmExitMessageBoxAccepted(object sender, PlayerIndexEventArgs e)
  75. {
  76. ScreenManager.Game.Exit();
  77. }
  78. #endregion
  79. }
  80. }