123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- #region File Description
- //-----------------------------------------------------------------------------
- // EquipmentScreen.cs
- //
- // Microsoft XNA Community Game Platform
- // Copyright (C) Microsoft Corporation. All rights reserved.
- //-----------------------------------------------------------------------------
- #endregion
- #region Using Statements
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Content;
- using RolePlayingGameData;
- #endregion
- namespace RolePlaying
- {
- /// <summary>
- /// Lists the player's equipped gear, and allows the user to unequip them.
- /// </summary>
- class EquipmentScreen : ListScreen<Equipment>
- {
- #region Columns
- protected string nameColumnText = "Name";
- private const int nameColumnInterval = 80;
- protected string powerColumnText = "Power (min, max)";
- private const int powerColumnInterval = 270;
- protected string slotColumnText = "Slot";
- private const int slotColumnInterval = 400;
- #endregion
- #region Data Access
- /// <summary>
- /// The FightingCharacter object whose equipment is displayed.
- /// </summary>
- private FightingCharacter fightingCharacter;
- /// <summary>
- /// Get the list that this screen displays.
- /// </summary>
- public override ReadOnlyCollection<Equipment> GetDataList()
- {
- return fightingCharacter.EquippedEquipment.AsReadOnly();
- }
- #endregion
- #region Initialization
- /// <summary>
- /// Creates a new EquipmentScreen object for the given player.
- /// </summary>
- public EquipmentScreen(FightingCharacter fightingCharacter)
- : base()
- {
- // check the parameter
- if (fightingCharacter == null)
- {
- throw new ArgumentNullException("fightingCharacter");
- }
- this.fightingCharacter = fightingCharacter;
- // sort the player's equipment
- this.fightingCharacter.EquippedEquipment.Sort(
- delegate(Equipment equipment1, Equipment equipment2)
- {
- // handle null values
- if (equipment1 == null)
- {
- return (equipment2 == null ? 0 : 1);
- }
- else if (equipment2 == null)
- {
- return -1;
- }
- // handle weapons - they're always first in the list
- if (equipment1 is Weapon)
- {
- return (equipment2 is Weapon ?
- equipment1.Name.CompareTo(equipment2.Name) : -1);
- }
- else if (equipment2 is Weapon)
- {
- return 1;
- }
- // compare armor slots
- Armor armor1 = equipment1 as Armor;
- Armor armor2 = equipment2 as Armor;
- if ((armor1 != null) && (armor2 != null))
- {
- return armor1.Slot.CompareTo(armor2.Slot);
- }
- return 0;
- });
- // configure the menu text
- titleText = "Equipped Gear";
- selectButtonText = String.Empty;
- backButtonText = "Back";
- xButtonText = "Unequip";
- yButtonText = String.Empty;
- leftTriggerText = String.Empty;
- rightTriggerText = String.Empty;
- }
- #endregion
- #region Input Handling
- /// <summary>
- /// Respond to the triggering of the X button (and related key).
- /// </summary>
- protected override void ButtonXPressed(Equipment entry)
- {
- // remove the equipment from the player's equipped list
- fightingCharacter.Unequip(entry);
- // add the equipment back to the party's inventory
- Session.Party.AddToInventory(entry, 1);
- }
- #endregion
- #region Drawing
- /// <summary>
- /// Draw the equipment at the given position in the list.
- /// </summary>
- /// <param name="contentEntry">The equipment to draw.</param>
- /// <param name="position">The position to draw the entry at.</param>
- /// <param name="isSelected">If true, this item is selected.</param>
- protected override void DrawEntry(Equipment entry, Vector2 position,
- bool isSelected)
- {
- // check the parameter
- if (entry == null)
- {
- throw new ArgumentNullException("entry");
- }
- SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
- Vector2 drawPosition = position;
- // draw the icon
- spriteBatch.Draw(entry.IconTexture, drawPosition + iconOffset, Color.White);
- // draw the name
- Color color = isSelected ? Fonts.HighlightColor : Fonts.DisplayColor;
- drawPosition.Y += listLineSpacing / 4;
- drawPosition.X += nameColumnInterval;
- spriteBatch.DrawString(Fonts.GearInfoFont, entry.Name, drawPosition, color);
- // draw the power
- drawPosition.X += powerColumnInterval;
- string powerText = entry.GetPowerText();
- Vector2 powerTextSize = Fonts.GearInfoFont.MeasureString(powerText);
- Vector2 powerPosition = drawPosition;
- powerPosition.Y -= (float)Math.Ceiling((powerTextSize.Y - 30f) / 2);
- spriteBatch.DrawString(Fonts.GearInfoFont, powerText,
- powerPosition, color);
- // draw the slot
- drawPosition.X += slotColumnInterval;
- if (entry is Weapon)
- {
- spriteBatch.DrawString(Fonts.GearInfoFont, "Weapon",
- drawPosition, color);
- }
- else if (entry is Armor)
- {
- Armor armor = entry as Armor;
- spriteBatch.DrawString(Fonts.GearInfoFont, armor.Slot.ToString(),
- drawPosition, color);
- }
- // turn on or off the unequip button
- if (isSelected)
- {
- xButtonText = "Unequip";
- }
- }
- /// <summary>
- /// Draw the description of the selected item.
- /// </summary>
- protected override void DrawSelectedDescription(Equipment entry)
- {
- // check the parameter
- if (entry == null)
- {
- throw new ArgumentNullException("entry");
- }
- SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
- Vector2 position = descriptionTextPosition;
- // draw the description
- // -- it's up to the content owner to fit the description
- string text = entry.Description;
- if (!String.IsNullOrEmpty(text))
- {
- spriteBatch.DrawString(Fonts.DescriptionFont, text, position,
- Fonts.DescriptionColor);
- position.Y += Fonts.DescriptionFont.LineSpacing;
- }
- // draw the modifiers
- text = entry.OwnerBuffStatistics.GetModifierString();
- if (!String.IsNullOrEmpty(text))
- {
- spriteBatch.DrawString(Fonts.DescriptionFont, text, position,
- Fonts.DescriptionColor);
- position.Y += Fonts.DescriptionFont.LineSpacing;
- }
- // draw the restrictions
- text = entry.GetRestrictionsText();
- if (!String.IsNullOrEmpty(text))
- {
- spriteBatch.DrawString(Fonts.DescriptionFont, text, position,
- Fonts.DescriptionColor);
- position.Y += Fonts.DescriptionFont.LineSpacing;
- }
- }
- /// <summary>
- /// Draw the column headers above the list.
- /// </summary>
- protected override void DrawColumnHeaders()
- {
- SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
- Vector2 position = listEntryStartPosition;
- position.X += nameColumnInterval;
- if (!String.IsNullOrEmpty(nameColumnText))
- {
- spriteBatch.DrawString(Fonts.CaptionFont, nameColumnText, position,
- Fonts.CaptionColor);
- }
- position.X += powerColumnInterval;
- if (!String.IsNullOrEmpty(powerColumnText))
- {
- spriteBatch.DrawString(Fonts.CaptionFont, powerColumnText, position,
- Fonts.CaptionColor);
- }
- position.X += slotColumnInterval;
- if (!String.IsNullOrEmpty(slotColumnText))
- {
- spriteBatch.DrawString(Fonts.CaptionFont, slotColumnText, position,
- Fonts.CaptionColor);
- }
- }
- #endregion
- }
- }
|