public bool DoJoystickEvent( JoystickInputEvent e )
{
//JoystickButtonDownEvent
{
JoystickButtonDownEvent evt = e as JoystickButtonDownEvent;
if( evt != null )
{
bool handled = false;
//!!!!!slowly
foreach( GameControlItem item in items )
{
//!!!!!need use binded values here
foreach( SystemJoystickValue value in item.DefaultJoystickValues )
{
if( value.Type == SystemJoystickValue.Types.Button &&
value.Button == evt.Button.Name )
{
if( GameControlsEvent != null )
{
GameControlsEvent( new GameControlsKeyDownEventData(
item.ControlKey, 1 ) );
}
handled = true;
}
}
}
return handled;
}
}
//JoystickButtonUpEvent
{
JoystickButtonUpEvent evt = e as JoystickButtonUpEvent;
if( evt != null )
{
bool handled = false;
//!!!!!slowly
foreach( GameControlItem item in items )
{
//!!!!!need use binded values here
foreach( SystemJoystickValue value in item.DefaultJoystickValues )
{
if( value.Type == SystemJoystickValue.Types.Button &&
value.Button == evt.Button.Name )
{
if( GameControlsEvent != null )
GameControlsEvent( new GameControlsKeyUpEventData( item.ControlKey ) );
handled = true;
}
}
}
return handled;
}
}
//JoystickAxisChangedEvent
{
JoystickAxisChangedEvent evt = e as JoystickAxisChangedEvent;
if( evt != null )
{
bool handled = false;
//!!!!!slowly
foreach( GameControlItem item in items )
{
//!!!!!need use binded values here
foreach( SystemJoystickValue value in item.DefaultJoystickValues )
{
if( value.Type == SystemJoystickValue.Types.Axis &&
value.Axis == evt.Axis.Name )
{
float strength = 0;
//!!!!need change in the options
const float deadZone = .2f;// 20%
switch( value.AxisFilter )
{
case JoystickAxisFilters.LessZero:
if( evt.Axis.Value < -deadZone )
strength = -evt.Axis.Value;
break;
case JoystickAxisFilters.GreaterZero:
if( evt.Axis.Value > deadZone )
strength = evt.Axis.Value;
break;
}
if( strength != 0 )
{
if( GameControlsEvent != null )
{
GameControlsEvent( new GameControlsKeyDownEventData(
item.ControlKey, strength ) );
}
}
else
{
if( GameControlsEvent != null )
{
GameControlsEvent( new GameControlsKeyUpEventData(
item.ControlKey ) );
}
}
handled = true;
}
}
}
return handled;
}
}
//JoystickPOVChangedEvent
{
JoystickPOVChangedEvent evt = e as JoystickPOVChangedEvent;
if( evt != null )
{
bool handled = false;
//!!!!!slowly
foreach( GameControlItem item in items )
{
//!!!!!need use binded values here
foreach( SystemJoystickValue value in item.DefaultJoystickValues )
{
if( value.Type == SystemJoystickValue.Types.POV &&
value.POV == evt.POV.Name )
{
if( ( value.POVDirection & evt.POV.Value ) != 0 )
{
if( GameControlsEvent != null )
{
GameControlsEvent( new GameControlsKeyDownEventData(
item.ControlKey, 1 ) );
}
}
else
{
if( GameControlsEvent != null )
{
GameControlsEvent( new GameControlsKeyUpEventData(
item.ControlKey ) );
}
}
handled = true;
}
}
}
return handled;
}
}
//JoystickSliderChangedEvent
{
JoystickSliderChangedEvent evt = e as JoystickSliderChangedEvent;
if( evt != null )
{
//..
}
}
return false;
}