input_map.cpp 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925
  1. /**************************************************************************/
  2. /* input_map.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "input_map.h"
  31. #include "input_map.compat.inc"
  32. #include "core/config/project_settings.h"
  33. #include "core/input/input.h"
  34. #include "core/os/keyboard.h"
  35. #include "core/os/os.h"
  36. #include "core/variant/typed_array.h"
  37. void InputMap::_bind_methods() {
  38. ClassDB::bind_method(D_METHOD("has_action", "action"), &InputMap::has_action);
  39. ClassDB::bind_method(D_METHOD("get_actions"), &InputMap::get_actions);
  40. ClassDB::bind_method(D_METHOD("add_action", "action", "deadzone"), &InputMap::add_action, DEFVAL(DEFAULT_DEADZONE));
  41. ClassDB::bind_method(D_METHOD("erase_action", "action"), &InputMap::erase_action);
  42. ClassDB::bind_method(D_METHOD("get_action_description", "action"), &InputMap::get_action_description);
  43. ClassDB::bind_method(D_METHOD("action_set_deadzone", "action", "deadzone"), &InputMap::action_set_deadzone);
  44. ClassDB::bind_method(D_METHOD("action_get_deadzone", "action"), &InputMap::action_get_deadzone);
  45. ClassDB::bind_method(D_METHOD("action_add_event", "action", "event"), &InputMap::action_add_event);
  46. ClassDB::bind_method(D_METHOD("action_has_event", "action", "event"), &InputMap::action_has_event);
  47. ClassDB::bind_method(D_METHOD("action_erase_event", "action", "event"), &InputMap::action_erase_event);
  48. ClassDB::bind_method(D_METHOD("action_erase_events", "action"), &InputMap::action_erase_events);
  49. ClassDB::bind_method(D_METHOD("action_get_events", "action"), &InputMap::_action_get_events);
  50. ClassDB::bind_method(D_METHOD("event_is_action", "event", "action", "exact_match"), &InputMap::event_is_action, DEFVAL(false));
  51. ClassDB::bind_method(D_METHOD("load_from_project_settings"), &InputMap::load_from_project_settings);
  52. }
  53. /**
  54. * Returns an nonexistent action error message with a suggestion of the closest
  55. * matching action name (if possible).
  56. */
  57. String InputMap::suggest_actions(const StringName &p_action) const {
  58. StringName closest_action;
  59. float closest_similarity = 0.0;
  60. // Find the most action with the most similar name.
  61. for (const KeyValue<StringName, Action> &kv : input_map) {
  62. const float similarity = String(kv.key).similarity(p_action);
  63. if (similarity > closest_similarity) {
  64. closest_action = kv.key;
  65. closest_similarity = similarity;
  66. }
  67. }
  68. String error_message = vformat("The InputMap action \"%s\" doesn't exist.", p_action);
  69. if (closest_similarity >= 0.4) {
  70. // Only include a suggestion in the error message if it's similar enough.
  71. error_message += vformat(" Did you mean \"%s\"?", closest_action);
  72. }
  73. return error_message;
  74. }
  75. #ifdef TOOLS_ENABLED
  76. void InputMap::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
  77. const String pf = p_function;
  78. bool first_argument_is_action = false;
  79. if (p_idx == 0) {
  80. first_argument_is_action = (pf == "has_action" || pf == "erase_action" ||
  81. pf == "action_set_deadzone" || pf == "action_get_deadzone" ||
  82. pf == "action_has_event" || pf == "action_add_event" || pf == "action_get_events" ||
  83. pf == "action_erase_event" || pf == "action_erase_events");
  84. }
  85. if (first_argument_is_action || (p_idx == 1 && pf == "event_is_action")) {
  86. // Cannot rely on `get_actions()`, otherwise the actions would be in the context of the Editor (no user-defined actions).
  87. List<PropertyInfo> pinfo;
  88. ProjectSettings::get_singleton()->get_property_list(&pinfo);
  89. for (const PropertyInfo &pi : pinfo) {
  90. if (!pi.name.begins_with("input/")) {
  91. continue;
  92. }
  93. String name = pi.name.substr(pi.name.find_char('/') + 1);
  94. r_options->push_back(name.quote());
  95. }
  96. }
  97. Object::get_argument_options(p_function, p_idx, r_options);
  98. }
  99. #endif
  100. void InputMap::add_action(const StringName &p_action, float p_deadzone) {
  101. ERR_FAIL_COND_MSG(input_map.has(p_action), vformat("InputMap already has action \"%s\".", String(p_action)));
  102. input_map[p_action] = Action();
  103. static int last_id = 1;
  104. input_map[p_action].id = last_id;
  105. input_map[p_action].deadzone = p_deadzone;
  106. last_id++;
  107. }
  108. void InputMap::erase_action(const StringName &p_action) {
  109. ERR_FAIL_COND_MSG(!input_map.has(p_action), suggest_actions(p_action));
  110. input_map.erase(p_action);
  111. }
  112. TypedArray<StringName> InputMap::get_actions() {
  113. TypedArray<StringName> ret;
  114. ret.resize(input_map.size());
  115. uint32_t i = 0;
  116. for (const KeyValue<StringName, Action> &kv : input_map) {
  117. ret[i] = kv.key;
  118. i++;
  119. }
  120. return ret;
  121. }
  122. List<Ref<InputEvent>>::Element *InputMap::_find_event(Action &p_action, const Ref<InputEvent> &p_event, bool p_exact_match, bool *r_pressed, float *r_strength, float *r_raw_strength, int *r_event_index) const {
  123. ERR_FAIL_COND_V(p_event.is_null(), nullptr);
  124. int i = 0;
  125. for (List<Ref<InputEvent>>::Element *E = p_action.inputs.front(); E; E = E->next()) {
  126. int device = E->get()->get_device();
  127. if (device == ALL_DEVICES || device == p_event->get_device()) {
  128. if (E->get()->action_match(p_event, p_exact_match, p_action.deadzone, r_pressed, r_strength, r_raw_strength)) {
  129. if (r_event_index) {
  130. *r_event_index = i;
  131. }
  132. return E;
  133. }
  134. }
  135. i++;
  136. }
  137. return nullptr;
  138. }
  139. bool InputMap::has_action(const StringName &p_action) const {
  140. return input_map.has(p_action);
  141. }
  142. String InputMap::get_action_description(const StringName &p_action) const {
  143. ERR_FAIL_COND_V_MSG(!input_map.has(p_action), String(), suggest_actions(p_action));
  144. String ret;
  145. const List<Ref<InputEvent>> &inputs = input_map[p_action].inputs;
  146. for (Ref<InputEventKey> iek : inputs) {
  147. if (iek.is_valid()) {
  148. if (!ret.is_empty()) {
  149. ret += RTR(" or ");
  150. }
  151. ret += iek->as_text();
  152. }
  153. }
  154. if (ret.is_empty()) {
  155. ret = RTR("Action has no bound inputs");
  156. }
  157. return ret;
  158. }
  159. float InputMap::action_get_deadzone(const StringName &p_action) {
  160. ERR_FAIL_COND_V_MSG(!input_map.has(p_action), 0.0f, suggest_actions(p_action));
  161. return input_map[p_action].deadzone;
  162. }
  163. void InputMap::action_set_deadzone(const StringName &p_action, float p_deadzone) {
  164. ERR_FAIL_COND_MSG(!input_map.has(p_action), suggest_actions(p_action));
  165. input_map[p_action].deadzone = p_deadzone;
  166. }
  167. void InputMap::action_add_event(const StringName &p_action, RequiredParam<InputEvent> rp_event) {
  168. EXTRACT_PARAM_OR_FAIL_MSG(p_event, rp_event, "It's not a reference to a valid InputEvent object.");
  169. ERR_FAIL_COND_MSG(!input_map.has(p_action), suggest_actions(p_action));
  170. if (_find_event(input_map[p_action], p_event, true)) {
  171. return; // Already added.
  172. }
  173. input_map[p_action].inputs.push_back(p_event);
  174. }
  175. bool InputMap::action_has_event(const StringName &p_action, RequiredParam<InputEvent> rp_event) {
  176. EXTRACT_PARAM_OR_FAIL_V(p_event, rp_event, false);
  177. ERR_FAIL_COND_V_MSG(!input_map.has(p_action), false, suggest_actions(p_action));
  178. return (_find_event(input_map[p_action], p_event, true) != nullptr);
  179. }
  180. void InputMap::action_erase_event(const StringName &p_action, RequiredParam<InputEvent> rp_event) {
  181. EXTRACT_PARAM_OR_FAIL(p_event, rp_event);
  182. ERR_FAIL_COND_MSG(!input_map.has(p_action), suggest_actions(p_action));
  183. List<Ref<InputEvent>>::Element *E = _find_event(input_map[p_action], p_event, true);
  184. if (E) {
  185. input_map[p_action].inputs.erase(E);
  186. if (Input::get_singleton()->is_action_pressed(p_action)) {
  187. Input::get_singleton()->action_release(p_action);
  188. }
  189. }
  190. }
  191. void InputMap::action_erase_events(const StringName &p_action) {
  192. ERR_FAIL_COND_MSG(!input_map.has(p_action), suggest_actions(p_action));
  193. input_map[p_action].inputs.clear();
  194. }
  195. TypedArray<InputEvent> InputMap::_action_get_events(const StringName &p_action) {
  196. TypedArray<InputEvent> ret;
  197. const List<Ref<InputEvent>> *al = action_get_events(p_action);
  198. if (al) {
  199. for (const List<Ref<InputEvent>>::Element *E = al->front(); E; E = E->next()) {
  200. ret.push_back(E->get());
  201. }
  202. }
  203. return ret;
  204. }
  205. const List<Ref<InputEvent>> *InputMap::action_get_events(const StringName &p_action) {
  206. HashMap<StringName, Action>::Iterator E = input_map.find(p_action);
  207. if (!E) {
  208. return nullptr;
  209. }
  210. return &E->value.inputs;
  211. }
  212. bool InputMap::event_is_action(RequiredParam<InputEvent> rp_event, const StringName &p_action, bool p_exact_match) const {
  213. EXTRACT_PARAM_OR_FAIL_V(p_event, rp_event, false);
  214. return event_get_action_status(p_event, p_action, p_exact_match);
  215. }
  216. int InputMap::event_get_index(const Ref<InputEvent> &p_event, const StringName &p_action, bool p_exact_match) const {
  217. int index = -1;
  218. bool valid = event_get_action_status(p_event, p_action, p_exact_match, nullptr, nullptr, nullptr, &index);
  219. return valid ? index : -1;
  220. }
  221. bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const StringName &p_action, bool p_exact_match, bool *r_pressed, float *r_strength, float *r_raw_strength, int *r_event_index) const {
  222. HashMap<StringName, Action>::Iterator E = input_map.find(p_action);
  223. ERR_FAIL_COND_V_MSG(!E, false, suggest_actions(p_action));
  224. Ref<InputEventAction> input_event_action = p_event;
  225. if (input_event_action.is_valid()) {
  226. const bool pressed = input_event_action->is_pressed();
  227. if (r_pressed != nullptr) {
  228. *r_pressed = pressed;
  229. }
  230. const float strength = pressed ? input_event_action->get_strength() : 0.0f;
  231. if (r_strength != nullptr) {
  232. *r_strength = strength;
  233. }
  234. if (r_raw_strength != nullptr) {
  235. *r_raw_strength = strength;
  236. }
  237. if (r_event_index) {
  238. if (input_event_action->get_event_index() >= 0) {
  239. *r_event_index = input_event_action->get_event_index();
  240. } else {
  241. *r_event_index = E->value.inputs.size();
  242. }
  243. }
  244. return input_event_action->get_action() == p_action;
  245. }
  246. List<Ref<InputEvent>>::Element *event = _find_event(E->value, p_event, p_exact_match, r_pressed, r_strength, r_raw_strength, r_event_index);
  247. return event != nullptr;
  248. }
  249. const HashMap<StringName, InputMap::Action> &InputMap::get_action_map() const {
  250. return input_map;
  251. }
  252. void InputMap::load_from_project_settings() {
  253. input_map.clear();
  254. List<PropertyInfo> pinfo;
  255. ProjectSettings::get_singleton()->get_property_list(&pinfo);
  256. for (const PropertyInfo &pi : pinfo) {
  257. if (!pi.name.begins_with("input/")) {
  258. continue;
  259. }
  260. String name = pi.name.substr(pi.name.find_char('/') + 1);
  261. Dictionary action = GLOBAL_GET(pi.name);
  262. float deadzone = action.has("deadzone") ? (float)action["deadzone"] : DEFAULT_DEADZONE;
  263. Array events = action["events"];
  264. add_action(name, deadzone);
  265. for (int i = 0; i < events.size(); i++) {
  266. Ref<InputEvent> event = events[i];
  267. if (event.is_null()) {
  268. continue;
  269. }
  270. action_add_event(name, event);
  271. }
  272. }
  273. }
  274. struct _BuiltinActionDisplayName {
  275. const char *name;
  276. const char *display_name;
  277. };
  278. static const _BuiltinActionDisplayName _builtin_action_display_names[] = {
  279. /* clang-format off */
  280. { "ui_accept", TTRC("Accept") },
  281. { "ui_select", TTRC("Select") },
  282. { "ui_cancel", TTRC("Cancel") },
  283. { "ui_close_dialog", TTRC("Close Dialog") },
  284. { "ui_focus_next", TTRC("Focus Next") },
  285. { "ui_focus_prev", TTRC("Focus Prev") },
  286. { "ui_left", TTRC("Left") },
  287. { "ui_right", TTRC("Right") },
  288. { "ui_up", TTRC("Up") },
  289. { "ui_down", TTRC("Down") },
  290. { "ui_page_up", TTRC("Page Up") },
  291. { "ui_page_down", TTRC("Page Down") },
  292. { "ui_home", TTRC("Home") },
  293. { "ui_end", TTRC("End") },
  294. { "ui_cut", TTRC("Cut") },
  295. { "ui_copy", TTRC("Copy") },
  296. { "ui_paste", TTRC("Paste") },
  297. { "ui_focus_mode", TTRC("Toggle Tab Focus Mode") },
  298. { "ui_undo", TTRC("Undo") },
  299. { "ui_redo", TTRC("Redo") },
  300. { "ui_text_completion_query", TTRC("Completion Query") },
  301. { "ui_text_newline", TTRC("New Line") },
  302. { "ui_text_newline_blank", TTRC("New Blank Line") },
  303. { "ui_text_newline_above", TTRC("New Line Above") },
  304. { "ui_text_indent", TTRC("Indent") },
  305. { "ui_text_dedent", TTRC("Dedent") },
  306. { "ui_text_backspace", TTRC("Backspace") },
  307. { "ui_text_backspace_word", TTRC("Backspace Word") },
  308. { "ui_text_backspace_all_to_left", TTRC("Backspace all to Left") },
  309. { "ui_text_delete", TTRC("Delete") },
  310. { "ui_text_delete_word", TTRC("Delete Word") },
  311. { "ui_text_delete_all_to_right", TTRC("Delete all to Right") },
  312. { "ui_text_caret_left", TTRC("Caret Left") },
  313. { "ui_text_caret_word_left", TTRC("Caret Word Left") },
  314. { "ui_text_caret_right", TTRC("Caret Right") },
  315. { "ui_text_caret_word_right", TTRC("Caret Word Right") },
  316. { "ui_text_caret_up", TTRC("Caret Up") },
  317. { "ui_text_caret_down", TTRC("Caret Down") },
  318. { "ui_text_caret_line_start", TTRC("Caret Line Start") },
  319. { "ui_text_caret_line_end", TTRC("Caret Line End") },
  320. { "ui_text_caret_page_up", TTRC("Caret Page Up") },
  321. { "ui_text_caret_page_down", TTRC("Caret Page Down") },
  322. { "ui_text_caret_document_start", TTRC("Caret Document Start") },
  323. { "ui_text_caret_document_end", TTRC("Caret Document End") },
  324. { "ui_text_caret_add_below", TTRC("Caret Add Below") },
  325. { "ui_text_caret_add_above", TTRC("Caret Add Above") },
  326. { "ui_text_scroll_up", TTRC("Scroll Up") },
  327. { "ui_text_scroll_down", TTRC("Scroll Down") },
  328. { "ui_text_select_all", TTRC("Select All") },
  329. { "ui_text_select_word_under_caret", TTRC("Select Word Under Caret") },
  330. { "ui_text_add_selection_for_next_occurrence", TTRC("Add Selection for Next Occurrence") },
  331. { "ui_text_skip_selection_for_next_occurrence", TTRC("Skip Selection for Next Occurrence") },
  332. { "ui_text_clear_carets_and_selection", TTRC("Clear Carets and Selection") },
  333. { "ui_text_toggle_insert_mode", TTRC("Toggle Insert Mode") },
  334. { "ui_text_submit", TTRC("Submit Text") },
  335. { "ui_graph_duplicate", TTRC("Duplicate Nodes") },
  336. { "ui_graph_delete", TTRC("Delete Nodes") },
  337. { "ui_graph_follow_left", TTRC("Follow Input Port Connection") },
  338. { "ui_graph_follow_right", TTRC("Follow Output Port Connection") },
  339. { "ui_filedialog_delete", TTRC("Delete") },
  340. { "ui_filedialog_up_one_level", TTRC("Go Up One Level") },
  341. { "ui_filedialog_refresh", TTRC("Refresh") },
  342. { "ui_filedialog_show_hidden", TTRC("Show Hidden") },
  343. { "ui_filedialog_find", TTRC("Find") },
  344. { "ui_filedialog_focus_path", TTRC("Focus Path") },
  345. { "ui_swap_input_direction", TTRC("Swap Input Direction") },
  346. { "ui_unicode_start", TTRC("Start Unicode Character Input") },
  347. { "ui_colorpicker_delete_preset", TTRC("ColorPicker: Delete Preset") },
  348. { "ui_accessibility_drag_and_drop", TTRC("Accessibility: Keyboard Drag and Drop") },
  349. { "", ""}
  350. /* clang-format on */
  351. };
  352. String InputMap::get_builtin_display_name(const String &p_name) const {
  353. const String name = p_name.get_slicec('.', 0);
  354. constexpr int len = std_size(_builtin_action_display_names);
  355. for (int i = 0; i < len; i++) {
  356. if (_builtin_action_display_names[i].name == name) {
  357. return _builtin_action_display_names[i].display_name;
  358. }
  359. }
  360. return p_name;
  361. }
  362. const HashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins() {
  363. // Return cache if it has already been built.
  364. if (default_builtin_cache.size()) {
  365. return default_builtin_cache;
  366. }
  367. List<Ref<InputEvent>> inputs;
  368. inputs.push_back(InputEventKey::create_reference(Key::ENTER));
  369. inputs.push_back(InputEventKey::create_reference(Key::KP_ENTER));
  370. inputs.push_back(InputEventKey::create_reference(Key::SPACE));
  371. default_builtin_cache.insert("ui_accept", inputs);
  372. inputs = List<Ref<InputEvent>>();
  373. inputs.push_back(InputEventJoypadButton::create_reference(JoyButton::Y));
  374. inputs.push_back(InputEventKey::create_reference(Key::SPACE));
  375. default_builtin_cache.insert("ui_select", inputs);
  376. inputs = List<Ref<InputEvent>>();
  377. inputs.push_back(InputEventKey::create_reference(Key::ESCAPE));
  378. default_builtin_cache.insert("ui_cancel", inputs);
  379. inputs = List<Ref<InputEvent>>();
  380. inputs.push_back(InputEventKey::create_reference(Key::ESCAPE));
  381. default_builtin_cache.insert("ui_close_dialog", inputs);
  382. inputs = List<Ref<InputEvent>>();
  383. inputs.push_back(InputEventKey::create_reference(Key::W | KeyModifierMask::META));
  384. inputs.push_back(InputEventKey::create_reference(Key::ESCAPE));
  385. default_builtin_cache.insert("ui_close_dialog.macos", inputs);
  386. inputs = List<Ref<InputEvent>>();
  387. inputs.push_back(InputEventKey::create_reference(Key::TAB));
  388. default_builtin_cache.insert("ui_focus_next", inputs);
  389. inputs = List<Ref<InputEvent>>();
  390. inputs.push_back(InputEventKey::create_reference(Key::TAB | KeyModifierMask::SHIFT));
  391. default_builtin_cache.insert("ui_focus_prev", inputs);
  392. inputs = List<Ref<InputEvent>>();
  393. inputs.push_back(InputEventKey::create_reference(Key::LEFT));
  394. inputs.push_back(InputEventJoypadButton::create_reference(JoyButton::DPAD_LEFT));
  395. inputs.push_back(InputEventJoypadMotion::create_reference(JoyAxis::LEFT_X, -1.0));
  396. default_builtin_cache.insert("ui_left", inputs);
  397. inputs = List<Ref<InputEvent>>();
  398. inputs.push_back(InputEventKey::create_reference(Key::RIGHT));
  399. inputs.push_back(InputEventJoypadButton::create_reference(JoyButton::DPAD_RIGHT));
  400. inputs.push_back(InputEventJoypadMotion::create_reference(JoyAxis::LEFT_X, 1.0));
  401. default_builtin_cache.insert("ui_right", inputs);
  402. inputs = List<Ref<InputEvent>>();
  403. inputs.push_back(InputEventKey::create_reference(Key::UP));
  404. inputs.push_back(InputEventJoypadButton::create_reference(JoyButton::DPAD_UP));
  405. inputs.push_back(InputEventJoypadMotion::create_reference(JoyAxis::LEFT_Y, -1.0));
  406. default_builtin_cache.insert("ui_up", inputs);
  407. inputs = List<Ref<InputEvent>>();
  408. inputs.push_back(InputEventKey::create_reference(Key::DOWN));
  409. inputs.push_back(InputEventJoypadButton::create_reference(JoyButton::DPAD_DOWN));
  410. inputs.push_back(InputEventJoypadMotion::create_reference(JoyAxis::LEFT_Y, 1.0));
  411. default_builtin_cache.insert("ui_down", inputs);
  412. inputs = List<Ref<InputEvent>>();
  413. inputs.push_back(InputEventKey::create_reference(Key::PAGEUP));
  414. default_builtin_cache.insert("ui_page_up", inputs);
  415. inputs = List<Ref<InputEvent>>();
  416. inputs.push_back(InputEventKey::create_reference(Key::PAGEDOWN));
  417. default_builtin_cache.insert("ui_page_down", inputs);
  418. inputs = List<Ref<InputEvent>>();
  419. inputs.push_back(InputEventKey::create_reference(Key::HOME));
  420. default_builtin_cache.insert("ui_home", inputs);
  421. inputs = List<Ref<InputEvent>>();
  422. inputs.push_back(InputEventKey::create_reference(Key::END));
  423. default_builtin_cache.insert("ui_end", inputs);
  424. inputs = List<Ref<InputEvent>>();
  425. default_builtin_cache.insert("ui_accessibility_drag_and_drop", inputs);
  426. // ///// UI basic Shortcuts /////
  427. inputs = List<Ref<InputEvent>>();
  428. inputs.push_back(InputEventKey::create_reference(Key::X | KeyModifierMask::CMD_OR_CTRL));
  429. inputs.push_back(InputEventKey::create_reference(Key::KEY_DELETE | KeyModifierMask::SHIFT));
  430. default_builtin_cache.insert("ui_cut", inputs);
  431. inputs = List<Ref<InputEvent>>();
  432. inputs.push_back(InputEventKey::create_reference(Key::C | KeyModifierMask::CMD_OR_CTRL));
  433. inputs.push_back(InputEventKey::create_reference(Key::INSERT | KeyModifierMask::CMD_OR_CTRL));
  434. default_builtin_cache.insert("ui_copy", inputs);
  435. inputs = List<Ref<InputEvent>>();
  436. inputs.push_back(InputEventKey::create_reference(Key::M | KeyModifierMask::CTRL));
  437. default_builtin_cache.insert("ui_focus_mode", inputs);
  438. inputs = List<Ref<InputEvent>>();
  439. inputs.push_back(InputEventKey::create_reference(Key::V | KeyModifierMask::CMD_OR_CTRL));
  440. inputs.push_back(InputEventKey::create_reference(Key::INSERT | KeyModifierMask::SHIFT));
  441. default_builtin_cache.insert("ui_paste", inputs);
  442. inputs = List<Ref<InputEvent>>();
  443. inputs.push_back(InputEventKey::create_reference(Key::Z | KeyModifierMask::CMD_OR_CTRL));
  444. default_builtin_cache.insert("ui_undo", inputs);
  445. inputs = List<Ref<InputEvent>>();
  446. inputs.push_back(InputEventKey::create_reference(Key::Z | KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT));
  447. inputs.push_back(InputEventKey::create_reference(Key::Y | KeyModifierMask::CMD_OR_CTRL));
  448. default_builtin_cache.insert("ui_redo", inputs);
  449. // ///// UI Text Input Shortcuts /////
  450. inputs = List<Ref<InputEvent>>();
  451. inputs.push_back(InputEventKey::create_reference(Key::SPACE | KeyModifierMask::CTRL));
  452. default_builtin_cache.insert("ui_text_completion_query", inputs);
  453. inputs = List<Ref<InputEvent>>();
  454. inputs.push_back(InputEventKey::create_reference(KeyModifierMask::SHIFT | Key::TAB));
  455. inputs.push_back(InputEventKey::create_reference(KeyModifierMask::SHIFT | Key::ENTER));
  456. inputs.push_back(InputEventKey::create_reference(KeyModifierMask::SHIFT | Key::KP_ENTER));
  457. default_builtin_cache.insert("ui_text_completion_accept", inputs);
  458. inputs = List<Ref<InputEvent>>();
  459. inputs.push_back(InputEventKey::create_reference(Key::TAB));
  460. inputs.push_back(InputEventKey::create_reference(Key::ENTER));
  461. inputs.push_back(InputEventKey::create_reference(Key::KP_ENTER));
  462. default_builtin_cache.insert("ui_text_completion_replace", inputs);
  463. // Newlines
  464. inputs = List<Ref<InputEvent>>();
  465. inputs.push_back(InputEventKey::create_reference(Key::ENTER));
  466. inputs.push_back(InputEventKey::create_reference(Key::KP_ENTER));
  467. default_builtin_cache.insert("ui_text_newline", inputs);
  468. inputs = List<Ref<InputEvent>>();
  469. inputs.push_back(InputEventKey::create_reference(Key::ENTER | KeyModifierMask::CMD_OR_CTRL));
  470. inputs.push_back(InputEventKey::create_reference(Key::KP_ENTER | KeyModifierMask::CMD_OR_CTRL));
  471. default_builtin_cache.insert("ui_text_newline_blank", inputs);
  472. inputs = List<Ref<InputEvent>>();
  473. inputs.push_back(InputEventKey::create_reference(Key::ENTER | KeyModifierMask::SHIFT | KeyModifierMask::CMD_OR_CTRL));
  474. inputs.push_back(InputEventKey::create_reference(Key::KP_ENTER | KeyModifierMask::SHIFT | KeyModifierMask::CMD_OR_CTRL));
  475. default_builtin_cache.insert("ui_text_newline_above", inputs);
  476. // Indentation
  477. inputs = List<Ref<InputEvent>>();
  478. inputs.push_back(InputEventKey::create_reference(Key::TAB));
  479. default_builtin_cache.insert("ui_text_indent", inputs);
  480. inputs = List<Ref<InputEvent>>();
  481. inputs.push_back(InputEventKey::create_reference(Key::TAB | KeyModifierMask::SHIFT));
  482. default_builtin_cache.insert("ui_text_dedent", inputs);
  483. // Text Backspace and Delete
  484. inputs = List<Ref<InputEvent>>();
  485. inputs.push_back(InputEventKey::create_reference(Key::BACKSPACE));
  486. inputs.push_back(InputEventKey::create_reference(Key::BACKSPACE | KeyModifierMask::SHIFT));
  487. default_builtin_cache.insert("ui_text_backspace", inputs);
  488. inputs = List<Ref<InputEvent>>();
  489. inputs.push_back(InputEventKey::create_reference(Key::BACKSPACE | KeyModifierMask::CMD_OR_CTRL));
  490. default_builtin_cache.insert("ui_text_backspace_word", inputs);
  491. inputs = List<Ref<InputEvent>>();
  492. inputs.push_back(InputEventKey::create_reference(Key::BACKSPACE | KeyModifierMask::ALT));
  493. default_builtin_cache.insert("ui_text_backspace_word.macos", inputs);
  494. inputs = List<Ref<InputEvent>>();
  495. default_builtin_cache.insert("ui_text_backspace_all_to_left", inputs);
  496. inputs = List<Ref<InputEvent>>();
  497. inputs.push_back(InputEventKey::create_reference(Key::BACKSPACE | KeyModifierMask::CMD_OR_CTRL));
  498. default_builtin_cache.insert("ui_text_backspace_all_to_left.macos", inputs);
  499. inputs = List<Ref<InputEvent>>();
  500. inputs.push_back(InputEventKey::create_reference(Key::KEY_DELETE));
  501. default_builtin_cache.insert("ui_text_delete", inputs);
  502. inputs = List<Ref<InputEvent>>();
  503. inputs.push_back(InputEventKey::create_reference(Key::KEY_DELETE | KeyModifierMask::CMD_OR_CTRL));
  504. default_builtin_cache.insert("ui_text_delete_word", inputs);
  505. inputs = List<Ref<InputEvent>>();
  506. inputs.push_back(InputEventKey::create_reference(Key::KEY_DELETE | KeyModifierMask::ALT));
  507. default_builtin_cache.insert("ui_text_delete_word.macos", inputs);
  508. inputs = List<Ref<InputEvent>>();
  509. default_builtin_cache.insert("ui_text_delete_all_to_right", inputs);
  510. inputs = List<Ref<InputEvent>>();
  511. inputs.push_back(InputEventKey::create_reference(Key::KEY_DELETE | KeyModifierMask::CMD_OR_CTRL));
  512. default_builtin_cache.insert("ui_text_delete_all_to_right.macos", inputs);
  513. // Text Caret Movement Left/Right
  514. inputs = List<Ref<InputEvent>>();
  515. inputs.push_back(InputEventKey::create_reference(Key::LEFT));
  516. default_builtin_cache.insert("ui_text_caret_left", inputs);
  517. inputs = List<Ref<InputEvent>>();
  518. inputs.push_back(InputEventKey::create_reference(Key::LEFT | KeyModifierMask::CMD_OR_CTRL));
  519. default_builtin_cache.insert("ui_text_caret_word_left", inputs);
  520. inputs = List<Ref<InputEvent>>();
  521. inputs.push_back(InputEventKey::create_reference(Key::LEFT | KeyModifierMask::ALT));
  522. default_builtin_cache.insert("ui_text_caret_word_left.macos", inputs);
  523. inputs = List<Ref<InputEvent>>();
  524. inputs.push_back(InputEventKey::create_reference(Key::RIGHT));
  525. default_builtin_cache.insert("ui_text_caret_right", inputs);
  526. inputs = List<Ref<InputEvent>>();
  527. inputs.push_back(InputEventKey::create_reference(Key::RIGHT | KeyModifierMask::CMD_OR_CTRL));
  528. default_builtin_cache.insert("ui_text_caret_word_right", inputs);
  529. inputs = List<Ref<InputEvent>>();
  530. inputs.push_back(InputEventKey::create_reference(Key::RIGHT | KeyModifierMask::ALT));
  531. default_builtin_cache.insert("ui_text_caret_word_right.macos", inputs);
  532. // Text Caret Movement Up/Down
  533. inputs = List<Ref<InputEvent>>();
  534. inputs.push_back(InputEventKey::create_reference(Key::UP));
  535. default_builtin_cache.insert("ui_text_caret_up", inputs);
  536. inputs = List<Ref<InputEvent>>();
  537. inputs.push_back(InputEventKey::create_reference(Key::DOWN));
  538. default_builtin_cache.insert("ui_text_caret_down", inputs);
  539. // Text Caret Movement Line Start/End
  540. inputs = List<Ref<InputEvent>>();
  541. inputs.push_back(InputEventKey::create_reference(Key::HOME));
  542. default_builtin_cache.insert("ui_text_caret_line_start", inputs);
  543. inputs = List<Ref<InputEvent>>();
  544. inputs.push_back(InputEventKey::create_reference(Key::A | KeyModifierMask::CTRL));
  545. inputs.push_back(InputEventKey::create_reference(Key::LEFT | KeyModifierMask::CMD_OR_CTRL));
  546. inputs.push_back(InputEventKey::create_reference(Key::HOME));
  547. default_builtin_cache.insert("ui_text_caret_line_start.macos", inputs);
  548. inputs = List<Ref<InputEvent>>();
  549. inputs.push_back(InputEventKey::create_reference(Key::END));
  550. default_builtin_cache.insert("ui_text_caret_line_end", inputs);
  551. inputs = List<Ref<InputEvent>>();
  552. inputs.push_back(InputEventKey::create_reference(Key::E | KeyModifierMask::CTRL));
  553. inputs.push_back(InputEventKey::create_reference(Key::RIGHT | KeyModifierMask::CMD_OR_CTRL));
  554. inputs.push_back(InputEventKey::create_reference(Key::END));
  555. default_builtin_cache.insert("ui_text_caret_line_end.macos", inputs);
  556. // Text Caret Movement Page Up/Down
  557. inputs = List<Ref<InputEvent>>();
  558. inputs.push_back(InputEventKey::create_reference(Key::PAGEUP));
  559. default_builtin_cache.insert("ui_text_caret_page_up", inputs);
  560. inputs = List<Ref<InputEvent>>();
  561. inputs.push_back(InputEventKey::create_reference(Key::PAGEDOWN));
  562. default_builtin_cache.insert("ui_text_caret_page_down", inputs);
  563. // Text Caret Movement Document Start/End
  564. inputs = List<Ref<InputEvent>>();
  565. inputs.push_back(InputEventKey::create_reference(Key::HOME | KeyModifierMask::CMD_OR_CTRL));
  566. default_builtin_cache.insert("ui_text_caret_document_start", inputs);
  567. inputs = List<Ref<InputEvent>>();
  568. inputs.push_back(InputEventKey::create_reference(Key::UP | KeyModifierMask::CMD_OR_CTRL));
  569. inputs.push_back(InputEventKey::create_reference(Key::HOME | KeyModifierMask::CMD_OR_CTRL));
  570. default_builtin_cache.insert("ui_text_caret_document_start.macos", inputs);
  571. inputs = List<Ref<InputEvent>>();
  572. inputs.push_back(InputEventKey::create_reference(Key::END | KeyModifierMask::CMD_OR_CTRL));
  573. default_builtin_cache.insert("ui_text_caret_document_end", inputs);
  574. inputs = List<Ref<InputEvent>>();
  575. inputs.push_back(InputEventKey::create_reference(Key::DOWN | KeyModifierMask::CMD_OR_CTRL));
  576. inputs.push_back(InputEventKey::create_reference(Key::END | KeyModifierMask::CMD_OR_CTRL));
  577. default_builtin_cache.insert("ui_text_caret_document_end.macos", inputs);
  578. // Text Caret Addition Below/Above
  579. inputs = List<Ref<InputEvent>>();
  580. inputs.push_back(InputEventKey::create_reference(Key::DOWN | KeyModifierMask::SHIFT | KeyModifierMask::CMD_OR_CTRL));
  581. default_builtin_cache.insert("ui_text_caret_add_below", inputs);
  582. inputs = List<Ref<InputEvent>>();
  583. inputs.push_back(InputEventKey::create_reference(Key::L | KeyModifierMask::SHIFT | KeyModifierMask::CMD_OR_CTRL));
  584. default_builtin_cache.insert("ui_text_caret_add_below.macos", inputs);
  585. inputs = List<Ref<InputEvent>>();
  586. inputs.push_back(InputEventKey::create_reference(Key::UP | KeyModifierMask::SHIFT | KeyModifierMask::CMD_OR_CTRL));
  587. default_builtin_cache.insert("ui_text_caret_add_above", inputs);
  588. inputs = List<Ref<InputEvent>>();
  589. inputs.push_back(InputEventKey::create_reference(Key::O | KeyModifierMask::SHIFT | KeyModifierMask::CMD_OR_CTRL));
  590. default_builtin_cache.insert("ui_text_caret_add_above.macos", inputs);
  591. // Text Scrolling
  592. inputs = List<Ref<InputEvent>>();
  593. inputs.push_back(InputEventKey::create_reference(Key::UP | KeyModifierMask::CMD_OR_CTRL));
  594. default_builtin_cache.insert("ui_text_scroll_up", inputs);
  595. inputs = List<Ref<InputEvent>>();
  596. inputs.push_back(InputEventKey::create_reference(Key::UP | KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::ALT));
  597. default_builtin_cache.insert("ui_text_scroll_up.macos", inputs);
  598. inputs = List<Ref<InputEvent>>();
  599. inputs.push_back(InputEventKey::create_reference(Key::DOWN | KeyModifierMask::CMD_OR_CTRL));
  600. default_builtin_cache.insert("ui_text_scroll_down", inputs);
  601. inputs = List<Ref<InputEvent>>();
  602. inputs.push_back(InputEventKey::create_reference(Key::DOWN | KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::ALT));
  603. default_builtin_cache.insert("ui_text_scroll_down.macos", inputs);
  604. // Text Misc
  605. inputs = List<Ref<InputEvent>>();
  606. inputs.push_back(InputEventKey::create_reference(Key::A | KeyModifierMask::CMD_OR_CTRL));
  607. default_builtin_cache.insert("ui_text_select_all", inputs);
  608. inputs = List<Ref<InputEvent>>();
  609. inputs.push_back(InputEventKey::create_reference(Key::G | KeyModifierMask::ALT));
  610. default_builtin_cache.insert("ui_text_select_word_under_caret", inputs);
  611. inputs = List<Ref<InputEvent>>();
  612. inputs.push_back(InputEventKey::create_reference(Key::G | KeyModifierMask::CTRL | KeyModifierMask::META));
  613. default_builtin_cache.insert("ui_text_select_word_under_caret.macos", inputs);
  614. inputs = List<Ref<InputEvent>>();
  615. inputs.push_back(InputEventKey::create_reference(Key::D | KeyModifierMask::CMD_OR_CTRL));
  616. default_builtin_cache.insert("ui_text_add_selection_for_next_occurrence", inputs);
  617. inputs = List<Ref<InputEvent>>();
  618. inputs.push_back(InputEventKey::create_reference(Key::D | KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::ALT));
  619. default_builtin_cache.insert("ui_text_skip_selection_for_next_occurrence", inputs);
  620. inputs = List<Ref<InputEvent>>();
  621. inputs.push_back(InputEventKey::create_reference(Key::ESCAPE));
  622. default_builtin_cache.insert("ui_text_clear_carets_and_selection", inputs);
  623. inputs = List<Ref<InputEvent>>();
  624. inputs.push_back(InputEventKey::create_reference(Key::INSERT));
  625. default_builtin_cache.insert("ui_text_toggle_insert_mode", inputs);
  626. inputs = List<Ref<InputEvent>>();
  627. inputs.push_back(InputEventKey::create_reference(Key::MENU));
  628. default_builtin_cache.insert("ui_menu", inputs);
  629. inputs = List<Ref<InputEvent>>();
  630. inputs.push_back(InputEventKey::create_reference(Key::ENTER));
  631. inputs.push_back(InputEventKey::create_reference(Key::KP_ENTER));
  632. default_builtin_cache.insert("ui_text_submit", inputs);
  633. inputs = List<Ref<InputEvent>>();
  634. inputs.push_back(InputEventKey::create_reference(Key::U | KeyModifierMask::CTRL | KeyModifierMask::SHIFT));
  635. default_builtin_cache.insert("ui_unicode_start", inputs);
  636. // ///// UI Graph Shortcuts /////
  637. inputs = List<Ref<InputEvent>>();
  638. inputs.push_back(InputEventKey::create_reference(Key::D | KeyModifierMask::CMD_OR_CTRL));
  639. default_builtin_cache.insert("ui_graph_duplicate", inputs);
  640. inputs = List<Ref<InputEvent>>();
  641. inputs.push_back(InputEventKey::create_reference(Key::KEY_DELETE));
  642. default_builtin_cache.insert("ui_graph_delete", inputs);
  643. inputs = List<Ref<InputEvent>>();
  644. inputs.push_back(InputEventKey::create_reference(Key::LEFT | KeyModifierMask::CMD_OR_CTRL));
  645. default_builtin_cache.insert("ui_graph_follow_left", inputs);
  646. inputs = List<Ref<InputEvent>>();
  647. inputs.push_back(InputEventKey::create_reference(Key::LEFT | KeyModifierMask::ALT));
  648. default_builtin_cache.insert("ui_graph_follow_left.macos", inputs);
  649. inputs = List<Ref<InputEvent>>();
  650. inputs.push_back(InputEventKey::create_reference(Key::RIGHT | KeyModifierMask::CMD_OR_CTRL));
  651. default_builtin_cache.insert("ui_graph_follow_right", inputs);
  652. inputs = List<Ref<InputEvent>>();
  653. inputs.push_back(InputEventKey::create_reference(Key::RIGHT | KeyModifierMask::ALT));
  654. default_builtin_cache.insert("ui_graph_follow_right.macos", inputs);
  655. // ///// UI File Dialog Shortcuts /////
  656. inputs = List<Ref<InputEvent>>();
  657. inputs.push_back(InputEventKey::create_reference(Key::KEY_DELETE));
  658. default_builtin_cache.insert("ui_filedialog_delete", inputs);
  659. inputs = List<Ref<InputEvent>>();
  660. inputs.push_back(InputEventKey::create_reference(Key::BACKSPACE));
  661. default_builtin_cache.insert("ui_filedialog_up_one_level", inputs);
  662. inputs = List<Ref<InputEvent>>();
  663. inputs.push_back(InputEventKey::create_reference(Key::F5));
  664. default_builtin_cache.insert("ui_filedialog_refresh", inputs);
  665. inputs = List<Ref<InputEvent>>();
  666. inputs.push_back(InputEventKey::create_reference(Key::H));
  667. default_builtin_cache.insert("ui_filedialog_show_hidden", inputs);
  668. inputs = List<Ref<InputEvent>>();
  669. inputs.push_back(InputEventKey::create_reference(Key::F | KeyModifierMask::CMD_OR_CTRL));
  670. default_builtin_cache.insert("ui_filedialog_find", inputs);
  671. inputs = List<Ref<InputEvent>>();
  672. // Ctrl + L (matches most Windows/Linux file managers' "focus on path bar" shortcut,
  673. // plus macOS Safari's "focus on address bar" shortcut).
  674. inputs.push_back(InputEventKey::create_reference(Key::L | KeyModifierMask::CMD_OR_CTRL));
  675. default_builtin_cache.insert("ui_filedialog_focus_path", inputs);
  676. inputs = List<Ref<InputEvent>>();
  677. // Cmd + Shift + G (matches Finder's "Go To" shortcut).
  678. inputs.push_back(InputEventKey::create_reference(Key::G | KeyModifierMask::CMD_OR_CTRL));
  679. inputs.push_back(InputEventKey::create_reference(Key::L | KeyModifierMask::CMD_OR_CTRL));
  680. default_builtin_cache.insert("ui_filedialog_focus_path.macos", inputs);
  681. inputs = List<Ref<InputEvent>>();
  682. inputs.push_back(InputEventKey::create_reference(Key::QUOTELEFT | KeyModifierMask::CMD_OR_CTRL));
  683. default_builtin_cache.insert("ui_swap_input_direction", inputs);
  684. // ///// UI ColorPicker Shortcuts /////
  685. inputs = List<Ref<InputEvent>>();
  686. inputs.push_back(InputEventJoypadButton::create_reference(JoyButton::X));
  687. inputs.push_back(InputEventKey::create_reference(Key::KEY_DELETE));
  688. default_builtin_cache.insert("ui_colorpicker_delete_preset", inputs);
  689. return default_builtin_cache;
  690. }
  691. const HashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins_with_feature_overrides_applied() {
  692. if (default_builtin_with_overrides_cache.size() > 0) {
  693. return default_builtin_with_overrides_cache;
  694. }
  695. const HashMap<String, List<Ref<InputEvent>>> &builtins = get_builtins();
  696. // Get a list of all built in inputs which are valid overrides for the OS
  697. // Key = builtin name (e.g. ui_accept)
  698. // Value = override/feature names (e.g. macos, if it was defined as "ui_accept.macos" and the platform supports that feature)
  699. HashMap<String, Vector<String>> builtins_with_overrides;
  700. for (const KeyValue<String, List<Ref<InputEvent>>> &E : builtins) {
  701. String fullname = E.key;
  702. const String &name = fullname.get_slicec('.', 0);
  703. String override_for = fullname.get_slice_count(".") > 1 ? fullname.get_slicec('.', 1) : String();
  704. if (!override_for.is_empty() && OS::get_singleton()->has_feature(override_for)) {
  705. builtins_with_overrides[name].push_back(override_for);
  706. }
  707. }
  708. for (const KeyValue<String, List<Ref<InputEvent>>> &E : builtins) {
  709. String fullname = E.key;
  710. const String &name = fullname.get_slicec('.', 0);
  711. String override_for = fullname.get_slice_count(".") > 1 ? fullname.get_slicec('.', 1) : String();
  712. if (builtins_with_overrides.has(name) && override_for.is_empty()) {
  713. // Builtin has an override but this particular one is not an override, so skip.
  714. continue;
  715. }
  716. if (!override_for.is_empty() && !OS::get_singleton()->has_feature(override_for)) {
  717. // OS does not support this override - skip.
  718. continue;
  719. }
  720. default_builtin_with_overrides_cache.insert(name, E.value);
  721. }
  722. return default_builtin_with_overrides_cache;
  723. }
  724. void InputMap::load_default() {
  725. HashMap<String, List<Ref<InputEvent>>> builtins = get_builtins_with_feature_overrides_applied();
  726. for (const KeyValue<String, List<Ref<InputEvent>>> &E : builtins) {
  727. String name = E.key;
  728. add_action(name);
  729. const List<Ref<InputEvent>> &inputs = E.value;
  730. for (const List<Ref<InputEvent>>::Element *I = inputs.front(); I; I = I->next()) {
  731. Ref<InputEventKey> iek = I->get();
  732. // For the editor, only add keyboard actions.
  733. if (iek.is_valid()) {
  734. action_add_event(name, I->get());
  735. }
  736. }
  737. }
  738. }
  739. InputMap::InputMap() {
  740. ERR_FAIL_COND_MSG(singleton, "Singleton in InputMap already exists.");
  741. singleton = this;
  742. }
  743. InputMap::~InputMap() {
  744. singleton = nullptr;
  745. }