Skip to content

Commit 0070077

Browse files
authored
Merge pull request #9 from Immersive-Plugins-Team/1.3
1.3
2 parents e20fd39 + 6e99d61 commit 0070077

11 files changed

Lines changed: 436 additions & 9 deletions

IPT.Common/API/Events.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,22 @@ public static class Events
1414
public delegate void UserInputChangedEventHandler(GenericCombo combo);
1515

1616
/// <summary>
17-
/// Even for user input changes.
17+
/// Delegate event handler for holdable user inputs.
18+
/// </summary>
19+
/// <param name="combo">The holdable key or controller combo.</param>
20+
/// <param name="isLongPress">True if it was a long press, otherwise false.</param>
21+
public delegate void HoldableUserInputEventHandler(HoldableCombo combo, bool isLongPress);
22+
23+
/// <summary>
24+
/// Event for user input changes.
1825
/// </summary>
1926
public static event UserInputChangedEventHandler OnUserInputChanged;
2027

28+
/// <summary>
29+
/// Event for holdable user inputs.
30+
/// </summary>
31+
public static event HoldableUserInputEventHandler OnHoldableUserInput;
32+
2133
/// <summary>
2234
/// Fires an event for a user input change.
2335
/// </summary>
@@ -26,5 +38,15 @@ internal static void FireUserInputChanged(GenericCombo combo)
2638
{
2739
OnUserInputChanged?.Invoke(combo);
2840
}
41+
42+
/// <summary>
43+
/// Fires an event for a holdable user input.
44+
/// </summary>
45+
/// <param name="combo">The key or controller combo.</param>
46+
/// <param name="isLongPress">True if it was a long press, otherwise false.</param>
47+
internal static void FireHoldableUserInput(HoldableCombo combo, bool isLongPress)
48+
{
49+
OnHoldableUserInput?.Invoke(combo, isLongPress);
50+
}
2951
}
3052
}

IPT.Common/Callouts.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,21 @@ public static class Callouts
1616
/// <returns>A Callout object contained within the LHandle.</returns>
1717
public static LSPD_First_Response.Mod.Callouts.Callout GetCalloutFromHandle(LSPD_First_Response.Mod.API.LHandle handle)
1818
{
19-
foreach (var props in handle.GetType().GetRuntimeProperties())
19+
if (handle != null)
2020
{
21-
if (props.GetValue(handle) is LSPD_First_Response.Mod.Callouts.Callout callout)
21+
try
2222
{
23-
return callout;
23+
foreach (var props in handle.GetType().GetRuntimeProperties())
24+
{
25+
if (props.GetValue(handle) is LSPD_First_Response.Mod.Callouts.Callout callout)
26+
{
27+
return callout;
28+
}
29+
}
30+
}
31+
catch
32+
{
33+
// just return null
2434
}
2535
}
2636

IPT.Common/IPT.Common.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,16 @@
9292
<Compile Include="User\Inputs\ButtonCombo.cs" />
9393
<Compile Include="User\Inputs\GenericCombo.cs" />
9494
<Compile Include="Fibers\ComboFiber.cs" />
95+
<Compile Include="User\Inputs\HoldableButtonCombo.cs" />
96+
<Compile Include="User\Inputs\HoldableCombo.cs" />
97+
<Compile Include="User\Inputs\HoldableKeyCombo.cs" />
9598
<Compile Include="User\Inputs\KeyCombo.cs" />
9699
<Compile Include="User\Settings\Setting.cs" />
97100
<Compile Include="User\Settings\SettingBool.cs" />
98101
<Compile Include="User\Settings\SettingButtonCombo.cs" />
99102
<Compile Include="User\Settings\SettingFloat.cs" />
103+
<Compile Include="User\Settings\SettingHoldableButtonCombo.cs" />
104+
<Compile Include="User\Settings\SettingHoldableKeyCombo.cs" />
100105
<Compile Include="User\Settings\SettingInt.cs" />
101106
<Compile Include="User\Settings\SettingKeyCombo.cs" />
102107
<Compile Include="User\Settings\SettingString.cs" />

IPT.Common/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,5 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("1.2.0.0")]
35-
[assembly: AssemblyFileVersion("1.2.0.0")]
36-
34+
[assembly: AssemblyVersion("1.3.0.0")]
35+
[assembly: AssemblyFileVersion("1.3.0.0")]

IPT.Common/UX/UXMenu.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,25 @@ public class UXMenu : RAGENativeUI.UIMenu
1313
/// <param name="title">The title of the UIMenu.</param>
1414
/// <param name="subtitle">The subtitle of the UIMenu.</param>
1515
public UXMenu(string title, string subtitle)
16+
: this(title, subtitle, false)
17+
{
18+
}
19+
20+
/// <summary>
21+
/// Initializes a new instance of the <see cref="UXMenu"/> class.
22+
/// </summary>
23+
/// <param name="title">The title of the UIMenu.</param>
24+
/// <param name="subtitle">The subtitle of the UIMenu.</param>
25+
/// <param name="isMouseDisabled">When true, the mouse will be disabled.</param>
26+
public UXMenu(string title, string subtitle, bool isMouseDisabled)
1627
: base(title, subtitle)
1728
{
29+
if (isMouseDisabled)
30+
{
31+
this.AllowCameraMovement = true;
32+
this.InstructionalButtonsEnabled = false;
33+
this.MouseControlsEnabled = false;
34+
}
1835
}
1936

