/* * StartMenu.cs * Authors: Mike DeMauro * 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.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Util; namespace StellarProspector { /// /// Start menu screen for stellar prospector /// public class StartMenu : GameScreen { #region Fields // The list of strings representing all the menu items in the start menu private List m_MenuItems = new List(); // The index of the currently selected item private int m_ItemSelected; // The sprite batch to render textures private SpriteBatch m_SpriteBatch; // The sprite font to render text private SpriteFont m_SpriteFont; // The input handler to handle any input for the start menu private InputHandler inputHandler; // The texture for the background private Texture2D m_Background; // The texture for the start button private Texture2D m_StartButton; // The texture for the tutorial button private Texture2D m_TutorialButton; // The texture for the quit button private Texture2D m_QuitButton; // The texture for giving a highlight effect over the selected button private Texture2D m_ButtonOverlay; // The color to apply to the Button highlight for transparency private Color m_Transparent; // Whether to increase or decrease the current value of the highlight transparency private bool m_TransModPos; #endregion #region Initialization /// /// Basic initialization /// public override void Initialize() { Util.Settings.LoadFrom(RootDirectory); // Logger setup GetLogger().Initialize(); // Menu Screen input is not relevent to the experiment, and should not be written out the parallel port. inputHandler = GetInputHandler(); m_MenuItems.Add("Play"); m_MenuItems.Add("Tutorial"); m_MenuItems.Add("Main Menu"); inputHandler.Initialize(); inputHandler.BindButton(Keys.Down, Trigger.Activated, (int)EventCodes.Menu_Down); inputHandler.BindButton(Keys.Up, Trigger.Activated, (int)EventCodes.Menu_Up); inputHandler.BindButton(Keys.Enter, Trigger.Activated, (int)EventCodes.Menu_Select); inputHandler.BindButton(Keys.Escape, Trigger.Activated, (int)EventCodes.Menu_Cancel); m_Transparent = Color.White; m_Transparent.A = 100; m_TransModPos = false; base.Initialize(); } /// /// Reinitializes all values that need to be reset /// public override void Reinitialize() { inputHandler.Enable(); Enabled = true; Visible = true; } #endregion #region Management /// /// Loads all content dependent compontents /// protected override void LoadContent() { Util.Settings.ApplyGraphicsChanges(); inputHandler.ForceUpdateWindow(WindowBounds); SoundManager.SoundManager.LoadAudioProject(Content.RootDirectory, @"AudioProject.xgs"); m_SpriteBatch = new SpriteBatch(GraphicsDevice); m_SpriteFont = Content.Load(@"Fonts\menufont"); m_Background = Content.Load(@"TitleScreen\SP_Background"); m_StartButton = Content.Load(@"TitleScreen\SP_Start"); m_TutorialButton = Content.Load(@"TitleScreen\SP_Tutorial"); m_QuitButton = Content.Load(@"TitleScreen\SP_Quit"); m_ButtonOverlay = Content.Load(@"Textures\pixel"); base.LoadContent(); } /// /// Unloads all content dependent components /// protected override void UnloadContent() { SoundManager.SoundManager.UnloadAudioProject(); } /// /// Disposes any needed components /// /// Whether or not currently disposing protected override void Dispose(bool disposing) { if (disposing) { m_SpriteBatch.Dispose(); } base.Dispose(disposing); } #endregion #region Update /// /// Handles updating input and component updates for start menu of stellar prospector /// /// Amount of time that has passed in game public override void Update(GameTime gameTime) { base.Update(gameTime); if (m_TransModPos) { m_Transparent.A++; } else { m_Transparent.A--; } if (m_Transparent.A > 100) { m_TransModPos = false; } else if (m_Transparent.A < 25) { m_TransModPos = true; } while (inputHandler.HasEvent()) { InputEvent e = inputHandler.GetNextEvent(); e.WriteToLog(GetLogger(), "IGNORE SP_Start_Menu_Action"); switch ((EventCodes)e.EventCode) { case EventCodes.Menu_Down: m_ItemSelected = (m_ItemSelected + 1) % m_MenuItems.Count; SoundManager.SoundManager.PlayEffect("Menu_Move"); break; case EventCodes.Menu_Up: m_ItemSelected = (m_ItemSelected - 1 + m_MenuItems.Count) % m_MenuItems.Count; SoundManager.SoundManager.PlayEffect("Menu_Move"); break; case EventCodes.Menu_Select: SoundManager.SoundManager.PlayEffect("Menu_Select"); if (m_MenuItems[m_ItemSelected] == "Play") { Enabled = false; Visible = false; inputHandler.Disable(); Raise(new StellarProspectorGameScreen(Phases.One)); } else if (m_MenuItems[m_ItemSelected] == "Tutorial") { Enabled = false; Visible = false; inputHandler.Disable(); Raise(new StellarProspectorGameScreen(Phases.Tutorial)); } else if (m_MenuItems[m_ItemSelected] == "Main Menu") { Done(); } break; case EventCodes.Menu_Cancel: Done(); break; } } } #endregion #region Render /// /// Renders all components associated with the start menu for steallar prospector /// /// Amount of time that has passed in game public override void Draw(GameTime gameTime) { base.Draw(gameTime); GraphicsDevice.Clear(Color.Black); Vector2 location = new Vector2(100, 50); m_SpriteBatch.Begin(); m_SpriteBatch.Draw(m_Background, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White); m_SpriteBatch.Draw(m_StartButton, new Rectangle(45, 196, 238, 98), Color.White); m_SpriteBatch.Draw(m_TutorialButton, new Rectangle(45, 294, 238, 98), Color.White); m_SpriteBatch.Draw(m_QuitButton, new Rectangle(45, 392, 238, 98), Color.White); m_SpriteBatch.Draw(m_ButtonOverlay, new Rectangle(45, 196 + (98 * m_ItemSelected), 238, 98), m_Transparent); m_SpriteBatch.End(); } #endregion } }