-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgame_input.cpp
338 lines (265 loc) · 10.1 KB
/
game_input.cpp
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
/* Copyright (c) 2012 Cheese and Bacon Games, LLC */
/* This file is licensed under the MIT License. */
/* See the file docs/LICENSE.txt for the full license text. */
#include "game.h"
#include "world.h"
using namespace std;
void Game::prepare_for_input(){
if(in_progress){
command_states.clear();
display_scoreboard=false;
}
}
void Game::handle_command_states_multiplayer(){
if(in_progress){
if(network.status=="server"){
network.prepare_server_input_states();
for(int i=0;i<network.clients.size();i++){
if(!paused){
//Example multiplayer command state
/**if(network.clients[i].game_command_state("some_command")){
///Deal with command state here
}*/
}
}
}
}
}
void Game::handle_game_commands_multiplayer(){
if(in_progress){
if(network.status=="server"){
for(int i=0;i<network.clients.size();i++){
for(int j=0;j<network.clients[i].command_buffer.size();j++){
string command_name=network.clients[i].command_buffer[j];
if(!paused){
//Example multiplayer command
/**if(command_name=="some_command"){
///Deal with command here
}*/
}
}
network.clients[i].command_buffer.clear();
}
}
}
}
void Game::handle_input_states_gui(){
int mouse_x=0;
int mouse_y=0;
engine_interface.get_mouse_state(&mouse_x,&mouse_y);
if(in_progress){
if(engine_interface.game_command_state("scoreboard")){
display_scoreboard=true;
}
}
}
void Game::handle_input_states(){
int mouse_x=0;
int mouse_y=0;
engine_interface.get_mouse_state(&mouse_x,&mouse_y);
if(in_progress){
if(!paused){
//Example multiplayer command state
/**if(engine_interface.game_command_state("some_command")){
command_states.push_back("some_command");
}*/
}
}
}
bool Game::handle_game_command_gui(string command_name){
//Example multiplayer pause
/**if(command_name=="pause"){
if(network.status=="server"){
toggle_pause();
network.send_paused();
}
return true;
}*/
//Toggle chat box
/**else if(command_name=="chat"){
engine_interface.chat.toggle_on();
return true;
}*/
//Help
if(command_name=="help"){
Window* notice=engine_interface.get_window("notice");
if(!notice->on){
string help="Scroll the file list up and down using the mouse scroll wheel, the arrow keys, or a gamepad.\n";
help+="Click on a file/directory by clicking on it with the left mouse button (or press Enter or A on a gamepad).\n";
help+="Clicking on a directory navigates to it.\n\n";
help+="Drag files/directories onto the program window to copy them from your computer to the current directory.\n\n";
help+="Hold Control (or the Left Shoulder button on a gamepad) when clicking on a file/directory to select it.\n";
help+="Press A (or the Right Shoulder button on a gamepad) to select all files/directories in the current directory.\n";
help+="Press Z to deselect all selected files/directories.\n\n";
help+="Press C (or the X button on a gamepad) to copy all selected files/directories to your computer.\n";
help+="Press V to copy all selected files/directories to the current directory.\n";
help+="Press X to move all selected files/directories to the current directory.\n";
help+="Press F2 (with one file/directory selected) to rename a selected file/directory.\n";
help+="Press F3 to create a new directory in the current directory.\n";
help+="Files copied to your computer are located in '"+engine_interface.get_home_directory()+"files/'\n";
help+="WARNING: Copying/moving/renaming files in either direction has no prompt and simply overwrites any identically\nnamed files already located in the same place. Use wisely.\n\n";
help+="Press Delete (or the Y button on a gamepad) to delete all selected files/directories.\n";
help+="WARNING: Directories are deleted recursively. Use wisely.\n\n";
help+="Press H (or the Left Stick on a gamepad) to toggle the display of hidden files and directories.\n";
help+="Press F5 (or the Right Stick on a gamepad) to refresh the file list.\n";
help+="Press Backspace (or click mouse button 4 or B on a gamepad) to move up a directory.\n";
engine_interface.make_notice(help);
}
else{
if(!engine_interface.is_window_on_top(notice)){
engine_interface.bring_window_to_top(notice);
}
else{
notice->toggle_on(true,false);
}
}
return true;
}
//Toggle hidden files
else if(command_name=="toggle_hidden_files"){
option_hidden_files=!option_hidden_files;
engine_interface.get_window("browser")->rebuild_scrolling_buttons();
return true;
}
//Refresh
else if(command_name=="refresh"){
engine_interface.get_window("browser")->rebuild_scrolling_buttons();
return true;
}
//Up
else if(command_name=="up"){
world.change_directory("..");
return true;
}
//Select all
else if(command_name=="select_all"){
world.select_all();
return true;
}
//Deselect all
else if(command_name=="deselect_all"){
world.deselect_all();
return true;
}
//Rename
else if(command_name=="rename"){
if(world.selected_files.size()==1){
Window* window=engine_interface.get_window("rename_file");
if(!window->on){
window->set_info_text(0,world.path_to_filename(world.selected_files[0]));
window->toggle_on(true,true);
engine_interface.set_mutable_info(&window->informations[1]);
}
else{
if(!engine_interface.is_window_on_top(window)){
window->set_info_text(0,world.path_to_filename(world.selected_files[0]));
engine_interface.bring_window_to_top(window);
engine_interface.set_mutable_info(&window->informations[1]);
}
}
}
return true;
}
//Create directory
else if(command_name=="create_directory"){
Window* window=engine_interface.get_window("create_directory");
if(!window->on){
window->set_info_text(0,"");
window->toggle_on(true,true);
engine_interface.set_mutable_info(&window->informations[1]);
}
else{
if(!engine_interface.is_window_on_top(window)){
window->set_info_text(0,"");
engine_interface.bring_window_to_top(window);
engine_interface.set_mutable_info(&window->informations[1]);
}
}
return true;
}
//Copy
else if(command_name=="copy"){
world.copy_selected();
return true;
}
//Copy on device
else if(command_name=="copy_device"){
world.copy_selected_on_device();
return true;
}
//Move
else if(command_name=="move"){
world.move_files();
return true;
}
//Delete
else if(command_name=="delete"){
if(world.selected_files.size()>0){
Window* window=engine_interface.get_window("confirm_delete_selected");
if(world.selected_files.size()==1){
window->informations[1].text=world.selected_files[0];
}
else{
window->informations[1].text="";
}
window->toggle_on(true,true);
}
return true;
}
return false;
}
bool Game::handle_game_command(string command_name){
const uint8_t* keystates=SDL_GetKeyboardState(NULL);
///DEV COMMANDS
if(engine_interface.option_dev && keystates[SDL_SCANCODE_F1]){
//Example dev command
/**if(command_name=="some_dev_command"){
///Dev command here.
return true;
}*/
}
///END OF DEV COMMANDS
if(!paused){
//Example command
/**if(command_name=="some_command"){
///Command here
return true;
}*/
//Example multiplayer command input
/**if(command_name=="some_command"){
network.add_command(command_name);
return true;
}*/
}
return false;
}
bool Game::handle_input_events_gui(){
bool event_consumed=false;
if(in_progress){
for(int i=0;i<engine_interface.game_commands.size() && !event_consumed;i++){
if((event.type==SDL_CONTROLLERBUTTONDOWN && engine_interface.game_commands[i].button==event.cbutton.button) ||
(event.type==SDL_KEYDOWN && event.key.repeat==0 && engine_interface.game_commands[i].key==event.key.keysym.scancode)){
event_consumed=handle_game_command_gui(engine_interface.game_commands[i].name);
}
}
if(event.type==SDL_MOUSEBUTTONDOWN){
if(!event_consumed && event.button.button==SDL_BUTTON_X1){
world.change_directory("..");
event_consumed=true;
}
}
}
return event_consumed;
}
bool Game::handle_input_events(){
bool event_consumed=false;
if(in_progress){
for(int i=0;i<engine_interface.game_commands.size() && !event_consumed;i++){
if((event.type==SDL_CONTROLLERBUTTONDOWN && engine_interface.game_commands[i].button==event.cbutton.button) ||
(event.type==SDL_KEYDOWN && event.key.repeat==0 && engine_interface.game_commands[i].key==event.key.keysym.scancode)){
event_consumed=handle_game_command(engine_interface.game_commands[i].name);
}
}
}
return event_consumed;
}