//---------------------------------------------------------------------------------------------------------------------------------------------------
//
// Copyright (C)2007 DarkWynter Studios. All rights reserved.
//
//---------------------------------------------------------------------------------------------------------------------------------------------------
// {Contact : darkwynter.com for licensing information
//---------------------------------------------------------------------------------------------------------------------------------------------------
namespace DarkWynter.Engine.Menus
{
#region Using Statements
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using DWGame.Globals;
#endregion
///
/// Generic Game Screen.
///
public class GameScreen: Game
{
///
/// Menu Object used by this screen.
///
protected GameMenu menu;
///
/// Stores the EngineState associated with this screen
///
protected Enums_Engine.MenuState engineState;
///
/// Background texture used by this screen.
///
protected Texture2D backgroundTexture;
///
/// Overlay Graphics list drawn from first to last.
///
protected List graphics;
///
/// Alpha value to draw this screen with.
///
protected float backgroundAlpha = 1.0f;
///
/// String location of the screen
///
protected string backgroundTexturePath;
///
/// Location of the image on the screen
///
protected Rectangle drawRectangle;
protected float alpha;
protected Enums_Engine.MenuState menuState;
protected Enums_Engine.EngineState eState;
protected bool hasSprites;
protected bool hasMenu;
protected Texture2D bgTexture;
///
/// Game Screen constructor.
///
/// Tells this screen what EngineState it will run under.
public GameScreen(Enums_Engine.MenuState GameEngineState)
{
engineState = GameEngineState;
}
///
/// Returns the Engine State associated with this screen.
///
///
public Enums_Engine.MenuState GetEngineState()
{
return engineState;
}
///
/// Returns the game menu.
///
/// This screen's game menu.
public GameMenu GetMenu()
{
return menu;
}
///
/// Set the background texture
///
/// Texture used in background.
public void SetBackground(Texture2D backgroundTexture)
{
this.backgroundTexture = backgroundTexture;
backgroundAlpha = 1.0f;
}
///
/// Set the background texture with a specific alpha value.
///
/// Texture used in background.
/// Alpha value used to draw.
public void SetBackground(Texture2D backgroundTexture, float alpha)
{
this.backgroundTexture = backgroundTexture;
backgroundAlpha = alpha;
}
public void SetAlpha(float alpha)
{
backgroundAlpha = alpha;
}
///
/// Draw this game screen.
///
/// SpriteBatch used to draw used to draw.
public virtual void Draw(SpriteBatch spriteBatch)
{
// First draw the background texture if it is not null
if (backgroundTexture != null)
{
spriteBatch.Draw(backgroundTexture, this.drawRectangle,
new Color(255, 255, 255, (byte)(255 * backgroundAlpha)));
}
//now draw the menu elements
menu.Draw(spriteBatch);
}
///
/// Check to see if menu has been updated by user.
///
/// Current ObjectLibrary.
public virtual void Update()
{
}
///
/// Method invoked when the right menu button has been pressed
///
public virtual void MenuRight()
{
UpdateMenuController(GetMenu().GetActiveMenuElement(), Enums_Engine.MenuDirection.RIGHT);
}
///
/// Method invoked when the left menu button has been pressed
///
public virtual void MenuLeft()
{
UpdateMenuController(GetMenu().GetActiveMenuElement(), Enums_Engine.MenuDirection.LEFT);
}
///
/// Method invoked when the down menu button has been pressed
///
public virtual void MenuDown()
{
GetMenu().NextMenuElement();
}
///
/// Method invoked when the up menu button has been pressed
///
public virtual void MenuUp()
{
GetMenu().PreviousMenuElement();
}
///
/// Method invoked when the start menu button has been pressed
///
/// Object Library
public virtual void MenuStart(int index)
{
bool nextGameState = false;
if (Statics.menuState == Enums_Engine.MenuState.FINALIZE_G2LSTUFF)
{
Statics.menuState = Enums_Engine.MenuState.TITLE_SCREEN;
}
if (Statics.menuState == Enums_Engine.MenuState.GAME_OVER)
{
Statics.menuState = Enums_Engine.MenuState.TITLE_SCREEN;
}
if (DW.Stream.Window.menuSystem.gameScreens[index].engineState == Enums_Engine.MenuState.LOAD_LEVEL)
{
Statics.engineState = Enums_Engine.EngineState.GAME_MODE;
}
if (Statics.menuState != Enums_Engine.MenuState.GAME_PAUSE)
{
nextGameState = true;
Statics.menuState++;
}
// Commit Game and Player
if (Statics.menuState == Enums_Engine.MenuState.LOAD_LEVEL && nextGameState)
{
// DarkWynterEngine.Load_LevelIndex();
}
}
///
/// Method invoked when the down menu button has been pressed
///
public virtual void MenuBack()
{
if (Statics.menuState != Enums_Engine.MenuState.TITLE_SCREEN &&
Statics.menuState != Enums_Engine.MenuState.GAME_OVER)
{
Statics.menuState--; // Exit
}
}
///
/// Update the active element based on user input
///
/// Active menu element
/// Menu direction key that was pressed
private void UpdateMenuController(GameMenuElement activeElement, Enums_Engine.MenuDirection menuDirection)
{
// OptionBox
if (activeElement.GetElementType() == Enums_Engine.MenuElementType.OPTION)
{
// Cast as option and change value
GameMenuOption option = (GameMenuOption)activeElement;
// If they pressed left, get previous option
if (menuDirection == Enums_Engine.MenuDirection.LEFT)
{
//Audio.MenuLeft();
option.PreviousOption();
}
// Or if they pressed right, get next option
else if (menuDirection == Enums_Engine.MenuDirection.RIGHT)
{
// Audio.MenuRight();
option.NextOption();
}
}
// ValueSlider
else if (activeElement.GetElementType() == Enums_Engine.MenuElementType.VALUE)
{
// Cast as ValueInput type and change value
GameMenuValueInput valueInput = (GameMenuValueInput)activeElement;
//int activeIndex = playerSetup.GetMenu().GetActiveIndex();
// If they pressed left, decrease the value
if (menuDirection == Enums_Engine.MenuDirection.LEFT)
{
//Audio.MenuLeft();
valueInput.Decrement();
}
// Or if they pressed right, increase it
else if (menuDirection == Enums_Engine.MenuDirection.RIGHT)
{
//Audio.MenuRight();
valueInput.Increment();
}
}
else if (activeElement.GetElementType() == Enums_Engine.MenuElementType.IMAGE_SCROLL)
{
// Cast as ValueInput type and change value
GameMenuImageScroller scroller = (GameMenuImageScroller)activeElement;
//int activeIndex = playerSetup.GetMenu().GetActiveIndex();
// If they pressed left, decrease the value
if (menuDirection == Enums_Engine.MenuDirection.LEFT)
{
//Audio.MenuLeft();
scroller.PreviousItem();
}
// Or if they pressed right, increase it
else if (menuDirection == Enums_Engine.MenuDirection.RIGHT)
{
// Audio.MenuRight();
scroller.NextItem();
}
}
}
}
}