Skip to content

Commit

Permalink
Added more button methods for ButtonPosition.
Browse files Browse the repository at this point in the history
  • Loading branch information
vchelaru committed Nov 18, 2023
1 parent c6542b2 commit 684a557
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions Engines/FlatRedBallXNA/FlatRedBall/Input/Xbox360Gamepad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public enum GamepadLayout
PlayStationDualShock,
}

/// <summary>
/// A list of button positions on the face of a controller which can be used to generalize
/// a button regardless of the button letter. This addresses the inconsistent button names between
/// Nintendo and Xbox controllers.
/// </summary>
public enum ButtonPosition
{
FaceDown,
Expand Down Expand Up @@ -840,6 +845,7 @@ public bool ButtonDown(Button button)
return returnValue;

}
public bool ButtonDown(ButtonPosition buttonPosition) => ButtonDown(GetButtonFromPosition(buttonPosition));

/// <summary>
/// Returns whether the argument button type is pushed. For analog buttons, such as LeftTrigger
Expand Down Expand Up @@ -1007,7 +1013,7 @@ public bool ButtonPushed(Button button)

return returnValue;
}

public bool ButtonPushed(ButtonPosition buttonPosition) => ButtonPushed(GetButtonFromPosition(buttonPosition));

public bool ButtonReleased(Button button)
{
Expand Down Expand Up @@ -1156,6 +1162,7 @@ public bool ButtonReleased(Button button)
return returnValue;

}
public bool ButtonReleased(ButtonPosition buttonPosition) => ButtonReleased(GetButtonFromPosition(buttonPosition));

/// <summary>
/// Returns whether the argument was pushed this frame, or whether it is continually being held down and a "repeat" press
Expand Down Expand Up @@ -1194,6 +1201,8 @@ public bool ButtonRepeatRate(Button button, double timeAfterPush = .35, double t
return false;

}
public bool ButtonRepeatRate(ButtonPosition buttonPosition, double timeAfterPush = .35, double timeBetweenRepeating = .12) =>
ButtonRepeatRate(GetButtonFromPosition(buttonPosition), timeAfterPush, timeBetweenRepeating);

/// <summary>
/// Returns an Xbox360ButtonReference for the argument Button.
Expand All @@ -1212,11 +1221,15 @@ public Xbox360ButtonReference GetButton(Button button)
return cachedButtons[button];
}

public Xbox360ButtonReference GetButton(ButtonPosition buttonPosition)
public Xbox360ButtonReference GetButton(ButtonPosition buttonPosition) =>
GetButton(GetButtonFromPosition(buttonPosition));


public Button GetButtonFromPosition(ButtonPosition buttonPosition)
{
Button button = Button.A;

if(this.ButtonLayout == ButtonLayout.NintendoPro)
if (this.ButtonLayout == ButtonLayout.NintendoPro)
{
switch (buttonPosition)
{
Expand All @@ -1234,7 +1247,7 @@ public Xbox360ButtonReference GetButton(ButtonPosition buttonPosition)
break;
}
}
else if(this.ButtonLayout == ButtonLayout.GameCube)
else if (this.ButtonLayout == ButtonLayout.GameCube)
{
switch (buttonPosition)
{
Expand Down Expand Up @@ -1271,7 +1284,7 @@ public Xbox360ButtonReference GetButton(ButtonPosition buttonPosition)
}
}

return GetButton(button);
return button;
}

#endregion
Expand Down Expand Up @@ -1473,9 +1486,11 @@ public void CreateDefaultButtonMap()
public void IgnoreButtonForOneFrame(Button buttonToIgnore)
{
mButtonsIgnoredForThisFrame[(int)buttonToIgnore] = true;

}

public void IgnoreButtonForOneFrame(ButtonPosition buttonPosition) =>
IgnoreButtonForOneFrame(GetButtonFromPosition(buttonPosition));


/// <summary>
/// Updates the Xbox360Gamepad according to the argument gamepadState. This is publicly available for games
Expand Down

0 comments on commit 684a557

Please sign in to comment.