QuestDetailsScreen.cs 13 KB

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