StatisticsScreen.cs 22 KB

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