HelpScreen.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // HelpScreen.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 Microsoft.Xna.Framework;
  14. using Microsoft.Xna.Framework.Graphics;
  15. using Microsoft.Xna.Framework.Content;
  16. using RolePlayingGameData;
  17. #endregion
  18. namespace RolePlaying
  19. {
  20. /// <summary>
  21. /// Shows the help screen, explaining the basic game idea to the user.
  22. /// </summary>
  23. class HelpScreen : GameScreen
  24. {
  25. #region Fields
  26. private Texture2D backgroundTexture;
  27. private Texture2D plankTexture;
  28. private Vector2 plankPosition;
  29. private Vector2 titlePosition;
  30. private string helpText =
  31. "Welcome, hero! You must meet new comrades, earn necessary " +
  32. "experience, gold, spells, and the equipment required to challenge " +
  33. "and defeat the evil Tamar, who resides in his lair, known as the " +
  34. "Unspoken Tower. Be wary! The Unspoken Tower is filled with " +
  35. "monstrosities that only the most hardened of heroes could possibly " +
  36. "face. Good luck!";
  37. private List<string> textLines;
  38. private Texture2D scrollUpTexture;
  39. private readonly Vector2 scrollUpPosition = new Vector2(980, 200);
  40. private Texture2D scrollDownTexture;
  41. private readonly Vector2 scrollDownPosition = new Vector2(980, 460);
  42. private Texture2D lineBorderTexture;
  43. private readonly Vector2 linePosition = new Vector2(200, 570);
  44. private Texture2D backTexture;
  45. private readonly Vector2 backPosition = new Vector2(225, 610);
  46. private int startIndex;
  47. private const int maxLineDisplay = 7;
  48. #endregion
  49. #region Initialization
  50. public HelpScreen()
  51. : base()
  52. {
  53. textLines = Fonts.BreakTextIntoList(helpText, Fonts.DescriptionFont, 590);
  54. }
  55. /// <summary>
  56. /// Loads the graphics content for this screen
  57. /// </summary>
  58. public override void LoadContent()
  59. {
  60. base.LoadContent();
  61. ContentManager content = ScreenManager.Game.Content;
  62. backgroundTexture = content.Load<Texture2D>(@"Textures\MainMenu\MainMenu");
  63. plankTexture =
  64. content.Load<Texture2D>(@"Textures\MainMenu\MainMenuPlank03");
  65. backTexture =
  66. content.Load<Texture2D>(@"Textures\Buttons\BButton");
  67. scrollUpTexture =
  68. content.Load<Texture2D>(@"Textures\GameScreens\ScrollUp");
  69. scrollDownTexture =
  70. content.Load<Texture2D>(@"Textures\GameScreens\ScrollDown");
  71. lineBorderTexture =
  72. content.Load<Texture2D>(@"Textures\GameScreens\LineBorder");
  73. plankPosition.X = backgroundTexture.Width / 2 - plankTexture.Width / 2;
  74. plankPosition.Y = 60;
  75. titlePosition.X = plankPosition.X + (plankTexture.Width -
  76. Fonts.HeaderFont.MeasureString("Help").X) / 2;
  77. titlePosition.Y = plankPosition.Y + (plankTexture.Height -
  78. Fonts.HeaderFont.MeasureString("Help").Y) / 2;
  79. }
  80. #endregion
  81. #region Updating
  82. /// <summary>
  83. /// Handles user input.
  84. /// </summary>
  85. public override void HandleInput()
  86. {
  87. // exits the screen
  88. if (InputManager.IsActionTriggered(InputManager.Action.Back))
  89. {
  90. ExitScreen();
  91. return;
  92. }
  93. // scroll down
  94. else if (InputManager.IsActionTriggered(InputManager.Action.CursorDown))
  95. {
  96. // Traverse down the help text
  97. if (startIndex + maxLineDisplay < textLines.Count)
  98. {
  99. startIndex += 1;
  100. }
  101. }
  102. // scroll up
  103. else if (InputManager.IsActionTriggered(InputManager.Action.CursorUp))
  104. {
  105. // Traverse up the help text
  106. if (startIndex > 0)
  107. {
  108. startIndex -= 1;
  109. }
  110. }
  111. }
  112. #endregion
  113. #region Drawing
  114. /// <summary>
  115. /// Draws the help screen.
  116. /// </summary>
  117. public override void Draw(GameTime gameTime)
  118. {
  119. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  120. spriteBatch.Begin();
  121. spriteBatch.Draw(backgroundTexture, Vector2.Zero, Color.White);
  122. spriteBatch.Draw(plankTexture, plankPosition, Color.White);
  123. spriteBatch.Draw(backTexture, backPosition, Color.White);
  124. spriteBatch.Draw(lineBorderTexture, linePosition, Color.White);
  125. spriteBatch.DrawString(Fonts.ButtonNamesFont, "Back",
  126. new Vector2(backPosition.X + 55, backPosition.Y + 5), Color.White);
  127. spriteBatch.Draw(scrollUpTexture, scrollUpPosition, Color.White);
  128. spriteBatch.Draw(scrollDownTexture, scrollDownPosition, Color.White);
  129. spriteBatch.DrawString(Fonts.HeaderFont, "Help", titlePosition,
  130. Fonts.TitleColor);
  131. for (int i = 0; i < maxLineDisplay; i++)
  132. {
  133. spriteBatch.DrawString(Fonts.DescriptionFont, textLines[startIndex + i],
  134. new Vector2(360, 200 + (Fonts.DescriptionFont.LineSpacing + 10) * i),
  135. Color.Black);
  136. }
  137. spriteBatch.End();
  138. }
  139. #endregion
  140. }
  141. }