action_map_editor.cpp 23 KB

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