forked from EasyRPG/Player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput_buttons.h
285 lines (261 loc) · 5.81 KB
/
input_buttons.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/*
* This file is part of EasyRPG Player.
*
* EasyRPG Player is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EasyRPG Player is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EasyRPG Player. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef EP_INPUT_BUTTONS_H
#define EP_INPUT_BUTTONS_H
// Headers
#include <vector>
#include <array>
#include <cassert>
#include <cstdint>
#include <initializer_list>
#include <algorithm>
#include <ostream>
#include <lcf/enum_tags.h>
#include "flat_map.h"
#include "keys.h"
struct Game_ConfigInput;
#if USE_SDL==1
#include "platform/sdl/axis.h"
#endif
/**
* Input namespace.
*/
namespace Input {
/** Input buttons list. */
enum InputButton : uint8_t {
UP,
DOWN,
LEFT,
RIGHT,
DECISION,
CANCEL,
SHIFT,
N0,
N1,
N2,
N3,
N4,
N5,
N6,
N7,
N8,
N9,
PLUS,
MINUS,
MULTIPLY,
DIVIDE,
PERIOD,
DEBUG_MENU,
DEBUG_THROUGH,
DEBUG_SAVE,
DEBUG_ABORT_EVENT,
SETTINGS_MENU,
TOGGLE_FPS,
TAKE_SCREENSHOT,
SHOW_LOG,
RESET,
PAGE_UP,
PAGE_DOWN,
MOUSE_LEFT,
MOUSE_RIGHT,
MOUSE_MIDDLE,
SCROLL_UP,
SCROLL_DOWN,
FAST_FORWARD_A,
FAST_FORWARD_B,
TOGGLE_FULLSCREEN,
TOGGLE_ZOOM,
BUTTON_COUNT
};
constexpr auto kInputButtonNames = lcf::makeEnumTags<InputButton>(
"UP",
"DOWN",
"LEFT",
"RIGHT",
"DECISION",
"CANCEL",
"SHIFT",
"N0",
"N1",
"N2",
"N3",
"N4",
"N5",
"N6",
"N7",
"N8",
"N9",
"PLUS",
"MINUS",
"MULTIPLY",
"DIVIDE",
"PERIOD",
"DEBUG_MENU",
"DEBUG_THROUGH",
"DEBUG_SAVE",
"DEBUG_ABORT_EVENT",
"SETTINGS_MENU",
"TOGGLE_FPS",
"TAKE_SCREENSHOT",
"SHOW_LOG",
"RESET",
"PAGE_UP",
"PAGE_DOWN",
"MOUSE_LEFT",
"MOUSE_RIGHT",
"MOUSE_MIDDLE",
"SCROLL_UP",
"SCROLL_DOWN",
"FAST_FORWARD_A",
"FAST_FORWARD_B",
"TOGGLE_FULLSCREEN",
"TOGGLE_ZOOM",
"BUTTON_COUNT");
constexpr auto kInputButtonHelp = lcf::makeEnumTags<InputButton>(
"Up Direction",
"Down Direction",
"Left Direction",
"Right Direction",
"Decision (Enter) Key",
"Cancel (ESC) Key",
"Shift Key",
"Number 0",
"Number 1",
"Number 2",
"Number 3",
"Number 4",
"Number 5",
"Number 6",
"Number 7",
"Number 8",
"Number 9",
"Plus Key",
"Minus Key",
"Multiply Key",
"Divide Key",
"Period Key",
"(Test Play) Open the debug menu",
"(Test Play) Walk through walls",
"(Test Play) Open the save menu",
"(Test Play) Aborts current active event",
"Open this settings menu",
"Toggle the FPS display",
"Take a screenshot",
"Show the console log on the screen",
"Reset to the title screen",
"Move up one page in menus",
"Move down one page in menus",
"Left mouse key",
"Right mouse key",
"Middle mouse key",
"Scroll up key",
"Scroll down key",
"Run the game at x{} speed",
"Run the game at x{} speed",
"Toggle Fullscreen mode",
"Toggle Window Zoom level",
"Total Button Count");
/**
* Return true if the given button is a system button.
* System buttons are refreshed on every physical frame
* and do not affect the game logic.
*/
constexpr bool IsSystemButton(InputButton b) {
switch (b) {
case TOGGLE_FPS:
case TAKE_SCREENSHOT:
case SHOW_LOG:
case TOGGLE_ZOOM:
case FAST_FORWARD_A:
case FAST_FORWARD_B:
return true;
default:
return false;
}
}
/**
* Protected buttons are buttons where unmapping them makes the Player unusable.
* @return true when the button is protected
*/
constexpr bool IsProtectedButton(InputButton b) {
switch (b) {
case UP:
case DOWN:
case LEFT:
case RIGHT:
case DECISION:
case CANCEL:
case SETTINGS_MENU: // Not really critical but needs a way to enter it
return true;
default:
return false;
}
}
namespace Direction {
enum InputDirection : uint8_t {
NONE = 0,
DOWNLEFT = 1,
DOWN = 2,
DOWNRIGHT = 3,
LEFT = 4,
CENTER = 5,
RIGHT = 6,
UPLEFT = 7,
UP = 8,
UPRIGHT = 9,
NUM_DIRECTIONS = 10,
};
static constexpr auto kInputDirectionNames = lcf::makeEnumTags<InputDirection>(
"NONE",
"DOWNLEFT",
"DOWN",
"DOWNRIGHT",
"LEFT",
"CENTER",
"RIGHT",
"UPLEFT",
"UP",
"UPRIGHT",
"NUM_DIRECTIONS");
};
using ButtonMappingArray = FlatUniqueMultiMap<InputButton,Keys::InputKey>;
/** A mapping for a button to a input key */
using ButtonMapping = ButtonMappingArray::pair_type;
inline std::ostream& operator<<(std::ostream& os, ButtonMapping bm) {
os << "{ " << kInputButtonNames.tag(bm.first) << ", " << Keys::kInputKeyNames.tag(bm.second) << " }";
return os;
}
using DirectionMappingArray = FlatUniqueMultiMap<Direction::InputDirection, InputButton>;
/** A mapping for a single direction to a button */
using DirectionMapping = DirectionMappingArray::pair_type;
inline std::ostream& operator<<(std::ostream& os, DirectionMapping dm) {
os << "{ " << Direction::kInputDirectionNames.tag(dm.first) << ", " << kInputButtonNames.tag(dm.second) << " }";
return os;
}
/** Provides platform-specific, human readable name for an input key */
using KeyNamesArray = std::vector<std::pair<Keys::InputKey, std::string>>;
/** Returns default button mappings */
ButtonMappingArray GetDefaultButtonMappings();
/** Returns platform-specific, human readable name for an input key */
KeyNamesArray GetInputKeyNames();
/** Used to declare which config options are available */
void GetSupportedConfig(Game_ConfigInput& cfg);
#if USE_SDL==1
SdlAxis GetSdlAxis();
#endif
}
#endif