ShortcutHandler.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. /*
  2. * ShortcutHandler.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 "ShortcutHandler.h"
  12. #include "Shortcut.h"
  13. #include "../../lib/json/JsonUtils.h"
  14. ShortcutHandler::ShortcutHandler()
  15. {
  16. const JsonNode config = JsonUtils::assembleFromFiles("config/shortcutsConfig");
  17. mappedKeyboardShortcuts = loadShortcuts(config["keyboard"]);
  18. mappedJoystickShortcuts = loadShortcuts(config["joystickButtons"]);
  19. mappedJoystickAxes = loadShortcuts(config["joystickAxes"]);
  20. #ifndef ENABLE_GOLDMASTER
  21. std::vector<EShortcut> assignedShortcuts;
  22. std::vector<EShortcut> missingShortcuts;
  23. for (auto const & entry : config["keyboard"].Struct())
  24. {
  25. EShortcut shortcutID = findShortcut(entry.first);
  26. assert(!vstd::contains(assignedShortcuts, shortcutID));
  27. assignedShortcuts.push_back(shortcutID);
  28. }
  29. for (EShortcut id = vstd::next(EShortcut::NONE, 1); id < EShortcut::AFTER_LAST; id = vstd::next(id, 1))
  30. if (!vstd::contains(assignedShortcuts, id))
  31. missingShortcuts.push_back(id);
  32. if (!missingShortcuts.empty())
  33. logGlobal->error("Found %d shortcuts without config entry!", missingShortcuts.size());
  34. #endif
  35. }
  36. std::multimap<std::string, EShortcut> ShortcutHandler::loadShortcuts(const JsonNode & data) const
  37. {
  38. std::multimap<std::string, EShortcut> result;
  39. for (auto const & entry : data.Struct())
  40. {
  41. std::string shortcutName = entry.first;
  42. EShortcut shortcutID = findShortcut(shortcutName);
  43. if (shortcutID == EShortcut::NONE)
  44. {
  45. logGlobal->warn("Unknown shortcut '%s' found when loading shortcuts config!", shortcutName);
  46. continue;
  47. }
  48. if (entry.second.isString())
  49. {
  50. result.emplace(entry.second.String(), shortcutID);
  51. }
  52. if (entry.second.isVector())
  53. {
  54. for (auto const & entryVector : entry.second.Vector())
  55. result.emplace(entryVector.String(), shortcutID);
  56. }
  57. }
  58. return result;
  59. }
  60. std::vector<EShortcut> ShortcutHandler::translateShortcut(const std::multimap<std::string, EShortcut> & options, const std::string & key) const
  61. {
  62. auto range = options.equal_range(key);
  63. // FIXME: some code expects calls to keyPressed / captureThisKey even without defined hotkeys
  64. if (range.first == range.second)
  65. return {EShortcut::NONE};
  66. std::vector<EShortcut> result;
  67. for (auto it = range.first; it != range.second; ++it)
  68. result.push_back(it->second);
  69. return result;
  70. }
  71. std::vector<EShortcut> ShortcutHandler::translateKeycode(const std::string & key) const
  72. {
  73. return translateShortcut(mappedKeyboardShortcuts, key);
  74. }
  75. std::vector<EShortcut> ShortcutHandler::translateJoystickButton(const std::string & key) const
  76. {
  77. return translateShortcut(mappedJoystickShortcuts, key);
  78. }
  79. std::vector<EShortcut> ShortcutHandler::translateJoystickAxis(const std::string & key) const
  80. {
  81. return translateShortcut(mappedJoystickAxes, key);
  82. }
  83. EShortcut ShortcutHandler::findShortcut(const std::string & identifier ) const
  84. {
  85. static const std::map<std::string, EShortcut> shortcutNames = {
  86. {"mouseClickLeft", EShortcut::MOUSE_LEFT },
  87. {"mouseClickRight", EShortcut::MOUSE_RIGHT },
  88. {"mouseCursorX", EShortcut::MOUSE_CURSOR_X, },
  89. {"mouseCursorY", EShortcut::MOUSE_CURSOR_Y, },
  90. {"mouseSwipeX", EShortcut::MOUSE_SWIPE_X, },
  91. {"mouseSwipeY", EShortcut::MOUSE_SWIPE_Y, },
  92. {"globalAccept", EShortcut::GLOBAL_ACCEPT },
  93. {"globalCancel", EShortcut::GLOBAL_CANCEL },
  94. {"globalReturn", EShortcut::GLOBAL_RETURN },
  95. {"globalFullscreen", EShortcut::GLOBAL_FULLSCREEN },
  96. {"globalOptions", EShortcut::GLOBAL_OPTIONS },
  97. {"globalBackspace", EShortcut::GLOBAL_BACKSPACE },
  98. {"globalMoveFocus", EShortcut::GLOBAL_MOVE_FOCUS },
  99. {"moveLeft", EShortcut::MOVE_LEFT },
  100. {"moveRight", EShortcut::MOVE_RIGHT },
  101. {"moveUp", EShortcut::MOVE_UP },
  102. {"moveDown", EShortcut::MOVE_DOWN },
  103. {"moveFirst", EShortcut::MOVE_FIRST },
  104. {"moveLast", EShortcut::MOVE_LAST },
  105. {"movePageUp", EShortcut::MOVE_PAGE_UP },
  106. {"movePageDown", EShortcut::MOVE_PAGE_DOWN },
  107. {"selectIndex1", EShortcut::SELECT_INDEX_1 },
  108. {"selectIndex2", EShortcut::SELECT_INDEX_2 },
  109. {"selectIndex3", EShortcut::SELECT_INDEX_3 },
  110. {"selectIndex4", EShortcut::SELECT_INDEX_4 },
  111. {"selectIndex5", EShortcut::SELECT_INDEX_5 },
  112. {"selectIndex6", EShortcut::SELECT_INDEX_6 },
  113. {"selectIndex7", EShortcut::SELECT_INDEX_7 },
  114. {"selectIndex8", EShortcut::SELECT_INDEX_8 },
  115. {"mainMenuNewGame", EShortcut::MAIN_MENU_NEW_GAME },
  116. {"mainMenuLoadGame", EShortcut::MAIN_MENU_LOAD_GAME },
  117. {"mainMenuHighScores", EShortcut::MAIN_MENU_HIGH_SCORES },
  118. {"mainMenuCredits", EShortcut::MAIN_MENU_CREDITS },
  119. {"mainMenuQuit", EShortcut::MAIN_MENU_QUIT },
  120. {"mainMenuBack", EShortcut::MAIN_MENU_BACK },
  121. {"mainMenuSingleplayer", EShortcut::MAIN_MENU_SINGLEPLAYER },
  122. {"mainMenuMultiplayer", EShortcut::MAIN_MENU_MULTIPLAYER },
  123. {"mainMenuCampaign", EShortcut::MAIN_MENU_CAMPAIGN },
  124. {"mainMenuTutorial", EShortcut::MAIN_MENU_TUTORIAL },
  125. {"mainMenuCampaignSod", EShortcut::MAIN_MENU_CAMPAIGN_SOD },
  126. {"mainMenuCampaignRoe", EShortcut::MAIN_MENU_CAMPAIGN_ROE },
  127. {"mainMenuCampaignAb", EShortcut::MAIN_MENU_CAMPAIGN_AB },
  128. {"mainMenuCampaignCustom", EShortcut::MAIN_MENU_CAMPAIGN_CUSTOM },
  129. {"mainMenuLobby", EShortcut::MAIN_MENU_LOBBY },
  130. {"lobbyBeginStandardGame", EShortcut::LOBBY_BEGIN_STANDARD_GAME },
  131. {"lobbyBeginCampaign", EShortcut::LOBBY_BEGIN_CAMPAIGN },
  132. {"lobbyLoadGame", EShortcut::LOBBY_LOAD_GAME },
  133. {"lobbySaveGame", EShortcut::LOBBY_SAVE_GAME },
  134. {"lobbyRandomMap", EShortcut::LOBBY_RANDOM_MAP },
  135. {"lobbyToggleChat", EShortcut::LOBBY_TOGGLE_CHAT },
  136. {"lobbyAdditionalOptions", EShortcut::LOBBY_ADDITIONAL_OPTIONS },
  137. {"lobbySelectScenario", EShortcut::LOBBY_SELECT_SCENARIO },
  138. {"gameEndTurn", EShortcut::ADVENTURE_END_TURN }, // compatibility ID - extra's use this string
  139. {"adventureEndTurn", EShortcut::ADVENTURE_END_TURN },
  140. {"adventureLoadGame", EShortcut::ADVENTURE_LOAD_GAME },
  141. {"adventureSaveGame", EShortcut::ADVENTURE_SAVE_GAME },
  142. {"adventureRestartGame", EShortcut::ADVENTURE_RESTART_GAME },
  143. {"adventureMainMenu", EShortcut::ADVENTURE_TO_MAIN_MENU },
  144. {"adventureQuitGame", EShortcut::ADVENTURE_QUIT_GAME },
  145. {"adventureMarketplace", EShortcut::ADVENTURE_MARKETPLACE },
  146. {"adventureThievesGuild", EShortcut::ADVENTURE_THIEVES_GUILD },
  147. {"gameActivateConsole", EShortcut::GAME_ACTIVATE_CONSOLE },
  148. {"adventureGameOptions", EShortcut::ADVENTURE_GAME_OPTIONS },
  149. {"adventureToggleGrid", EShortcut::ADVENTURE_TOGGLE_GRID },
  150. {"adventureToggleVisitable", EShortcut::ADVENTURE_TOGGLE_VISITABLE},
  151. {"adventureToggleBlocked", EShortcut::ADVENTURE_TOGGLE_BLOCKED },
  152. {"adventureToggleSleep", EShortcut::ADVENTURE_TOGGLE_SLEEP },
  153. {"adventureSetHeroAsleep", EShortcut::ADVENTURE_SET_HERO_ASLEEP },
  154. {"adventureSetHeroAwake", EShortcut::ADVENTURE_SET_HERO_AWAKE },
  155. {"adventureMoveHero", EShortcut::ADVENTURE_MOVE_HERO },
  156. {"adventureVisitObject", EShortcut::ADVENTURE_VISIT_OBJECT },
  157. {"adventureMoveHeroSW", EShortcut::ADVENTURE_MOVE_HERO_SW },
  158. {"adventureMoveHeroSS", EShortcut::ADVENTURE_MOVE_HERO_SS },
  159. {"adventureMoveHeroSE", EShortcut::ADVENTURE_MOVE_HERO_SE },
  160. {"adventureMoveHeroWW", EShortcut::ADVENTURE_MOVE_HERO_WW },
  161. {"adventureMoveHeroEE", EShortcut::ADVENTURE_MOVE_HERO_EE },
  162. {"adventureMoveHeroNW", EShortcut::ADVENTURE_MOVE_HERO_NW },
  163. {"adventureMoveHeroNN", EShortcut::ADVENTURE_MOVE_HERO_NN },
  164. {"adventureMoveHeroNE", EShortcut::ADVENTURE_MOVE_HERO_NE },
  165. {"adventureViewSelected", EShortcut::ADVENTURE_VIEW_SELECTED },
  166. {"adventureNextObject", EShortcut::ADVENTURE_NEXT_OBJECT },
  167. {"adventureNextTown", EShortcut::ADVENTURE_NEXT_TOWN },
  168. {"adventureNextHero", EShortcut::ADVENTURE_NEXT_HERO },
  169. {"adventureFirstTown", EShortcut::ADVENTURE_FIRST_TOWN },
  170. {"adventureFirstHero", EShortcut::ADVENTURE_FIRST_HERO },
  171. {"adventureViewScenario", EShortcut::ADVENTURE_VIEW_SCENARIO },
  172. {"adventureDigGrail", EShortcut::ADVENTURE_DIG_GRAIL },
  173. {"adventureViewPuzzle", EShortcut::ADVENTURE_VIEW_PUZZLE },
  174. {"adventureViewWorld", EShortcut::ADVENTURE_VIEW_WORLD },
  175. {"adventureViewWorld1", EShortcut::ADVENTURE_VIEW_WORLD_X1 },
  176. {"adventureViewWorld2", EShortcut::ADVENTURE_VIEW_WORLD_X2 },
  177. {"adventureViewWorld4", EShortcut::ADVENTURE_VIEW_WORLD_X4 },
  178. {"adventureTrackHero", EShortcut::ADVENTURE_TRACK_HERO, },
  179. {"adventureToggleMapLevel", EShortcut::ADVENTURE_TOGGLE_MAP_LEVEL},
  180. {"adventureKingdomOverview", EShortcut::ADVENTURE_KINGDOM_OVERVIEW},
  181. {"adventureQuestLog", EShortcut::ADVENTURE_QUEST_LOG },
  182. {"adventureCastSpell", EShortcut::ADVENTURE_CAST_SPELL },
  183. {"adventureThievesGuild", EShortcut::ADVENTURE_THIEVES_GUILD },
  184. {"adventureExitWorldView", EShortcut::ADVENTURE_EXIT_WORLD_VIEW },
  185. {"adventureZoomIn", EShortcut::ADVENTURE_ZOOM_IN },
  186. {"adventureZoomOut", EShortcut::ADVENTURE_ZOOM_OUT },
  187. {"adventureZoomReset", EShortcut::ADVENTURE_ZOOM_RESET },
  188. {"adventureSearch", EShortcut::ADVENTURE_SEARCH },
  189. {"adventureSearchContinue", EShortcut::ADVENTURE_SEARCH_CONTINUE },
  190. {"battleToggleHeroesStats", EShortcut::BATTLE_TOGGLE_HEROES_STATS},
  191. {"battleToggleQueue", EShortcut::BATTLE_TOGGLE_QUEUE },
  192. {"battleUseCreatureSpell", EShortcut::BATTLE_USE_CREATURE_SPELL },
  193. {"battleSurrender", EShortcut::BATTLE_SURRENDER },
  194. {"battleRetreat", EShortcut::BATTLE_RETREAT },
  195. {"battleAutocombat", EShortcut::BATTLE_AUTOCOMBAT },
  196. {"battleAutocombatEnd", EShortcut::BATTLE_END_WITH_AUTOCOMBAT},
  197. {"battleCastSpell", EShortcut::BATTLE_CAST_SPELL },
  198. {"battleWait", EShortcut::BATTLE_WAIT },
  199. {"battleDefend", EShortcut::BATTLE_DEFEND },
  200. {"battleConsoleUp", EShortcut::BATTLE_CONSOLE_UP },
  201. {"battleConsoleDown", EShortcut::BATTLE_CONSOLE_DOWN },
  202. {"battleTacticsNext", EShortcut::BATTLE_TACTICS_NEXT },
  203. {"battleTacticsEnd", EShortcut::BATTLE_TACTICS_END },
  204. {"battleSelectAction", EShortcut::BATTLE_SELECT_ACTION },
  205. {"battleToggleQuickSpell", EShortcut::BATTLE_TOGGLE_QUICKSPELL },
  206. {"battleSpellShortcut0", EShortcut::BATTLE_SPELL_SHORTCUT_0 },
  207. {"battleSpellShortcut1", EShortcut::BATTLE_SPELL_SHORTCUT_1 },
  208. {"battleSpellShortcut2", EShortcut::BATTLE_SPELL_SHORTCUT_2 },
  209. {"battleSpellShortcut3", EShortcut::BATTLE_SPELL_SHORTCUT_3 },
  210. {"battleSpellShortcut4", EShortcut::BATTLE_SPELL_SHORTCUT_4 },
  211. {"battleSpellShortcut5", EShortcut::BATTLE_SPELL_SHORTCUT_5 },
  212. {"battleSpellShortcut6", EShortcut::BATTLE_SPELL_SHORTCUT_6 },
  213. {"battleSpellShortcut7", EShortcut::BATTLE_SPELL_SHORTCUT_7 },
  214. {"battleSpellShortcut8", EShortcut::BATTLE_SPELL_SHORTCUT_8 },
  215. {"battleSpellShortcut9", EShortcut::BATTLE_SPELL_SHORTCUT_9 },
  216. {"battleSpellShortcut10", EShortcut::BATTLE_SPELL_SHORTCUT_10 },
  217. {"battleSpellShortcut11", EShortcut::BATTLE_SPELL_SHORTCUT_11 },
  218. {"spectateTrackHero", EShortcut::SPECTATE_TRACK_HERO },
  219. {"spectateSkipBattle", EShortcut::SPECTATE_SKIP_BATTLE },
  220. {"spectateSkipBattleResult", EShortcut::SPECTATE_SKIP_BATTLE_RESULT },
  221. {"townOpenTavern", EShortcut::TOWN_OPEN_TAVERN },
  222. {"townSwapArmies", EShortcut::TOWN_SWAP_ARMIES },
  223. {"recruitmentMax", EShortcut::RECRUITMENT_MAX },
  224. {"recruitmentMin", EShortcut::RECRUITMENT_MIN },
  225. {"recruitmentUpgrade", EShortcut::RECRUITMENT_UPGRADE },
  226. {"recruitmentUpgradeAll", EShortcut::RECRUITMENT_UPGRADE_ALL },
  227. {"kingdomHeroesTab", EShortcut::KINGDOM_HEROES_TAB },
  228. {"kingdomTownsTab", EShortcut::KINGDOM_TOWNS_TAB },
  229. {"heroDismiss", EShortcut::HERO_DISMISS },
  230. {"heroCommander", EShortcut::HERO_COMMANDER },
  231. {"heroLooseFormation", EShortcut::HERO_LOOSE_FORMATION },
  232. {"heroTightFormation", EShortcut::HERO_TIGHT_FORMATION },
  233. {"heroToggleTactics", EShortcut::HERO_TOGGLE_TACTICS },
  234. {"heroCostumeSave0", EShortcut::HERO_COSTUME_SAVE_0 },
  235. {"heroCostumeSave1", EShortcut::HERO_COSTUME_SAVE_1 },
  236. {"heroCostumeSave2", EShortcut::HERO_COSTUME_SAVE_2 },
  237. {"heroCostumeSave3", EShortcut::HERO_COSTUME_SAVE_3 },
  238. {"heroCostumeSave4", EShortcut::HERO_COSTUME_SAVE_4 },
  239. {"heroCostumeSave5", EShortcut::HERO_COSTUME_SAVE_5 },
  240. {"heroCostumeSave6", EShortcut::HERO_COSTUME_SAVE_6 },
  241. {"heroCostumeSave7", EShortcut::HERO_COSTUME_SAVE_7 },
  242. {"heroCostumeSave8", EShortcut::HERO_COSTUME_SAVE_8 },
  243. {"heroCostumeSave9", EShortcut::HERO_COSTUME_SAVE_9 },
  244. {"heroCostumeLoad0", EShortcut::HERO_COSTUME_LOAD_0 },
  245. {"heroCostumeLoad1", EShortcut::HERO_COSTUME_LOAD_1 },
  246. {"heroCostumeLoad2", EShortcut::HERO_COSTUME_LOAD_2 },
  247. {"heroCostumeLoad3", EShortcut::HERO_COSTUME_LOAD_3 },
  248. {"heroCostumeLoad4", EShortcut::HERO_COSTUME_LOAD_4 },
  249. {"heroCostumeLoad5", EShortcut::HERO_COSTUME_LOAD_5 },
  250. {"heroCostumeLoad6", EShortcut::HERO_COSTUME_LOAD_6 },
  251. {"heroCostumeLoad7", EShortcut::HERO_COSTUME_LOAD_7 },
  252. {"heroCostumeLoad8", EShortcut::HERO_COSTUME_LOAD_8 },
  253. {"heroCostumeLoad9", EShortcut::HERO_COSTUME_LOAD_9 },
  254. {"spellbookTabAdventure", EShortcut::SPELLBOOK_TAB_ADVENTURE },
  255. {"spellbookTabCombat", EShortcut::SPELLBOOK_TAB_COMBAT },
  256. {"spellbookSearchFocus", EShortcut::SPELLBOOK_SEARCH_FOCUS },
  257. {"listHeroUp", EShortcut::LIST_HERO_UP },
  258. {"listHeroDown", EShortcut::LIST_HERO_DOWN },
  259. {"listHeroTop", EShortcut::LIST_HERO_TOP },
  260. {"listHeroBottom", EShortcut::LIST_HERO_BOTTOM },
  261. {"listHeroDismiss", EShortcut::LIST_HERO_DISMISS },
  262. {"listTownUp", EShortcut::LIST_TOWN_UP },
  263. {"listTownDown", EShortcut::LIST_TOWN_DOWN },
  264. {"listTownTop", EShortcut::LIST_TOWN_TOP },
  265. {"listTownBottom", EShortcut::LIST_TOWN_BOTTOM },
  266. {"mainMenuHotseat", EShortcut::MAIN_MENU_HOTSEAT },
  267. {"mainMenuHostGame", EShortcut::MAIN_MENU_HOST_GAME },
  268. {"mainMenuJoinGame", EShortcut::MAIN_MENU_JOIN_GAME },
  269. {"highScoresCampaigns", EShortcut::HIGH_SCORES_CAMPAIGNS },
  270. {"highScoresScenarios", EShortcut::HIGH_SCORES_SCENARIOS },
  271. {"highScoresReset", EShortcut::HIGH_SCORES_RESET },
  272. {"highScoresStatistics", EShortcut::HIGH_SCORES_STATISTICS },
  273. {"lobbyReplayVideo", EShortcut::LOBBY_REPLAY_VIDEO },
  274. {"lobbyExtraOptions", EShortcut::LOBBY_EXTRA_OPTIONS },
  275. {"lobbyTurnOptions", EShortcut::LOBBY_TURN_OPTIONS },
  276. {"lobbyInvitePlayers", EShortcut::LOBBY_INVITE_PLAYERS },
  277. {"lobbyFlipCoin", EShortcut::LOBBY_FLIP_COIN },
  278. {"lobbyRandomTown", EShortcut::LOBBY_RANDOM_TOWN },
  279. {"lobbyRandomTownVs", EShortcut::LOBBY_RANDOM_TOWN_VS },
  280. {"lobbyHandicap", EShortcut::LOBBY_HANDICAP },
  281. {"mapsSizeS", EShortcut::MAPS_SIZE_S },
  282. {"mapsSizeM", EShortcut::MAPS_SIZE_M },
  283. {"mapsSizeL", EShortcut::MAPS_SIZE_L },
  284. {"mapsSizeXl", EShortcut::MAPS_SIZE_XL },
  285. {"mapsSizeAll", EShortcut::MAPS_SIZE_ALL },
  286. {"mapsSortPlayers", EShortcut::MAPS_SORT_PLAYERS },
  287. {"mapsSortSize", EShortcut::MAPS_SORT_SIZE },
  288. {"mapsSortFormat", EShortcut::MAPS_SORT_FORMAT },
  289. {"mapsSortName", EShortcut::MAPS_SORT_NAME },
  290. {"mapsSortVictory", EShortcut::MAPS_SORT_VICTORY },
  291. {"mapsSortDefeat", EShortcut::MAPS_SORT_DEFEAT },
  292. {"mapsSortMaps", EShortcut::MAPS_SORT_MAPS },
  293. {"mapsSortChangedate", EShortcut::MAPS_SORT_CHANGEDATE },
  294. {"settingsLoadGame", EShortcut::SETTINGS_LOAD_GAME },
  295. {"settingsSaveGame", EShortcut::SETTINGS_SAVE_GAME },
  296. {"settingsNewGame", EShortcut::SETTINGS_NEW_GAME },
  297. {"settingsRestartGame", EShortcut::SETTINGS_RESTART_GAME },
  298. {"settingsToMainMenu", EShortcut::SETTINGS_TO_MAIN_MENU },
  299. {"settingsQuitGame", EShortcut::SETTINGS_QUIT_GAME },
  300. {"adventureReplayTurn", EShortcut::ADVENTURE_REPLAY_TURN },
  301. {"adventureNewGame", EShortcut::ADVENTURE_NEW_GAME },
  302. {"battleOpenActiveUnit", EShortcut::BATTLE_OPEN_ACTIVE_UNIT },
  303. {"battleOpenHoveredUnit", EShortcut::BATTLE_OPEN_HOVERED_UNIT },
  304. {"marketDeal", EShortcut::MARKET_DEAL },
  305. {"marketMaxAmount", EShortcut::MARKET_MAX_AMOUNT },
  306. {"marketSacrificeAll", EShortcut::MARKET_SACRIFICE_ALL },
  307. {"marketSacrificeBackpack", EShortcut::MARKET_SACRIFICE_BACKPACK },
  308. {"marketResourcePlayer", EShortcut::MARKET_RESOURCE_PLAYER },
  309. {"marketArtifactResource", EShortcut::MARKET_ARTIFACT_RESOURCE },
  310. {"marketResourceArtifact", EShortcut::MARKET_RESOURCE_ARTIFACT },
  311. {"marketCreatureResource", EShortcut::MARKET_CREATURE_RESOURCE },
  312. {"marketResourceResource", EShortcut::MARKET_RESOURCE_RESOURCE },
  313. {"marketCreatureExperience", EShortcut::MARKET_CREATURE_EXPERIENCE },
  314. {"marketArtifactExperience", EShortcut::MARKET_ARTIFACT_EXPERIENCE },
  315. {"townOpenHall", EShortcut::TOWN_OPEN_HALL },
  316. {"townOpenFort", EShortcut::TOWN_OPEN_FORT },
  317. {"townOpenMarket", EShortcut::TOWN_OPEN_MARKET },
  318. {"townOpenMageGuild", EShortcut::TOWN_OPEN_MAGE_GUILD },
  319. {"townOpenThievesGuild", EShortcut::TOWN_OPEN_THIEVES_GUILD },
  320. {"townOpenRecruitment", EShortcut::TOWN_OPEN_RECRUITMENT },
  321. {"townOpenHeroExchange", EShortcut::TOWN_OPEN_HERO_EXCHANGE },
  322. {"townOpenHero", EShortcut::TOWN_OPEN_HERO },
  323. {"townOpenVisitingHero", EShortcut::TOWN_OPEN_VISITING_HERO },
  324. {"townOpenGarrisonedHero", EShortcut::TOWN_OPEN_GARRISONED_HERO },
  325. {"recruitmentSwitchLevel", EShortcut::RECRUITMENT_SWITCH_LEVEL },
  326. {"heroArmySplit", EShortcut::HERO_ARMY_SPLIT },
  327. {"heroBackpack", EShortcut::HERO_BACKPACK },
  328. {"exchangeArmyToLeft", EShortcut::EXCHANGE_ARMY_TO_LEFT },
  329. {"exchangeArmyToRight", EShortcut::EXCHANGE_ARMY_TO_RIGHT },
  330. {"exchangeArmySwap", EShortcut::EXCHANGE_ARMY_SWAP },
  331. {"exchangeArtifactsToLeft", EShortcut::EXCHANGE_ARTIFACTS_TO_LEFT },
  332. {"exchangeArtifactsToRight", EShortcut::EXCHANGE_ARTIFACTS_TO_RIGHT },
  333. {"exchangeArtifactsSwap", EShortcut::EXCHANGE_ARTIFACTS_SWAP },
  334. {"exchangeBackpackLeft", EShortcut::EXCHANGE_BACKPACK_LEFT },
  335. {"exchangeBackpackRight", EShortcut::EXCHANGE_BACKPACK_RIGHT },
  336. {"exchangeEquippedToLeft", EShortcut::EXCHANGE_EQUIPPED_TO_LEFT },
  337. {"exchangeEquippedToRight", EShortcut::EXCHANGE_EQUIPPED_TO_RIGHT},
  338. {"exchangeEquippedSwap", EShortcut::EXCHANGE_EQUIPPED_SWAP },
  339. {"exchangeBackpackToLeft", EShortcut::EXCHANGE_BACKPACK_TO_LEFT },
  340. {"exchangeBackpackToRight", EShortcut::EXCHANGE_BACKPACK_TO_RIGHT},
  341. {"exchangeBackpackSwap", EShortcut::EXCHANGE_BACKPACK_SWAP },
  342. };
  343. #ifndef ENABLE_GOLDMASTER
  344. std::vector<EShortcut> assignedShortcuts;
  345. std::vector<EShortcut> missingShortcuts;
  346. for (auto const & entry : shortcutNames)
  347. assignedShortcuts.push_back(entry.second);
  348. for (EShortcut id = vstd::next(EShortcut::NONE, 1); id < EShortcut::AFTER_LAST; id = vstd::next(id, 1))
  349. if (!vstd::contains(assignedShortcuts, id))
  350. missingShortcuts.push_back(id);
  351. if (!missingShortcuts.empty())
  352. logGlobal->error("Found %d shortcuts without assigned string name!", missingShortcuts.size());
  353. #endif
  354. if (shortcutNames.count(identifier))
  355. return shortcutNames.at(identifier);
  356. return EShortcut::NONE;
  357. }