RewardsScreen.cs 10 KB

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