2
0

GameControllerShortcuts.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * GameControllerShortcuts.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "GameControllerShortcuts.h"
  12. #include "../gui/CGuiHandler.h"
  13. #include "../gui/ShortcutHandler.h"
  14. std::vector<EShortcut> getButtonBShortcuts()
  15. {
  16. auto shortcuts = GH.shortcuts().translateKeycode(SDLK_ESCAPE);
  17. // avoid someday ADVENTURE_EXIT_WORLD_VIEW be add in SDLK_ESCAPE shortcuts
  18. if(std::find(shortcuts.begin(), shortcuts.end(), EShortcut::ADVENTURE_EXIT_WORLD_VIEW) == shortcuts.end())
  19. shortcuts.push_back(EShortcut::ADVENTURE_EXIT_WORLD_VIEW);
  20. return shortcuts;
  21. }
  22. std::vector<EShortcut> getButtonXShortcuts()
  23. {
  24. auto shortcuts = GH.shortcuts().translateKeycode(SDLK_RETURN);
  25. // avoid someday ADVENTURE_EXIT_WORLD_VIEW be add in SDLK_RETURN shortcuts
  26. if(std::find(shortcuts.begin(), shortcuts.end(), EShortcut::ADVENTURE_EXIT_WORLD_VIEW) == shortcuts.end())
  27. shortcuts.push_back(EShortcut::ADVENTURE_EXIT_WORLD_VIEW);
  28. return shortcuts;
  29. }
  30. const ButtonShortcutsMap & getButtonShortcutsMap() {
  31. static const ButtonShortcutsMap buttonShortcutsMap =
  32. {
  33. // SDL_CONTROLLER_BUTTON_A for mouse left click
  34. {SDL_CONTROLLER_BUTTON_B, getButtonBShortcuts()},
  35. {SDL_CONTROLLER_BUTTON_X, getButtonXShortcuts()},
  36. // SDL_CONTROLLER_BUTTON_Y for mouse right click
  37. {SDL_CONTROLLER_BUTTON_LEFTSHOULDER, {EShortcut::ADVENTURE_NEXT_HERO, EShortcut::BATTLE_DEFEND}},
  38. {SDL_CONTROLLER_BUTTON_RIGHTSHOULDER, {EShortcut::ADVENTURE_NEXT_TOWN, EShortcut::BATTLE_WAIT}},
  39. {SDL_CONTROLLER_BUTTON_BACK, {EShortcut::GAME_END_TURN, EShortcut::BATTLE_END_WITH_AUTOCOMBAT}},
  40. {SDL_CONTROLLER_BUTTON_START, {EShortcut::GLOBAL_OPTIONS, EShortcut::ADVENTURE_GAME_OPTIONS}},
  41. {SDL_CONTROLLER_BUTTON_DPAD_UP, {EShortcut::MOVE_UP, EShortcut::ADVENTURE_VIEW_WORLD,
  42. EShortcut::RECRUITMENT_UPGRADE,
  43. EShortcut::RECRUITMENT_UPGRADE_ALL,
  44. EShortcut::BATTLE_CONSOLE_UP, EShortcut::RECRUITMENT_MAX}},
  45. {SDL_CONTROLLER_BUTTON_DPAD_DOWN, {EShortcut::MOVE_DOWN, EShortcut::ADVENTURE_KINGDOM_OVERVIEW,
  46. EShortcut::BATTLE_CONSOLE_DOWN, EShortcut::RECRUITMENT_MIN}},
  47. {SDL_CONTROLLER_BUTTON_DPAD_LEFT, {EShortcut::MOVE_LEFT, EShortcut::ADVENTURE_VIEW_SCENARIO}},
  48. {SDL_CONTROLLER_BUTTON_DPAD_RIGHT, {EShortcut::MOVE_RIGHT, EShortcut::ADVENTURE_THIEVES_GUILD}},
  49. {SDL_CONTROLLER_BUTTON_LEFTSTICK, {EShortcut::ADVENTURE_TOGGLE_MAP_LEVEL,
  50. EShortcut::BATTLE_TOGGLE_HEROES_STATS}},
  51. {SDL_CONTROLLER_BUTTON_RIGHTSTICK, {EShortcut::ADVENTURE_TOGGLE_GRID, EShortcut::BATTLE_TOGGLE_QUEUE}}
  52. };
  53. return buttonShortcutsMap;
  54. }
  55. const TriggerShortcutsMap & getTriggerShortcutsMap()
  56. {
  57. static const TriggerShortcutsMap triggerShortcutsMap = {
  58. {SDL_CONTROLLER_AXIS_TRIGGERLEFT, {EShortcut::ADVENTURE_VISIT_OBJECT, EShortcut::BATTLE_TACTICS_NEXT,
  59. EShortcut::BATTLE_USE_CREATURE_SPELL}},
  60. {SDL_CONTROLLER_AXIS_TRIGGERRIGHT, {EShortcut::ADVENTURE_CAST_SPELL, EShortcut::BATTLE_CAST_SPELL}}
  61. };
  62. return triggerShortcutsMap;
  63. }