//---------------------------------------------------------------------------------------------------------------------------------------------------
//
// Copyright (C)2007 DarkWynter Studios. All rights reserved.
//
//---------------------------------------------------------------------------------------------------------------------------------------------------
// {Contact : darkwynter.com for licensing information
//---------------------------------------------------------------------------------------------------------------------------------------------------
namespace DarkWynter.Engine.Menus
{
#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using DarkWynter.Engine.Init;
using DarkWynter.Engine.Audio;
using DarkWynter.Engine.Globals;
using DarkWynter.Engine.Controllers;
using DarkWynter.Engine.ObjectLib;
using DarkWynter.Stream;
#endregion
///
/// Generic Game Screen.
///
public class GameScreen
{
///
/// Menu Object used by this screen.
///
protected GameMenu menu;
///
/// Stores the EngineState associated with this screen
///
protected Enums_Engine.EngineState 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;
///
/// Game Screen constructor.
///
/// Tells this screen what EngineState it will run under.
public GameScreen(Enums_Engine.EngineState GameEngineState)
{
engineState = GameEngineState;
}
///
/// Returns the Engine State associated with this screen.
///
///
public Enums_Engine.EngineState 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,
new Rectangle(0, 0, Statics_Stream.RenderSettings.GAME_WINDOW_WIDTH, Statics_Stream.RenderSettings.GAME_WINDOW_HEIGHT),
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(ObjectLibrary objectLibrary)
{
//MenuBack();
//MenuStart(objectLibrary);
//MenuUp();
//MenuDown();
//MenuLeft();
//MenuRight();
}
///
/// 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()
{
Audio.MenuDown();
GetMenu().NextMenuElement();
}
///
/// Method invoked when the up menu button has been pressed
///
public virtual void MenuUp()
{
Audio.MenuUp();
GetMenu().PreviousMenuElement();
}
///
/// Method invoked when the start menu button has been pressed
///
/// Object Library
public virtual void MenuStart(ObjectLibrary objectLibrary)
{
bool nextGameState = false;
if (Statics_Engine.SystemSettings.gameState == Enums_Engine.EngineState.FINALIZE_G2LSTUFF)
{
Statics_Engine.SystemSettings.gameState = Enums_Engine.EngineState.TITLE_SCREEN;
}
if (Statics_Engine.SystemSettings.gameState == Enums_Engine.EngineState.GAME_OVER)
{
Statics_Engine.SystemSettings.gameState = Enums_Engine.EngineState.TITLE_SCREEN;
}
if (Statics_Engine.SystemSettings.gameState != Enums_Engine.EngineState.GAME_PAUSE)
{
nextGameState = true;
Statics_Engine.SystemSettings.gameState++;
}
Statics_Engine.SystemSettings.screenSaverTimer.Reset();
Statics_Engine.SystemSettings.screenSaverTimer.Start();
}
///
/// Method invoked when the down menu button has been pressed
///
public virtual void MenuBack()
{
Audio.MenuBack(); // Play a sound
if (Statics_Engine.SystemSettings.gameState != Enums_Engine.EngineState.TITLE_SCREEN &&
Statics_Engine.SystemSettings.gameState != Enums_Engine.EngineState.GAME_OVER)
{
Statics_Engine.SystemSettings.gameState--; // Exit
}
Statics_Engine.SystemSettings.screenSaverTimer.Reset();
Statics_Engine.SystemSettings.screenSaverTimer.Start();
}
///
/// 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();
}
}
}
}
}