GameControllerConfig.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * GameControllerConfig.h, 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. #pragma once
  11. #include <SDL.h>
  12. #include "../gui/Shortcut.h"
  13. #include "../../lib/json/JsonUtils.h"
  14. enum AxisType
  15. {
  16. CURSOR_MOTION,
  17. MAP_SCROLL,
  18. NONE
  19. };
  20. class GameControllerConfig {
  21. using ButtonShortcutsMap = std::map<SDL_GameControllerButton, std::vector<EShortcut> >;
  22. using TriggerShortcutsMap = std::map<SDL_GameControllerAxis, std::vector<EShortcut> >;
  23. ButtonShortcutsMap buttonShortcutsMap;
  24. TriggerShortcutsMap triggerShortcutsMap;
  25. std::set<SDL_GameControllerButton> leftClickButtonSet;
  26. std::set<SDL_GameControllerButton> rightClickButtonSet;
  27. std::set<SDL_GameControllerAxis> leftClickTriggerSet;
  28. std::set<SDL_GameControllerAxis> rightClickTriggerSet;
  29. AxisType leftAxisType;
  30. AxisType rightAxisType;
  31. void load();
  32. std::vector<std::string> getOperations(const std::string & key, const JsonNode & value);
  33. AxisType parseAxis(const std::string & key, const JsonNode & value);
  34. void parseTrigger(const std::string & key, const JsonNode & value);
  35. void parseButton(const std::string & key, const JsonNode & value);
  36. public:
  37. GameControllerConfig();
  38. ~GameControllerConfig() = default;
  39. const AxisType & getLeftAxisType();
  40. const AxisType & getRightAxisType();
  41. bool isLeftClickButton(int buttonValue);
  42. bool isRightClickButton(int buttonValue);
  43. bool isShortcutsButton(int buttonValue);
  44. const std::vector<EShortcut> & getButtonShortcuts(int buttonValue);
  45. bool isLeftClickTrigger(int axisValue);
  46. bool isRightClickTrigger(int axisValue);
  47. bool isShortcutsTrigger(int axisValue);
  48. const std::vector<EShortcut> & getTriggerShortcuts(int axisValue);
  49. };