/*
* StarJack.cs
* Authors: Karl Orosz, Brian Chesborough
* 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.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using tAC_Engine.Graphics.Cameras;
using tAC_Engine.Graphics.Entities;
using tAC_Engine.Graphics;
using Util;
namespace StarJack
{
///
/// This is the main type for your game
///
public class StarJack : GameScreen
{
public static String TextureDirectory = @"Texture\";
List mMenuItems = new List();
int mItemSelected = 0;
SpriteBatch mSpriteBatch;
SpriteFont mSpriteFont;
public int curWorld;
public int curLevel;
public int curRoom;
private Logger mLogger;
List textl;
EntitySprite mBackground;
EntitySprite text;
EntitySprite curs;
InputHandler inputHandler;
//The list of the components that this screen will own
List mComponents;
public StarJack()
{
mLogger = GetLogger();
mLogger.Initialize();
mLogger.Write((int)EventCode.Start, "SJ_START");
// base.IsMouseVisible = true;
}
private string mLevelFilePath;
public StarJack(string levelFilePath)
{
mLevelFilePath = levelFilePath;
mLogger = GetLogger();
mLogger.Initialize();
mLogger.Write((int)EventCode.Start, "SJ_START");
// base.IsMouseVisible = true;
}
///
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
///
public override void Initialize()
{
Entity.RootDirectory = RootDirectory;
mComponents = new List();
inputHandler = GetInputHandler();
mMenuItems.Add("Start");
mMenuItems.Add("Tutorial");
mMenuItems.Add("Hack");
mMenuItems.Add("Sally Anne");
mMenuItems.Add("Exit");
inputHandler.Initialize();
inputHandler.BindButton(Keys.Right, Trigger.Activated, (int)EventCode.MenuRight);
inputHandler.BindButton(Keys.Left, Trigger.Activated, (int)EventCode.MenuLeft);
inputHandler.BindButton(Keys.Enter, Trigger.Activated, (int)EventCode.ConsoleEnter);
inputHandler.BindButton(MouseButton.Left, Trigger.Activated, (int)EventCode.MenuSelect);
// inputHandler.Bind(Keys.Escape, Trigger.Pressed, (int)EventCode.MenuCancel);
mBackground = new EntitySprite(Content, @"Texture\StarJack_Main");
mBackground.Position = Vector2.Zero;
mBackground.DrawOrder = -1;
mBackground.Initialize();
text = new EntitySprite(Content, @"Texture\StarJack_Main");
text.Position = Vector2.Zero;
text.DrawOrder = 0;
text.Initialize();
curs = new EntitySprite(Content, @"Texture\Cursor");
curs.BlendMode = SpriteBlendMode.AlphaBlend;
curs.DrawOrder = 1;
mComponents.Add(curs);
mComponents.Add(mBackground);
base.Initialize();
curs.SpriteBatch = mSpriteBatch;
mBackground.SpriteBatch = mSpriteBatch;
text.SpriteBatch = mSpriteBatch;
curs.Visible = true;
curs.Width = 50;
curs.Height = 50;
curs.Initialize();
Vector2 location = new Vector2(this.GraphicsDevice.Viewport.X + this.GraphicsDevice.Viewport.Width / 10,
this.GraphicsDevice.Viewport.Height / 10 * 8);
textl = new List();
//mSpriteBatch.DrawString(mSpriteFont, StarJackInfo.Name, shadow, Color.Black);
//mSpriteBatch.DrawString(mSpriteFont, StarJackInfo.Name, location, Color.BurlyWood);
float x = (this.GraphicsDevice.Viewport.Width / 10 * 8) / (float)(mMenuItems.Count);
float y = this.GraphicsDevice.Viewport.Height / 10;
for (int i = 0; i < mMenuItems.Count; i++)
{
text = new EntitySprite(Content, "");
text.DrawOrder = 0;
text.TextureName = @"Texture\" + mMenuItems[i] + "BTN";
text.Initialize();
text.Texture = Content.Load(text.TextureName);
text.TextureCenter = new Vector2(text.Texture.Width >> 1, text.Texture.Height >> 1);
text.Radius = Vector2.Distance(Vector2.Zero, text.TextureCenter);
Rectangle dest = new Rectangle();
dest.Width = (int)x;
dest.Height = (int)y;
text.Height = (int)y;
text.Width = (int)x;
text.BlendMode = SpriteBlendMode.AlphaBlend;
text.Destination = dest;
// text.Texture = Content.Load(text.TextureName);
text.Visible = true;
text.Position = new Vector2(location.X, location.Y);
location.X += x;
text.SpriteBatch = mSpriteBatch;
mComponents.Add(text);
textl.Add(text);
}
#if DEBUG
ShowFPS();
#endif
}
///
/// LoadContent will be called once per game and is the place to load
/// all of your content.
///
protected override void LoadContent()
{
mSpriteBatch = new SpriteBatch(GraphicsDevice);
foreach (GameComponent gc in mComponents)
{
EntitySprite s = gc as EntitySprite;
if (s != null)
{
s.SpriteBatch = mSpriteBatch;
}
}
// mSpriteFont = Content.Load(@"Fonts\menufont");
//GraphicsDeviceManager.ToggleFullScreen();
base.LoadContent();
}
///
/// UnloadContent will be called once per game and is the place to unload
/// all content.
///
protected override void UnloadContent()
{
base.UnloadContent();
}
public override void Reinitialize()
{
inputHandler.Enable();
this.Enabled = true;
this.Visible = true;
}
protected override void Dispose(bool disposing)
{
//Console.WriteLine("Example menu screen disposing");
if (disposing)
{
mBackground.Dispose();
mSpriteBatch.Dispose();
}
base.Dispose(disposing);
}
///
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
///
/// Provides a snapshot of timing values.
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
curs.X = inputHandler.MouseLocation.X;
curs.Y = inputHandler.MouseLocation.Y;
while (inputHandler.HasEvent())
{
InputEvent e = inputHandler.GetNextEvent();
switch ((EventCode)e.EventCode)
{
case EventCode.MenuRight:
mItemSelected = (mItemSelected + 1) % mMenuItems.Count;
e.WriteToLog(mLogger, "SJ_MENU_INPUT_Right");
//SoundManager.SoundManager.PlayEffect("Menu_Move");
break;
case EventCode.MenuLeft:
mItemSelected = (mItemSelected - 1 + mMenuItems.Count) % mMenuItems.Count;
e.WriteToLog(mLogger, "SJ_MENU_INPUT_Left");
//SoundManager.SoundManager.PlayEffect("Menu_Move");
break;
case EventCode.MenuSelect:
e.WriteToLog(mLogger, "SJ_MENU_INPUT_MouseClick");
if (inputHandler.MouseLocation.X >= textl[mItemSelected].X && inputHandler.MouseLocation.X <= textl[mItemSelected].X + textl[mItemSelected].Width
&& inputHandler.MouseLocation.Y >= textl[mItemSelected].Y && inputHandler.MouseLocation.Y <= textl[mItemSelected].Y + textl[mItemSelected].Height)
{
MenuSelect(e);
}
break;
case EventCode.ConsoleEnter:
//SoundManager.SoundManager.PlayEffect("Menu_Select");
e.WriteToLog(mLogger, "SJ_MENU_INPUT_Enter");
MenuSelect(e);
break;
case EventCode.MenuCancel:
Done();
break;
}
}
}
public void MenuSelect(InputEvent e)
{
if (mMenuItems[mItemSelected] == "Start")
{
inputHandler.Disable();
this.Enabled = false;
this.Visible = false;
Raise(new DungeonScreen(mLevelFilePath, GraphicsDevice.Viewport, false));
return;
}
else if (mMenuItems[mItemSelected] == "Hack")
{
inputHandler.Disable();
this.Enabled = false;
this.Visible = false;
Raise(new HackingPhaseScreen(12));
return;
}
else if (mMenuItems[mItemSelected] == "Sally Anne")
{
inputHandler.Disable();
this.Enabled = false;
this.Visible = false;
Raise(new SallyAnneScreen());
return;
}
else if (mMenuItems[mItemSelected] == "Exit")
{
e.WriteToLog(mLogger, "SJ_END_QUIT");
Done();
}
else if (mMenuItems[mItemSelected] == "Tutorial")
{
inputHandler.Disable();
this.Enabled = false;
this.Visible = false;
Raise(new DungeonScreen(mLevelFilePath, GraphicsDevice.Viewport,true));
return;
}
}
///
/// This is called when the game should draw itself.
///
/// Provides a snapshot of timing values.
public override void Draw(GameTime gameTime)
{
base.Draw(gameTime);
mBackground.Draw(gameTime);
int mouseSelected = -1;
for (int i = 0; i < textl.Count; i++)
{
if (inputHandler.MouseLocation.X >= textl[i].X && inputHandler.MouseLocation.X <= textl[i].X + textl[i].Width
&& inputHandler.MouseLocation.Y >= textl[i].Y && inputHandler.MouseLocation.Y <= textl[i].Y + textl[i].Height)
{
mouseSelected = i;
}
}
if (mouseSelected != -1)
{
mItemSelected = mouseSelected;
}
textl[mItemSelected].TextureName += "roll";
textl[mItemSelected].Texture = Content.Load(textl[mItemSelected].TextureName);
foreach (EntitySprite s in textl)
{
s.Draw(gameTime);
}
textl[mItemSelected].TextureName = textl[mItemSelected].TextureName.Substring(0, textl[mItemSelected].TextureName.Length - 4);
textl[mItemSelected].Texture = Content.Load(textl[mItemSelected].TextureName);
curs.Draw(gameTime);
}
}
}