/* * CSDisplayPanel.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 Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using tAC_Engine.GUI; namespace ColonySim.GUI { /// /// Displays the current numbers for the Colony Sim. The values displayed are /// Money, Population, and GOP. /// class CSStatusDisplayPanel : GUIPanel { #region Fields // Copy of our mFont SpriteFont mFont; // The amount of money int mMoney; // The amount of population int mPopulation; // The current GOP float mGOP; // The labels for money GUILabel mMoneyIcon; GUILabel mMoneyValue; // The labels for population GUILabel mPopulationIcon; GUILabel mPopulationValue; // The labels for GOP GUILabel mGOPIcon; GUILabel mGOPValue; // The resource labels we have List mResourceLabels = new List(); #endregion #region Properties /// /// Allows access to the money value that should be displayed. /// public int Money { get { return mMoney; } set { mMoney = value; } } /// /// Allows access to the population value that should be displayed. /// public int Population { get { return mPopulation; } set { mPopulation = value; } } /// /// Allows access to the GOP value that should be displayed. /// public float GOP { get { return mGOP; } set { mGOP = value; } } /// /// Allows access to the list of resource labels. /// public List ResourceLabels { get { return mResourceLabels; } } #endregion #region Constructs public CSStatusDisplayPanel() { // Clear our list Components.Clear(); // Now go through and create each of the components // Money icon and value mMoneyIcon = new GUILabel(); mMoneyValue = new GUILabel(); // Population icon and value mPopulationIcon = new GUILabel(); mPopulationValue = new GUILabel(); // GOP icon and value mGOPIcon = new GUILabel(); mGOPValue = new GUILabel(); // Add them to us //this.Add(mMoneyIcon); Add(mMoneyValue); //this.Add(mPopulationIcon); Add(mPopulationValue); //this.Add(mGOPIcon); Add(mGOPValue); // Create the resource labels foreach (ResourceCode code in Enum.GetValues(typeof(ResourceCode))) { // If it's not any of the firsts if (code != ResourceCode.A0 && code != ResourceCode.B0 && code != ResourceCode.C0 && code != ResourceCode.None) { // Create a label CSResourceLabel label = new CSResourceLabel(); label.Resource = code; // Add the label Add(label); } } } #endregion #region Initialize public override void Resize() { // Set the size and such of each of the internals // Money icon and value mMoneyIcon.Position = new Vector2(Position.X + 12, Position.Y + 12); mMoneyIcon.Size = new Vector2( 36, 36 ); mMoneyValue.Position = new Vector2(mMoneyIcon.Bounds.Right, Position.Y + 18); mMoneyValue.Size = new Vector2(Size.X - 6, Size.Y / 13 - 6); // Population icon and value mPopulationIcon.Position = new Vector2(Position.X + 12, mMoneyIcon.Bounds.Bottom + 3); mPopulationIcon.Size = new Vector2(36, 36); mPopulationValue.Position = new Vector2(mPopulationIcon.Bounds.Right, mMoneyIcon.Bounds.Bottom + 3); mPopulationValue.Size = new Vector2(Size.X - 6, Size.Y / 13 - 6); // GOP icon and value mGOPIcon.Position = new Vector2(Position.X + 12, mPopulationIcon.Bounds.Bottom + 3); mGOPIcon.Size = new Vector2(36, 36); mGOPValue.Position = new Vector2(mGOPIcon.Bounds.Right, mPopulationIcon.Bounds.Bottom + 3); mGOPValue.Size = new Vector2(Size.X - 6, Size.Y / 13 - 6); // Now, for each of the resource labels Vector2 position = new Vector2(Position.X + 15, Bounds.Bottom + 15); Vector2 size = new Vector2(Size.X + 24 - 6, Size.Y / 5 - 6); foreach (GUIComponent component in mResourceLabels) { // Go through and set the size and position component.Position = position; component.Size = size; // Nopw increment the position position.Y += size.Y + 6; } // Base call base.Resize(); } /// /// Load the content for our GUI. /// public override void LoadContent() { // Base call base.LoadContent(); // Load our background texture Background = ParentScreen.Content.Load(@"Textures\GUI\00_sidePanelBackground"); // Get the mFont we need mFont = ParentScreen.Content.Load(@"Fonts\InformationPanelFont"); // Load the content for the panels // Money icon and value mMoneyIcon.Background = ParentScreen.Content.Load(@"Textures\MoneyIcon"); mMoneyValue.Background = null; mMoneyValue.Font = mFont; mMoneyValue.TextColor = Color.White; // Population icon and value mPopulationIcon.Background = ParentScreen.Content.Load(@"Textures\PopulationIcon"); mPopulationValue.Background = null; mPopulationValue.Font = mFont; mPopulationValue.TextColor = Color.White; // GOP icon and value mGOPIcon.Background = ParentScreen.Content.Load(@"Textures\GOPIcon"); mGOPValue.Background = null; mGOPValue.Font = mFont; mGOPValue.TextColor = Color.White; // Go through each of the labels foreach (CSResourceLabel label in mResourceLabels) { // Set the amount label.ResourceAmount = 0.ToString(); // Switch on the type switch (label.Resource) { case ResourceCode.A1: label.ResourceIcon = ParentScreen.Content.Load(@"Textures\GUI\ResourceA1Icon"); break; case ResourceCode.A2: label.ResourceIcon = ParentScreen.Content.Load(@"Textures\GUI\ResourceA2Icon"); break; case ResourceCode.A3: label.ResourceIcon = ParentScreen.Content.Load(@"Textures\GUI\ResourceA3Icon"); break; case ResourceCode.B1: label.ResourceIcon = ParentScreen.Content.Load(@"Textures\GUI\ResourceB1Icon"); break; case ResourceCode.B2: label.ResourceIcon = ParentScreen.Content.Load(@"Textures\GUI\ResourceB2Icon"); break; case ResourceCode.B3: label.ResourceIcon = ParentScreen.Content.Load(@"Textures\GUI\ResourceB3Icon"); break; case ResourceCode.C1: label.ResourceIcon = ParentScreen.Content.Load(@"Textures\GUI\ResourceC1Icon"); break; case ResourceCode.C2: label.ResourceIcon = ParentScreen.Content.Load(@"Textures\GUI\ResourceC2Icon"); break; case ResourceCode.C3: label.ResourceIcon = ParentScreen.Content.Load(@"Textures\GUI\ResourceC3Icon"); break; } } // Call reinitialize to set the sizes Resize(); } #endregion #region Container /// /// Add the given component. /// /// The component to add. public override void Add(GUIComponent component) { // Add the component base.Add(component); // If it's a resource label if (component is CSResourceLabel) { // Add it to the list mResourceLabels.Add(component as CSResourceLabel); } } #endregion #region Update /// /// Update the displayed values. /// /// The current game time. public override void Update(GameTime gameTime) { // Base update base.Update(gameTime); // Set the displayed values as needed mMoneyValue.Text = mMoney.ToString(); mPopulationValue.Text = mPopulation.ToString(); mGOPValue.Text = mGOP.ToString("00.0") + "%"; } #endregion } }