StatisticsScreen.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. //-----------------------------------------------------------------------------
  2. // StatisticsScreen.cs
  3. //
  4. // Microsoft XNA Community Game Platform
  5. // Copyright (C) Microsoft Corporation. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. using System.IO;
  8. using Microsoft.Xna.Framework;
  9. using Microsoft.Xna.Framework.Content;
  10. using Microsoft.Xna.Framework.Graphics;
  11. using RolePlaying.Data;
  12. namespace RolePlaying
  13. {
  14. /// <summary>
  15. /// Draws the statistics for a particular Player.
  16. /// </summary>
  17. class StatisticsScreen : GameScreen
  18. {
  19. /// <summary>
  20. /// This is used ass the Player NPC to display statistics of the player
  21. /// </summary>
  22. private Player player;
  23. private Texture2D statisticsScreen;
  24. private Texture2D selectButton;
  25. private Texture2D backButton;
  26. private Texture2D dropButton;
  27. private Texture2D statisticsBorder;
  28. private Texture2D plankTexture;
  29. private Texture2D fadeTexture;
  30. private Texture2D goldIcon;
  31. private Texture2D scoreBoardTexture;
  32. private Texture2D rightTriggerButton;
  33. private Texture2D leftTriggerButton;
  34. private Texture2D borderLine;
  35. private Rectangle screenRectangle;
  36. private const int intervalBetweenEachInfo = 30;
  37. private int playerIndex = 0;
  38. private AnimatingSprite screenAnimation;
  39. private readonly Vector2 playerTextPosition = new Vector2(515, 200);
  40. private Vector2 currentTextPosition;
  41. private readonly Vector2 scoreBoardPosition = new Vector2(1160, 354);
  42. private Vector2 placeTextMid;
  43. private Vector2 statisticsNamePosition;
  44. private readonly Vector2 shieldPosition = new Vector2(1124, 253);
  45. private readonly Vector2 idlePortraitPosition = new Vector2(300f, 400f);
  46. private readonly Vector2 dropButtonPosition = new Vector2(900, 640);
  47. private readonly Vector2 statisticsBorderPosition = new Vector2(180, 147);
  48. private readonly Vector2 borderLinePosition = new Vector2(184, 523);
  49. private readonly Vector2 characterNamePosition = new Vector2(330, 188);
  50. private readonly Vector2 classNamePosition = new Vector2(330, 460);
  51. private Vector2 plankPosition;
  52. private readonly Vector2 goldIconPosition = new Vector2(490, 640);
  53. private readonly Vector2 weaponPosition = new Vector2(790, 220);
  54. private readonly Vector2 armorPosition = new Vector2(790, 346);
  55. private readonly Vector2 weaponTextPosition = new Vector2(790, 285);
  56. private readonly Vector2 leftTriggerPosition = new Vector2(340, 50);
  57. private readonly Vector2 rightTriggerPosition = new Vector2(900, 50);
  58. private readonly Vector2 iconPosition = new Vector2(100, 200);
  59. private readonly Vector2 selectButtonPosition = new Vector2(1150, 640);
  60. private readonly Vector2 backButtonPosition = new Vector2(80, 640);
  61. private readonly Vector2 goldPosition = new Vector2(565, 648);
  62. /// <summary>
  63. /// Creates a new StatisticsScreen object for the first party member.
  64. /// </summary>
  65. public StatisticsScreen() : this(Session.Party.Players[0]) { }
  66. /// <summary>
  67. /// Creates a new StatisticsScreen object for the given player.
  68. /// </summary>
  69. public StatisticsScreen(Player player)
  70. : base()
  71. {
  72. this.IsPopup = true;
  73. this.player = player;
  74. screenAnimation = new AnimatingSprite();
  75. screenAnimation.FrameDimensions = player.MapSprite.FrameDimensions;
  76. screenAnimation.FramesPerRow = player.MapSprite.FramesPerRow;
  77. screenAnimation.SourceOffset = player.MapSprite.SourceOffset;
  78. screenAnimation.Texture = player.MapSprite.Texture;
  79. screenAnimation.AddAnimation(new Animation("Idle", 43, 48, 150, true));
  80. screenAnimation.PlayAnimation(0);
  81. }
  82. /// <summary>
  83. /// Loads graphics content from the content manager.
  84. /// </summary>
  85. public override void LoadContent()
  86. {
  87. ContentManager content = ScreenManager.Game.Content;
  88. statisticsScreen =
  89. content.Load<Texture2D>(Path.Combine("Textures", "GameScreens", "GameScreenBkgd"));
  90. plankTexture =
  91. content.Load<Texture2D>(Path.Combine("Textures", "MainMenu", "MainMenuPlank03"));
  92. scoreBoardTexture =
  93. content.Load<Texture2D>(Path.Combine("Textures", "GameScreens", "CountShieldWithArrow"));
  94. leftTriggerButton =
  95. content.Load<Texture2D>(Path.Combine("Textures", "Buttons", "LeftTriggerButton"));
  96. rightTriggerButton =
  97. content.Load<Texture2D>(Path.Combine("Textures", "Buttons", "RightTriggerButton"));
  98. backButton =
  99. content.Load<Texture2D>(Path.Combine("Textures", "Buttons", "BButton"));
  100. selectButton =
  101. content.Load<Texture2D>(Path.Combine("Textures", "Buttons", "AButton"));
  102. dropButton =
  103. content.Load<Texture2D>(Path.Combine("Textures", "Buttons", "YButton"));
  104. statisticsBorder =
  105. content.Load<Texture2D>(Path.Combine("Textures", "GameScreens", "StatsBorderTable"));
  106. borderLine =
  107. content.Load<Texture2D>(Path.Combine("Textures", "GameScreens", "LineBorder"));
  108. goldIcon =
  109. content.Load<Texture2D>(Path.Combine("Textures", "GameScreens", "GoldIcon"));
  110. fadeTexture =
  111. content.Load<Texture2D>(Path.Combine("Textures", "GameScreens", "FadeScreen"));
  112. screenRectangle = new Rectangle(0, 0, Session.BACK_BUFFER_WIDTH, Session.BACK_BUFFER_HEIGHT);
  113. statisticsNamePosition.X = (Session.BACK_BUFFER_WIDTH -
  114. Fonts.HeaderFont.MeasureString("Statistics").X) / 2;
  115. statisticsNamePosition.Y = 95f;
  116. plankPosition.X = (Session.BACK_BUFFER_WIDTH - plankTexture.Width) / 2;
  117. plankPosition.Y = 67f;
  118. }
  119. /// <summary>
  120. /// Handle user input.
  121. /// </summary>
  122. public override void HandleInput()
  123. {
  124. // exit the screen
  125. if (InputManager.IsActionTriggered(InputManager.InputAction.Back))
  126. {
  127. ExitScreen();
  128. return;
  129. }
  130. // shows the spells for this player
  131. else if (InputManager.IsActionTriggered(InputManager.InputAction.Ok))
  132. {
  133. ScreenManager.AddScreen(new SpellbookScreen(player, player.CharacterStatistics));
  134. return;
  135. }
  136. // show the equipment for this player, allowing the user to unequip
  137. else if (InputManager.IsActionTriggered(InputManager.InputAction.TakeView))
  138. {
  139. ScreenManager.AddScreen(new EquipmentScreen(player));
  140. return;
  141. }
  142. else if (Session.Party.Players.Contains(player)) // player is in the party
  143. {
  144. // move to the previous screen
  145. if (InputManager.IsActionTriggered(InputManager.InputAction.PageLeft))
  146. {
  147. ExitScreen();
  148. ScreenManager.AddScreen(new QuestLogScreen(null));
  149. return;
  150. }
  151. // move to the next screen
  152. else if (InputManager.IsActionTriggered(InputManager.InputAction.PageRight))
  153. {
  154. ExitScreen();
  155. ScreenManager.AddScreen(new InventoryScreen(true));
  156. return;
  157. }
  158. // move to the previous party member
  159. else if (InputManager.IsActionTriggered(InputManager.InputAction.CursorUp))
  160. {
  161. playerIndex--;
  162. if (playerIndex < 0)
  163. {
  164. playerIndex = Session.Party.Players.Count - 1;
  165. }
  166. Player newPlayer = Session.Party.Players[playerIndex];
  167. if (newPlayer != player)
  168. {
  169. player = newPlayer;
  170. screenAnimation = new AnimatingSprite();
  171. screenAnimation.FrameDimensions = player.MapSprite.FrameDimensions;
  172. screenAnimation.FramesPerRow = player.MapSprite.FramesPerRow;
  173. screenAnimation.SourceOffset = player.MapSprite.SourceOffset;
  174. screenAnimation.Texture = player.MapSprite.Texture;
  175. screenAnimation.AddAnimation(new Animation("Idle", 43, 48, 150, true));
  176. screenAnimation.PlayAnimation(0);
  177. }
  178. }
  179. // move to the next party member
  180. else if (InputManager.IsActionTriggered(InputManager.InputAction.CursorDown))
  181. {
  182. playerIndex++;
  183. if (playerIndex >= Session.Party.Players.Count)
  184. {
  185. playerIndex = 0;
  186. }
  187. Player newPlayer = Session.Party.Players[playerIndex];
  188. if (newPlayer != player)
  189. {
  190. player = newPlayer;
  191. screenAnimation = new AnimatingSprite();
  192. screenAnimation.FrameDimensions = player.MapSprite.FrameDimensions;
  193. screenAnimation.FramesPerRow = player.MapSprite.FramesPerRow;
  194. screenAnimation.SourceOffset = player.MapSprite.SourceOffset;
  195. screenAnimation.Texture = player.MapSprite.Texture;
  196. screenAnimation.AddAnimation(new Animation("Idle", 43, 48, 150, true));
  197. screenAnimation.PlayAnimation(0);
  198. }
  199. }
  200. }
  201. }
  202. /// <summary>
  203. /// Draws the screen.
  204. /// </summary>
  205. public override void Draw(GameTime gameTime)
  206. {
  207. screenAnimation.UpdateAnimation((float)gameTime.ElapsedGameTime.TotalSeconds);
  208. ScreenManager.SpriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, ScreenManager.GlobalTransformation);
  209. DrawStatistics();
  210. ScreenManager.SpriteBatch.End();
  211. }
  212. /// <summary>
  213. /// Draws the player statistics.
  214. /// </summary>
  215. private void DrawStatistics()
  216. {
  217. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  218. // Draw faded screen
  219. spriteBatch.Draw(fadeTexture, screenRectangle, Color.White);
  220. // Draw the Statistics Screen
  221. spriteBatch.Draw(statisticsScreen, screenRectangle, Color.White);
  222. spriteBatch.Draw(plankTexture, plankPosition, Color.White);
  223. spriteBatch.Draw(statisticsBorder, statisticsBorderPosition, Color.White);
  224. spriteBatch.Draw(borderLine, borderLinePosition, Color.White);
  225. spriteBatch.Draw(screenAnimation.Texture, idlePortraitPosition,
  226. screenAnimation.SourceRectangle, Color.White, 0f,
  227. new Vector2(screenAnimation.SourceOffset.X,
  228. screenAnimation.SourceOffset.Y), 1f, SpriteEffects.None, 0f);
  229. spriteBatch.DrawString(Fonts.HeaderFont, "Statistics", statisticsNamePosition, Fonts.TitleColor, MathHelper.ToRadians(-3.0f), Vector2.Zero, 1.0f, SpriteEffects.None, 0f);
  230. DrawPlayerDetails();
  231. DrawButtons();
  232. }
  233. /// <summary>
  234. /// D
  235. /// </summary>
  236. private void DrawButtons()
  237. {
  238. if (!IsActive)
  239. {
  240. return;
  241. }
  242. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  243. Vector2 position = new Vector2();
  244. if (Session.Party.Players.Contains(player))
  245. {
  246. // Left Trigger
  247. position = leftTriggerPosition;
  248. spriteBatch.Draw(leftTriggerButton, position, Color.White);
  249. // Draw Left Trigger Information
  250. position.Y += leftTriggerButton.Height;
  251. placeTextMid = Fonts.PlayerStatisticsFont.MeasureString("Quest");
  252. position.X += (leftTriggerButton.Width / 2) - placeTextMid.X / 2;
  253. spriteBatch.DrawString(Fonts.PlayerStatisticsFont, "Quest", position,
  254. Color.Black);
  255. // Right Trigger
  256. position = rightTriggerPosition;
  257. spriteBatch.Draw(rightTriggerButton, position, Color.White);
  258. // Draw Right Trigger Information
  259. position.Y += rightTriggerButton.Height;
  260. placeTextMid = Fonts.PlayerStatisticsFont.MeasureString("Equipment");
  261. position.X += (leftTriggerButton.Width / 2) - placeTextMid.X / 2;
  262. spriteBatch.DrawString(Fonts.PlayerStatisticsFont, "Equipment", position,
  263. Color.Black);
  264. }
  265. // Back Button
  266. spriteBatch.Draw(backButton, backButtonPosition, Color.White);
  267. spriteBatch.Draw(selectButton, selectButtonPosition, Color.White);
  268. position = selectButtonPosition;
  269. position.X -= Fonts.ButtonNamesFont.MeasureString("Spellbook").X + 10f;
  270. position.Y += 5;
  271. spriteBatch.DrawString(Fonts.ButtonNamesFont, "Spellbook", position,
  272. Color.White);
  273. // Draw Back
  274. position = backButtonPosition;
  275. position.X += backButton.Width + 10f;
  276. position.Y += 5;
  277. spriteBatch.DrawString(Fonts.ButtonNamesFont, "Back", position,
  278. Color.White);
  279. // Draw drop Button
  280. spriteBatch.Draw(dropButton, dropButtonPosition, Color.White);
  281. position = dropButtonPosition;
  282. position.X -= Fonts.ButtonNamesFont.MeasureString("Equipment").X + 10;
  283. position.Y += 5;
  284. spriteBatch.DrawString(Fonts.ButtonNamesFont, "Equipment", position,
  285. Color.White);
  286. // Draw Gold Icon
  287. spriteBatch.Draw(goldIcon, goldIconPosition, Color.White);
  288. }
  289. /// <summary>
  290. /// Draws player information.
  291. /// </summary>
  292. private void DrawPlayerDetails()
  293. {
  294. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  295. if (player != null)
  296. {
  297. currentTextPosition.X = playerTextPosition.X;
  298. currentTextPosition.Y = playerTextPosition.Y;
  299. // Current Level
  300. spriteBatch.DrawString(Fonts.DescriptionFont, "Level: " +
  301. player.CharacterLevel,
  302. currentTextPosition, Color.Black);
  303. // Health Points
  304. currentTextPosition.Y += intervalBetweenEachInfo;
  305. spriteBatch.DrawString(Fonts.DescriptionFont, "Health Points: " +
  306. player.CurrentStatistics.HealthPoints + "/" +
  307. player.CharacterStatistics.HealthPoints,
  308. currentTextPosition, Color.Black);
  309. // Magic Points
  310. currentTextPosition.Y += intervalBetweenEachInfo;
  311. spriteBatch.DrawString(Fonts.DescriptionFont, "Magic Points: " +
  312. player.CurrentStatistics.MagicPoints + "/" +
  313. player.CharacterStatistics.MagicPoints,
  314. currentTextPosition, Color.Black);
  315. // Experience Details
  316. currentTextPosition.Y += intervalBetweenEachInfo;
  317. if (player.IsMaximumCharacterLevel)
  318. {
  319. spriteBatch.DrawString(Fonts.DescriptionFont, "Experience: Maximum",
  320. currentTextPosition, Color.Black);
  321. }
  322. else
  323. {
  324. spriteBatch.DrawString(Fonts.DescriptionFont, "Experience: " +
  325. player.Experience + "/" +
  326. player.ExperienceForNextLevel,
  327. currentTextPosition, Color.Black);
  328. }
  329. DrawEquipmentInfo(player);
  330. DrawModifiers(player);
  331. DrawEquipmentStatistics(player);
  332. if (player == null)
  333. {
  334. DrawPlayerCount();
  335. }
  336. }
  337. // Draw Gold
  338. spriteBatch.DrawString(Fonts.ButtonNamesFont,
  339. Fonts.GetGoldString(Session.Party.PartyGold), goldPosition,
  340. Color.White);
  341. }
  342. /// <summary>
  343. /// Draws Current Selected Player Count to Total Player count
  344. /// </summary>
  345. private void DrawPlayerCount()
  346. {
  347. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  348. Vector2 position = new Vector2();
  349. // Draw the ScoreBoard
  350. spriteBatch.Draw(scoreBoardTexture, shieldPosition,
  351. Color.White);
  352. position = scoreBoardPosition;
  353. position.X = scoreBoardPosition.X -
  354. Fonts.GearInfoFont.MeasureString((playerIndex + 1).ToString()).X / 2;
  355. // Draw Current Selected Player Count
  356. spriteBatch.DrawString(Fonts.GearInfoFont, (playerIndex + 1).ToString(),
  357. position, Fonts.CountColor);
  358. position.X = scoreBoardPosition.X - Fonts.GearInfoFont.MeasureString(
  359. Session.Party.Players.Count.ToString()).X / 2;
  360. position.Y += 30;
  361. // Draw Total Player count
  362. spriteBatch.DrawString(Fonts.GearInfoFont,
  363. Session.Party.Players.Count.ToString(), position, Fonts.CountColor);
  364. }
  365. /// <summary>
  366. /// Draw Equipment Info of the player selected
  367. /// </summary>
  368. /// <param name="selectedPlayer">The selected player</param>
  369. private void DrawEquipmentInfo(Player selectedPlayer)
  370. {
  371. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  372. // Character name
  373. currentTextPosition = characterNamePosition;
  374. currentTextPosition.X -= Fonts.HeaderFont.MeasureString(selectedPlayer.Name).X / 2;
  375. spriteBatch.DrawString(Fonts.HeaderFont, selectedPlayer.Name, currentTextPosition, Fonts.TitleColor);
  376. // Class name
  377. currentTextPosition = classNamePosition;
  378. currentTextPosition.X -= Fonts.HeaderFont.MeasureString(selectedPlayer.CharacterClass.Name).X / 2;
  379. spriteBatch.DrawString(Fonts.HeaderFont, selectedPlayer.CharacterClass.Name, currentTextPosition, Color.Black);
  380. }
  381. /// <summary>
  382. /// Draw Base Amount Plus any Modifiers
  383. /// </summary>
  384. /// <param name="selectedPlayer">The selected player</param>
  385. private void DrawModifiers(Player selectedPlayer)
  386. {
  387. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  388. currentTextPosition.X = playerTextPosition.X;
  389. currentTextPosition.Y = playerTextPosition.Y + 150;
  390. // PO + Modifiers
  391. spriteBatch.DrawString(Fonts.DescriptionFont, "Physical Offense: " +
  392. selectedPlayer.CurrentStatistics.PhysicalOffense,
  393. currentTextPosition, Color.Black);
  394. // PD + Modifiers
  395. currentTextPosition.Y += intervalBetweenEachInfo;
  396. spriteBatch.DrawString(Fonts.DescriptionFont, "Physical Defense: " +
  397. selectedPlayer.CurrentStatistics.PhysicalDefense,
  398. currentTextPosition, Color.Black);
  399. // MO + Modifiers
  400. currentTextPosition.Y += intervalBetweenEachInfo;
  401. spriteBatch.DrawString(Fonts.DescriptionFont, "Magical Offense: " +
  402. selectedPlayer.CurrentStatistics.MagicalOffense,
  403. currentTextPosition, Color.Black);
  404. // MD + Modifiers
  405. currentTextPosition.Y += intervalBetweenEachInfo;
  406. spriteBatch.DrawString(Fonts.DescriptionFont, "Magical Defense: " +
  407. selectedPlayer.CurrentStatistics.MagicalDefense,
  408. currentTextPosition, Color.Black);
  409. }
  410. /// <summary>
  411. /// Draw the equipment statistics
  412. /// </summary>
  413. /// <param name="selectedPlayer">The selected Player</param>
  414. private void DrawEquipmentStatistics(Player selectedPlayer)
  415. {
  416. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  417. Vector2 position = weaponPosition;
  418. Int32Range healthDamageRange = new Int32Range();
  419. healthDamageRange.Minimum = healthDamageRange.Maximum =
  420. selectedPlayer.CurrentStatistics.PhysicalOffense;
  421. Weapon weapon = selectedPlayer.GetEquippedWeapon();
  422. if (weapon != null)
  423. {
  424. weapon.DrawIcon(ScreenManager.SpriteBatch, position);
  425. healthDamageRange += weapon.TargetDamageRange;
  426. }
  427. position = armorPosition;
  428. Int32Range healthDefenseRange = new Int32Range();
  429. healthDefenseRange.Minimum = healthDefenseRange.Maximum =
  430. selectedPlayer.CurrentStatistics.PhysicalDefense;
  431. Int32Range magicDefenseRange = new Int32Range();
  432. magicDefenseRange.Minimum = magicDefenseRange.Maximum =
  433. selectedPlayer.CurrentStatistics.MagicalDefense;
  434. for (int i = 0; i < (int)4; i++)
  435. {
  436. Armor armor = selectedPlayer.GetEquippedArmor((Armor.ArmorSlot)i);
  437. if (armor != null)
  438. {
  439. armor.DrawIcon(ScreenManager.SpriteBatch, position);
  440. healthDefenseRange += armor.OwnerHealthDefenseRange;
  441. magicDefenseRange += armor.OwnerMagicDefenseRange;
  442. }
  443. position.X += 68;
  444. }
  445. position = weaponTextPosition;
  446. spriteBatch.DrawString(Fonts.DescriptionFont, "Weapon Attack: " + "(" +
  447. healthDamageRange.Minimum + "," +
  448. healthDamageRange.Maximum + ")",
  449. position, Color.Black);
  450. position.Y += 130;
  451. spriteBatch.DrawString(Fonts.DescriptionFont, "Weapon Defense: " + "(" +
  452. healthDefenseRange.Minimum + "," +
  453. healthDefenseRange.Maximum + ")",
  454. position, Color.Black);
  455. position.Y += 30;
  456. spriteBatch.DrawString(Fonts.DescriptionFont, "Spell Defense: " + "(" +
  457. magicDefenseRange.Minimum + "," +
  458. magicDefenseRange.Maximum + ")",
  459. position, Color.Black);
  460. }
  461. }
  462. }