//---------------------------------------------------------------------------------------------------------------------------------------------------
//
// Copyright (C)2007 DarkWynter Studios. All rights reserved.
//
//---------------------------------------------------------------------------------------------------------------------------------------------------
// {Contact : darkwynter.com for licensing information
//---------------------------------------------------------------------------------------------------------------------------------------------------
namespace DarkWynter.Engine.Controllers
{
#region Using Statements
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using System.Diagnostics;
using DarkWynter.Engine.ObjectLib;
using DarkWynter.Engine.Menus;
using Globals;
#endregion
///
/// Xbox digital event class for mapping a digital button/motion to an event
///
public class XboxDigitalControl
{
// Time delay between key presses to avoid double input
private int KEY_TIMER_MAX_MILLI = 100;
private Stopwatch controlTimer = new Stopwatch();
//Button we are checking for
private Buttons button;
///
/// On click delegate type
///
/// Controller boolean event arguments
public delegate void OnClickHandler(ControllerBoolEventArgs args);
private event OnClickHandler click;
///
/// Click constructor
///
/// Click control type
/// Click handler
/// Time delay between multiple invocations
public XboxDigitalControl(Buttons xboxbutton, OnClickHandler onClickHandler, int timerValue)
{
button = xboxbutton;
click += new OnClickHandler(onClickHandler);
controlTimer.Start();
KEY_TIMER_MAX_MILLI = timerValue;
}
///
/// Update Method
///
/// Updated game pad state
/// Object Library
/// Menu System
public void Update(GamePadState gamePadState, ref ObjectLibrary objectLibrary, ref MenuSystem menuSystem)
{
// Check double-input timer
if (controlTimer.ElapsedMilliseconds > KEY_TIMER_MAX_MILLI)
{
// Reset Timer
controlTimer.Reset();
controlTimer.Start();
// If button was pressed
if (gamePadState.IsButtonDown(button))
{
if (click != null)
{
click(new ControllerBoolEventArgs(true, ref objectLibrary, ref menuSystem));
}
}
}
}
}
}