/* * FourWayHubPopUp.cs * Authors: * 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.Graphics.Entities; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework; using ColonySim.Structures; using Microsoft.Xna.Framework.Graphics; using tAC_Engine.Graphics.Cameras; namespace ColonySim { class FourWayHubPopUp : InteractivePopUp { FourWayHub mCurrentSelection; PopUpComponent posXDecrease; PopUpComponent posXIncrease; PopUpComponent negXDecrease; PopUpComponent negXIncrease; PopUpComponent posYDecrease; PopUpComponent posYIncrease; PopUpComponent negYDecrease; PopUpComponent negYIncrease; PopUpComponent commitButton; PopUpString posXPercentage; int posXInt; PopUpString negXPercentage; int negXInt; PopUpString posYPercentage; int posYInt; PopUpString negYPercentage; int negYInt; PopUpString freeSpaceComponent; int freeSpace = 100; Viewport mViewport; Vector2 posXOffsetPosition = Vector2.Zero; Vector2 negXOffsetPosition = Vector2.Zero; Vector2 posYOffsetPosition = Vector2.Zero; Vector2 negYOffsetPosition = Vector2.Zero; Vector3 mCenter3D = Vector3.Zero; public FourWayHubPopUp(ContentManager pContent, string pTextureName, FourWayHub pCurrentSelection, float pTime, Viewport pCurrentViewport, Camera pPlayerCam, SpriteBatch pSpriteBatch, SpriteFont pSpriteFont) : base(pContent, pTextureName, new Vector2(pCurrentViewport.Project(pCurrentSelection.Center, pPlayerCam.Projection, pPlayerCam.View,Matrix.Identity).X, pCurrentViewport.Project(pCurrentSelection.Center, pPlayerCam.Projection, pPlayerCam.View,Matrix.Identity).Y), pTime) { mCurrentSelection = pCurrentSelection; if (mCurrentSelection.TubeExists(Hub.Directions.Positive_X)) { posXIncrease = new PopUpComponent(pContent, @"Textures\Arrow_Up", new Vector2(10, 10)); posXIncrease.Height = 15; posXIncrease.Width = 30; posXDecrease = new PopUpComponent(pContent, @"Textures\Arrow_Down", new Vector2(10, 45)); posXDecrease.Height = 15; posXDecrease.Width = 30; posXInt = (int)mCurrentSelection.GetFlow(Hub.Directions.Positive_X); freeSpace -= posXInt; posXPercentage = new PopUpString(posXInt + "%", Vector2.Zero, Color.White, pSpriteBatch, pSpriteFont); this.AddComponent(posXIncrease); this.AddComponent(posXDecrease); } if(mCurrentSelection.TubeExists(Hub.Directions.Negative_X)) { negXIncrease = new PopUpComponent(pContent, @"Textures\Arrow_Up", new Vector2(10, 45)); negXIncrease.Height = 15; negXIncrease.Width = 30; negXDecrease = new PopUpComponent(pContent, @"Textures\Arrow_Down", new Vector2(10, 45)); negXDecrease.Height = 15; negXDecrease.Width = 30; negXInt = (int)mCurrentSelection.GetFlow(Hub.Directions.Negative_X); freeSpace -= negXInt; negXPercentage = new PopUpString( negXInt + "%", Vector2.Zero, Color.White, pSpriteBatch, pSpriteFont); this.AddComponent(negXIncrease); this.AddComponent(negXDecrease); } if(mCurrentSelection.TubeExists(Hub.Directions.Positive_Y)) { posYIncrease = new PopUpComponent(pContent, @"Textures\Arrow_Up", new Vector2(10, 45)); posYIncrease.Height = 15; posYIncrease.Width = 30; posYDecrease = new PopUpComponent(pContent, @"Textures\Arrow_Down", new Vector2(10, 45)); posYDecrease.Height = 15; posYDecrease.Width = 30; posYInt = (int)mCurrentSelection.GetFlow(Hub.Directions.Positive_Y); freeSpace -= posYInt; posYPercentage = new PopUpString(posYInt + "%", Vector2.Zero, Color.White, pSpriteBatch, pSpriteFont); this.AddComponent(posYIncrease); this.AddComponent(posYDecrease); } if(mCurrentSelection.TubeExists(Hub.Directions.Negative_Y)) { negYIncrease = new PopUpComponent(pContent, @"Textures\Arrow_Up", new Vector2(10, 45)); negYIncrease.Height = 15; negYIncrease.Width = 30; negYDecrease = new PopUpComponent(pContent, @"Textures\Arrow_Down", new Vector2(10, 45)); negYDecrease.Height = 15; negYDecrease.Width = 30; negYInt = (int)mCurrentSelection.GetFlow(Hub.Directions.Negative_Y); freeSpace -= negYInt; negYPercentage = new PopUpString(negYInt + "%", Vector2.Zero, Color.White, pSpriteBatch, pSpriteFont); this.AddComponent(negYIncrease); this.AddComponent(negYDecrease); } mViewport = pCurrentViewport; mCenter3D = mCurrentSelection.Center; commitButton = new PopUpComponent(pContent, @"Textures\CommitButton", Center); commitButton.Height = 30; commitButton.Width = 35; freeSpaceComponent = new PopUpString(freeSpace + "%", commitButton.Offset, Color.White, pSpriteBatch, pSpriteFont); this.AddComponent(commitButton); this.BlendMode = SpriteBlendMode.AlphaBlend; } public void UpdateCamera(Camera pPlayerCam) { Vector3 offsetPositionTemp = Vector3.Zero; if (posXIncrease != null && posXIncrease.Visible) { offsetPositionTemp = mViewport.Project(mCenter3D + Vector3.Right, pPlayerCam.Projection, pPlayerCam.View, Matrix.Identity) - new Vector3(mViewport.X, mViewport.Y, 0); posXOffsetPosition = (Center - Position) + (Vector2.Normalize(new Vector2(offsetPositionTemp.X, offsetPositionTemp.Y) - Center) * 50); posXOffsetPosition.Y -= 15; posXIncrease.Offset = posXOffsetPosition; posXOffsetPosition.Y += 30; posXDecrease.Offset = posXOffsetPosition; posXPercentage.Position = new Vector2(posXIncrease.Position.X, posXIncrease.Position.Y + 12); } if (negXIncrease != null && negXIncrease.Visible) { offsetPositionTemp = mViewport.Project(mCenter3D + Vector3.Left, pPlayerCam.Projection, pPlayerCam.View, Matrix.Identity) - new Vector3(mViewport.X, mViewport.Y, 0); negXOffsetPosition = (Center - Position) + (Vector2.Normalize(new Vector2(offsetPositionTemp.X, offsetPositionTemp.Y) - Center) * 50); negXOffsetPosition.Y -= 15; negXIncrease.Offset = negXOffsetPosition; negXOffsetPosition.Y += 30; negXDecrease.Offset = negXOffsetPosition; negXPercentage.Position = new Vector2(negXIncrease.Position.X, negXIncrease.Position.Y + 12); } if (posYIncrease != null && posYIncrease.Visible) { offsetPositionTemp = mViewport.Project(mCenter3D + Vector3.Backward, pPlayerCam.Projection, pPlayerCam.View, Matrix.Identity) - new Vector3(mViewport.X, mViewport.Y, 0); posYOffsetPosition = (Center - Position) + (Vector2.Normalize(new Vector2(offsetPositionTemp.X, offsetPositionTemp.Y) - Center) * 50); posYOffsetPosition.Y -= 15; posYIncrease.Offset = posYOffsetPosition; posYOffsetPosition.Y += 30; posYDecrease.Offset = posYOffsetPosition; posYPercentage.Position = new Vector2(posYIncrease.Position.X, posYIncrease.Position.Y + 12); } if (negYIncrease != null && negYIncrease.Visible) { offsetPositionTemp = mViewport.Project(mCenter3D + Vector3.Forward, pPlayerCam.Projection, pPlayerCam.View, Matrix.Identity) - new Vector3(mViewport.X, mViewport.Y, 0); negYOffsetPosition = (Center - Position) + (Vector2.Normalize(new Vector2(offsetPositionTemp.X, offsetPositionTemp.Y) - Center) * 50); negYOffsetPosition.Y -= 15; negYIncrease.Offset = negYOffsetPosition; negYOffsetPosition.Y += 30; negYDecrease.Offset = negYOffsetPosition; negYPercentage.Position = new Vector2(negYIncrease.Position.X, negYIncrease.Position.Y + 12); } offsetPositionTemp = mViewport.Project(mCenter3D, pPlayerCam.Projection, pPlayerCam.View, Matrix.Identity) - new Vector3(mViewport.X, mViewport.Y, 0); commitButton.Offset = new Vector2(offsetPositionTemp.X, offsetPositionTemp.Y) - Position; freeSpaceComponent.Position = commitButton.Position - new Vector2(0, 15); } new public bool Click(Vector2 mPosition) { PopUpComponent compClicked = base.Click(mPosition); if (compClicked != null) { if (compClicked == posXIncrease) { if (freeSpace > 0) { posXInt += 1; freeSpace -= 1; posXPercentage.String = posXInt + "%"; } } else if (compClicked == posXDecrease) { if (posXInt > 0) { posXInt -= 1; freeSpace += 1; posXPercentage.String = posXInt + "%"; } } else if (compClicked == negXIncrease) { if (freeSpace > 0) { negXInt += 1; freeSpace -= 1; negXPercentage.String = negXInt + "%"; } } else if (compClicked == negXDecrease) { if (negXInt > 0) { negXInt -= 1; freeSpace += 1; negXPercentage.String = negXInt + "%"; } } else if (compClicked == posYIncrease) { if (freeSpace > 0) { posYInt += 1; freeSpace -= 1; posYPercentage.String = posYInt + "%"; } } else if (compClicked == posYDecrease) { if (posYInt > 0) { posYInt -= 1; freeSpace += 1; posYPercentage.String = posYInt + "%"; } } else if (compClicked == negYIncrease) { if (freeSpace > 0) { negYInt += 1; freeSpace -= 1; negYPercentage.String = negYInt + "%"; } } else if (compClicked == negYDecrease) { if (negYInt > 0) { negYInt -= 1; freeSpace += 1; negYPercentage.String = negYInt + "%"; } } else if (compClicked == commitButton) { mCurrentSelection.SetFlow(posYInt, Hub.Directions.Positive_Y); mCurrentSelection.SetFlow(negYInt, Hub.Directions.Negative_Y); mCurrentSelection.SetFlow(posXInt, Hub.Directions.Positive_X); mCurrentSelection.SetFlow(negXInt, Hub.Directions.Negative_X); } freeSpaceComponent.String = freeSpace + "%"; } return base.WithinBounds(mPosition); } public override void Draw(GameTime gameTime) { base.Draw(gameTime); if (!GettingLarger && !GettingSmaller) { if(mCurrentSelection.TubeExists(Hub.Directions.Positive_X)) posXPercentage.Draw(gameTime); if (mCurrentSelection.TubeExists(Hub.Directions.Positive_Y)) posYPercentage.Draw(gameTime); if (mCurrentSelection.TubeExists(Hub.Directions.Negative_X)) negXPercentage.Draw(gameTime); if(mCurrentSelection.TubeExists(Hub.Directions.Negative_Y)) negYPercentage.Draw(gameTime); freeSpaceComponent.Draw(gameTime); } } } }