action_map_editor.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. /**************************************************************************/
  2. /* action_map_editor.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 "action_map_editor.h"
  31. #include "editor/editor_string_names.h"
  32. #include "editor/settings/editor_event_search_bar.h"
  33. #include "editor/settings/editor_settings.h"
  34. #include "editor/settings/event_listener_line_edit.h"
  35. #include "editor/settings/input_event_configuration_dialog.h"
  36. #include "editor/themes/editor_scale.h"
  37. #include "scene/gui/check_button.h"
  38. #include "scene/gui/separator.h"
  39. #include "scene/gui/tree.h"
  40. static bool _is_action_name_valid(const String &p_name) {
  41. const char32_t *cstr = p_name.get_data();
  42. for (int i = 0; cstr[i]; i++) {
  43. if (cstr[i] == '/' || cstr[i] == ':' || cstr[i] == '"' ||
  44. cstr[i] == '=' || cstr[i] == '\\' || cstr[i] < 32) {
  45. return false;
  46. }
  47. }
  48. return true;
  49. }
  50. void ActionMapEditor::_event_config_confirmed() {
  51. Ref<InputEvent> ev = event_config_dialog->get_event();
  52. Dictionary new_action = current_action.duplicate();
  53. Array events = new_action["events"].duplicate();
  54. if (current_action_event_index == -1) {
  55. // Add new event
  56. events.push_back(ev);
  57. } else {
  58. // Edit existing event
  59. events[current_action_event_index] = ev;
  60. }
  61. new_action["events"] = events;
  62. emit_signal(SNAME("action_edited"), current_action_name, new_action);
  63. }
  64. void ActionMapEditor::_add_action_pressed() {
  65. _add_action(add_edit->get_text());
  66. }
  67. String ActionMapEditor::_check_new_action_name(const String &p_name) {
  68. if (p_name.is_empty() || !_is_action_name_valid(p_name)) {
  69. return TTR("Invalid action name. It cannot be empty nor contain '/', ':', '=', '\\' or '\"'");
  70. }
  71. if (_has_action(p_name)) {
  72. return vformat(TTR("An action with the name '%s' already exists."), p_name);
  73. }
  74. return "";
  75. }
  76. void ActionMapEditor::_add_edit_text_changed(const String &p_name) {
  77. const String error = _check_new_action_name(p_name);
  78. add_button->set_tooltip_text(error);
  79. add_button->set_disabled(!error.is_empty());
  80. }
  81. bool ActionMapEditor::_has_action(const String &p_name) const {
  82. for (const ActionInfo &action_info : actions_cache) {
  83. if (p_name == action_info.name) {
  84. return true;
  85. }
  86. }
  87. return false;
  88. }
  89. void ActionMapEditor::_add_action(const String &p_name) {
  90. String error = _check_new_action_name(p_name);
  91. if (!error.is_empty()) {
  92. show_message(error);
  93. return;
  94. }
  95. add_edit->clear();
  96. emit_signal(SNAME("action_added"), p_name);
  97. }
  98. void ActionMapEditor::_action_edited() {
  99. TreeItem *ti = action_tree->get_edited();
  100. if (!ti) {
  101. return;
  102. }
  103. if (action_tree->get_selected_column() == 0) {
  104. // Name Edited
  105. String new_name = ti->get_text(0);
  106. String old_name = ti->get_meta("__name");
  107. if (new_name == old_name) {
  108. return;
  109. }
  110. if (new_name.is_empty() || !_is_action_name_valid(new_name)) {
  111. ti->set_text(0, old_name);
  112. show_message(TTR("Invalid action name. It cannot be empty nor contain '/', ':', '=', '\\' or '\"'"));
  113. return;
  114. }
  115. if (_has_action(new_name)) {
  116. ti->set_text(0, old_name);
  117. show_message(vformat(TTR("An action with the name '%s' already exists."), new_name));
  118. return;
  119. }
  120. emit_signal(SNAME("action_renamed"), old_name, new_name);
  121. } else if (action_tree->get_selected_column() == 1) {
  122. // Deadzone Edited
  123. String name = ti->get_meta("__name");
  124. Dictionary old_action = ti->get_meta("__action");
  125. Dictionary new_action = old_action.duplicate();
  126. new_action["deadzone"] = ti->get_range(1);
  127. // Call deferred so that input can finish propagating through tree, allowing re-making of tree to occur.
  128. call_deferred(SNAME("emit_signal"), "action_edited", name, new_action);
  129. }
  130. }
  131. void ActionMapEditor::_tree_button_pressed(Object *p_item, int p_column, int p_id, MouseButton p_button) {
  132. if (p_button != MouseButton::LEFT) {
  133. return;
  134. }
  135. ItemButton option = (ItemButton)p_id;
  136. TreeItem *item = Object::cast_to<TreeItem>(p_item);
  137. if (!item) {
  138. return;
  139. }
  140. switch (option) {
  141. case ActionMapEditor::BUTTON_ADD_EVENT: {
  142. current_action = item->get_meta("__action");
  143. current_action_name = item->get_meta("__name");
  144. current_action_event_index = -1;
  145. event_config_dialog->popup_and_configure(Ref<InputEvent>(), current_action_name);
  146. } break;
  147. case ActionMapEditor::BUTTON_EDIT_EVENT: {
  148. // Action and Action name is located on the parent of the event.
  149. current_action = item->get_parent()->get_meta("__action");
  150. current_action_name = item->get_parent()->get_meta("__name");
  151. current_action_event_index = item->get_meta("__index");
  152. Ref<InputEvent> ie = item->get_meta("__event");
  153. if (ie.is_valid()) {
  154. event_config_dialog->popup_and_configure(ie, current_action_name);
  155. }
  156. } break;
  157. case ActionMapEditor::BUTTON_REMOVE_ACTION: {
  158. // Send removed action name
  159. String name = item->get_meta("__name");
  160. emit_signal(SNAME("action_removed"), name);
  161. } break;
  162. case ActionMapEditor::BUTTON_REMOVE_EVENT: {
  163. // Remove event and send updated action
  164. Dictionary action = item->get_parent()->get_meta("__action").duplicate();
  165. String action_name = item->get_parent()->get_meta("__name");
  166. int event_index = item->get_meta("__index");
  167. Array events = action["events"].duplicate();
  168. events.remove_at(event_index);
  169. action["events"] = events;
  170. emit_signal(SNAME("action_edited"), action_name, action);
  171. } break;
  172. case ActionMapEditor::BUTTON_REVERT_ACTION: {
  173. ERR_FAIL_COND_MSG(!item->has_meta("__action_initial"), "Tree Item for action which can be reverted is expected to have meta value with initial value of action.");
  174. Dictionary action = item->get_meta("__action_initial").duplicate();
  175. String action_name = item->get_meta("__name");
  176. emit_signal(SNAME("action_edited"), action_name, action);
  177. } break;
  178. default:
  179. break;
  180. }
  181. }
  182. void ActionMapEditor::_tree_item_activated() {
  183. TreeItem *item = action_tree->get_selected();
  184. if (!item || !item->has_meta("__event")) {
  185. return;
  186. }
  187. _tree_button_pressed(item, 2, BUTTON_EDIT_EVENT, MouseButton::LEFT);
  188. }
  189. void ActionMapEditor::_set_show_builtin_actions(bool p_show) {
  190. show_builtin_actions = p_show;
  191. EditorSettings::get_singleton()->set_project_metadata("project_settings", "show_builtin_actions", show_builtin_actions);
  192. // Prevent unnecessary updates of action list when cache is empty.
  193. if (!actions_cache.is_empty()) {
  194. update_action_list();
  195. }
  196. }
  197. void ActionMapEditor::_on_search_bar_value_changed() {
  198. if (action_list_search_bar->is_searching()) {
  199. show_builtin_actions_checkbutton->set_pressed_no_signal(true);
  200. show_builtin_actions_checkbutton->set_disabled(true);
  201. show_builtin_actions_checkbutton->set_tooltip_text(TTRC("Built-in actions are always shown when searching."));
  202. } else {
  203. show_builtin_actions_checkbutton->set_pressed_no_signal(show_builtin_actions);
  204. show_builtin_actions_checkbutton->set_disabled(false);
  205. show_builtin_actions_checkbutton->set_tooltip_text(String());
  206. }
  207. update_action_list();
  208. }
  209. Variant ActionMapEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
  210. TreeItem *selected = action_tree->get_selected();
  211. if (!selected) {
  212. return Variant();
  213. }
  214. String name = selected->get_text(0);
  215. Label *label = memnew(Label(name));
  216. label->set_theme_type_variation("HeaderSmall");
  217. label->set_modulate(Color(1, 1, 1, 1.0f));
  218. label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  219. action_tree->set_drag_preview(label);
  220. get_viewport()->gui_set_drag_description(vformat(RTR("Action %s"), name));
  221. Dictionary drag_data;
  222. if (selected->has_meta("__action")) {
  223. drag_data["input_type"] = "action";
  224. }
  225. if (selected->has_meta("__event")) {
  226. drag_data["input_type"] = "event";
  227. }
  228. drag_data["source"] = selected->get_instance_id();
  229. action_tree->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN);
  230. return drag_data;
  231. }
  232. bool ActionMapEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
  233. Dictionary d = p_data;
  234. if (!d.has("input_type")) {
  235. return false;
  236. }
  237. TreeItem *source = Object::cast_to<TreeItem>(ObjectDB::get_instance(d["source"].operator ObjectID()));
  238. TreeItem *selected = action_tree->get_selected();
  239. TreeItem *item = (p_point == Vector2(Math::INF, Math::INF)) ? selected : action_tree->get_item_at_position(p_point);
  240. if (!selected || !item || item == source) {
  241. return false;
  242. }
  243. // Don't allow moving an action in-between events.
  244. if (d["input_type"] == "action" && item->has_meta("__event")) {
  245. return false;
  246. }
  247. // Don't allow moving an event to a different action.
  248. if (d["input_type"] == "event" && item->get_parent() != selected->get_parent()) {
  249. return false;
  250. }
  251. return true;
  252. }
  253. void ActionMapEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
  254. if (!can_drop_data_fw(p_point, p_data, p_from)) {
  255. return;
  256. }
  257. TreeItem *selected = action_tree->get_selected();
  258. TreeItem *target = (p_point == Vector2(Math::INF, Math::INF)) ? selected : action_tree->get_item_at_position(p_point);
  259. if (!target) {
  260. return;
  261. }
  262. bool drop_above = ((p_point == Vector2(Math::INF, Math::INF)) ? action_tree->get_drop_section_at_position(action_tree->get_item_rect(target).position) : action_tree->get_drop_section_at_position(p_point)) == -1;
  263. Dictionary d = p_data;
  264. if (d["input_type"] == "action") {
  265. // Change action order.
  266. String relative_to = target->get_meta("__name");
  267. String action_name = selected->get_meta("__name");
  268. emit_signal(SNAME("action_reordered"), action_name, relative_to, drop_above);
  269. } else if (d["input_type"] == "event") {
  270. // Change event order
  271. int current_index = selected->get_meta("__index");
  272. int target_index = target->get_meta("__index");
  273. // Construct new events array.
  274. Dictionary new_action = selected->get_parent()->get_meta("__action");
  275. Array events = new_action["events"];
  276. Array new_events;
  277. // The following method was used to perform the array changes since `remove` followed by `insert` was not working properly at time of writing.
  278. // Loop thought existing events
  279. for (int i = 0; i < events.size(); i++) {
  280. // If you come across the current index, just skip it, as it has been moved.
  281. if (i == current_index) {
  282. continue;
  283. } else if (i == target_index) {
  284. // We are at the target index. If drop above, add selected event there first, then target, so moved event goes on top.
  285. if (drop_above) {
  286. new_events.push_back(events[current_index]);
  287. new_events.push_back(events[target_index]);
  288. } else {
  289. new_events.push_back(events[target_index]);
  290. new_events.push_back(events[current_index]);
  291. }
  292. } else {
  293. new_events.push_back(events[i]);
  294. }
  295. }
  296. new_action["events"] = new_events;
  297. emit_signal(SNAME("action_edited"), selected->get_parent()->get_meta("__name"), new_action);
  298. }
  299. }
  300. void ActionMapEditor::_notification(int p_what) {
  301. switch (p_what) {
  302. case NOTIFICATION_TRANSLATION_CHANGED: {
  303. if (!actions_cache.is_empty()) {
  304. update_action_list();
  305. }
  306. if (!add_button->get_tooltip_text().is_empty()) {
  307. _add_edit_text_changed(add_edit->get_text());
  308. }
  309. } break;
  310. case NOTIFICATION_THEME_CHANGED: {
  311. add_button->set_button_icon(get_editor_theme_icon(SNAME("Add")));
  312. if (!actions_cache.is_empty()) {
  313. update_action_list();
  314. }
  315. } break;
  316. }
  317. }
  318. void ActionMapEditor::_bind_methods() {
  319. ADD_SIGNAL(MethodInfo("action_added", PropertyInfo(Variant::STRING, "name")));
  320. ADD_SIGNAL(MethodInfo("action_edited", PropertyInfo(Variant::STRING, "name"), PropertyInfo(Variant::DICTIONARY, "new_action")));
  321. ADD_SIGNAL(MethodInfo("action_removed", PropertyInfo(Variant::STRING, "name")));
  322. ADD_SIGNAL(MethodInfo("action_renamed", PropertyInfo(Variant::STRING, "old_name"), PropertyInfo(Variant::STRING, "new_name")));
  323. ADD_SIGNAL(MethodInfo("action_reordered", PropertyInfo(Variant::STRING, "action_name"), PropertyInfo(Variant::STRING, "relative_to"), PropertyInfo(Variant::BOOL, "before")));
  324. }
  325. LineEdit *ActionMapEditor::get_search_box() const {
  326. return action_list_search_bar->get_name_search_box();
  327. }
  328. LineEdit *ActionMapEditor::get_path_box() const {
  329. return add_edit;
  330. }
  331. InputEventConfigurationDialog *ActionMapEditor::get_configuration_dialog() {
  332. return event_config_dialog;
  333. }
  334. bool ActionMapEditor::_should_display_action(const String &p_name, const Array &p_events) const {
  335. const Ref<InputEvent> search_ev = action_list_search_bar->get_event();
  336. bool event_match = true;
  337. if (search_ev.is_valid()) {
  338. event_match = false;
  339. for (int i = 0; i < p_events.size(); ++i) {
  340. const Ref<InputEvent> ev = p_events[i];
  341. if (ev.is_valid() && ev->is_match(search_ev, true)) {
  342. event_match = true;
  343. }
  344. }
  345. }
  346. return event_match && action_list_search_bar->get_name().is_subsequence_ofn(p_name);
  347. }
  348. void ActionMapEditor::update_action_list(const Vector<ActionInfo> &p_action_infos) {
  349. if (!p_action_infos.is_empty()) {
  350. actions_cache = p_action_infos;
  351. }
  352. action_tree->clear();
  353. TreeItem *root = action_tree->create_item();
  354. for (const ActionInfo &action_info : actions_cache) {
  355. const Array events = action_info.action["events"];
  356. if (!_should_display_action(action_info.name, events)) {
  357. continue;
  358. }
  359. if (!action_info.editable && !action_list_search_bar->is_searching() && !show_builtin_actions) {
  360. continue;
  361. }
  362. const Variant deadzone = action_info.action["deadzone"];
  363. // Update Tree...
  364. TreeItem *action_item = action_tree->create_item(root);
  365. ERR_FAIL_NULL(action_item);
  366. action_item->set_meta("__action", action_info.action);
  367. action_item->set_meta("__name", action_info.name);
  368. // First Column - Action Name
  369. action_item->set_auto_translate_mode(0, AUTO_TRANSLATE_MODE_DISABLED);
  370. action_item->set_text(0, action_info.name);
  371. action_item->set_editable(0, action_info.editable);
  372. action_item->set_icon(0, action_info.icon);
  373. // Second Column - Deadzone
  374. action_item->set_editable(1, true);
  375. action_item->set_cell_mode(1, TreeItem::CELL_MODE_RANGE);
  376. action_item->set_range_config(1, 0.0, 1.0, 0.01);
  377. action_item->set_range(1, deadzone);
  378. // Third column - buttons
  379. if (action_info.has_initial) {
  380. bool deadzone_eq = action_info.action_initial["deadzone"] == action_info.action["deadzone"];
  381. bool events_eq = Shortcut::is_event_array_equal(action_info.action_initial["events"], action_info.action["events"]);
  382. bool action_eq = deadzone_eq && events_eq;
  383. action_item->set_meta("__action_initial", action_info.action_initial);
  384. action_item->add_button(2, get_editor_theme_icon(SNAME("ReloadSmall")), BUTTON_REVERT_ACTION, action_eq, action_eq ? TTRC("Cannot Revert - Action is same as initial") : TTRC("Revert Action"));
  385. }
  386. action_item->add_button(2, get_editor_theme_icon(SNAME("Add")), BUTTON_ADD_EVENT, false, TTRC("Add Event"));
  387. action_item->add_button(2, get_editor_theme_icon(SNAME("Remove")), BUTTON_REMOVE_ACTION, !action_info.editable, action_info.editable ? TTRC("Remove Action") : TTRC("Cannot Remove Action"));
  388. action_item->set_custom_bg_color(0, get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
  389. action_item->set_custom_bg_color(1, get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
  390. for (int evnt_idx = 0; evnt_idx < events.size(); evnt_idx++) {
  391. Ref<InputEvent> event = events[evnt_idx];
  392. if (event.is_null()) {
  393. continue;
  394. }
  395. TreeItem *event_item = action_tree->create_item(action_item);
  396. // First Column - Text
  397. event_item->set_auto_translate_mode(0, AUTO_TRANSLATE_MODE_DISABLED);
  398. event_item->set_text(0, EventListenerLineEdit::get_event_text(event, true));
  399. event_item->set_meta("__event", event);
  400. event_item->set_meta("__index", evnt_idx);
  401. // First Column - Icon
  402. Ref<InputEventKey> k = event;
  403. if (k.is_valid()) {
  404. if (k->get_physical_keycode() == Key::NONE && k->get_keycode() == Key::NONE && k->get_key_label() != Key::NONE) {
  405. event_item->set_icon(0, get_editor_theme_icon(SNAME("KeyboardLabel")));
  406. } else if (k->get_keycode() != Key::NONE) {
  407. event_item->set_icon(0, get_editor_theme_icon(SNAME("Keyboard")));
  408. } else if (k->get_physical_keycode() != Key::NONE) {
  409. event_item->set_icon(0, get_editor_theme_icon(SNAME("KeyboardPhysical")));
  410. } else {
  411. event_item->set_icon(0, get_editor_theme_icon(SNAME("KeyboardError")));
  412. }
  413. }
  414. Ref<InputEventMouseButton> mb = event;
  415. if (mb.is_valid()) {
  416. event_item->set_icon(0, get_editor_theme_icon(SNAME("Mouse")));
  417. }
  418. Ref<InputEventJoypadButton> jb = event;
  419. if (jb.is_valid()) {
  420. event_item->set_icon(0, get_editor_theme_icon(SNAME("JoyButton")));
  421. }
  422. Ref<InputEventJoypadMotion> jm = event;
  423. if (jm.is_valid()) {
  424. event_item->set_icon(0, get_editor_theme_icon(SNAME("JoyAxis")));
  425. }
  426. // Third Column - Buttons
  427. event_item->add_button(2, get_editor_theme_icon(SNAME("Edit")), BUTTON_EDIT_EVENT, false, TTRC("Edit Event"), TTRC("Edit Event"));
  428. event_item->add_button(2, get_editor_theme_icon(SNAME("Remove")), BUTTON_REMOVE_EVENT, false, TTRC("Remove Event"), TTRC("Remove Event"));
  429. event_item->set_button_color(2, 0, Color(1, 1, 1, 0.75));
  430. event_item->set_button_color(2, 1, Color(1, 1, 1, 0.75));
  431. }
  432. }
  433. }
  434. void ActionMapEditor::show_message(const String &p_message) {
  435. message->set_text(p_message);
  436. message->popup_centered();
  437. }
  438. ActionMapEditor::ActionMapEditor() {
  439. // Main Vbox Container
  440. VBoxContainer *main_vbox = memnew(VBoxContainer);
  441. main_vbox->set_anchors_and_offsets_preset(PRESET_FULL_RECT);
  442. add_child(main_vbox);
  443. action_list_search_bar = memnew(EditorEventSearchBar);
  444. action_list_search_bar->connect(SceneStringName(value_changed), callable_mp(this, &ActionMapEditor::_on_search_bar_value_changed));
  445. main_vbox->add_child(action_list_search_bar);
  446. // Adding Action line edit + button
  447. add_hbox = memnew(HBoxContainer);
  448. add_hbox->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  449. add_edit = memnew(LineEdit);
  450. add_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  451. add_edit->set_placeholder(TTRC("Add New Action"));
  452. add_edit->set_accessibility_name(TTRC("Add New Action"));
  453. add_edit->set_clear_button_enabled(true);
  454. add_edit->set_keep_editing_on_text_submit(true);
  455. add_edit->connect(SceneStringName(text_changed), callable_mp(this, &ActionMapEditor::_add_edit_text_changed));
  456. add_edit->connect(SceneStringName(text_submitted), callable_mp(this, &ActionMapEditor::_add_action));
  457. add_hbox->add_child(add_edit);
  458. add_button = memnew(Button);
  459. add_button->set_text(TTRC("Add"));
  460. add_button->connect(SceneStringName(pressed), callable_mp(this, &ActionMapEditor::_add_action_pressed));
  461. add_hbox->add_child(add_button);
  462. // Disable the button and set its tooltip.
  463. _add_edit_text_changed(add_edit->get_text());
  464. add_hbox->add_child(memnew(VSeparator));
  465. show_builtin_actions_checkbutton = memnew(CheckButton);
  466. show_builtin_actions_checkbutton->set_text(TTRC("Show Built-in Actions"));
  467. show_builtin_actions_checkbutton->connect(SceneStringName(toggled), callable_mp(this, &ActionMapEditor::_set_show_builtin_actions));
  468. add_hbox->add_child(show_builtin_actions_checkbutton);
  469. show_builtin_actions = EditorSettings::get_singleton()->get_project_metadata("project_settings", "show_builtin_actions", false);
  470. show_builtin_actions_checkbutton->set_pressed_no_signal(show_builtin_actions);
  471. main_vbox->add_child(add_hbox);
  472. // Action Editor Tree
  473. action_tree = memnew(Tree);
  474. action_tree->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  475. action_tree->set_accessibility_name(TTRC("Action Map"));
  476. action_tree->set_columns(3);
  477. action_tree->set_hide_root(true);
  478. action_tree->set_column_titles_visible(true);
  479. action_tree->set_column_title(0, TTRC("Action"));
  480. action_tree->set_column_clip_content(0, true);
  481. action_tree->set_column_title(1, TTRC("Deadzone"));
  482. action_tree->set_column_expand(1, false);
  483. action_tree->set_column_custom_minimum_width(1, 80 * EDSCALE);
  484. action_tree->set_column_expand(2, false);
  485. action_tree->set_column_custom_minimum_width(2, 50 * EDSCALE);
  486. action_tree->connect("item_edited", callable_mp(this, &ActionMapEditor::_action_edited), CONNECT_DEFERRED);
  487. action_tree->connect("item_activated", callable_mp(this, &ActionMapEditor::_tree_item_activated));
  488. action_tree->connect("button_clicked", callable_mp(this, &ActionMapEditor::_tree_button_pressed));
  489. main_vbox->add_child(action_tree);
  490. SET_DRAG_FORWARDING_GCD(action_tree, ActionMapEditor);
  491. // Adding event dialog
  492. event_config_dialog = memnew(InputEventConfigurationDialog);
  493. event_config_dialog->connect(SceneStringName(confirmed), callable_mp(this, &ActionMapEditor::_event_config_confirmed));
  494. add_child(event_config_dialog);
  495. message = memnew(AcceptDialog);
  496. add_child(message);
  497. }