/*
* MainMenuScreen.cs
* Authors: Adam Nabinger
* 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 Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Util;
namespace MaritimeDefender
{
///
/// Defines how the main menu screen for Maritime Defender works
///
internal class MainMenuScreen : MenuScreen
{
#region Creation
Logger mLogger;
///
/// Constructor
///
public MainMenuScreen() : base(null) { }
#endregion
#region Initialization
///
/// Initializes input handling and sets the project directory
///
public override void Initialize()
{
// throws file not found if script not found...
Util.Settings.LoadFrom(RootDirectory);
base.Initialize();
mLogger = GetLogger();
// Enter -> Start Game
inputHandler.BindButton(Keys.Enter, Trigger.Activated, (int)EventCode.MD_MaritimeDefenderGameBegin);
// T -> Tutorial
inputHandler.BindButton(Keys.T, Trigger.Activated, (int)EventCode.MD_TutorialStart);
// Left Mouse Click -> Menu Select
inputHandler.BindButton(MouseButton.Left, Trigger.Activated, (int)EventCode.MD_MenuSelect);
}
///
/// Resets the main menu screen back to the state it was at upon creation
///
public override void Reinitialize()
{
Enabled = true;
Visible = true;
inputHandler.Enable();
}
#endregion
#region Management
///
/// Loads in any necessary information for all content dependent objects
///
protected override void LoadContent()
{
if (Util.Settings.ApplyGraphicsChanges())
{
//return;
}
inputHandler.ForceUpdateWindow(WindowBounds);
SoundManager.SoundManager.UnloadAudioProject();
SoundManager.SoundManager.LoadAudioProject(Content.RootDirectory, @"AudioProject.xgs");
SoundManager.SoundManager.PlayMusic("Maritime Defender Theme");
mBackground = Content.Load(@"MiniGames\MMMenuBackground");
mMousePointer = Content.Load(@"General\StandardCursor");
int screenWidth = GraphicsDevice.Viewport.Width;
int screenHeight = GraphicsDevice.Viewport.Height;
mBackgroundLocation = new Rectangle(0, 0, screenWidth, screenHeight);
mMouseLocation = new Rectangle(0, 0, mMousePointer.Width, mMousePointer.Height);
int buttonWidth = (int)(screenWidth * 0.22f);
int buttonHeight = (int)(screenHeight * 0.09f);
mButtons = new MenuButton[3];
mButtons[0] = new MenuButton(@"MiniGames\MMStartButton", new Rectangle((int)(screenWidth * .01f), (int)(screenHeight * .89f), buttonWidth, buttonHeight), delegate { MaritimeDefender MM = new MaritimeDefender(); Raise(MM); MM.StartGame(); });
mButtons[1] = new MenuButton(@"MiniGames\MMTutorialButton", new Rectangle((int)(screenWidth * .25f), (int)(screenHeight * .89f), buttonWidth, buttonHeight), delegate { MaritimeDefender MM = new MaritimeDefender(); Raise(MM); MM.StartTutorial(); });
mButtons[2] = new MenuButton(@"MiniGames\MMBackButton", new Rectangle((int)(screenWidth * .49f), (int)(screenHeight * .89f), buttonWidth, buttonHeight), delegate { Done(); });
base.LoadContent();
}
///
/// UnloadContent will be called once per game and is the place to unload
/// all content.
///
protected override void UnloadContent()
{
SoundManager.SoundManager.UnloadAudioProject();
}
#endregion
#region Update
///
/// Updates the main menu screen
///
/// Time passed in game
public override void Update(GameTime gameTime)
{
Point tempLocation = inputHandler.MouseLocation;
mMouseLocation.X = tempLocation.X;
mMouseLocation.Y = tempLocation.Y;
while (inputHandler.HasEvent())
{
InputEvent e = inputHandler.GetNextEvent();
switch (e.EventCode)
{
case (int)EventCode.MD_MenuSelect:
foreach (MenuButton b in mButtons)
{
e.WriteToLog(mLogger, "MD_MENU_INPUT_Left_Click X=" + tempLocation.X + " Y=" + tempLocation.Y);
if (b.Location.Contains((e as MouseInputEvent).Location))
{
Enabled = false;
Visible = false;
inputHandler.Disable();
b.Execute(m_Game);
return;
}
}
break;
case (int)EventCode.MD_MenuCancel:
e.WriteToLog(mLogger, "MD_MENU_INPUT_exit");
Done();
return;
case (int)EventCode.MD_MaritimeDefenderGameBegin:
e.WriteToLog(mLogger, "MD_MENU_INPUT_Begin");
Enabled = false;
Visible = false;
inputHandler.Disable();
mButtons[0].Execute(m_Game);
return;
case (int)EventCode.MD_TutorialStart:
e.WriteToLog(mLogger, "MD_MENU_INPUT_TutorialStart");
Enabled = false;
Visible = false;
inputHandler.Disable();
mButtons[1].Execute(m_Game);
return;
}
}
base.Update(gameTime);
}
#endregion
}
}