/* * CSFactoryPanel.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 ColonySim.Structures; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; namespace ColonySim.GUI { /// /// Represents the panel for selecting Factory structures. /// class CSFactoryPanel : GUIRadioContainer { #region Fields // The array of buttons for the Basic Tubes CSStructureButton[] mButtons = new CSStructureButton[3]; // The current selected structure Structure mCurrentStructure; #endregion #region Properties /// /// Gets the currently available structure to build. /// public Structure CurrentStructure { get { return mCurrentStructure.Clone(); ; } } #endregion #region Constructs /// /// Base constructor /// public CSFactoryPanel() { // Create all of the tube buttons for (int i = 0; i < mButtons.Length; i++) { // Create the button mButtons[i] = new CSStructureButton(); } // Add them all foreach (CSStructureButton button in mButtons) { // Add the buttons this.Add(button); } } #endregion #region Initialize /// /// Initialize all of the components and set their positions and sizes. /// public override void Initialize() { // Base call base.Initialize(); // Create the structures for the buttons Factory m1 = new Factory(ParentScreen.Content, @"Models\Industrial Plant_JPx", null); m1.BuildRadius = 1; m1.FootPrintSize = new Vector2(1, 1); m1.Name = "Factory 1"; // Create 2 more Factory m2 = m1.Clone() as Factory; m2.Name = "Factory 2"; m2.ColorToAdd = Color.Green; m2.BuildRadius = 2; Factory m3 = m1.Clone() as Factory; m3.Name = "Factory 3"; m3.ColorToAdd = Color.Red; m3.BuildRadius = 3; // Set the structures for the buttons mButtons[0].Structure = m1; mButtons[1].Structure = m2; mButtons[2].Structure = m3; } /// /// Resize the internals of the panel. /// public override void Resize() { // Base call base.Resize(); // Set the size of the buttons and positions Vector2 position = Position; foreach (CSStructureButton button in mButtons) { // Set the size button.Size = new Vector2(Size.X / 4, Size.Y); button.Position = position; position.X = button.Bounds.Right; } } /// /// Loads the content of the buttons. /// public override void LoadContent() { // Base call base.LoadContent(); // Set the textures for the tube buttons //// Horizontal //mButtons[0].ButtonDown = mParentScreen.Content.Load(@"Textures\GUI\TubePXDown"); //mButtons[0].ButtonUp = mParentScreen.Content.Load(@"Textures\GUI\TubePXUp"); //// Vertical //mButtons[1].ButtonDown = mParentScreen.Content.Load(@"Textures\GUI\TubePYDown"); //mButtons[1].ButtonUp = mParentScreen.Content.Load(@"Textures\GUI\TubePYUp"); //// Horizontal //mButtons[2].ButtonDown = mParentScreen.Content.Load(@"Textures\GUI\TubeNXDown"); //mButtons[2].ButtonUp = mParentScreen.Content.Load(@"Textures\GUI\TubeNXUp"); } #endregion #region Events public event EventHandler FactoryChanged; public override bool HandleMouseEvent(Util.MouseInputEvent e) { // Get the retVal bool retVal = base.HandleMouseEvent(e); // Only if we received the event if (retVal) { // Set the current structure based on the pressed button foreach (CSStructureButton button in mButtons) { // If the button is down if (button.State == GUIButton.ButtonState.DOWN) { // Set the current structure mCurrentStructure = button.Structure; //Invoke Event if (FactoryChanged != null) FactoryChanged.Invoke(this, EventArgs.Empty); break; } } } // Return return retVal; } #endregion } }