/*
* DungeonUIScreen.cs
* Authors: Karl Orosz, Brian Chesbrough
* 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 Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Util;
namespace StarJack
{
///
/// This will draw the UI parts of the screen.
///
public class DungeonUIScreen : GameScreen
{
private PlayerObject mPlayer;
public PlayerObject Player
{
get { return mPlayer; }
set
{
mPlayer = value;
foreach (Button b in mButtons)
{
PlayerBasedButton pb = b as PlayerBasedButton;
if (b != null)
{
pb.Player = value;
}
}
mPower.Player = value;
}
}
SpriteBatch mSpriteBatch;
SpriteFont mSpriteFont;
private Logger mLogger;
InputHandler inputHandler;
DungeonScreen mGameArea;
Entity mBack;
Point mMousePos;
Entity mMouse;
private List mDialogList;
private List mButtons;
Viewport mUIPort;
public Viewport UIPort
{
get { return mUIPort; }
set{mUIPort = value;}
}
PowerBar mPower;
TextEntity te;
public DungeonUIScreen(Viewport uiPort, DungeonScreen gameArea)
{
mLogger = GetLogger();
mLogger.Initialize();
mDialogList = new List();
mUIPort = uiPort;
mGameArea = gameArea;
mBack = new Entity("Background");
mBack.TextureName = "UIBack";
mBack.X = 0;
mBack.Y = 0;
mBack.Width = uiPort.Width;
mBack.Height = uiPort.Height;
mBack.Depth = Room.Depth.UI;
mButtons = new List();
Button temp;
Button last;
temp = new HackButton("Hack");
temp.Height = mBack.Height / 20;
temp.Width = mBack.Width / 6;
temp.X = (mBack.Width - temp.Width) / 4;
temp.Y = mBack.Height / 20 * 12;
temp.Depth = Room.Depth.UIButton;
mButtons.Add(temp);
last = temp;
temp = new CloakButton("Cloak");
temp.Height = mBack.Height / 20;
temp.Width = mBack.Width / 6;
temp.X = (mBack.Width - temp.Width) / 4;
temp.Y = last.Y+ last.Height +temp.Height/3 *2;
temp.Depth = Room.Depth.UIButton;
mButtons.Add(temp);
last = temp;
temp = new TrapButton("Trap");
temp.Height = mBack.Height / 20;
temp.Width = mBack.Width /6;
temp.X = (mBack.Width - temp.Width) / 4;
temp.Y = last.Y + last.Height + temp.Height / 3 * 2;
temp.Depth = Room.Depth.UIButton;
mButtons.Add(temp);
last = temp;
temp = new WaitButton("Wait");
temp.Height = mBack.Height / 20;
temp.Width = mBack.Width / 6;
temp.X = (mBack.Width - temp.Width) / 4;
temp.Y = last.Y + last.Height + temp.Height / 3 * 2;
temp.Depth = Room.Depth.UIButton;
mButtons.Add(temp);
last = temp;
//temp = new PDAButton("Controls",this);
//temp.Height = mBack.Height / 20;
//temp.Width = mBack.Width / 6;
//temp.X = (mBack.Width - temp.Width) / 4;
//temp.Y = last.Y + last.Height + temp.Height / 3 * 2;
//temp.Depth = Room.Depth.UIButton;
//mButtons.Add(temp);
//last = temp;
mPower = new PowerBar("power");
mPower.Height = mBack.Height/8;
mPower.Width = mBack.Width/4;
mPower.X = (mBack.Width - mPower.Width) /2;
mPower.Y = mBack.Height/10 *4;
mPower.CalcPos();
te = mPower.AddText("Power", "dialogFont", Microsoft.Xna.Framework.Graphics.Color.White, Microsoft.Xna.Framework.Graphics.Color.Black, Button.Orientation.ToTheLeft, 1.5f);
te.Depth = Room.Depth.UIText;
te.Height = mPower.Height/5;
te.Y = mPower.Y + mPower.Height / 2 - te.Height / 2; ;
}
///
/// 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()
{
inputHandler = GetInputHandler();
inputHandler.Initialize();
inputHandler.BindButton(Keys.Escape, Trigger.Activated, (int)EventCode.GamePause);
inputHandler.BindButton(MouseButton.Left, Trigger.Activated, (int)SJInputEvent.Click);
mMousePos = Point.Zero;
mMouse = new Entity("Mouse");
mMouse.TextureName = "Cursor";
mMouse.Width = 32;
mMouse.Height = 32;
mMouse.X = (int)(mMousePos.X);
mMouse.Y = (int)(mMousePos.Y);
mMouse.Depth = Room.Depth.Mouse;
foreach (Button b in mButtons)
{
b.Initialize();
}
base.Initialize();
}
///
/// 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);
mSpriteFont = Content.Load(@"Fonts\dialogfont");
mBack.LoadContent(Content);
mMouse.LoadContent(Content);
foreach (Button b in mButtons)
{
b.LoadContent(Content);
}
mPower.LoadContent(Content);
te.LoadContent(Content);
base.LoadContent();
}
///
/// UnloadContent will be called once per game and is the place to unload
/// all content.
///
protected override void UnloadContent()
{
}
public override void Reinitialize()
{
inputHandler.Enable();
inputHandler.ClearEvents();
this.Enabled = true;
this.Visible = true;
mGameArea.Reinitialize();
}
protected override void Dispose(bool disposing)
{
//Console.WriteLine("Example menu screen disposing");
if (disposing)
{
inputHandler.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)
{
mMousePos = GameScreen.MouseViewportLocation(inputHandler.MouseLocation, mUIPort);
mMouse.X = (int)(mMousePos.X);
mMouse.Y = (int)(mMousePos.Y);
bool mouseClicked = false;
base.Update(gameTime);
if (mPlayer.MyRoom.State != Room.GameState.TurnRoutines)
{
while (inputHandler.HasEvent())
{
InputEvent e = inputHandler.GetNextEvent();
switch (e.EventCode)
{
case (int)(EventCode.GamePause):
e.WriteToLog(mLogger, "SJ_INPUT_Esc");
mLogger.Dispose();
Done();
mGameArea.End();
break;
case(int)(SJInputEvent.Click):
e.WriteToLog(mLogger, "SJ_INPUT_LeftClick X=" + mMousePos.X + " Y=" + mMousePos.Y);
mouseClicked = true;
break;
}
}
foreach (Button b in mButtons)
{
b.Update(gameTime, mMousePos, mouseClicked);
}
if (mDialogList.Count > 0)
{
Raise(new DialogScreen(mDialogList));
inputHandler.Disable();
mDialogList.Clear();
}
mPower.Update(gameTime);
}
}
///
/// This is called when the game should draw itself.
///
/// Provides a snapshot of timing values.
public override void Draw(GameTime gameTime)
{
Viewport previous = GraphicsDevice.Viewport;
mSpriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.BackToFront, SaveStateMode.None);
//Draw UI Elements
GraphicsDevice.Viewport = mUIPort;
GraphicsDevice.Clear(Color.Black);
mBack.Draw(mSpriteBatch);
foreach (Button b in mButtons)
{
b.Draw(mSpriteBatch);
}
mPower.Draw(mSpriteBatch);
te.Draw(mSpriteBatch);
mMouse.Draw(mSpriteBatch);
mSpriteBatch.End();
GraphicsDevice.Viewport = previous;
}
public void RaiseScreen(GameScreen gs){
inputHandler.Disable();
Enabled = false;
Raise(gs);
}
}
}