/*
* ColonySimGUIScreen.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 ColonySim.Structures;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using tAC_Engine.GUI;
using Util;
namespace ColonySim.GUI
{
///
/// Represents the GUI for the colony simulation.
///
internal class ColonySimGUIScreen : GUIScreen
{
#region Constants
// Game Paused ticker lifetime
private const float GAME_PAUSED_LIFETIME = -1;
// Game Unpaused ticker lifetime
private const float GAME_UNPAUSED_LIFETIME = 5000;
// Game Tier Upgrade ticker lifetime
private const float TIER_UPGRADE_LIFETIME = 5000;
///
/// An enumeration of the values along the bottom panel.
///
public enum BottomPanelEnumeration
{
TRANSPORT,
RESIDENTIAL,
COMMERCIAL,
SELECTION,
DELETION,
PAUSE_UNPAUSE,
MISSION,
OPTIONS,
EXIT
}
#endregion
#region Fields
// Reference to the viewport we'll use
Viewport mViewport;
// Reference to the grid we will use
Grid mGrid;
// Reference to the Colony Simulation
readonly ColonySim mColonySim;
// The message ticker for displaying messages to the player
readonly CSTickerMessage mMessageTicker = new CSTickerMessage();
// The message panel for displaying messages to the player
readonly CSMessageDisplayPanel mMessagePanel = new CSMessageDisplayPanel();
// The panel for displaying current values
readonly CSStatusDisplayPanel mStandardDisplayPanel = new CSStatusDisplayPanel();
// The panel which holds the two selection panels
readonly GUIPanel mBottomPanel = new GUIPanel();
// The panel which selects modes and other windows
readonly CSSelectionPanel mSelectionPanel = new CSSelectionPanel();
// Panel for displaying the primary controls for the game
readonly CSMainPanel mMainPanel = new CSMainPanel();
// Button for telling a mini game is available
readonly GUIToggleButton mMiniGameNotification = new GUIToggleButton();
// The Transport Panel
readonly CSTransportPanel mTransportPanel = new CSTransportPanel();
// The residential panel
readonly CSStructureSelectionPanel mResidentialPanel = new CSStructureSelectionPanel();
// The commercial panel
readonly CSStructureSelectionPanel mCommercialPanel = new CSStructureSelectionPanel();
// The mini game Panel
readonly CSMiniGameSelectionPanel mMinigamePanel = new CSMiniGameSelectionPanel();
// The options panel
readonly CSOptionsMenuPanel mOptionsPanel = new CSOptionsMenuPanel();
// Test for popping something up
readonly CSMiniGamePopUpPanel mMiniGamePopUp = new CSMiniGamePopUpPanel();
// The cursor
readonly GUICursor mCursor = new GUICursor();
#endregion
#region Properties
///
/// The viewport for the GUI.
///
public Viewport GUIViewport
{
get { return mViewport; }
set { mViewport = value; UpdateComponentLayout(); }
}
protected void UpdateComponentLayout()
{
// set the position and size of the message ticker
mMessageTicker.Position = new Vector2(0, 0);
mMessageTicker.Size = new Vector2(mViewport.Width * 0.82f, mViewport.Height * 0.3f);
mMessageTicker.DisplayTime = 5000.0f;
// Set the position and size of the message display panel
mMessagePanel.Position = new Vector2(0, 0);
mMessagePanel.Size = new Vector2(mViewport.Width * 0.82f, mViewport.Height * 0.3f);
mMessagePanel.DisplayTime = 5000.0f;
mMessagePanel.ClickThrough = true;
// Set the position and size of the display panel
mStandardDisplayPanel.Size = new Vector2(mViewport.Width * 0.16f, mViewport.Height * 0.213f);
mStandardDisplayPanel.Position = new Vector2(mViewport.Width - mStandardDisplayPanel.Size.X, 0);
// Set the size and position of the background panel
mBottomPanel.Size = new Vector2(mViewport.Width, 64);
mBottomPanel.Position = new Vector2(0, mViewport.Height - mBottomPanel.Size.Y);
mBottomPanel.ClickThrough = true;
// Set the position and size of the selection panel
mSelectionPanel.Size = new Vector2(mBottomPanel.Size.X * 0.4f, mBottomPanel.Size.Y);
mSelectionPanel.Position = new Vector2(mBottomPanel.Position.X, mBottomPanel.Position.Y);
// Set the position and the size of the main panel
mMainPanel.Size = new Vector2(mBottomPanel.Size.X * 0.32f, mBottomPanel.Size.Y);
mMainPanel.Position = new Vector2(mViewport.Width - mMainPanel.Size.X, mBottomPanel.Bounds.Top);
// Set the position and size of the button
mMiniGameNotification.Size = new Vector2((mMainPanel.Bounds.Left - mSelectionPanel.Bounds.Right) * 2 / 3f,
mBottomPanel.Size.Y);
mMiniGameNotification.Position = new Vector2(mSelectionPanel.Bounds.Right + mMiniGameNotification.Size.X / 3,
mBottomPanel.Bounds.Top);
// Set the position and size of the transport panel
mTransportPanel.Size = new Vector2(64,64);
mTransportPanel.Position = new Vector2(0, mBottomPanel.Position.Y - mTransportPanel.Size.Y);
mTransportPanel.ClickThrough = true;
// Set the position and size of the residential panel
mResidentialPanel.Size = new Vector2(64, 64);
mResidentialPanel.Position = new Vector2(0, mBottomPanel.Position.Y - mTransportPanel.Size.Y);
mResidentialPanel.ClickThrough = true;
// Set the position and size of the commercial panel
mCommercialPanel.Size = new Vector2(64, 64);
mCommercialPanel.Position = new Vector2(0, mBottomPanel.Position.Y - mTransportPanel.Size.Y);
mCommercialPanel.ClickThrough = true;
// Set the position and size of the mini game panel
mMinigamePanel.Size = new Vector2(64, 64);
mMinigamePanel.Position = new Vector2(mBottomPanel.Position.X,
mBottomPanel.Position.Y - mTransportPanel.Size.Y);
// Set the size of the options panel
mOptionsPanel.Size = new Vector2(mViewport.Width * 0.40f, mViewport.Height * 0.60f);
mOptionsPanel.Position = new Vector2(mViewport.Width * 0.30f, mViewport.Height * 0.2f);
// Set the pop up panel's values
mMiniGamePopUp.Size = new Vector2(mViewport.Width * 2 / 3f, mBottomPanel.Size.Y);
mMiniGamePopUp.Position = new Vector2((mViewport.Width - mMiniGamePopUp.Size.X) / 2,
mBottomPanel.Position.Y - 2 * mMiniGamePopUp.Size.Y - 3);
//mMiniGamePopUp.AppearOrFade = false;
//mMiniGamePopUp.Effect = GUIPopUpPanel.Effects.ZOOM;
//mMiniGamePopUp.Time = 1000;
//// Set the position and size of the tube panel
//mTubePanel.Position = new Vector2(0, mDisplayPanel.Bounds.Bottom + 6);
//mTubePan5el.Size = new Vector2(mViewport.Width / 4 - 3, mViewport.Height / 4 - mDisplayPanel.Size.Y);
//CSTubeSelectionPanel.TubeChanged tubeCallback = TubePanelChanged;
//mTubePanel.AddCallback(tubeCallback);
//// Set the position and size of the hub panel
//mHubPanel.Position = new Vector2(mTubePanel.Bounds.Right + 6, mDisplayPanel.Bounds.Bottom + 6);
//mHubPanel.Size = new Vector2(mViewport.Width / 5 - 3, mViewport.Height / 4 - mDisplayPanel.Size.Y);
//CSHubSelectionPanel.HubChanged hubCallback = HubPanelChanged;
//mHubPanel.AddCallback(hubCallback);
//// Create hte model panel
//mModePanel.Position = new Vector2(mHubPanel.Bounds.Right + 6, mDisplayPanel.Bounds.Bottom + 6);
//mModePanel.Size = new Vector2(mViewport.Width / 5 - 3, mViewport.Height / 4 - mDisplayPanel.Size.Y);
//CSModePanel.ModeChanged modeCallback = ModePanelChanged;
//mModePanel.AddCallback(modeCallback);
//// Create the toggle button
//mPauseButton.Size = new Vector2(mViewport.Width / 5 - 3, mViewport.Height / 12);
//mPauseButton.Position = new Vector2(mViewport.Width - mPauseButton.Size.X, mDisplayPanel.Bounds.Bottom + 6);
}
#endregion
#region Constructs
///
/// Base constructor
///
/// The colony sim reference.
/// Reference to the structure grid.
public ColonySimGUIScreen(ColonySim pColonySim, Grid pGrid)
{
// Set the sim reference
mColonySim = pColonySim;
// Set the grid reference
mGrid = pGrid;
// Add to the bottom panel
mBottomPanel.Add(mSelectionPanel);
mBottomPanel.Add(mMainPanel);
// Add the panel
Add(mMessageTicker);
Add(mMessagePanel);
Add(mStandardDisplayPanel);
Add(mBottomPanel);
Add(mMiniGameNotification);
Add(mTransportPanel);
Add(mResidentialPanel);
Add(mCommercialPanel);
Add(mMinigamePanel);
Add(mOptionsPanel);
Add(mMiniGamePopUp);
Add(mCursor);
}
#endregion
#region Initialization
///
/// Initialize the components and their values
///
public override void Initialize()
{
// Base call
base.Initialize();
// Add a handler for handling events from the selection panel
mSelectionPanel.StateChanged += mSelectionPanel_StateChanged;
// Handle events for the transport panel
mTransportPanel.TransportChanged += StructureSelection_HasChanged;
mResidentialPanel.SelectionChanged += StructureSelection_HasChanged;
mCommercialPanel.SelectionChanged += StructureSelection_HasChanged;
// Handle events for the mini game panel
mMinigamePanel.MiniGameChanged += mMinigamePanel_MiniGameChanged;
// Handle events for gthe mini game pop up panel
mMiniGamePopUp.PlayMiniGame += mMiniGamePopUp_PlayMiniGame;
mMiniGamePopUp.DenyMiniGame += mMiniGamePopUp_DenyMiniGame;
// Handle events for the main panel
mMainPanel.PauseToggle += mMainPanel_PauseToggle;
mMainPanel.MiniGameToggle += mMainPanel_MiniGameToggle;
mMainPanel.OptionsPressed += mMainPanel_OptionsPressed;
mMainPanel.ExitPressed += mMainPanel_ExitPressed;
// Handle events for the options panel
mOptionsPanel.SaveEvent += mOptionsPanel_SaveEvent;
mOptionsPanel.LoadEvent += mOptionsPanel_LoadEvent;
// Set the toggle event
mMiniGameNotification.ButtonToggled += mMiniGameNotification_ButtonToggled;
// Set the transport panel to be disabled
mTransportPanel.Visible = false;
mResidentialPanel.Visible = false;
mCommercialPanel.Visible = false;
mMinigamePanel.Visible = false;
mOptionsPanel.Visible = false;
mMiniGamePopUp.Visible = false;
mMessagePanel.Visible = false;
mMiniGameNotification.Visible = false;
}
///
/// Called when graphics resources need to be loaded. Override this method to
/// load any component-specific graphics resources.
///
protected override void LoadContent()
{
// Base call
base.LoadContent();
// Set the font for the tool tip
TipPanel.Font = Content.Load(@"Fonts\InformationPanelFont");
TipPanel.Background = Content.Load(@"Textures\GUI\ToolTipBackground");
TipPanel.TextColor = Color.White;
TipPanel.ClickThrough = true;
// Set our background texture
mBottomPanel.Background = Content.Load(@"Textures\GUI\00_bottomPanelBackground");
// Set the message ticker values
mMessageTicker.Font = Content.Load(@"Fonts\InformationPanelFont");
mMessageTicker.Background = null;
mMessageTicker.ClickThrough = true;
mMessageTicker.Visible = false;
mMessageTicker.TextColor = Color.Gold;
// Set the font, text color, and text for the mini game notification
mMiniGameNotification.Text = "ALERT!";
mMiniGameNotification.Font = Content.Load(@"Fonts\Courier New");
mMiniGameNotification.TextColor = Color.Black;
// Set the background color for the message display
mMessagePanel.AddColor = new Color(255, 255, 255, 50);
}
///
/// Resize the current tip panel to fit in our GUI scene.
///
protected override void ResizeTipPanel()
{
// Resize the tip panel
if (TipPanel != null)
{
// If it has a font
if (TipPanel.Font != null)
{
// Set it's size based on the font it has and its text
TipPanel.Size = TipPanel.Font.MeasureString(TipPanel.Text);
}
}
}
public override void Reinitialize()
{
// Base call
base.Reinitialize();
// Enable everyone
Enable();
}
///
/// Enable this screen to run.
///
public override void Enable()
{
// Enable us
base.Enable();
// Do the same for Colony Sim
mColonySim.Reinitialize();
}
///
/// Disables us until further notice.
///
public override void Disable()
{
// Dis-enable us and set us as invisible
base.Disable();
// Do the same for the Colony Sim
mColonySim.Disable();
}
#endregion
#region Draw
public override void Draw(GameTime gameTime)
{
// Set the graphics viewport
GraphicsDevice.Viewport = mViewport;
// The base call
base.Draw(gameTime);
}
#endregion
#region Behavior
///
/// Ublocks the entire GUI.
///
public void UnlockAll()
{
// Make sure all of the components are enabled
foreach (GUIComponent component in Components)
{
// Enable the component
component.Enabled = true;
}
}
///
/// Locks all of the GUI.
///
public void LockAll()
{
// Make sure all of the components are enabled
foreach (GUIComponent component in Components)
{
// Enable the component
component.Enabled = false;
}
}
///
/// This method limits the possible structures that can be selected at
/// a given point in time by limiting the structure buttons that are
/// enabled given a specific structure button.
///
/// The type of panel to disable specify.
/// The name of the structure we need.
public void LimitStructureSelection(
BottomPanelEnumeration pType, string pStructureName)
{
// The panel to disable the button in
GUIContainer panel = null;
// Switch on the type of the panel to enable
switch (pType)
{
// Selected within the commercial panel
case BottomPanelEnumeration.COMMERCIAL:
panel = mCommercialPanel;
break;
// Selected within the residential panel
case BottomPanelEnumeration.RESIDENTIAL:
panel = mResidentialPanel;
break;
// Selected within the transport panel
case BottomPanelEnumeration.TRANSPORT:
panel = mTransportPanel;
break;
}
// If we have a panel
if (panel != null)
{
// Go through each of the components for the panel
foreach (GUIComponent component in panel.Components)
{
// Cast
CSStructureButton button = component as CSStructureButton;
component.Enabled = true;
// If we have a valid cast and we're not correct
if ((button == null) || (button.Structure.Name != pStructureName))
{
// Disable the button
component.Enabled = false;
}
}
}
}
///
/// Enables or disables the given panel.
///
/// The type of panel to enable / disable.
/// Whether it should be enabled or disabled.
public void EnableDisable(BottomPanelEnumeration pType, bool pEnabled)
{
// Switch on the type of the panel to enable
switch (pType)
{
// Enable/Disable the commercial panels
case BottomPanelEnumeration.COMMERCIAL:
mSelectionPanel.EnableDisableSelection(
CSSelectionPanel.States.COMMERCIAL, pEnabled);
break;
// Enable/Disable the deletion panels
case BottomPanelEnumeration.DELETION:
mSelectionPanel.EnableDisableSelection(
CSSelectionPanel.States.DELETION, pEnabled);
break;
case BottomPanelEnumeration.EXIT:
mMainPanel.EnableDisableMain(
CSMainPanel.MainTypes.EXIT, pEnabled);
break;
case BottomPanelEnumeration.MISSION:
mMainPanel.EnableDisableMain(
CSMainPanel.MainTypes.MISSIONS, pEnabled);
break;
case BottomPanelEnumeration.OPTIONS:
mMainPanel.EnableDisableMain(
CSMainPanel.MainTypes.OPTIONS, pEnabled);
break;
case BottomPanelEnumeration.PAUSE_UNPAUSE:
mMainPanel.EnableDisableMain(
CSMainPanel.MainTypes.PAUSE_UNPAUSE, pEnabled);
break;
// Enable/Disable the residential panels
case BottomPanelEnumeration.RESIDENTIAL:
mSelectionPanel.EnableDisableSelection(
CSSelectionPanel.States.RESIDENTIAL, pEnabled);
break;
// Enable/Disable the selection panels
case BottomPanelEnumeration.SELECTION:
mSelectionPanel.EnableDisableSelection(
CSSelectionPanel.States.SELECTION, pEnabled);
break;
// Enable/Disable the transport panels
case BottomPanelEnumeration.TRANSPORT:
mSelectionPanel.EnableDisableSelection(
CSSelectionPanel.States.TRANSPORT, pEnabled);
break;
}
}
///
/// Display a ticker message in the Colony Sim for the given amount of
/// time, in milliseconds.
///
/// The text to display.
/// The amount of time to display it, in milliseconds.
public void DisplayTicker(string pText, float pTime)
{
// Display the ticker
mMessageTicker.DisplayTime = pTime;
mMessageTicker.DisplayTicker(pText);
}
///
/// Display a message in a panel in the Colony Sim for the given amount
/// of time, in milliseconds.
///
/// The string and relative icon positions.
/// The icons to display.
/// The amount of time to display for.
public void DisplayMessagePanel(string pMessageString, Texture2D[] pIconArray, float pTime)
{
mMessagePanel.DisplayTime = pTime;
mMessagePanel.MessageIcons = pIconArray;
mMessagePanel.DisplayMessage(pMessageString);
}
///
/// Generates the given mini game and sets the display up for it.
///
/// The mini-game to display.
public void GenerateMiniGame(MiniGameInfo miniGame)
{
// Set the toggle button visible
mMiniGameNotification.Visible = true;
mMiniGameNotification.State = GUIButton.ButtonState.UP;
// Set the mini game
mMiniGamePopUp.CurrentMiniGame = miniGame;
mMiniGamePopUp.IsGenerated = true;
//mMiniGamePopUp.Visible = true;
//mMiniGamePopUp.AppearOrFade = true;
}
///
/// Upgrades the currently accessible Tier for the game that is
/// allowed for the player to access GUI-wise.
///
public void UpgradeTier(Tier pNewTier)
{
// Upgrade to the new Tier
Structure[] structures = pNewTier.Structures;
// Go through each structure
foreach (Structure structure in structures)
{
// Create a new structure button
CSStructureButton button = new CSStructureButton();
button.Structure = structure;
// If it has icons
if (structure.StructureIcons.Length == 2)
{
button.ButtonDown = structure.StructureIcons[0];
button.ButtonUp = structure.StructureIcons[1];
}
// Mining plant
if (structure is MiningPlant)
{
// Add the button to the mining plant panel
mCommercialPanel.Add(button);
}
// Factory
else if (structure is Factory)
{
// Add the button to the mining plant panel
mCommercialPanel.Add(button);
}
// Residential
else if (structure is Residential)
{
// Add the button to the mining plant panel
mResidentialPanel.Add(button);
}
// Commercial
else if (structure is Commercial)
{
// Add the button to the mining plant panel
mCommercialPanel.Add(button);
}
// Entertainment
else if (structure is Entertainment)
{
// Add the button to the entertainment panel
mResidentialPanel.Add(button);
}
}
// Add each of the new resources
ResourceCode[] resources = pNewTier.Resources;
// Go through each resources
foreach (ResourceCode resource in resources)
{
// Find the matching label and show it
foreach (CSResourceLabel rlabel in mStandardDisplayPanel.ResourceLabels)
{
// Display the correct label
if (rlabel.Resource == resource)
{
// Make it visible
rlabel.Visible = true;
break;
}
}
}
// Resize each of the panels
mResidentialPanel.Resize();
mCommercialPanel.Resize();
mStandardDisplayPanel.Resize();
// Message display
DisplayTicker("Congratulations, You've Upgraded to Tier " + pNewTier.Name,TIER_UPGRADE_LIFETIME);
}
#endregion
#region Handle Inputs
///
/// Handle key events as they come in.
///
/// The event to handle.
public override void HandleKeyEvent(KeyInputEvent e)
{
// If we got an escape event
if (e.Key == Microsoft.Xna.Framework.Input.Keys.Escape)
{
// Make this done
Done();
}
// The base call
base.HandleKeyEvent(e);
}
#endregion
#region Event Handlers
///
/// Toggle the visibility of the mini game pop up.
///
///
///
void mMiniGameNotification_ButtonToggled(object sender, EventArgs e)
{
// Toggle the visibility to that of our state
if (mMiniGameNotification.State == GUIButton.ButtonState.UP)
mMiniGamePopUp.Visible = false;
else if (mMiniGameNotification.State == GUIButton.ButtonState.DOWN)
mMiniGamePopUp.Visible = true;
}
///
/// Toggle the visibility of the mini game panel.
///
void mMainPanel_MiniGameToggle(object sender, EventArgs e)
{
// Toggle our visibility
mMinigamePanel.Visible = !mMinigamePanel.Visible;
// set everyone else as invisible
mTransportPanel.Visible = false;
mResidentialPanel.Visible = false;
mCommercialPanel.Visible = false;
// Toggle reset the options
mTransportPanel.DeselectAll();
mResidentialPanel.DeselectAll();
mCommercialPanel.DeselectAll();
mSelectionPanel.DeselectAll();
mMinigamePanel.DeselectAll();
// set the selection mode
mColonySim.CurrentCursorMode = ColonySim.CursorMode.NONE;
}
///
/// Load the given game from file.
///
void mOptionsPanel_LoadEvent(object sender, EventArgs e)
{
// Call the colony sim to load
mColonySim.Load((sender as CSOptionsMenuPanel).GetLoadString + ".csg");
}
///
/// Save the game to file.
///
void mOptionsPanel_SaveEvent(object sender, EventArgs e)
{
// Call the colony sim to save
mColonySim.Save((sender as CSOptionsMenuPanel).GetSaveString);
}
///
/// Deny playing the mini game.
///
void mMiniGamePopUp_DenyMiniGame(object sender, EventArgs e)
{
// If it's generated
if (mMiniGamePopUp.IsGenerated)
{
// Then add to the denials for the mini game
mMiniGamePopUp.CurrentMiniGame.NumRejects += 1;
mMiniGamePopUp.IsGenerated = false;
mMiniGamePopUp.WasPlayed = false;
}
else
{
// Clear the panel
mMinigamePanel.Visible = false;
}
// Close the panel
//mMiniGamePopUp.AppearOrFade = false;
mMiniGamePopUp.Visible = false;
mMiniGameNotification.Visible = false;
mMiniGameNotification.State = GUIButton.ButtonState.UP;
mMinigamePanel.DeselectAll();
}
///
/// Play the mini game.
///
void mMiniGamePopUp_PlayMiniGame(object sender, EventArgs e)
{
// Increment the number of plays
mMiniGamePopUp.CurrentMiniGame.NumPlayed += 1;
mMiniGamePopUp.WasPlayed = true;
// Raise the mini game
Raise(mMiniGamePopUp.CurrentMiniGame.GameScreen);
this.Disable();
// Make the screen disapper
mMiniGamePopUp.Visible = false;
mMiniGameNotification.Visible = false;
mMiniGameNotification.State = GUIButton.ButtonState.UP;
mMiniGamePopUp.IsGenerated = false;
// Clear the mini game stuff
mMinigamePanel.DeselectAll();
mMinigamePanel.Visible = false;
}
///
/// The currently selected mini game to play has changed.
///
void mMinigamePanel_MiniGameChanged(object sender, EventArgs e)
{
// Only is the current mini game is not generated
if (!mMiniGamePopUp.IsGenerated)
{
// Display the mini-game pop-up screen
mMiniGamePopUp.CurrentMiniGame = mMinigamePanel.MiniGame;
mMiniGamePopUp.Visible = true;
}
}
///
/// The current structure to build from the transport panel has changed.
///
void StructureSelection_HasChanged(object sender, EventArgs e)
{
// If it's the structure panel
if (sender is CSStructureSelectionPanel)
{
// Now get the structure
mColonySim.CurrentStructure = (sender as CSStructureSelectionPanel).CurrentStructure;
mColonySim.CurrentStructure.DrawOrder = mColonySim.SolidDrawOrder;
}
else if (sender is CSTransportPanel)
{
// Now get the structure
mColonySim.CurrentStructure = mTransportPanel.CurrentStructure;
mColonySim.CurrentStructure.DrawOrder = mColonySim.TransparentDrawOrder;
}
}
///
/// The main selection panel at the bottom has been changed.
///
void mSelectionPanel_StateChanged(object sender, EventArgs e)
{
// Switch on the state
switch (mSelectionPanel.State)
{
case CSSelectionPanel.States.TRANSPORT:
mColonySim.CurrentCursorMode = ColonySim.CursorMode.CONSTRUCT;
mTransportPanel.Visible = true;
mResidentialPanel.Visible = false;
mCommercialPanel.Visible = false;
mMinigamePanel.Visible = false;
//mMiniGamePopUp.AppearOrFade = false;
mMiniGamePopUp.Visible = false;
mMiniGameNotification.State = GUIButton.ButtonState.UP;
break;
case CSSelectionPanel.States.RESIDENTIAL:
mColonySim.CurrentCursorMode = ColonySim.CursorMode.CONSTRUCT;
mTransportPanel.Visible = false;
mResidentialPanel.Visible = true;
mCommercialPanel.Visible = false;
mMinigamePanel.Visible = false;
//mMiniGamePopUp.AppearOrFade = false;
mMiniGamePopUp.Visible = false;
mMiniGameNotification.State = GUIButton.ButtonState.UP;
break;
case CSSelectionPanel.States.COMMERCIAL:
mColonySim.CurrentCursorMode = ColonySim.CursorMode.CONSTRUCT;
mTransportPanel.Visible = false;
mResidentialPanel.Visible = false;
mCommercialPanel.Visible = true;
mMinigamePanel.Visible = false;
//mMiniGamePopUp.AppearOrFade = false;
mMiniGamePopUp.Visible = false;
mMiniGameNotification.State = GUIButton.ButtonState.UP;
break;
case CSSelectionPanel.States.SELECTION:
mColonySim.CurrentCursorMode = ColonySim.CursorMode.SELECT;
mTransportPanel.Visible = false;
mMinigamePanel.Visible = false;
mResidentialPanel.Visible = false;
mCommercialPanel.Visible = false;
mMinigamePanel.Visible = false;
//mMiniGamePopUp.AppearOrFade = false;
mMiniGamePopUp.Visible = false;
mMiniGameNotification.State = GUIButton.ButtonState.UP;
break;
case CSSelectionPanel.States.DELETION:
mColonySim.CurrentCursorMode = ColonySim.CursorMode.DELETE;
mTransportPanel.Visible = false;
mMinigamePanel.Visible = false;
mResidentialPanel.Visible = false;
mCommercialPanel.Visible = false;
mMinigamePanel.Visible = false;
//mMiniGamePopUp.AppearOrFade = false;
mMiniGamePopUp.Visible = false;
mMiniGameNotification.State = GUIButton.ButtonState.UP;
break;
//case CSSelectionPanel.States.NADDA:
// break;
}
// Deselect all of the current selection
mTransportPanel.DeselectAll();
mResidentialPanel.DeselectAll();
mCommercialPanel.DeselectAll();
mMinigamePanel.DeselectAll();
}
///
/// The exit button was pressed, so the game should end.
///
void mMainPanel_ExitPressed(object sender, EventArgs e)
{
// Call the colony sim to save an autosave
mColonySim.Save("Autosave");
// Make this done
Done();
// Exit the colony sim screen as well
mColonySim.Done();
}
///
/// Display the Colony Sim options window.
///
void mMainPanel_OptionsPressed(object sender, EventArgs e)
{
// Make the options panel visible
mOptionsPanel.Visible = !mOptionsPanel.Visible;
// Set the current save string to something natural
mOptionsPanel.SetSaveString = UserProfileUtility.CurrentUser + "SaveGame";
}
///
/// Toggle whether the Colony Sim should be running or not.
///
///
///
void mMainPanel_PauseToggle(object sender, EventArgs e)
{
// If we're running
if (mMainPanel.IsRunning)
{
// Make sure the colony sim is running
mColonySim.IsRunning = true;
DisplayTicker("Game Unpaused", GAME_UNPAUSED_LIFETIME);
}
else
{
// Make sure it's not
mColonySim.IsRunning = false;
DisplayTicker("Game Paused", GAME_PAUSED_LIFETIME);
}
}
#endregion
#region Update
///
/// Update the GUI.
///
/// The current game time.
public override void Update(GameTime gameTime)
{
// Base call
base.Update(gameTime);
// Set the values of the main panel
mStandardDisplayPanel.Money = mColonySim.StatusInfo.Money;
mStandardDisplayPanel.Population = mColonySim.StatusInfo.Population;
mStandardDisplayPanel.GOP = mColonySim.StatusInfo.Happiness;
// Update the resource labels
foreach (CSResourceLabel label in mStandardDisplayPanel.ResourceLabels)
{
// If the value exists
if (mColonySim.StatusInfo.Resources.ContainsKey(label.Resource))
{
// Set the value
label.ResourceAmount = mColonySim.StatusInfo.Resources[label.Resource].ToString();
}
}
// The mini game was played, hence we need to do something about it
if (mMiniGamePopUp.WasPlayed)
{
// Make it not played anymore
mMiniGamePopUp.WasPlayed = false;
}
}
#endregion
}
}