//---------------------------------------------------------------------------------------------------------------------------------------------------
//
// Copyright (C)2007 DarkWynter Studios. All rights reserved.
//
//---------------------------------------------------------------------------------------------------------------------------------------------------
// {Contact : darkwynter.com for licensing information
//---------------------------------------------------------------------------------------------------------------------------------------------------
namespace DWControllerDemo
{
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using DarkWynter.Engine;
using DarkWynter.Engine.Controllers;
using DWControllerDemo;
using DWGame;
using DWGame.Globals;
using DW.Stream;
///
/// Menu Controller for getting player inputs for the menu system
///
public class MenuController : Controller
{
///
/// Constructor
///
/// Player index for this controller
public MenuController(int playerNumber)
: base(playerNumber)
{
Add(new KeyboardControl(Keys.Escape, Escape, 100));
Add(new KeyboardControl(Keys.Enter, MenuStart, 200));
Add(new KeyboardControl(Keys.Up, MenuUp, 200));
Add(new KeyboardControl(Keys.Down, MenuDown, 200));
Add(new KeyboardControl(Keys.Left, MenuLeft, 200));
Add(new KeyboardControl(Keys.Right, MenuRight, 200));
}
///
/// Constructor for Xbox only controls
///
/// Controller index
public MenuController(PlayerIndex playerIndex)
: base(playerIndex)
{
// Add Xbox controls
}
///
/// Constructor for Xbox and keyboard controls
///
/// Player index in ObjectLibrary
/// Player index for this controller
public MenuController(int player, PlayerIndex playerIndex)
: base(player, playerIndex)
{
Add(new KeyboardControl(Keys.Escape, Escape, 100));
Add(new KeyboardControl(Keys.Enter, MenuStart, 200));
Add(new KeyboardControl(Keys.Up, MenuUp, 0));
Add(new KeyboardControl(Keys.Down, MenuDown, 0));
Add(new KeyboardControl(Keys.Left, MenuLeft, 0));
Add(new KeyboardControl(Keys.Right, MenuRight, 0));
// Add xbox controls
}
private void Escape(ControllerBoolEventArgs args)
{
Statics._self.Exit();
}
private void MenuStart(ControllerBoolEventArgs args)
{
for (int i = 0; i < Window.menuSystem.gameScreens.Count; i++)
{
// Update appropriate menu screen
if (Statics.menuState == Window.menuSystem.gameScreens[i].GetEngineState())
{
Window.menuSystem.gameScreens[i].MenuStart(i + 1);
break;
}
}
}
#region Directinal Menu controls - only work if you have menu elements, if not crash...need to fix this HACK
private void MenuUp(ControllerBoolEventArgs args)
{
for (int i = 0; i < Window.menuSystem.gameScreens.Count; i++)
{
// Update appropriate menu screen
if (Statics.menuState == Window.menuSystem.gameScreens[i].GetEngineState())
{
Window.menuSystem.gameScreens[i].MenuUp();
break;
}
}
}
private void MenuDown(ControllerBoolEventArgs args)
{
for (int i = 0; i < Window.menuSystem.gameScreens.Count; i++)
{
// Update appropriate menu screen
if (Statics.menuState == Window.menuSystem.gameScreens[i].GetEngineState())
{
Window.menuSystem.gameScreens[i].MenuDown();
break;
}
}
}
private void MenuLeft(ControllerBoolEventArgs args)
{
for (int i = 0; i < Window.menuSystem.gameScreens.Count; i++)
{
// Update appropriate menu screen
if (Statics.menuState == Window.menuSystem.gameScreens[i].GetEngineState())
{
Window.menuSystem.gameScreens[i].MenuLeft();
break;
}
}
}
private void MenuRight(ControllerBoolEventArgs args)
{
for (int i = 0; i < Window.menuSystem.gameScreens.Count; i++)
{
// Update appropriate menu screen
if (Statics.menuState == Window.menuSystem.gameScreens[i].GetEngineState())
{
Window.menuSystem.gameScreens[i].MenuRight();
break;
}
}
}
#endregion
}
}