/*
* MiniGameScoreScreen.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 Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
namespace tAC_Engine.GUI
{
///
/// A special score screen for displaying scores after the mini game has
/// been played.
///
public class MiniGameScoreScreen : GUIScreen
{
#region Fields
// The label for the title
GUILabel mTitleLabel = new GUILabel();
// The labels for the score headings
GUILabel[] mScoreHeadings;
// The labels for the score values
GUILabel[] mScoreValues;
// The exit button
GUIButton mExitButton = new GUIButton();
// The font for our text
SpriteFont mFont;
// The color for our font
Color mFontColor;
// The background for our screen
Texture2D mBackground;
#endregion
#region Properties
public SpriteFont Font
{
get { return mFont; }
set { mFont = value; }
}
public Color FontColor
{
get { return mFontColor; }
set { mFontColor = value; }
}
public Texture2D Background
{
get { return mBackground; }
set { mBackground = value; }
}
#endregion
#region Constructs
///
/// Constructor for the score screen.
///
public MiniGameScoreScreen()
{
}
#endregion
#region Content
///
/// Load content for the game.
///
protected override void LoadContent()
{
// Base call
base.LoadContent();
// Load the base font
mFont = Content.Load(@"Fonts\dialogfont");
// Set the font color
mFontColor = Color.White;
// Load the background
mBackground = Content.Load(@"Textures\ScoreSummaryBackground");
}
#endregion
#region Behavior
///
/// Sets the display scores for the mini game score screen.
///
///
///
public void DisplayScores(string pTitle, Dictionary pScores)
{
// Remove all of the old elements
this.Components.Clear();
// Create the new button
mExitButton = new GUIButton();
// Set the text
mExitButton.Text = "Exit";
// Add it
this.Add(mExitButton);
// Set the font and color for the button
mExitButton.Font = mFont;
mExitButton.TextColor = Color.Black;
mExitButton.ButtonReleased += new EventHandler(mExitButton_ButtonReleased);
// Create the new title label
mTitleLabel = new GUILabel();
// Set the title label's values
mTitleLabel.Text = pTitle;
// Re-add the top label to the components
this.Add(mTitleLabel);
// Set the font and color for the label
mTitleLabel.Font = mFont;
mTitleLabel.TextColor = mFontColor;
mTitleLabel.Background = null;
// Set the and scores to the dictionary values
mScoreHeadings = new GUILabel[pScores.Count];
mScoreValues = new GUILabel[pScores.Count];
// Indexed counter to use
int counter = 0;
// Set the text for the labels
foreach (KeyValuePair pair in pScores)
{
// Create the label
mScoreHeadings[counter] = new GUILabel();
mScoreValues[counter] = new GUILabel();
// Add the components
this.Add(mScoreHeadings[counter]);
this.Add(mScoreValues[counter]);
// Get rid of the backgrounds
mScoreHeadings[counter].Background = null;
mScoreValues[counter].Background = null;
// Set the value for the pairs
mScoreHeadings[counter].Text = pair.Key;
mScoreValues[counter].Text = pair.Value;
// Set the font for the pairs
mScoreHeadings[counter].Font = mFont;
mScoreValues[counter].Font = mFont;
// Set the text color
mScoreHeadings[counter].TextColor = mFontColor;
mScoreValues[counter].TextColor = mFontColor;
// Increment the counter
counter++;
}
// Unhide the mouse
this.IsMouseVisible = true;
// Resize the elements
Resize();
}
void mExitButton_ButtonReleased(object sender, EventArgs e)
{
// hide the mouse
this.IsMouseVisible = false;
// Dispose of the screens
Done();
Done();
Done();
}
///
/// Resizes the elements of the score screen.
///
public void Resize()
{
// Set the top element to take the majority top of the viewport
mTitleLabel.Size = mTitleLabel.Font.MeasureString(mTitleLabel.Text);
mTitleLabel.Position = new Vector2((this.GraphicsDevice.Viewport.Width - mTitleLabel.Size.X) / 2,
this.GraphicsDevice.Viewport.Height / 10);
// Now get the position for each of the next two labels going down
Vector2 position = new Vector2(this.GraphicsDevice.Viewport.Width / 7 + 6,
mTitleLabel.Bounds.Bottom + this.GraphicsDevice.Viewport.Height / 6);
// Go through the labels and do this right
for (int counter = 0; counter < mScoreHeadings.Length; counter++)
{
// Set the heading position and size
mScoreHeadings[counter].Size = mFont.MeasureString(mScoreHeadings[counter].Text);
mScoreHeadings[counter].Position = position;
// Set the value position and size
mScoreValues[counter].Size = mFont.MeasureString(mScoreValues[counter].Text);
mScoreValues[counter].Position = new Vector2(this.GraphicsDevice.Viewport.Width * 5 / 6 -
mScoreValues[counter].Size.X - 6, position.Y);
// Update the position
position.Y += mScoreHeadings[counter].Size.Y;
}
// Set the exit button's position
mExitButton.Size = new Vector2(this.GraphicsDevice.Viewport.Width / 8, 36);
mExitButton.Position = new Vector2(this.GraphicsDevice.Viewport.Width - 2 * mExitButton.Size.X,
this.GraphicsDevice.Viewport.Height - mExitButton.Size.Y - 6);
}
#endregion
#region Draw
///
/// Draws the GUI window.
///
/// Draw the window.
public override void Draw(GameTime gameTime)
{
// Begin drawing
Batch.Begin();
// Draw the background image
Batch.Draw(
mBackground,
new Rectangle(this.GraphicsDevice.Viewport.Y, this.GraphicsDevice.Viewport.X,
this.GraphicsDevice.Viewport.Width, this.GraphicsDevice.Viewport.Height),
Color.White);
// End drawing
Batch.End();
// Base call
base.Draw(gameTime);
}
#endregion
}
}