RewardsScreen.cs 11 KB

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