QuestLogScreen.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // QuestLogScreen.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.Collections.ObjectModel;
  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. /// Displays all of the quests completed by the party
  22. /// </summary>
  23. class QuestLogScreen : ListScreen<Quest>
  24. {
  25. #region Initial Detail Quest
  26. /// <summary>
  27. /// The quest that is shown when the screen is created.
  28. /// </summary>
  29. /// <remarks>
  30. /// Stored because new screens can't be added until the first update.
  31. /// </remarks>
  32. private Quest initialDetailQuest;
  33. #endregion
  34. #region Columns
  35. protected string nameColumnText = "Name";
  36. private const int nameColumnInterval = 20;
  37. protected string stageColumnText = "Stage";
  38. private const int stageColumnInterval = 450;
  39. #endregion
  40. #region Data Access
  41. /// <summary>
  42. /// Get the list that this screen displays.
  43. /// </summary>
  44. public override ReadOnlyCollection<Quest> GetDataList()
  45. {
  46. List<Quest> quests = new List<Quest>();
  47. for (int i = 0; i <= Session.CurrentQuestIndex; i++)
  48. {
  49. if (i < Session.QuestLine.Quests.Count)
  50. {
  51. quests.Add(Session.QuestLine.Quests[i]);
  52. }
  53. }
  54. return quests.AsReadOnly();
  55. }
  56. #endregion
  57. #region Initialization
  58. /// <summary>
  59. /// Creates a new EquipmentScreen object for the given player.
  60. /// </summary>
  61. public QuestLogScreen(Quest initialDetailQuest)
  62. : base()
  63. {
  64. // assign the parameter - null is permitted
  65. this.initialDetailQuest = initialDetailQuest;
  66. // configure the menu text
  67. titleText = Session.QuestLine.Name;
  68. selectButtonText = "Select";
  69. backButtonText = "Back";
  70. xButtonText = String.Empty;
  71. yButtonText = String.Empty;
  72. leftTriggerText = "Equipment";
  73. rightTriggerText = "Statistics";
  74. // select the current quest
  75. SelectedIndex = Session.CurrentQuestIndex;
  76. }
  77. #endregion
  78. #region Input Handling
  79. /// <summary>
  80. /// Handle user input.
  81. /// </summary>
  82. public override void HandleInput()
  83. {
  84. // open the initial QuestDetailScreen, if any
  85. // -- this is the first opportunity to add another screen
  86. if (initialDetailQuest != null)
  87. {
  88. ScreenManager.AddScreen(new QuestDetailsScreen(initialDetailQuest));
  89. // if the selected quest is in the list, make sure it's visible
  90. SelectedIndex = Session.QuestLine.Quests.IndexOf(initialDetailQuest);
  91. // only open the screen once
  92. initialDetailQuest = null;
  93. }
  94. base.HandleInput();
  95. }
  96. /// <summary>
  97. /// Respond to the triggering of the X button (and related key).
  98. /// </summary>
  99. protected override void SelectTriggered(Quest entry)
  100. {
  101. ScreenManager.AddScreen(new QuestDetailsScreen(entry));
  102. }
  103. /// <summary>
  104. /// Switch to the screen to the "left" of this one in the UI.
  105. /// </summary>
  106. protected override void PageScreenLeft()
  107. {
  108. ExitScreen();
  109. ScreenManager.AddScreen(new InventoryScreen(false));
  110. }
  111. /// <summary>
  112. /// Switch to the screen to the "right" of this one in the UI.
  113. /// </summary>
  114. protected override void PageScreenRight()
  115. {
  116. ExitScreen();
  117. ScreenManager.AddScreen(new StatisticsScreen(Session.Party.Players[0]));
  118. }
  119. #endregion
  120. #region Drawing
  121. /// <summary>
  122. /// Draw the quest at the given position in the list.
  123. /// </summary>
  124. /// <param name="contentEntry">The quest to draw.</param>
  125. /// <param name="position">The position to draw the entry at.</param>
  126. /// <param name="isSelected">If true, this item is selected.</param>
  127. protected override void DrawEntry(Quest entry, Vector2 position,
  128. bool isSelected)
  129. {
  130. // check the parameter
  131. if (entry == null)
  132. {
  133. throw new ArgumentNullException("entry");
  134. }
  135. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  136. Vector2 drawPosition = position;
  137. // draw the name
  138. Color color = isSelected ? Fonts.HighlightColor : Fonts.DisplayColor;
  139. drawPosition.Y += listLineSpacing / 4;
  140. drawPosition.X += nameColumnInterval;
  141. spriteBatch.DrawString(Fonts.GearInfoFont, entry.Name, drawPosition, color);
  142. // draw the stage
  143. drawPosition.X += stageColumnInterval;
  144. string stageText = String.Empty;
  145. switch (entry.Stage)
  146. {
  147. case Quest.QuestStage.Completed:
  148. stageText = "Completed";
  149. break;
  150. case Quest.QuestStage.InProgress:
  151. stageText = "In Progress";
  152. break;
  153. case Quest.QuestStage.NotStarted:
  154. stageText = "Not Started";
  155. break;
  156. case Quest.QuestStage.RequirementsMet:
  157. stageText = "Requirements Met";
  158. break;
  159. }
  160. spriteBatch.DrawString(Fonts.GearInfoFont, stageText, drawPosition, color);
  161. // turn on or off the select button
  162. if (isSelected)
  163. {
  164. selectButtonText = "Select";
  165. }
  166. }
  167. /// <summary>
  168. /// Draw the description of the selected item.
  169. /// </summary>
  170. protected override void DrawSelectedDescription(Quest entry) { }
  171. /// <summary>
  172. /// Draw the column headers above the list.
  173. /// </summary>
  174. protected override void DrawColumnHeaders()
  175. {
  176. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  177. Vector2 position = listEntryStartPosition;
  178. position.X += nameColumnInterval;
  179. if (!String.IsNullOrEmpty(nameColumnText))
  180. {
  181. spriteBatch.DrawString(Fonts.CaptionFont, nameColumnText, position,
  182. Fonts.CaptionColor);
  183. }
  184. position.X += stageColumnInterval;
  185. if (!String.IsNullOrEmpty(stageColumnText))
  186. {
  187. spriteBatch.DrawString(Fonts.CaptionFont, stageColumnText, position,
  188. Fonts.CaptionColor);
  189. }
  190. }
  191. #endregion
  192. }
  193. }