RewardsScreen.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. //-----------------------------------------------------------------------------
  2. // RewardsScreen.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. /// Displays the rewards earned by the party, from a quest or combat.
  18. /// </summary>
  19. class RewardsScreen : GameScreen
  20. {
  21. public enum RewardScreenMode
  22. {
  23. Quest,
  24. Combat,
  25. };
  26. /// <summary>
  27. /// The mode of this screen.
  28. /// </summary>
  29. private RewardScreenMode mode;
  30. private int experienceReward;
  31. private int goldReward;
  32. private List<Gear> gearReward;
  33. private Texture2D backTexture;
  34. private Texture2D selectIconTexture;
  35. private Texture2D lineTexture;
  36. private Texture2D scrollUpTexture;
  37. private Texture2D scrollDownTexture;
  38. private Texture2D fadeTexture;
  39. private Vector2 backgroundPosition;
  40. private Vector2 textPosition;
  41. private Vector2 iconPosition;
  42. private Vector2 linePosition;
  43. private Vector2 selectPosition;
  44. private Vector2 selectIconPosition;
  45. private Vector2 screenSize;
  46. private Vector2 titlePosition;
  47. private Vector2 scrollUpPosition;
  48. private Vector2 scrollDownPosition;
  49. private Vector2 xpAwardPosition;
  50. private Vector2 goldAwardPosition;
  51. private Vector2 itemAwardPosition;
  52. private Rectangle fadeDest;
  53. private string titleText;
  54. private readonly string selectString = "Continue";
  55. /// <summary>
  56. /// Starting index of the list to be displayed
  57. /// </summary>
  58. private int startIndex;
  59. /// <summary>
  60. /// Ending index of the list to be displayed
  61. /// </summary>
  62. private int endIndex;
  63. /// <summary>
  64. /// Maximum number of lines to draw in the screen
  65. /// </summary>
  66. private int maxLines;
  67. /// <summary>
  68. /// Vertical spacing between each line
  69. /// </summary>
  70. private int lineSpacing;
  71. /// <summary>
  72. /// Creates a new RewardsScreen object.
  73. /// </summary>
  74. public RewardsScreen(RewardScreenMode mode, int experienceReward,
  75. int goldReward, List<Gear> gearReward)
  76. : base()
  77. {
  78. this.IsPopup = true;
  79. this.mode = mode;
  80. this.experienceReward = experienceReward;
  81. this.goldReward = goldReward;
  82. this.gearReward = gearReward;
  83. maxLines = 3;
  84. lineSpacing = 74;
  85. startIndex = 0;
  86. endIndex = maxLines;
  87. if (endIndex > gearReward.Count)
  88. {
  89. endIndex = gearReward.Count;
  90. }
  91. // play the appropriate music
  92. switch (mode)
  93. {
  94. case RewardScreenMode.Combat:
  95. // play the combat-victory music
  96. AudioManager.PushMusic("WinTheme");
  97. break;
  98. case RewardScreenMode.Quest:
  99. // play the quest-complete music
  100. AudioManager.PushMusic("QuestComplete");
  101. break;
  102. }
  103. this.Exiting += new EventHandler(RewardsScreen_Exiting);
  104. }
  105. void RewardsScreen_Exiting(object sender, EventArgs e)
  106. {
  107. AudioManager.PopMusic();
  108. }
  109. /// <summary>
  110. /// Load the graphics content from the content manager.
  111. /// </summary>
  112. public override void LoadContent()
  113. {
  114. ContentManager content = ScreenManager.Game.Content;
  115. backTexture =
  116. content.Load<Texture2D>(Path.Combine("Textures", "GameScreens", "PopupScreen"));
  117. selectIconTexture =
  118. content.Load<Texture2D>(Path.Combine("Textures", "Buttons", "AButton"));
  119. scrollUpTexture =
  120. content.Load<Texture2D>(Path.Combine("Textures", "GameScreens", "ScrollUp"));
  121. scrollDownTexture =
  122. content.Load<Texture2D>(Path.Combine("Textures", "GameScreens", "ScrollDown"));
  123. lineTexture =
  124. content.Load<Texture2D>(Path.Combine("Textures", "GameScreens", "SeparationLine"));
  125. fadeTexture = content.Load<Texture2D>(Path.Combine("Textures", "GameScreens", "FadeScreen"));
  126. fadeDest = new Rectangle(0, 0, Session.BACK_BUFFER_WIDTH, Session.BACK_BUFFER_HEIGHT);
  127. backgroundPosition.X = (Session.BACK_BUFFER_WIDTH - backTexture.Width) / 2;
  128. backgroundPosition.Y = (Session.BACK_BUFFER_HEIGHT - backTexture.Height) / 2;
  129. screenSize = new Vector2(Session.BACK_BUFFER_WIDTH, Session.BACK_BUFFER_HEIGHT);
  130. selectIconPosition.X = screenSize.X / 2 + 260;
  131. selectIconPosition.Y = backgroundPosition.Y + 530f;
  132. selectPosition.X = selectIconPosition.X -
  133. Fonts.ButtonNamesFont.MeasureString(selectString).X - 10f;
  134. selectPosition.Y = backgroundPosition.Y + 530f;
  135. textPosition = backgroundPosition + new Vector2(335f, 320f);
  136. iconPosition = backgroundPosition + new Vector2(155f, 303f);
  137. linePosition = backgroundPosition + new Vector2(142f, 285f);
  138. scrollUpPosition = backgroundPosition + new Vector2(810f, 300f);
  139. scrollDownPosition = backgroundPosition + new Vector2(810f, 480f);
  140. xpAwardPosition = backgroundPosition + new Vector2(160f, 180f);
  141. goldAwardPosition = backgroundPosition + new Vector2(160f, 210f);
  142. itemAwardPosition = backgroundPosition + new Vector2(160f, 240f);
  143. }
  144. /// <summary>
  145. /// Handles user input.
  146. /// </summary>
  147. public override void HandleInput()
  148. {
  149. // exit the screen
  150. if (InputManager.IsActionTriggered(InputManager.InputAction.Ok) ||
  151. InputManager.IsActionTriggered(InputManager.InputAction.Back))
  152. {
  153. ExitScreen();
  154. // give the rewards to the party
  155. Session.Party.PartyGold += goldReward;
  156. foreach (Gear gear in gearReward)
  157. {
  158. Session.Party.AddToInventory(gear, 1);
  159. }
  160. Session.Party.GiveExperience(experienceReward);
  161. }
  162. // Scroll up
  163. else if (InputManager.IsActionTriggered(InputManager.InputAction.CursorUp))
  164. {
  165. if (startIndex > 0)
  166. {
  167. startIndex--;
  168. endIndex--;
  169. }
  170. }
  171. // Scroll down
  172. else if (InputManager.IsActionTriggered(InputManager.InputAction.CursorDown))
  173. {
  174. if (startIndex < gearReward.Count - maxLines)
  175. {
  176. endIndex++;
  177. startIndex++;
  178. }
  179. }
  180. }
  181. /// <summary>
  182. /// Draw the screen.
  183. /// </summary>
  184. public override void Draw(GameTime gameTime)
  185. {
  186. Vector2 currentIconPosition = iconPosition;
  187. Vector2 currentTextPosition = textPosition;
  188. Vector2 currentlinePosition = linePosition;
  189. switch (mode)
  190. {
  191. case RewardScreenMode.Quest:
  192. titleText = "Quest Complete";
  193. break;
  194. case RewardScreenMode.Combat:
  195. titleText = "Combat Won";
  196. break;
  197. }
  198. titlePosition.X = (screenSize.X -
  199. Fonts.HeaderFont.MeasureString(titleText).X) / 2;
  200. titlePosition.Y = backgroundPosition.Y + lineSpacing;
  201. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  202. spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, ScreenManager.GlobalTransformation);
  203. // Draw the fading screen
  204. spriteBatch.Draw(fadeTexture, fadeDest, Color.White);
  205. // Draw the popup background
  206. spriteBatch.Draw(backTexture, backgroundPosition, Color.White);
  207. // Draw the title
  208. spriteBatch.DrawString(Fonts.HeaderFont, titleText, titlePosition,
  209. Fonts.TitleColor);
  210. // Draw the experience points awarded
  211. spriteBatch.DrawString(Fonts.GearInfoFont,
  212. "XP Awarded : " + experienceReward,
  213. xpAwardPosition, Fonts.CountColor);
  214. // Draw the gold points awarded
  215. spriteBatch.DrawString(Fonts.GearInfoFont,
  216. "Gold Awarded : " + Fonts.GetGoldString(goldReward),
  217. goldAwardPosition, Fonts.CountColor);
  218. // Draw the items awarded
  219. spriteBatch.DrawString(Fonts.GearInfoFont, "Items Awarded :",
  220. itemAwardPosition, Fonts.CountColor);
  221. // Draw horizontal divider lines
  222. for (int i = 0; i <= maxLines; i++)
  223. {
  224. spriteBatch.Draw(lineTexture, currentlinePosition, Color.White);
  225. currentlinePosition.Y += lineSpacing;
  226. }
  227. // Draw the item details
  228. for (int i = startIndex; i < endIndex; i++)
  229. {
  230. // Draw the item icon
  231. gearReward[i].DrawIcon(ScreenManager.SpriteBatch, currentIconPosition);
  232. // Draw the item name
  233. spriteBatch.DrawString(Fonts.GearInfoFont,
  234. gearReward[i].Name, currentTextPosition, Fonts.CountColor);
  235. // Increment the position to the next line
  236. currentTextPosition.Y += lineSpacing;
  237. currentIconPosition.Y += lineSpacing;
  238. }
  239. // Draw the scroll buttons
  240. spriteBatch.Draw(scrollUpTexture, scrollUpPosition, Color.White);
  241. spriteBatch.Draw(scrollDownTexture, scrollDownPosition, Color.White);
  242. // Draw the select button and its corresponding text
  243. spriteBatch.Draw(selectIconTexture, selectIconPosition, Color.White);
  244. spriteBatch.DrawString(Fonts.ButtonNamesFont, selectString, selectPosition,
  245. Color.White);
  246. spriteBatch.End();
  247. }
  248. }
  249. }