project_settings_editor.cpp 28 KB

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