ShortcutHandler.cpp 22 KB

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