forked from citizenfx/NativeUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControls.cs
More file actions
87 lines (84 loc) · 2.36 KB
/
Copy pathControls.cs
File metadata and controls
87 lines (84 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using CitizenFX.Core;
using static CitizenFX.Core.Native.API;
using System.Linq;
namespace NativeUI
{
/// <summary>
/// Class that provides tools to handle the game controls.
/// </summary>
public static class Controls
{
/// <summary>
/// All of the controls required for using a keyboard.
/// </summary>
private static readonly Control[] NecessaryControlsKeyboard = new Control[]
{
Control.FrontendAccept,
Control.FrontendAxisX,
Control.FrontendAxisY,
Control.FrontendDown,
Control.FrontendUp,
Control.FrontendLeft,
Control.FrontendRight,
Control.FrontendCancel,
Control.FrontendSelect,
Control.CursorScrollDown,
Control.CursorScrollUp,
Control.CursorX,
Control.CursorY,
Control.MoveUpDown,
Control.MoveLeftRight,
Control.Sprint,
Control.Jump,
Control.Enter,
Control.VehicleExit,
Control.VehicleAccelerate,
Control.VehicleBrake,
Control.VehicleMoveLeftRight,
Control.VehicleFlyYawLeft,
Control.FlyLeftRight,
Control.FlyUpDown,
Control.VehicleFlyYawRight,
Control.VehicleHandbrake,
};
/// <summary>
/// All of the controls required for using a keyboard.
/// </summary>
private static readonly Control[] NecessaryControlsGamePad = NecessaryControlsKeyboard.Concat(new Control[]
{
Control.LookUpDown,
Control.LookLeftRight,
Control.Aim,
Control.Attack,
})
.ToArray();
/// <summary>
/// Toggles the availability of the controls.
/// It does not disable the basic movement and frontend controls.
/// </summary>
/// <param name="toggle">If we want to enable or disable the controls.</param>
public static void Toggle(bool toggle)
{
// If we want to enable the controls
if (toggle)
{
// Enable all of them
Game.EnableAllControlsThisFrame(0);
Game.EnableAllControlsThisFrame(1);
Game.EnableAllControlsThisFrame(2);
}
// If we don't need them
else
{
// Disable all of the controls
Game.DisableAllControlsThisFrame(2);
// Now, re-enable the controls that are required for the game
// First, pick the right controls for gamepad or keyboard and mouse
Control[] list = Game.CurrentInputMode == InputMode.GamePad ? NecessaryControlsGamePad : NecessaryControlsKeyboard;
// Then, enable all of the controls for that input mode
foreach (Control control in list)
EnableControlAction(0, (int)control, true);
}
}
}
}