OptionsMenu.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // OptionsMenu.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 System;
  11. using System.Collections.Generic;
  12. using System.Text;
  13. using GameStateManagement;
  14. using Microsoft.Xna.Framework;
  15. using Microsoft.Xna.Framework.Graphics;
  16. using CardsFramework;
  17. #endregion
  18. namespace Blackjack
  19. {
  20. class OptionsMenu : MenuScreen
  21. {
  22. Dictionary<string, Texture2D> themes = new Dictionary<string, Texture2D>();
  23. AnimatedGameComponent card;
  24. Texture2D background;
  25. Rectangle safeArea;
  26. #region Initializations
  27. /// <summary>
  28. /// Initializes a new instance of the screen.
  29. /// </summary>
  30. public OptionsMenu()
  31. : base("")
  32. {
  33. }
  34. #endregion
  35. /// <summary>
  36. /// Loads content required by the screen, and initializes the displayed menu.
  37. /// </summary>
  38. public override void LoadContent()
  39. {
  40. safeArea = ScreenManager.SafeArea;
  41. // Create our menu entries.
  42. MenuEntry themeGameMenuEntry = new MenuEntry("Deck");
  43. MenuEntry returnMenuEntry = new MenuEntry("Return");
  44. // Hook up menu event handlers.
  45. themeGameMenuEntry.Selected += ThemeGameMenuEntrySelected;
  46. returnMenuEntry.Selected += OnCancel;
  47. // Add entries to the menu.
  48. MenuEntries.Add(themeGameMenuEntry);
  49. MenuEntries.Add(returnMenuEntry);
  50. themes.Add("Red", ScreenManager.Game.Content.Load<Texture2D>(
  51. @"Images\Cards\CardBack_Red"));
  52. themes.Add("Blue", ScreenManager.Game.Content.Load<Texture2D>(
  53. @"Images\Cards\CardBack_Blue"));
  54. background = ScreenManager.Game.Content.Load<Texture2D>(
  55. @"Images\UI\table");
  56. card = new AnimatedGameComponent(ScreenManager.Game,
  57. themes[MainMenuScreen.Theme])
  58. {
  59. CurrentPosition = new Vector2(safeArea.Center.X, safeArea.Center.Y - 50)
  60. };
  61. ScreenManager.Game.Components.Add(card);
  62. base.LoadContent();
  63. }
  64. #region Update and Render
  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();
  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. #endregion
  105. }
  106. }