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