/* * CSMiningPanel.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 Mining structures. /// class CSMiningPanel : 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 CSMiningPanel() { // 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 MiningPlant m1 = new MiningPlant(ParentScreen.Content, @"Models\Mall", null); m1.BuildRadius = 0; m1.FootPrintSize = new Vector2(1, 1); m1.Name = "Mining Plant 1"; // Create 2 more MiningPlant m2 = m1.Clone() as MiningPlant; m2.Name = "Mining Plant 2"; m2.ColorToAdd = Color.Green; MiningPlant m3 = m1.Clone() as MiningPlant; m3.Name = "Mining Plant 3"; m3.ColorToAdd = Color.Red; // Set the structures for the buttons mButtons[0].Structure = m1; mButtons[1].Structure = m2; mButtons[2].Structure = m3; } #endregion #region Modifiers /// /// 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; } } #endregion #region Events public event EventHandler MiningChanged; 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 (MiningChanged != null) MiningChanged.Invoke(this, EventArgs.Empty); break; } } } // Return return retVal; } #endregion } }