PauseMenuScreen.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // PauseMenuScreen.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 pause menu comes up over the top of the game,
  20. /// giving the player options to resume or quit.
  21. /// </summary>
  22. class PauseMenuScreen : MenuScreen
  23. {
  24. #region Initialization
  25. /// <summary>
  26. /// Constructor.
  27. /// </summary>
  28. public PauseMenuScreen()
  29. : base("Paused")
  30. {
  31. // Flag that there is no need for the game to transition
  32. // off when the pause menu is on top of it.
  33. IsPopup = true;
  34. // Create our menu entries.
  35. MenuEntry resumeGameMenuEntry = new MenuEntry("Resume Game");
  36. MenuEntry quitGameMenuEntry = new MenuEntry("Quit Game");
  37. // Hook up menu event handlers.
  38. resumeGameMenuEntry.Selected += OnCancel;
  39. quitGameMenuEntry.Selected += QuitGameMenuEntrySelected;
  40. // Add entries to the menu.
  41. MenuEntries.Add(resumeGameMenuEntry);
  42. MenuEntries.Add(quitGameMenuEntry);
  43. }
  44. #endregion
  45. #region Handle Input
  46. /// <summary>
  47. /// Event handler for when the Quit Game menu entry is selected.
  48. /// </summary>
  49. void QuitGameMenuEntrySelected(object sender, PlayerIndexEventArgs e)
  50. {
  51. const string message = "Are you sure you want to quit this game?";
  52. MessageBoxScreen confirmQuitMessageBox = new MessageBoxScreen(message);
  53. confirmQuitMessageBox.Accepted += ConfirmQuitMessageBoxAccepted;
  54. ScreenManager.AddScreen(confirmQuitMessageBox, ControllingPlayer);
  55. }
  56. /// <summary>
  57. /// Event handler for when the user selects ok on the "are you sure
  58. /// you want to quit" message box. This uses the loading screen to
  59. /// transition from the game back to the main menu screen.
  60. /// </summary>
  61. void ConfirmQuitMessageBoxAccepted(object sender, PlayerIndexEventArgs e)
  62. {
  63. LoadingScreen.Load(ScreenManager, false, null, new BackgroundScreen(),
  64. new MainMenuScreen());
  65. }
  66. #endregion
  67. #region Draw
  68. /// <summary>
  69. /// Draws the pause menu screen. This darkens down the gameplay screen
  70. /// that is underneath us, and then chains to the base MenuScreen.Draw.
  71. /// </summary>
  72. public override void Draw(GameTime gameTime)
  73. {
  74. ScreenManager.FadeBackBufferToBlack(TransitionAlpha * 2 / 3);
  75. base.Draw(gameTime);
  76. }
  77. #endregion
  78. }
  79. }