LevelUpScreen.cs 17 KB

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