MainMenuScreen.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. namespace UserInterfaceSample
  9. {
  10. /// <summary>
  11. /// The main menu screen is the first thing displayed when the game starts up.
  12. /// </summary>
  13. class MainMenuScreen : MenuScreen
  14. {
  15. /// <summary>
  16. /// Constructor fills in the menu contents.
  17. /// </summary>
  18. public MainMenuScreen()
  19. : base("Main Menu")
  20. {
  21. // Create our menu entries.
  22. MenuEntry levelSelect = new MenuEntry("Select level");
  23. levelSelect.Selected += SelectLevelPressed;
  24. MenuEntries.Add(levelSelect);
  25. MenuEntry highScores = new MenuEntry("High scores");
  26. highScores.Selected += HighScoresPressed;
  27. MenuEntries.Add(highScores);
  28. }
  29. /// <summary>
  30. /// Event handler for our Select Level button.
  31. /// </summary>
  32. private void SelectLevelPressed(object sender, PlayerIndexEventArgs e)
  33. {
  34. // We use the loading screen to move to our level selection screen because the
  35. // level selection screen needs to load in a decent amount of level art. The Load
  36. // method will cause all current screens to exit, so to enable us to be able to
  37. // easily come back from the level select screen, we must also pass down the
  38. // background and main menu screens.
  39. LoadingScreen.Load(
  40. ScreenManager,
  41. true,
  42. e.PlayerIndex,
  43. new BackgroundScreen(), new MainMenuScreen(), new LevelSelectScreen());
  44. }
  45. /// <summary>
  46. /// Event handler for our High Scores button.
  47. /// </summary>
  48. private void HighScoresPressed(object sender, PlayerIndexEventArgs e)
  49. {
  50. ScreenManager.AddScreen(new HighScoreScreen(), e.PlayerIndex);
  51. }
  52. /// <summary>
  53. /// When the user cancels the main menu, we exit the game.
  54. /// </summary>
  55. protected override void OnCancel(PlayerIndex playerIndex)
  56. {
  57. ScreenManager.Game.Exit();
  58. }
  59. }
  60. }