project_settings_editor.cpp 28 KB

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