project_settings_editor.cpp 29 KB

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