123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587 |
- #region File Description
- //-----------------------------------------------------------------------------
- // StatisticsScreen.cs
- //
- // Microsoft XNA Community Game Platform
- // Copyright (C) Microsoft Corporation. All rights reserved.
- //-----------------------------------------------------------------------------
- #endregion
- #region Using Statements
- using System;
- using System.Collections.Generic;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Content;
- using RolePlayingGameData;
- #endregion
- namespace RolePlaying
- {
- /// <summary>
- /// Draws the statistics for a particular Player.
- /// </summary>
- class StatisticsScreen : GameScreen
- {
- /// <summary>
- /// This is used ass the Player NPC to display statistics of the player
- /// </summary>
- private Player player;
- #region Graphics Data
- private Texture2D statisticsScreen;
- private Texture2D selectButton;
- private Texture2D backButton;
- private Texture2D dropButton;
- private Texture2D statisticsBorder;
- private Texture2D plankTexture;
- private Texture2D fadeTexture;
- private Texture2D goldIcon;
- private Texture2D scoreBoardTexture;
- private Texture2D rightTriggerButton;
- private Texture2D leftTriggerButton;
- private Texture2D borderLine;
- private Rectangle screenRectangle;
- private const int intervalBetweenEachInfo = 30;
- private int playerIndex = 0;
- private AnimatingSprite screenAnimation;
- #endregion
- #region Positions
- private readonly Vector2 playerTextPosition = new Vector2(515, 200);
- private Vector2 currentTextPosition;
- private readonly Vector2 scoreBoardPosition = new Vector2(1160, 354);
- private Vector2 placeTextMid;
- private Vector2 statisticsNamePosition;
- private readonly Vector2 shieldPosition = new Vector2(1124, 253);
- private readonly Vector2 idlePortraitPosition = new Vector2(300f, 380f);
- private readonly Vector2 dropButtonPosition = new Vector2(900, 640);
- private readonly Vector2 statisticsBorderPosition = new Vector2(180, 147);
- private readonly Vector2 borderLinePosition = new Vector2(184, 523);
- private readonly Vector2 characterNamePosition = new Vector2(330, 180);
- private readonly Vector2 classNamePosition = new Vector2(330, 465);
- private Vector2 plankPosition;
- private readonly Vector2 goldIconPosition = new Vector2(490, 640);
- private readonly Vector2 weaponPosition = new Vector2(790, 220);
- private readonly Vector2 armorPosition = new Vector2(790, 346);
- private readonly Vector2 weaponTextPosition = new Vector2(790, 285);
- private readonly Vector2 leftTriggerPosition = new Vector2(340, 50);
- private readonly Vector2 rightTriggerPosition = new Vector2(900, 50);
- private readonly Vector2 iconPosition = new Vector2(100, 200);
- private readonly Vector2 selectButtonPosition = new Vector2(1150, 640);
- private readonly Vector2 backButtonPosition = new Vector2(80, 640);
- private readonly Vector2 goldPosition = new Vector2(565, 648);
- #endregion
- #region Initialization
- /// <summary>
- /// Creates a new StatisticsScreen object for the first party member.
- /// </summary>
- public StatisticsScreen() : this(Session.Party.Players[0]) { }
- /// <summary>
- /// Creates a new StatisticsScreen object for the given player.
- /// </summary>
- public StatisticsScreen(Player player)
- : base()
- {
- this.IsPopup = true;
- this.player = player;
- screenAnimation = new AnimatingSprite();
- screenAnimation.FrameDimensions = player.MapSprite.FrameDimensions;
- screenAnimation.FramesPerRow = player.MapSprite.FramesPerRow;
- screenAnimation.SourceOffset = player.MapSprite.SourceOffset;
- screenAnimation.Texture = player.MapSprite.Texture;
- screenAnimation.AddAnimation(new Animation("Idle", 43, 48, 150, true));
- screenAnimation.PlayAnimation(0);
- }
- /// <summary>
- /// Loads graphics content from the content manager.
- /// </summary>
- public override void LoadContent()
- {
- ContentManager content = ScreenManager.Game.Content;
- Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
- statisticsScreen =
- content.Load<Texture2D>(@"Textures\GameScreens\GameScreenBkgd");
- plankTexture =
- content.Load<Texture2D>(@"Textures\MainMenu\MainMenuPlank03");
- scoreBoardTexture =
- content.Load<Texture2D>(@"Textures\GameScreens\CountShieldWithArrow");
- leftTriggerButton =
- content.Load<Texture2D>(@"Textures\Buttons\LeftTriggerButton");
- rightTriggerButton =
- content.Load<Texture2D>(@"Textures\Buttons\RightTriggerButton");
- backButton =
- content.Load<Texture2D>(@"Textures\Buttons\BButton");
- selectButton =
- content.Load<Texture2D>(@"Textures\Buttons\AButton");
- dropButton =
- content.Load<Texture2D>(@"Textures\Buttons\YButton");
- statisticsBorder =
- content.Load<Texture2D>(@"Textures\GameScreens\StatsBorderTable");
- borderLine =
- content.Load<Texture2D>(@"Textures\GameScreens\LineBorder");
- goldIcon =
- content.Load<Texture2D>(@"Textures\GameScreens\GoldIcon");
- fadeTexture =
- content.Load<Texture2D>(@"Textures\GameScreens\FadeScreen");
- screenRectangle = new Rectangle(viewport.X, viewport.Y,
- viewport.Width, viewport.Height);
- statisticsNamePosition.X = (viewport.Width -
- Fonts.HeaderFont.MeasureString("Statistics").X) / 2;
- statisticsNamePosition.Y = 90f;
- plankPosition.X = (viewport.Width - plankTexture.Width) / 2;
- plankPosition.Y = 67f;
- }
- #endregion
- #region Updating
- /// <summary>
- /// Handle user input.
- /// </summary>
- public override void HandleInput()
- {
- // exit the screen
- if (InputManager.IsActionTriggered(InputManager.Action.Back))
- {
- ExitScreen();
- return;
- }
- // shows the spells for this player
- else if (InputManager.IsActionTriggered(InputManager.Action.Ok))
- {
- ScreenManager.AddScreen(new SpellbookScreen(player,
- player.CharacterStatistics));
- return;
- }
- // show the equipment for this player, allowing the user to unequip
- else if (InputManager.IsActionTriggered(InputManager.Action.TakeView))
- {
- ScreenManager.AddScreen(new EquipmentScreen(player));
- return;
- }
- else if (Session.Party.Players.Contains(player)) // player is in the party
- {
- // move to the previous screen
- if (InputManager.IsActionTriggered(InputManager.Action.PageLeft))
- {
- ExitScreen();
- ScreenManager.AddScreen(new QuestLogScreen(null));
- return;
- }
- // move to the next screen
- else if (InputManager.IsActionTriggered(InputManager.Action.PageRight))
- {
- ExitScreen();
- ScreenManager.AddScreen(new InventoryScreen(true));
- return;
- }
- // move to the previous party member
- else if (InputManager.IsActionTriggered(InputManager.Action.CursorUp))
- {
- playerIndex--;
- if (playerIndex < 0)
- {
- playerIndex = Session.Party.Players.Count - 1;
- }
- Player newPlayer = Session.Party.Players[playerIndex];
- if (newPlayer != player)
- {
- player = newPlayer;
- screenAnimation = new AnimatingSprite();
- screenAnimation.FrameDimensions =
- player.MapSprite.FrameDimensions;
- screenAnimation.FramesPerRow = player.MapSprite.FramesPerRow;
- screenAnimation.SourceOffset = player.MapSprite.SourceOffset;
- screenAnimation.Texture = player.MapSprite.Texture;
- screenAnimation.AddAnimation(
- new Animation("Idle", 43, 48, 150, true));
- screenAnimation.PlayAnimation(0);
- }
- }
- // move to the next party member
- else if (InputManager.IsActionTriggered(InputManager.Action.CursorDown))
- {
- playerIndex++;
- if (playerIndex >= Session.Party.Players.Count)
- {
- playerIndex = 0;
- }
- Player newPlayer = Session.Party.Players[playerIndex];
- if (newPlayer != player)
- {
- player = newPlayer;
- screenAnimation = new AnimatingSprite();
- screenAnimation.FrameDimensions =
- player.MapSprite.FrameDimensions;
- screenAnimation.FramesPerRow = player.MapSprite.FramesPerRow;
- screenAnimation.SourceOffset = player.MapSprite.SourceOffset;
- screenAnimation.Texture = player.MapSprite.Texture;
- screenAnimation.AddAnimation(
- new Animation("Idle", 43, 48, 150, true));
- screenAnimation.PlayAnimation(0);
- }
- }
- }
- }
- #endregion
- #region Drawing
- /// <summary>
- /// Draws the screen.
- /// </summary>
- public override void Draw(GameTime gameTime)
- {
- screenAnimation.UpdateAnimation(
- (float)gameTime.ElapsedGameTime.TotalSeconds);
- ScreenManager.SpriteBatch.Begin();
- DrawStatistics();
- ScreenManager.SpriteBatch.End();
- }
- /// <summary>
- /// Draws the player statistics.
- /// </summary>
- private void DrawStatistics()
- {
- SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
- // Draw faded screen
- spriteBatch.Draw(fadeTexture, screenRectangle, Color.White);
- // Draw the Statistics Screen
- spriteBatch.Draw(statisticsScreen, screenRectangle, Color.White);
- spriteBatch.Draw(plankTexture, plankPosition, Color.White);
- spriteBatch.Draw(statisticsBorder, statisticsBorderPosition, Color.White);
- spriteBatch.Draw(borderLine, borderLinePosition, Color.White);
- spriteBatch.Draw(screenAnimation.Texture, idlePortraitPosition,
- screenAnimation.SourceRectangle, Color.White, 0f,
- new Vector2(screenAnimation.SourceOffset.X,
- screenAnimation.SourceOffset.Y), 1f, SpriteEffects.None, 0f);
- spriteBatch.DrawString(Fonts.HeaderFont, "Statistics",
- statisticsNamePosition, Fonts.TitleColor);
- DrawPlayerDetails();
- DrawButtons();
- }
- /// <summary>
- /// D
- /// </summary>
- private void DrawButtons()
- {
- if (!IsActive)
- {
- return;
- }
- SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
- Vector2 position = new Vector2();
- if (Session.Party.Players.Contains(player))
- {
- // Left Trigger
- position = leftTriggerPosition;
- spriteBatch.Draw(leftTriggerButton, position, Color.White);
- // Draw Left Trigger Information
- position.Y += leftTriggerButton.Height;
- placeTextMid = Fonts.PlayerStatisticsFont.MeasureString("Quest");
- position.X += (leftTriggerButton.Width / 2) - placeTextMid.X / 2;
- spriteBatch.DrawString(Fonts.PlayerStatisticsFont, "Quest", position,
- Color.Black);
- // Right Trigger
- position = rightTriggerPosition;
- spriteBatch.Draw(rightTriggerButton, position, Color.White);
- // Draw Right Trigger Information
- position.Y += rightTriggerButton.Height;
- placeTextMid = Fonts.PlayerStatisticsFont.MeasureString("Items");
- position.X += (leftTriggerButton.Width / 2) - placeTextMid.X / 2;
- spriteBatch.DrawString(Fonts.PlayerStatisticsFont, "Items", position,
- Color.Black);
- }
- // Back Button
- spriteBatch.Draw(backButton, backButtonPosition, Color.White);
- spriteBatch.Draw(selectButton, selectButtonPosition, Color.White);
- position = selectButtonPosition;
- position.X -= Fonts.ButtonNamesFont.MeasureString("Spellbook").X + 10f;
- position.Y += 5;
- spriteBatch.DrawString(Fonts.ButtonNamesFont, "Spellbook", position,
- Color.White);
- // Draw Back
- position = backButtonPosition;
- position.X += backButton.Width + 10f;
- position.Y += 5;
- spriteBatch.DrawString(Fonts.ButtonNamesFont, "Back", position,
- Color.White);
- // Draw drop Button
- spriteBatch.Draw(dropButton, dropButtonPosition, Color.White);
- position = dropButtonPosition;
- position.X -= Fonts.ButtonNamesFont.MeasureString("Equipment").X + 10;
- position.Y += 5;
- spriteBatch.DrawString(Fonts.ButtonNamesFont, "Equipment", position,
- Color.White);
- // Draw Gold Icon
- spriteBatch.Draw(goldIcon, goldIconPosition, Color.White);
- }
- /// <summary>
- /// Draws player information.
- /// </summary>
- private void DrawPlayerDetails()
- {
- SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
- if (player != null)
- {
- currentTextPosition.X = playerTextPosition.X;
- currentTextPosition.Y = playerTextPosition.Y;
- // Current Level
- spriteBatch.DrawString(Fonts.DescriptionFont, "Level: " +
- player.CharacterLevel,
- currentTextPosition, Color.Black);
- // Health Points
- currentTextPosition.Y += intervalBetweenEachInfo;
- spriteBatch.DrawString(Fonts.DescriptionFont, "Health Points: " +
- player.CurrentStatistics.HealthPoints + "/" +
- player.CharacterStatistics.HealthPoints,
- currentTextPosition, Color.Black);
- // Magic Points
- currentTextPosition.Y += intervalBetweenEachInfo;
- spriteBatch.DrawString(Fonts.DescriptionFont, "Magic Points: " +
- player.CurrentStatistics.MagicPoints + "/" +
- player.CharacterStatistics.MagicPoints,
- currentTextPosition, Color.Black);
- // Experience Details
- currentTextPosition.Y += intervalBetweenEachInfo;
- if (player.IsMaximumCharacterLevel)
- {
- spriteBatch.DrawString(Fonts.DescriptionFont, "Experience: Maximum",
- currentTextPosition, Color.Black);
- }
- else
- {
- spriteBatch.DrawString(Fonts.DescriptionFont, "Experience: " +
- player.Experience + "/" +
- player.ExperienceForNextLevel,
- currentTextPosition, Color.Black);
- }
- DrawEquipmentInfo(player);
- DrawModifiers(player);
- DrawEquipmentStatistics(player);
- if (player == null)
- {
- DrawPlayerCount();
- }
- }
- // Draw Gold
- spriteBatch.DrawString(Fonts.ButtonNamesFont,
- Fonts.GetGoldString(Session.Party.PartyGold), goldPosition,
- Color.White);
- }
- /// <summary>
- /// Draws Current Selected Player Count to Total Player count
- /// </summary>
- private void DrawPlayerCount()
- {
- SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
- Vector2 position = new Vector2();
- // Draw the ScoreBoard
- spriteBatch.Draw(scoreBoardTexture, shieldPosition,
- Color.White);
- position = scoreBoardPosition;
- position.X = scoreBoardPosition.X -
- Fonts.GearInfoFont.MeasureString((playerIndex + 1).ToString()).X / 2;
- // Draw Current Selected Player Count
- spriteBatch.DrawString(Fonts.GearInfoFont, (playerIndex + 1).ToString(),
- position, Fonts.CountColor);
- position.X = scoreBoardPosition.X - Fonts.GearInfoFont.MeasureString(
- Session.Party.Players.Count.ToString()).X / 2;
- position.Y += 30;
- // Draw Total Player count
- spriteBatch.DrawString(Fonts.GearInfoFont,
- Session.Party.Players.Count.ToString(), position, Fonts.CountColor);
- }
- /// <summary>
- /// Draw Equipment Info of the player selected
- /// </summary>
- /// <param name="selectedPlayer">The selected player</param>
- private void DrawEquipmentInfo(Player selectedPlayer)
- {
- SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
- // Character name
- currentTextPosition = characterNamePosition;
- currentTextPosition.X -=
- Fonts.HeaderFont.MeasureString(selectedPlayer.Name).X / 2;
- spriteBatch.DrawString(Fonts.HeaderFont, selectedPlayer.Name,
- currentTextPosition, Fonts.TitleColor);
- // Class name
- currentTextPosition = classNamePosition;
- currentTextPosition.X -= Fonts.GearInfoFont.MeasureString(
- selectedPlayer.CharacterClass.Name).X / 2;
- spriteBatch.DrawString(Fonts.GearInfoFont,
- selectedPlayer.CharacterClass.Name, currentTextPosition, Color.Black);
- }
- /// <summary>
- /// Draw Base Amount Plus any Modifiers
- /// </summary>
- /// <param name="selectedPlayer">The selected player</param>
- private void DrawModifiers(Player selectedPlayer)
- {
- SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
- currentTextPosition.X = playerTextPosition.X;
- currentTextPosition.Y = playerTextPosition.Y + 150;
- // PO + Modifiers
- spriteBatch.DrawString(Fonts.DescriptionFont, "Physical Offense: " +
- selectedPlayer.CurrentStatistics.PhysicalOffense,
- currentTextPosition, Color.Black);
- // PD + Modifiers
- currentTextPosition.Y += intervalBetweenEachInfo;
- spriteBatch.DrawString(Fonts.DescriptionFont, "Physical Defense: " +
- selectedPlayer.CurrentStatistics.PhysicalDefense,
- currentTextPosition, Color.Black);
- // MO + Modifiers
- currentTextPosition.Y += intervalBetweenEachInfo;
- spriteBatch.DrawString(Fonts.DescriptionFont, "Magical Offense: " +
- selectedPlayer.CurrentStatistics.MagicalOffense,
- currentTextPosition, Color.Black);
- // MD + Modifiers
- currentTextPosition.Y += intervalBetweenEachInfo;
- spriteBatch.DrawString(Fonts.DescriptionFont, "Magical Defense: " +
- selectedPlayer.CurrentStatistics.MagicalDefense,
- currentTextPosition, Color.Black);
- }
- /// <summary>
- /// Draw the equipment statistics
- /// </summary>
- /// <param name="selectedPlayer">The selected Player</param>
- private void DrawEquipmentStatistics(Player selectedPlayer)
- {
- SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
- Vector2 position = weaponPosition;
- Int32Range healthDamageRange = new Int32Range();
- healthDamageRange.Minimum = healthDamageRange.Maximum =
- selectedPlayer.CurrentStatistics.PhysicalOffense;
- Weapon weapon = selectedPlayer.GetEquippedWeapon();
- if (weapon != null)
- {
- weapon.DrawIcon(ScreenManager.SpriteBatch, position);
- healthDamageRange += weapon.TargetDamageRange;
- }
- position = armorPosition;
- Int32Range healthDefenseRange = new Int32Range();
- healthDefenseRange.Minimum = healthDefenseRange.Maximum =
- selectedPlayer.CurrentStatistics.PhysicalDefense;
- Int32Range magicDefenseRange = new Int32Range();
- magicDefenseRange.Minimum = magicDefenseRange.Maximum =
- selectedPlayer.CurrentStatistics.MagicalDefense;
- for (int i = 0; i < (int)4; i++)
- {
- Armor armor = selectedPlayer.GetEquippedArmor((Armor.ArmorSlot)i);
- if (armor != null)
- {
- armor.DrawIcon(ScreenManager.SpriteBatch, position);
- healthDefenseRange += armor.OwnerHealthDefenseRange;
- magicDefenseRange += armor.OwnerMagicDefenseRange;
- }
- position.X += 68;
- }
- position = weaponTextPosition;
- spriteBatch.DrawString(Fonts.DescriptionFont, "Weapon Attack: " + "(" +
- healthDamageRange.Minimum + "," +
- healthDamageRange.Maximum + ")",
- position, Color.Black);
- position.Y += 130;
- spriteBatch.DrawString(Fonts.DescriptionFont, "Weapon Defense: " + "(" +
- healthDefenseRange.Minimum + "," +
- healthDefenseRange.Maximum + ")",
- position, Color.Black);
- position.Y += 30;
- spriteBatch.DrawString(Fonts.DescriptionFont, "Spell Defense: " + "(" +
- magicDefenseRange.Minimum + "," +
- magicDefenseRange.Maximum + ")",
- position, Color.Black);
- }
- #endregion
- }
- }
|