//--------------------------------------------------------------------------------------------------------------------------------------------------- // // Copyright (C)2007 DarkWynter Studios. All rights reserved. // //--------------------------------------------------------------------------------------------------------------------------------------------------- // {License Information: Creative Commons} //--------------------------------------------------------------------------------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Text; using System.Collections; using System.Diagnostics; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Storage; using System.ComponentModel; using System.Xml; using DWGame.Globals; using DW.Stream; namespace DW.UserInterface_2D { /// /// Base class for all types. /// public class ScreenObject { /// /// Text string drawn to HUD. /// public string text = ""; public string _text { get { return text; } set { text = value; } } /// /// Position of HUD element. /// public Vector2 position = new Vector2(); public Vector2 _position { get { return position; } set { position = value; } } /// /// Width of HUD element. /// public int width; public int _width { get { return width; } set { width = value; } } /// /// Height of HUD element. /// public int height; public int _height { get { return height; } set { height = value; } } /// /// Color of text element. /// public Color color; public Color _color { get { return color; } set { color = value; } } /// /// Type of HUD element. /// public DisplayType type = DisplayType.BASE; public DisplayType _type { get { return type; } set { type = value; } } /// /// Visibility of HUD element. /// public bool visible = true; public bool _visible { get { return visible; } set { visible = value; } } /// /// Time limit for the text display /// public float timeLimit; public float _timeLimit { get { return timeLimit; } set { timeLimit = value; } } /// /// Stopwatch to regulate time limit /// public Stopwatch stopWatch = new Stopwatch(); public Stopwatch _stopWatch { get { return stopWatch; } set { stopWatch = value; } } /// /// Rotation of HUD element. /// public float rotation; public float _rotation { get { return rotation; } set { rotation = value; } } public static Color GetColor(XmlNode node) { return new Color( byte.Parse(node.Attributes["colorR"].Value), byte.Parse(node.Attributes["colorG"].Value), byte.Parse(node.Attributes["colorB"].Value), byte.Parse(node.Attributes["colorA"].Value) ); } }; #region Children of ScreenObject /// /// Indicates what type of Heads Up Display element this is. /// public enum DisplayType { /// /// A string of text. /// TEXT, /// /// An image. /// IMAGE, /// /// Default. /// BASE }; /// /// Used to display Text. /// public class TextDisplay : ScreenObject { string mName; /// /// Sets the image and defaults the source to the entire image /// public string name { get { return mName; } set { mName = value; } } /// /// Text display constructor. /// public TextDisplay() { type = DisplayType.TEXT; } /// /// Text display constructor. /// public TextDisplay(XmlNode node) { type = DisplayType.TEXT; name = node.Attributes["nameID"].Value; position = new Vector2(int.Parse(node.Attributes["posX"].Value), int.Parse(node.Attributes["posY"].Value)); visible = bool.Parse(node.Attributes["toDraw"].Value); color = GetColor(node); text = node.Attributes["text"].Value; } } /// /// Used to display Images. /// public class ImageDisplay : ScreenObject { /// /// Image drawn to HUD. /// Edit by Drew: I changed this so that there is a "Source" property in the image... /// this is used for my health bar. Getters and setters change eachother appropriately. /// References that use Width*Scale in existing code will just be left alone. /// string mName; /// /// Sets the image and defaults the source to the entire image /// public string name { get { return mName; } set { mName = value; } } Texture2D mImage; /// /// Sets the image and defaults the source to the entire image /// public Texture2D image { get { return mImage; } set { mImage = value; Source = new Rectangle(0, 0, image.Width, image.Height); } } /// /// X scale of image. /// public float xScale; /// /// Y scale of image. /// public float yScale; /// /// Contains the size of the image (source/scale) /// This is only different from Texture Dimension * scale when /// the source is changed... i.e. only on my health bars /// public Rectangle Size; Rectangle mSource; /// /// Changes the Source Rectangle /// public Rectangle Source { get { return mSource; } set { mSource = value; Size = new Rectangle(0, 0, (int)(mSource.Width * xScale), (int)(mSource.Height * yScale)); } } /// /// Image display constructor. /// Scale defaults to 1. /// public ImageDisplay() { xScale = 1.0f; yScale = 1.0f; type = DisplayType.IMAGE; } /// /// Image display constructor. /// Scale defaults to 1. /// public ImageDisplay(XmlNode node) { xScale = 1.0f; yScale = 1.0f; type = DisplayType.IMAGE; name = node.Attributes["nameID"].Value; position = new Vector2(int.Parse(node.Attributes["posX"].Value), int.Parse(node.Attributes["posY"].Value)); visible = bool.Parse(node.Attributes["toDraw"].Value); color = GetColor(node); image = Renderer.content.Load(node.Attributes["texturePath"].Value); } } /// /// Used to display image sequences /// public class ImageSpinner_old : ScreenObject { /// /// Array of images /// public ImageDisplay[] images; /// /// Index of active image /// public int activeIndex; /// /// Constructor /// /// Size of Image Display public ImageSpinner_old(int size) { this.activeIndex = 0; this.images = new ImageDisplay[size]; } /// /// Add an image to our array /// /// Image /// Location public void addImage(ImageDisplay val, int slot) { images[slot] = val; } /// /// Iterate to next image /// public void next() { if (this.images.Length <= this.activeIndex + 1) { this.activeIndex = 0; } else { this.activeIndex++; } } /// /// Iterate to previous image /// public void prev() { if (this.activeIndex == 0) { this.activeIndex = this.images.Length - 1; } else { this.activeIndex--; } } } #endregion }