-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeyMapper.h
163 lines (139 loc) · 4.29 KB
/
KeyMapper.h
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#pragma once
#include <iostream>
#include <fstream>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
/// <summary>
/// Allows the Mapping of Keynames and Keys, loaded and saved to the KeyMapper Config File
/// </summary>
class KeyMapper
{
public:
/// <summary>
/// Initializes a new instance of the <see cref="KeyMapper"/> class.
/// </summary>
KeyMapper();
/// <summary>
/// Finalizes an instance of the <see cref="KeyMapper"/> class.
/// </summary>
~KeyMapper();
/// <summary>
/// Check if the Key / Mouse linked to the Keyname is Pressed.
/// </summary>
/// <param name="key">The Keyaction name (for Example "Jump").</param>
/// <param name="e">The Event</param>
/// <returns>Result of the Evaluation</returns>
bool KeyPressed(std::string key, sf::Event e);
/// <summary>
/// Saves the specified key.
/// </summary>
/// <param name="key">The Keyaction name (for Example "Jump").</param>
/// <param name="e">The Event</param>
/// <returns>Result of the Save</returns>
bool Save(std::string key, sf::Event e);
/// <summary>
/// Writes the Config File.
/// </summary>
void WriteFile();
/// <summary>
/// Starts the Keybind process
/// </summary>
void Start();
/// <summary>
/// Applies the Keybinds created during the Keybind process.
/// </summary>
void Apply();
/// <summary>
/// Discards the Keybinds created during the Keybind process.
/// </summary>
void Discard();
/// <summary>
/// Gets the bind mode.
/// </summary>
/// <returns><c>true</c> if the binding process has started; otherwise, <c>false</c></returns>
bool GetBindMode();
/// <summary>
/// Check if there are duplicate Keys or not.
/// </summary>
/// <returns></returns>
bool GetDuplicatedKeys();
/// <summary>
/// Get the keys with Actionname and the Keybind
/// </summary>
/// <returns></returns>
std::map<std::string, std::string> GetKeys();
private:
/// <summary>
/// InputType Enum
/// </summary>
enum InputType
{
KeyboardInput,
MouseInput,
JoystickInput
};
/// <summary>
/// Key Structure
/// </summary>
struct Key
{
Key() : modifier(sf::Keyboard::Unknown) { };
InputType inputType;
sf::Event::EventType eventType;
sf::Keyboard::Key keyCode;
sf::Mouse::Button mouseButton;
sf::Keyboard::Key modifier;
};
/// <summary>
/// The last Key pressed
/// </summary>
sf::Keyboard::Key lastKey = sf::Keyboard::Key::Unknown;
/// <summary>
/// Determines whether the specified key is modifier.
/// </summary>
/// <param name="key">The key.</param>
/// <returns>
/// <c>true</c> if the specified key is a modifier; otherwise, <c>false</c>.
/// </returns>
bool IsModifier(sf::Keyboard::Key key);
/// <summary>
/// Map for the Key and the Keyaction Name ("Jump")
/// </summary>
std::map<std::string, KeyMapper::Key> Keys;
/// <summary>
/// Save Keybinds before applying them
/// </summary>
std::map<std::string, KeyMapper::Key> SaveKeys;
/// <summary>
/// If a binding process is started and Keybinding is possible
/// </summary>
bool BindMode = false;
/// <summary>
/// If there are Duplicate Keys or not
/// </summary>
bool DuplicateKeys = false;
/// <summary>
/// Check if there are Dublicate Keys.
/// </summary>
/// <returns></returns>
bool CheckDuplicateKeys();
/// <summary>
/// Compares two Keys.
/// </summary>
/// <param name="key1">The first key.</param>
/// <param name="secondKey">The second key</param>
/// <returns></returns>
bool CompareKey(KeyMapper::Key firstKey, KeyMapper::Key secondKey);
/// <summary>
/// Gets the name of the key.
/// </summary>
/// <param name="key">The key.</param>
/// <returns></returns>
const char* getKeyName(const sf::Keyboard::Key key);
/// <summary>
/// Gets the name of the mouse button.
/// </summary>
/// <param name="button">The button.</param>
/// <returns></returns>
const char* KeyMapper::getMouseName(const sf::Mouse::Button button);
};