QuestLogScreen.cs 6.8 KB

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