/* * PowerBar.cs * Authors: * 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 Microsoft.Xna.Framework.Graphics; namespace StarJack { class PowerBar:Entity, PlayerBasedButton { PlayerObject mPlayer; #region PlayerBasedButton Members public PlayerObject Player { set { mPlayer = value; } } #endregion Entity mCurBar; Entity mPower; Entity mFrame; TextEntity mText; public TextEntity Text { set { mText = value; } } public override float Depth { get { return base.Depth; } set { base.Depth = value; mText.Depth = Depth + 0.2f; } } public override int X { get { return base.X; } set { base.X = value; CalcPos(); } } public override int Y { get { return base.Y; } set { base.Y = value; CalcPos(); } } public override int Height { get { return base.Height; } set { base.Height = value; CalcPos(); } } public override int Width { get { return base.Width; } set { base.Width = value; CalcPos(); } } public void CalcPos() { mCurBar.X = X; mCurBar.Height = (int)(Height * 0.08f); mCurBar.Width = Width; mFrame.X = X; mFrame.Y = Y - mCurBar.Height; mFrame.Width = Width; mFrame.Height = Height+ mCurBar.Height/2; mFrame.Depth = Room.Depth.UIText; mPower.X = X; mPower.Y = mFrame.Y; mPower.Height = mFrame.Height; mPower.Width = Width; } public void CalcBarPos(){ mCurBar.Y = Y - mCurBar.Height / 2 + (int)(Height * (1 - (mPlayer.Power / (PlayerObject.MAX_POWER + 0.0f)))); if (mCurBar.Y > Height + base.Y) { mCurBar.Y = Height + base.Y; } } public PowerBar(string name) : base(name) { mFrame = new Entity("Frame"); mFrame.Depth = Room.Depth.UIButton; mFrame.TextureName = "BarFrame"; mPower = new Entity("Power"); mPower.Depth = Room.Depth.UIIcon; mPower.TextureName = "EnergyBar"; mCurBar = new Entity("CurBar"); mCurBar.Depth = Room.Depth.UIText; mCurBar.TextureName = "Bar"; } public override void LoadContent(Microsoft.Xna.Framework.Content.ContentManager content) { base.LoadContent(content); mCurBar.LoadContent(content); mPower.LoadContent(content); mFrame.LoadContent(content); } public override void Update(Microsoft.Xna.Framework.GameTime time) { CalcBarPos(); } public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch pSpriteBatch) { mPower.Draw(pSpriteBatch); mCurBar.Draw(pSpriteBatch); mFrame.Draw(pSpriteBatch); } public TextEntity AddText(string text, string fontName, Color textColor, Color textShadow, Button.Orientation or, float space) { TextEntity mText = new TextEntity(text); // mText.Depth = this.Depth + 0.02f; mText.FontName = fontName; mText.Color = textColor; mText.ShadowColor = textShadow; mText.Height = (int)(Height * space); mText.Width = (int)(Width * space); Button.SetOrientation(this, mText, or); return mText; } } }