editor_settings_dialog.cpp 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137
  1. /**************************************************************************/
  2. /* editor_settings_dialog.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_settings_dialog.h"
  31. #include "core/config/project_settings.h"
  32. #include "core/input/input_map.h"
  33. #include "core/os/keyboard.h"
  34. #include "editor/debugger/editor_debugger_node.h"
  35. #include "editor/editor_inspector.h"
  36. #include "editor/editor_log.h"
  37. #include "editor/editor_node.h"
  38. #include "editor/editor_property_name_processor.h"
  39. #include "editor/editor_sectioned_inspector.h"
  40. #include "editor/editor_settings.h"
  41. #include "editor/editor_string_names.h"
  42. #include "editor/editor_undo_redo_manager.h"
  43. #include "editor/event_listener_line_edit.h"
  44. #include "editor/input_event_configuration_dialog.h"
  45. #include "editor/plugins/node_3d_editor_plugin.h"
  46. #include "editor/project_settings_editor.h"
  47. #include "editor/themes/editor_scale.h"
  48. #include "editor/themes/editor_theme_manager.h"
  49. #include "scene/gui/check_button.h"
  50. #include "scene/gui/panel_container.h"
  51. #include "scene/gui/tab_container.h"
  52. #include "scene/gui/texture_rect.h"
  53. #include "scene/gui/tree.h"
  54. void EditorSettingsDialog::ok_pressed() {
  55. if (!EditorSettings::get_singleton()) {
  56. return;
  57. }
  58. _settings_save();
  59. }
  60. void EditorSettingsDialog::_settings_changed() {
  61. if (is_visible()) {
  62. timer->start();
  63. }
  64. }
  65. void EditorSettingsDialog::_settings_property_edited(const String &p_name) {
  66. String full_name = inspector->get_full_item_path(p_name);
  67. // Set theme presets to Custom when controlled settings change.
  68. if (full_name == "interface/theme/accent_color" || full_name == "interface/theme/base_color" || full_name == "interface/theme/contrast" || full_name == "interface/theme/draw_extra_borders") {
  69. EditorSettings::get_singleton()->set_manually("interface/theme/preset", "Custom");
  70. } else if (full_name == "interface/theme/base_spacing" || full_name == "interface/theme/additional_spacing") {
  71. EditorSettings::get_singleton()->set_manually("interface/theme/spacing_preset", "Custom");
  72. } else if (full_name.begins_with("text_editor/theme/highlighting")) {
  73. EditorSettings::get_singleton()->set_manually("text_editor/theme/color_theme", "Custom");
  74. } else if (full_name.begins_with("editors/visual_editors/connection_colors") || full_name.begins_with("editors/visual_editors/category_colors")) {
  75. EditorSettings::get_singleton()->set_manually("editors/visual_editors/color_theme", "Custom");
  76. } else if (full_name == "editors/3d/navigation/orbit_mouse_button" || full_name == "editors/3d/navigation/pan_mouse_button" || full_name == "editors/3d/navigation/zoom_mouse_button" || full_name == "editors/3d/navigation/emulate_3_button_mouse") {
  77. EditorSettings::get_singleton()->set_manually("editors/3d/navigation/navigation_scheme", (int)Node3DEditorViewport::NAVIGATION_CUSTOM);
  78. } else if (full_name == "editors/3d/navigation/navigation_scheme") {
  79. update_navigation_preset();
  80. }
  81. }
  82. void EditorSettingsDialog::update_navigation_preset() {
  83. Node3DEditorViewport::NavigationScheme nav_scheme = (Node3DEditorViewport::NavigationScheme)EDITOR_GET("editors/3d/navigation/navigation_scheme").operator int();
  84. Node3DEditorViewport::ViewportNavMouseButton set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
  85. Node3DEditorViewport::ViewportNavMouseButton set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
  86. Node3DEditorViewport::ViewportNavMouseButton set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
  87. bool set_3_button_mouse = false;
  88. Ref<InputEventKey> orbit_mod_key_1;
  89. Ref<InputEventKey> orbit_mod_key_2;
  90. Ref<InputEventKey> pan_mod_key_1;
  91. Ref<InputEventKey> pan_mod_key_2;
  92. Ref<InputEventKey> zoom_mod_key_1;
  93. Ref<InputEventKey> zoom_mod_key_2;
  94. bool set_preset = false;
  95. if (nav_scheme == Node3DEditorViewport::NAVIGATION_GODOT) {
  96. set_preset = true;
  97. set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;
  98. set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;
  99. set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;
  100. set_3_button_mouse = false;
  101. orbit_mod_key_1 = InputEventKey::create_reference(Key::NONE);
  102. orbit_mod_key_2 = InputEventKey::create_reference(Key::NONE);
  103. pan_mod_key_1 = InputEventKey::create_reference(Key::SHIFT);
  104. pan_mod_key_2 = InputEventKey::create_reference(Key::NONE);
  105. zoom_mod_key_1 = InputEventKey::create_reference(Key::CTRL);
  106. zoom_mod_key_2 = InputEventKey::create_reference(Key::NONE);
  107. } else if (nav_scheme == Node3DEditorViewport::NAVIGATION_MAYA) {
  108. set_preset = true;
  109. set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
  110. set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;
  111. set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_RIGHT_MOUSE;
  112. set_3_button_mouse = false;
  113. orbit_mod_key_1 = InputEventKey::create_reference(Key::ALT);
  114. orbit_mod_key_2 = InputEventKey::create_reference(Key::NONE);
  115. pan_mod_key_1 = InputEventKey::create_reference(Key::NONE);
  116. pan_mod_key_2 = InputEventKey::create_reference(Key::NONE);
  117. zoom_mod_key_1 = InputEventKey::create_reference(Key::ALT);
  118. zoom_mod_key_2 = InputEventKey::create_reference(Key::NONE);
  119. } else if (nav_scheme == Node3DEditorViewport::NAVIGATION_MODO) {
  120. set_preset = true;
  121. set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
  122. set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
  123. set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
  124. set_3_button_mouse = false;
  125. orbit_mod_key_1 = InputEventKey::create_reference(Key::ALT);
  126. orbit_mod_key_2 = InputEventKey::create_reference(Key::NONE);
  127. pan_mod_key_1 = InputEventKey::create_reference(Key::SHIFT);
  128. pan_mod_key_2 = InputEventKey::create_reference(Key::ALT);
  129. zoom_mod_key_1 = InputEventKey::create_reference(Key::ALT);
  130. zoom_mod_key_2 = InputEventKey::create_reference(Key::CTRL);
  131. } else if (nav_scheme == Node3DEditorViewport::NAVIGATION_TABLET) {
  132. set_preset = true;
  133. set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;
  134. set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;
  135. set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;
  136. set_3_button_mouse = true;
  137. orbit_mod_key_1 = InputEventKey::create_reference(Key::ALT);
  138. orbit_mod_key_2 = InputEventKey::create_reference(Key::NONE);
  139. pan_mod_key_1 = InputEventKey::create_reference(Key::SHIFT);
  140. pan_mod_key_2 = InputEventKey::create_reference(Key::NONE);
  141. zoom_mod_key_1 = InputEventKey::create_reference(Key::CTRL);
  142. zoom_mod_key_2 = InputEventKey::create_reference(Key::NONE);
  143. }
  144. // Set settings to the desired preset values.
  145. if (set_preset) {
  146. EditorSettings::get_singleton()->set_manually("editors/3d/navigation/orbit_mouse_button", (int)set_orbit_mouse_button);
  147. EditorSettings::get_singleton()->set_manually("editors/3d/navigation/pan_mouse_button", (int)set_pan_mouse_button);
  148. EditorSettings::get_singleton()->set_manually("editors/3d/navigation/zoom_mouse_button", (int)set_zoom_mouse_button);
  149. EditorSettings::get_singleton()->set_manually("editors/3d/navigation/emulate_3_button_mouse", set_3_button_mouse);
  150. _set_shortcut_input("spatial_editor/viewport_orbit_modifier_1", orbit_mod_key_1);
  151. _set_shortcut_input("spatial_editor/viewport_orbit_modifier_2", orbit_mod_key_2);
  152. _set_shortcut_input("spatial_editor/viewport_pan_modifier_1", pan_mod_key_1);
  153. _set_shortcut_input("spatial_editor/viewport_pan_modifier_2", pan_mod_key_2);
  154. _set_shortcut_input("spatial_editor/viewport_zoom_modifier_1", zoom_mod_key_1);
  155. _set_shortcut_input("spatial_editor/viewport_zoom_modifier_2", zoom_mod_key_2);
  156. }
  157. }
  158. void EditorSettingsDialog::_set_shortcut_input(const String &p_name, Ref<InputEventKey> &p_event) {
  159. Array sc_events;
  160. if (p_event->get_keycode() != Key::NONE) {
  161. sc_events.push_back((Variant)p_event);
  162. }
  163. Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_name);
  164. sc->set_events(sc_events);
  165. }
  166. void EditorSettingsDialog::_settings_save() {
  167. if (!timer->is_stopped()) {
  168. timer->stop();
  169. }
  170. EditorSettings::get_singleton()->notify_changes();
  171. EditorSettings::get_singleton()->save();
  172. }
  173. void EditorSettingsDialog::cancel_pressed() {
  174. if (!EditorSettings::get_singleton()) {
  175. return;
  176. }
  177. EditorSettings::get_singleton()->notify_changes();
  178. }
  179. void EditorSettingsDialog::popup_edit_settings() {
  180. if (!EditorSettings::get_singleton()) {
  181. return;
  182. }
  183. EditorSettings::get_singleton()->list_text_editor_themes(); // make sure we have an up to date list of themes
  184. _update_dynamic_property_hints();
  185. inspector->edit(EditorSettings::get_singleton());
  186. inspector->get_inspector()->update_tree();
  187. _update_shortcuts();
  188. set_process_shortcut_input(true);
  189. // Restore valid window bounds or pop up at default size.
  190. Rect2 saved_size = EditorSettings::get_singleton()->get_project_metadata("dialog_bounds", "editor_settings", Rect2());
  191. if (saved_size != Rect2()) {
  192. popup(saved_size);
  193. } else {
  194. popup_centered_clamped(Size2(900, 700) * EDSCALE, 0.8);
  195. }
  196. _focus_current_search_box();
  197. }
  198. void EditorSettingsDialog::_filter_shortcuts(const String &) {
  199. _update_shortcuts();
  200. }
  201. void EditorSettingsDialog::_filter_shortcuts_by_event(const Ref<InputEvent> &p_event) {
  202. if (p_event.is_null() || (p_event->is_pressed() && !p_event->is_echo())) {
  203. _update_shortcuts();
  204. }
  205. }
  206. void EditorSettingsDialog::_undo_redo_callback(void *p_self, const String &p_name) {
  207. EditorNode::get_log()->add_message(p_name, EditorLog::MSG_TYPE_EDITOR);
  208. }
  209. void EditorSettingsDialog::_notification(int p_what) {
  210. switch (p_what) {
  211. case NOTIFICATION_VISIBILITY_CHANGED: {
  212. if (!is_visible()) {
  213. EditorSettings::get_singleton()->set_project_metadata("dialog_bounds", "editor_settings", Rect2(get_position(), get_size()));
  214. set_process_shortcut_input(false);
  215. }
  216. } break;
  217. case NOTIFICATION_READY: {
  218. EditorSettingsPropertyWrapper::restart_request_callback = callable_mp(this, &EditorSettingsDialog::_editor_restart_request);
  219. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  220. undo_redo->get_or_create_history(EditorUndoRedoManager::GLOBAL_HISTORY).undo_redo->set_method_notify_callback(EditorDebuggerNode::_methods_changed, nullptr);
  221. undo_redo->get_or_create_history(EditorUndoRedoManager::GLOBAL_HISTORY).undo_redo->set_property_notify_callback(EditorDebuggerNode::_properties_changed, nullptr);
  222. undo_redo->get_or_create_history(EditorUndoRedoManager::GLOBAL_HISTORY).undo_redo->set_commit_notify_callback(_undo_redo_callback, this);
  223. } break;
  224. case NOTIFICATION_ENTER_TREE: {
  225. _update_icons();
  226. } break;
  227. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  228. if (EditorThemeManager::is_generated_theme_outdated()) {
  229. _update_icons();
  230. }
  231. bool update_shortcuts_tab =
  232. EditorSettings::get_singleton()->check_changed_settings_in_group("shortcuts") ||
  233. EditorSettings::get_singleton()->check_changed_settings_in_group("builtin_action_overrides");
  234. if (update_shortcuts_tab) {
  235. _update_shortcuts();
  236. }
  237. if (EditorSettings::get_singleton()->check_changed_settings_in_group("editors/3d/navigation")) {
  238. // Shortcuts may have changed, so dynamic hint values must update.
  239. _update_dynamic_property_hints();
  240. inspector->get_inspector()->update_tree();
  241. }
  242. if (EditorSettings::get_singleton()->check_changed_settings_in_group("interface/editor/localize_settings")) {
  243. inspector->update_category_list();
  244. }
  245. } break;
  246. }
  247. }
  248. void EditorSettingsDialog::shortcut_input(const Ref<InputEvent> &p_event) {
  249. const Ref<InputEventKey> k = p_event;
  250. if (k.is_valid() && k->is_pressed()) {
  251. bool handled = false;
  252. if (ED_IS_SHORTCUT("ui_undo", p_event)) {
  253. EditorNode::get_singleton()->undo();
  254. handled = true;
  255. }
  256. if (ED_IS_SHORTCUT("ui_redo", p_event)) {
  257. EditorNode::get_singleton()->redo();
  258. handled = true;
  259. }
  260. if (k->is_match(InputEventKey::create_reference(KeyModifierMask::CMD_OR_CTRL | Key::F))) {
  261. _focus_current_search_box();
  262. handled = true;
  263. }
  264. if (handled) {
  265. set_input_as_handled();
  266. }
  267. }
  268. }
  269. void EditorSettingsDialog::_update_icons() {
  270. search_box->set_right_icon(shortcuts->get_editor_theme_icon(SNAME("Search")));
  271. search_box->set_clear_button_enabled(true);
  272. shortcut_search_box->set_right_icon(shortcuts->get_editor_theme_icon(SNAME("Search")));
  273. shortcut_search_box->set_clear_button_enabled(true);
  274. restart_close_button->set_button_icon(shortcuts->get_editor_theme_icon(SNAME("Close")));
  275. restart_container->add_theme_style_override(SceneStringName(panel), shortcuts->get_theme_stylebox(SceneStringName(panel), SNAME("Tree")));
  276. restart_icon->set_texture(shortcuts->get_editor_theme_icon(SNAME("StatusWarning")));
  277. restart_label->add_theme_color_override(SceneStringName(font_color), shortcuts->get_theme_color(SNAME("warning_color"), EditorStringName(Editor)));
  278. }
  279. void EditorSettingsDialog::_event_config_confirmed() {
  280. Ref<InputEventKey> k = shortcut_editor->get_event();
  281. if (k.is_null()) {
  282. return;
  283. }
  284. if (current_event_index == -1) {
  285. // Add new event
  286. current_events.push_back(k);
  287. } else {
  288. // Edit existing event
  289. current_events[current_event_index] = k;
  290. }
  291. if (is_editing_action) {
  292. _update_builtin_action(current_edited_identifier, current_events);
  293. } else {
  294. _update_shortcut_events(current_edited_identifier, current_events);
  295. }
  296. }
  297. void EditorSettingsDialog::_update_builtin_action(const String &p_name, const Array &p_events) {
  298. Array old_input_array = EditorSettings::get_singleton()->get_builtin_action_overrides(p_name);
  299. if (old_input_array.is_empty()) {
  300. List<Ref<InputEvent>> defaults = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied()[current_edited_identifier];
  301. old_input_array = _event_list_to_array_helper(defaults);
  302. }
  303. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  304. undo_redo->create_action(vformat(TTR("Edit Built-in Action: %s"), p_name));
  305. undo_redo->add_do_method(EditorSettings::get_singleton(), "mark_setting_changed", "builtin_action_overrides");
  306. undo_redo->add_undo_method(EditorSettings::get_singleton(), "mark_setting_changed", "builtin_action_overrides");
  307. undo_redo->add_do_method(EditorSettings::get_singleton(), "set_builtin_action_override", p_name, p_events);
  308. undo_redo->add_undo_method(EditorSettings::get_singleton(), "set_builtin_action_override", p_name, old_input_array);
  309. undo_redo->add_do_method(this, "_update_shortcuts");
  310. undo_redo->add_undo_method(this, "_update_shortcuts");
  311. undo_redo->add_do_method(this, "_settings_changed");
  312. undo_redo->add_undo_method(this, "_settings_changed");
  313. undo_redo->commit_action();
  314. }
  315. void EditorSettingsDialog::_update_shortcut_events(const String &p_path, const Array &p_events) {
  316. Ref<Shortcut> current_sc = EditorSettings::get_singleton()->get_shortcut(p_path);
  317. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  318. undo_redo->create_action(vformat(TTR("Edit Shortcut: %s"), p_path), UndoRedo::MERGE_DISABLE, EditorSettings::get_singleton());
  319. // History must be fixed based on the EditorSettings object because current_sc would
  320. // incorrectly make this action use the scene history.
  321. undo_redo->force_fixed_history();
  322. undo_redo->add_do_method(current_sc.ptr(), "set_events", p_events);
  323. undo_redo->add_undo_method(current_sc.ptr(), "set_events", current_sc->get_events());
  324. undo_redo->add_do_method(EditorSettings::get_singleton(), "mark_setting_changed", "shortcuts");
  325. undo_redo->add_undo_method(EditorSettings::get_singleton(), "mark_setting_changed", "shortcuts");
  326. undo_redo->add_do_method(this, "_update_shortcuts");
  327. undo_redo->add_undo_method(this, "_update_shortcuts");
  328. undo_redo->add_do_method(this, "_settings_changed");
  329. undo_redo->add_undo_method(this, "_settings_changed");
  330. undo_redo->commit_action();
  331. bool path_is_orbit_mod = p_path == "spatial_editor/viewport_orbit_modifier_1" || p_path == "spatial_editor/viewport_orbit_modifier_2";
  332. bool path_is_pan_mod = p_path == "spatial_editor/viewport_pan_modifier_1" || p_path == "spatial_editor/viewport_pan_modifier_2";
  333. bool path_is_zoom_mod = p_path == "spatial_editor/viewport_zoom_modifier_1" || p_path == "spatial_editor/viewport_zoom_modifier_2";
  334. if (path_is_orbit_mod || path_is_pan_mod || path_is_zoom_mod) {
  335. EditorSettings::get_singleton()->set_manually("editors/3d/navigation/navigation_scheme", (int)Node3DEditorViewport::NAVIGATION_CUSTOM);
  336. }
  337. }
  338. Array EditorSettingsDialog::_event_list_to_array_helper(const List<Ref<InputEvent>> &p_events) {
  339. Array events;
  340. // Convert the list to an array, and only keep key events as this is for the editor.
  341. for (const List<Ref<InputEvent>>::Element *E = p_events.front(); E; E = E->next()) {
  342. Ref<InputEventKey> k = E->get();
  343. if (k.is_valid()) {
  344. events.append(E->get());
  345. }
  346. }
  347. return events;
  348. }
  349. TreeItem *EditorSettingsDialog::_create_shortcut_treeitem(TreeItem *p_parent, const String &p_shortcut_identifier, const String &p_display, Array &p_events, bool p_allow_revert, bool p_is_action, bool p_is_collapsed) {
  350. TreeItem *shortcut_item = shortcuts->create_item(p_parent);
  351. shortcut_item->set_collapsed(p_is_collapsed);
  352. shortcut_item->set_text(0, p_display);
  353. Ref<InputEvent> primary = p_events.size() > 0 ? Ref<InputEvent>(p_events[0]) : Ref<InputEvent>();
  354. Ref<InputEvent> secondary = p_events.size() > 1 ? Ref<InputEvent>(p_events[1]) : Ref<InputEvent>();
  355. String sc_text = TTRC("None");
  356. if (primary.is_valid()) {
  357. sc_text = primary->as_text();
  358. if (secondary.is_valid()) {
  359. sc_text += ", " + secondary->as_text();
  360. if (p_events.size() > 2) {
  361. sc_text += " (+" + itos(p_events.size() - 2) + ")";
  362. }
  363. }
  364. shortcut_item->set_auto_translate_mode(1, AUTO_TRANSLATE_MODE_DISABLED);
  365. }
  366. shortcut_item->set_text(1, sc_text);
  367. if (sc_text == "None") {
  368. // Fade out unassigned shortcut labels for easier visual grepping.
  369. shortcut_item->set_custom_color(1, shortcuts->get_theme_color(SceneStringName(font_color), SNAME("Label")) * Color(1, 1, 1, 0.5));
  370. }
  371. if (p_allow_revert) {
  372. shortcut_item->add_button(1, shortcuts->get_editor_theme_icon(SNAME("Reload")), SHORTCUT_REVERT);
  373. }
  374. shortcut_item->add_button(1, shortcuts->get_editor_theme_icon(SNAME("Add")), SHORTCUT_ADD);
  375. shortcut_item->add_button(1, shortcuts->get_editor_theme_icon(SNAME("Close")), SHORTCUT_ERASE);
  376. shortcut_item->set_meta("is_action", p_is_action);
  377. shortcut_item->set_meta("type", "shortcut");
  378. shortcut_item->set_meta("shortcut_identifier", p_shortcut_identifier);
  379. shortcut_item->set_meta("events", p_events);
  380. // Shortcut Input Events
  381. for (int i = 0; i < p_events.size(); i++) {
  382. Ref<InputEvent> ie = p_events[i];
  383. if (ie.is_null()) {
  384. continue;
  385. }
  386. TreeItem *event_item = shortcuts->create_item(shortcut_item);
  387. // TRANSLATORS: This is the label for the main input event of a shortcut.
  388. event_item->set_text(0, shortcut_item->get_child_count() == 1 ? TTRC("Primary") : "");
  389. event_item->set_text(1, ie->as_text());
  390. event_item->set_auto_translate_mode(1, AUTO_TRANSLATE_MODE_DISABLED);
  391. event_item->add_button(1, shortcuts->get_editor_theme_icon(SNAME("Edit")), SHORTCUT_EDIT);
  392. event_item->add_button(1, shortcuts->get_editor_theme_icon(SNAME("Close")), SHORTCUT_ERASE);
  393. event_item->set_custom_bg_color(0, shortcuts->get_theme_color(SNAME("dark_color_3"), EditorStringName(Editor)));
  394. event_item->set_custom_bg_color(1, shortcuts->get_theme_color(SNAME("dark_color_3"), EditorStringName(Editor)));
  395. event_item->set_meta("is_action", p_is_action);
  396. event_item->set_meta("type", "event");
  397. event_item->set_meta("event_index", i);
  398. }
  399. return shortcut_item;
  400. }
  401. bool EditorSettingsDialog::_should_display_shortcut(const String &p_name, const Array &p_events, bool p_match_localized_name) const {
  402. const Ref<InputEvent> search_ev = shortcut_search_by_event->get_event();
  403. if (search_ev.is_valid()) {
  404. bool event_match = false;
  405. for (int i = 0; i < p_events.size(); ++i) {
  406. const Ref<InputEvent> ev = p_events[i];
  407. if (ev.is_valid() && ev->is_match(search_ev, true)) {
  408. event_match = true;
  409. break;
  410. }
  411. }
  412. if (!event_match) {
  413. return false;
  414. }
  415. }
  416. const String &search_text = shortcut_search_box->get_text();
  417. if (search_text.is_empty()) {
  418. return true;
  419. }
  420. if (search_text.is_subsequence_ofn(p_name)) {
  421. return true;
  422. }
  423. if (p_match_localized_name && search_text.is_subsequence_ofn(TTR(p_name))) {
  424. return true;
  425. }
  426. return false;
  427. }
  428. void EditorSettingsDialog::_update_shortcuts() {
  429. // Before clearing the tree, take note of which categories are collapsed so that this state can be maintained when the tree is repopulated.
  430. HashMap<String, bool> collapsed;
  431. if (shortcuts->get_root() && shortcuts->get_root()->get_first_child()) {
  432. TreeItem *ti = shortcuts->get_root()->get_first_child();
  433. while (ti) {
  434. // Not all items have valid or unique text in the first column - so if it has an identifier, use that, as it should be unique.
  435. if (ti->get_first_child() && ti->has_meta("shortcut_identifier")) {
  436. collapsed[ti->get_meta("shortcut_identifier")] = ti->is_collapsed();
  437. } else {
  438. collapsed[ti->get_text(0)] = ti->is_collapsed();
  439. }
  440. // Try go down tree
  441. TreeItem *ti_next = ti->get_first_child();
  442. // Try go to the next node via in-order traversal
  443. if (!ti_next) {
  444. ti_next = ti;
  445. while (ti_next && !ti_next->get_next()) {
  446. ti_next = ti_next->get_parent();
  447. }
  448. if (ti_next) {
  449. ti_next = ti_next->get_next();
  450. }
  451. }
  452. ti = ti_next;
  453. }
  454. }
  455. shortcuts->clear();
  456. TreeItem *root = shortcuts->create_item();
  457. HashMap<String, TreeItem *> sections;
  458. // Set up section for Common/Built-in actions
  459. TreeItem *common_section = shortcuts->create_item(root);
  460. sections["Common"] = common_section;
  461. common_section->set_text(0, TTRC("Common"));
  462. common_section->set_selectable(0, false);
  463. common_section->set_selectable(1, false);
  464. if (collapsed.has("Common")) {
  465. common_section->set_collapsed(collapsed["Common"]);
  466. }
  467. common_section->set_custom_bg_color(0, shortcuts->get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
  468. common_section->set_custom_bg_color(1, shortcuts->get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
  469. // Get the action map for the editor, and add each item to the "Common" section.
  470. for (const KeyValue<StringName, InputMap::Action> &E : InputMap::get_singleton()->get_action_map()) {
  471. const String &action_name = E.key;
  472. const InputMap::Action &action = E.value;
  473. // Skip non-builtin actions.
  474. if (!InputMap::get_singleton()->get_builtins_with_feature_overrides_applied().has(action_name)) {
  475. continue;
  476. }
  477. const List<Ref<InputEvent>> &all_default_events = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied().find(action_name)->value;
  478. Array action_events = _event_list_to_array_helper(action.inputs);
  479. if (!_should_display_shortcut(action_name, action_events, false)) {
  480. continue;
  481. }
  482. Array default_events = _event_list_to_array_helper(all_default_events);
  483. bool same_as_defaults = Shortcut::is_event_array_equal(default_events, action_events);
  484. bool collapse = !collapsed.has(action_name) || (collapsed.has(action_name) && collapsed[action_name]);
  485. TreeItem *item = _create_shortcut_treeitem(common_section, action_name, action_name, action_events, !same_as_defaults, true, collapse);
  486. item->set_auto_translate_mode(0, AUTO_TRANSLATE_MODE_DISABLED); // `ui_*` input action names are untranslatable identifiers.
  487. }
  488. // Editor Shortcuts
  489. List<String> slist;
  490. EditorSettings::get_singleton()->get_shortcut_list(&slist);
  491. slist.sort(); // Sort alphabetically.
  492. const EditorPropertyNameProcessor::Style name_style = EditorPropertyNameProcessor::get_settings_style();
  493. const EditorPropertyNameProcessor::Style tooltip_style = EditorPropertyNameProcessor::get_tooltip_style(name_style);
  494. // Create all sections first.
  495. for (const String &E : slist) {
  496. Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(E);
  497. String section_name = E.get_slicec('/', 0);
  498. if (sections.has(section_name)) {
  499. continue;
  500. }
  501. TreeItem *section = shortcuts->create_item(root);
  502. const String item_name = EditorPropertyNameProcessor::get_singleton()->process_name(section_name, name_style, E);
  503. const String tooltip = EditorPropertyNameProcessor::get_singleton()->process_name(section_name, tooltip_style, E);
  504. section->set_auto_translate_mode(0, AUTO_TRANSLATE_MODE_DISABLED); // Already translated manually.
  505. section->set_text(0, item_name);
  506. section->set_tooltip_text(0, tooltip);
  507. section->set_selectable(0, false);
  508. section->set_selectable(1, false);
  509. section->set_custom_bg_color(0, shortcuts->get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
  510. section->set_custom_bg_color(1, shortcuts->get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
  511. if (collapsed.has(item_name)) {
  512. section->set_collapsed(collapsed[item_name]);
  513. }
  514. sections[section_name] = section;
  515. }
  516. // Add shortcuts to sections.
  517. for (const String &E : slist) {
  518. Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(E);
  519. if (!sc->has_meta("original")) {
  520. continue;
  521. }
  522. String section_name = E.get_slicec('/', 0);
  523. TreeItem *section = sections[section_name];
  524. if (!_should_display_shortcut(sc->get_name(), sc->get_events(), true)) {
  525. continue;
  526. }
  527. Array original = sc->get_meta("original");
  528. Array shortcuts_array = sc->get_events().duplicate(true);
  529. bool same_as_defaults = Shortcut::is_event_array_equal(original, shortcuts_array);
  530. bool collapse = !collapsed.has(E) || (collapsed.has(E) && collapsed[E]);
  531. _create_shortcut_treeitem(section, E, sc->get_name(), shortcuts_array, !same_as_defaults, false, collapse);
  532. }
  533. // remove sections with no shortcuts
  534. for (KeyValue<String, TreeItem *> &E : sections) {
  535. TreeItem *section = E.value;
  536. if (section->get_first_child() == nullptr) {
  537. root->remove_child(section);
  538. memdelete(section);
  539. }
  540. }
  541. // Update UI.
  542. clear_all_search->set_disabled(shortcut_search_box->get_text().is_empty() && shortcut_search_by_event->get_event().is_null());
  543. }
  544. void EditorSettingsDialog::_shortcut_button_pressed(Object *p_item, int p_column, int p_idx, MouseButton p_button) {
  545. if (p_button != MouseButton::LEFT) {
  546. return;
  547. }
  548. TreeItem *ti = Object::cast_to<TreeItem>(p_item);
  549. ERR_FAIL_NULL_MSG(ti, "Object passed is not a TreeItem.");
  550. ShortcutButton button_idx = (ShortcutButton)p_idx;
  551. is_editing_action = ti->get_meta("is_action");
  552. String type = ti->get_meta("type");
  553. if (type == "event") {
  554. current_edited_identifier = ti->get_parent()->get_meta("shortcut_identifier");
  555. current_events = ti->get_parent()->get_meta("events");
  556. current_event_index = ti->get_meta("event_index");
  557. } else { // Type is "shortcut"
  558. current_edited_identifier = ti->get_meta("shortcut_identifier");
  559. current_events = ti->get_meta("events");
  560. current_event_index = -1;
  561. }
  562. switch (button_idx) {
  563. case EditorSettingsDialog::SHORTCUT_ADD: {
  564. // Only for "shortcut" types
  565. shortcut_editor->popup_and_configure();
  566. } break;
  567. case EditorSettingsDialog::SHORTCUT_EDIT: {
  568. // Only for "event" types
  569. shortcut_editor->popup_and_configure(current_events[current_event_index]);
  570. } break;
  571. case EditorSettingsDialog::SHORTCUT_ERASE: {
  572. if (type == "shortcut") {
  573. if (is_editing_action) {
  574. _update_builtin_action(current_edited_identifier, Array());
  575. } else {
  576. _update_shortcut_events(current_edited_identifier, Array());
  577. }
  578. } else if (type == "event") {
  579. current_events.remove_at(current_event_index);
  580. if (is_editing_action) {
  581. _update_builtin_action(current_edited_identifier, current_events);
  582. } else {
  583. _update_shortcut_events(current_edited_identifier, current_events);
  584. }
  585. }
  586. } break;
  587. case EditorSettingsDialog::SHORTCUT_REVERT: {
  588. // Only for "shortcut" types
  589. if (is_editing_action) {
  590. List<Ref<InputEvent>> defaults = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied()[current_edited_identifier];
  591. Array events = _event_list_to_array_helper(defaults);
  592. _update_builtin_action(current_edited_identifier, events);
  593. } else {
  594. Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(current_edited_identifier);
  595. Array original = sc->get_meta("original");
  596. _update_shortcut_events(current_edited_identifier, original);
  597. }
  598. } break;
  599. default:
  600. break;
  601. }
  602. }
  603. void EditorSettingsDialog::_shortcut_cell_double_clicked() {
  604. // When a shortcut cell is double clicked:
  605. // If the cell has children and is in the bindings column, and if its first child is editable,
  606. // then uncollapse the cell, and if the first child is the only child, then edit that child.
  607. // If the cell is in the bindings column and can be edited, then edit it.
  608. // If the cell is in the name column, then toggle collapse.
  609. const ShortcutButton edit_btn_id = EditorSettingsDialog::SHORTCUT_EDIT;
  610. const int edit_btn_col = 1;
  611. TreeItem *ti = shortcuts->get_selected();
  612. if (ti == nullptr) {
  613. return;
  614. }
  615. String type = ti->get_meta("type");
  616. int col = shortcuts->get_selected_column();
  617. if (type == "shortcut" && col == 0) {
  618. if (ti->get_first_child()) {
  619. ti->set_collapsed(!ti->is_collapsed());
  620. }
  621. } else if (type == "shortcut" && col == 1) {
  622. if (ti->get_first_child()) {
  623. TreeItem *child_ti = ti->get_first_child();
  624. if (child_ti->get_button_by_id(edit_btn_col, edit_btn_id) != -1) {
  625. ti->set_collapsed(false);
  626. if (ti->get_child_count() == 1) {
  627. _shortcut_button_pressed(child_ti, edit_btn_col, edit_btn_id);
  628. }
  629. }
  630. }
  631. } else if (type == "event" && col == 1) {
  632. if (ti->get_button_by_id(edit_btn_col, edit_btn_id) != -1) {
  633. _shortcut_button_pressed(ti, edit_btn_col, edit_btn_id);
  634. }
  635. }
  636. }
  637. Variant EditorSettingsDialog::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
  638. TreeItem *selected = shortcuts->get_selected();
  639. // Only allow drag for events
  640. if (!selected || (String)selected->get_meta("type", "") != "event") {
  641. return Variant();
  642. }
  643. String label_text = vformat(TTRC("Event %d"), selected->get_meta("event_index"));
  644. Label *label = memnew(Label(label_text));
  645. label->set_modulate(Color(1, 1, 1, 1.0f));
  646. shortcuts->set_drag_preview(label);
  647. shortcuts->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN);
  648. return Dictionary(); // No data required
  649. }
  650. bool EditorSettingsDialog::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
  651. TreeItem *selected = shortcuts->get_selected();
  652. TreeItem *item = (p_point == Vector2(Math::INF, Math::INF)) ? shortcuts->get_selected() : shortcuts->get_item_at_position(p_point);
  653. if (!selected || !item || item == selected || (String)item->get_meta("type", "") != "event") {
  654. return false;
  655. }
  656. // Don't allow moving an events in-between shortcuts.
  657. if (selected->get_parent()->get_meta("shortcut_identifier") != item->get_parent()->get_meta("shortcut_identifier")) {
  658. return false;
  659. }
  660. return true;
  661. }
  662. void EditorSettingsDialog::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
  663. if (!can_drop_data_fw(p_point, p_data, p_from)) {
  664. return;
  665. }
  666. TreeItem *selected = shortcuts->get_selected();
  667. TreeItem *target = (p_point == Vector2(Math::INF, Math::INF)) ? shortcuts->get_selected() : shortcuts->get_item_at_position(p_point);
  668. if (!target) {
  669. return;
  670. }
  671. int target_event_index = target->get_meta("event_index");
  672. int index_moving_from = selected->get_meta("event_index");
  673. Array events = selected->get_parent()->get_meta("events");
  674. Variant event_moved = events[index_moving_from];
  675. events.remove_at(index_moving_from);
  676. events.insert(target_event_index, event_moved);
  677. String ident = selected->get_parent()->get_meta("shortcut_identifier");
  678. if (selected->get_meta("is_action")) {
  679. _update_builtin_action(ident, events);
  680. } else {
  681. _update_shortcut_events(ident, events);
  682. }
  683. }
  684. void EditorSettingsDialog::_tabs_tab_changed(int p_tab) {
  685. _focus_current_search_box();
  686. // When tab has switched, shortcuts may have changed.
  687. _update_dynamic_property_hints();
  688. inspector->get_inspector()->update_tree();
  689. }
  690. void EditorSettingsDialog::_update_dynamic_property_hints() {
  691. // Calling add_property_hint overrides the existing hint.
  692. EditorSettings *settings = EditorSettings::get_singleton();
  693. settings->add_property_hint(_create_mouse_shortcut_property_info("editors/3d/navigation/orbit_mouse_button", "spatial_editor/viewport_orbit_modifier_1", "spatial_editor/viewport_orbit_modifier_2"));
  694. settings->add_property_hint(_create_mouse_shortcut_property_info("editors/3d/navigation/pan_mouse_button", "spatial_editor/viewport_pan_modifier_1", "spatial_editor/viewport_pan_modifier_2"));
  695. settings->add_property_hint(_create_mouse_shortcut_property_info("editors/3d/navigation/zoom_mouse_button", "spatial_editor/viewport_zoom_modifier_1", "spatial_editor/viewport_zoom_modifier_2"));
  696. }
  697. PropertyInfo EditorSettingsDialog::_create_mouse_shortcut_property_info(const String &p_property_name, const String &p_shortcut_1_name, const String &p_shortcut_2_name) {
  698. String hint_string;
  699. hint_string += _get_shortcut_button_string(p_shortcut_1_name) + _get_shortcut_button_string(p_shortcut_2_name);
  700. hint_string += "Left Mouse,";
  701. hint_string += _get_shortcut_button_string(p_shortcut_1_name) + _get_shortcut_button_string(p_shortcut_2_name);
  702. hint_string += "Middle Mouse,";
  703. hint_string += _get_shortcut_button_string(p_shortcut_1_name) + _get_shortcut_button_string(p_shortcut_2_name);
  704. hint_string += "Right Mouse,";
  705. hint_string += _get_shortcut_button_string(p_shortcut_1_name) + _get_shortcut_button_string(p_shortcut_2_name);
  706. hint_string += "Mouse Button 4,";
  707. hint_string += _get_shortcut_button_string(p_shortcut_1_name) + _get_shortcut_button_string(p_shortcut_2_name);
  708. hint_string += "Mouse Button 5";
  709. return PropertyInfo(Variant::INT, p_property_name, PROPERTY_HINT_ENUM, hint_string);
  710. }
  711. String EditorSettingsDialog::_get_shortcut_button_string(const String &p_shortcut_name) {
  712. String button_string;
  713. Ref<Shortcut> shortcut_ref = EditorSettings::get_singleton()->get_shortcut(p_shortcut_name);
  714. Array events = shortcut_ref->get_events();
  715. for (Ref<InputEvent> input_event : events) {
  716. button_string += input_event->as_text() + " + ";
  717. }
  718. return button_string;
  719. }
  720. void EditorSettingsDialog::_focus_current_search_box() {
  721. Control *tab = tabs->get_current_tab_control();
  722. LineEdit *current_search_box = nullptr;
  723. if (tab == tab_general) {
  724. current_search_box = search_box;
  725. } else if (tab == tab_shortcuts) {
  726. current_search_box = shortcut_search_box;
  727. }
  728. if (current_search_box) {
  729. current_search_box->grab_focus();
  730. current_search_box->select_all();
  731. }
  732. }
  733. void EditorSettingsDialog::_advanced_toggled(bool p_button_pressed) {
  734. EditorSettings::get_singleton()->set("_editor_settings_advanced_mode", p_button_pressed);
  735. }
  736. void EditorSettingsDialog::_editor_restart() {
  737. EditorNode::get_singleton()->save_all_scenes();
  738. EditorNode::get_singleton()->restart_editor();
  739. }
  740. void EditorSettingsDialog::_editor_restart_request() {
  741. restart_container->show();
  742. }
  743. void EditorSettingsDialog::_editor_restart_close() {
  744. restart_container->hide();
  745. }
  746. void EditorSettingsDialog::_bind_methods() {
  747. ClassDB::bind_method(D_METHOD("_update_shortcuts"), &EditorSettingsDialog::_update_shortcuts);
  748. ClassDB::bind_method(D_METHOD("_settings_changed"), &EditorSettingsDialog::_settings_changed);
  749. }
  750. EditorSettingsDialog::EditorSettingsDialog() {
  751. set_title(TTRC("Editor Settings"));
  752. set_clamp_to_embedder(true);
  753. tabs = memnew(TabContainer);
  754. tabs->set_theme_type_variation("TabContainerOdd");
  755. tabs->connect("tab_changed", callable_mp(this, &EditorSettingsDialog::_tabs_tab_changed));
  756. add_child(tabs);
  757. // General Tab
  758. tab_general = memnew(VBoxContainer);
  759. tabs->add_child(tab_general);
  760. tab_general->set_name(TTRC("General"));
  761. HBoxContainer *hbc = memnew(HBoxContainer);
  762. hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  763. tab_general->add_child(hbc);
  764. search_box = memnew(LineEdit);
  765. search_box->set_placeholder(TTRC("Filter Settings"));
  766. search_box->set_accessibility_name(TTRC("Filter Settings"));
  767. search_box->set_virtual_keyboard_show_on_focus(false);
  768. search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  769. hbc->add_child(search_box);
  770. advanced_switch = memnew(CheckButton(TTRC("Advanced Settings")));
  771. hbc->add_child(advanced_switch);
  772. bool use_advanced = EDITOR_DEF("_editor_settings_advanced_mode", false);
  773. advanced_switch->set_pressed(use_advanced);
  774. advanced_switch->connect(SceneStringName(toggled), callable_mp(this, &EditorSettingsDialog::_advanced_toggled));
  775. inspector = memnew(SectionedInspector);
  776. inspector->get_inspector()->set_use_filter(true);
  777. inspector->get_inspector()->set_mark_unsaved(false);
  778. inspector->register_search_box(search_box);
  779. inspector->register_advanced_toggle(advanced_switch);
  780. inspector->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  781. tab_general->add_child(inspector);
  782. inspector->get_inspector()->connect("property_edited", callable_mp(this, &EditorSettingsDialog::_settings_property_edited));
  783. inspector->get_inspector()->connect("restart_requested", callable_mp(this, &EditorSettingsDialog::_editor_restart_request));
  784. if (EDITOR_GET("interface/touchscreen/enable_touch_optimizations")) {
  785. inspector->set_touch_dragger_enabled(true);
  786. }
  787. restart_container = memnew(PanelContainer);
  788. tab_general->add_child(restart_container);
  789. HBoxContainer *restart_hb = memnew(HBoxContainer);
  790. restart_container->add_child(restart_hb);
  791. restart_icon = memnew(TextureRect);
  792. restart_icon->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
  793. restart_hb->add_child(restart_icon);
  794. restart_label = memnew(Label);
  795. restart_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
  796. restart_label->set_text(TTRC("The editor must be restarted for changes to take effect."));
  797. restart_hb->add_child(restart_label);
  798. restart_hb->add_spacer();
  799. Button *restart_button = memnew(Button);
  800. restart_button->connect(SceneStringName(pressed), callable_mp(this, &EditorSettingsDialog::_editor_restart));
  801. restart_hb->add_child(restart_button);
  802. restart_button->set_text(TTRC("Save & Restart"));
  803. restart_close_button = memnew(Button);
  804. restart_close_button->set_accessibility_name(TTRC("Close"));
  805. restart_close_button->set_flat(true);
  806. restart_close_button->connect(SceneStringName(pressed), callable_mp(this, &EditorSettingsDialog::_editor_restart_close));
  807. restart_hb->add_child(restart_close_button);
  808. restart_container->hide();
  809. // Shortcuts Tab
  810. tab_shortcuts = memnew(VBoxContainer);
  811. tabs->add_child(tab_shortcuts);
  812. tab_shortcuts->set_name(TTRC("Shortcuts"));
  813. HBoxContainer *top_hbox = memnew(HBoxContainer);
  814. top_hbox->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  815. tab_shortcuts->add_child(top_hbox);
  816. shortcut_search_box = memnew(LineEdit);
  817. shortcut_search_box->set_placeholder(TTRC("Filter by Name"));
  818. shortcut_search_box->set_accessibility_name(TTRC("Filter by Name"));
  819. shortcut_search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  820. top_hbox->add_child(shortcut_search_box);
  821. shortcut_search_box->connect(SceneStringName(text_changed), callable_mp(this, &EditorSettingsDialog::_filter_shortcuts));
  822. shortcut_search_by_event = memnew(EventListenerLineEdit);
  823. shortcut_search_by_event->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  824. shortcut_search_by_event->set_stretch_ratio(0.75);
  825. shortcut_search_by_event->set_allowed_input_types(INPUT_KEY);
  826. shortcut_search_by_event->connect("event_changed", callable_mp(this, &EditorSettingsDialog::_filter_shortcuts_by_event));
  827. shortcut_search_by_event->connect(SceneStringName(focus_entered), callable_mp((AcceptDialog *)this, &AcceptDialog::set_close_on_escape).bind(false));
  828. shortcut_search_by_event->connect(SceneStringName(focus_exited), callable_mp((AcceptDialog *)this, &AcceptDialog::set_close_on_escape).bind(true));
  829. top_hbox->add_child(shortcut_search_by_event);
  830. clear_all_search = memnew(Button);
  831. clear_all_search->set_text(TTRC("Clear All"));
  832. clear_all_search->set_tooltip_text(TTRC("Clear all search filters."));
  833. clear_all_search->connect(SceneStringName(pressed), callable_mp(shortcut_search_box, &LineEdit::clear));
  834. clear_all_search->connect(SceneStringName(pressed), callable_mp(shortcut_search_by_event, &EventListenerLineEdit::clear_event));
  835. top_hbox->add_child(clear_all_search);
  836. shortcuts = memnew(Tree);
  837. shortcuts->set_accessibility_name(TTRC("Shortcuts"));
  838. shortcuts->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  839. shortcuts->set_columns(2);
  840. shortcuts->set_hide_root(true);
  841. shortcuts->set_column_titles_visible(true);
  842. shortcuts->set_column_title(0, TTRC("Name"));
  843. shortcuts->set_column_title(1, TTRC("Binding"));
  844. shortcuts->connect("button_clicked", callable_mp(this, &EditorSettingsDialog::_shortcut_button_pressed));
  845. shortcuts->connect("item_activated", callable_mp(this, &EditorSettingsDialog::_shortcut_cell_double_clicked));
  846. tab_shortcuts->add_child(shortcuts);
  847. SET_DRAG_FORWARDING_GCD(shortcuts, EditorSettingsDialog);
  848. // Adding event dialog
  849. shortcut_editor = memnew(InputEventConfigurationDialog);
  850. shortcut_editor->connect(SceneStringName(confirmed), callable_mp(this, &EditorSettingsDialog::_event_config_confirmed));
  851. shortcut_editor->set_allowed_input_types(INPUT_KEY);
  852. add_child(shortcut_editor);
  853. set_hide_on_ok(true);
  854. timer = memnew(Timer);
  855. timer->set_wait_time(1.5);
  856. timer->connect("timeout", callable_mp(this, &EditorSettingsDialog::_settings_save));
  857. timer->set_one_shot(true);
  858. add_child(timer);
  859. EditorSettings::get_singleton()->connect("settings_changed", callable_mp(this, &EditorSettingsDialog::_settings_changed));
  860. set_ok_button_text(TTRC("Close"));
  861. Ref<EditorSettingsInspectorPlugin> plugin;
  862. plugin.instantiate();
  863. plugin->inspector = inspector;
  864. EditorInspector::add_inspector_plugin(plugin);
  865. }
  866. void EditorSettingsPropertyWrapper::_update_override() {
  867. // Don't allow overriding theme properties, because it causes problems. Overriding Project Manager settings makes no sense.
  868. // TODO: Find a better way to define exception prefixes (if the list happens to grow).
  869. if (property.begins_with("interface/theme") || property.begins_with("project_manager")) {
  870. can_override = false;
  871. return;
  872. }
  873. const bool has_override = ProjectSettings::get_singleton()->has_editor_setting_override(property);
  874. if (has_override) {
  875. const Variant override_value = EDITOR_GET(property);
  876. override_label->set_text(vformat(TTR("Overridden in project: %s"), override_value));
  877. // In case the text is too long and trimmed.
  878. override_label->set_tooltip_text(override_value);
  879. }
  880. override_info->set_visible(has_override);
  881. can_override = !has_override;
  882. }
  883. void EditorSettingsPropertyWrapper::_create_override() {
  884. ProjectSettings::get_singleton()->set_editor_setting_override(property, EDITOR_GET(property));
  885. ProjectSettings::get_singleton()->save();
  886. _update_override();
  887. }
  888. void EditorSettingsPropertyWrapper::_remove_override() {
  889. ProjectSettings::get_singleton()->set_editor_setting_override(property, Variant());
  890. ProjectSettings::get_singleton()->save();
  891. EditorSettings::get_singleton()->mark_setting_changed(property);
  892. EditorNode::get_singleton()->notify_settings_overrides_changed();
  893. _update_override();
  894. if (requires_restart) {
  895. restart_request_callback.call();
  896. }
  897. }
  898. void EditorSettingsPropertyWrapper::_notification(int p_what) {
  899. if (p_what == NOTIFICATION_THEME_CHANGED) {
  900. goto_button->set_button_icon(get_editor_theme_icon(SNAME("MethodOverride")));
  901. remove_button->set_button_icon(get_editor_theme_icon(SNAME("Close")));
  902. }
  903. }
  904. void EditorSettingsPropertyWrapper::update_property() {
  905. editor_property->update_property();
  906. }
  907. void EditorSettingsPropertyWrapper::setup(const String &p_property, EditorProperty *p_editor_property, bool p_requires_restart) {
  908. requires_restart = p_requires_restart;
  909. property = p_property;
  910. container = memnew(VBoxContainer);
  911. editor_property = p_editor_property;
  912. editor_property->set_h_size_flags(SIZE_EXPAND_FILL);
  913. container->add_child(editor_property);
  914. override_info = memnew(HBoxContainer);
  915. override_info->hide();
  916. container->add_child(override_info);
  917. override_label = memnew(Label);
  918. override_label->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS);
  919. override_label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  920. override_label->set_mouse_filter(MOUSE_FILTER_STOP); // For tooltip.
  921. override_label->set_h_size_flags(SIZE_EXPAND_FILL);
  922. override_info->add_child(override_label);
  923. goto_button = memnew(Button);
  924. goto_button->set_tooltip_text(TTRC("Go to the override in the Project Settings."));
  925. override_info->add_child(goto_button);
  926. goto_button->connect(SceneStringName(pressed), callable_mp(EditorNode::get_singleton(), &EditorNode::open_setting_override).bind(property), CONNECT_DEFERRED);
  927. remove_button = memnew(Button);
  928. remove_button->set_tooltip_text(TTRC("Remove this override."));
  929. override_info->add_child(remove_button);
  930. remove_button->connect(SceneStringName(pressed), callable_mp(this, &EditorSettingsPropertyWrapper::_remove_override));
  931. add_child(container);
  932. _update_override();
  933. connect(SNAME("property_overridden"), callable_mp(this, &EditorSettingsPropertyWrapper::_create_override));
  934. editor_property->connect("property_changed", callable_mp((EditorProperty *)this, &EditorProperty::emit_changed));
  935. }
  936. bool EditorSettingsInspectorPlugin::can_handle(Object *p_object) {
  937. return p_object->is_class("SectionedInspectorFilter") && p_object != current_object;
  938. }
  939. bool EditorSettingsInspectorPlugin::parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const BitField<PropertyUsageFlags> p_usage, const bool p_wide) {
  940. if (!p_object->is_class("SectionedInspectorFilter")) {
  941. return false;
  942. }
  943. const String property = inspector->get_full_item_path(p_path);
  944. if (!EditorSettings::get_singleton()->has_setting(property)) {
  945. return false;
  946. }
  947. current_object = p_object;
  948. EditorSettingsPropertyWrapper *editor = memnew(EditorSettingsPropertyWrapper);
  949. EditorProperty *real_property = inspector->get_inspector()->instantiate_property_editor(p_object, p_type, p_path, p_hint, p_hint_text, p_usage, p_wide);
  950. real_property->set_object_and_property(p_object, p_path);
  951. real_property->set_name_split_ratio(0.0);
  952. editor->setup(property, real_property, bool(p_usage & PROPERTY_USAGE_RESTART_IF_CHANGED));
  953. add_property_editor(p_path, editor);
  954. current_object = nullptr;
  955. return true;
  956. }