action_map_editor.cpp 22 KB

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