/* * CSMainPanel.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; using Microsoft.Xna.Framework.Graphics; namespace ColonySim.GUI { /// /// Represents the small panel used for /// class CSMainPanel : GUIContainer { #region Enums /// /// The types that are accessible to the GUI and Colony Sim from this /// panel. /// public enum MainTypes { PAUSE_UNPAUSE, MISSIONS, OPTIONS, EXIT } #endregion #region Fields // The button for pausing the game GUIToggleButton mPauseButton = new GUIToggleButton(); // The button for the mini game GUIButton mMiniGameButton = new GUIButton(); // The button for pulling up the options menu GUIToggleButton mOptionsButton = new GUIToggleButton(); // The button for exitting the game GUIButton mExitButton = new GUIButton(); #endregion #region Properties /// /// Returns whether or not the state of the pause button is down or not, /// indicating whether the system should be running or not. /// public bool IsRunning { get { return mPauseButton.State == GUIButton.ButtonState.UP; } } #endregion #region Constructs /// /// Base constructor. /// public CSMainPanel() { // Add all of the components this.Add(mPauseButton); this.Add(mMiniGameButton); this.Add(mOptionsButton); this.Add(mExitButton); } #endregion #region Initialize /// /// Initialize everything. /// public override void Initialize() { // Base call base.Initialize(); // Add event handlers to the three buttons mPauseButton.ButtonToggled += new EventHandler(mPauseButton_ButtonToggled); mMiniGameButton.ButtonPressed += new EventHandler(mMiniGameButton_ButtonToggled); mOptionsButton.ButtonToggled += new EventHandler(mOptionsButton_ButtonPressed); mExitButton.ButtonPressed += new EventHandler(mExitButton_ButtonPressed); // Set the tool tips mPauseButton.ToolTipText = "Pause or Unpause the Game"; mMiniGameButton.ToolTipText = "Play a Mission"; mOptionsButton.ToolTipText = "Open the Colony Sim Options Screen"; mExitButton.ToolTipText = "Exit the Colony and Save"; } /// /// Load the content for the buttons. /// public override void LoadContent() { // Base call base.LoadContent(); // Pause Button mPauseButton.ButtonUp = ParentScreen.Content.Load(@"Textures\GUI\06_pauseButtonUp"); mPauseButton.ButtonDown = ParentScreen.Content.Load(@"Textures\GUI\06_pauseButtonDn"); // Mini Game Button mMiniGameButton.ButtonDown = ParentScreen.Content.Load(@"Textures\GUI\07_miniGameDn"); mMiniGameButton.ButtonUp = ParentScreen.Content.Load(@"Textures\GUI\07_miniGameUp"); // Options Button mOptionsButton.ButtonDown = ParentScreen.Content.Load(@"Textures\GUI\08_optionsDn"); mOptionsButton.ButtonUp = ParentScreen.Content.Load(@"Textures\GUI\08_optionsUp"); // Exit button mExitButton.ButtonDown = ParentScreen.Content.Load(@"Textures\GUI\09_exitButtonDn"); mExitButton.ButtonUp = ParentScreen.Content.Load(@"Textures\GUI\09_exitButtonUp"); // Set the pause button's state to being down initially mPauseButton.State = GUIButton.ButtonState.DOWN; } /// /// Resize the buttons to be the correct size. /// public override void Resize() { // Base call base.Resize(); // Get the size for the buttons Vector2 size = new Vector2(Size.X / 4, Size.Y); // Set everyone's size mPauseButton.Size = size; mMiniGameButton.Size = size; mOptionsButton.Size = size; mExitButton.Size = size; // Set each button's position mPauseButton.Position = Position; mMiniGameButton.Position = new Vector2(mPauseButton.Bounds.Right, mPauseButton.Position.Y); mOptionsButton.Position = new Vector2(mMiniGameButton.Bounds.Right, mMiniGameButton.Position.Y); mExitButton.Position = new Vector2(mOptionsButton.Bounds.Right, mPauseButton.Position.Y); } #endregion #region Behavior /// /// Enables or disables the given main type button. /// /// The type to effect. /// Whether it is enabled or disabled. public void EnableDisableMain(MainTypes pType, bool pEnabled) { // Switch on the type switch (pType) { case MainTypes.EXIT: mExitButton.Enabled = pEnabled; break; case MainTypes.MISSIONS: mMiniGameButton.Enabled = pEnabled; break; case MainTypes.OPTIONS: mOptionsButton.Enabled = pEnabled; break; case MainTypes.PAUSE_UNPAUSE: mPauseButton.Enabled = pEnabled; break; } } #endregion #region Events // Event for handling pause changed public event EventHandler PauseToggle; // Event for the mini game button public event EventHandler MiniGameToggle; // Event for handling the options button being pressed public event EventHandler OptionsPressed; // Event for handling the exit button being pressed public event EventHandler ExitPressed; /// /// Toggle the mini game display. /// void mMiniGameButton_ButtonToggled(object sender, EventArgs e) { // Execute the action if(MiniGameToggle != null) MiniGameToggle.Invoke(this, EventArgs.Empty); } /// /// Handle the pause button being toggled. /// public void mPauseButton_ButtonToggled(object sender, EventArgs e) { // Execute the other event if(PauseToggle != null) PauseToggle.Invoke(mPauseButton, EventArgs.Empty); } /// /// Handle the options button being pressed and send an event to the /// GUI screen to let it know to display the options menu. /// void mOptionsButton_ButtonPressed(object sender, EventArgs e) { // Execute the new event if(OptionsPressed != null) OptionsPressed.Invoke(this, EventArgs.Empty); } /// /// Tell the Colony Sim that it should exit. /// void mExitButton_ButtonPressed(object sender, EventArgs e) { // Execute the new event if(ExitPressed != null) ExitPressed.Invoke(this, EventArgs.Empty); } #endregion } }