|
| 1 | +using System; |
| 2 | +using Rage; |
| 3 | + |
| 4 | +namespace IPT.Common.User.Inputs |
| 5 | +{ |
| 6 | + /// <summary> |
| 7 | + /// A holdable combination of controller buttons. |
| 8 | + /// </summary> |
| 9 | + public sealed class HoldableButtonCombo : HoldableCombo, IEquatable<HoldableButtonCombo> |
| 10 | + { |
| 11 | + /// <summary> |
| 12 | + /// Initializes a new instance of the <see cref="HoldableButtonCombo"/> class. |
| 13 | + /// </summary> |
| 14 | + /// <param name="primary">A controller button that must be pressed.</param> |
| 15 | + /// <param name="secondary">An optional modifier button.</param> |
| 16 | + /// <param name="interval">How long to wait for a long press.</param> |
| 17 | + public HoldableButtonCombo(ControllerButtons primary, ControllerButtons secondary, int interval = 500) |
| 18 | + : base(primary, secondary, interval) |
| 19 | + { |
| 20 | + } |
| 21 | + |
| 22 | + /// <summary> |
| 23 | + /// Gets get the value for the primary button. |
| 24 | + /// </summary> |
| 25 | + public ControllerButtons PrimaryButton |
| 26 | + { |
| 27 | + get |
| 28 | + { |
| 29 | + return (ControllerButtons)this.Primary; |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + /// <summary> |
| 34 | + /// Gets the value for the optional second button. |
| 35 | + /// </summary> |
| 36 | + public ControllerButtons SecondaryButton |
| 37 | + { |
| 38 | + get |
| 39 | + { |
| 40 | + return (ControllerButtons)this.Secondary; |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + /// <summary> |
| 45 | + /// Gets a value indicating whether or not the combination contains a secondary button. |
| 46 | + /// </summary> |
| 47 | + public override bool HasSecondary |
| 48 | + { |
| 49 | + get |
| 50 | + { |
| 51 | + return this.SecondaryButton != ControllerButtons.None; |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + /// <summary> |
| 56 | + /// Gets a value indicating whether or not the combination is the same as another combination. |
| 57 | + /// </summary> |
| 58 | + /// <param name="other">The combination to compare against.</param> |
| 59 | + /// <returns>True if the combinations have the same buttons.</returns> |
| 60 | + public bool Equals(HoldableButtonCombo other) |
| 61 | + { |
| 62 | + return this.PrimaryButton == other.PrimaryButton && this.SecondaryButton == other.SecondaryButton; |
| 63 | + } |
| 64 | + |
| 65 | + /// <summary> |
| 66 | + /// Checks the game to determine the current status of the buttons. |
| 67 | + /// </summary> |
| 68 | + /// <returns>True if the game says they are currently pressed.</returns> |
| 69 | + protected override bool CheckGameIsPressed() |
| 70 | + { |
| 71 | + return Game.IsControllerButtonDownRightNow(this.PrimaryButton) && (!this.HasSecondary || Game.IsControllerButtonDownRightNow(this.SecondaryButton)); |
| 72 | + } |
| 73 | + } |
| 74 | +} |
0 commit comments