action_map_editor.cpp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167
  1. /*************************************************************************/
  2. /* action_map_editor.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  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 "action_map_editor.h"
  31. #include "core/input/input_map.h"
  32. #include "core/os/keyboard.h"
  33. #include "editor/editor_scale.h"
  34. #include "scene/gui/center_container.h"
  35. /////////////////////////////////////////
  36. // Maps to 2*axis if value is neg, or + 1 if value is pos.
  37. static const char *_joy_axis_descriptions[JOY_AXIS_MAX * 2] = {
  38. TTRC("Left Stick Left, Joystick 0 Left"),
  39. TTRC("Left Stick Right, Joystick 0 Right"),
  40. TTRC("Left Stick Up, Joystick 0 Up"),
  41. TTRC("Left Stick Down, Joystick 0 Down"),
  42. TTRC("Right Stick Left, Joystick 1 Left"),
  43. TTRC("Right Stick Right, Joystick 1 Right"),
  44. TTRC("Right Stick Up, Joystick 1 Up"),
  45. TTRC("Right Stick Down, Joystick 1 Down"),
  46. TTRC("Joystick 2 Left"),
  47. TTRC("Left Trigger, Sony L2, Xbox LT, Joystick 2 Right"),
  48. TTRC("Joystick 2 Up"),
  49. TTRC("Right Trigger, Sony R2, Xbox RT, Joystick 2 Down"),
  50. TTRC("Joystick 3 Left"),
  51. TTRC("Joystick 3 Right"),
  52. TTRC("Joystick 3 Up"),
  53. TTRC("Joystick 3 Down"),
  54. TTRC("Joystick 4 Left"),
  55. TTRC("Joystick 4 Right"),
  56. TTRC("Joystick 4 Up"),
  57. TTRC("Joystick 4 Down"),
  58. };
  59. String InputEventConfigurationDialog::get_event_text(const Ref<InputEvent> &p_event) {
  60. ERR_FAIL_COND_V_MSG(p_event.is_null(), String(), "Provided event is not a valid instance of InputEvent");
  61. // Joypad motion events will display slighlty differently than what the event->as_text() provides. See #43660.
  62. Ref<InputEventJoypadMotion> jpmotion = p_event;
  63. if (jpmotion.is_valid()) {
  64. String desc = TTR("Unknown Joypad Axis");
  65. if (jpmotion->get_axis() < JOY_AXIS_MAX) {
  66. desc = RTR(_joy_axis_descriptions[2 * jpmotion->get_axis() + (jpmotion->get_axis_value() < 0 ? 0 : 1)]);
  67. }
  68. return vformat("Joypad Axis %s %s (%s)", itos(jpmotion->get_axis()), jpmotion->get_axis_value() < 0 ? "-" : "+", desc);
  69. } else {
  70. return p_event->as_text();
  71. }
  72. }
  73. void InputEventConfigurationDialog::_set_event(const Ref<InputEvent> &p_event) {
  74. if (p_event.is_valid()) {
  75. event = p_event;
  76. // Update Label
  77. event_as_text->set_text(get_event_text(event));
  78. Ref<InputEventKey> k = p_event;
  79. Ref<InputEventMouseButton> mb = p_event;
  80. Ref<InputEventJoypadButton> joyb = p_event;
  81. Ref<InputEventJoypadMotion> joym = p_event;
  82. Ref<InputEventWithModifiers> mod = p_event;
  83. // Update option values and visibility
  84. bool show_mods = false;
  85. bool show_device = false;
  86. bool show_phys_key = false;
  87. if (mod.is_valid()) {
  88. show_mods = true;
  89. mod_checkboxes[MOD_ALT]->set_pressed(mod->get_alt());
  90. mod_checkboxes[MOD_SHIFT]->set_pressed(mod->get_shift());
  91. mod_checkboxes[MOD_COMMAND]->set_pressed(mod->get_command());
  92. mod_checkboxes[MOD_CONTROL]->set_pressed(mod->get_control());
  93. mod_checkboxes[MOD_META]->set_pressed(mod->get_metakey());
  94. store_command_checkbox->set_pressed(mod->is_storing_command());
  95. }
  96. if (k.is_valid()) {
  97. show_phys_key = true;
  98. physical_key_checkbox->set_pressed(k->get_physical_keycode() != 0 && k->get_keycode() == 0);
  99. } else if (joyb.is_valid() || joym.is_valid() || mb.is_valid()) {
  100. show_device = true;
  101. _set_current_device(event->get_device());
  102. }
  103. mod_container->set_visible(show_mods);
  104. device_container->set_visible(show_device);
  105. physical_key_checkbox->set_visible(show_phys_key);
  106. additional_options_container->show();
  107. // Update selected item in input list for keys, joybuttons and joyaxis only (since the mouse cannot be "listened" for).
  108. if (k.is_valid() || joyb.is_valid() || joym.is_valid()) {
  109. TreeItem *category = input_list_tree->get_root()->get_children();
  110. while (category) {
  111. TreeItem *input_item = category->get_children();
  112. // has_type this should be always true, unless the tree structure has been misconfigured.
  113. bool has_type = input_item->get_parent()->has_meta("__type");
  114. int input_type = input_item->get_parent()->get_meta("__type");
  115. if (!has_type) {
  116. return;
  117. }
  118. // If event type matches input types of this category.
  119. if ((k.is_valid() && input_type == INPUT_KEY) || (joyb.is_valid() && input_type == INPUT_JOY_BUTTON) || (joym.is_valid() && input_type == INPUT_JOY_MOTION)) {
  120. // Loop through all items of this category until one matches.
  121. while (input_item) {
  122. bool key_match = k.is_valid() && (Variant(k->get_keycode()) == input_item->get_meta("__keycode") || Variant(k->get_physical_keycode()) == input_item->get_meta("__keycode"));
  123. bool joyb_match = joyb.is_valid() && Variant(joyb->get_button_index()) == input_item->get_meta("__index");
  124. bool joym_match = joym.is_valid() && Variant(joym->get_axis()) == input_item->get_meta("__axis") && joym->get_axis_value() == (float)input_item->get_meta("__value");
  125. if (key_match || joyb_match || joym_match) {
  126. category->set_collapsed(false);
  127. input_item->select(0);
  128. input_list_tree->ensure_cursor_is_visible();
  129. return;
  130. }
  131. input_item = input_item->get_next();
  132. }
  133. }
  134. category->set_collapsed(true); // Event not in this category, so collapse;
  135. category = category->get_next();
  136. }
  137. }
  138. } else {
  139. // Event is not valid, reset dialog
  140. event = p_event;
  141. Vector<String> strings;
  142. // Reset message, promp for input according to which input types are allowed.
  143. String text = TTR("Perform an Input (%s).");
  144. if (allowed_input_types & INPUT_KEY) {
  145. strings.append(TTR("Key"));
  146. }
  147. // We don't check for INPUT_MOUSE_BUTTON since it is ignored in the "Listen Window Input" method.
  148. if (allowed_input_types & INPUT_JOY_BUTTON) {
  149. strings.append(TTR("Joypad Button"));
  150. }
  151. if (allowed_input_types & INPUT_JOY_MOTION) {
  152. strings.append(TTR("Joypad Axis"));
  153. }
  154. if (strings.size() == 0) {
  155. text = TTR("Input Event dialog has been misconfigured: No input types are allowed.");
  156. event_as_text->set_text(text);
  157. } else {
  158. String insert_text = String(", ").join(strings);
  159. event_as_text->set_text(vformat(text, insert_text));
  160. }
  161. additional_options_container->hide();
  162. input_list_tree->deselect_all();
  163. _update_input_list();
  164. }
  165. }
  166. void InputEventConfigurationDialog::_tab_selected(int p_tab) {
  167. Callable signal_method = callable_mp(this, &InputEventConfigurationDialog::_listen_window_input);
  168. if (p_tab == 0) {
  169. // Start Listening.
  170. if (!is_connected("window_input", signal_method)) {
  171. connect("window_input", signal_method);
  172. }
  173. } else {
  174. // Stop Listening.
  175. if (is_connected("window_input", signal_method)) {
  176. disconnect("window_input", signal_method);
  177. }
  178. input_list_tree->call_deferred("ensure_cursor_is_visible");
  179. if (input_list_tree->get_selected() == nullptr) {
  180. // If nothing selected, scroll to top.
  181. input_list_tree->scroll_to_item(input_list_tree->get_root());
  182. }
  183. }
  184. }
  185. void InputEventConfigurationDialog::_listen_window_input(const Ref<InputEvent> &p_event) {
  186. // Ignore if echo or not pressed
  187. if (p_event->is_echo() || !p_event->is_pressed()) {
  188. return;
  189. }
  190. // Ignore mouse
  191. Ref<InputEventMouse> m = p_event;
  192. if (m.is_valid()) {
  193. return;
  194. }
  195. // Check what the type is and if it is allowed.
  196. Ref<InputEventKey> k = p_event;
  197. Ref<InputEventJoypadButton> joyb = p_event;
  198. Ref<InputEventJoypadMotion> joym = p_event;
  199. int type = k.is_valid() ? INPUT_KEY : joyb.is_valid() ? INPUT_JOY_BUTTON :
  200. joym.is_valid() ? INPUT_JOY_MOTION :
  201. 0;
  202. if (!(allowed_input_types & type)) {
  203. return;
  204. }
  205. if (joym.is_valid()) {
  206. float axis_value = joym->get_axis_value();
  207. if (ABS(axis_value) < 0.9) {
  208. // Ignore motion below 0.9 magnitude to avoid accidental touches
  209. return;
  210. } else {
  211. // Always make the value 1 or -1 for display consistency
  212. joym->set_axis_value(SGN(axis_value));
  213. }
  214. }
  215. if (k.is_valid()) {
  216. k->set_pressed(false); // to avoid serialisation of 'pressed' property - doesn't matter for actions anyway.
  217. // Maintain physical keycode option state
  218. if (physical_key_checkbox->is_pressed()) {
  219. k->set_physical_keycode(k->get_keycode());
  220. k->set_keycode(0);
  221. } else {
  222. k->set_keycode(k->get_physical_keycode());
  223. k->set_physical_keycode(0);
  224. }
  225. }
  226. Ref<InputEventWithModifiers> mod = p_event;
  227. if (mod.is_valid()) {
  228. // Maintain store command option state
  229. mod->set_store_command(store_command_checkbox->is_pressed());
  230. mod->set_window_id(0);
  231. }
  232. _set_event(p_event);
  233. set_input_as_handled();
  234. }
  235. void InputEventConfigurationDialog::_search_term_updated(const String &) {
  236. _update_input_list();
  237. }
  238. void InputEventConfigurationDialog::_update_input_list() {
  239. input_list_tree->clear();
  240. TreeItem *root = input_list_tree->create_item();
  241. String search_term = input_list_search->get_text();
  242. bool collapse = input_list_search->get_text().is_empty();
  243. if (allowed_input_types & INPUT_KEY) {
  244. TreeItem *kb_root = input_list_tree->create_item(root);
  245. kb_root->set_text(0, TTR("Keyboard Keys"));
  246. kb_root->set_icon(0, icon_cache.keyboard);
  247. kb_root->set_collapsed(collapse);
  248. kb_root->set_meta("__type", INPUT_KEY);
  249. for (int i = 0; i < keycode_get_count(); i++) {
  250. String name = keycode_get_name_by_index(i);
  251. if (!search_term.is_empty() && name.findn(search_term) == -1) {
  252. continue;
  253. }
  254. TreeItem *item = input_list_tree->create_item(kb_root);
  255. item->set_text(0, name);
  256. item->set_meta("__keycode", keycode_get_value_by_index(i));
  257. }
  258. }
  259. if (allowed_input_types & INPUT_MOUSE_BUTTON) {
  260. TreeItem *mouse_root = input_list_tree->create_item(root);
  261. mouse_root->set_text(0, TTR("Mouse Buttons"));
  262. mouse_root->set_icon(0, icon_cache.mouse);
  263. mouse_root->set_collapsed(collapse);
  264. mouse_root->set_meta("__type", INPUT_MOUSE_BUTTON);
  265. int mouse_buttons[9] = { BUTTON_LEFT, BUTTON_RIGHT, BUTTON_MIDDLE, BUTTON_WHEEL_UP, BUTTON_WHEEL_DOWN, BUTTON_WHEEL_LEFT, BUTTON_WHEEL_RIGHT, BUTTON_XBUTTON1, BUTTON_XBUTTON2 };
  266. for (int i = 0; i < 9; i++) {
  267. Ref<InputEventMouseButton> mb;
  268. mb.instance();
  269. mb->set_button_index(mouse_buttons[i]);
  270. String desc = get_event_text(mb);
  271. if (!search_term.is_empty() && desc.findn(search_term) == -1) {
  272. continue;
  273. }
  274. TreeItem *item = input_list_tree->create_item(mouse_root);
  275. item->set_text(0, desc);
  276. item->set_meta("__index", mouse_buttons[i]);
  277. }
  278. }
  279. if (allowed_input_types & INPUT_JOY_BUTTON) {
  280. TreeItem *joyb_root = input_list_tree->create_item(root);
  281. joyb_root->set_text(0, TTR("Joypad Buttons"));
  282. joyb_root->set_icon(0, icon_cache.joypad_button);
  283. joyb_root->set_collapsed(collapse);
  284. joyb_root->set_meta("__type", INPUT_JOY_BUTTON);
  285. for (int i = 0; i < JOY_BUTTON_MAX; i++) {
  286. Ref<InputEventJoypadButton> joyb;
  287. joyb.instance();
  288. joyb->set_button_index(i);
  289. String desc = get_event_text(joyb);
  290. if (!search_term.is_empty() && desc.findn(search_term) == -1) {
  291. continue;
  292. }
  293. TreeItem *item = input_list_tree->create_item(joyb_root);
  294. item->set_text(0, desc);
  295. item->set_meta("__index", i);
  296. }
  297. }
  298. if (allowed_input_types & INPUT_JOY_MOTION) {
  299. TreeItem *joya_root = input_list_tree->create_item(root);
  300. joya_root->set_text(0, TTR("Joypad Axes"));
  301. joya_root->set_icon(0, icon_cache.joypad_axis);
  302. joya_root->set_collapsed(collapse);
  303. joya_root->set_meta("__type", INPUT_JOY_MOTION);
  304. for (int i = 0; i < JOY_AXIS_MAX * 2; i++) {
  305. int axis = i / 2;
  306. int direction = (i & 1) ? 1 : -1;
  307. Ref<InputEventJoypadMotion> joym;
  308. joym.instance();
  309. joym->set_axis(axis);
  310. joym->set_axis_value(direction);
  311. String desc = get_event_text(joym);
  312. if (!search_term.is_empty() && desc.findn(search_term) == -1) {
  313. continue;
  314. }
  315. TreeItem *item = input_list_tree->create_item(joya_root);
  316. item->set_text(0, desc);
  317. item->set_meta("__axis", i >> 1);
  318. item->set_meta("__value", (i & 1) ? 1 : -1);
  319. }
  320. }
  321. }
  322. void InputEventConfigurationDialog::_mod_toggled(bool p_checked, int p_index) {
  323. Ref<InputEventWithModifiers> ie = event;
  324. // Not event with modifiers
  325. if (ie.is_null()) {
  326. return;
  327. }
  328. if (p_index == 0) {
  329. ie->set_alt(p_checked);
  330. } else if (p_index == 1) {
  331. ie->set_shift(p_checked);
  332. } else if (p_index == 2) {
  333. ie->set_command(p_checked);
  334. } else if (p_index == 3) {
  335. ie->set_control(p_checked);
  336. } else if (p_index == 4) {
  337. ie->set_metakey(p_checked);
  338. }
  339. _set_event(ie);
  340. }
  341. void InputEventConfigurationDialog::_store_command_toggled(bool p_checked) {
  342. Ref<InputEventWithModifiers> ie = event;
  343. if (ie.is_valid()) {
  344. ie->set_store_command(p_checked);
  345. _set_event(ie);
  346. }
  347. if (p_checked) {
  348. // If storing Command, show it's checkbox and hide Control (Win/Lin) or Meta (Mac)
  349. #ifdef APPLE_STYLE_KEYS
  350. mod_checkboxes[MOD_META]->hide();
  351. mod_checkboxes[MOD_COMMAND]->show();
  352. mod_checkboxes[MOD_COMMAND]->set_text("Meta (Command)");
  353. #else
  354. mod_checkboxes[MOD_CONTROL]->hide();
  355. mod_checkboxes[MOD_COMMAND]->show();
  356. mod_checkboxes[MOD_COMMAND]->set_text("Control (Command)");
  357. #endif
  358. } else {
  359. // If not, hide Command, show Control and Meta.
  360. mod_checkboxes[MOD_COMMAND]->hide();
  361. mod_checkboxes[MOD_CONTROL]->show();
  362. mod_checkboxes[MOD_META]->show();
  363. }
  364. }
  365. void InputEventConfigurationDialog::_physical_keycode_toggled(bool p_checked) {
  366. Ref<InputEventKey> k = event;
  367. if (k.is_null()) {
  368. return;
  369. }
  370. if (p_checked) {
  371. k->set_physical_keycode(k->get_keycode());
  372. k->set_keycode(0);
  373. } else {
  374. k->set_keycode(k->get_physical_keycode());
  375. k->set_physical_keycode(0);
  376. }
  377. _set_event(k);
  378. }
  379. void InputEventConfigurationDialog::_input_list_item_selected() {
  380. TreeItem *selected = input_list_tree->get_selected();
  381. // Invalid tree selection - type only exists on the "category" items, which are not a valid selection.
  382. if (selected->has_meta("__type")) {
  383. return;
  384. }
  385. int input_type = selected->get_parent()->get_meta("__type");
  386. switch (input_type) {
  387. case InputEventConfigurationDialog::INPUT_KEY: {
  388. int kc = selected->get_meta("__keycode");
  389. Ref<InputEventKey> k;
  390. k.instance();
  391. if (physical_key_checkbox->is_pressed()) {
  392. k->set_physical_keycode(kc);
  393. k->set_keycode(0);
  394. } else {
  395. k->set_physical_keycode(0);
  396. k->set_keycode(kc);
  397. }
  398. // Maintain modifier state from checkboxes
  399. k->set_alt(mod_checkboxes[MOD_ALT]->is_pressed());
  400. k->set_shift(mod_checkboxes[MOD_SHIFT]->is_pressed());
  401. k->set_command(mod_checkboxes[MOD_COMMAND]->is_pressed());
  402. k->set_control(mod_checkboxes[MOD_CONTROL]->is_pressed());
  403. k->set_metakey(mod_checkboxes[MOD_META]->is_pressed());
  404. k->set_store_command(store_command_checkbox->is_pressed());
  405. _set_event(k);
  406. } break;
  407. case InputEventConfigurationDialog::INPUT_MOUSE_BUTTON: {
  408. int idx = selected->get_meta("__index");
  409. Ref<InputEventMouseButton> mb;
  410. mb.instance();
  411. mb->set_button_index(idx);
  412. // Maintain modifier state from checkboxes
  413. mb->set_alt(mod_checkboxes[MOD_ALT]->is_pressed());
  414. mb->set_shift(mod_checkboxes[MOD_SHIFT]->is_pressed());
  415. mb->set_command(mod_checkboxes[MOD_COMMAND]->is_pressed());
  416. mb->set_control(mod_checkboxes[MOD_CONTROL]->is_pressed());
  417. mb->set_metakey(mod_checkboxes[MOD_META]->is_pressed());
  418. mb->set_store_command(store_command_checkbox->is_pressed());
  419. _set_event(mb);
  420. } break;
  421. case InputEventConfigurationDialog::INPUT_JOY_BUTTON: {
  422. int idx = selected->get_meta("__index");
  423. Ref<InputEventJoypadButton> jb = InputEventJoypadButton::create_reference(idx);
  424. _set_event(jb);
  425. } break;
  426. case InputEventConfigurationDialog::INPUT_JOY_MOTION: {
  427. int axis = selected->get_meta("__axis");
  428. int value = selected->get_meta("__value");
  429. Ref<InputEventJoypadMotion> jm;
  430. jm.instance();
  431. jm->set_axis(axis);
  432. jm->set_axis_value(value);
  433. _set_event(jm);
  434. } break;
  435. default:
  436. break;
  437. }
  438. }
  439. void InputEventConfigurationDialog::_set_current_device(int i_device) {
  440. device_id_option->select(i_device + 1);
  441. }
  442. int InputEventConfigurationDialog::_get_current_device() const {
  443. return device_id_option->get_selected() - 1;
  444. }
  445. String InputEventConfigurationDialog::_get_device_string(int i_device) const {
  446. if (i_device == InputMap::ALL_DEVICES) {
  447. return TTR("All Devices");
  448. }
  449. return TTR("Device") + " " + itos(i_device);
  450. }
  451. void InputEventConfigurationDialog::_notification(int p_what) {
  452. switch (p_what) {
  453. case NOTIFICATION_ENTER_TREE:
  454. case NOTIFICATION_THEME_CHANGED: {
  455. input_list_search->set_right_icon(input_list_search->get_theme_icon("Search", "EditorIcons"));
  456. physical_key_checkbox->set_icon(get_theme_icon("KeyboardPhysical", "EditorIcons"));
  457. icon_cache.keyboard = get_theme_icon("Keyboard", "EditorIcons");
  458. icon_cache.mouse = get_theme_icon("Mouse", "EditorIcons");
  459. icon_cache.joypad_button = get_theme_icon("JoyButton", "EditorIcons");
  460. icon_cache.joypad_axis = get_theme_icon("JoyAxis", "EditorIcons");
  461. _update_input_list();
  462. } break;
  463. default:
  464. break;
  465. }
  466. }
  467. void InputEventConfigurationDialog::popup_and_configure(const Ref<InputEvent> &p_event) {
  468. if (p_event.is_valid()) {
  469. _set_event(p_event);
  470. } else {
  471. // Clear Event
  472. _set_event(p_event);
  473. // Clear Checkbox Values
  474. for (int i = 0; i < MOD_MAX; i++) {
  475. mod_checkboxes[i]->set_pressed(false);
  476. }
  477. physical_key_checkbox->set_pressed(false);
  478. store_command_checkbox->set_pressed(true);
  479. _set_current_device(0);
  480. // Switch to "Listen" tab
  481. tab_container->set_current_tab(0);
  482. }
  483. popup_centered();
  484. }
  485. Ref<InputEvent> InputEventConfigurationDialog::get_event() const {
  486. return event;
  487. }
  488. void InputEventConfigurationDialog::set_allowed_input_types(int p_type_masks) {
  489. allowed_input_types = p_type_masks;
  490. }
  491. InputEventConfigurationDialog::InputEventConfigurationDialog() {
  492. allowed_input_types = INPUT_KEY | INPUT_MOUSE_BUTTON | INPUT_JOY_BUTTON | INPUT_JOY_MOTION;
  493. set_title("Event Configuration");
  494. set_min_size(Size2i(550 * EDSCALE, 0)); // Min width
  495. VBoxContainer *main_vbox = memnew(VBoxContainer);
  496. add_child(main_vbox);
  497. tab_container = memnew(TabContainer);
  498. tab_container->set_tab_align(TabContainer::TabAlign::ALIGN_LEFT);
  499. tab_container->set_use_hidden_tabs_for_min_size(true);
  500. tab_container->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  501. tab_container->connect("tab_selected", callable_mp(this, &InputEventConfigurationDialog::_tab_selected));
  502. main_vbox->add_child(tab_container);
  503. CenterContainer *cc = memnew(CenterContainer);
  504. cc->set_name("Listen for Input");
  505. event_as_text = memnew(Label);
  506. event_as_text->set_align(Label::ALIGN_CENTER);
  507. cc->add_child(event_as_text);
  508. tab_container->add_child(cc);
  509. // List of all input options to manually select from.
  510. VBoxContainer *manual_vbox = memnew(VBoxContainer);
  511. manual_vbox->set_name("Manual Selection");
  512. manual_vbox->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  513. tab_container->add_child(manual_vbox);
  514. input_list_search = memnew(LineEdit);
  515. input_list_search->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  516. input_list_search->set_placeholder(TTR("Filter Inputs"));
  517. input_list_search->set_clear_button_enabled(true);
  518. input_list_search->connect("text_changed", callable_mp(this, &InputEventConfigurationDialog::_search_term_updated));
  519. manual_vbox->add_child(input_list_search);
  520. input_list_tree = memnew(Tree);
  521. input_list_tree->set_custom_minimum_size(Size2(0, 100 * EDSCALE)); // Min height for tree
  522. input_list_tree->connect("item_selected", callable_mp(this, &InputEventConfigurationDialog::_input_list_item_selected));
  523. input_list_tree->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  524. manual_vbox->add_child(input_list_tree);
  525. input_list_tree->set_hide_root(true);
  526. input_list_tree->set_columns(1);
  527. _update_input_list();
  528. // Additional Options
  529. additional_options_container = memnew(VBoxContainer);
  530. additional_options_container->hide();
  531. Label *opts_label = memnew(Label);
  532. opts_label->set_text("Additional Options");
  533. additional_options_container->add_child(opts_label);
  534. // Device Selection
  535. device_container = memnew(HBoxContainer);
  536. device_container->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  537. Label *device_label = memnew(Label);
  538. device_label->set_text("Device:");
  539. device_container->add_child(device_label);
  540. device_id_option = memnew(OptionButton);
  541. device_id_option->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  542. device_container->add_child(device_id_option);
  543. for (int i = -1; i < 8; i++) {
  544. device_id_option->add_item(_get_device_string(i));
  545. }
  546. _set_current_device(0);
  547. device_container->hide();
  548. additional_options_container->add_child(device_container);
  549. // Modifier Selection
  550. mod_container = memnew(HBoxContainer);
  551. for (int i = 0; i < MOD_MAX; i++) {
  552. String name = mods[i];
  553. mod_checkboxes[i] = memnew(CheckBox);
  554. mod_checkboxes[i]->connect("toggled", callable_mp(this, &InputEventConfigurationDialog::_mod_toggled), varray(i));
  555. mod_checkboxes[i]->set_text(name);
  556. mod_container->add_child(mod_checkboxes[i]);
  557. }
  558. mod_container->add_child(memnew(VSeparator));
  559. store_command_checkbox = memnew(CheckBox);
  560. store_command_checkbox->connect("toggled", callable_mp(this, &InputEventConfigurationDialog::_store_command_toggled));
  561. store_command_checkbox->set_pressed(true);
  562. store_command_checkbox->set_text(TTR("Store Command"));
  563. #ifdef APPLE_STYLE_KEYS
  564. store_command_checkbox->set_tooltip(TTR("Toggles between serializing 'command' and 'meta'. Used for compatibility with Windows/Linux style keyboard."));
  565. #else
  566. store_command_checkbox->set_tooltip(TTR("Toggles between serializing 'command' and 'control'. Used for compatibility with Apple Style keyboards."));
  567. #endif
  568. mod_container->add_child(store_command_checkbox);
  569. mod_container->hide();
  570. additional_options_container->add_child(mod_container);
  571. // Physical Key Checkbox
  572. physical_key_checkbox = memnew(CheckBox);
  573. physical_key_checkbox->set_text(TTR("Use Physical Keycode"));
  574. physical_key_checkbox->set_tooltip(TTR("Stores the physical position of the key on the keyboard rather than the keys value. Used for compatibility with non-latin layouts."));
  575. physical_key_checkbox->connect("toggled", callable_mp(this, &InputEventConfigurationDialog::_physical_keycode_toggled));
  576. physical_key_checkbox->hide();
  577. additional_options_container->add_child(physical_key_checkbox);
  578. main_vbox->add_child(additional_options_container);
  579. // Default to first tab
  580. tab_container->set_current_tab(0);
  581. }
  582. /////////////////////////////////////////
  583. static bool _is_action_name_valid(const String &p_name) {
  584. const char32_t *cstr = p_name.get_data();
  585. for (int i = 0; cstr[i]; i++) {
  586. if (cstr[i] == '/' || cstr[i] == ':' || cstr[i] == '"' ||
  587. cstr[i] == '=' || cstr[i] == '\\' || cstr[i] < 32) {
  588. return false;
  589. }
  590. }
  591. return true;
  592. }
  593. void ActionMapEditor::_event_config_confirmed() {
  594. Ref<InputEvent> ev = event_config_dialog->get_event();
  595. Dictionary new_action = current_action.duplicate();
  596. Array events = new_action["events"];
  597. if (current_action_event_index == -1) {
  598. // Add new event
  599. events.push_back(ev);
  600. } else {
  601. // Edit existing event
  602. events[current_action_event_index] = ev;
  603. }
  604. new_action["events"] = events;
  605. emit_signal("action_edited", current_action_name, new_action);
  606. }
  607. void ActionMapEditor::_add_action_pressed() {
  608. _add_action(add_edit->get_text());
  609. }
  610. void ActionMapEditor::_add_action(const String &p_name) {
  611. if (!allow_editing_actions) {
  612. return;
  613. }
  614. if (p_name == "" || !_is_action_name_valid(p_name)) {
  615. show_message(TTR("Invalid action name. it cannot be.is_empty()() nor contain '/', ':', '=', '\\' or '\"'"));
  616. return;
  617. }
  618. add_edit->clear();
  619. emit_signal("action_added", p_name);
  620. }
  621. void ActionMapEditor::_action_edited() {
  622. if (!allow_editing_actions) {
  623. return;
  624. }
  625. TreeItem *ti = action_tree->get_edited();
  626. if (!ti) {
  627. return;
  628. }
  629. if (action_tree->get_selected_column() == 0) {
  630. // Name Edited
  631. String new_name = ti->get_text(0);
  632. String old_name = ti->get_meta("__name");
  633. if (new_name == old_name) {
  634. return;
  635. }
  636. if (new_name == "" || !_is_action_name_valid(new_name)) {
  637. ti->set_text(0, old_name);
  638. show_message(TTR("Invalid action name. it cannot be.is_empty()() nor contain '/', ':', '=', '\\' or '\"'"));
  639. return;
  640. }
  641. emit_signal("action_renamed", old_name, new_name);
  642. } else if (action_tree->get_selected_column() == 1) {
  643. // Deadzone Edited
  644. String name = ti->get_meta("__name");
  645. Dictionary old_action = ti->get_meta("__action");
  646. Dictionary new_action = old_action.duplicate();
  647. new_action["deadzone"] = ti->get_range(1);
  648. // Call deferred so that input can finish propagating through tree, allowing re-making of tree to occur.
  649. call_deferred("emit_signal", "action_edited", name, new_action);
  650. }
  651. }
  652. void ActionMapEditor::_tree_button_pressed(Object *p_item, int p_column, int p_id) {
  653. ItemButton option = (ItemButton)p_id;
  654. TreeItem *item = Object::cast_to<TreeItem>(p_item);
  655. if (!item) {
  656. return;
  657. }
  658. switch (option) {
  659. case ActionMapEditor::BUTTON_ADD_EVENT: {
  660. current_action = item->get_meta("__action");
  661. current_action_name = item->get_meta("__name");
  662. current_action_event_index = -1;
  663. event_config_dialog->popup_and_configure();
  664. } break;
  665. case ActionMapEditor::BUTTON_EDIT_EVENT: {
  666. // Action and Action name is located on the parent of the event.
  667. current_action = item->get_parent()->get_meta("__action");
  668. current_action_name = item->get_parent()->get_meta("__name");
  669. current_action_event_index = item->get_meta("__index");
  670. Ref<InputEvent> ie = item->get_meta("__event");
  671. if (ie.is_valid()) {
  672. event_config_dialog->popup_and_configure(ie);
  673. }
  674. } break;
  675. case ActionMapEditor::BUTTON_REMOVE_ACTION: {
  676. if (!allow_editing_actions) {
  677. break;
  678. }
  679. // Send removed action name
  680. String name = item->get_meta("__name");
  681. emit_signal("action_removed", name);
  682. } break;
  683. case ActionMapEditor::BUTTON_REMOVE_EVENT: {
  684. // Remove event and send updated action
  685. Dictionary action = item->get_parent()->get_meta("__action");
  686. String action_name = item->get_parent()->get_meta("__name");
  687. int event_index = item->get_meta("__index");
  688. Array events = action["events"];
  689. events.remove(event_index);
  690. action["events"] = events;
  691. emit_signal("action_edited", action_name, action);
  692. } break;
  693. default:
  694. break;
  695. }
  696. }
  697. void ActionMapEditor::_tree_item_activated() {
  698. TreeItem *item = action_tree->get_selected();
  699. if (!item || !item->has_meta("__event")) {
  700. return;
  701. }
  702. _tree_button_pressed(item, 2, BUTTON_EDIT_EVENT);
  703. }
  704. void ActionMapEditor::set_show_uneditable(bool p_show) {
  705. show_uneditable = p_show;
  706. show_uneditable_actions_checkbox->set_pressed(p_show);
  707. // Prevent unnecessary updates of action list when cache is.is_empty()().
  708. if (!actions_cache.is_empty()) {
  709. update_action_list();
  710. }
  711. }
  712. void ActionMapEditor::_search_term_updated(const String &) {
  713. update_action_list();
  714. }
  715. Variant ActionMapEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
  716. TreeItem *selected = action_tree->get_selected();
  717. if (!selected) {
  718. return Variant();
  719. }
  720. String name = selected->get_text(0);
  721. Label *label = memnew(Label(name));
  722. label->set_modulate(Color(1, 1, 1, 1.0f));
  723. action_tree->set_drag_preview(label);
  724. Dictionary drag_data;
  725. if (selected->has_meta("__action")) {
  726. drag_data["input_type"] = "action";
  727. }
  728. if (selected->has_meta("__event")) {
  729. drag_data["input_type"] = "event";
  730. }
  731. action_tree->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN);
  732. return drag_data;
  733. }
  734. bool ActionMapEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
  735. Dictionary d = p_data;
  736. if (!d.has("input_type")) {
  737. return false;
  738. }
  739. TreeItem *selected = action_tree->get_selected();
  740. TreeItem *item = action_tree->get_item_at_position(p_point);
  741. if (!selected || !item || item == selected) {
  742. return false;
  743. }
  744. // Don't allow moving an action in-between events.
  745. if (d["input_type"] == "action" && item->has_meta("__event")) {
  746. return false;
  747. }
  748. // Don't allow moving an event to a different action.
  749. if (d["input_type"] == "event" && item->get_parent() != selected->get_parent()) {
  750. return false;
  751. }
  752. return true;
  753. }
  754. void ActionMapEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
  755. if (!can_drop_data_fw(p_point, p_data, p_from)) {
  756. return;
  757. }
  758. TreeItem *selected = action_tree->get_selected();
  759. TreeItem *target = action_tree->get_item_at_position(p_point);
  760. bool drop_above = action_tree->get_drop_section_at_position(p_point) == -1;
  761. if (!target) {
  762. return;
  763. }
  764. Dictionary d = p_data;
  765. if (d["input_type"] == "action") {
  766. // Change action order.
  767. String relative_to = target->get_meta("__name");
  768. String action_name = selected->get_meta("__name");
  769. emit_signal("action_reordered", action_name, relative_to, drop_above);
  770. } else if (d["input_type"] == "event") {
  771. // Change event order
  772. int current_index = selected->get_meta("__index");
  773. int target_index = target->get_meta("__index");
  774. // Construct new events array.
  775. Dictionary new_action = selected->get_parent()->get_meta("__action");
  776. Array events = new_action["events"];
  777. Array new_events;
  778. // The following method was used to perform the array changes since `remove` followed by `insert` was not working properly at time of writing.
  779. // Loop thought existing events
  780. for (int i = 0; i < events.size(); i++) {
  781. // If you come across the current index, just skip it, as it has been moved.
  782. if (i == current_index) {
  783. continue;
  784. } else if (i == target_index) {
  785. // We are at the target index. If drop above, add selected event there first, then target, so moved event goes on top.
  786. if (drop_above) {
  787. new_events.push_back(events[current_index]);
  788. new_events.push_back(events[target_index]);
  789. } else {
  790. new_events.push_back(events[target_index]);
  791. new_events.push_back(events[current_index]);
  792. }
  793. } else {
  794. new_events.push_back(events[i]);
  795. }
  796. }
  797. new_action["events"] = new_events;
  798. emit_signal("action_edited", selected->get_parent()->get_meta("__name"), new_action);
  799. }
  800. }
  801. void ActionMapEditor::_notification(int p_what) {
  802. switch (p_what) {
  803. case NOTIFICATION_ENTER_TREE:
  804. case NOTIFICATION_THEME_CHANGED: {
  805. action_list_search->set_right_icon(get_theme_icon("Search", "EditorIcons"));
  806. } break;
  807. default:
  808. break;
  809. }
  810. }
  811. void ActionMapEditor::_bind_methods() {
  812. ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &ActionMapEditor::get_drag_data_fw);
  813. ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &ActionMapEditor::can_drop_data_fw);
  814. ClassDB::bind_method(D_METHOD("drop_data_fw"), &ActionMapEditor::drop_data_fw);
  815. ADD_SIGNAL(MethodInfo("action_added", PropertyInfo(Variant::STRING, "name")));
  816. ADD_SIGNAL(MethodInfo("action_edited", PropertyInfo(Variant::STRING, "name"), PropertyInfo(Variant::DICTIONARY, "new_action")));
  817. ADD_SIGNAL(MethodInfo("action_removed", PropertyInfo(Variant::STRING, "name")));
  818. ADD_SIGNAL(MethodInfo("action_renamed", PropertyInfo(Variant::STRING, "old_name"), PropertyInfo(Variant::STRING, "new_name")));
  819. ADD_SIGNAL(MethodInfo("action_reordered", PropertyInfo(Variant::STRING, "action_name"), PropertyInfo(Variant::STRING, "relative_to"), PropertyInfo(Variant::BOOL, "before")));
  820. }
  821. LineEdit *ActionMapEditor::get_search_box() const {
  822. return action_list_search;
  823. }
  824. InputEventConfigurationDialog *ActionMapEditor::get_configuration_dialog() {
  825. return event_config_dialog;
  826. }
  827. void ActionMapEditor::update_action_list(const Vector<ActionInfo> &p_action_infos) {
  828. if (!p_action_infos.is_empty()) {
  829. actions_cache = p_action_infos;
  830. }
  831. action_tree->clear();
  832. TreeItem *root = action_tree->create_item();
  833. int uneditable_count = 0;
  834. for (int i = 0; i < actions_cache.size(); i++) {
  835. ActionInfo action_info = actions_cache[i];
  836. if (!action_info.editable) {
  837. uneditable_count++;
  838. }
  839. String search_term = action_list_search->get_text();
  840. if (!search_term.is_empty() && action_info.name.findn(search_term) == -1) {
  841. continue;
  842. }
  843. if (!action_info.editable && !show_uneditable) {
  844. continue;
  845. }
  846. const Array events = action_info.action["events"];
  847. const Variant deadzone = action_info.action["deadzone"];
  848. // Update Tree...
  849. TreeItem *action_item = action_tree->create_item(root);
  850. action_item->set_meta("__action", action_info.action);
  851. action_item->set_meta("__name", action_info.name);
  852. // First Column - Action Name
  853. action_item->set_text(0, action_info.name);
  854. action_item->set_editable(0, action_info.editable);
  855. action_item->set_icon(0, action_info.icon);
  856. // Second Column - Deadzone
  857. action_item->set_editable(1, true);
  858. action_item->set_cell_mode(1, TreeItem::CELL_MODE_RANGE);
  859. action_item->set_range_config(1, 0.0, 1.0, 0.01);
  860. action_item->set_range(1, deadzone);
  861. // Third column - buttons
  862. action_item->add_button(2, action_tree->get_theme_icon("Add", "EditorIcons"), BUTTON_ADD_EVENT, false, TTR("Add Event"));
  863. action_item->add_button(2, action_tree->get_theme_icon("Remove", "EditorIcons"), BUTTON_REMOVE_ACTION, !action_info.editable, action_info.editable ? "Remove Action" : "Cannot Remove Action");
  864. action_item->set_custom_bg_color(0, action_tree->get_theme_color("prop_subsection", "Editor"));
  865. action_item->set_custom_bg_color(1, action_tree->get_theme_color("prop_subsection", "Editor"));
  866. for (int evnt_idx = 0; evnt_idx < events.size(); evnt_idx++) {
  867. Ref<InputEvent> event = events[evnt_idx];
  868. if (event.is_null()) {
  869. continue;
  870. }
  871. TreeItem *event_item = action_tree->create_item(action_item);
  872. // First Column - Text
  873. event_item->set_text(0, event_config_dialog->get_event_text(event)); // Need to us the special description for JoypadMotion here, so don't use as_text() directly.
  874. event_item->set_meta("__event", event);
  875. event_item->set_meta("__index", evnt_idx);
  876. // Third Column - Buttons
  877. event_item->add_button(2, action_tree->get_theme_icon("Edit", "EditorIcons"), BUTTON_EDIT_EVENT, false, TTR("Edit Event"));
  878. event_item->add_button(2, action_tree->get_theme_icon("Remove", "EditorIcons"), BUTTON_REMOVE_EVENT, false, TTR("Remove Event"));
  879. event_item->set_button_color(2, 0, Color(1, 1, 1, 0.75));
  880. event_item->set_button_color(2, 1, Color(1, 1, 1, 0.75));
  881. }
  882. }
  883. }
  884. void ActionMapEditor::show_message(const String &p_message) {
  885. message->set_text(p_message);
  886. message->popup_centered(Size2(300, 100) * EDSCALE);
  887. }
  888. void ActionMapEditor::set_allow_editing_actions(bool p_allow) {
  889. allow_editing_actions = p_allow;
  890. add_hbox->set_visible(p_allow);
  891. }
  892. void ActionMapEditor::set_toggle_editable_label(const String &p_label) {
  893. show_uneditable_actions_checkbox->set_text(p_label);
  894. }
  895. void ActionMapEditor::use_external_search_box(LineEdit *p_searchbox) {
  896. memdelete(action_list_search);
  897. action_list_search = p_searchbox;
  898. action_list_search->connect("text_changed", callable_mp(this, &ActionMapEditor::_search_term_updated));
  899. }
  900. ActionMapEditor::ActionMapEditor() {
  901. allow_editing_actions = true;
  902. show_uneditable = true;
  903. // Main Vbox Container
  904. VBoxContainer *main_vbox = memnew(VBoxContainer);
  905. main_vbox->set_anchors_and_offsets_preset(PRESET_WIDE);
  906. add_child(main_vbox);
  907. HBoxContainer *top_hbox = memnew(HBoxContainer);
  908. main_vbox->add_child(top_hbox);
  909. action_list_search = memnew(LineEdit);
  910. action_list_search->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  911. action_list_search->set_placeholder(TTR("Filter Actions"));
  912. action_list_search->set_clear_button_enabled(true);
  913. action_list_search->connect("text_changed", callable_mp(this, &ActionMapEditor::_search_term_updated));
  914. top_hbox->add_child(action_list_search);
  915. show_uneditable_actions_checkbox = memnew(CheckBox);
  916. show_uneditable_actions_checkbox->set_pressed(false);
  917. show_uneditable_actions_checkbox->set_text(TTR("Show Uneditable Actions"));
  918. show_uneditable_actions_checkbox->connect("toggled", callable_mp(this, &ActionMapEditor::set_show_uneditable));
  919. top_hbox->add_child(show_uneditable_actions_checkbox);
  920. // Adding Action line edit + button
  921. add_hbox = memnew(HBoxContainer);
  922. add_hbox->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  923. add_edit = memnew(LineEdit);
  924. add_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  925. add_edit->set_placeholder(TTR("Add New Action"));
  926. add_edit->set_clear_button_enabled(true);
  927. add_edit->connect("text_entered", callable_mp(this, &ActionMapEditor::_add_action));
  928. add_hbox->add_child(add_edit);
  929. Button *add_button = memnew(Button);
  930. add_button->set_text("Add");
  931. add_button->connect("pressed", callable_mp(this, &ActionMapEditor::_add_action_pressed));
  932. add_hbox->add_child(add_button);
  933. main_vbox->add_child(add_hbox);
  934. // Action Editor Tree
  935. action_tree = memnew(Tree);
  936. action_tree->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  937. action_tree->set_columns(3);
  938. action_tree->set_hide_root(true);
  939. action_tree->set_column_titles_visible(true);
  940. action_tree->set_column_title(0, TTR("Action"));
  941. action_tree->set_column_title(1, TTR("Deadzone"));
  942. action_tree->set_column_expand(1, false);
  943. action_tree->set_column_min_width(1, 80 * EDSCALE);
  944. action_tree->set_column_expand(2, false);
  945. action_tree->set_column_min_width(2, 50 * EDSCALE);
  946. action_tree->connect("item_edited", callable_mp(this, &ActionMapEditor::_action_edited));
  947. action_tree->connect("item_activated", callable_mp(this, &ActionMapEditor::_tree_item_activated));
  948. action_tree->connect("button_pressed", callable_mp(this, &ActionMapEditor::_tree_button_pressed));
  949. main_vbox->add_child(action_tree);
  950. action_tree->set_drag_forwarding(this);
  951. // Adding event dialog
  952. event_config_dialog = memnew(InputEventConfigurationDialog);
  953. event_config_dialog->connect("confirmed", callable_mp(this, &ActionMapEditor::_event_config_confirmed));
  954. add_child(event_config_dialog);
  955. message = memnew(AcceptDialog);
  956. add_child(message);
  957. }