QuestDetailsScreen.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // QuestDetailsScreen.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 Microsoft.Xna.Framework;
  13. using Microsoft.Xna.Framework.Graphics;
  14. using Microsoft.Xna.Framework.Content;
  15. using RolePlayingGameData;
  16. #endregion
  17. namespace RolePlaying
  18. {
  19. /// <summary>
  20. /// Display the details of a particular quest.
  21. /// </summary>
  22. class QuestDetailsScreen : GameScreen
  23. {
  24. private Quest quest;
  25. #region Graphics Data
  26. private Texture2D backgroundTexture;
  27. private Texture2D backIconTexture;
  28. private Texture2D scrollTexture;
  29. private Texture2D fadeTexture;
  30. private Texture2D lineTexture;
  31. private Vector2 backgroundPosition;
  32. private Vector2 screenSize;
  33. private Vector2 titlePosition;
  34. private Vector2 textPosition;
  35. private Vector2 backTextPosition;
  36. private Vector2 backIconPosition;
  37. private Vector2 scrollPosition;
  38. private Vector2 topLinePosition;
  39. private Vector2 bottomLinePosition;
  40. private Rectangle fadeDest;
  41. private Color headerColor = new Color(128, 6, 6);
  42. private Color textColor = new Color(102, 40, 16);
  43. #endregion
  44. #region Dialog Text
  45. private string titleString = "Quest Details";
  46. private List<Line> currentDialogue;
  47. private int startIndex;
  48. private int endIndex;
  49. private int maxLines;
  50. #endregion
  51. #region Initialization
  52. /// <summary>
  53. /// Creates a new QuestDetailsScreen object.
  54. /// </summary>
  55. public QuestDetailsScreen(Quest quest)
  56. : base()
  57. {
  58. // check the parameter
  59. if (quest == null)
  60. {
  61. throw new ArgumentNullException("quest");
  62. }
  63. this.quest = quest;
  64. this.IsPopup = true;
  65. currentDialogue = new List<Line>();
  66. maxLines = 13;
  67. textPosition.X = 261f;
  68. AddStrings(this.quest.Name,
  69. Fonts.BreakTextIntoList(this.quest.Description,
  70. Fonts.DescriptionFont, 715), GetRequirements(this.quest));
  71. }
  72. /// <summary>
  73. /// Loads the graphics content from the content manager.
  74. /// </summary>
  75. public override void LoadContent()
  76. {
  77. ContentManager content = ScreenManager.Game.Content;
  78. Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
  79. backgroundTexture =
  80. content.Load<Texture2D>(@"Textures\GameScreens\PopupScreen");
  81. backIconTexture =
  82. content.Load<Texture2D>(@"Textures\Buttons\BButton");
  83. scrollTexture =
  84. content.Load<Texture2D>(@"Textures\GameScreens\ScrollButtons");
  85. lineTexture =
  86. content.Load<Texture2D>(@"Textures\GameScreens\SeparationLine");
  87. fadeTexture = content.Load<Texture2D>(@"Textures\GameScreens\FadeScreen");
  88. // Get the screen positions
  89. screenSize = new Vector2(viewport.Width, viewport.Height);
  90. fadeDest = new Rectangle(viewport.X, viewport.Y,
  91. viewport.Width, viewport.Height);
  92. backgroundPosition = new Vector2(
  93. (viewport.Width - backgroundTexture.Width) / 2,
  94. (viewport.Height - backgroundTexture.Height) / 2);
  95. scrollPosition = backgroundPosition + new Vector2(820f, 200f);
  96. titlePosition = new Vector2(
  97. (screenSize.X - Fonts.HeaderFont.MeasureString(titleString).X) / 2,
  98. backgroundPosition.Y + 70f);
  99. backTextPosition = new Vector2(screenSize.X / 2 - 250f,
  100. backgroundPosition.Y + 530f);
  101. backIconPosition = new Vector2(
  102. backTextPosition.X - backIconTexture.Width - 10f, backTextPosition.Y);
  103. topLinePosition = new Vector2(
  104. (viewport.Width - lineTexture.Width) / 2 - 30f, 200f);
  105. bottomLinePosition = new Vector2(topLinePosition.X, 550f);
  106. }
  107. #endregion
  108. #region Text Generation
  109. /// <summary>
  110. /// A line of text with its own color and font.
  111. /// </summary>
  112. private struct Line
  113. {
  114. public string text;
  115. public Color color;
  116. public SpriteFont font;
  117. }
  118. /// <summary>
  119. /// Add strings to list of lines
  120. /// </summary>
  121. /// <param name="name">Name of the quest</param>
  122. /// <param name="description">Description of the quest</param>
  123. /// <param name="requirements">Requirements of the quest</param>
  124. private void AddStrings(string name, List<string> description,
  125. List<Line> requirements)
  126. {
  127. Line line;
  128. line.color = headerColor;
  129. line.font = Fonts.DescriptionFont;
  130. // Title text
  131. titleString = name;
  132. titlePosition.X = (screenSize.X -
  133. Fonts.HeaderFont.MeasureString(titleString).X) / 2;
  134. titlePosition.Y = backgroundPosition.Y + 70f;
  135. currentDialogue.Clear();
  136. line.text = "Description";
  137. currentDialogue.Add(line);
  138. foreach (string str in description)
  139. {
  140. line.text = str;
  141. line.color = textColor;
  142. currentDialogue.Add(line);
  143. }
  144. foreach (Line str in requirements)
  145. {
  146. currentDialogue.Add(str);
  147. }
  148. // Set the start index and end index
  149. startIndex = 0;
  150. endIndex = maxLines;
  151. if (endIndex > currentDialogue.Count)
  152. {
  153. textPosition.Y = 375f;
  154. foreach (Line str in currentDialogue)
  155. {
  156. textPosition.Y -= str.font.LineSpacing / 2;
  157. }
  158. endIndex = currentDialogue.Count;
  159. }
  160. else
  161. {
  162. textPosition.Y = 225f;
  163. }
  164. }
  165. /// <summary>
  166. /// Get the quest requirements
  167. /// </summary>
  168. /// <param name="quest">The particular quest</param>
  169. /// <returns>List of strings containing formatted output</returns>
  170. private List<Line> GetRequirements(Quest quest)
  171. {
  172. List<Line> reqdList;
  173. Line reqd;
  174. int currentCount = 0;
  175. int totalCount = 0;
  176. List<string> dialog;
  177. reqdList = new List<Line>();
  178. reqd.font = Fonts.DescriptionFont;
  179. // Add Monster Requirements
  180. if (quest.MonsterRequirements.Count > 0)
  181. {
  182. reqd.color = headerColor;
  183. reqd.text = String.Empty;
  184. reqdList.Add(reqd);
  185. reqd.text = "Monster Progress";
  186. reqdList.Add(reqd);
  187. for (int i = 0; i < quest.MonsterRequirements.Count; i++)
  188. {
  189. reqd.color = textColor;
  190. currentCount = quest.MonsterRequirements[i].CompletedCount;
  191. totalCount = quest.MonsterRequirements[i].Count;
  192. Monster monster = quest.MonsterRequirements[i].Content;
  193. reqd.text = monster.Name + " = " + currentCount + " / " +
  194. totalCount;
  195. if (currentCount == totalCount)
  196. {
  197. reqd.color = Color.Red;
  198. }
  199. reqdList.Add(reqd);
  200. }
  201. }
  202. // Add Item Requirements
  203. if (quest.GearRequirements.Count > 0)
  204. {
  205. reqd.color = headerColor;
  206. reqd.text = String.Empty;
  207. reqdList.Add(reqd);
  208. reqd.text = "Item Progress";
  209. reqdList.Add(reqd);
  210. for (int i = 0; i < quest.GearRequirements.Count; i++)
  211. {
  212. reqd.color = textColor;
  213. currentCount = quest.GearRequirements[i].CompletedCount;
  214. totalCount = quest.GearRequirements[i].Count;
  215. Gear gear = quest.GearRequirements[i].Content;
  216. reqd.text = gear.Name + " = " + currentCount + " / " + totalCount;
  217. if (currentCount == totalCount)
  218. {
  219. reqd.color = Color.Red;
  220. }
  221. reqdList.Add(reqd);
  222. }
  223. }
  224. // Add Current Objective
  225. reqd.color = headerColor;
  226. reqd.text = String.Empty;
  227. reqdList.Add(reqd);
  228. reqd.text = "Current Objective";
  229. reqdList.Add(reqd);
  230. reqd.color = textColor;
  231. switch (quest.Stage)
  232. {
  233. case Quest.QuestStage.InProgress:
  234. dialog = Fonts.BreakTextIntoList(quest.ObjectiveMessage,
  235. Fonts.DescriptionFont, 715);
  236. for (int i = 0; i < dialog.Count; i++)
  237. {
  238. reqd.text = dialog[i];
  239. reqdList.Add(reqd);
  240. }
  241. break;
  242. case Quest.QuestStage.RequirementsMet:
  243. dialog = Fonts.BreakTextIntoList(quest.DestinationObjectiveMessage,
  244. Fonts.DescriptionFont, 715);
  245. for (int i = 0; i < dialog.Count; i++)
  246. {
  247. reqd.text = dialog[i];
  248. reqdList.Add(reqd);
  249. }
  250. break;
  251. case Quest.QuestStage.Completed:
  252. reqd.font = Fonts.ButtonNamesFont;
  253. reqd.color = new Color(139, 21, 73);
  254. reqd.text = "Quest Completed";
  255. reqdList.Add(reqd);
  256. break;
  257. }
  258. return reqdList;
  259. }
  260. #endregion
  261. #region Updating
  262. /// <summary>
  263. /// Handles user input.
  264. /// </summary>
  265. public override void HandleInput()
  266. {
  267. // exit the screen
  268. if (InputManager.IsActionTriggered(InputManager.Action.Back) ||
  269. InputManager.IsActionTriggered(InputManager.Action.Ok))
  270. {
  271. ExitScreen();
  272. return;
  273. }
  274. // scroll up
  275. else if (InputManager.IsActionTriggered(InputManager.Action.CursorUp))
  276. {
  277. if (startIndex > 0)
  278. {
  279. startIndex--;
  280. endIndex--;
  281. }
  282. }
  283. // scroll Down
  284. else if (InputManager.IsActionTriggered(InputManager.Action.CursorDown))
  285. {
  286. if (endIndex < currentDialogue.Count)
  287. {
  288. startIndex++;
  289. endIndex++;
  290. }
  291. }
  292. }
  293. #endregion
  294. #region Drawing
  295. /// <summary>
  296. /// Draw the screen
  297. /// </summary>
  298. public override void Draw(GameTime gameTime)
  299. {
  300. Vector2 dialoguePosition = textPosition;
  301. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  302. spriteBatch.Begin();
  303. // Draw the fading screen
  304. spriteBatch.Draw(fadeTexture, fadeDest, Color.White);
  305. // Draw the popup background
  306. spriteBatch.Draw(backgroundTexture, backgroundPosition, Color.White);
  307. // Draw the top line
  308. spriteBatch.Draw(lineTexture, topLinePosition, Color.White);
  309. // Draw the bottom line
  310. spriteBatch.Draw(lineTexture, bottomLinePosition, Color.White);
  311. // Draw the scrollbar
  312. spriteBatch.Draw(scrollTexture, scrollPosition, Color.White);
  313. // Draw the Back button
  314. spriteBatch.Draw(backIconTexture, backIconPosition, Color.White);
  315. spriteBatch.DrawString(Fonts.ButtonNamesFont, "Back", backTextPosition,
  316. Color.White);
  317. // Draw the title
  318. spriteBatch.DrawString(Fonts.HeaderFont, titleString, titlePosition,
  319. Fonts.TitleColor);
  320. //Draw the information dialog
  321. for (int i = startIndex; i < endIndex; i++)
  322. {
  323. dialoguePosition.X = (int)((screenSize.X -
  324. currentDialogue[i].font.MeasureString(
  325. currentDialogue[i].text).X) / 2) - 20;
  326. spriteBatch.DrawString(currentDialogue[i].font,
  327. currentDialogue[i].text, dialoguePosition,
  328. currentDialogue[i].color);
  329. dialoguePosition.Y += currentDialogue[i].font.LineSpacing;
  330. }
  331. spriteBatch.End();
  332. }
  333. #endregion
  334. }
  335. }