/*
* EntityProgressBar.cs
* Authors: Mike DeMauro
* Copyright (c) 2007-2008 Cornell University
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
using System;
using System.Collections.Generic;
using System.Text;
using tAC_Engine.Graphics.Entities;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace StellarProspector
{
///
/// Keeps track of progress in Integer form in a range from 0 to MaxProgress.
/// Graphically, this progress bar is intended for a 180 degree arc, rotating as progress increases.
///
internal class EntityProgressBar : EntitySprite
{
#region Fields
///
/// The viewport that is used in the rendering of this object
///
protected Viewport myViewport;
///
/// A reference to the old viewport so that it can be restored after drawing
///
protected Viewport gameViewport;
///
/// The current value of progress.
///
protected int mProgress;
///
/// The maximum progress cap.
///
protected int mMaxProgress;
#endregion
#region Properties
///
/// Gets/Sets the current value of progress.
///
public int Progress
{
get { return mProgress; }
set
{
if (value < 0)
{
mProgress = 0;
}
else if (value > mMaxProgress)
{
mProgress = mMaxProgress;
}
else
{
mProgress = value;
}
}
}
///
/// Gets/Sets the maximum progress cap.
///
public int MaxProgress
{
get { return mMaxProgress; }
set { mMaxProgress = value; }
}
///
/// Gets/Sets the position of the sprite on the screen. Defaults to Vecter2.Zero
///
public new Vector2 Position
{
get { return new Vector2(m_Destination.X, m_Destination.Y); }
set
{
myViewport.X = (int)value.X - (int)m_RotationOrigin.X;
myViewport.Y = (int)value.Y - (int)m_RotationOrigin.Y;
}
}
///
/// Gets/Sets the origin of rotation of the sprite. Default is Upper left (Vector.Zero).
///
public new Vector2 RotationOrigin
{
get { return m_RotationOrigin; }
set
{
m_RotationOrigin = value;
m_Destination.X = (int)value.X;
m_Destination.Y = (int)value.Y;
}
}
#endregion
#region Methods
///
/// Creates a new EntityProgressBar
///
/// The content manager to load in associated content
/// Name of the texture to represent the progress bar
public EntityProgressBar(ContentManager content, string textureName)
: base(content, textureName) { }
///
/// Loads in content dependent values
///
protected override void LoadContent()
{
base.LoadContent();
myViewport = new Viewport();
myViewport.Width = Width;
myViewport.Height = Height;
myViewport.MinDepth = GraphicsDevice.Viewport.MinDepth;
myViewport.MaxDepth = GraphicsDevice.Viewport.MaxDepth;
gameViewport = GraphicsDevice.Viewport;
}
///
/// Updates progress bar
///
/// The time that has passed in-game
public override void Update(Microsoft.Xna.Framework.GameTime gameTime)
{
m_Rotation = (1f - ((float)mProgress / mMaxProgress)) * MathHelper.Pi;
base.Update(gameTime);
}
///
/// Renders the progress bar
///
/// The time that has passed in-game
public override void Draw(Microsoft.Xna.Framework.GameTime gameTime)
{
GraphicsDevice.Viewport = myViewport;
base.Draw(gameTime);
GraphicsDevice.Viewport = gameViewport;
}
#endregion
}
}