MainMenuScreen.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //-----------------------------------------------------------------------------
  2. // MainMenuScreen.cs
  3. //
  4. // Microsoft XNA Community Game Platform
  5. // Copyright (C) Microsoft Corporation. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. using Microsoft.Xna.Framework;
  8. using Microsoft.Xna.Framework.Net;
  9. namespace NetworkStateManagement
  10. {
  11. /// <summary>
  12. /// The main menu screen is the first thing displayed when the game starts up.
  13. /// </summary>
  14. class MainMenuScreen : MenuScreen
  15. {
  16. /// <summary>
  17. /// Constructor fills in the menu contents.
  18. /// </summary>
  19. public MainMenuScreen()
  20. : base(Resources.MainMenu)
  21. {
  22. // Create our menu entries.
  23. MenuEntry singlePlayerMenuEntry = new MenuEntry(Resources.SinglePlayer);
  24. // TODO MenuEntry liveMenuEntry = new MenuEntry(Resources.PlayerMatch);
  25. MenuEntry systemLinkMenuEntry = new MenuEntry(Resources.SystemLink);
  26. MenuEntry exitMenuEntry = new MenuEntry(Resources.Exit);
  27. // Hook up menu event handlers.
  28. singlePlayerMenuEntry.Selected += SinglePlayerMenuEntrySelected;
  29. // TODO liveMenuEntry.Selected += LiveMenuEntrySelected;
  30. systemLinkMenuEntry.Selected += SystemLinkMenuEntrySelected;
  31. exitMenuEntry.Selected += OnCancel;
  32. // Add entries to the menu.
  33. // TODO MenuEntries.Add(liveMenuEntry);
  34. MenuEntries.Add(systemLinkMenuEntry);
  35. MenuEntries.Add(singlePlayerMenuEntry);
  36. MenuEntries.Add(exitMenuEntry);
  37. }
  38. /// <summary>
  39. /// Event handler for when the Single Player menu entry is selected.
  40. /// </summary>
  41. void SinglePlayerMenuEntrySelected(object sender, PlayerIndexEventArgs e)
  42. {
  43. LoadingScreen.Load(ScreenManager, true, e.PlayerIndex,
  44. new GameplayScreen(null));
  45. }
  46. /// <summary>
  47. /// Event handler for when the Live menu entry is selected.
  48. /// </summary>
  49. void LiveMenuEntrySelected(object sender, PlayerIndexEventArgs e)
  50. {
  51. CreateOrFindSession(NetworkSessionType.PlayerMatch, e.PlayerIndex);
  52. }
  53. /// <summary>
  54. /// Event handler for when the System Link menu entry is selected.
  55. /// </summary>
  56. void SystemLinkMenuEntrySelected(object sender, PlayerIndexEventArgs e)
  57. {
  58. CreateOrFindSession(NetworkSessionType.SystemLink, e.PlayerIndex);
  59. }
  60. /// <summary>
  61. /// Helper method shared by the Live and System Link menu event handlers.
  62. /// </summary>
  63. void CreateOrFindSession(NetworkSessionType sessionType,
  64. PlayerIndex playerIndex)
  65. {
  66. // First, we need to make sure a suitable gamer profile is signed in.
  67. ProfileSignInScreen profileSignIn = new ProfileSignInScreen(sessionType);
  68. // Hook up an event so once the ProfileSignInScreen is happy,
  69. // it will activate the CreateOrFindSessionScreen.
  70. profileSignIn.ProfileSignedIn += delegate
  71. {
  72. GameScreen createOrFind = new CreateOrFindSessionScreen(sessionType);
  73. ScreenManager.AddScreen(createOrFind, playerIndex);
  74. };
  75. // Activate the ProfileSignInScreen.
  76. ScreenManager.AddScreen(profileSignIn, playerIndex);
  77. }
  78. /// <summary>
  79. /// When the user cancels the main menu, ask if they want to exit the sample.
  80. /// </summary>
  81. protected override void OnCancel(PlayerIndex playerIndex)
  82. {
  83. MessageBoxScreen confirmExitMessageBox =
  84. new MessageBoxScreen(Resources.ConfirmExitSample);
  85. confirmExitMessageBox.Accepted += ConfirmExitMessageBoxAccepted;
  86. ScreenManager.AddScreen(confirmExitMessageBox, playerIndex);
  87. }
  88. /// <summary>
  89. /// Event handler for when the user selects ok on the "are you sure
  90. /// you want to exit" message box.
  91. /// </summary>
  92. void ConfirmExitMessageBoxAccepted(object sender, PlayerIndexEventArgs e)
  93. {
  94. ScreenManager.Game.Exit();
  95. }
  96. }
  97. }