/*
* CSMiniGamePopUpPanel.cs
* Authors: Bradley R. Blankenship
* 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.GUI;
using Util;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace ColonySim.GUI
{
///
/// Represents a panel which is used for displaying the currently selected
/// mini game to play.
///
class CSMiniGamePopUpPanel : GUIPanel
{
#region Fields
// The background for the label for the mini game
GUILabel mMiniGameIcon = new GUILabel();
// The button to accept playing a mini game
GUIButton mPlayButton = new GUIButton();
// The button to deny playing a mini game
GUIButton mDenyButton = new GUIButton();
// The current mini game data
MiniGameInfo mCurrentMiniGame = null;
// Whether this was a generated mini game event or not
bool mIsGenerated = false;
// Whether the game was played or not
bool mWasPlayed = false;
#endregion
#region Properties
///
/// Allows the user to get or set the current mini game.
///
public MiniGameInfo CurrentMiniGame
{
get { return mCurrentMiniGame; }
set { mCurrentMiniGame = value; ResetMiniGameContent(); }
}
///
/// Allows the user to get or set whether the current mini game was
/// generated randomly or if the user selected the mini game
/// themselves.
///
public bool IsGenerated
{
get { return mIsGenerated; }
set { mIsGenerated = value; }
}
///
/// Allows access to whether the user played this game or not. If the
/// user did, then we need some way of getting back the rewards from
/// the mini-game.
///
public bool WasPlayed
{
get { return mWasPlayed; }
set { mWasPlayed = false; }
}
#endregion
#region Constructs
///
/// Base Constructor
///
public CSMiniGamePopUpPanel()
{
// Add the components
this.Add(mMiniGameIcon);
this.Add(mPlayButton);
this.Add(mDenyButton);
}
#endregion
#region Initialize
///
/// Base initialize call.
///
public override void Initialize()
{
// Base call
base.Initialize();
// Add two handlers, one for each of the mini game selections.
mPlayButton.ButtonPressed += new EventHandler(mPlayButton_ButtonPressed);
mDenyButton.ButtonPressed += new EventHandler(mDenyButton_ButtonPressed);
}
#region Internal Events
///
/// The denied button has been pressed.
///
void mDenyButton_ButtonPressed(object sender, EventArgs e)
{
// Invoke the deny event
DenyMiniGame.Invoke(this, EventArgs.Empty);
}
///
/// The play button has been pressed.
///
void mPlayButton_ButtonPressed(object sender, EventArgs e)
{
// Invoke the play event
PlayMiniGame.Invoke(this, EventArgs.Empty);
}
#endregion
///
/// Load content for the components.
///
public override void LoadContent()
{
// Base call
base.LoadContent();
// Set the background of the label
mMiniGameIcon.Background = ParentScreen.Content.Load(@"Textures\singlePixel");
// Load our background
this.Background = ParentScreen.Content.Load(@"Textures\GUI\ToolTipBackground");
// Get the font for the buttons
SpriteFont font = ParentScreen.Content.Load(@"Fonts\Courier New");
// Set the font
mPlayButton.Font = font;
mDenyButton.Font = font;
// Set the text for the buttons
mPlayButton.Text = "Play";
mDenyButton.Text = "Cancel";
// Set the text color
mPlayButton.TextColor = Color.Black;
mDenyButton.TextColor = Color.Black;
}
///
/// Resize the components for this panel.
///
public override void Resize()
{
// Base call
base.Resize();
// Set the size of the label for the mini game
mMiniGameIcon.Size = new Vector2(Size.Y - 6, Size.Y - 6);
mMiniGameIcon.Position = new Vector2(Bounds.X + 6, Bounds.Y + 3);
// Set the size for each of the buttons
Vector2 buttonSize = new Vector2(Size.X * 1 / 3 - 6, Size.Y - 6);
mPlayButton.Size = buttonSize;
mDenyButton.Size = buttonSize;
// Set the position of the two other buttons
mPlayButton.Position = new Vector2(Bounds.Right - 2 * buttonSize.X - 12, Bounds.Y + 3);
mDenyButton.Position = new Vector2(Bounds.Right - buttonSize.X - 6, Bounds.Y + 3);
}
///
/// Resets content affected by the mini game.
///
public void ResetMiniGameContent()
{
// If the mini game is not null and the up icon isn't null
if (mCurrentMiniGame != null && mCurrentMiniGame.IconUp != null)
{
// Load the icon as our icon for the mini game
mMiniGameIcon.Background = ParentScreen.Content.Load(mCurrentMiniGame.IconUp);
mMiniGameIcon.ToolTipText = mCurrentMiniGame.DisplayName;
// Set the button text
mPlayButton.ToolTipText = "Play " + mCurrentMiniGame.DisplayName;
mDenyButton.ToolTipText = "Cancel Playing " + mCurrentMiniGame.DisplayName;
}
else if(mCurrentMiniGame != null)
{
// Set the background of the label
mMiniGameIcon.Background = ParentScreen.Content.Load(@"Textures\singlePixel");
mMiniGameIcon.ToolTipText = mCurrentMiniGame.DisplayName;
// Set the button text
mPlayButton.ToolTipText = "Play " + mCurrentMiniGame.DisplayName;
mDenyButton.ToolTipText = "Cancel Playing " + mCurrentMiniGame.DisplayName;
}
}
#endregion
#region Events
// Event which is handled when the player wants to play the selected minigame
public event EventHandler PlayMiniGame;
// Event which is handled when the player wants to not play the selected minigame
public event EventHandler DenyMiniGame;
#endregion
}
}