OptionsMenu.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //-----------------------------------------------------------------------------
  2. // OptionsMenu.cs
  3. //
  4. // Microsoft XNA Community Game Platform
  5. // Copyright (C) Microsoft Corporation. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Text;
  10. using GameStateManagement;
  11. using Microsoft.Xna.Framework;
  12. using Microsoft.Xna.Framework.Graphics;
  13. using CardsFramework;
  14. using System.IO;
  15. namespace Blackjack
  16. {
  17. class OptionsMenu : MenuScreen
  18. {
  19. private CardsGame cardGame;
  20. Dictionary<string, Texture2D> themes = new Dictionary<string, Texture2D>();
  21. AnimatedGameComponent card;
  22. Texture2D background;
  23. Rectangle safeArea;
  24. /// <summary>
  25. /// Initializes a new instance of the screen.
  26. /// </summary>
  27. public OptionsMenu()
  28. : base("")
  29. {
  30. }
  31. public OptionsMenu(CardsGame cardGame)
  32. : base("")
  33. {
  34. this.cardGame = cardGame;
  35. }
  36. /// <summary>
  37. /// Loads content required by the screen, and initializes the displayed menu.
  38. /// </summary>
  39. public override void LoadContent()
  40. {
  41. safeArea = ScreenManager.SafeArea;
  42. // Create our menu entries.
  43. MenuEntry themeGameMenuEntry = new MenuEntry("Deck");
  44. MenuEntry returnMenuEntry = new MenuEntry("Return");
  45. // Hook up menu event handlers.
  46. themeGameMenuEntry.Selected += ThemeGameMenuEntrySelected;
  47. returnMenuEntry.Selected += OnCancel;
  48. // Add entries to the menu.
  49. MenuEntries.Add(themeGameMenuEntry);
  50. MenuEntries.Add(returnMenuEntry);
  51. themes.Add("Red", ScreenManager.Game.Content.Load<Texture2D>(
  52. Path.Combine("Images", "Cards", "CardBack_Red")));
  53. themes.Add("Blue", ScreenManager.Game.Content.Load<Texture2D>(
  54. Path.Combine("Images", "Cards", "CardBack_Blue")));
  55. background = ScreenManager.Game.Content.Load<Texture2D>(
  56. Path.Combine("Images", "UI", "table"));
  57. card = new AnimatedGameComponent(cardGame,
  58. themes[MainMenuScreen.Theme], ScreenManager.SpriteBatch, ScreenManager.GlobalTransformation)
  59. {
  60. CurrentPosition = new Vector2(safeArea.Center.X, safeArea.Center.Y - 50)
  61. };
  62. ScreenManager.Game.Components.Add(card);
  63. base.LoadContent();
  64. }
  65. /// <summary>
  66. /// Respond to "Theme" Item Selection
  67. /// </summary>
  68. /// <param name="sender"></param>
  69. /// <param name="e"></param>
  70. void ThemeGameMenuEntrySelected(object sender, EventArgs e)
  71. {
  72. if (MainMenuScreen.Theme == "Red")
  73. {
  74. MainMenuScreen.Theme = "Blue";
  75. }
  76. else
  77. {
  78. MainMenuScreen.Theme = "Red";
  79. }
  80. card.CurrentFrame = themes[MainMenuScreen.Theme];
  81. }
  82. /// <summary>
  83. /// Respond to "Return" Item Selection
  84. /// </summary>
  85. /// <param name="playerIndex"></param>
  86. protected override void OnCancel(PlayerIndex playerIndex)
  87. {
  88. ScreenManager.Game.Components.Remove(card);
  89. ExitScreen();
  90. }
  91. /// <summary>
  92. /// Draws the menu.
  93. /// </summary>
  94. /// <param name="gameTime"></param>
  95. public override void Draw(GameTime gameTime)
  96. {
  97. ScreenManager.SpriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, ScreenManager.GlobalTransformation);
  98. // Draw the card back
  99. ScreenManager.SpriteBatch.Draw(background, ScreenManager.GraphicsDevice.Viewport.Bounds,
  100. Color.White * TransitionAlpha);
  101. ScreenManager.SpriteBatch.End();
  102. base.Draw(gameTime);
  103. }
  104. }
  105. }