HelpScreen.cs 5.4 KB

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