project_settings_editor.cpp 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. /**************************************************************************/
  2. /* project_settings_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 "project_settings_editor.h"
  31. #include "core/config/project_settings.h"
  32. #include "editor/editor_log.h"
  33. #include "editor/editor_node.h"
  34. #include "editor/editor_settings.h"
  35. #include "editor/editor_string_names.h"
  36. #include "editor/editor_undo_redo_manager.h"
  37. #include "editor/export/editor_export.h"
  38. #include "editor/themes/editor_scale.h"
  39. #include "scene/gui/check_button.h"
  40. #include "servers/movie_writer/movie_writer.h"
  41. ProjectSettingsEditor *ProjectSettingsEditor::singleton = nullptr;
  42. void ProjectSettingsEditor::connect_filesystem_dock_signals(FileSystemDock *p_fs_dock) {
  43. localization_editor->connect_filesystem_dock_signals(p_fs_dock);
  44. group_settings->connect_filesystem_dock_signals(p_fs_dock);
  45. }
  46. void ProjectSettingsEditor::popup_project_settings(bool p_clear_filter) {
  47. // Restore valid window bounds or pop up at default size.
  48. Rect2 saved_size = EditorSettings::get_singleton()->get_project_metadata("dialog_bounds", "project_settings", Rect2());
  49. if (saved_size != Rect2()) {
  50. popup(saved_size);
  51. } else {
  52. popup_centered_clamped(Size2(900, 700) * EDSCALE, 0.8);
  53. }
  54. _add_feature_overrides();
  55. general_settings_inspector->update_category_list();
  56. set_process_shortcut_input(true);
  57. localization_editor->update_translations();
  58. autoload_settings->update_autoload();
  59. group_settings->update_groups();
  60. plugin_settings->update_plugins();
  61. import_defaults_editor->clear();
  62. if (p_clear_filter) {
  63. search_box->clear();
  64. }
  65. _focus_current_search_box();
  66. }
  67. void ProjectSettingsEditor::queue_save() {
  68. timer->start();
  69. }
  70. void ProjectSettingsEditor::set_plugins_page() {
  71. tab_container->set_current_tab(tab_container->get_tab_idx_from_control(plugin_settings));
  72. }
  73. void ProjectSettingsEditor::set_general_page(const String &p_category) {
  74. tab_container->set_current_tab(tab_container->get_tab_idx_from_control(general_editor));
  75. general_settings_inspector->set_current_section(p_category);
  76. }
  77. void ProjectSettingsEditor::update_plugins() {
  78. plugin_settings->update_plugins();
  79. }
  80. void ProjectSettingsEditor::_setting_edited(const String &p_name) {
  81. queue_save();
  82. }
  83. void ProjectSettingsEditor::_update_advanced(bool p_is_advanced) {
  84. custom_properties->set_visible(p_is_advanced);
  85. }
  86. void ProjectSettingsEditor::_advanced_toggled(bool p_button_pressed) {
  87. EditorSettings::get_singleton()->set_project_metadata("project_settings", "advanced_mode", p_button_pressed);
  88. _update_advanced(p_button_pressed);
  89. general_settings_inspector->set_restrict_to_basic_settings(!p_button_pressed);
  90. }
  91. void ProjectSettingsEditor::_setting_selected(const String &p_path) {
  92. if (p_path.is_empty()) {
  93. return;
  94. }
  95. property_box->set_text(general_settings_inspector->get_current_section() + "/" + p_path);
  96. _update_property_box(); // set_text doesn't trigger text_changed
  97. }
  98. void ProjectSettingsEditor::_add_setting() {
  99. String setting = _get_setting_name();
  100. // Initialize the property with the default value for the given type.
  101. Callable::CallError ce;
  102. Variant value;
  103. Variant::construct(Variant::Type(type_box->get_selected_id()), value, nullptr, 0, ce);
  104. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  105. undo_redo->create_action(TTR("Add Project Setting"));
  106. undo_redo->add_do_property(ps, setting, value);
  107. undo_redo->add_undo_property(ps, setting, ps->has_setting(setting) ? ps->get(setting) : Variant());
  108. undo_redo->add_do_method(general_settings_inspector, "update_category_list");
  109. undo_redo->add_undo_method(general_settings_inspector, "update_category_list");
  110. undo_redo->add_do_method(this, "queue_save");
  111. undo_redo->add_undo_method(this, "queue_save");
  112. undo_redo->commit_action();
  113. general_settings_inspector->set_current_section(setting.get_slice("/", 1));
  114. add_button->release_focus();
  115. }
  116. void ProjectSettingsEditor::_delete_setting() {
  117. String setting = _get_setting_name();
  118. Variant value = ps->get(setting);
  119. int order = ps->get_order(setting);
  120. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  121. undo_redo->create_action(TTR("Delete Item"));
  122. undo_redo->add_do_method(ps, "clear", setting);
  123. undo_redo->add_undo_method(ps, "set", setting, value);
  124. undo_redo->add_undo_method(ps, "set_order", setting, order);
  125. undo_redo->add_do_method(general_settings_inspector, "update_category_list");
  126. undo_redo->add_undo_method(general_settings_inspector, "update_category_list");
  127. undo_redo->add_do_method(this, "queue_save");
  128. undo_redo->add_undo_method(this, "queue_save");
  129. undo_redo->commit_action();
  130. property_box->clear();
  131. del_button->release_focus();
  132. }
  133. void ProjectSettingsEditor::_property_box_changed(const String &p_text) {
  134. _update_property_box();
  135. }
  136. void ProjectSettingsEditor::_feature_selected(int p_index) {
  137. Vector<String> t = property_box->get_text().strip_edges().split(".", true, 1);
  138. const String feature = p_index ? "." + feature_box->get_item_text(p_index) : "";
  139. property_box->set_text(t[0] + feature);
  140. _update_property_box();
  141. }
  142. void ProjectSettingsEditor::_update_property_box() {
  143. const String setting = _get_setting_name();
  144. const Vector<String> t = setting.split(".", true, 1);
  145. const String &name = t[0];
  146. const String feature = (t.size() == 2) ? t[1] : "";
  147. bool feature_invalid = (t.size() == 2) && (t[1].is_empty());
  148. add_button->set_disabled(true);
  149. del_button->set_disabled(true);
  150. if (!feature.is_empty()) {
  151. feature_invalid = true;
  152. for (int i = 1; i < feature_box->get_item_count(); i++) {
  153. if (feature == feature_box->get_item_text(i)) {
  154. feature_invalid = false;
  155. feature_box->select(i);
  156. break;
  157. }
  158. }
  159. }
  160. if (feature.is_empty() || feature_invalid) {
  161. feature_box->select(0);
  162. }
  163. if (property_box->get_text().is_empty()) {
  164. return;
  165. }
  166. if (ps->has_setting(setting)) {
  167. del_button->set_disabled(ps->is_builtin_setting(setting));
  168. _select_type(ps->get_setting(setting).get_type());
  169. } else {
  170. if (ps->has_setting(name)) {
  171. _select_type(ps->get_setting(name).get_type());
  172. } else {
  173. type_box->select(0);
  174. }
  175. if (feature_invalid) {
  176. return;
  177. }
  178. const Vector<String> names = name.split("/");
  179. for (int i = 0; i < names.size(); i++) {
  180. if (!names[i].is_valid_identifier()) {
  181. return;
  182. }
  183. }
  184. add_button->set_disabled(false);
  185. }
  186. }
  187. void ProjectSettingsEditor::_select_type(Variant::Type p_type) {
  188. type_box->select(type_box->get_item_index(p_type));
  189. }
  190. void ProjectSettingsEditor::shortcut_input(const Ref<InputEvent> &p_event) {
  191. ERR_FAIL_COND(p_event.is_null());
  192. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  193. const Ref<InputEventKey> k = p_event;
  194. if (k.is_valid() && k->is_pressed()) {
  195. bool handled = false;
  196. if (ED_IS_SHORTCUT("ui_undo", p_event)) {
  197. String action = undo_redo->get_current_action_name();
  198. if (!action.is_empty()) {
  199. EditorNode::get_log()->add_message(vformat(TTR("Undo: %s"), action), EditorLog::MSG_TYPE_EDITOR);
  200. }
  201. undo_redo->undo();
  202. handled = true;
  203. }
  204. if (ED_IS_SHORTCUT("ui_redo", p_event)) {
  205. undo_redo->redo();
  206. String action = undo_redo->get_current_action_name();
  207. if (!action.is_empty()) {
  208. EditorNode::get_log()->add_message(vformat(TTR("Redo: %s"), action), EditorLog::MSG_TYPE_EDITOR);
  209. }
  210. handled = true;
  211. }
  212. if (ED_IS_SHORTCUT("editor/open_search", p_event)) {
  213. _focus_current_search_box();
  214. handled = true;
  215. }
  216. if (ED_IS_SHORTCUT("file_dialog/focus_path", p_event)) {
  217. _focus_current_path_box();
  218. handled = true;
  219. }
  220. if (handled) {
  221. set_input_as_handled();
  222. }
  223. }
  224. }
  225. String ProjectSettingsEditor::_get_setting_name() const {
  226. String name = property_box->get_text().strip_edges();
  227. if (!name.contains("/")) {
  228. name = "global/" + name;
  229. }
  230. return name;
  231. }
  232. void ProjectSettingsEditor::_add_feature_overrides() {
  233. HashSet<String> presets;
  234. presets.insert("bptc");
  235. presets.insert("s3tc");
  236. presets.insert("etc2");
  237. presets.insert("editor");
  238. presets.insert("editor_hint");
  239. presets.insert("editor_runtime");
  240. presets.insert("template_debug");
  241. presets.insert("template_release");
  242. presets.insert("debug");
  243. presets.insert("release");
  244. presets.insert("template");
  245. presets.insert("double");
  246. presets.insert("single");
  247. presets.insert("32");
  248. presets.insert("64");
  249. presets.insert("movie");
  250. EditorExport *ee = EditorExport::get_singleton();
  251. for (int i = 0; i < ee->get_export_platform_count(); i++) {
  252. List<String> p;
  253. ee->get_export_platform(i)->get_platform_features(&p);
  254. for (const String &E : p) {
  255. presets.insert(E);
  256. }
  257. }
  258. for (int i = 0; i < ee->get_export_preset_count(); i++) {
  259. List<String> p;
  260. ee->get_export_preset(i)->get_platform()->get_preset_features(ee->get_export_preset(i), &p);
  261. for (const String &E : p) {
  262. presets.insert(E);
  263. }
  264. String custom = ee->get_export_preset(i)->get_custom_features();
  265. Vector<String> custom_list = custom.split(",");
  266. for (int j = 0; j < custom_list.size(); j++) {
  267. String f = custom_list[j].strip_edges();
  268. if (!f.is_empty()) {
  269. presets.insert(f);
  270. }
  271. }
  272. }
  273. feature_box->clear();
  274. feature_box->add_item(TTR("(All)"), 0); // So it is always on top.
  275. int id = 1;
  276. for (const String &E : presets) {
  277. feature_box->add_item(E, id++);
  278. }
  279. }
  280. void ProjectSettingsEditor::_tabs_tab_changed(int p_tab) {
  281. _focus_current_search_box();
  282. }
  283. void ProjectSettingsEditor::_focus_current_search_box() {
  284. Control *tab = tab_container->get_current_tab_control();
  285. LineEdit *current_search_box = nullptr;
  286. if (tab == general_editor) {
  287. current_search_box = search_box;
  288. } else if (tab == action_map_editor) {
  289. current_search_box = action_map_editor->get_search_box();
  290. }
  291. if (current_search_box) {
  292. current_search_box->grab_focus();
  293. current_search_box->select_all();
  294. }
  295. }
  296. void ProjectSettingsEditor::_focus_current_path_box() {
  297. Control *tab = tab_container->get_current_tab_control();
  298. LineEdit *current_path_box = nullptr;
  299. if (tab == general_editor) {
  300. current_path_box = property_box;
  301. } else if (tab == action_map_editor) {
  302. current_path_box = action_map_editor->get_path_box();
  303. } else if (tab == autoload_settings) {
  304. current_path_box = autoload_settings->get_path_box();
  305. } else if (tab == shaders_global_shader_uniforms_editor) {
  306. current_path_box = shaders_global_shader_uniforms_editor->get_name_box();
  307. } else if (tab == group_settings) {
  308. current_path_box = group_settings->get_name_box();
  309. }
  310. if (current_path_box) {
  311. current_path_box->grab_focus();
  312. current_path_box->select_all();
  313. }
  314. }
  315. void ProjectSettingsEditor::_editor_restart() {
  316. ProjectSettings::get_singleton()->save();
  317. EditorNode::get_singleton()->save_all_scenes();
  318. EditorNode::get_singleton()->restart_editor();
  319. }
  320. void ProjectSettingsEditor::_editor_restart_request() {
  321. restart_container->show();
  322. }
  323. void ProjectSettingsEditor::_editor_restart_close() {
  324. restart_container->hide();
  325. }
  326. void ProjectSettingsEditor::_action_added(const String &p_name) {
  327. String name = "input/" + p_name;
  328. ERR_FAIL_COND_MSG(ProjectSettings::get_singleton()->has_setting(name),
  329. "An action with this name already exists.");
  330. Dictionary action;
  331. action["events"] = Array();
  332. action["deadzone"] = 0.5f;
  333. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  334. undo_redo->create_action(TTR("Add Input Action"));
  335. undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", name, action);
  336. undo_redo->add_undo_method(ProjectSettings::get_singleton(), "clear", name);
  337. undo_redo->add_do_method(this, "_update_action_map_editor");
  338. undo_redo->add_undo_method(this, "_update_action_map_editor");
  339. undo_redo->add_do_method(this, "queue_save");
  340. undo_redo->add_undo_method(this, "queue_save");
  341. undo_redo->commit_action();
  342. }
  343. void ProjectSettingsEditor::_action_edited(const String &p_name, const Dictionary &p_action) {
  344. const String property_name = "input/" + p_name;
  345. Dictionary old_val = GLOBAL_GET(property_name);
  346. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  347. if (old_val["deadzone"] != p_action["deadzone"]) {
  348. // Deadzone Changed
  349. undo_redo->create_action(TTR("Change Action deadzone"));
  350. undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", property_name, p_action);
  351. undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", property_name, old_val);
  352. } else {
  353. // Events changed
  354. undo_redo->create_action(TTR("Change Input Action Event(s)"));
  355. undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", property_name, p_action);
  356. undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", property_name, old_val);
  357. }
  358. undo_redo->add_do_method(this, "_update_action_map_editor");
  359. undo_redo->add_undo_method(this, "_update_action_map_editor");
  360. undo_redo->add_do_method(this, "queue_save");
  361. undo_redo->add_undo_method(this, "queue_save");
  362. undo_redo->commit_action();
  363. }
  364. void ProjectSettingsEditor::_action_removed(const String &p_name) {
  365. const String property_name = "input/" + p_name;
  366. Dictionary old_val = GLOBAL_GET(property_name);
  367. int order = ProjectSettings::get_singleton()->get_order(property_name);
  368. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  369. undo_redo->create_action(TTR("Erase Input Action"));
  370. undo_redo->add_do_method(ProjectSettings::get_singleton(), "clear", property_name);
  371. undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", property_name, old_val);
  372. undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", property_name, order);
  373. undo_redo->add_do_method(this, "_update_action_map_editor");
  374. undo_redo->add_undo_method(this, "_update_action_map_editor");
  375. undo_redo->add_do_method(this, "queue_save");
  376. undo_redo->add_undo_method(this, "queue_save");
  377. undo_redo->commit_action();
  378. }
  379. void ProjectSettingsEditor::_action_renamed(const String &p_old_name, const String &p_new_name) {
  380. const String old_property_name = "input/" + p_old_name;
  381. const String new_property_name = "input/" + p_new_name;
  382. ERR_FAIL_COND_MSG(ProjectSettings::get_singleton()->has_setting(new_property_name),
  383. "An action with this name already exists.");
  384. int order = ProjectSettings::get_singleton()->get_order(old_property_name);
  385. Dictionary action = GLOBAL_GET(old_property_name);
  386. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  387. undo_redo->create_action(TTR("Rename Input Action"));
  388. // Do: clear old, set new
  389. undo_redo->add_do_method(ProjectSettings::get_singleton(), "clear", old_property_name);
  390. undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", new_property_name, action);
  391. undo_redo->add_do_method(ProjectSettings::get_singleton(), "set_order", new_property_name, order);
  392. // Undo: clear new, set old
  393. undo_redo->add_undo_method(ProjectSettings::get_singleton(), "clear", new_property_name);
  394. undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", old_property_name, action);
  395. undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", old_property_name, order);
  396. undo_redo->add_do_method(this, "_update_action_map_editor");
  397. undo_redo->add_undo_method(this, "_update_action_map_editor");
  398. undo_redo->add_do_method(this, "queue_save");
  399. undo_redo->add_undo_method(this, "queue_save");
  400. undo_redo->commit_action();
  401. }
  402. void ProjectSettingsEditor::_action_reordered(const String &p_action_name, const String &p_relative_to, bool p_before) {
  403. const String action_name = "input/" + p_action_name;
  404. const String target_name = "input/" + p_relative_to;
  405. // It is much easier to rebuild the custom "input" properties rather than messing around with the "order" values of them.
  406. Variant action_value = ps->get(action_name);
  407. Variant target_value = ps->get(target_name);
  408. List<PropertyInfo> props;
  409. HashMap<String, Variant> action_values;
  410. ProjectSettings::get_singleton()->get_property_list(&props);
  411. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  412. undo_redo->create_action(TTR("Update Input Action Order"));
  413. for (const PropertyInfo &prop : props) {
  414. // Skip builtins and non-inputs
  415. // Order matters here, checking for "input/" filters out properties that aren't settings and produce errors in is_builtin_setting().
  416. if (!prop.name.begins_with("input/") || ProjectSettings::get_singleton()->is_builtin_setting(prop.name)) {
  417. continue;
  418. }
  419. action_values.insert(prop.name, ps->get(prop.name));
  420. undo_redo->add_do_method(ProjectSettings::get_singleton(), "clear", prop.name);
  421. undo_redo->add_undo_method(ProjectSettings::get_singleton(), "clear", prop.name);
  422. }
  423. for (const KeyValue<String, Variant> &E : action_values) {
  424. String name = E.key;
  425. const Variant &value = E.value;
  426. if (name == target_name) {
  427. if (p_before) {
  428. // Insert before target
  429. undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", action_name, action_value);
  430. undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", target_name, target_value);
  431. undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", target_name, target_value);
  432. undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", action_name, action_value);
  433. } else {
  434. // Insert after target
  435. undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", target_name, target_value);
  436. undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", action_name, action_value);
  437. undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", action_name, action_value);
  438. undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", target_name, target_value);
  439. }
  440. } else if (name != action_name) {
  441. undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", name, value);
  442. undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", name, value);
  443. }
  444. }
  445. undo_redo->add_do_method(this, "_update_action_map_editor");
  446. undo_redo->add_undo_method(this, "_update_action_map_editor");
  447. undo_redo->add_do_method(this, "queue_save");
  448. undo_redo->add_undo_method(this, "queue_save");
  449. undo_redo->commit_action();
  450. }
  451. void ProjectSettingsEditor::_update_action_map_editor() {
  452. Vector<ActionMapEditor::ActionInfo> actions;
  453. List<PropertyInfo> props;
  454. ProjectSettings::get_singleton()->get_property_list(&props);
  455. const Ref<Texture2D> builtin_icon = get_editor_theme_icon(SNAME("PinPressed"));
  456. for (const PropertyInfo &E : props) {
  457. const String property_name = E.name;
  458. if (!property_name.begins_with("input/")) {
  459. continue;
  460. }
  461. // Strip the "input/" from the left.
  462. String display_name = property_name.substr(String("input/").size() - 1);
  463. Dictionary action = GLOBAL_GET(property_name);
  464. ActionMapEditor::ActionInfo action_info;
  465. action_info.action = action;
  466. action_info.editable = true;
  467. action_info.name = display_name;
  468. const bool is_builtin_input = ProjectSettings::get_singleton()->get_input_presets().find(property_name) != nullptr;
  469. if (is_builtin_input) {
  470. action_info.editable = false;
  471. action_info.icon = builtin_icon;
  472. action_info.has_initial = true;
  473. action_info.action_initial = ProjectSettings::get_singleton()->property_get_revert(property_name);
  474. }
  475. actions.push_back(action_info);
  476. }
  477. action_map_editor->update_action_list(actions);
  478. }
  479. void ProjectSettingsEditor::_update_theme() {
  480. add_button->set_icon(get_editor_theme_icon(SNAME("Add")));
  481. del_button->set_icon(get_editor_theme_icon(SNAME("Remove")));
  482. search_box->set_right_icon(get_editor_theme_icon(SNAME("Search")));
  483. restart_close_button->set_icon(get_editor_theme_icon(SNAME("Close")));
  484. restart_container->add_theme_style_override("panel", get_theme_stylebox(SNAME("panel"), SNAME("Tree")));
  485. restart_icon->set_texture(get_editor_theme_icon(SNAME("StatusWarning")));
  486. restart_label->add_theme_color_override("font_color", get_theme_color(SNAME("warning_color"), EditorStringName(Editor)));
  487. type_box->clear();
  488. for (int i = 0; i < Variant::VARIANT_MAX; i++) {
  489. if (i == Variant::NIL || i == Variant::OBJECT || i == Variant::CALLABLE || i == Variant::SIGNAL || i == Variant::RID) {
  490. // These types can't be serialized properly, so skip them.
  491. continue;
  492. }
  493. String type = Variant::get_type_name(Variant::Type(i));
  494. type_box->add_icon_item(get_editor_theme_icon(type), type, i);
  495. }
  496. }
  497. void ProjectSettingsEditor::_notification(int p_what) {
  498. switch (p_what) {
  499. case NOTIFICATION_VISIBILITY_CHANGED: {
  500. if (!is_visible()) {
  501. EditorSettings::get_singleton()->set_project_metadata("dialog_bounds", "project_settings", Rect2(get_position(), get_size()));
  502. }
  503. } break;
  504. case NOTIFICATION_ENTER_TREE: {
  505. general_settings_inspector->edit(ps);
  506. _update_action_map_editor();
  507. _update_theme();
  508. } break;
  509. case NOTIFICATION_THEME_CHANGED: {
  510. _update_theme();
  511. } break;
  512. }
  513. }
  514. void ProjectSettingsEditor::_bind_methods() {
  515. ClassDB::bind_method(D_METHOD("queue_save"), &ProjectSettingsEditor::queue_save);
  516. ClassDB::bind_method(D_METHOD("_update_action_map_editor"), &ProjectSettingsEditor::_update_action_map_editor);
  517. }
  518. ProjectSettingsEditor::ProjectSettingsEditor(EditorData *p_data) {
  519. singleton = this;
  520. set_title(TTR("Project Settings (project.godot)"));
  521. set_clamp_to_embedder(true);
  522. ps = ProjectSettings::get_singleton();
  523. data = p_data;
  524. tab_container = memnew(TabContainer);
  525. tab_container->set_use_hidden_tabs_for_min_size(true);
  526. tab_container->set_theme_type_variation("TabContainerOdd");
  527. tab_container->connect("tab_changed", callable_mp(this, &ProjectSettingsEditor::_tabs_tab_changed));
  528. add_child(tab_container);
  529. general_editor = memnew(VBoxContainer);
  530. general_editor->set_name(TTR("General"));
  531. general_editor->set_alignment(BoxContainer::ALIGNMENT_BEGIN);
  532. general_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  533. tab_container->add_child(general_editor);
  534. HBoxContainer *search_bar = memnew(HBoxContainer);
  535. general_editor->add_child(search_bar);
  536. search_box = memnew(LineEdit);
  537. search_box->set_placeholder(TTR("Filter Settings"));
  538. search_box->set_clear_button_enabled(true);
  539. search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  540. search_bar->add_child(search_box);
  541. advanced = memnew(CheckButton);
  542. advanced->set_text(TTR("Advanced Settings"));
  543. advanced->connect("toggled", callable_mp(this, &ProjectSettingsEditor::_advanced_toggled));
  544. search_bar->add_child(advanced);
  545. custom_properties = memnew(HBoxContainer);
  546. general_editor->add_child(custom_properties);
  547. property_box = memnew(LineEdit);
  548. property_box->set_placeholder(TTR("Select a Setting or Type its Name"));
  549. property_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  550. property_box->connect("text_changed", callable_mp(this, &ProjectSettingsEditor::_property_box_changed));
  551. custom_properties->add_child(property_box);
  552. feature_box = memnew(OptionButton);
  553. feature_box->set_custom_minimum_size(Size2(120, 0) * EDSCALE);
  554. feature_box->connect("item_selected", callable_mp(this, &ProjectSettingsEditor::_feature_selected));
  555. custom_properties->add_child(feature_box);
  556. type_box = memnew(OptionButton);
  557. type_box->set_custom_minimum_size(Size2(120, 0) * EDSCALE);
  558. custom_properties->add_child(type_box);
  559. add_button = memnew(Button);
  560. add_button->set_text(TTR("Add"));
  561. add_button->set_disabled(true);
  562. add_button->connect(SceneStringName(pressed), callable_mp(this, &ProjectSettingsEditor::_add_setting));
  563. custom_properties->add_child(add_button);
  564. del_button = memnew(Button);
  565. del_button->set_text(TTR("Delete"));
  566. del_button->set_disabled(true);
  567. del_button->connect(SceneStringName(pressed), callable_mp(this, &ProjectSettingsEditor::_delete_setting));
  568. custom_properties->add_child(del_button);
  569. general_settings_inspector = memnew(SectionedInspector);
  570. general_settings_inspector->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  571. general_settings_inspector->register_search_box(search_box);
  572. general_settings_inspector->get_inspector()->set_use_filter(true);
  573. general_settings_inspector->get_inspector()->connect("property_selected", callable_mp(this, &ProjectSettingsEditor::_setting_selected));
  574. general_settings_inspector->get_inspector()->connect("property_edited", callable_mp(this, &ProjectSettingsEditor::_setting_edited));
  575. general_settings_inspector->get_inspector()->connect("restart_requested", callable_mp(this, &ProjectSettingsEditor::_editor_restart_request));
  576. general_editor->add_child(general_settings_inspector);
  577. restart_container = memnew(PanelContainer);
  578. general_editor->add_child(restart_container);
  579. HBoxContainer *restart_hb = memnew(HBoxContainer);
  580. restart_container->hide();
  581. restart_container->add_child(restart_hb);
  582. restart_icon = memnew(TextureRect);
  583. restart_icon->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
  584. restart_hb->add_child(restart_icon);
  585. restart_label = memnew(Label);
  586. restart_label->set_text(TTR("Changed settings will be applied to the editor after restarting."));
  587. restart_hb->add_child(restart_label);
  588. restart_hb->add_spacer();
  589. Button *restart_button = memnew(Button);
  590. restart_button->connect(SceneStringName(pressed), callable_mp(this, &ProjectSettingsEditor::_editor_restart));
  591. restart_hb->add_child(restart_button);
  592. restart_button->set_text(TTR("Save & Restart"));
  593. restart_close_button = memnew(Button);
  594. restart_close_button->set_flat(true);
  595. restart_close_button->connect(SceneStringName(pressed), callable_mp(this, &ProjectSettingsEditor::_editor_restart_close));
  596. restart_hb->add_child(restart_close_button);
  597. action_map_editor = memnew(ActionMapEditor);
  598. action_map_editor->set_name(TTR("Input Map"));
  599. action_map_editor->connect("action_added", callable_mp(this, &ProjectSettingsEditor::_action_added));
  600. action_map_editor->connect("action_edited", callable_mp(this, &ProjectSettingsEditor::_action_edited));
  601. action_map_editor->connect("action_removed", callable_mp(this, &ProjectSettingsEditor::_action_removed));
  602. action_map_editor->connect("action_renamed", callable_mp(this, &ProjectSettingsEditor::_action_renamed));
  603. action_map_editor->connect("action_reordered", callable_mp(this, &ProjectSettingsEditor::_action_reordered));
  604. action_map_editor->connect(SNAME("filter_focused"), callable_mp((AcceptDialog *)this, &AcceptDialog::set_close_on_escape).bind(false));
  605. action_map_editor->connect(SNAME("filter_unfocused"), callable_mp((AcceptDialog *)this, &AcceptDialog::set_close_on_escape).bind(true));
  606. tab_container->add_child(action_map_editor);
  607. localization_editor = memnew(LocalizationEditor);
  608. localization_editor->set_name(TTR("Localization"));
  609. localization_editor->connect("localization_changed", callable_mp(this, &ProjectSettingsEditor::queue_save));
  610. tab_container->add_child(localization_editor);
  611. autoload_settings = memnew(EditorAutoloadSettings);
  612. autoload_settings->set_name(TTR("Autoload"));
  613. autoload_settings->connect("autoload_changed", callable_mp(this, &ProjectSettingsEditor::queue_save));
  614. tab_container->add_child(autoload_settings);
  615. shaders_global_shader_uniforms_editor = memnew(ShaderGlobalsEditor);
  616. shaders_global_shader_uniforms_editor->set_name(TTR("Shader Globals"));
  617. shaders_global_shader_uniforms_editor->connect("globals_changed", callable_mp(this, &ProjectSettingsEditor::queue_save));
  618. tab_container->add_child(shaders_global_shader_uniforms_editor);
  619. group_settings = memnew(GroupSettingsEditor);
  620. group_settings->set_name(TTR("Global Groups"));
  621. group_settings->connect("group_changed", callable_mp(this, &ProjectSettingsEditor::queue_save));
  622. tab_container->add_child(group_settings);
  623. plugin_settings = memnew(EditorPluginSettings);
  624. plugin_settings->set_name(TTR("Plugins"));
  625. tab_container->add_child(plugin_settings);
  626. timer = memnew(Timer);
  627. timer->set_wait_time(1.5);
  628. timer->connect("timeout", callable_mp(ps, &ProjectSettings::save));
  629. timer->set_one_shot(true);
  630. add_child(timer);
  631. set_ok_button_text(TTR("Close"));
  632. set_hide_on_ok(true);
  633. bool use_advanced = EditorSettings::get_singleton()->get_project_metadata("project_settings", "advanced_mode", false);
  634. if (use_advanced) {
  635. advanced->set_pressed(true);
  636. }
  637. _update_advanced(use_advanced);
  638. general_settings_inspector->set_restrict_to_basic_settings(!use_advanced);
  639. import_defaults_editor = memnew(ImportDefaultsEditor);
  640. import_defaults_editor->set_name(TTR("Import Defaults"));
  641. tab_container->add_child(import_defaults_editor);
  642. MovieWriter::set_extensions_hint(); // ensure extensions are properly displayed.
  643. }