/* * CSMiniGameSelectionPanel.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 the panel that displays the different mini-games that can /// be played. /// class CSMiniGameSelectionPanel : GUIRadioContainer { #region Fields // The array of buttons CSMiniGameButton[] mButtons; // The current mini game MiniGameInfo mMiniGame; #endregion #region Properties /// /// The current mini game selected. /// public MiniGameInfo MiniGame { get { return mMiniGame; } } #endregion #region Constructs /// /// Base constructor. /// public CSMiniGameSelectionPanel() { // Get the mini games MiniGameInfo[] minigames = AssemblyLocator.AllKnownMiniGames.ToArray(); // Get the number of playable ones int playableGames = 0; for (int i = 0; i < minigames.Length; i++) { if (minigames[i].CSPlayable) { playableGames++; } } // Set the number of playable mini games to buttons mButtons = new CSMiniGameButton[playableGames]; // Create all of the buttons and add them for (int i = 0, j = 0; i < minigames.Length && j < mButtons.Length; i++) { // If it's playable if (minigames[i].CSPlayable) { // Create the button mButtons[j] = new CSMiniGameButton(); mButtons[j].MiniGame = minigames[i]; mButtons[j].ToolTipText = minigames[i].DisplayName; // If we have both names if (minigames[i].IconDown != null && minigames[i].IconUp != null) { mButtons[j].ButtonDownName = minigames[i].IconDown; mButtons[j].ButtonUpName = minigames[i].IconUp; } // Add them this.Add(mButtons[j]); // Increment j++; } } } #endregion #region Initialize /// /// Initialize the components and the sizes of them. /// public override void Initialize() { // Base call base.Initialize(); } /// /// Load content for the games. /// public override void LoadContent() { // Base call base.LoadContent(); // Go through each of the mini game buttons foreach (CSMiniGameButton button in mButtons) { } } /// /// Resize the panel. /// public override void Resize() { // Base call base.Resize(); // Set the size and position of the buttons Vector2 position = Position; Vector2 size = new Vector2(Size.X, Size.Y); foreach (CSMiniGameButton button in mButtons) { // Set the size and position button.Size = size; button.Position = position; position.X = button.Bounds.Right; } } #endregion #region Handle Events public event EventHandler MiniGameChanged; public override bool HandleMouseEvent(MouseInputEvent e) { // Return value bool retVal = base.HandleMouseEvent(e); // If the return value is true if (retVal) { // See which button is pressed foreach (CSMiniGameButton button in mButtons) { // If the button is down if (button.State == GUIButton.ButtonState.DOWN) { // Set the current mini game mMiniGame = button.MiniGame; // Invoke Event if (MiniGameChanged != null) MiniGameChanged.Invoke(this, EventArgs.Empty); break; } } } // Return the value return retVal; } #endregion } /// /// Reference a mini-game to let us know it was selected. /// class CSMiniGameButton : GUIButton { #region Fields // Reference to the mini game we can play MiniGameInfo mMiniGame; #endregion #region Properties /// /// Allows access to the internal mini-game. /// public MiniGameInfo MiniGame { get { return mMiniGame; } set { // If it's not null if (value != null) { // Set the values mMiniGame = value; mToolTipText = mMiniGame.DisplayName; } } } #endregion } }