/*
* GUIPanel.cs
* Authors: Bradley Blankenship, 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 Microsoft.Xna.Framework.Graphics;
namespace tAC_Engine.GUI
{
///
/// Results of a closing panel.
///
public enum PanelResult
{
NONE,
YES,
NO,
OKAY,
CANCEL
}
///
/// Handler for a panel result event
///
/// The object sending the event
/// The result data
public delegate void PanelResultHandler(object source, PanelResult result);
///
/// Represents a panel for the GUI.
///
public class GUIPanel : GUIContainer
{
#region Fields
///
/// The background texture for the panel
///
Texture2D mBackground;
#endregion
#region Properties
///
/// Allows access to the background of the panel.
///
public Texture2D Background
{
get { return mBackground; }
set { mBackground = value; }
}
#endregion
#region Initialization
///
/// Get the basic texture if we do not have one for our background.
///
public override void LoadContent()
{
// If our texture is null
if (Background == null && ParentScreen != null)
{
// Load the basic background texture
Background = ParentScreen.Content.Load(@"Textures\BasicGUIBackground");
}
base.LoadContent();
}
#endregion
#region Draw
///
/// Draw us then the rest of our components.
///
/// The current game time.
public override void Draw(Microsoft.Xna.Framework.GameTime gameTime)
{
// If we're visible
if (Visible)
{
// If we have a background
if (Background != null)
{
// Draw it!
Batch.Draw(Background, Bounds, mAddColor);
}
// The rest are drawn
base.Draw(gameTime);
}
}
#endregion
///
/// Attempts to remove the panel from its parent screen
///
/// The result state.
public void Remove(PanelResult result)
{
if (PanelRemoving != null) PanelRemoving(this, result);
if (ParentScreen != null) ParentScreen.Remove(this);
else throw new System.Exception("Attempted to remove a GUIPanel that has no parent.");
if (PanelRemoved != null) PanelRemoved(this, result);
}
///
/// Occurs just before a panel closes
///
public event PanelResultHandler PanelRemoving;
///
/// Occurs just after a panel closes
///
public event PanelResultHandler PanelRemoved;
}
}