action_map_editor.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  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/editor_settings.h"
  33. #include "editor/editor_string_names.h"
  34. #include "editor/event_listener_line_edit.h"
  35. #include "editor/input_event_configuration_dialog.h"
  36. #include "scene/gui/check_button.h"
  37. #include "scene/gui/tree.h"
  38. #include "scene/scene_string_names.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();
  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);
  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. if (!actions_cache.is_empty()) {
  298. update_action_list();
  299. }
  300. } break;
  301. }
  302. }
  303. void ActionMapEditor::_bind_methods() {
  304. ADD_SIGNAL(MethodInfo("action_added", PropertyInfo(Variant::STRING, "name")));
  305. ADD_SIGNAL(MethodInfo("action_edited", PropertyInfo(Variant::STRING, "name"), PropertyInfo(Variant::DICTIONARY, "new_action")));
  306. ADD_SIGNAL(MethodInfo("action_removed", PropertyInfo(Variant::STRING, "name")));
  307. ADD_SIGNAL(MethodInfo("action_renamed", PropertyInfo(Variant::STRING, "old_name"), PropertyInfo(Variant::STRING, "new_name")));
  308. ADD_SIGNAL(MethodInfo("action_reordered", PropertyInfo(Variant::STRING, "action_name"), PropertyInfo(Variant::STRING, "relative_to"), PropertyInfo(Variant::BOOL, "before")));
  309. ADD_SIGNAL(MethodInfo(SNAME("filter_focused")));
  310. ADD_SIGNAL(MethodInfo(SNAME("filter_unfocused")));
  311. }
  312. LineEdit *ActionMapEditor::get_search_box() const {
  313. return action_list_search;
  314. }
  315. InputEventConfigurationDialog *ActionMapEditor::get_configuration_dialog() {
  316. return event_config_dialog;
  317. }
  318. bool ActionMapEditor::_should_display_action(const String &p_name, const Array &p_events) const {
  319. const Ref<InputEvent> search_ev = action_list_search_by_event->get_event();
  320. bool event_match = true;
  321. if (search_ev.is_valid()) {
  322. event_match = false;
  323. for (int i = 0; i < p_events.size(); ++i) {
  324. const Ref<InputEvent> ev = p_events[i];
  325. if (ev.is_valid() && ev->is_match(search_ev, true)) {
  326. event_match = true;
  327. }
  328. }
  329. }
  330. return event_match && action_list_search->get_text().is_subsequence_ofn(p_name);
  331. }
  332. void ActionMapEditor::update_action_list(const Vector<ActionInfo> &p_action_infos) {
  333. if (!p_action_infos.is_empty()) {
  334. actions_cache = p_action_infos;
  335. }
  336. action_tree->clear();
  337. TreeItem *root = action_tree->create_item();
  338. for (int i = 0; i < actions_cache.size(); i++) {
  339. ActionInfo action_info = actions_cache[i];
  340. const Array events = action_info.action["events"];
  341. if (!_should_display_action(action_info.name, events)) {
  342. continue;
  343. }
  344. if (!action_info.editable && !show_builtin_actions) {
  345. continue;
  346. }
  347. const Variant deadzone = action_info.action["deadzone"];
  348. // Update Tree...
  349. TreeItem *action_item = action_tree->create_item(root);
  350. action_item->set_meta("__action", action_info.action);
  351. action_item->set_meta("__name", action_info.name);
  352. // First Column - Action Name
  353. action_item->set_text(0, action_info.name);
  354. action_item->set_editable(0, action_info.editable);
  355. action_item->set_icon(0, action_info.icon);
  356. // Second Column - Deadzone
  357. action_item->set_editable(1, true);
  358. action_item->set_cell_mode(1, TreeItem::CELL_MODE_RANGE);
  359. action_item->set_range_config(1, 0.0, 1.0, 0.01);
  360. action_item->set_range(1, deadzone);
  361. // Third column - buttons
  362. if (action_info.has_initial) {
  363. bool deadzone_eq = action_info.action_initial["deadzone"] == action_info.action["deadzone"];
  364. bool events_eq = Shortcut::is_event_array_equal(action_info.action_initial["events"], action_info.action["events"]);
  365. bool action_eq = deadzone_eq && events_eq;
  366. action_item->set_meta("__action_initial", action_info.action_initial);
  367. 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"));
  368. }
  369. action_item->add_button(2, action_tree->get_editor_theme_icon(SNAME("Add")), BUTTON_ADD_EVENT, false, TTR("Add Event"));
  370. 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"));
  371. action_item->set_custom_bg_color(0, action_tree->get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
  372. action_item->set_custom_bg_color(1, action_tree->get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
  373. for (int evnt_idx = 0; evnt_idx < events.size(); evnt_idx++) {
  374. Ref<InputEvent> event = events[evnt_idx];
  375. if (event.is_null()) {
  376. continue;
  377. }
  378. TreeItem *event_item = action_tree->create_item(action_item);
  379. // First Column - Text
  380. event_item->set_text(0, EventListenerLineEdit::get_event_text(event, true));
  381. event_item->set_meta("__event", event);
  382. event_item->set_meta("__index", evnt_idx);
  383. // First Column - Icon
  384. Ref<InputEventKey> k = event;
  385. if (k.is_valid()) {
  386. if (k->get_physical_keycode() == Key::NONE && k->get_keycode() == Key::NONE && k->get_key_label() != Key::NONE) {
  387. event_item->set_icon(0, action_tree->get_editor_theme_icon(SNAME("KeyboardLabel")));
  388. } else if (k->get_keycode() != Key::NONE) {
  389. event_item->set_icon(0, action_tree->get_editor_theme_icon(SNAME("Keyboard")));
  390. } else if (k->get_physical_keycode() != Key::NONE) {
  391. event_item->set_icon(0, action_tree->get_editor_theme_icon(SNAME("KeyboardPhysical")));
  392. } else {
  393. event_item->set_icon(0, action_tree->get_editor_theme_icon(SNAME("KeyboardError")));
  394. }
  395. }
  396. Ref<InputEventMouseButton> mb = event;
  397. if (mb.is_valid()) {
  398. event_item->set_icon(0, action_tree->get_editor_theme_icon(SNAME("Mouse")));
  399. }
  400. Ref<InputEventJoypadButton> jb = event;
  401. if (jb.is_valid()) {
  402. event_item->set_icon(0, action_tree->get_editor_theme_icon(SNAME("JoyButton")));
  403. }
  404. Ref<InputEventJoypadMotion> jm = event;
  405. if (jm.is_valid()) {
  406. event_item->set_icon(0, action_tree->get_editor_theme_icon(SNAME("JoyAxis")));
  407. }
  408. // Third Column - Buttons
  409. event_item->add_button(2, action_tree->get_editor_theme_icon(SNAME("Edit")), BUTTON_EDIT_EVENT, false, TTR("Edit Event"));
  410. event_item->add_button(2, action_tree->get_editor_theme_icon(SNAME("Remove")), BUTTON_REMOVE_EVENT, false, TTR("Remove Event"));
  411. event_item->set_button_color(2, 0, Color(1, 1, 1, 0.75));
  412. event_item->set_button_color(2, 1, Color(1, 1, 1, 0.75));
  413. }
  414. }
  415. }
  416. void ActionMapEditor::show_message(const String &p_message) {
  417. message->set_text(p_message);
  418. message->popup_centered();
  419. }
  420. void ActionMapEditor::use_external_search_box(LineEdit *p_searchbox) {
  421. memdelete(action_list_search);
  422. action_list_search = p_searchbox;
  423. action_list_search->connect("text_changed", callable_mp(this, &ActionMapEditor::_search_term_updated));
  424. }
  425. void ActionMapEditor::_on_filter_focused() {
  426. emit_signal(SNAME("filter_focused"));
  427. }
  428. void ActionMapEditor::_on_filter_unfocused() {
  429. emit_signal(SNAME("filter_unfocused"));
  430. }
  431. ActionMapEditor::ActionMapEditor() {
  432. // Main Vbox Container
  433. VBoxContainer *main_vbox = memnew(VBoxContainer);
  434. main_vbox->set_anchors_and_offsets_preset(PRESET_FULL_RECT);
  435. add_child(main_vbox);
  436. HBoxContainer *top_hbox = memnew(HBoxContainer);
  437. main_vbox->add_child(top_hbox);
  438. action_list_search = memnew(LineEdit);
  439. action_list_search->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  440. action_list_search->set_placeholder(TTR("Filter by name..."));
  441. action_list_search->set_clear_button_enabled(true);
  442. action_list_search->connect("text_changed", callable_mp(this, &ActionMapEditor::_search_term_updated));
  443. top_hbox->add_child(action_list_search);
  444. action_list_search_by_event = memnew(EventListenerLineEdit);
  445. action_list_search_by_event->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  446. action_list_search_by_event->set_stretch_ratio(0.75);
  447. action_list_search_by_event->connect("event_changed", callable_mp(this, &ActionMapEditor::_search_by_event));
  448. action_list_search_by_event->connect(SceneStringNames::get_singleton()->focus_entered, callable_mp(this, &ActionMapEditor::_on_filter_focused));
  449. action_list_search_by_event->connect(SceneStringNames::get_singleton()->focus_exited, callable_mp(this, &ActionMapEditor::_on_filter_unfocused));
  450. top_hbox->add_child(action_list_search_by_event);
  451. Button *clear_all_search = memnew(Button);
  452. clear_all_search->set_text(TTR("Clear All"));
  453. clear_all_search->connect("pressed", callable_mp(action_list_search_by_event, &EventListenerLineEdit::clear_event));
  454. clear_all_search->connect("pressed", callable_mp(action_list_search, &LineEdit::clear));
  455. top_hbox->add_child(clear_all_search);
  456. // Adding Action line edit + button
  457. add_hbox = memnew(HBoxContainer);
  458. add_hbox->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  459. add_edit = memnew(LineEdit);
  460. add_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  461. add_edit->set_placeholder(TTR("Add New Action"));
  462. add_edit->set_clear_button_enabled(true);
  463. add_edit->connect("text_changed", callable_mp(this, &ActionMapEditor::_add_edit_text_changed));
  464. add_edit->connect("text_submitted", callable_mp(this, &ActionMapEditor::_add_action));
  465. add_hbox->add_child(add_edit);
  466. add_button = memnew(Button);
  467. add_button->set_text(TTR("Add"));
  468. add_button->connect("pressed", callable_mp(this, &ActionMapEditor::_add_action_pressed));
  469. add_hbox->add_child(add_button);
  470. // Disable the button and set its tooltip.
  471. _add_edit_text_changed(add_edit->get_text());
  472. show_builtin_actions_checkbutton = memnew(CheckButton);
  473. show_builtin_actions_checkbutton->set_text(TTR("Show Built-in Actions"));
  474. show_builtin_actions_checkbutton->connect("toggled", callable_mp(this, &ActionMapEditor::set_show_builtin_actions));
  475. add_hbox->add_child(show_builtin_actions_checkbutton);
  476. show_builtin_actions = EditorSettings::get_singleton()->get_project_metadata("project_settings", "show_builtin_actions", false);
  477. show_builtin_actions_checkbutton->set_pressed(show_builtin_actions);
  478. main_vbox->add_child(add_hbox);
  479. // Action Editor Tree
  480. action_tree = memnew(Tree);
  481. action_tree->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  482. action_tree->set_columns(3);
  483. action_tree->set_hide_root(true);
  484. action_tree->set_column_titles_visible(true);
  485. action_tree->set_column_title(0, TTR("Action"));
  486. action_tree->set_column_clip_content(0, true);
  487. action_tree->set_column_title(1, TTR("Deadzone"));
  488. action_tree->set_column_expand(1, false);
  489. action_tree->set_column_custom_minimum_width(1, 80 * EDSCALE);
  490. action_tree->set_column_expand(2, false);
  491. action_tree->set_column_custom_minimum_width(2, 50 * EDSCALE);
  492. action_tree->connect("item_edited", callable_mp(this, &ActionMapEditor::_action_edited));
  493. action_tree->connect("item_activated", callable_mp(this, &ActionMapEditor::_tree_item_activated));
  494. action_tree->connect("button_clicked", callable_mp(this, &ActionMapEditor::_tree_button_pressed));
  495. main_vbox->add_child(action_tree);
  496. SET_DRAG_FORWARDING_GCD(action_tree, ActionMapEditor);
  497. // Adding event dialog
  498. event_config_dialog = memnew(InputEventConfigurationDialog);
  499. event_config_dialog->connect("confirmed", callable_mp(this, &ActionMapEditor::_event_config_confirmed));
  500. add_child(event_config_dialog);
  501. message = memnew(AcceptDialog);
  502. add_child(message);
  503. }