-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathInput.cs
96 lines (73 loc) · 2.03 KB
/
Input.cs
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
88
89
90
91
92
93
94
95
96
using static SFML.Window.Keyboard;
using SFML.Window;
using System;
namespace Nitemare3D
{
//todo: implement more keys, should be easy to just automate at some point
public enum KeyboardKey
{
Enter = Key.Enter,
Up = Key.Up,
Down = Key.Down,
Left = Key.Left,
Right = Key.Right,
Space = Key.Space,
Num1 = Key.Num1,
Num2 = Key.Num2,
Num3 = Key.Num3,
Num4 = Key.Num4,
Backspace = Key.Backspace,
LControl = Key.LControl,
F1 = Key.F1,
F2 = Key.F2,
F3 = Key.F3,
F4 = Key.F4,
F5 = Key.F5
}
public static class Input
{
static int numberInput = -1;
const float textInputTime = .1f;
static float textInputTimer = 0;
public static string text = string.Empty;
static void OnTextEnter(object sender, TextEventArgs e)
{
if (textInputTime > textInputTimer) { return; }
numberInput = -1;
int num;
bool isNumber = int.TryParse(e.Unicode, out num);
if (isNumber)
{
numberInput = num;
}
if (e.Unicode == "\b" || e.Unicode == "\n")
{
return;
}
text = e.Unicode;
}
//returns -1 if input is not a number
public static int GetNumberInput()
{
return numberInput;
}
public static bool LeftClick()
{
return Mouse.IsButtonPressed(Mouse.Button.Left);
}
public static void Update()
{
textInputTimer += Time.dt;
text = string.Empty;
numberInput = -1;
}
public static void Init()
{
GameWindow.sfWindow.TextEntered += new EventHandler<TextEventArgs>(OnTextEnter);
}
public static bool IsKeyDown(KeyboardKey key)
{
return IsKeyPressed((Key)key) && GameWindow.sfWindow.HasFocus();
}
}
}