1 /******************************************************************************
2 * Warmux is a convivial mass murder game.
3 * Copyright (C) 2001-2011 Warmux Team.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
18 ******************************************************************************
19 * Virtual class to handle man/machine interaction
20 *****************************************************************************/
21
22 #include "interface/man_machine_interface.h"
23 #include "interface/interface.h"
24 #include "character/character.h"
25 #include "game/config.h"
26 #include "game/game.h"
27 #include "game/game_mode.h"
28 #include "game/game_time.h"
29 #include "graphic/video.h"
30 #include "include/app.h"
31 #include "include/action_handler.h"
32 #include "map/camera.h"
33 #include "menu/options_menu.h"
34 #include "network/chat.h"
35 #include "network/network.h"
36 #include "object/objbox.h"
37 #include "team/teams_list.h"
38 #include "team/team.h"
39 #include "sound/jukebox.h"
40 #include "weapon/weapons_list.h"
41 #include <SDL_events.h>
42
43
Reset()44 void ManMachineInterface::Reset()
45 {
46 for (int i = 0; i != 256; i++)
47 PressedKeys[i] = false;
48 }
49
IsRegistredEvent(uint32_t event_type)50 bool ManMachineInterface::IsRegistredEvent(uint32_t event_type)
51 {
52 std::list<uint32_t>::iterator it;
53 for (it = registred_event.begin(); it != registred_event.end(); it ++) {
54 if (event_type == (*it))
55 return true;
56 }
57 return false;
58 }
59
60 // Get the key associated to an action.
GetKeyAssociatedToAction(Key_t at) const61 int ManMachineInterface::GetKeyAssociatedToAction(Key_t at) const
62 {
63 std::map<int, std::vector<Key_t> >::const_iterator it;
64 std::vector<Key_t>::const_iterator itv;
65 for (it = layout.begin(); it != layout.end(); it++) {
66 const std::vector<Key_t>& key_list = it->second;
67 for (itv = key_list.begin(); itv != key_list.end(); itv++) {
68 if (*itv == at) {
69 return it->first;
70 }
71 }
72 }
73 return 0;
74 }
75
76 // Handle a pressed key
HandleKeyPressed(const Key_t & key)77 void ManMachineInterface::HandleKeyPressed(const Key_t &key)
78 {
79 // Key repeat is useful in the menu, but we are handling it manually
80 // during the game
81 if (PressedKeys[key]) {
82 SDL_EnableKeyRepeat(0,0);
83 return;
84 }
85
86 switch (key) {
87 case KEY_MOVE_CAMERA_RIGHT:
88 Camera::GetInstance()->AddLRMoveIntention(INTENTION_MOVE_RIGHT);
89 break;
90 case KEY_MOVE_CAMERA_LEFT:
91 Camera::GetInstance()->AddLRMoveIntention(INTENTION_MOVE_LEFT);
92 break;
93 case KEY_MOVE_CAMERA_UP:
94 Camera::GetInstance()->AddUDMoveIntention(INTENTION_MOVE_UP);
95 break;
96 case KEY_MOVE_CAMERA_DOWN:
97 Camera::GetInstance()->AddUDMoveIntention(INTENTION_MOVE_DOWN);
98 break;
99 default:
100 break;
101 }
102
103 // Managing keys related to character moves
104 // Available only when local
105 if (!ActiveTeam().IsLocalHuman()) return;
106 if (Game::GetInstance()->ReadState() == Game::END_TURN) return;
107 if (ActiveCharacter().IsDead()) return;
108
109 switch (key) {
110 case KEY_MOVE_RIGHT:
111 ActiveCharacter().HandleKeyPressed_MoveRight(false);
112 break;
113 case KEY_MOVE_RIGHT_SLOWLY:
114 ActiveCharacter().HandleKeyPressed_MoveRight(true);
115 break;
116 case KEY_MOVE_LEFT:
117 ActiveCharacter().HandleKeyPressed_MoveLeft(false);
118 break;
119 case KEY_MOVE_LEFT_SLOWLY:
120 ActiveCharacter().HandleKeyPressed_MoveLeft(true);
121 break;
122 case KEY_UP:
123 ActiveCharacter().HandleKeyPressed_Up(false);
124 break;
125 case KEY_UP_SLOWLY:
126 ActiveCharacter().HandleKeyPressed_Up(true);
127 break;
128 case KEY_DOWN:
129 ActiveCharacter().HandleKeyPressed_Down(false);
130 break;
131 case KEY_DOWN_SLOWLY:
132 ActiveCharacter().HandleKeyPressed_Down(true);
133 break;
134 case KEY_JUMP:
135 ActiveCharacter().HandleKeyPressed_Jump();
136 break;
137 case KEY_HIGH_JUMP:
138 ActiveCharacter().HandleKeyPressed_HighJump();
139 break;
140 case KEY_BACK_JUMP:
141 ActiveCharacter().HandleKeyPressed_BackJump();
142 break;
143 case KEY_SHOOT:
144 // Shoot key is not accepted in HAS_PLAYED state
145 if (Game::GetInstance()->ReadState() == Game::HAS_PLAYED)
146 return;
147 break;
148 case KEY_SCREENSHOT:
149 AppWarmux::GetInstance()->video->SaveScreenshot();
150 return;
151 default:
152 // key not supported
153 return;
154 }
155 if (Game::GetInstance()->ReadState() == Game::PLAYING) {
156 switch (key) {
157 case KEY_MOVE_RIGHT:
158 ActiveTeam().AccessWeapon().HandleKeyPressed_MoveRight(false);
159 break;
160 case KEY_MOVE_RIGHT_SLOWLY:
161 ActiveTeam().AccessWeapon().HandleKeyPressed_MoveRight(true);
162 break;
163 case KEY_MOVE_LEFT:
164 ActiveTeam().AccessWeapon().HandleKeyPressed_MoveLeft(false);
165 break;
166 case KEY_MOVE_LEFT_SLOWLY:
167 ActiveTeam().AccessWeapon().HandleKeyPressed_MoveLeft(true);
168 break;
169 case KEY_UP:
170 ActiveTeam().AccessWeapon().HandleKeyPressed_Up(false);
171 break;
172 case KEY_UP_SLOWLY:
173 ActiveTeam().AccessWeapon().HandleKeyPressed_Up(true);
174 break;
175 case KEY_DOWN:
176 ActiveTeam().AccessWeapon().HandleKeyPressed_Down(false);
177 break;
178 case KEY_DOWN_SLOWLY:
179 ActiveTeam().AccessWeapon().HandleKeyPressed_Down(true);
180 break;
181 case KEY_JUMP:
182 ActiveTeam().AccessWeapon().HandleKeyPressed_Jump();
183 break;
184 case KEY_HIGH_JUMP:
185 ActiveTeam().AccessWeapon().HandleKeyPressed_HighJump();
186 break;
187 case KEY_BACK_JUMP:
188 ActiveTeam().AccessWeapon().HandleKeyPressed_BackJump();
189 break;
190 case KEY_SHOOT:
191 ActiveTeam().AccessWeapon().HandleKeyPressed_Shoot();
192 break;
193 default:
194 // key not supported
195 return;
196 }
197 }
198
199 PressedKeys[key] = true ;
200 }
201
202 // Handle a released key
HandleKeyReleased(const Key_t & key)203 void ManMachineInterface::HandleKeyReleased(const Key_t &key)
204 {
205 PressedKeys[key] = false;
206 // Here we manage only actions which are activated on KEY_RELEASED event.
207
208 { // Managing keys related to interface (no game interaction)
209 // Always available
210 switch(key){
211 // Managing interface
212 case KEY_HELP:
213 Game::GetInstance()->UserAsksForHelpMenu();
214 return;
215 case KEY_QUIT:
216 case KEY_PAUSE:
217 Game::GetInstance()->UserAsksForMenu();
218 return;
219 case KEY_FULLSCREEN:
220 AppWarmux::GetInstance()->video->ToggleFullscreen();
221 return;
222 case KEY_CHAT:
223 if(Network::IsConnected())
224 Game::GetInstance()->chatsession.ShowInput();
225 return;
226 case KEY_CENTER:
227 Camera::GetInstance()->CenterOnActiveCharacter();
228 return;
229 case KEY_TOGGLE_INTERFACE:
230 Interface::GetInstance()->EnableDisplay(!Interface::GetInstance()->IsDisplayed());
231 return;
232 case KEY_MINIMAP_FROM_GAME:
233 Interface::GetInstance()->ToggleMinimap();
234 return;
235 case KEY_MENU_OPTIONS_FROM_GAME: {
236 OptionMenu options_menu;
237 options_menu.Run();
238 return;
239 }
240 case KEY_MOVE_CAMERA_RIGHT:
241 Camera::GetInstance()->RemoveLRMoveIntention(INTENTION_MOVE_RIGHT);
242 return;
243 case KEY_MOVE_CAMERA_LEFT:
244 Camera::GetInstance()->RemoveLRMoveIntention(INTENTION_MOVE_LEFT);
245 return;
246 case KEY_MOVE_CAMERA_UP:
247 Camera::GetInstance()->RemoveUDMoveIntention(INTENTION_MOVE_UP);
248 return;
249 case KEY_MOVE_CAMERA_DOWN:
250 Camera::GetInstance()->RemoveUDMoveIntention(INTENTION_MOVE_DOWN);
251 return;
252 case KEY_DECREASE_MINIMAP:
253 Interface::GetInstance()->MinimapSizeDelta(1);
254 return;
255 case KEY_INCREASE_MINIMAP:
256 Interface::GetInstance()->MinimapSizeDelta(-1);
257 return;
258 case KEY_DECREASE_VOLUME:
259 {
260 Config *cfg = Config::GetInstance();
261 int volume = cfg->GetVolumeMusic() - 5;
262 if (volume > 0) {
263 cfg->SetVolumeMusic(volume);
264 } else {
265 cfg->SetVolumeMusic(0);
266 JukeBox::GetInstance()->ActiveMusic(false);
267 }
268 volume = cfg->GetVolumeEffects() - 5;
269 if (volume > 0) {
270 cfg->SetVolumeEffects(volume);
271 } else {
272 cfg->SetVolumeEffects(0);
273 cfg->SetSoundEffects(false);
274 }
275 return;
276 }
277 case KEY_INCREASE_VOLUME:
278 {
279 Config *cfg = Config::GetInstance();
280 int max_volume = cfg->GetMaxVolume();
281 int volume = cfg->GetVolumeMusic() + 5;
282 if (volume < max_volume) {
283 cfg->SetVolumeMusic(volume);
284 } else {
285 cfg->SetVolumeMusic(max_volume);
286 }
287 JukeBox::GetInstance()->ActiveMusic(true);
288
289 volume = cfg->GetVolumeEffects() + 5;
290 if (volume < max_volume) {
291 cfg->SetVolumeEffects(volume);
292 } else {
293 cfg->SetVolumeEffects(max_volume);
294 }
295 cfg->SetSoundEffects(true);
296 return;
297 }
298 default:
299 break;
300 }
301 }
302
303 // Managing shoot key
304 // Drop bonus box or medkit when outside a turn
305 // Shoot when in turn
306 if (key == KEY_SHOOT) {
307
308 if (Game::GetInstance()->ReadState() == Game::END_TURN) {
309 Game::GetInstance()->RequestBonusBoxDrop();
310 } else if (Game::GetInstance()->ReadState() == Game::PLAYING &&
311 ActiveTeam().IsLocalHuman() &&
312 !ActiveCharacter().IsDead()) {
313 ActiveTeam().AccessWeapon().HandleKeyReleased_Shoot();
314 }
315 return;
316 }
317
318 { // Managing keys related to character moves
319 // Available only when local
320 if (!ActiveTeam().IsLocalHuman()) return;
321 if (ActiveCharacter().IsDead()) return;
322 if (Game::GetInstance()->ReadState() == Game::END_TURN) return;
323
324 switch (key) {
325 case KEY_MOVE_RIGHT:
326 ActiveCharacter().HandleKeyReleased_MoveRight(false);
327 break;
328 case KEY_MOVE_RIGHT_SLOWLY:
329 ActiveCharacter().HandleKeyReleased_MoveRight(true);
330 break;
331 case KEY_MOVE_LEFT:
332 ActiveCharacter().HandleKeyReleased_MoveLeft(false);
333 break;
334 case KEY_MOVE_LEFT_SLOWLY:
335 ActiveCharacter().HandleKeyReleased_MoveLeft(true);
336 break;
337 case KEY_UP:
338 ActiveCharacter().HandleKeyReleased_Up(false);
339 break;
340 case KEY_UP_SLOWLY:
341 ActiveCharacter().HandleKeyReleased_Up(true);
342 break;
343 case KEY_DOWN:
344 ActiveCharacter().HandleKeyReleased_Down(false);
345 break;
346 case KEY_DOWN_SLOWLY:
347 ActiveCharacter().HandleKeyReleased_Down(true);
348 break;
349 case KEY_JUMP:
350 ActiveCharacter().HandleKeyReleased_Jump();
351 break;
352 case KEY_HIGH_JUMP:
353 ActiveCharacter().HandleKeyReleased_HighJump();
354 break;
355 case KEY_BACK_JUMP:
356 ActiveCharacter().HandleKeyReleased_BackJump();
357 break;
358 default:
359 if (Game::GetInstance()->ReadState() == Game::HAS_PLAYED)
360 return;
361 break;
362 }
363 if (Game::GetInstance()->ReadState() == Game::PLAYING) {
364 switch (key) {
365
366 case KEY_MOVE_RIGHT:
367 ActiveTeam().AccessWeapon().HandleKeyReleased_MoveRight(false);
368 return;
369 case KEY_MOVE_RIGHT_SLOWLY:
370 ActiveTeam().AccessWeapon().HandleKeyReleased_MoveRight(true);
371 return;
372 case KEY_MOVE_LEFT:
373 ActiveTeam().AccessWeapon().HandleKeyReleased_MoveLeft(false);
374 return;
375 case KEY_MOVE_LEFT_SLOWLY:
376 ActiveTeam().AccessWeapon().HandleKeyReleased_MoveLeft(true);
377 return;
378 case KEY_UP:
379 ActiveTeam().AccessWeapon().HandleKeyReleased_Up(false);
380 return;
381 case KEY_UP_SLOWLY:
382 ActiveTeam().AccessWeapon().HandleKeyReleased_Up(true);
383 return;
384 case KEY_DOWN:
385 ActiveTeam().AccessWeapon().HandleKeyReleased_Down(false);
386 return;
387 case KEY_DOWN_SLOWLY:
388 ActiveTeam().AccessWeapon().HandleKeyReleased_Down(true);
389 return;
390 case KEY_JUMP:
391 ActiveTeam().AccessWeapon().HandleKeyReleased_Jump();
392 return;
393 case KEY_HIGH_JUMP:
394 ActiveTeam().AccessWeapon().HandleKeyReleased_HighJump();
395 return;
396 case KEY_BACK_JUMP:
397 ActiveTeam().AccessWeapon().HandleKeyReleased_BackJump();
398 return;
399
400 // Shoot key
401 case KEY_SHOOT:
402 ActiveTeam().AccessWeapon().HandleKeyReleased_Shoot();
403 return;
404
405 // Other keys usefull for weapons
406 case KEY_WEAPON_1:
407 ActiveTeam().AccessWeapon().HandleKeyReleased_Num1();
408 return;
409 case KEY_WEAPON_2:
410 ActiveTeam().AccessWeapon().HandleKeyReleased_Num2();
411 return;
412 case KEY_WEAPON_3:
413 ActiveTeam().AccessWeapon().HandleKeyReleased_Num3();
414 return;
415 case KEY_WEAPON_4:
416 ActiveTeam().AccessWeapon().HandleKeyReleased_Num4();
417 return;
418 case KEY_WEAPON_5:
419 ActiveTeam().AccessWeapon().HandleKeyReleased_Num5();
420 return;
421 case KEY_WEAPON_6:
422 ActiveTeam().AccessWeapon().HandleKeyReleased_Num6();
423 return;
424 case KEY_WEAPON_7:
425 ActiveTeam().AccessWeapon().HandleKeyReleased_Num7();
426 return;
427 case KEY_WEAPON_8:
428 ActiveTeam().AccessWeapon().HandleKeyReleased_Num8();
429 return;
430 case KEY_WEAPON_9:
431 ActiveTeam().AccessWeapon().HandleKeyReleased_Num9();
432 return;
433 case KEY_WEAPON_LESS:
434 ActiveTeam().AccessWeapon().HandleKeyReleased_Less();
435 return;
436 case KEY_WEAPON_MORE:
437 ActiveTeam().AccessWeapon().HandleKeyReleased_More();
438 return;
439 default:
440 break;
441 }
442 }
443 }
444
445 { // Managing keys related to change of character or weapon
446
447 if (Game::GetInstance()->ReadState() != Game::PLAYING ||
448 !ActiveTeam().GetWeapon().CanChangeWeapon() ||
449 !ActiveTeam().IsLocalHuman())
450 return;
451
452 Weapon::category_t weapon_sort = Weapon::INVALID;
453
454 switch(key) {
455
456 case KEY_NEXT_CHARACTER:
457 if (GameMode::GetInstance()->AllowCharacterSelection()) {
458 SDLMod mod = SDL_GetModState();
459 if (mod & KMOD_CTRL) {
460 ActiveTeam().PreviousCharacter();
461 } else {
462 ActiveTeam().NextCharacter();
463 }
464 ActionHandler::GetInstance()->NewActionActiveCharacter();
465 }
466 return;
467
468 case KEY_WEAPONS1:
469 weapon_sort = Weapon::HEAVY;
470 break;
471 case KEY_WEAPONS2:
472 weapon_sort = Weapon::RIFLE;
473 break;
474 case KEY_WEAPONS3:
475 weapon_sort = Weapon::THROW;
476 break;
477 case KEY_WEAPONS4:
478 weapon_sort = Weapon::SPECIAL;
479 break;
480 case KEY_WEAPONS5:
481 weapon_sort = Weapon::DUEL;
482 break;
483 case KEY_WEAPONS6:
484 weapon_sort = Weapon::MOVE;
485 break;
486 case KEY_WEAPONS7:
487 weapon_sort = Weapon::TOOL;
488 break;
489 default:
490 // Key not supported
491 return;
492 }
493
494 if (weapon_sort != Weapon::INVALID && ActiveTeam().GetWeapon().CanChangeWeapon()) {
495 Weapon::Weapon_type weapon;
496 WeaponsList * weapons_list = Game::GetInstance()->GetWeaponsList();
497 if (weapons_list->GetWeaponBySort(weapon_sort, weapon)) {
498 ASSERT (weapon >= Weapon::FIRST && weapon <= Weapon::LAST);
499 ActionHandler::GetInstance()->NewAction(new Action(Action::ACTION_PLAYER_CHANGE_WEAPON, weapon));
500 }
501 }
502 }
503 }
504
ClearKeyAction(Key_t at)505 void ManMachineInterface::ClearKeyAction(Key_t at)
506 {
507 int key = GetKeyAssociatedToAction(at);
508 if (key)
509 layout[key].clear();
510 }
511
GetKeyFromKeyName(const std::string & name) const512 int ManMachineInterface::GetKeyFromKeyName(const std::string &name) const
513 {
514 if(name == "unknown") return SDLK_UNKNOWN;
515
516 // The keyboard syms have been cleverly chosen to map to ASCII
517 if(name == "backspace") return SDLK_BACKSPACE;
518 if(name == "tab") return SDLK_TAB;
519 if(name == "clear") return SDLK_CLEAR;
520 if(name == "return") return SDLK_RETURN;
521 if(name == "pause") return SDLK_PAUSE;
522 if(name == "escape") return SDLK_ESCAPE;
523 if(name == "space") return SDLK_SPACE;
524 if(name == "exclaim") return SDLK_EXCLAIM;
525 if(name == "quotedbl") return SDLK_QUOTEDBL;
526 if(name == "hash") return SDLK_HASH;
527 if(name == "dollar") return SDLK_DOLLAR;
528 if(name == "ampersand") return SDLK_AMPERSAND;
529 if(name == "quote") return SDLK_QUOTE;
530 if(name == "leftparen") return SDLK_LEFTPAREN;
531 if(name == "rightparen") return SDLK_RIGHTPAREN;
532 if(name == "asterisk") return SDLK_ASTERISK;
533 if(name == "plus") return SDLK_PLUS;
534 if(name == "comma") return SDLK_COMMA;
535 if(name == "minus") return SDLK_MINUS;
536 if(name == "period") return SDLK_PERIOD;
537 if(name == "slash") return SDLK_SLASH;
538 if(name == "0") return SDLK_0;
539 if(name == "1") return SDLK_1;
540 if(name == "2") return SDLK_2;
541 if(name == "3") return SDLK_3;
542 if(name == "4") return SDLK_4;
543 if(name == "5") return SDLK_5;
544 if(name == "6") return SDLK_6;
545 if(name == "7") return SDLK_7;
546 if(name == "8") return SDLK_8;
547 if(name == "9") return SDLK_9;
548 if(name == "colon") return SDLK_COLON;
549 if(name == "semicolon") return SDLK_SEMICOLON;
550 if(name == "less") return SDLK_LESS;
551 if(name == "equals") return SDLK_EQUALS;
552 if(name == "greater") return SDLK_GREATER;
553 if(name == "question") return SDLK_QUESTION;
554 if(name == "at") return SDLK_AT;
555
556 //Skip uppercase letters
557 if(name == "leftbracket") return SDLK_LEFTBRACKET;
558 if(name == "backslash") return SDLK_BACKSLASH;
559 if(name == "rightbracket") return SDLK_RIGHTBRACKET;
560 if(name == "caret") return SDLK_CARET;
561 if(name == "underscore") return SDLK_UNDERSCORE;
562 if(name == "backquote") return SDLK_BACKQUOTE;
563 if(name == "a") return SDLK_a;
564 if(name == "b") return SDLK_b;
565 if(name == "c") return SDLK_c;
566 if(name == "d") return SDLK_d;
567 if(name == "e") return SDLK_e;
568 if(name == "f") return SDLK_f;
569 if(name == "g") return SDLK_g;
570 if(name == "h") return SDLK_h;
571 if(name == "i") return SDLK_i;
572 if(name == "j") return SDLK_j;
573 if(name == "k") return SDLK_k;
574 if(name == "l") return SDLK_l;
575 if(name == "m") return SDLK_m;
576 if(name == "n") return SDLK_n;
577 if(name == "o") return SDLK_o;
578 if(name == "p") return SDLK_p;
579 if(name == "q") return SDLK_q;
580 if(name == "r") return SDLK_r;
581 if(name == "s") return SDLK_s;
582 if(name == "t") return SDLK_t;
583 if(name == "u") return SDLK_u;
584 if(name == "v") return SDLK_v;
585 if(name == "w") return SDLK_w;
586 if(name == "x") return SDLK_x;
587 if(name == "y") return SDLK_y;
588 if(name == "z") return SDLK_z;
589 if(name == "delete") return SDLK_DELETE;
590 // End of ASCII mapped keysyms
591
592 #if SDL_MINOR_VERSION == 2
593 // International keyboard syms
594 if(name == "world_0") return SDLK_WORLD_0;
595 if(name == "world_1") return SDLK_WORLD_1;
596 if(name == "world_2") return SDLK_WORLD_2;
597 if(name == "world_3") return SDLK_WORLD_3;
598 if(name == "world_4") return SDLK_WORLD_4;
599 if(name == "world_5") return SDLK_WORLD_5;
600 if(name == "world_6") return SDLK_WORLD_6;
601 if(name == "world_7") return SDLK_WORLD_7;
602 if(name == "world_8") return SDLK_WORLD_8;
603 if(name == "world_9") return SDLK_WORLD_9;
604 if(name == "world_10") return SDLK_WORLD_10;
605 if(name == "world_11") return SDLK_WORLD_11;
606 if(name == "world_12") return SDLK_WORLD_12;
607 if(name == "world_13") return SDLK_WORLD_13;
608 if(name == "world_14") return SDLK_WORLD_14;
609 if(name == "world_15") return SDLK_WORLD_15;
610 if(name == "world_16") return SDLK_WORLD_16;
611 if(name == "world_17") return SDLK_WORLD_17;
612 if(name == "world_18") return SDLK_WORLD_18;
613 if(name == "world_19") return SDLK_WORLD_19;
614 if(name == "world_20") return SDLK_WORLD_20;
615 if(name == "world_21") return SDLK_WORLD_21;
616 if(name == "world_22") return SDLK_WORLD_22;
617 if(name == "world_23") return SDLK_WORLD_23;
618 if(name == "world_24") return SDLK_WORLD_24;
619 if(name == "world_25") return SDLK_WORLD_25;
620 if(name == "world_26") return SDLK_WORLD_26;
621 if(name == "world_27") return SDLK_WORLD_27;
622 if(name == "world_28") return SDLK_WORLD_28;
623 if(name == "world_29") return SDLK_WORLD_29;
624 if(name == "world_30") return SDLK_WORLD_30;
625 if(name == "world_31") return SDLK_WORLD_31;
626 if(name == "world_32") return SDLK_WORLD_32;
627 if(name == "world_33") return SDLK_WORLD_33;
628 if(name == "world_34") return SDLK_WORLD_34;
629 if(name == "world_35") return SDLK_WORLD_35;
630 if(name == "world_36") return SDLK_WORLD_36;
631 if(name == "world_37") return SDLK_WORLD_37;
632 if(name == "world_38") return SDLK_WORLD_38;
633 if(name == "world_39") return SDLK_WORLD_39;
634 if(name == "world_40") return SDLK_WORLD_40;
635 if(name == "world_41") return SDLK_WORLD_41;
636 if(name == "world_42") return SDLK_WORLD_42;
637 if(name == "world_43") return SDLK_WORLD_43;
638 if(name == "world_44") return SDLK_WORLD_44;
639 if(name == "world_45") return SDLK_WORLD_45;
640 if(name == "world_46") return SDLK_WORLD_46;
641 if(name == "world_47") return SDLK_WORLD_47;
642 if(name == "world_48") return SDLK_WORLD_48;
643 if(name == "world_49") return SDLK_WORLD_49;
644 if(name == "world_50") return SDLK_WORLD_50;
645 if(name == "world_51") return SDLK_WORLD_51;
646 if(name == "world_52") return SDLK_WORLD_52;
647 if(name == "world_53") return SDLK_WORLD_53;
648 if(name == "world_54") return SDLK_WORLD_54;
649 if(name == "world_55") return SDLK_WORLD_55;
650 if(name == "world_56") return SDLK_WORLD_56;
651 if(name == "world_57") return SDLK_WORLD_57;
652 if(name == "world_58") return SDLK_WORLD_58;
653 if(name == "world_59") return SDLK_WORLD_59;
654 if(name == "world_60") return SDLK_WORLD_60;
655 if(name == "world_61") return SDLK_WORLD_61;
656 if(name == "world_62") return SDLK_WORLD_62;
657 if(name == "world_63") return SDLK_WORLD_63;
658 if(name == "world_64") return SDLK_WORLD_64;
659 if(name == "world_65") return SDLK_WORLD_65;
660 if(name == "world_66") return SDLK_WORLD_66;
661 if(name == "world_67") return SDLK_WORLD_67;
662 if(name == "world_68") return SDLK_WORLD_68;
663 if(name == "world_69") return SDLK_WORLD_69;
664 if(name == "world_70") return SDLK_WORLD_70;
665 if(name == "world_71") return SDLK_WORLD_71;
666 if(name == "world_72") return SDLK_WORLD_72;
667 if(name == "world_73") return SDLK_WORLD_73;
668 if(name == "world_74") return SDLK_WORLD_74;
669 if(name == "world_75") return SDLK_WORLD_75;
670 if(name == "world_76") return SDLK_WORLD_76;
671 if(name == "world_77") return SDLK_WORLD_77;
672 if(name == "world_78") return SDLK_WORLD_78;
673 if(name == "world_79") return SDLK_WORLD_79;
674 if(name == "world_80") return SDLK_WORLD_80;
675 if(name == "world_81") return SDLK_WORLD_81;
676 if(name == "world_82") return SDLK_WORLD_82;
677 if(name == "world_83") return SDLK_WORLD_83;
678 if(name == "world_84") return SDLK_WORLD_84;
679 if(name == "world_85") return SDLK_WORLD_85;
680 if(name == "world_86") return SDLK_WORLD_86;
681 if(name == "world_87") return SDLK_WORLD_87;
682 if(name == "world_88") return SDLK_WORLD_88;
683 if(name == "world_89") return SDLK_WORLD_89;
684 if(name == "world_90") return SDLK_WORLD_90;
685 if(name == "world_91") return SDLK_WORLD_91;
686 if(name == "world_92") return SDLK_WORLD_92;
687 if(name == "world_93") return SDLK_WORLD_93;
688 if(name == "world_94") return SDLK_WORLD_94;
689 if(name == "world_95") return SDLK_WORLD_95;
690 #endif
691
692 // Numeric keypad
693 if(name == "kp0") return SDLK_KP0;
694 if(name == "kp1") return SDLK_KP1;
695 if(name == "kp2") return SDLK_KP2;
696 if(name == "kp3") return SDLK_KP3;
697 if(name == "kp4") return SDLK_KP4;
698 if(name == "kp5") return SDLK_KP5;
699 if(name == "kp6") return SDLK_KP6;
700 if(name == "kp7") return SDLK_KP7;
701 if(name == "kp8") return SDLK_KP8;
702 if(name == "kp9") return SDLK_KP9;
703 if(name == "kp_period") return SDLK_KP_PERIOD;
704 if(name == "kp_divide") return SDLK_KP_DIVIDE;
705 if(name == "kp_multiply") return SDLK_KP_MULTIPLY;
706 if(name == "kp_minus") return SDLK_KP_MINUS;
707 if(name == "kp_plus") return SDLK_KP_PLUS;
708 if(name == "kp_enter") return SDLK_KP_ENTER;
709 if(name == "kp_equals") return SDLK_KP_EQUALS;
710
711 // Arrows + Home/End pad
712 if(name == "up") return SDLK_UP;
713 if(name == "down") return SDLK_DOWN;
714 if(name == "right") return SDLK_RIGHT;
715 if(name == "left") return SDLK_LEFT;
716 if(name == "insert") return SDLK_INSERT;
717 if(name == "home") return SDLK_HOME;
718 if(name == "end") return SDLK_END;
719 if(name == "pageup") return SDLK_PAGEUP;
720 if(name == "pagedown") return SDLK_PAGEDOWN;
721
722 // Function keys
723 if(name == "f1") return SDLK_F1;
724 if(name == "f2") return SDLK_F2;
725 if(name == "f3") return SDLK_F3;
726 if(name == "f4") return SDLK_F4;
727 if(name == "f5") return SDLK_F5;
728 if(name == "f6") return SDLK_F6;
729 if(name == "f7") return SDLK_F7;
730 if(name == "f8") return SDLK_F8;
731 if(name == "f9") return SDLK_F9;
732 if(name == "f10") return SDLK_F10;
733 if(name == "f11") return SDLK_F11;
734 if(name == "f12") return SDLK_F12;
735 if(name == "f13") return SDLK_F13;
736 if(name == "f14") return SDLK_F14;
737 if(name == "F15") return SDLK_F15;
738
739 // Key state modifier keys
740 if(name == "numlock") return SDLK_NUMLOCK;
741 if(name == "capslock") return SDLK_CAPSLOCK;
742 if(name == "scrollock") return SDLK_SCROLLOCK;
743 if(name == "rshift") return SDLK_RSHIFT;
744 if(name == "lshift") return SDLK_LSHIFT;
745 if(name == "rctrl") return SDLK_RCTRL;
746 if(name == "lctrl") return SDLK_LCTRL;
747 if(name == "ralt") return SDLK_RALT;
748 if(name == "lalt") return SDLK_LALT;
749 if(name == "rmeta") return SDLK_RMETA;
750 if(name == "lmeta") return SDLK_LMETA;
751 if(name == "lsuper") return SDLK_LSUPER;
752 if(name == "rsuper") return SDLK_RSUPER;
753 if(name == "mode") return SDLK_MODE;
754 if(name == "compose") return SDLK_COMPOSE;
755
756 // Miscellaneous function keys
757 if(name == "help") return SDLK_HELP;
758 if(name == "print") return SDLK_PRINT;
759 if(name == "sysreq") return SDLK_SYSREQ;
760 if(name == "break") return SDLK_BREAK;
761 if(name == "menu") return SDLK_MENU;
762 if(name == "power") return SDLK_POWER;
763 if(name == "euro") return SDLK_EURO;
764 if(name == "undo") return SDLK_UNDO;
765
766 return SDLK_UNKNOWN;
767 }
768
GetKeyNameFromKey(int key) const769 std::string ManMachineInterface::GetKeyNameFromKey(int key) const
770 {
771 if(key == SDLK_UNKNOWN) return "unknown";
772
773 // The keyboard syms have been cleverly chosen to map to ASCII
774 if(key == SDLK_BACKSPACE) return "backspace";
775 if(key == SDLK_TAB) return "tab";
776 if(key == SDLK_CLEAR) return "clear";
777 if(key == SDLK_RETURN) return "return";
778 if(key == SDLK_PAUSE) return "pause";
779 if(key == SDLK_ESCAPE) return "escape";
780 if(key == SDLK_SPACE) return "space";
781 if(key == SDLK_EXCLAIM) return "exclaim";
782 if(key == SDLK_QUOTEDBL) return "quotedbl";
783 if(key == SDLK_HASH) return "hash";
784 if(key == SDLK_DOLLAR) return "dollar";
785 if(key == SDLK_AMPERSAND) return "ampersand";
786 if(key == SDLK_QUOTE) return "quote";
787 if(key == SDLK_LEFTPAREN) return "leftparen";
788 if(key == SDLK_RIGHTPAREN) return "rightparen";
789 if(key == SDLK_ASTERISK) return "asterisk";
790 if(key == SDLK_PLUS) return "plus";
791 if(key == SDLK_COMMA) return "comma";
792 if(key == SDLK_MINUS) return "minus";
793 if(key == SDLK_PERIOD) return "period";
794 if(key == SDLK_SLASH) return "slash";
795 if(key == SDLK_0) return "0";
796 if(key == SDLK_1) return "1";
797 if(key == SDLK_2) return "2";
798 if(key == SDLK_3) return "3";
799 if(key == SDLK_4) return "4";
800 if(key == SDLK_5) return "5";
801 if(key == SDLK_6) return "6";
802 if(key == SDLK_7) return "7";
803 if(key == SDLK_8) return "8";
804 if(key == SDLK_9) return "9";
805 if(key == SDLK_COLON) return "colon";
806 if(key == SDLK_SEMICOLON) return "semicolon";
807 if(key == SDLK_LESS) return "less";
808 if(key == SDLK_EQUALS) return "equals";
809 if(key == SDLK_GREATER) return "greater";
810 if(key == SDLK_QUESTION) return "question";
811 if(key == SDLK_AT) return "at";
812
813 //Skip uppercase letters
814 if(key == SDLK_LEFTBRACKET) return "leftbracket";
815 if(key == SDLK_BACKSLASH) return "backslash";
816 if(key == SDLK_RIGHTBRACKET) return "rightbracket";
817 if(key == SDLK_CARET) return "caret";
818 if(key == SDLK_UNDERSCORE) return "underscore";
819 if(key == SDLK_BACKQUOTE) return "backquote";
820 if(key == SDLK_a) return "a";
821 if(key == SDLK_b) return "b";
822 if(key == SDLK_c) return "c";
823 if(key == SDLK_d) return "d";
824 if(key == SDLK_e) return "e";
825 if(key == SDLK_f) return "f";
826 if(key == SDLK_g) return "g";
827 if(key == SDLK_h) return "h";
828 if(key == SDLK_i) return "i";
829 if(key == SDLK_j) return "j";
830 if(key == SDLK_k) return "k";
831 if(key == SDLK_l) return "l";
832 if(key == SDLK_m) return "m";
833 if(key == SDLK_n) return "n";
834 if(key == SDLK_o) return "o";
835 if(key == SDLK_p) return "p";
836 if(key == SDLK_q) return "q";
837 if(key == SDLK_r) return "r";
838 if(key == SDLK_s) return "s";
839 if(key == SDLK_t) return "t";
840 if(key == SDLK_u) return "u";
841 if(key == SDLK_v) return "v";
842 if(key == SDLK_w) return "w";
843 if(key == SDLK_x) return "x";
844 if(key == SDLK_y) return "y";
845 if(key == SDLK_z) return "z";
846 if(key == SDLK_DELETE) return "delete";
847 // End of ASCII mapped keysyms
848
849 #if SDL_MINOR_VERSION == 2
850 // International keyboard syms
851 if(key == SDLK_WORLD_0) return "world_0";
852 if(key == SDLK_WORLD_1) return "world_1";
853 if(key == SDLK_WORLD_2) return "world_2";
854 if(key == SDLK_WORLD_3) return "world_3";
855 if(key == SDLK_WORLD_4) return "world_4";
856 if(key == SDLK_WORLD_5) return "world_5";
857 if(key == SDLK_WORLD_6) return "world_6";
858 if(key == SDLK_WORLD_7) return "world_7";
859 if(key == SDLK_WORLD_8) return "world_8";
860 if(key == SDLK_WORLD_9) return "world_9";
861 if(key == SDLK_WORLD_10) return "world_10";
862 if(key == SDLK_WORLD_11) return "world_11";
863 if(key == SDLK_WORLD_12) return "world_12";
864 if(key == SDLK_WORLD_13) return "world_13";
865 if(key == SDLK_WORLD_14) return "world_14";
866 if(key == SDLK_WORLD_15) return "world_15";
867 if(key == SDLK_WORLD_16) return "world_16";
868 if(key == SDLK_WORLD_17) return "world_17";
869 if(key == SDLK_WORLD_18) return "world_18";
870 if(key == SDLK_WORLD_19) return "world_19";
871 if(key == SDLK_WORLD_20) return "world_20";
872 if(key == SDLK_WORLD_21) return "world_21";
873 if(key == SDLK_WORLD_22) return "world_22";
874 if(key == SDLK_WORLD_23) return "world_23";
875 if(key == SDLK_WORLD_24) return "world_24";
876 if(key == SDLK_WORLD_25) return "world_25";
877 if(key == SDLK_WORLD_26) return "world_26";
878 if(key == SDLK_WORLD_27) return "world_27";
879 if(key == SDLK_WORLD_28) return "world_28";
880 if(key == SDLK_WORLD_29) return "world_29";
881 if(key == SDLK_WORLD_30) return "world_30";
882 if(key == SDLK_WORLD_31) return "world_31";
883 if(key == SDLK_WORLD_32) return "world_32";
884 if(key == SDLK_WORLD_33) return "world_33";
885 if(key == SDLK_WORLD_34) return "world_34";
886 if(key == SDLK_WORLD_35) return "world_35";
887 if(key == SDLK_WORLD_36) return "world_36";
888 if(key == SDLK_WORLD_37) return "world_37";
889 if(key == SDLK_WORLD_38) return "world_38";
890 if(key == SDLK_WORLD_39) return "world_39";
891 if(key == SDLK_WORLD_40) return "world_40";
892 if(key == SDLK_WORLD_41) return "world_41";
893 if(key == SDLK_WORLD_42) return "world_42";
894 if(key == SDLK_WORLD_43) return "world_43";
895 if(key == SDLK_WORLD_44) return "world_44";
896 if(key == SDLK_WORLD_45) return "world_45";
897 if(key == SDLK_WORLD_46) return "world_46";
898 if(key == SDLK_WORLD_47) return "world_47";
899 if(key == SDLK_WORLD_48) return "world_48";
900 if(key == SDLK_WORLD_49) return "world_49";
901 if(key == SDLK_WORLD_50) return "world_50";
902 if(key == SDLK_WORLD_51) return "world_51";
903 if(key == SDLK_WORLD_52) return "world_52";
904 if(key == SDLK_WORLD_53) return "world_53";
905 if(key == SDLK_WORLD_54) return "world_54";
906 if(key == SDLK_WORLD_55) return "world_55";
907 if(key == SDLK_WORLD_56) return "world_56";
908 if(key == SDLK_WORLD_57) return "world_57";
909 if(key == SDLK_WORLD_58) return "world_58";
910 if(key == SDLK_WORLD_59) return "world_59";
911 if(key == SDLK_WORLD_60) return "world_60";
912 if(key == SDLK_WORLD_61) return "world_61";
913 if(key == SDLK_WORLD_62) return "world_62";
914 if(key == SDLK_WORLD_63) return "world_63";
915 if(key == SDLK_WORLD_64) return "world_64";
916 if(key == SDLK_WORLD_65) return "world_65";
917 if(key == SDLK_WORLD_66) return "world_66";
918 if(key == SDLK_WORLD_67) return "world_67";
919 if(key == SDLK_WORLD_68) return "world_68";
920 if(key == SDLK_WORLD_69) return "world_69";
921 if(key == SDLK_WORLD_70) return "world_70";
922 if(key == SDLK_WORLD_71) return "world_71";
923 if(key == SDLK_WORLD_72) return "world_72";
924 if(key == SDLK_WORLD_73) return "world_73";
925 if(key == SDLK_WORLD_74) return "world_74";
926 if(key == SDLK_WORLD_75) return "world_75";
927 if(key == SDLK_WORLD_76) return "world_76";
928 if(key == SDLK_WORLD_77) return "world_77";
929 if(key == SDLK_WORLD_78) return "world_78";
930 if(key == SDLK_WORLD_79) return "world_79";
931 if(key == SDLK_WORLD_80) return "world_80";
932 if(key == SDLK_WORLD_81) return "world_81";
933 if(key == SDLK_WORLD_82) return "world_82";
934 if(key == SDLK_WORLD_83) return "world_83";
935 if(key == SDLK_WORLD_84) return "world_84";
936 if(key == SDLK_WORLD_85) return "world_85";
937 if(key == SDLK_WORLD_86) return "world_86";
938 if(key == SDLK_WORLD_87) return "world_87";
939 if(key == SDLK_WORLD_88) return "world_88";
940 if(key == SDLK_WORLD_89) return "world_89";
941 if(key == SDLK_WORLD_90) return "world_90";
942 if(key == SDLK_WORLD_91) return "world_91";
943 if(key == SDLK_WORLD_92) return "world_92";
944 if(key == SDLK_WORLD_93) return "world_93";
945 if(key == SDLK_WORLD_94) return "world_94";
946 if(key == SDLK_WORLD_95) return "world_95";
947 #endif
948
949 // Numeric keypad
950 if(key == SDLK_KP0) return "kp0";
951 if(key == SDLK_KP1) return "kp1";
952 if(key == SDLK_KP2) return "kp2";
953 if(key == SDLK_KP3) return "kp3";
954 if(key == SDLK_KP4) return "kp4";
955 if(key == SDLK_KP5) return "kp5";
956 if(key == SDLK_KP6) return "kp6";
957 if(key == SDLK_KP7) return "kp7";
958 if(key == SDLK_KP8) return "kp8";
959 if(key == SDLK_KP9) return "kp9";
960 if(key == SDLK_KP_PERIOD) return "kp_period";
961 if(key == SDLK_KP_DIVIDE) return "kp_divide";
962 if(key == SDLK_KP_MULTIPLY) return "kp_multiply";
963 if(key == SDLK_KP_MINUS) return "kp_minus";
964 if(key == SDLK_KP_PLUS) return "kp_plus";
965 if(key == SDLK_KP_ENTER) return "kp_enter";
966 if(key == SDLK_KP_EQUALS) return "kp_equals";
967
968 // Arrows + Home/End pad
969 if(key == SDLK_UP) return "up";
970 if(key == SDLK_DOWN) return "down";
971 if(key == SDLK_RIGHT) return "right";
972 if(key == SDLK_LEFT) return "left";
973 if(key == SDLK_INSERT) return "insert";
974 if(key == SDLK_HOME) return "home";
975 if(key == SDLK_END) return "end";
976 if(key == SDLK_PAGEUP) return "pageup";
977 if(key == SDLK_PAGEDOWN) return "pagedown";
978
979 // Function keys
980 if(key == SDLK_F1) return "f1";
981 if(key == SDLK_F2) return "f2";
982 if(key == SDLK_F3) return "f3";
983 if(key == SDLK_F4) return "f4";
984 if(key == SDLK_F5) return "f5";
985 if(key == SDLK_F6) return "f6";
986 if(key == SDLK_F7) return "f7";
987 if(key == SDLK_F8) return "f8";
988 if(key == SDLK_F9) return "f9";
989 if(key == SDLK_F10) return "f10";
990 if(key == SDLK_F11) return "f11";
991 if(key == SDLK_F12) return "f12";
992 if(key == SDLK_F13) return "f13";
993 if(key == SDLK_F14) return "f14";
994 if(key == SDLK_F15) return "f15";
995
996 // Key state modifier keys
997 if(key == SDLK_NUMLOCK) return "numlock";
998 if(key == SDLK_CAPSLOCK) return "capslock";
999 if(key == SDLK_SCROLLOCK) return "scrollock";
1000 if(key == SDLK_RSHIFT) return "rshift";
1001 if(key == SDLK_LSHIFT) return "lshift";
1002 if(key == SDLK_RCTRL) return "rctrl";
1003 if(key == SDLK_LCTRL) return "lctrl";
1004 if(key == SDLK_RALT) return "ralt";
1005 if(key == SDLK_LALT) return "lalt";
1006 if(key == SDLK_RMETA) return "rmeta";
1007 if(key == SDLK_LMETA) return "lmeta";
1008 if(key == SDLK_LSUPER) return "lsuper";
1009 if(key == SDLK_RSUPER) return "rsuper";
1010 if(key == SDLK_MODE) return "mode";
1011 if(key == SDLK_COMPOSE) return "compose";
1012
1013 // Miscellaneous function keys
1014 if(key == SDLK_HELP) return "help";
1015 if(key == SDLK_PRINT) return "print";
1016 if(key == SDLK_SYSREQ) return "sysreq";
1017 if(key == SDLK_BREAK) return "break";
1018 if(key == SDLK_MENU) return "menu";
1019 if(key == SDLK_POWER) return "power";
1020 if(key == SDLK_EURO) return "euro";
1021 if(key == SDLK_UNDO) return "undo";
1022
1023 return "unknown";
1024 }
1025
GetActionFromActionName(const std::string & name) const1026 ManMachineInterface::Key_t ManMachineInterface::GetActionFromActionName(const std::string &name) const
1027 {
1028 if(name == "quit") return KEY_QUIT;
1029 if(name == "weapons1") return KEY_WEAPONS1;
1030 if(name == "weapons2") return KEY_WEAPONS2;
1031 if(name == "weapons3") return KEY_WEAPONS3;
1032 if(name == "weapons4") return KEY_WEAPONS4;
1033 if(name == "weapons5") return KEY_WEAPONS5;
1034 if(name == "weapons6") return KEY_WEAPONS6;
1035 if(name == "weapons7") return KEY_WEAPONS7;
1036 if(name == "weapons8") return KEY_WEAPONS8;
1037 if(name == "PAUSE") return KEY_PAUSE;
1038 if(name == "fullscreen") return KEY_FULLSCREEN;
1039 if(name == "toggle_interface") return KEY_TOGGLE_INTERFACE;
1040 if(name == "center") return KEY_CENTER;
1041 if(name == "toggle_weapons_menus") return KEY_TOGGLE_WEAPONS_MENUS;
1042 if(name == "chat") return KEY_CHAT;
1043 if(name == "move_left") return KEY_MOVE_LEFT;
1044 if(name == "move_left_slowly") return KEY_MOVE_LEFT_SLOWLY;
1045 if(name == "move_right") return KEY_MOVE_RIGHT;
1046 if(name == "move_right_slowly") return KEY_MOVE_RIGHT_SLOWLY;
1047 if(name == "up") return KEY_UP;
1048 if(name == "up_slowly") return KEY_UP_SLOWLY;
1049 if(name == "down") return KEY_DOWN;
1050 if(name == "down_slowly") return KEY_DOWN_SLOWLY;
1051 if(name == "move_camera_left") return KEY_MOVE_CAMERA_LEFT;
1052 if(name == "move_camera_right") return KEY_MOVE_CAMERA_RIGHT;
1053 if(name == "move_camera_up") return KEY_MOVE_CAMERA_UP;
1054 if(name == "move_camera_down") return KEY_MOVE_CAMERA_DOWN;
1055 if(name == "jump") return KEY_JUMP;
1056 if(name == "high_jump") return KEY_HIGH_JUMP;
1057 if(name == "help") return KEY_HELP;
1058 if(name == "back_jump") return KEY_BACK_JUMP;
1059 if(name == "shoot") return KEY_SHOOT;
1060 if(name == "change_weapon") return KEY_CHANGE_WEAPON;
1061 if(name == "weapon_1") return KEY_WEAPON_1;
1062 if(name == "weapon_2") return KEY_WEAPON_2;
1063 if(name == "weapon_3") return KEY_WEAPON_3;
1064 if(name == "weapon_4") return KEY_WEAPON_4;
1065 if(name == "weapon_5") return KEY_WEAPON_5;
1066 if(name == "weapon_6") return KEY_WEAPON_6;
1067 if(name == "weapon_7") return KEY_WEAPON_7;
1068 if(name == "weapon_8") return KEY_WEAPON_8;
1069 if(name == "weapon_9") return KEY_WEAPON_9;
1070 if(name == "weapon_less") return KEY_WEAPON_LESS;
1071 if(name == "weapon_more") return KEY_WEAPON_MORE;
1072 if(name == "next_character") return KEY_NEXT_CHARACTER;
1073 if(name == "menu_options_from_game") return KEY_MENU_OPTIONS_FROM_GAME;
1074 if(name == "minimap_from_game") return KEY_MINIMAP_FROM_GAME;
1075 if(name == "decrease_minimap") return KEY_DECREASE_MINIMAP;
1076 if(name == "increase_minimap") return KEY_INCREASE_MINIMAP;
1077 if(name == "decrease_volume") return KEY_DECREASE_VOLUME;
1078 if(name == "increase_volume") return KEY_INCREASE_VOLUME;
1079 if(name == "screenshot") return KEY_SCREENSHOT;
1080
1081 return KEY_NONE;
1082 }
1083
GetActionNameFromAction(ManMachineInterface::Key_t key) const1084 std::string ManMachineInterface::GetActionNameFromAction(ManMachineInterface::Key_t key) const
1085 {
1086 if(key == KEY_QUIT) return "quit";
1087 if(key == KEY_WEAPONS1) return "weapons1";
1088 if(key == KEY_WEAPONS2) return "weapons2";
1089 if(key == KEY_WEAPONS3) return "weapons3";
1090 if(key == KEY_WEAPONS4) return "weapons4";
1091 if(key == KEY_WEAPONS5) return "weapons5";
1092 if(key == KEY_WEAPONS6) return "weapons6";
1093 if(key == KEY_WEAPONS7) return "weapons7";
1094 if(key == KEY_WEAPONS8) return "weapons8";
1095 if(key == KEY_PAUSE) return "pause";
1096 if(key == KEY_FULLSCREEN) return "fullscreen";
1097 if(key == KEY_TOGGLE_INTERFACE) return "toggle_interface";
1098 if(key == KEY_CENTER) return "center";
1099 if(key == KEY_TOGGLE_WEAPONS_MENUS) return "toggle_weapons_menus";
1100 if(key == KEY_CHAT) return "chat";
1101 if(key == KEY_MOVE_LEFT) return "move_left";
1102 if(key == KEY_MOVE_LEFT_SLOWLY) return "move_left_slowly";
1103 if(key == KEY_MOVE_RIGHT) return "move_right";
1104 if(key == KEY_MOVE_RIGHT_SLOWLY) return "move_right_slowly";
1105 if(key == KEY_UP) return "up";
1106 if(key == KEY_UP_SLOWLY) return "up_slowly";
1107 if(key == KEY_DOWN) return "down";
1108 if(key == KEY_DOWN_SLOWLY) return "down_slowly";
1109 if(key == KEY_MOVE_CAMERA_LEFT) return "move_camera_left";
1110 if(key == KEY_MOVE_CAMERA_RIGHT) return "move_camera_right";
1111 if(key == KEY_MOVE_CAMERA_UP) return "move_camera_up";
1112 if(key == KEY_MOVE_CAMERA_DOWN) return "move_camera_down";
1113 if(key == KEY_JUMP) return "jump";
1114 if(key == KEY_HIGH_JUMP) return "high_jump";
1115 if(key == KEY_HELP) return "help";
1116 if(key == KEY_BACK_JUMP) return "back_jump";
1117 if(key == KEY_SHOOT) return "shoot";
1118 if(key == KEY_CHANGE_WEAPON) return "change_weapon";
1119 if(key == KEY_WEAPON_1) return "weapon_1";
1120 if(key == KEY_WEAPON_2) return "weapon_2";
1121 if(key == KEY_WEAPON_3) return "weapon_3";
1122 if(key == KEY_WEAPON_4) return "weapon_4";
1123 if(key == KEY_WEAPON_5) return "weapon_5";
1124 if(key == KEY_WEAPON_6) return "weapon_6";
1125 if(key == KEY_WEAPON_7) return "weapon_7";
1126 if(key == KEY_WEAPON_8) return "weapon_8";
1127 if(key == KEY_WEAPON_9) return "weapon_9";
1128 if(key == KEY_WEAPON_LESS) return "weapon_less";
1129 if(key == KEY_WEAPON_MORE) return "weapon_more";
1130 if(key == KEY_NEXT_CHARACTER) return "next_character";
1131 if(key == KEY_MENU_OPTIONS_FROM_GAME) return "menu_options_from_game";
1132 if(key == KEY_MINIMAP_FROM_GAME) return "minimap_from_game";
1133 if(key == KEY_DECREASE_MINIMAP) return "decrease_minimap";
1134 if(key == KEY_INCREASE_MINIMAP) return "increase_minimap";
1135 if(key == KEY_DECREASE_VOLUME) return "decrease_volume";
1136 if(key == KEY_INCREASE_VOLUME) return "increase_volume";
1137 if(key == KEY_SCREENSHOT) return "screenshot";
1138
1139 return "none";
1140 }
1141
GetHumanReadableActionName(Key_t key) const1142 std::string ManMachineInterface::GetHumanReadableActionName(Key_t key) const
1143 {
1144 if(key == KEY_QUIT) return _("Quit");
1145 if(key == KEY_WEAPONS1) return _("'Heavy' weapon category");
1146 if(key == KEY_WEAPONS2) return _("'Rifle' weapon category");
1147 if(key == KEY_WEAPONS3) return _("'Throwing' weapon category");
1148 if(key == KEY_WEAPONS4) return _("'Special' weapon category");
1149 if(key == KEY_WEAPONS5) return _("'Duel' weapon category");
1150 if(key == KEY_WEAPONS6) return _("'Move' weapon category");
1151 if(key == KEY_WEAPONS7) return _("'Tool' weapon category");
1152 if(key == KEY_WEAPONS8) return _("Weapon category 8");
1153 if(key == KEY_PAUSE) return _("Pause");
1154 if(key == KEY_FULLSCREEN) return _("Toggle fullscreen");
1155 if(key == KEY_TOGGLE_INTERFACE) return _("Toggle interface");
1156 if(key == KEY_CENTER) return _("Center on active character");
1157 if(key == KEY_TOGGLE_WEAPONS_MENUS) return _("Toggle weapons menu");
1158 if(key == KEY_CHAT) return _("Chat");
1159 if(key == KEY_MOVE_LEFT) return _("Move left");
1160 if(key == KEY_MOVE_LEFT_SLOWLY) return _("Move left slowly");
1161 if(key == KEY_MOVE_RIGHT) return _("Move right");
1162 if(key == KEY_MOVE_RIGHT_SLOWLY) return _("Move right slowly");
1163 if(key == KEY_UP) return _("Up");
1164 if(key == KEY_UP_SLOWLY) return _("Up slowly");
1165 if(key == KEY_DOWN) return _("Down");
1166 if(key == KEY_DOWN_SLOWLY) return _("Down slowly");
1167 if(key == KEY_MOVE_CAMERA_LEFT) return _("Move camera left");
1168 if(key == KEY_MOVE_CAMERA_RIGHT) return _("Move camera right");
1169 if(key == KEY_MOVE_CAMERA_UP) return _("Move camera up");
1170 if(key == KEY_MOVE_CAMERA_DOWN) return _("Move camera down");
1171 if(key == KEY_JUMP) return _("Jump");
1172 if(key == KEY_HIGH_JUMP) return _("High jump");
1173 if(key == KEY_HELP) return _("Help");
1174 if(key == KEY_BACK_JUMP) return _("Back jump");
1175 if(key == KEY_SHOOT) return _("Shoot");
1176 if(key == KEY_CHANGE_WEAPON) return _("Change weapon");
1177 if(key == KEY_WEAPON_1) return Format(_("Explosion delay of %u"), 1);
1178 if(key == KEY_WEAPON_2) return Format(_("Explosion delay of %u"), 2);
1179 if(key == KEY_WEAPON_3) return Format(_("Explosion delay of %u"), 3);
1180 if(key == KEY_WEAPON_4) return Format(_("Explosion delay of %u"), 4);
1181 if(key == KEY_WEAPON_5) return Format(_("Explosion delay of %u"), 5);
1182 if(key == KEY_WEAPON_6) return Format(_("Explosion delay of %u"), 6);
1183 if(key == KEY_WEAPON_7) return Format(_("Explosion delay of %u"), 7);
1184 if(key == KEY_WEAPON_8) return Format(_("Explosion delay of %u"), 8);
1185 if(key == KEY_WEAPON_9) return Format(_("Explosion delay of %u"), 9);
1186 if(key == KEY_WEAPON_LESS) return _("Decrease explosion delay");
1187 if(key == KEY_WEAPON_MORE) return _("Increase explosion delay");
1188 if(key == KEY_NEXT_CHARACTER) return _("Next character");
1189 if(key == KEY_MENU_OPTIONS_FROM_GAME) return _("Open options menu");
1190 if(key == KEY_MINIMAP_FROM_GAME) return _("Toggle minimap");
1191 if(key == KEY_DECREASE_MINIMAP) return _("Decrease minimap size");
1192 if(key == KEY_INCREASE_MINIMAP) return _("Increase minimap size");
1193 if(key == KEY_DECREASE_VOLUME) return _("Decrease sound volume");
1194 if(key == KEY_INCREASE_VOLUME) return _("Increase sound volume");
1195 if(key == KEY_SCREENSHOT) return _("Take screenshot");
1196
1197 return _("None");
1198 }
1199