action_map_editor.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  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. action_tree->set_drag_preview(label);
  215. Dictionary drag_data;
  216. if (selected->has_meta("__action")) {
  217. drag_data["input_type"] = "action";
  218. }
  219. if (selected->has_meta("__event")) {
  220. drag_data["input_type"] = "event";
  221. }
  222. action_tree->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN);
  223. return drag_data;
  224. }
  225. bool ActionMapEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
  226. Dictionary d = p_data;
  227. if (!d.has("input_type")) {
  228. return false;
  229. }
  230. TreeItem *selected = action_tree->get_selected();
  231. TreeItem *item = action_tree->get_item_at_position(p_point);
  232. if (!selected || !item || item == selected) {
  233. return false;
  234. }
  235. // Don't allow moving an action in-between events.
  236. if (d["input_type"] == "action" && item->has_meta("__event")) {
  237. return false;
  238. }
  239. // Don't allow moving an event to a different action.
  240. if (d["input_type"] == "event" && item->get_parent() != selected->get_parent()) {
  241. return false;
  242. }
  243. return true;
  244. }
  245. void ActionMapEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
  246. if (!can_drop_data_fw(p_point, p_data, p_from)) {
  247. return;
  248. }
  249. TreeItem *selected = action_tree->get_selected();
  250. TreeItem *target = action_tree->get_item_at_position(p_point);
  251. bool drop_above = action_tree->get_drop_section_at_position(p_point) == -1;
  252. if (!target) {
  253. return;
  254. }
  255. Dictionary d = p_data;
  256. if (d["input_type"] == "action") {
  257. // Change action order.
  258. String relative_to = target->get_meta("__name");
  259. String action_name = selected->get_meta("__name");
  260. emit_signal(SNAME("action_reordered"), action_name, relative_to, drop_above);
  261. } else if (d["input_type"] == "event") {
  262. // Change event order
  263. int current_index = selected->get_meta("__index");
  264. int target_index = target->get_meta("__index");
  265. // Construct new events array.
  266. Dictionary new_action = selected->get_parent()->get_meta("__action");
  267. Array events = new_action["events"];
  268. Array new_events;
  269. // The following method was used to perform the array changes since `remove` followed by `insert` was not working properly at time of writing.
  270. // Loop thought existing events
  271. for (int i = 0; i < events.size(); i++) {
  272. // If you come across the current index, just skip it, as it has been moved.
  273. if (i == current_index) {
  274. continue;
  275. } else if (i == target_index) {
  276. // We are at the target index. If drop above, add selected event there first, then target, so moved event goes on top.
  277. if (drop_above) {
  278. new_events.push_back(events[current_index]);
  279. new_events.push_back(events[target_index]);
  280. } else {
  281. new_events.push_back(events[target_index]);
  282. new_events.push_back(events[current_index]);
  283. }
  284. } else {
  285. new_events.push_back(events[i]);
  286. }
  287. }
  288. new_action["events"] = new_events;
  289. emit_signal(SNAME("action_edited"), selected->get_parent()->get_meta("__name"), new_action);
  290. }
  291. }
  292. void ActionMapEditor::_notification(int p_what) {
  293. switch (p_what) {
  294. case NOTIFICATION_ENTER_TREE:
  295. case NOTIFICATION_THEME_CHANGED: {
  296. action_list_search->set_right_icon(get_editor_theme_icon(SNAME("Search")));
  297. add_button->set_icon(get_editor_theme_icon(SNAME("Add")));
  298. if (!actions_cache.is_empty()) {
  299. update_action_list();
  300. }
  301. } break;
  302. }
  303. }
  304. void ActionMapEditor::_bind_methods() {
  305. ADD_SIGNAL(MethodInfo("action_added", PropertyInfo(Variant::STRING, "name")));
  306. ADD_SIGNAL(MethodInfo("action_edited", PropertyInfo(Variant::STRING, "name"), PropertyInfo(Variant::DICTIONARY, "new_action")));
  307. ADD_SIGNAL(MethodInfo("action_removed", PropertyInfo(Variant::STRING, "name")));
  308. ADD_SIGNAL(MethodInfo("action_renamed", PropertyInfo(Variant::STRING, "old_name"), PropertyInfo(Variant::STRING, "new_name")));
  309. ADD_SIGNAL(MethodInfo("action_reordered", PropertyInfo(Variant::STRING, "action_name"), PropertyInfo(Variant::STRING, "relative_to"), PropertyInfo(Variant::BOOL, "before")));
  310. ADD_SIGNAL(MethodInfo(SNAME("filter_focused")));
  311. ADD_SIGNAL(MethodInfo(SNAME("filter_unfocused")));
  312. }
  313. LineEdit *ActionMapEditor::get_search_box() const {
  314. return action_list_search;
  315. }
  316. LineEdit *ActionMapEditor::get_path_box() const {
  317. return add_edit;
  318. }
  319. InputEventConfigurationDialog *ActionMapEditor::get_configuration_dialog() {
  320. return event_config_dialog;
  321. }
  322. bool ActionMapEditor::_should_display_action(const String &p_name, const Array &p_events) const {
  323. const Ref<InputEvent> search_ev = action_list_search_by_event->get_event();
  324. bool event_match = true;
  325. if (search_ev.is_valid()) {
  326. event_match = false;
  327. for (int i = 0; i < p_events.size(); ++i) {
  328. const Ref<InputEvent> ev = p_events[i];
  329. if (ev.is_valid() && ev->is_match(search_ev, true)) {
  330. event_match = true;
  331. }
  332. }
  333. }
  334. return event_match && action_list_search->get_text().is_subsequence_ofn(p_name);
  335. }
  336. void ActionMapEditor::update_action_list(const Vector<ActionInfo> &p_action_infos) {
  337. if (!p_action_infos.is_empty()) {
  338. actions_cache = p_action_infos;
  339. }
  340. action_tree->clear();
  341. TreeItem *root = action_tree->create_item();
  342. for (int i = 0; i < actions_cache.size(); i++) {
  343. ActionInfo action_info = actions_cache[i];
  344. const Array events = action_info.action["events"];
  345. if (!_should_display_action(action_info.name, events)) {
  346. continue;
  347. }
  348. if (!action_info.editable && !show_builtin_actions) {
  349. continue;
  350. }
  351. const Variant deadzone = action_info.action["deadzone"];
  352. // Update Tree...
  353. TreeItem *action_item = action_tree->create_item(root);
  354. action_item->set_meta("__action", action_info.action);
  355. action_item->set_meta("__name", action_info.name);
  356. // First Column - Action Name
  357. action_item->set_text(0, action_info.name);
  358. action_item->set_editable(0, action_info.editable);
  359. action_item->set_icon(0, action_info.icon);
  360. // Second Column - Deadzone
  361. action_item->set_editable(1, true);
  362. action_item->set_cell_mode(1, TreeItem::CELL_MODE_RANGE);
  363. action_item->set_range_config(1, 0.0, 1.0, 0.01);
  364. action_item->set_range(1, deadzone);
  365. // Third column - buttons
  366. if (action_info.has_initial) {
  367. bool deadzone_eq = action_info.action_initial["deadzone"] == action_info.action["deadzone"];
  368. bool events_eq = Shortcut::is_event_array_equal(action_info.action_initial["events"], action_info.action["events"]);
  369. bool action_eq = deadzone_eq && events_eq;
  370. action_item->set_meta("__action_initial", action_info.action_initial);
  371. 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"));
  372. }
  373. action_item->add_button(2, action_tree->get_editor_theme_icon(SNAME("Add")), BUTTON_ADD_EVENT, false, TTR("Add Event"));
  374. 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"));
  375. action_item->set_custom_bg_color(0, action_tree->get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
  376. action_item->set_custom_bg_color(1, action_tree->get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
  377. for (int evnt_idx = 0; evnt_idx < events.size(); evnt_idx++) {
  378. Ref<InputEvent> event = events[evnt_idx];
  379. if (event.is_null()) {
  380. continue;
  381. }
  382. TreeItem *event_item = action_tree->create_item(action_item);
  383. // First Column - Text
  384. event_item->set_text(0, EventListenerLineEdit::get_event_text(event, true));
  385. event_item->set_meta("__event", event);
  386. event_item->set_meta("__index", evnt_idx);
  387. // First Column - Icon
  388. Ref<InputEventKey> k = event;
  389. if (k.is_valid()) {
  390. if (k->get_physical_keycode() == Key::NONE && k->get_keycode() == Key::NONE && k->get_key_label() != Key::NONE) {
  391. event_item->set_icon(0, action_tree->get_editor_theme_icon(SNAME("KeyboardLabel")));
  392. } else if (k->get_keycode() != Key::NONE) {
  393. event_item->set_icon(0, action_tree->get_editor_theme_icon(SNAME("Keyboard")));
  394. } else if (k->get_physical_keycode() != Key::NONE) {
  395. event_item->set_icon(0, action_tree->get_editor_theme_icon(SNAME("KeyboardPhysical")));
  396. } else {
  397. event_item->set_icon(0, action_tree->get_editor_theme_icon(SNAME("KeyboardError")));
  398. }
  399. }
  400. Ref<InputEventMouseButton> mb = event;
  401. if (mb.is_valid()) {
  402. event_item->set_icon(0, action_tree->get_editor_theme_icon(SNAME("Mouse")));
  403. }
  404. Ref<InputEventJoypadButton> jb = event;
  405. if (jb.is_valid()) {
  406. event_item->set_icon(0, action_tree->get_editor_theme_icon(SNAME("JoyButton")));
  407. }
  408. Ref<InputEventJoypadMotion> jm = event;
  409. if (jm.is_valid()) {
  410. event_item->set_icon(0, action_tree->get_editor_theme_icon(SNAME("JoyAxis")));
  411. }
  412. // Third Column - Buttons
  413. event_item->add_button(2, action_tree->get_editor_theme_icon(SNAME("Edit")), BUTTON_EDIT_EVENT, false, TTR("Edit Event"));
  414. event_item->add_button(2, action_tree->get_editor_theme_icon(SNAME("Remove")), BUTTON_REMOVE_EVENT, false, TTR("Remove Event"));
  415. event_item->set_button_color(2, 0, Color(1, 1, 1, 0.75));
  416. event_item->set_button_color(2, 1, Color(1, 1, 1, 0.75));
  417. }
  418. }
  419. }
  420. void ActionMapEditor::show_message(const String &p_message) {
  421. message->set_text(p_message);
  422. message->popup_centered();
  423. }
  424. void ActionMapEditor::use_external_search_box(LineEdit *p_searchbox) {
  425. memdelete(action_list_search);
  426. action_list_search = p_searchbox;
  427. action_list_search->connect("text_changed", callable_mp(this, &ActionMapEditor::_search_term_updated));
  428. }
  429. void ActionMapEditor::_on_filter_focused() {
  430. emit_signal(SNAME("filter_focused"));
  431. }
  432. void ActionMapEditor::_on_filter_unfocused() {
  433. emit_signal(SNAME("filter_unfocused"));
  434. }
  435. ActionMapEditor::ActionMapEditor() {
  436. // Main Vbox Container
  437. VBoxContainer *main_vbox = memnew(VBoxContainer);
  438. main_vbox->set_anchors_and_offsets_preset(PRESET_FULL_RECT);
  439. add_child(main_vbox);
  440. HBoxContainer *top_hbox = memnew(HBoxContainer);
  441. main_vbox->add_child(top_hbox);
  442. action_list_search = memnew(LineEdit);
  443. action_list_search->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  444. action_list_search->set_placeholder(TTR("Filter by Name"));
  445. action_list_search->set_clear_button_enabled(true);
  446. action_list_search->connect("text_changed", callable_mp(this, &ActionMapEditor::_search_term_updated));
  447. top_hbox->add_child(action_list_search);
  448. action_list_search_by_event = memnew(EventListenerLineEdit);
  449. action_list_search_by_event->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  450. action_list_search_by_event->set_stretch_ratio(0.75);
  451. action_list_search_by_event->connect("event_changed", callable_mp(this, &ActionMapEditor::_search_by_event));
  452. action_list_search_by_event->connect(SceneStringName(focus_entered), callable_mp(this, &ActionMapEditor::_on_filter_focused));
  453. action_list_search_by_event->connect(SceneStringName(focus_exited), callable_mp(this, &ActionMapEditor::_on_filter_unfocused));
  454. top_hbox->add_child(action_list_search_by_event);
  455. Button *clear_all_search = memnew(Button);
  456. clear_all_search->set_text(TTR("Clear All"));
  457. clear_all_search->connect(SceneStringName(pressed), callable_mp(action_list_search_by_event, &EventListenerLineEdit::clear_event));
  458. clear_all_search->connect(SceneStringName(pressed), callable_mp(action_list_search, &LineEdit::clear));
  459. top_hbox->add_child(clear_all_search);
  460. // Adding Action line edit + button
  461. add_hbox = memnew(HBoxContainer);
  462. add_hbox->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  463. add_edit = memnew(LineEdit);
  464. add_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  465. add_edit->set_placeholder(TTR("Add New Action"));
  466. add_edit->set_clear_button_enabled(true);
  467. add_edit->connect("text_changed", callable_mp(this, &ActionMapEditor::_add_edit_text_changed));
  468. add_edit->connect("text_submitted", callable_mp(this, &ActionMapEditor::_add_action));
  469. add_hbox->add_child(add_edit);
  470. add_button = memnew(Button);
  471. add_button->set_text(TTR("Add"));
  472. add_button->connect(SceneStringName(pressed), callable_mp(this, &ActionMapEditor::_add_action_pressed));
  473. add_hbox->add_child(add_button);
  474. // Disable the button and set its tooltip.
  475. _add_edit_text_changed(add_edit->get_text());
  476. add_hbox->add_child(memnew(VSeparator));
  477. show_builtin_actions_checkbutton = memnew(CheckButton);
  478. show_builtin_actions_checkbutton->set_text(TTR("Show Built-in Actions"));
  479. show_builtin_actions_checkbutton->connect("toggled", callable_mp(this, &ActionMapEditor::set_show_builtin_actions));
  480. add_hbox->add_child(show_builtin_actions_checkbutton);
  481. show_builtin_actions = EditorSettings::get_singleton()->get_project_metadata("project_settings", "show_builtin_actions", false);
  482. show_builtin_actions_checkbutton->set_pressed(show_builtin_actions);
  483. main_vbox->add_child(add_hbox);
  484. // Action Editor Tree
  485. action_tree = memnew(Tree);
  486. action_tree->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  487. action_tree->set_columns(3);
  488. action_tree->set_hide_root(true);
  489. action_tree->set_column_titles_visible(true);
  490. action_tree->set_column_title(0, TTR("Action"));
  491. action_tree->set_column_clip_content(0, true);
  492. action_tree->set_column_title(1, TTR("Deadzone"));
  493. action_tree->set_column_expand(1, false);
  494. action_tree->set_column_custom_minimum_width(1, 80 * EDSCALE);
  495. action_tree->set_column_expand(2, false);
  496. action_tree->set_column_custom_minimum_width(2, 50 * EDSCALE);
  497. action_tree->connect("item_edited", callable_mp(this, &ActionMapEditor::_action_edited));
  498. action_tree->connect("item_activated", callable_mp(this, &ActionMapEditor::_tree_item_activated));
  499. action_tree->connect("button_clicked", callable_mp(this, &ActionMapEditor::_tree_button_pressed));
  500. main_vbox->add_child(action_tree);
  501. SET_DRAG_FORWARDING_GCD(action_tree, ActionMapEditor);
  502. // Adding event dialog
  503. event_config_dialog = memnew(InputEventConfigurationDialog);
  504. event_config_dialog->connect("confirmed", callable_mp(this, &ActionMapEditor::_event_config_confirmed));
  505. add_child(event_config_dialog);
  506. message = memnew(AcceptDialog);
  507. add_child(message);
  508. }