StatisticsScreen.cs 23 KB

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