LevelUpScreen.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. //-----------------------------------------------------------------------------
  2. // LevelUpScreen.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 all the players that have leveled up
  17. /// </summary>
  18. class LevelUpScreen : GameScreen
  19. {
  20. private int index;
  21. private List<Player> leveledUpPlayers;
  22. private List<Spell> spellList = new List<Spell>();
  23. private Texture2D backTexture;
  24. private Texture2D selectIconTexture;
  25. private Texture2D portraitBackTexture;
  26. private Texture2D headerTexture;
  27. private Texture2D lineTexture;
  28. private Texture2D scrollUpTexture;
  29. private Texture2D scrollDownTexture;
  30. private Texture2D fadeTexture;
  31. private Color color;
  32. private Color colorName = new Color(241, 173, 10);
  33. private Color colorClass = new Color(207, 130, 42);
  34. private Color colorText = new Color(76, 49, 8);
  35. private Vector2 backgroundPosition;
  36. private Vector2 textPosition;
  37. private Vector2 levelPosition;
  38. private Vector2 iconPosition;
  39. private Vector2 linePosition;
  40. private Vector2 selectPosition;
  41. private Vector2 selectIconPosition;
  42. private Vector2 screenSize;
  43. private Vector2 titlePosition;
  44. private Vector2 scrollUpPosition;
  45. private Vector2 scrollDownPosition;
  46. private Vector2 spellUpgradePosition;
  47. private Vector2 portraitPosition;
  48. private Vector2 playerNamePosition;
  49. private Vector2 playerLvlPosition;
  50. private Vector2 playerClassPosition;
  51. private Vector2 topLinePosition;
  52. private Vector2 playerDamagePosition;
  53. private Vector2 headerPosition;
  54. private Vector2 backPosition;
  55. private Rectangle fadeDest;
  56. private readonly string titleText = "Level Up";
  57. private readonly string selectString = "Continue";
  58. private int startIndex;
  59. private int endIndex;
  60. private const int maxLines = 3;
  61. private const int lineSpacing = 74;
  62. /// <summary>
  63. /// Constructs a new LevelUpScreen object.
  64. /// </summary>
  65. /// <param name="leveledUpPlayers"></param>
  66. public LevelUpScreen(List<Player> leveledUpPlayers)
  67. {
  68. if ((leveledUpPlayers == null) || (leveledUpPlayers.Count <= 0))
  69. {
  70. throw new ArgumentNullException("leveledUpPlayers");
  71. }
  72. this.IsPopup = true;
  73. this.leveledUpPlayers = leveledUpPlayers;
  74. index = 0;
  75. GetSpellList();
  76. AudioManager.PushMusic("LevelUp");
  77. this.Exiting += new EventHandler(LevelUpScreen_Exiting);
  78. }
  79. void LevelUpScreen_Exiting(object sender, EventArgs e)
  80. {
  81. AudioManager.PopMusic();
  82. }
  83. /// <summary>
  84. /// Load the graphics content
  85. /// </summary>
  86. /// <param name="sprite">SpriteBatch</param>
  87. /// <param name="screenWidth">Width of the screen</param>
  88. /// <param name="screenHeight">Height of the screen</param>
  89. public override void LoadContent()
  90. {
  91. ContentManager content = ScreenManager.Game.Content;
  92. backTexture =
  93. content.Load<Texture2D>(@"Textures\GameScreens\PopupScreen");
  94. selectIconTexture =
  95. content.Load<Texture2D>(@"Textures\Buttons\AButton");
  96. portraitBackTexture =
  97. content.Load<Texture2D>(@"Textures\GameScreens\PlayerSelected");
  98. headerTexture =
  99. content.Load<Texture2D>(@"Textures\GameScreens\Caption");
  100. lineTexture =
  101. content.Load<Texture2D>(@"Textures\GameScreens\SeparationLine");
  102. scrollUpTexture =
  103. content.Load<Texture2D>(@"Textures\GameScreens\ScrollUp");
  104. scrollDownTexture =
  105. content.Load<Texture2D>(@"Textures\GameScreens\ScrollDown");
  106. fadeTexture =
  107. content.Load<Texture2D>(@"Textures\GameScreens\FadeScreen");
  108. Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
  109. backgroundPosition.X = (viewport.Width - backTexture.Width) / 2;
  110. backgroundPosition.Y = (viewport.Height - backTexture.Height) / 2;
  111. screenSize = new Vector2(viewport.Width, viewport.Height);
  112. fadeDest = new Rectangle(0, 0, viewport.Width, viewport.Height);
  113. titlePosition.X = (screenSize.X -
  114. Fonts.HeaderFont.MeasureString(titleText).X) / 2;
  115. titlePosition.Y = backgroundPosition.Y + lineSpacing;
  116. selectIconPosition.X = screenSize.X / 2 + 260;
  117. selectIconPosition.Y = backgroundPosition.Y + 530f;
  118. selectPosition.X = selectIconPosition.X -
  119. Fonts.ButtonNamesFont.MeasureString(selectString).X - 10f;
  120. selectPosition.Y = selectIconPosition.Y;
  121. portraitPosition = backgroundPosition + new Vector2(143f, 155f);
  122. backPosition = backgroundPosition + new Vector2(140f, 135f);
  123. playerNamePosition = backgroundPosition + new Vector2(230f, 160f);
  124. playerClassPosition = backgroundPosition + new Vector2(230f, 185f);
  125. playerLvlPosition = backgroundPosition + new Vector2(230f, 205f);
  126. topLinePosition = backgroundPosition + new Vector2(380f, 160f);
  127. textPosition = backgroundPosition + new Vector2(335f, 320f);
  128. levelPosition = backgroundPosition + new Vector2(540f, 320f);
  129. iconPosition = backgroundPosition + new Vector2(155f, 303f);
  130. linePosition = backgroundPosition + new Vector2(142f, 285f);
  131. scrollUpPosition = backgroundPosition + new Vector2(810f, 300f);
  132. scrollDownPosition = backgroundPosition + new Vector2(810f, 480f);
  133. playerDamagePosition = backgroundPosition + new Vector2(560f, 160f);
  134. spellUpgradePosition = backgroundPosition + new Vector2(380f, 265f);
  135. headerPosition = backgroundPosition + new Vector2(120f, 248f);
  136. }
  137. /// <summary>
  138. /// Handles user input.
  139. /// </summary>
  140. public override void HandleInput()
  141. {
  142. // exit without bothering to see the rest
  143. if (InputManager.IsActionTriggered(InputManager.Action.Back))
  144. {
  145. ExitScreen();
  146. }
  147. // advance to the next player to have leveled up
  148. else if (InputManager.IsActionTriggered(InputManager.Action.Ok))
  149. {
  150. if (leveledUpPlayers.Count <= 0)
  151. {
  152. // no players at all
  153. ExitScreen();
  154. return;
  155. }
  156. if (index < leveledUpPlayers.Count - 1)
  157. {
  158. // move to the next player
  159. index++;
  160. GetSpellList();
  161. }
  162. else
  163. {
  164. // no more players
  165. ExitScreen();
  166. return;
  167. }
  168. }
  169. // Scroll up
  170. else if (InputManager.IsActionTriggered(InputManager.Action.CursorUp))
  171. {
  172. if (startIndex > 0)
  173. {
  174. startIndex--;
  175. endIndex--;
  176. }
  177. }
  178. // Scroll down
  179. else if (InputManager.IsActionTriggered(InputManager.Action.CursorDown))
  180. {
  181. if (startIndex < spellList.Count - maxLines)
  182. {
  183. endIndex++;
  184. startIndex++;
  185. }
  186. }
  187. }
  188. /// <summary>
  189. /// Get the spell list
  190. /// </summary>
  191. private void GetSpellList()
  192. {
  193. spellList.Clear();
  194. if ((leveledUpPlayers.Count > 0) &&
  195. (leveledUpPlayers[index].CharacterLevel <=
  196. leveledUpPlayers[index].CharacterClass.LevelEntries.Count))
  197. {
  198. List<Spell> newSpells =
  199. leveledUpPlayers[index].CharacterClass.LevelEntries[
  200. leveledUpPlayers[index].CharacterLevel - 1].Spells;
  201. if ((newSpells == null) || (newSpells.Count <= 0))
  202. {
  203. startIndex = 0;
  204. endIndex = 0;
  205. }
  206. else
  207. {
  208. spellList.AddRange(leveledUpPlayers[index].Spells);
  209. spellList.RemoveAll(delegate(Spell spell)
  210. {
  211. return !newSpells.Exists(delegate(Spell newSpell)
  212. {
  213. return spell.AssetName == newSpell.AssetName;
  214. });
  215. });
  216. startIndex = 0;
  217. endIndex = Math.Min(maxLines, spellList.Count);
  218. }
  219. }
  220. else
  221. {
  222. startIndex = 0;
  223. endIndex = 0;
  224. }
  225. }
  226. /// <summary>
  227. /// Draw the screen.
  228. /// </summary>
  229. public override void Draw(GameTime gameTime)
  230. {
  231. Vector2 currentTextPosition = textPosition;
  232. Vector2 currentIconPosition = iconPosition;
  233. Vector2 currentLinePosition = linePosition;
  234. Vector2 currentLevelPosition = levelPosition;
  235. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  236. spriteBatch.Begin();
  237. // Draw the fading screen
  238. spriteBatch.Draw(fadeTexture, fadeDest, Color.White);
  239. // Draw the popup background
  240. spriteBatch.Draw(backTexture, backgroundPosition, Color.White);
  241. // Draw the title
  242. spriteBatch.DrawString(Fonts.HeaderFont, titleText, titlePosition,
  243. Fonts.TitleColor);
  244. DrawPlayerStats();
  245. // Draw the spell upgrades caption
  246. spriteBatch.Draw(headerTexture, headerPosition, Color.White);
  247. spriteBatch.DrawString(Fonts.PlayerNameFont, "Spell Upgrades",
  248. spellUpgradePosition, colorClass);
  249. // Draw the horizontal separating lines
  250. for (int i = 0; i <= maxLines - 1; i++)
  251. {
  252. currentLinePosition.Y += lineSpacing;
  253. spriteBatch.Draw(lineTexture, currentLinePosition, Color.White);
  254. }
  255. // Draw the spell upgrade details
  256. for (int i = startIndex; i < endIndex; i++)
  257. {
  258. // Draw the spell icon
  259. spriteBatch.Draw(spellList[i].IconTexture, currentIconPosition,
  260. Color.White);
  261. // Draw the spell name
  262. spriteBatch.DrawString(Fonts.GearInfoFont, spellList[i].Name,
  263. currentTextPosition, Fonts.CountColor);
  264. // Draw the spell level
  265. spriteBatch.DrawString(Fonts.GearInfoFont, "Spell Level " +
  266. spellList[i].Level.ToString(),
  267. currentLevelPosition, Fonts.CountColor);
  268. // Increment to next line position
  269. currentTextPosition.Y += lineSpacing;
  270. currentLevelPosition.Y += lineSpacing;
  271. currentIconPosition.Y += lineSpacing;
  272. }
  273. // Draw the scroll bars
  274. spriteBatch.Draw(scrollUpTexture, scrollUpPosition, Color.White);
  275. spriteBatch.Draw(scrollDownTexture, scrollDownPosition, Color.White);
  276. // Draw the select button and its corresponding text
  277. spriteBatch.DrawString(Fonts.ButtonNamesFont, selectString, selectPosition,
  278. Color.White);
  279. spriteBatch.Draw(selectIconTexture, selectIconPosition, Color.White);
  280. spriteBatch.End();
  281. }
  282. /// <summary>
  283. /// Draw the player stats here
  284. /// </summary>
  285. private void DrawPlayerStats()
  286. {
  287. Vector2 position = topLinePosition;
  288. Vector2 posDamage = playerDamagePosition;
  289. Player player = leveledUpPlayers[index];
  290. int level = player.CharacterLevel;
  291. CharacterLevelingStatistics levelingStatistics =
  292. player.CharacterClass.LevelingStatistics;
  293. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  294. // Draw the portrait
  295. spriteBatch.Draw(portraitBackTexture, backPosition, Color.White);
  296. spriteBatch.Draw(player.ActivePortraitTexture, portraitPosition,
  297. Color.White);
  298. // Print the character name
  299. spriteBatch.DrawString(Fonts.PlayerNameFont,
  300. player.Name, playerNamePosition, colorName);
  301. // Draw the Class Name
  302. spriteBatch.DrawString(Fonts.PlayerNameFont,
  303. player.CharacterClass.Name, playerClassPosition, colorClass);
  304. // Draw the character level
  305. spriteBatch.DrawString(Fonts.PlayerNameFont, "LEVEL: " +
  306. level.ToString(), playerLvlPosition, Color.Gray);
  307. // Draw the character Health Points
  308. SetColor(levelingStatistics.LevelsPerHealthPointsIncrease == 0 ? 0 :
  309. (level % levelingStatistics.LevelsPerHealthPointsIncrease) *
  310. levelingStatistics.HealthPointsIncrease);
  311. spriteBatch.DrawString(Fonts.PlayerStatisticsFont, "HP: " +
  312. player.CurrentStatistics.HealthPoints + "/" +
  313. player.CharacterStatistics.HealthPoints,
  314. position, color);
  315. // Draw the character Mana Points
  316. position.Y += Fonts.GearInfoFont.LineSpacing;
  317. SetColor(levelingStatistics.LevelsPerMagicPointsIncrease == 0 ? 0 :
  318. (level % levelingStatistics.LevelsPerMagicPointsIncrease) *
  319. levelingStatistics.MagicPointsIncrease);
  320. spriteBatch.DrawString(Fonts.PlayerStatisticsFont, "MP: " +
  321. player.CurrentStatistics.MagicPoints + "/" +
  322. player.CharacterStatistics.MagicPoints,
  323. position, color);
  324. // Draw the physical offense
  325. SetColor(levelingStatistics.LevelsPerPhysicalOffenseIncrease == 0 ? 0 :
  326. (level % levelingStatistics.LevelsPerPhysicalOffenseIncrease) *
  327. levelingStatistics.PhysicalOffenseIncrease);
  328. spriteBatch.DrawString(Fonts.PlayerStatisticsFont, "PO: " +
  329. player.CurrentStatistics.PhysicalOffense, posDamage, color);
  330. // Draw the physical defense
  331. posDamage.Y += Fonts.PlayerStatisticsFont.LineSpacing;
  332. SetColor(levelingStatistics.LevelsPerPhysicalDefenseIncrease == 0 ? 0 :
  333. (level % levelingStatistics.LevelsPerPhysicalDefenseIncrease) *
  334. levelingStatistics.PhysicalDefenseIncrease);
  335. spriteBatch.DrawString(Fonts.PlayerStatisticsFont, "PD: " +
  336. player.CurrentStatistics.PhysicalDefense, posDamage, color);
  337. // Draw the Magic offense
  338. posDamage.Y += Fonts.PlayerStatisticsFont.LineSpacing;
  339. SetColor(levelingStatistics.LevelsPerMagicalOffenseIncrease == 0 ? 0 :
  340. (level % levelingStatistics.LevelsPerMagicalOffenseIncrease) *
  341. levelingStatistics.MagicalOffenseIncrease);
  342. spriteBatch.DrawString(Fonts.PlayerStatisticsFont, "MO: " +
  343. player.CurrentStatistics.MagicalOffense, posDamage, color);
  344. // Draw the Magical defense
  345. posDamage.Y += Fonts.PlayerStatisticsFont.LineSpacing;
  346. SetColor(levelingStatistics.LevelsPerMagicalDefenseIncrease == 0 ? 0 :
  347. (level % levelingStatistics.LevelsPerMagicalDefenseIncrease) *
  348. levelingStatistics.MagicalDefenseIncrease);
  349. spriteBatch.DrawString(Fonts.PlayerStatisticsFont, "MD: " +
  350. player.CurrentStatistics.MagicalDefense, posDamage, color);
  351. }
  352. /// <summary>
  353. /// Set the current color based on whether the value has changed.
  354. /// </summary>
  355. /// <param name="change">State of levelled up values</param>
  356. public void SetColor(int value)
  357. {
  358. if (value > 0)
  359. {
  360. color = Color.Green;
  361. }
  362. else if (value < 0)
  363. {
  364. color = Color.Red;
  365. }
  366. else
  367. {
  368. color = colorText;
  369. }
  370. }
  371. }
  372. }