Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements trigger vibrations on UWP and add overloads #6933

Merged
merged 1 commit into from
Nov 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions MonoGame.Framework/Input/GamePad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,21 @@ public static GamePadState GetState(int index, GamePadDeadZone leftDeadZoneMode,
/// <returns>Returns true if the vibration motors were set.</returns>
public static bool SetVibration(PlayerIndex playerIndex, float leftMotor, float rightMotor)
{
return SetVibration((int)playerIndex, leftMotor, rightMotor);
return SetVibration((int)playerIndex, leftMotor, rightMotor, 0.0f, 0.0f);
}

/// <summary>
/// Sets the vibration motor speeds on the controller device if supported.
/// </summary>
/// <param name="playerIndex">Player index that identifies the controller to set.</param>
/// <param name="leftMotor">The speed of the left motor, between 0.0 and 1.0. This motor is a low-frequency motor.</param>
/// <param name="rightMotor">The speed of the right motor, between 0.0 and 1.0. This motor is a high-frequency motor.</param>
/// <param name="leftTrigger">(Xbox One controller only) The speed of the left trigger motor, between 0.0 and 1.0. This motor is a high-frequency motor.</param>
/// <param name="rightTrigger">(Xbox One controller only) The speed of the right trigger motor, between 0.0 and 1.0. This motor is a high-frequency motor.</param>
/// <returns>Returns true if the vibration motors were set.</returns>
public static bool SetVibration(PlayerIndex playerIndex, float leftMotor, float rightMotor, float leftTrigger, float rightTrigger)
{
return SetVibration((int)playerIndex, leftMotor, rightMotor, leftTrigger, rightTrigger);
}

/// <summary>
Expand All @@ -127,11 +141,25 @@ public static bool SetVibration(PlayerIndex playerIndex, float leftMotor, float
/// <param name="rightMotor">The speed of the right motor, between 0.0 and 1.0. This motor is a high-frequency motor.</param>
/// <returns>Returns true if the vibration motors were set.</returns>
public static bool SetVibration(int index, float leftMotor, float rightMotor)
{
return SetVibration(index, leftMotor, rightMotor, 0.0f, 0.0f);
}

/// <summary>
/// Sets the vibration motor speeds on the controller device if supported.
/// </summary>
/// <param name="index">Index for the controller you want to query.</param>
/// <param name="leftMotor">The speed of the left motor, between 0.0 and 1.0. This motor is a low-frequency motor.</param>
/// <param name="rightMotor">The speed of the right motor, between 0.0 and 1.0. This motor is a high-frequency motor.</param>
/// <param name="leftTrigger">(Xbox One controller only) The speed of the left trigger motor, between 0.0 and 1.0. This motor is a high-frequency motor.</param>
/// <param name="rightTrigger">(Xbox One controller only) The speed of the right trigger motor, between 0.0 and 1.0. This motor is a high-frequency motor.</param>
/// <returns>Returns true if the vibration motors were set.</returns>
public static bool SetVibration(int index, float leftMotor, float rightMotor, float leftTrigger, float rightTrigger)
{
if (index < 0 || index >= PlatformGetMaxNumberOfGamePads())
return false;
return PlatformSetVibration(index, MathHelper.Clamp(leftMotor, 0.0f, 1.0f), MathHelper.Clamp(rightMotor, 0.0f, 1.0f));

return PlatformSetVibration(index, MathHelper.Clamp(leftMotor, 0.0f, 1.0f), MathHelper.Clamp(rightMotor, 0.0f, 1.0f), MathHelper.Clamp(leftTrigger, 0.0f, 1.0f), MathHelper.Clamp(rightTrigger, 0.0f, 1.0f));
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion MonoGame.Framework/Platform/Input/GamePad.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private static GamePadState PlatformGetState(int index, GamePadDeadZone leftDead
return state;
}

private static bool PlatformSetVibration(int index, float leftMotor, float rightMotor)
private static bool PlatformSetVibration(int index, float leftMotor, float rightMotor, float leftTrigger, float rightTrigger)
{
var gamePad = GamePads[index];
if (gamePad == null)
Expand Down
2 changes: 1 addition & 1 deletion MonoGame.Framework/Platform/Input/GamePad.SDL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ private static GamePadState PlatformGetState(int index, GamePadDeadZone leftDead
return ret;
}

private static bool PlatformSetVibration(int index, float leftMotor, float rightMotor)
private static bool PlatformSetVibration(int index, float leftMotor, float rightMotor, float leftTrigger, float rightTrigger)
{
if (!Gamepads.ContainsKey(index))
return false;
Expand Down
6 changes: 3 additions & 3 deletions MonoGame.Framework/Platform/Input/GamePad.UWP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private static GamePadState PlatformGetState(int index, GamePadDeadZone leftDead
return result;
}

private static bool PlatformSetVibration(int index, float leftMotor, float rightMotor)
private static bool PlatformSetVibration(int index, float leftMotor, float rightMotor, float leftTrigger, float rightTrigger)
{
if (!_gamepads.ContainsKey(index))
return false;
Expand All @@ -159,9 +159,9 @@ private static bool PlatformSetVibration(int index, float leftMotor, float right
gamepad.Vibration = new WGI.GamepadVibration
{
LeftMotor = leftMotor,
LeftTrigger = leftMotor,
LeftTrigger = leftTrigger,
RightMotor = rightMotor,
RightTrigger = rightMotor
RightTrigger = rightTrigger
};

return true;
Expand Down
2 changes: 1 addition & 1 deletion MonoGame.Framework/Platform/Input/GamePad.Web.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private static GamePadState PlatformGetState(int index, GamePadDeadZone leftDead
return state;
}

private static bool PlatformSetVibration(int index, float leftMotor, float rightMotor)
private static bool PlatformSetVibration(int index, float leftMotor, float rightMotor, float leftTrigger, float rightTrigger)
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion MonoGame.Framework/Platform/Input/GamePad.XInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ private static GamePadButtons ConvertToButtons(SharpDX.XInput.GamepadButtonFlags
return new GamePadButtons(ret);
}

private static bool PlatformSetVibration(int index, float leftMotor, float rightMotor)
private static bool PlatformSetVibration(int index, float leftMotor, float rightMotor, float leftTrigger, float rightTrigger)
{
if (!_connected[index])
{
Expand Down
2 changes: 1 addition & 1 deletion MonoGame.Framework/Platform/Input/GamePad.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private static GamePadState PlatformGetState(int index, GamePadDeadZone leftDead
return state;
}

private static bool PlatformSetVibration(int index, float leftMotor, float rightMotor)
private static bool PlatformSetVibration(int index, float leftMotor, float rightMotor, float leftTrigger, float rightTrigger)
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion MonoGame.Framework/Platform/Input/GamePad.tvOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private static GamePadState PlatformGetState(int index, GamePadDeadZone leftDead
return state;
}

private static bool PlatformSetVibration(int index, float leftMotor, float rightMotor)
private static bool PlatformSetVibration(int index, float leftMotor, float rightMotor, float leftTrigger, float rightTrigger)
{
return false;
}
Expand Down