PauseMenuScreen.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. using Microsoft.Xna.Framework;
  11. #endregion
  12. namespace GameStateManagement
  13. {
  14. /// <summary>
  15. /// The pause menu comes up over the top of the game,
  16. /// giving the player options to resume or quit.
  17. /// </summary>
  18. class PauseMenuScreen : MenuScreen
  19. {
  20. #region Initialization
  21. /// <summary>
  22. /// Constructor.
  23. /// </summary>
  24. public PauseMenuScreen()
  25. : base("Paused")
  26. {
  27. // Create our menu entries.
  28. MenuEntry resumeGameMenuEntry = new MenuEntry("Resume Game");
  29. MenuEntry quitGameMenuEntry = new MenuEntry("Quit Game");
  30. // Hook up menu event handlers.
  31. resumeGameMenuEntry.Selected += OnCancel;
  32. quitGameMenuEntry.Selected += QuitGameMenuEntrySelected;
  33. // Add entries to the menu.
  34. MenuEntries.Add(resumeGameMenuEntry);
  35. MenuEntries.Add(quitGameMenuEntry);
  36. }
  37. #endregion
  38. #region Handle Input
  39. /// <summary>
  40. /// Event handler for when the Quit Game menu entry is selected.
  41. /// </summary>
  42. void QuitGameMenuEntrySelected(object sender, PlayerIndexEventArgs e)
  43. {
  44. const string message = "Are you sure you want to quit this game?";
  45. MessageBoxScreen confirmQuitMessageBox = new MessageBoxScreen(message);
  46. confirmQuitMessageBox.Accepted += ConfirmQuitMessageBoxAccepted;
  47. ScreenManager.AddScreen(confirmQuitMessageBox, ControllingPlayer);
  48. }
  49. /// <summary>
  50. /// Event handler for when the user selects ok on the "are you sure
  51. /// you want to quit" message box. This uses the loading screen to
  52. /// transition from the game back to the main menu screen.
  53. /// </summary>
  54. void ConfirmQuitMessageBoxAccepted(object sender, PlayerIndexEventArgs e)
  55. {
  56. LoadingScreen.Load(ScreenManager, false, null, new BackgroundScreen(),
  57. new MainMenuScreen());
  58. }
  59. #endregion
  60. }
  61. }