InstructionScreen.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. //-----------------------------------------------------------------------------
  2. // InstructionScreen.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 Microsoft.Xna.Framework.Graphics;
  11. using System.Threading;
  12. using Microsoft.Xna.Framework;
  13. using GameStateManagement;
  14. using Microsoft.Xna.Framework.Input;
  15. using Microsoft.Xna.Framework.Input.Touch;
  16. using System.IO;
  17. using CardsFramework;
  18. namespace Blackjack
  19. {
  20. class InstructionScreen : GameplayScreen
  21. {
  22. Texture2D background;
  23. SpriteFont font;
  24. GameplayScreen gameplayScreen;
  25. string theme;
  26. bool isExit = false;
  27. bool isExited = false;
  28. public InstructionScreen(string theme)
  29. : base("")
  30. {
  31. TransitionOnTime = TimeSpan.FromSeconds(0.0);
  32. TransitionOffTime = TimeSpan.FromSeconds(0.5);
  33. this.theme = theme;
  34. EnabledGestures = GestureType.Tap;
  35. }
  36. /// <summary>
  37. /// Load the screen resources
  38. /// </summary>
  39. public override void LoadContent()
  40. {
  41. background = Load<Texture2D>(Path.Combine("Images", "instructions"));
  42. font = Load<SpriteFont>(Path.Combine("Fonts", "MenuFont"));
  43. // Create a new instance of the gameplay screen
  44. gameplayScreen = new GameplayScreen(theme);
  45. }
  46. /// <summary>
  47. /// Exit the screen after a tap or click
  48. /// </summary>
  49. /// <param name="input"></param>
  50. private void HandleInput()
  51. {
  52. if (!isExit)
  53. {
  54. if (UIUtility.IsMobile)
  55. {
  56. if (ScreenManager.InputState.Gestures.Count > 0 &&
  57. ScreenManager.InputState.Gestures[0].GestureType == GestureType.Tap)
  58. {
  59. isExit = true;
  60. }
  61. }
  62. else
  63. {
  64. PlayerIndex result;
  65. if (ScreenManager.InputState.CurrentMouseState.LeftButton == ButtonState.Pressed)
  66. {
  67. isExit = true;
  68. }
  69. else if (ScreenManager.InputState.IsNewButtonPress(Buttons.A, null, out result) ||
  70. ScreenManager.InputState.IsNewButtonPress(Buttons.Start, null, out result))
  71. {
  72. isExit = true;
  73. }
  74. }
  75. }
  76. }
  77. /// <summary>
  78. /// Screen update logic
  79. /// </summary>
  80. /// <param name="gameTime"></param>
  81. /// <param name="otherScreenHasFocus"></param>
  82. /// <param name="coveredByOtherScreen"></param>
  83. public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
  84. {
  85. if (isExit && !isExited)
  86. {
  87. // Move on to the gameplay screen
  88. foreach (GameScreen screen in ScreenManager.GetScreens())
  89. screen.ExitScreen();
  90. gameplayScreen.ScreenManager = ScreenManager;
  91. ScreenManager.AddScreen(gameplayScreen, null);
  92. isExited = true;
  93. }
  94. HandleInput();
  95. base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
  96. }
  97. /// <summary>
  98. /// Render screen
  99. /// </summary>
  100. /// <param name="gameTime"></param>
  101. public override void Draw(GameTime gameTime)
  102. {
  103. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  104. spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, ScreenManager.GlobalTransformation);
  105. // Draw Background
  106. spriteBatch.Draw(background, ScreenManager.SafeArea, Color.White * TransitionAlpha);
  107. if (isExit)
  108. {
  109. Rectangle safeArea = ScreenManager.SafeArea;
  110. string text = Resources.Loading;
  111. Vector2 measure = font.MeasureString(text);
  112. Vector2 textPosition = new Vector2(safeArea.Center.X - measure.X / 2,
  113. safeArea.Center.Y - measure.Y / 2);
  114. spriteBatch.DrawString(font, text, textPosition, Color.Black);
  115. }
  116. spriteBatch.End();
  117. base.Draw(gameTime);
  118. }
  119. }
  120. }