QuestDetailsScreen.cs 13 KB

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