PauseMenuScreen.cs 2.2 KB

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