/*
* CSTransportPanel.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 Transportation structures.
///
class CSTransportPanel : GUIRadioContainer
{
#region Fields
// The array of buttons for the Basic Tubes
CSStructureButton[] mButtons = new CSStructureButton[2];
// 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 CSTransportPanel()
{
// 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 tube structures for the buttons
Tube tube = new Tube(ParentScreen.Content, @ColonyStrings.MODEL_PATH + ColonyStrings.Tube_Straight_Model, null);
tube.AlphaMapPath = @ColonyStrings.MODEL_PATH + ColonyStrings.ALPHAMAP_PATH + ColonyStrings.Tube_Straight_AlphaMap;
tube.TechniqueName = "AlphaMapSpecularAndDiffuse";
tube.ReloadModel();
tube.FootPrintSize = new Vector2(1,1);
tube.Running = Tube.Runnings.Positive_X;
tube.BuildRadius = 0;
tube.Cost = 100;
tube.RequiresBuildArea = false;
tube.Name = "Resource_Tube";
// Create the road structures for the other buttons
// Create the structures for the buttons
Road road = new Road(ParentScreen.Content, @ColonyStrings.MODEL_PATH + ColonyStrings.Road_Straight_Model, null);
road.ColorToAdd = Color.Green;
road.TechniqueName = "AlphaMapSpecularAndDiffuse";
road.FootPrintSize = new Vector2(1, 1);
road.Running = Road.Runnings.Positive_X;
road.BuildRadius = 0;
road.Cost = 100;
road.RequiresBuildArea = false;
road.Name = "Residents_Tube";
// Set the structures for the buttons
mButtons[0].Structure = tube;
mButtons[1].Structure = road;
}
///
/// 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, 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
// Tube
mButtons[0].ButtonDown = mParentScreen.Content.Load(@"Textures\GUI\01b_blueTransportDn");
mButtons[0].ButtonUp = mParentScreen.Content.Load(@"Textures\GUI\01b_blueTransportUp");
// Road
mButtons[1].ButtonDown = mParentScreen.Content.Load(@"Textures\GUI\01a_redTransportDn");
mButtons[1].ButtonUp = mParentScreen.Content.Load(@"Textures\GUI\01a_redTransportUp");
//// 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");
//// Vertical
//mButtons[3].ButtonDown = mParentScreen.Content.Load(@"Textures\GUI\TubeNYDown");
//mButtons[3].ButtonUp = mParentScreen.Content.Load(@"Textures\GUI\TubeNYUp");
}
#endregion
#region Events
public event EventHandler TransportChanged;
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 (TransportChanged != null)
TransportChanged.Invoke(this, EventArgs.Empty);
break;
}
}
}
// Return
return retVal;
}
#endregion
}
}