/* * ModeSelector.cs * Authors: August Zinsser, Brian Chesbrough * * Copyright Matthew Belmonte 2007 */ using System; using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Storage; using Nuclex.Fonts; using Pina3D.Particles; using Pina3D; using tAC_Engine; namespace Astropolis { /// /// This class is used to pick a minigame and then transition to that minigame. This should be called from the Practice section /// of the main menu. /// public class ModeSelector : MiniGame { /// /// Holds all the info needed to display each minigame /// private class MiniGameInfo { public AstroBaseApplication.Modes CodeName; // The name of that minigame in code public string DisplayName = ""; // The display name for the minigame (may be different than the code name) public Entity Logo = null; // The picture to display for the minigame public string Description = ""; // The one-line description for the minigame /// /// Initializer /// /// /// /// /// public MiniGameInfo(AstroBaseApplication.Modes codeName, string displayName, string logoFileName, string description) { CodeName = codeName; DisplayName = displayName; Logo = new Entity(TextureManager.Load(logoFileName)); Description = description; } } /// /// A helper class to display the game splash screen thumbnails at the top of the screen of the computer in mode selector /// private class ThumbnailStrip { private Vector2 mPosition = Vector2.Zero; // Position of this strip private Vector2 mSize = Vector2.Zero; // Size of this strip private Vector2 mSelectedPosition = Vector2.Zero; // The position of the currently-selected thumb private Vector2 mSelectedSize = Vector2.Zero; // The size of the currently-selected thumb private List mThumbnails; // Each thumbnail to display private List mClonedThumbnails; // Holds enough copies of the original Thumbnails list to fill the screen private int mCurrentClonedThumbnail = 0; // The currently selected cloned thumbnail private int mNumSlots; // Number of other thumbs to show before/after the currently selected one private List mSlots; // Placeholder positions for the thumbs private int mMinSlotIndex = 0; // Index of the reference for the left-most cloned thumb private int mMaxSlotIndex = 0; // '' right /// /// The currently selected thumbnail /// public int CurrentThumbnailIndex { get { return InRangeIndex(mCurrentClonedThumbnail); } } /// /// Initializer. Assumes that all thumbnails are of the same dimension as the first one /// /// public ThumbnailStrip(List thumbnails, Vector2 position, Vector2 size, Vector2 selectedPosition, Vector2 selectedSize) { mThumbnails = thumbnails; mPosition = position; mSize = size; mSelectedPosition = selectedPosition; mSelectedSize = selectedSize; mNumSlots = 9; mCurrentClonedThumbnail = mNumSlots / 2; mSlots = new List(); ArrangeSlots(); mClonedThumbnails = new List(); PopulateThumbnails(); } /// /// Selects the next thumbnail and pushes the strip to the left /// public void SelectNext() { mCurrentClonedThumbnail++; // Shift the strip mClonedThumbnails[mMinSlotIndex].Visible = false; int curThumbIndex = mMinSlotIndex + 1; for (int targetSlotIndex = 0; targetSlotIndex < mNumSlots; targetSlotIndex++) { if (curThumbIndex >= mClonedThumbnails.Count) curThumbIndex = 0; Entity curThumb = mClonedThumbnails[curThumbIndex]; Entity targetSlot = mSlots[targetSlotIndex]; // All but the last slot should visibly lerp if (targetSlotIndex < mNumSlots - 2) { curThumb.Visible = true; curThumb.Lerp(targetSlot.Position, targetSlot.Size, targetSlot.Rotation, .25f); } else { curThumb.Lerp(targetSlot.Position, targetSlot.Size, targetSlot.Rotation, 0f); } curThumbIndex++; } if (++mMinSlotIndex >= mClonedThumbnails.Count) mMinSlotIndex = 0; if (++mMaxSlotIndex >= mClonedThumbnails.Count) mMaxSlotIndex = 0; } /// /// Selects the previous thumbnail and pushes the strip to the right /// public void SelectPrevious() { mCurrentClonedThumbnail--; // Shift the strip mClonedThumbnails[mMaxSlotIndex].Visible = false; int curThumbIndex = mMinSlotIndex - 1; if (curThumbIndex < 0) curThumbIndex = mClonedThumbnails.Count - 1; for (int targetSlotIndex = 0; targetSlotIndex < mNumSlots; targetSlotIndex++) { if (curThumbIndex >= mClonedThumbnails.Count) curThumbIndex = 0; Entity curThumb = mClonedThumbnails[curThumbIndex]; Entity targetSlot = mSlots[targetSlotIndex]; // All but the last slot should visibly lerp if (targetSlotIndex > 0) { curThumb.Visible = true; curThumb.Lerp(targetSlot.Position, targetSlot.Size, targetSlot.Rotation, .25f); } else { curThumb.Lerp(targetSlot.Position, targetSlot.Size, targetSlot.Rotation, 0f); } curThumbIndex++; } if (--mMinSlotIndex < 0) mMinSlotIndex = mClonedThumbnails.Count - 1; if (--mMaxSlotIndex < 0) mMaxSlotIndex = mClonedThumbnails.Count - 1; } /// /// Updates each thumbnail /// public void Update() { foreach (Entity thumb in mClonedThumbnails) { thumb.Update(); } } /// /// Draws the thumbs in a strip to the spritebatch /// /// public void Draw(SpriteBatch spriteBatch) { foreach (Entity thumb in mClonedThumbnails) { thumb.Draw(spriteBatch); } } /// /// Arranges the placeholder slots /// public void ArrangeSlots() { // temp arrangement int thumbWidth = (int)mThumbnails[0].Size.X; for (int i = 0; i < mNumSlots; i++) { Entity newEnt = new Entity(mThumbnails[0].Texture, new Vector3(this.mPosition.X + (i - mNumSlots / 2) * thumbWidth, this.mPosition.Y, 0), mThumbnails[0].Size); mSlots.Add(newEnt); } mSlots[mNumSlots / 2].Position = new Vector3(mSelectedPosition, 1f); mSlots[mNumSlots / 2].Size = new Vector3(mSelectedSize, 0f); } /// /// Adds new entities to the cloned thumbnail list to make sure the screen is full and has enough padding to move edge entities around seamlessly /// private void PopulateThumbnails() { if (mClonedThumbnails.Count == 0) { mMinSlotIndex = 0; mMaxSlotIndex = mNumSlots - 1; // Fill the slots, overfilling to ensure that there are an equal number of each thumb for (int i = 0; i < mNumSlots || InRangeIndex(i) != 0; i++) { Entity newThumb = new Entity(mThumbnails[InRangeIndex(i)].Texture); newThumb.Size = mThumbnails[0].Size; newThumb.Visible = false; mClonedThumbnails.Add(newThumb); } // Put the thumbs in their initial positions int curSlotIndex = 0; for (int i = mMinSlotIndex; i != mMaxSlotIndex; i++) { if (i >= mClonedThumbnails.Count) i = 0; Entity curThumb = mClonedThumbnails[i]; Entity curSlot = mSlots[curSlotIndex++]; curThumb.Position = curSlot.Position; curThumb.Size = curSlot.Size; curThumb.Rotation = curSlot.Rotation; curThumb.Visible = true; } } } /// /// Returns an index that is in range of Thumbnails, where the InRangeIndex = X * index for some integer X /// /// /// private int InRangeIndex(int index) { int inRangeIndex = index % this.mThumbnails.Count; if (inRangeIndex < 0) inRangeIndex += mThumbnails.Count; return inRangeIndex; } } /// /// Displays a popup button that the user can click to go back to the hologram menu /// private class BackButton : Widget2D { private Entity mBackText = new Entity(TextureManager.Load(@"Content\ModeSelector\BackText")); private Entity mBackArrow = new Entity(TextureManager.Load(@"Content\ModeSelector\BackLeftArrow")); private Vector3 mIdlePosition; private Vector3 mDisplayPosition; public Vector3 DisplayPosition { set { mDisplayPosition = value; } get { return mDisplayPosition; } } public Vector3 IdlePosition { set { mIdlePosition = value; mBackArrow.Position = value; mBackText.Position = value; } } public new Vector3 Size { set { mBackText.Size = value; mBackArrow.Size = value; mSize = value; } get { return mSize; } } public override void Draw(SpriteBatch spriteBatch) { mBackText.Draw(spriteBatch); mBackArrow.Draw(spriteBatch); } public override void Update() { base.Update(); mBackText.Update(); mBackArrow.Update(); mPosition = mBackText.Position; } /// /// Slide in from the idle position /// public void PopIn() { mBackText.Lerp(mDisplayPosition, mBackText.Size, mBackText.Rotation, 1f); mBackArrow.Lerp(mDisplayPosition, mBackArrow.Size, mBackArrow.Rotation, 1f); } /// /// Slide out to the idle position /// public void PopOut() { mBackText.Lerp(mIdlePosition, mBackText.Size, mBackText.Rotation, 1f); mBackArrow.Lerp(mIdlePosition, mBackArrow.Size, mBackArrow.Rotation, 1f); } public override void OnLeftClick() { base.OnLeftClick(); ((ModeSelector)AstroBaseApplication.MiniGame).GoBackToHologram(); } } private enum Viewing { Startup, Hologram, Practice, Setup }; private static PinaModel mConsoleHologram; // Part of the 3D scene private static PinaModel mPracticeConsoleMainScreen; // '' private static PinaModel mPracticeConsoleSideScreen; // '' private static Camera mCamera; // '' private static Vector3 mCenterPosition; // One of the camera locations in the 3D scene private static Vector3 mCenterTarget; // '' private static Vector3 mPracticePosition; // '' private static Vector3 mPracticeTarget; // '' private static Vector3 mSetupPosition; // '' private static Vector3 mSetupTarget; // '' private Viewing mViewing; // Which screen the camera is looking at private List mGameInfoList; // The game info for each game private ThumbnailStrip mThumbnailStrip; // Helper class to display the game splash thumbs private float mKeypressWaitTime = .1f; // The time to wait before accepting another scroll command via the arrow keys private float mKeypressTimer = 0; // Counts down the time to wait before accepting another scroll command via the arrow keys private float mKeyholdWaitTime = .6f; // The time needed to hold down the arrow key to activate repeated-presses at an interval of keypresswaittime private float mKeyholdTimer = 0; // Counts down the time to waith before treating a held arrow key as a repeatedly-pressed arrow key private SpriteBatch mSpriteBatch; // An intermediate sprite batch to render the screens to private RenderTarget2D mHologramRT; // Renders the hologram screen on the computer model private RenderTarget2D mMainScreenRT; // Renders the main screen display on the computer model private RenderTarget2D mSideScreenRT; // Renders the side screen display on the computer model private int mMaxRenderTargets; // The number of render targets this computer is capable of private int mUnit; // Used for positioning and sizing of screen GUI elements // TODO (awz): Have these sizes scale with the current screen resolution private int mHologramWidth = 700; // The width of the hologram in the computer model private int mHologramHeight = 700; // '' height private int mMainScreenWidth = 500; // The width of the main screen of the computer model private int mMainScreenHeight = 500; // '' height private int mSideScreenWidth = 400; // '' width side private int mSideScreenHeight = 500; // '' height private Entity mBaseTexture; // GUI element private Entity mOverTexture; // '' private Entity mLoginBackground; // '' private Entity mButtonsBackground; // '' private Entity mColonyPicture; // '' private Entity mWelcome; // '' private Vector2 mUsernamePos; // '' private Entity mRightButton; // '' private Entity mLeftButton; // '' private Entity mUpButton; // '' private Entity mDownButton; // '' private Entity mDescriptionBlock; // '' private BackButton mBackButton; // '' private List mGameNameIndex; // '' private Entity mHighlightGameName; // '' //private int mGameNamesStartIndex; // Index of the first game on the list on the side screen //private int mGameNamesEndIndex; // Index of the last game on the list on the side screen private int mSelectedMiniGame; //used to index the currently selected minigame private List mMiniGameList; //list of all minigames for launching selected minigame /// /// Populates the info for each minigame and runs a script to build the 3D scene /// public ModeSelector() { LuaHelper.RegisterLuaCallbacks(this); Sparx.Flush(); mViewing = Viewing.Startup; mGameInfoList = new List(); List thumbnails = new List(); mUnit = mMainScreenWidth / 20; int screenW = GenericBaseApplication.GameManager.ScreenWidth; int screenH = GenericBaseApplication.GameManager.ScreenHeight; // Prep render target info mMaxRenderTargets = GenericBaseApplication.GameManager.GraphicsDevice.GraphicsDeviceCapabilities.NumberSimultaneousRenderTargets; mSpriteBatch = new SpriteBatch(GenericBaseApplication.GameManager.GraphicsDevice); mHologramRT = new RenderTarget2D(GenericBaseApplication.GameManager.GraphicsDevice, mHologramWidth, mHologramHeight, 1, GenericBaseApplication.GameManager.GraphicsDevice.DisplayMode.Format); mMainScreenRT = new RenderTarget2D(GenericBaseApplication.GameManager.GraphicsDevice, mMainScreenWidth, mMainScreenHeight, 1, GenericBaseApplication.GameManager.GraphicsDevice.DisplayMode.Format); mSideScreenRT = new RenderTarget2D(GenericBaseApplication.GameManager.GraphicsDevice, mSideScreenWidth, mSideScreenHeight, 1, GenericBaseApplication.GameManager.GraphicsDevice.DisplayMode.Format); // Get the Game Info for each game // Meteor Madness mGameInfoList.Add(new MiniGameInfo( AstroBaseApplication.Modes.MeteorMadness, "Maritime Defender", @"Content\MiniGames\MMSplashLogo", "Answer the distress signal of a freighter \n" + "under attack.")); thumbnails.Add(new Entity(TextureManager.Load(@"Content\MiniGames\MMSplashLogo"), mUnit * 4f, mUnit * 3f)); // Hacker Havoc mGameInfoList.Add(new MiniGameInfo( AstroBaseApplication.Modes.HackerHavoc, "Hacker Havoc", @"Content\MiniGames\HHSplashLogo", "Protect those payloads at all cost! ")); thumbnails.Add(new Entity(TextureManager.Load(@"Content\MiniGames\HHSplashLogo"), mUnit * 4f, mUnit * 3f)); // Temp fake minigames mGameInfoList.Add(new MiniGameInfo( AstroBaseApplication.Modes.MeteorMadness, "Maritime Defender", @"Content\General\WSI Wallpaper", "your face is ugly")); thumbnails.Add(new Entity(TextureManager.Load(@"Content\General\WSI Wallpaper"))); mGameInfoList.Add(new MiniGameInfo( AstroBaseApplication.Modes.MeteorMadness, "Maritime Defender", @"Content\General\OoO Wallpaper", "your face is \nextremely ugly.\nseriously.")); thumbnails.Add(new Entity(TextureManager.Load(@"Content\General\OoO Wallpaper"))); mGameInfoList.Add(new MiniGameInfo( AstroBaseApplication.Modes.MeteorMadness, "Maritime Defender", @"Content\MiniGames\Cheetah", "Yet another minigame. Let's fill out the text \n" + "on this one. Oh yeah, a whole lotta text. When\n" + "will it end? Nobody knows.")); thumbnails.Add(new Entity(TextureManager.Load(@"Content\MiniGames\Cheetah"))); // Initialize the thumbnails mThumbnailStrip = new ThumbnailStrip( thumbnails, new Vector2(mUnit * 10, mUnit * 1.5f), new Vector2(mUnit * 20, mUnit * 4), new Vector2(mUnit * 10, mUnit * 9), new Vector2(mUnit * 12, mUnit * 9) ); // Hologram Sprites mBaseTexture = new Entity(TextureManager.Load(@"Content\ModeSelector\BackLayerBlue")); mBaseTexture.Position = new Vector3(0, mHologramHeight / 2, 0); mBaseTexture.Size = new Vector3(mHologramWidth, mHologramHeight, 0); mOverTexture = new Entity(TextureManager.Load(@"Content\ModeSelector\BackLayerOver")); mOverTexture.Size = new Vector3(mHologramWidth * 2, mHologramHeight * 2, 0); mOverTexture.Opacity = 0.15f; mLoginBackground = new Entity(TextureManager.Load(@"Content\ModeSelector\LoginBackground")); mLoginBackground.Size = new Vector3(screenW, screenH * .30f, 0); mLoginBackground.Position = new Vector3(screenW * .50f, screenH * .15f, 0); mButtonsBackground = new Entity(TextureManager.Load(@"Content\ModeSelector\BottomButtonsBackground")); mButtonsBackground.Size = new Vector3(screenW, screenH * .08f, 0); mButtonsBackground.Position = new Vector3(screenW * .50f, screenH * .61f, 0); mColonyPicture = new Entity(TextureManager.Load(@"Content\ModeSelector\FakeCityScreenshot")); mColonyPicture.Size = new Vector3(screenW * .20f, screenH * .20f, 0); mColonyPicture.Position = new Vector3(screenW * .44f, screenH * .43f, 0); mWelcome = new Entity(TextureManager.Load(@"Content\ModeSelector\Welcome")); mWelcome.Size = new Vector3(screenW * .10f, screenH * .10f * mWelcome.Texture.Height / mWelcome.Texture.Width, 0); mWelcome.Position = new Vector3(screenW * .40f, screenH * .22f, 0); mWelcome.Opacity = .75f; mUsernamePos = new Vector2(screenW * .30f, screenH * .27f); // Navigation Buttons mRightButton = new Entity(TextureManager.Load(@"Content\ModeSelector\RightArrow")); mLeftButton = new Entity(TextureManager.Load(@"Content\ModeSelector\RightArrow")); mUpButton = new Entity(TextureManager.Load(@"Content\ModeSelector\RightArrow")); mDownButton = new Entity(TextureManager.Load(@"Content\ModeSelector\RightArrow")); mLeftButton.Rotation = Math.PI; mUpButton.Rotation = Math.PI * 3 / 2; mDownButton.Rotation = Math.PI / 2; mRightButton.Size = new Vector3(mUnit * 3, mUnit * 3, 0); mLeftButton.Size = mRightButton.Size; mUpButton.Size = new Vector3(mUnit * 2, mUnit * 2, 0); mDownButton.Size = mUpButton.Size; mRightButton.Position = new Vector3(mUnit * 18, mUnit * 9, 0); mLeftButton.Position = new Vector3(mUnit * 2, mUnit * 9, 0); mUpButton.Position = new Vector3(mUnit * 15, mUnit, 0); mDownButton.Position = new Vector3(mUnit * 15, mUnit * 19, 0); mBackButton = new BackButton(); mBackButton.Size = new Vector3(screenW * .20f, screenW * .10f, 0); mBackButton.DisplayPosition = new Vector3(screenW * .10f, screenH * .95f, 0); mBackButton.IdlePosition = new Vector3(mBackButton.DisplayPosition.X, screenH * 1.2f, 0f); HUD.Add(mBackButton); // Description Block mDescriptionBlock = new Entity(TextureManager.Load(@"Content\ModeSelector\DescriptionBlock")); mDescriptionBlock.Size = new Vector3(mUnit * 18, mUnit * 5, 0); mDescriptionBlock.Position = new Vector3(mUnit * 10, mUnit * 16.75f, 0); // Game Titles mGameNameIndex = new List(); //mGameNamesStartIndex = 0; //mGameNamesEndIndex = 10; foreach (MiniGameInfo gameInfo in mGameInfoList) { mGameNameIndex.Add(gameInfo.DisplayName); } mHighlightGameName = new Entity(TextureManager.Load(@"Content\ModeSelector\GameNameSelection")); mHighlightGameName.Size = new Vector3(mUnit * 16, mUnit * 2, 0f); // Build the scene mCamera = new Camera(); Pina.NearPlane = .02f; Pina.FarPlane = 10000f; Pina.Camera.TargetPoint = Vector3.Zero; GenericBaseApplication.GameManager.InterpretLuaFile(@"GeneralScripts\MainMenuScene.lua"); mSelectedMiniGame = 0; //add Minigames to list mMiniGameList = new List(); //Extra MM's to replace the palcehodler minigame graphics mMiniGameList.Add(AstroBaseApplication.Modes.MeteorMadness); mMiniGameList.Add(AstroBaseApplication.Modes.MeteorMadness); mMiniGameList.Add(AstroBaseApplication.Modes.HackerHavoc); mMiniGameList.Add(AstroBaseApplication.Modes.MeteorMadness); mMiniGameList.Add(AstroBaseApplication.Modes.MeteorMadness); } public override void LoadGraphicsContent(bool loadAllContent) { mSpriteBatch = new SpriteBatch(GenericBaseApplication.GameManager.GraphicsDevice); mHologramRT = new RenderTarget2D(GenericBaseApplication.GameManager.GraphicsDevice, mHologramWidth, mHologramHeight, 1, GenericBaseApplication.GameManager.GraphicsDevice.DisplayMode.Format); mMainScreenRT = new RenderTarget2D(GenericBaseApplication.GameManager.GraphicsDevice, mMainScreenWidth, mMainScreenHeight, 1, GenericBaseApplication.GameManager.GraphicsDevice.DisplayMode.Format); mSideScreenRT = new RenderTarget2D(GenericBaseApplication.GameManager.GraphicsDevice, mSideScreenWidth, mSideScreenHeight, 1, GenericBaseApplication.GameManager.GraphicsDevice.DisplayMode.Format); } /// /// Basic logic update /// /// public override void Update() { // ////// TEMP FOR TEST BUILD ///////////////////////////////////////////////// // #if !DEBUG Pina.FlushRenderables(); HUD.Clear(); AstroBaseApplication.SwitchMode(AstroBaseApplication.Modes.MeteorMadness); return; #endif // /////////// END TEMP /////////////////////////////////////////////////////// // InputState.DecodeAll(); // TODO: move this to an initialize float dT = GenericBaseApplication.GameManager.ElapsedSeconds; mKeypressTimer -= dT; // Controls depend on which screen is currently being viewed switch (mViewing) { case Viewing.Startup: Pina.Camera.Lerp( Pina.Camera.Position, mCenterPosition, Pina.Camera.TargetPoint.Value, mCenterTarget, 3f); mViewing = Viewing.Hologram; break; case Viewing.Hologram: // Load the colony simulator if (InputState.IsKeyDown(Keys.Enter) || InputState.IsKeyDown(Keys.E)) { Pina.FlushRenderables(); HUD.Clear(); AstroBaseApplication.SwitchMode(AstroBaseApplication.Modes.Colony); } // Go to the practice console if (InputState.IsKeyDown(Keys.P)) { Pina.Camera.Lerp( Pina.Camera.Position, mPracticePosition, Pina.Camera.TargetPoint.Value, mPracticeTarget, 1.5f); mBackButton.PopIn(); mViewing = Viewing.Practice; } // Quit if ((InputState.IsKeyDown(Keys.Escape) && !InputState.WasKeyDown(Keys.Escape)) || InputState.IsKeyDown(Keys.Q)) { AstroBaseApplication.SwitchMode(AstroBaseApplication.Modes.ShutDown); } break; case Viewing.Practice: // Go back to the hologram if (InputState.IsKeyDown(Keys.B) || InputState.IsKeyDown(Keys.Escape)) { GoBackToHologram(); } // Scroll through the current game or launch the current game if (mKeypressTimer < 0 && (mKeyholdTimer < 0 || mKeyholdTimer == mKeyholdWaitTime)) { if (InputState.IsKeyDown(Keys.Down) || InputState.IsKeyDown(Keys.Right)) { mKeypressTimer = mKeypressWaitTime; SelectNextMiniGame(); } else if (InputState.IsKeyDown(Keys.Up) || InputState.IsKeyDown(Keys.Left)) { mKeypressTimer = mKeypressWaitTime; SelectPreviousMiniGame(); } } if (InputState.IsKeyDown(Keys.Enter)) LaunchSelectedMiniGame(); break; } // Track the holding-ness of the arrow keys if (InputState.IsKeyDown(Keys.Up) || InputState.IsKeyDown(Keys.Down) || InputState.IsKeyDown(Keys.Left) || InputState.IsKeyDown(Keys.Right)) { mKeyholdTimer -= AstroBaseApplication.GameManager.ElapsedSeconds; } if (InputState.IsKeyUp(Keys.Up) && InputState.IsKeyUp(Keys.Down) && InputState.IsKeyUp(Keys.Left) && InputState.IsKeyUp(Keys.Right)) { mKeyholdTimer = mKeyholdWaitTime; } // Update GUI stuff mThumbnailStrip.Update(); mOverTexture.Y = mHologramHeight * .50f + (mHologramHeight * .25f * (float)Math.Cos(GenericBaseApplication.GameManager.TotalSeconds * .25f)); mOverTexture.X += mHologramWidth * .034f * dT; mBaseTexture.X -= mHologramWidth * .014f * dT; if (mBaseTexture.X < -mHologramWidth * .25f) mBaseTexture.X += mHologramWidth; if (mOverTexture.X > mHologramWidth * .5) mOverTexture.X -= mHologramWidth * 2; base.Update(); } /// /// Basic drawing function /// /// public override void Draw() { // Save some typing GraphicsDevice device = GenericBaseApplication.GameManager.GraphicsDevice; // Set rendering settings for the hologram mSpriteBatch.Begin(SpriteBlendMode.Additive, SpriteSortMode.Immediate, SaveStateMode.SaveState); device.SetRenderTarget(0, mHologramRT); device.Clear(Color.Black); // // Begin rendering the hologram // // Background textures float exactX = mBaseTexture.X; mBaseTexture.X = (int)mBaseTexture.X; mBaseTexture.Draw(mSpriteBatch); mBaseTexture.X += mBaseTexture.Width; mBaseTexture.Draw(mSpriteBatch); mBaseTexture.X = exactX; exactX = mOverTexture.X; mOverTexture.X = (int)mOverTexture.X; mOverTexture.Draw(mSpriteBatch); mOverTexture.X += mOverTexture.Width; mOverTexture.Draw(mSpriteBatch); mOverTexture.X = exactX; mLoginBackground.Draw(mSpriteBatch); mButtonsBackground.Draw(mSpriteBatch); mColonyPicture.Draw(mSpriteBatch); mWelcome.Draw(mSpriteBatch); // Username mSpriteBatch.End(); mSpriteBatch.Begin(SpriteBlendMode.Additive, SpriteSortMode.Immediate, SaveStateMode.SaveState); string text = "Username"; Rectangle size = GenericBaseApplication.GameManager.StandardFontBig.MeasureString(text); GenericBaseApplication.GameManager.SpaceFontBig.DrawString( new Vector2(mUsernamePos.X, mUsernamePos.Y), text, Color.DarkBlue); // Set rendering settings for the main screen of the practice console device.ResolveRenderTarget(0); mSpriteBatch.End(); mSpriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.FrontToBack, SaveStateMode.SaveState); device.SetRenderTarget(0, mMainScreenRT); device.Clear(Color.Blue); // // Begin rendering the main practice screen // // Navigation Buttons mRightButton.Draw(mSpriteBatch); mLeftButton.Draw(mSpriteBatch); // Description Block mDescriptionBlock.Draw(mSpriteBatch); // Thumbnail Strip mThumbnailStrip.Draw(mSpriteBatch); // Text (must be done in a new spritebatch session since nuclex doesn't play nice with layer depth mSpriteBatch.End(); mSpriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.SaveState); text = mGameInfoList[mThumbnailStrip.CurrentThumbnailIndex].Description; size = GenericBaseApplication.GameManager.StandardFontBig.MeasureString(text); GenericBaseApplication.GameManager.StandardFontBig.DrawString(new Vector2((int)mDescriptionBlock.Position.X - size.Width / 2, (int)mDescriptionBlock.Position.Y - mDescriptionBlock.Height / 2 + 50), text, Color.White); // Set rendering settings for the side screen device.ResolveRenderTarget(0); mSpriteBatch.End(); mSpriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.FrontToBack, SaveStateMode.SaveState); device.SetRenderTarget(0, mSideScreenRT); device.Clear(Color.Thistle); // // Begin rendering the practice side screen // // Navigation Buttons mUpButton.Draw(mSpriteBatch); mDownButton.Draw(mSpriteBatch); // Game Titles // Until there is a need to scroll, just display them all for (int i = 0; i < mGameInfoList.Count; i++) { string title = mGameInfoList[i].DisplayName; Rectangle titleSize = GenericBaseApplication.GameManager.StandardFontBig.MeasureString(title); GenericBaseApplication.GameManager.StandardFontBig.DrawString(new Vector2((int)mUnit, (int)mUnit * 4 + i * (titleSize.Height + mUnit * .75f)), title, Color.White); if (i == mThumbnailStrip.CurrentThumbnailIndex) mHighlightGameName.Position = new Vector3(mHighlightGameName.Width / 2, mUnit * 4 - titleSize.Height / 4 + i * (titleSize.Height + mUnit * .75f), 1f); } mHighlightGameName.Draw(mSpriteBatch); // Reset rendering settings to go to the back buffer mSpriteBatch.End(); device.ResolveRenderTarget(0); device.SetRenderTarget(0, null); // Put screen textures on 3D objects (they are all assigned at the same time) if (mPracticeConsoleMainScreen != null) { mConsoleHologram.SourceData.DefaultMaterial.DiffuseMap = mHologramRT.GetTexture(); mPracticeConsoleMainScreen.SourceData.DefaultMaterial.DiffuseMap = mMainScreenRT.GetTexture(); mPracticeConsoleSideScreen.SourceData.DefaultMaterial.DiffuseMap = mSideScreenRT.GetTexture(); } } /// /// Goes from the practice or setup menu back to the hologram /// private void GoBackToHologram() { Pina.Camera.Lerp( Pina.Camera.Position, mCenterPosition, Pina.Camera.TargetPoint.Value, mCenterTarget, 1.5f); mBackButton.PopOut(); mViewing = Viewing.Hologram; } /// /// Sets references to the ColladaModels to receive the screen renders from ModeSelector.Draw() /// /// [LuaCallback("SetModeSelectorScreens")] public static void SetModeSelectorScreens( PinaModel hologram, PinaModel practiceMain, PinaModel practiceSide) { mConsoleHologram = hologram; mPracticeConsoleMainScreen = practiceMain; mPracticeConsoleSideScreen = practiceSide; } /// /// Gets the camera used by the ModeSelector /// /// [LuaCallback("GetModeSelectorCamera")] public static Camera GetCamera() { return mCamera; } /// /// Sets the camera points used to navigate the main menu scene /// /// /// /// /// /// /// [LuaCallback("SetModeSelectorCameraLocations")] public static void SetModeSelectorCameraLocations( Vector3 centerPosition, Vector3 centerTarget, Vector3 practicePosition, Vector3 practiceTarget, Vector3 setupPosition, Vector3 setupTarget) { mCenterPosition = centerPosition; mCenterTarget = centerTarget; mPracticePosition = practicePosition; mPracticeTarget = practiceTarget; mSetupPosition = setupPosition; mSetupTarget = setupTarget; } /// /// Sets the selected minigame as the current minigame via SwitchMode() and cleans up the ModeSelector /// private void LaunchSelectedMiniGame() { HUD.Clear(); Pina.FlushRenderables(); Sparx.Flush(); AstroBaseApplication.SwitchMode(mMiniGameList[mSelectedMiniGame]); } /// /// Selects the next minigame on screen /// private void SelectNextMiniGame() { mThumbnailStrip.SelectNext(); if (mSelectedMiniGame < mMiniGameList.Count -1) mSelectedMiniGame++; else mSelectedMiniGame = 0; } /// /// Selects the previous minigame on screen /// private void SelectPreviousMiniGame() { mThumbnailStrip.SelectPrevious(); if (mSelectedMiniGame > 0) mSelectedMiniGame--; else mSelectedMiniGame = mMiniGameList.Count -1; } } }