/* * CSSelectionPanel.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 ColonySim.GUI { /// /// Represents the panel the user uses to select what they want to /// Build, or to destroy or select Structures in the Colony. /// class CSSelectionPanel : GUIRadioContainer { #region Enums /// /// The current state of the selection panel. Also represents the /// available types of the selection panel. /// public enum States { TRANSPORT, RESIDENTIAL, COMMERCIAL, SELECTION, DELETION } #endregion #region Fields // The current state States mCurrentState = States.SELECTION; // The transport button GUIButton mTransportButton = new GUIButton(); // The mining button GUIButton mResidentialButton = new GUIButton(); // The factory button GUIButton mCommercialButton = new GUIButton(); // The selection button GUIButton mSelectionButton = new GUIButton(); // The destroy button GUIButton mDestroyButton = new GUIButton(); #endregion #region Properties /// /// Returns the State that has been currently selected within the GUI. /// public States State { get { return mCurrentState; } } #endregion #region Constructs /// /// Base constructor. /// public CSSelectionPanel() { // Add them all this.Add(mTransportButton); this.Add(mResidentialButton); this.Add(mCommercialButton); this.Add(mSelectionButton); this.Add(mDestroyButton); } #endregion #region Initialize /// /// Initialize the components. /// public override void Initialize() { // Base call base.Initialize(); // Intialize tool tips mTransportButton.ToolTipText = "Build Resource Tubes and Colony Roads"; mResidentialButton.ToolTipText = "Build Residential and Entertainment Structures"; mCommercialButton.ToolTipText = "Build Resource and Commercial Structures"; mSelectionButton.ToolTipText = "Select Structures in the Colony"; mDestroyButton.ToolTipText = "Destroy Structures in the Colony"; // Create the handlers mTransportButton.ButtonPressed += new EventHandler(mTransportButton_ButtonPressed); mResidentialButton.ButtonPressed += new EventHandler(mResidentialButton_ButtonPressed); mCommercialButton.ButtonPressed += new EventHandler(mCommercialButton_ButtonPressed); mSelectionButton.ButtonPressed += new EventHandler(mSelectionButton_ButtonPressed); mDestroyButton.ButtonPressed += new EventHandler(mDestroyButton_ButtonPressed); } /// /// Resize the contents of the Panel. /// public override void Resize() { // Base call base.Resize(); // Set the size of all of the buttons mTransportButton.Size = new Microsoft.Xna.Framework.Vector2(Size.X / 5, Size.Y); mResidentialButton.Size = mTransportButton.Size; mCommercialButton.Size = mTransportButton.Size; mSelectionButton.Size = mTransportButton.Size; mDestroyButton.Size = mTransportButton.Size; // Set their positions Microsoft.Xna.Framework.Vector2 position = Position; mTransportButton.Position = position; mResidentialButton.Position = new Vector2(mTransportButton.Bounds.Right, position.Y); mCommercialButton.Position = new Vector2(mResidentialButton.Bounds.Right, position.Y); mSelectionButton.Position = new Vector2(mCommercialButton.Bounds.Right, position.Y); mDestroyButton.Position = new Vector2(mSelectionButton.Bounds.Right, position.Y); mToolTipText = "Blah blah"; } /// /// Load content for all of the buttons /// public override void LoadContent() { // Base call base.LoadContent(); // Get the tool tip font SpriteFont font = ParentScreen.Content.Load(@"Fonts\ToolTipFont"); // Now set the content of the buttons we can // Transport mTransportButton.Font = font; mTransportButton.ButtonDown = ParentScreen.Content.Load(@"Textures\GUI\01_transportDn"); mTransportButton.ButtonUp = ParentScreen.Content.Load(@"Textures\GUI\01_transportUp"); // Residential mResidentialButton.ButtonDown = ParentScreen.Content.Load(@"Textures\GUI\02_residentialDn"); mResidentialButton.ButtonUp = ParentScreen.Content.Load(@"Textures\GUI\02_residentialUp"); // Commercial mCommercialButton.ButtonDown = ParentScreen.Content.Load(@"Textures\GUI\03_commercialDn"); mCommercialButton.ButtonUp = ParentScreen.Content.Load(@"Textures\GUI\03_commercialUp"); // Selections mSelectionButton.ButtonDown = ParentScreen.Content.Load(@"Textures\GUI\04_selectionDn"); mSelectionButton.ButtonUp = ParentScreen.Content.Load(@"Textures\GUI\04_selectionUp"); mSelectionButton.Font = font; // Deletions mDestroyButton.ButtonDown = ParentScreen.Content.Load(@"Textures\GUI\05_deletionDn"); mDestroyButton.ButtonUp = ParentScreen.Content.Load(@"Textures\GUI\05_deletionUp"); mDestroyButton.Font = font; } #endregion #region Behavior /// /// Enable or disable the given value in the selection panel. /// /// The state button to enable. /// Whether it is enabled or disabled. public void EnableDisableSelection(States pType, bool pEnabled) { // Switch on the type switch (pType) { case States.COMMERCIAL: mCommercialButton.Enabled = pEnabled; break; case States.DELETION: mDestroyButton.Enabled = pEnabled; break; case States.RESIDENTIAL: mResidentialButton.Enabled = pEnabled; break; case States.SELECTION: mSelectionButton.Enabled = pEnabled; break; case States.TRANSPORT: mTransportButton.Enabled = pEnabled; break; } } #endregion #region Events public event EventHandler StateChanged; void mDestroyButton_ButtonPressed(object sender, EventArgs e) { mCurrentState = States.DELETION; if (StateChanged != null) StateChanged.Invoke(this, EventArgs.Empty); } void mSelectionButton_ButtonPressed(object sender, EventArgs e) { mCurrentState = States.SELECTION; if (StateChanged != null) StateChanged.Invoke(this, EventArgs.Empty); } void mCommercialButton_ButtonPressed(object sender, EventArgs e) { mCurrentState = States.COMMERCIAL; if (StateChanged != null) StateChanged.Invoke(this, EventArgs.Empty); } void mResidentialButton_ButtonPressed(object sender, EventArgs e) { mCurrentState = States.RESIDENTIAL; if (StateChanged != null) StateChanged.Invoke(this, EventArgs.Empty); } void mTransportButton_ButtonPressed(object sender, EventArgs e) { mCurrentState = States.TRANSPORT; if (StateChanged != null) StateChanged.Invoke(this, EventArgs.Empty); } #endregion } }