2037
/// <summary>

IPT.Common/User/Inputs/GenericCombo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ protected GenericCombo(object primary, object secondary)
2020
}
2121

2222
/// <summary>
23-
/// Gets a value indicating whether or not the key or button is currently marked as being pressed.
23+
/// Gets or sets a value indicating whether or not the key or button is currently marked as being pressed.
2424
/// </summary>
25-
public bool IsPressed { get; private set; }
25+
public bool IsPressed { get; protected set; }
2626

2727
/// <summary>
2828
/// Gets a value indicating whether or not the combination has a secondary key or button.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System.Diagnostics;
2+
3+
namespace IPT.Common.User.Inputs
4+
{
5+
/// <summary>
6+
/// A combo that can be either a short or long press.
7+
/// </summary>
8+
public abstract class HoldableCombo : GenericCombo
9+
{
10+
/// <summary>
11+
/// Initializes a new instance of the <see cref="HoldableCombo"/> class.
12+
/// </summary>
13+
/// <param name="primary">The primary key or button.</param>
14+
/// <param name="secondary">The secondary key or button.</param>
15+
/// <param name="interval">How long to wait for a long press.</param>
16+
protected HoldableCombo(object primary, object secondary, int interval)
17+
: base(primary, secondary)
18+
{
19+
this.Interval = interval;
20+
this.Timer = new Stopwatch();
21+
this.IsLong = false;
22+
}
23+
24+
/// <summary>
25+
/// Gets or sets a value indicating how long to wait for a long press.
26+
/// </summary>
27+
public int Interval { get; set; }
28+
29+
/// <summary>
30+
/// Gets or sets a value indicating whether or not a long press was made.
31+
/// </summary>
32+
public bool IsLong { get; protected set; }
33+
34+
/// <summary>
35+
/// Gets or sets the timer used for measuring long presses.
36+
/// </summary>
37+
public Stopwatch Timer { get; protected set; }
38+
39+
/// <summary>
40+
/// Checks the status of the combo.
41+
/// </summary>
42+
public override void Check()
43+
{
44+
if (this.CheckGameIsPressed() != this.IsPressed)
45+
{
46+
this.IsPressed = !this.IsPressed;
47+
if (this.IsPressed)
48+
{
49+
this.Timer.Start();
50+
}
51+
else
52+
{
53+
this.Timer.Reset();
54+
if (!this.IsLong)
55+
{
56+
API.Events.FireHoldableUserInput(this, false);
57+
}
58+
else
59+
{
60+
// we already fired the event from a long press
61+
this.IsLong = false;
62+
}
63+
}
64+
}
65+
else if (this.IsPressed && !this.IsLong && this.Timer.ElapsedMilliseconds > this.Interval)
66+
{
67+
this.IsLong = true;
68+
API.Events.FireHoldableUserInput(this, true);
69+
}
70+
}
71+
}
72+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using System;
2+
using System.Windows.Forms;
3+
using Rage;
4+
5+
namespace IPT.Common.User.Inputs
6+
{
7+
/// <summary>
8+
/// A holdable combination of keys.
9+
/// </summary>
10+
public sealed class HoldableKeyCombo : HoldableCombo, IEquatable<HoldableKeyCombo>
11+
{
12+
/// <summary>
13+
/// Initializes a new instance of the <see cref="HoldableKeyCombo"/> class.
14+
/// </summary>
15+
/// <param name="primary">The primary key.</param>
16+
/// <param name="secondary">The secondary key.</param>
17+
/// <param name="interval">How long to wait for a long press.</param>
18+
public HoldableKeyCombo(Keys primary, Keys secondary, int interval = 500)
19+
: base(primary, secondary, interval)
20+
{
21+
}
22+
23+
/// <summary>
24+
/// Gets the value of the primary key.
25+
/// </summary>
26+
public Keys PrimaryKey
27+
{
28+
get
29+
{
30+
return (Keys)this.Primary;
31+
}
32+
}
33+
34+
/// <summary>
35+
/// Gets a value of the optional modifier key.
36+
/// </summary>
37+
public Keys SecondaryKey
38+
{
39+
get
40+
{
41+
return (Keys)this.Secondary;
42+
}
43+
}
44+
45+
/// <summary>
46+
/// Gets a value indicating whether or not the key combination contains a secondary key.
47+
/// </summary>
48+
public override bool HasSecondary
49+
{
50+
get
51+
{
52+
return this.SecondaryKey != Keys.None;
53+
}
54+
}
55+
56+
/// <summary>
57+
/// Gets a value indicating whether or not the key combination is equal to another key combination.
58+
/// </summary>
59+
/// <param name="other">The key combination to compare.</param>
60+
/// <returns>True if the key combinations match.</returns>
61+
public bool Equals(HoldableKeyCombo other)
62+
{
63+
return this.PrimaryKey == other.PrimaryKey && this.SecondaryKey == other.SecondaryKey;
64+
}
65+
66+
/// <summary>
67+
/// Checks the current state of the game to see if the key combination is pressed.
68+
/// </summary>
69+
/// <returns>True if the key combination is pressed.</returns>
70+
protected override bool CheckGameIsPressed()
71+
{
72+
return Game.IsKeyDownRightNow(this.PrimaryKey) && (!this.HasSecondary || Game.IsKeyDownRightNow(this.SecondaryKey));
73+
}
74+
}
75+
}

0 commit comments

Comments
 (0)