editor_settings.cpp 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720
  1. /**************************************************************************/
  2. /* editor_settings.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 "editor_settings.h"
  31. #include "core/config/project_settings.h"
  32. #include "core/input/input_event.h"
  33. #include "core/input/input_map.h"
  34. #include "core/input/shortcut.h"
  35. #include "core/io/certs_compressed.gen.h"
  36. #include "core/io/dir_access.h"
  37. #include "core/io/file_access.h"
  38. #include "core/io/ip.h"
  39. #include "core/io/resource_loader.h"
  40. #include "core/io/resource_saver.h"
  41. #include "core/object/class_db.h"
  42. #include "core/os/keyboard.h"
  43. #include "core/os/os.h"
  44. #include "core/string/translation.h"
  45. #include "core/version.h"
  46. #include "editor/editor_node.h"
  47. #include "editor/editor_paths.h"
  48. #include "editor/editor_translation.h"
  49. #include "scene/main/node.h"
  50. #include "scene/main/scene_tree.h"
  51. #include "scene/main/window.h"
  52. // PRIVATE METHODS
  53. Ref<EditorSettings> EditorSettings::singleton = nullptr;
  54. // Properties
  55. bool EditorSettings::_set(const StringName &p_name, const Variant &p_value) {
  56. _THREAD_SAFE_METHOD_
  57. bool changed = _set_only(p_name, p_value);
  58. if (changed) {
  59. changed_settings.insert(p_name);
  60. emit_signal(SNAME("settings_changed"));
  61. }
  62. return true;
  63. }
  64. bool EditorSettings::_set_only(const StringName &p_name, const Variant &p_value) {
  65. _THREAD_SAFE_METHOD_
  66. if (p_name == "shortcuts") {
  67. Array arr = p_value;
  68. for (int i = 0; i < arr.size(); i++) {
  69. Dictionary dict = arr[i];
  70. String shortcut_name = dict["name"];
  71. Array shortcut_events = dict["shortcuts"];
  72. Ref<Shortcut> sc;
  73. sc.instantiate();
  74. sc->set_events(shortcut_events);
  75. add_shortcut(shortcut_name, sc);
  76. }
  77. return false;
  78. } else if (p_name == "builtin_action_overrides") {
  79. Array actions_arr = p_value;
  80. for (int i = 0; i < actions_arr.size(); i++) {
  81. Dictionary action_dict = actions_arr[i];
  82. String action_name = action_dict["name"];
  83. Array events = action_dict["events"];
  84. InputMap *im = InputMap::get_singleton();
  85. im->action_erase_events(action_name);
  86. builtin_action_overrides[action_name].clear();
  87. for (int ev_idx = 0; ev_idx < events.size(); ev_idx++) {
  88. im->action_add_event(action_name, events[ev_idx]);
  89. builtin_action_overrides[action_name].push_back(events[ev_idx]);
  90. }
  91. }
  92. return false;
  93. }
  94. bool changed = false;
  95. if (p_value.get_type() == Variant::NIL) {
  96. if (props.has(p_name)) {
  97. props.erase(p_name);
  98. changed = true;
  99. }
  100. } else {
  101. if (props.has(p_name)) {
  102. if (p_value != props[p_name].variant) {
  103. props[p_name].variant = p_value;
  104. changed = true;
  105. }
  106. } else {
  107. props[p_name] = VariantContainer(p_value, last_order++);
  108. changed = true;
  109. }
  110. if (save_changed_setting) {
  111. if (!props[p_name].save) {
  112. props[p_name].save = true;
  113. changed = true;
  114. }
  115. }
  116. }
  117. return changed;
  118. }
  119. bool EditorSettings::_get(const StringName &p_name, Variant &r_ret) const {
  120. _THREAD_SAFE_METHOD_
  121. if (p_name == "shortcuts") {
  122. Array save_array;
  123. const HashMap<String, List<Ref<InputEvent>>> &builtin_list = InputMap::get_singleton()->get_builtins();
  124. for (const KeyValue<String, Ref<Shortcut>> &shortcut_definition : shortcuts) {
  125. Ref<Shortcut> sc = shortcut_definition.value;
  126. if (builtin_list.has(shortcut_definition.key)) {
  127. // This shortcut was auto-generated from built in actions: don't save.
  128. // If the builtin is overridden, it will be saved in the "builtin_action_overrides" section below.
  129. continue;
  130. }
  131. Array shortcut_events = sc->get_events();
  132. Dictionary dict;
  133. dict["name"] = shortcut_definition.key;
  134. dict["shortcuts"] = shortcut_events;
  135. if (!sc->has_meta("original")) {
  136. // Getting the meta when it doesn't exist will return an empty array. If the 'shortcut_events' have been cleared,
  137. // we still want save the shortcut in this case so that shortcuts that the user has customized are not reset,
  138. // even if the 'original' has not been populated yet. This can happen when calling save() from the Project Manager.
  139. save_array.push_back(dict);
  140. continue;
  141. }
  142. Array original_events = sc->get_meta("original");
  143. bool is_same = Shortcut::is_event_array_equal(original_events, shortcut_events);
  144. if (is_same) {
  145. continue; // Not changed from default; don't save.
  146. }
  147. save_array.push_back(dict);
  148. }
  149. r_ret = save_array;
  150. return true;
  151. } else if (p_name == "builtin_action_overrides") {
  152. Array actions_arr;
  153. for (const KeyValue<String, List<Ref<InputEvent>>> &action_override : builtin_action_overrides) {
  154. List<Ref<InputEvent>> events = action_override.value;
  155. Dictionary action_dict;
  156. action_dict["name"] = action_override.key;
  157. // Convert the list to an array, and only keep key events as this is for the editor.
  158. Array events_arr;
  159. for (const Ref<InputEvent> &ie : events) {
  160. Ref<InputEventKey> iek = ie;
  161. if (iek.is_valid()) {
  162. events_arr.append(iek);
  163. }
  164. }
  165. Array defaults_arr;
  166. List<Ref<InputEvent>> defaults = InputMap::get_singleton()->get_builtins()[action_override.key];
  167. for (const Ref<InputEvent> &default_input_event : defaults) {
  168. if (default_input_event.is_valid()) {
  169. defaults_arr.append(default_input_event);
  170. }
  171. }
  172. bool same = Shortcut::is_event_array_equal(events_arr, defaults_arr);
  173. // Don't save if same as default.
  174. if (same) {
  175. continue;
  176. }
  177. action_dict["events"] = events_arr;
  178. actions_arr.push_back(action_dict);
  179. }
  180. r_ret = actions_arr;
  181. return true;
  182. }
  183. const VariantContainer *v = props.getptr(p_name);
  184. if (!v) {
  185. WARN_PRINT("EditorSettings::_get - Property not found: " + String(p_name));
  186. return false;
  187. }
  188. r_ret = v->variant;
  189. return true;
  190. }
  191. void EditorSettings::_initial_set(const StringName &p_name, const Variant &p_value) {
  192. set(p_name, p_value);
  193. props[p_name].initial = p_value;
  194. props[p_name].has_default_value = true;
  195. }
  196. struct _EVCSort {
  197. String name;
  198. Variant::Type type = Variant::Type::NIL;
  199. int order = 0;
  200. bool save = false;
  201. bool restart_if_changed = false;
  202. bool operator<(const _EVCSort &p_vcs) const { return order < p_vcs.order; }
  203. };
  204. void EditorSettings::_get_property_list(List<PropertyInfo> *p_list) const {
  205. _THREAD_SAFE_METHOD_
  206. RBSet<_EVCSort> vclist;
  207. for (const KeyValue<String, VariantContainer> &E : props) {
  208. const VariantContainer *v = &E.value;
  209. if (v->hide_from_editor) {
  210. continue;
  211. }
  212. _EVCSort vc;
  213. vc.name = E.key;
  214. vc.order = v->order;
  215. vc.type = v->variant.get_type();
  216. vc.save = v->save;
  217. /*if (vc.save) { this should be implemented, but lets do after 3.1 is out.
  218. if (v->initial.get_type() != Variant::NIL && v->initial == v->variant) {
  219. vc.save = false;
  220. }
  221. }*/
  222. vc.restart_if_changed = v->restart_if_changed;
  223. vclist.insert(vc);
  224. }
  225. for (const _EVCSort &E : vclist) {
  226. uint32_t pusage = PROPERTY_USAGE_NONE;
  227. if (E.save || !optimize_save) {
  228. pusage |= PROPERTY_USAGE_STORAGE;
  229. }
  230. if (!E.name.begins_with("_") && !E.name.begins_with("projects/")) {
  231. pusage |= PROPERTY_USAGE_EDITOR;
  232. } else {
  233. pusage |= PROPERTY_USAGE_STORAGE; //hiddens must always be saved
  234. }
  235. PropertyInfo pi(E.type, E.name);
  236. pi.usage = pusage;
  237. if (hints.has(E.name)) {
  238. pi = hints[E.name];
  239. }
  240. if (E.restart_if_changed) {
  241. pi.usage |= PROPERTY_USAGE_RESTART_IF_CHANGED;
  242. }
  243. p_list->push_back(pi);
  244. }
  245. p_list->push_back(PropertyInfo(Variant::ARRAY, "shortcuts", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL)); //do not edit
  246. p_list->push_back(PropertyInfo(Variant::ARRAY, "builtin_action_overrides", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));
  247. }
  248. void EditorSettings::_add_property_info_bind(const Dictionary &p_info) {
  249. ERR_FAIL_COND(!p_info.has("name"));
  250. ERR_FAIL_COND(!p_info.has("type"));
  251. PropertyInfo pinfo;
  252. pinfo.name = p_info["name"];
  253. ERR_FAIL_COND(!props.has(pinfo.name));
  254. pinfo.type = Variant::Type(p_info["type"].operator int());
  255. ERR_FAIL_INDEX(pinfo.type, Variant::VARIANT_MAX);
  256. if (p_info.has("hint")) {
  257. pinfo.hint = PropertyHint(p_info["hint"].operator int());
  258. }
  259. if (p_info.has("hint_string")) {
  260. pinfo.hint_string = p_info["hint_string"];
  261. }
  262. add_property_hint(pinfo);
  263. }
  264. // Default configs
  265. bool EditorSettings::has_default_value(const String &p_setting) const {
  266. _THREAD_SAFE_METHOD_
  267. if (!props.has(p_setting)) {
  268. return false;
  269. }
  270. return props[p_setting].has_default_value;
  271. }
  272. void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
  273. _THREAD_SAFE_METHOD_
  274. // Sets up the editor setting with a default value and hint PropertyInfo.
  275. #define EDITOR_SETTING(m_type, m_property_hint, m_name, m_default_value, m_hint_string) \
  276. _initial_set(m_name, m_default_value); \
  277. hints[m_name] = PropertyInfo(m_type, m_name, m_property_hint, m_hint_string);
  278. #define EDITOR_SETTING_USAGE(m_type, m_property_hint, m_name, m_default_value, m_hint_string, m_usage) \
  279. _initial_set(m_name, m_default_value); \
  280. hints[m_name] = PropertyInfo(m_type, m_name, m_property_hint, m_hint_string, m_usage);
  281. /* Languages */
  282. {
  283. String lang_hint = "en";
  284. String host_lang = OS::get_singleton()->get_locale();
  285. // Skip locales if Text server lack required features.
  286. Vector<String> locales_to_skip;
  287. if (!TS->has_feature(TextServer::FEATURE_BIDI_LAYOUT) || !TS->has_feature(TextServer::FEATURE_SHAPING)) {
  288. locales_to_skip.push_back("ar"); // Arabic
  289. locales_to_skip.push_back("fa"); // Persian
  290. locales_to_skip.push_back("ur"); // Urdu
  291. }
  292. if (!TS->has_feature(TextServer::FEATURE_BIDI_LAYOUT)) {
  293. locales_to_skip.push_back("he"); // Hebrew
  294. }
  295. if (!TS->has_feature(TextServer::FEATURE_SHAPING)) {
  296. locales_to_skip.push_back("bn"); // Bengali
  297. locales_to_skip.push_back("hi"); // Hindi
  298. locales_to_skip.push_back("ml"); // Malayalam
  299. locales_to_skip.push_back("si"); // Sinhala
  300. locales_to_skip.push_back("ta"); // Tamil
  301. locales_to_skip.push_back("te"); // Telugu
  302. }
  303. if (!locales_to_skip.is_empty()) {
  304. WARN_PRINT("Some locales are not properly supported by selected Text Server and are disabled.");
  305. }
  306. String best;
  307. int best_score = 0;
  308. for (const String &locale : get_editor_locales()) {
  309. // Skip locales which we can't render properly (see above comment).
  310. // Test against language code without regional variants (e.g. ur_PK).
  311. String lang_code = locale.get_slice("_", 0);
  312. if (locales_to_skip.has(lang_code)) {
  313. continue;
  314. }
  315. lang_hint += ",";
  316. lang_hint += locale;
  317. int score = TranslationServer::get_singleton()->compare_locales(host_lang, locale);
  318. if (score > 0 && score >= best_score) {
  319. best = locale;
  320. best_score = score;
  321. }
  322. }
  323. if (best_score == 0) {
  324. best = "en";
  325. }
  326. EDITOR_SETTING_USAGE(Variant::STRING, PROPERTY_HINT_ENUM, "interface/editor/editor_language", best, lang_hint, PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
  327. }
  328. /* Interface */
  329. // Editor
  330. // Display what the Auto display scale setting effectively corresponds to.
  331. const String display_scale_hint_string = vformat("Auto (%d%%),75%%,100%%,125%%,150%%,175%%,200%%,Custom", Math::round(get_auto_display_scale() * 100));
  332. EDITOR_SETTING_USAGE(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/display_scale", 0, display_scale_hint_string, PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  333. String ed_screen_hints = "Screen With Mouse Pointer:-4,Screen With Keyboard Focus:-3,Primary Screen:-2"; // Note: Main Window Screen:-1 is not used for the main window.
  334. for (int i = 0; i < DisplayServer::get_singleton()->get_screen_count(); i++) {
  335. ed_screen_hints += ",Screen " + itos(i + 1) + ":" + itos(i);
  336. }
  337. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/editor_screen", -2, ed_screen_hints)
  338. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/project_manager_screen", -2, ed_screen_hints)
  339. _initial_set("interface/editor/debug/enable_pseudolocalization", false);
  340. set_restart_if_changed("interface/editor/debug/enable_pseudolocalization", true);
  341. // Use pseudolocalization in editor.
  342. EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/use_embedded_menu", false, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  343. EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/expand_to_title", true, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  344. EDITOR_SETTING_USAGE(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/editor/custom_display_scale", 1.0, "0.5,3,0.01", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  345. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/editor/main_font_size", 14, "8,48,1")
  346. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/editor/code_font_size", 14, "8,48,1")
  347. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/code_font_contextual_ligatures", 1, "Enabled,Disable Contextual Alternates (Coding Ligatures),Use Custom OpenType Feature Set")
  348. _initial_set("interface/editor/code_font_custom_opentype_features", "");
  349. _initial_set("interface/editor/code_font_custom_variations", "");
  350. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/font_antialiasing", 1, "None,Grayscale,LCD Subpixel")
  351. #ifdef MACOS_ENABLED
  352. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/font_hinting", 0, "Auto (None),None,Light,Normal")
  353. #else
  354. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/font_hinting", 0, "Auto (Light),None,Light,Normal")
  355. #endif
  356. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/font_subpixel_positioning", 1, "Disabled,Auto,One Half of a Pixel,One Quarter of a Pixel")
  357. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "interface/editor/main_font", "", "*.ttf,*.otf,*.woff,*.woff2,*.pfb,*.pfm")
  358. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "interface/editor/main_font_bold", "", "*.ttf,*.otf,*.woff,*.woff2,*.pfb,*.pfm")
  359. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "interface/editor/code_font", "", "*.ttf,*.otf,*.woff,*.woff2,*.pfb,*.pfm")
  360. EDITOR_SETTING_USAGE(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/editor/low_processor_mode_sleep_usec", 6900, "1,100000,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  361. // Default unfocused usec sleep is for 10 FPS. Allow an unfocused FPS limit
  362. // as low as 1 FPS for those who really need low power usage (but don't need
  363. // to preview particles or shaders while the editor is unfocused). With very
  364. // low FPS limits, the editor can take a small while to become usable after
  365. // being focused again, so this should be used at the user's discretion.
  366. EDITOR_SETTING_USAGE(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/editor/unfocused_low_processor_mode_sleep_usec", 100000, "1,1000000,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  367. _initial_set("interface/editor/separate_distraction_mode", false);
  368. _initial_set("interface/editor/automatically_open_screenshots", true);
  369. EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/single_window_mode", false, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  370. _initial_set("interface/editor/mouse_extra_buttons_navigate_history", true);
  371. _initial_set("interface/editor/save_each_scene_on_quit", true); // Regression
  372. EDITOR_SETTING_USAGE(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/accept_dialog_cancel_ok_buttons", 0,
  373. vformat("Auto (%s),Cancel First,OK First", DisplayServer::get_singleton()->get_swap_cancel_ok() ? "OK First" : "Cancel First"),
  374. PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
  375. #ifdef DEV_ENABLED
  376. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/show_internal_errors_in_toast_notifications", 0, "Auto (Enabled),Enabled,Disabled")
  377. #else
  378. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/show_internal_errors_in_toast_notifications", 0, "Auto (Disabled),Enabled,Disabled")
  379. #endif
  380. // Inspector
  381. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/inspector/max_array_dictionary_items_per_page", 20, "10,100,1")
  382. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/inspector/show_low_level_opentype_features", false, "")
  383. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/inspector/float_drag_speed", 5.0, "0.1,100,0.01")
  384. // Theme
  385. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_ENUM, "interface/theme/preset", "Default", "Default,Breeze Dark,Godot 2,Gray,Light,Solarized (Dark),Solarized (Light),Black (OLED),Custom")
  386. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/theme/icon_and_font_color", 0, "Auto,Dark,Light")
  387. EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "interface/theme/base_color", Color(0.2, 0.23, 0.31), "")
  388. EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "interface/theme/accent_color", Color(0.41, 0.61, 0.91), "")
  389. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/theme/contrast", 0.3, "-1,1,0.01")
  390. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/theme/draw_extra_borders", false, "")
  391. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/theme/icon_saturation", 1.0, "0,2,0.01")
  392. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/theme/relationship_line_opacity", 0.1, "0.00,1,0.01")
  393. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/theme/border_size", 0, "0,2,1")
  394. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/theme/corner_radius", 3, "0,6,1")
  395. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/theme/additional_spacing", 0.0, "0,5,0.1")
  396. EDITOR_SETTING_USAGE(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "interface/theme/custom_theme", "", "*.res,*.tres,*.theme", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  397. // Touchscreen
  398. bool has_touchscreen_ui = DisplayServer::get_singleton()->is_touchscreen_available();
  399. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/touchscreen/increase_scrollbar_touch_area", has_touchscreen_ui, "")
  400. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/touchscreen/enable_long_press_as_right_click", has_touchscreen_ui, "")
  401. set_restart_if_changed("interface/touchscreen/enable_long_press_as_right_click", true);
  402. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/touchscreen/enable_pan_and_scale_gestures", has_touchscreen_ui, "")
  403. set_restart_if_changed("interface/touchscreen/enable_pan_and_scale_gestures", true);
  404. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/touchscreen/scale_gizmo_handles", has_touchscreen_ui ? 3 : 1, "1,5,1")
  405. // Scene tabs
  406. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/scene_tabs/display_close_button", 1, "Never,If Tab Active,Always"); // TabBar::CloseButtonDisplayPolicy
  407. _initial_set("interface/scene_tabs/show_thumbnail_on_hover", true);
  408. EDITOR_SETTING_USAGE(Variant::INT, PROPERTY_HINT_RANGE, "interface/scene_tabs/maximum_width", 350, "0,9999,1", PROPERTY_USAGE_DEFAULT)
  409. _initial_set("interface/scene_tabs/show_script_button", false);
  410. // Multi Window
  411. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/multi_window/enable", true, "");
  412. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/multi_window/restore_windows_on_load", true, "");
  413. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/multi_window/maximize_window", false, "");
  414. set_restart_if_changed("interface/multi_window/enable", true);
  415. /* Filesystem */
  416. // External Programs
  417. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "filesystem/external_programs/raster_image_editor", "", "")
  418. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "filesystem/external_programs/vector_image_editor", "", "")
  419. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "filesystem/external_programs/audio_editor", "", "")
  420. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "filesystem/external_programs/3d_model_editor", "", "")
  421. // Directories
  422. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_DIR, "filesystem/directories/autoscan_project_path", "", "")
  423. const String fs_dir_default_project_path = OS::get_singleton()->has_environment("HOME") ? OS::get_singleton()->get_environment("HOME") : OS::get_singleton()->get_system_dir(OS::SYSTEM_DIR_DOCUMENTS);
  424. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_DIR, "filesystem/directories/default_project_path", fs_dir_default_project_path, "")
  425. // On save
  426. _initial_set("filesystem/on_save/compress_binary_resources", true);
  427. _initial_set("filesystem/on_save/safe_save_on_backup_then_rename", true);
  428. // File dialog
  429. _initial_set("filesystem/file_dialog/show_hidden_files", false);
  430. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "filesystem/file_dialog/display_mode", 0, "Thumbnails,List")
  431. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "filesystem/file_dialog/thumbnail_size", 64, "32,128,16")
  432. /* Docks */
  433. // SceneTree
  434. _initial_set("docks/scene_tree/start_create_dialog_fully_expanded", false);
  435. _initial_set("docks/scene_tree/auto_expand_to_selected", true);
  436. // FileSystem
  437. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "docks/filesystem/thumbnail_size", 64, "32,128,16")
  438. _initial_set("docks/filesystem/always_show_folders", true);
  439. _initial_set("docks/filesystem/textfile_extensions", "txt,md,cfg,ini,log,json,yml,yaml,toml");
  440. // Property editor
  441. _initial_set("docks/property_editor/auto_refresh_interval", 0.2); //update 5 times per second by default
  442. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "docks/property_editor/subresource_hue_tint", 0.75, "0,1,0.01")
  443. /* Text editor */
  444. // Theme
  445. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_ENUM, "text_editor/theme/color_theme", "Default", "Default,Godot 2,Custom")
  446. // Theme: Highlighting
  447. _load_godot2_text_editor_theme();
  448. // Appearance
  449. // Appearance: Caret
  450. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/appearance/caret/type", 0, "Line,Block")
  451. _initial_set("text_editor/appearance/caret/caret_blink", true);
  452. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "text_editor/appearance/caret/caret_blink_interval", 0.5, "0.1,10,0.01")
  453. _initial_set("text_editor/appearance/caret/highlight_current_line", true);
  454. _initial_set("text_editor/appearance/caret/highlight_all_occurrences", true);
  455. // Appearance: Guidelines
  456. _initial_set("text_editor/appearance/guidelines/show_line_length_guidelines", true);
  457. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/appearance/guidelines/line_length_guideline_soft_column", 80, "20,160,1")
  458. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/appearance/guidelines/line_length_guideline_hard_column", 100, "20,160,1")
  459. // Appearance: Gutters
  460. _initial_set("text_editor/appearance/gutters/show_line_numbers", true);
  461. _initial_set("text_editor/appearance/gutters/line_numbers_zero_padded", false);
  462. _initial_set("text_editor/appearance/gutters/highlight_type_safe_lines", true);
  463. _initial_set("text_editor/appearance/gutters/show_info_gutter", true);
  464. // Appearance: Minimap
  465. _initial_set("text_editor/appearance/minimap/show_minimap", true);
  466. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/appearance/minimap/minimap_width", 80, "50,250,1")
  467. // Appearance: Lines
  468. _initial_set("text_editor/appearance/lines/code_folding", true);
  469. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/appearance/lines/word_wrap", 0, "None,Boundary")
  470. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/appearance/lines/autowrap_mode", 3, "Arbitrary:1,Word:2,Word (Smart):3")
  471. // Appearance: Whitespace
  472. _initial_set("text_editor/appearance/whitespace/draw_tabs", true);
  473. _initial_set("text_editor/appearance/whitespace/draw_spaces", false);
  474. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/appearance/whitespace/line_spacing", 4, "0,50,1")
  475. // Behavior
  476. // Behavior: Navigation
  477. _initial_set("text_editor/behavior/navigation/move_caret_on_right_click", true);
  478. _initial_set("text_editor/behavior/navigation/scroll_past_end_of_file", false);
  479. _initial_set("text_editor/behavior/navigation/smooth_scrolling", true);
  480. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/behavior/navigation/v_scroll_speed", 80, "1,10000,1")
  481. _initial_set("text_editor/behavior/navigation/drag_and_drop_selection", true);
  482. _initial_set("text_editor/behavior/navigation/stay_in_script_editor_on_node_selected", true);
  483. // Behavior: Indent
  484. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/behavior/indent/type", 0, "Tabs,Spaces")
  485. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/behavior/indent/size", 4, "1,64,1") // size of 0 crashes.
  486. _initial_set("text_editor/behavior/indent/auto_indent", true);
  487. // Behavior: Files
  488. _initial_set("text_editor/behavior/files/trim_trailing_whitespace_on_save", false);
  489. _initial_set("text_editor/behavior/files/autosave_interval_secs", 0);
  490. _initial_set("text_editor/behavior/files/restore_scripts_on_load", true);
  491. _initial_set("text_editor/behavior/files/convert_indent_on_save", true);
  492. _initial_set("text_editor/behavior/files/auto_reload_scripts_on_external_change", false);
  493. // Script list
  494. _initial_set("text_editor/script_list/show_members_overview", true);
  495. _initial_set("text_editor/script_list/sort_members_outline_alphabetically", false);
  496. // Completion
  497. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "text_editor/completion/idle_parse_delay", 2.0, "0.1,10,0.01")
  498. _initial_set("text_editor/completion/auto_brace_complete", true);
  499. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "text_editor/completion/code_complete_delay", 0.3, "0.01,5,0.01")
  500. _initial_set("text_editor/completion/put_callhint_tooltip_below_current_line", true);
  501. _initial_set("text_editor/completion/complete_file_paths", true);
  502. _initial_set("text_editor/completion/add_type_hints", false);
  503. _initial_set("text_editor/completion/use_single_quotes", false);
  504. // Help
  505. _initial_set("text_editor/help/show_help_index", true);
  506. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/help/help_font_size", 16, "8,48,1")
  507. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/help/help_source_font_size", 15, "8,48,1")
  508. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/help/help_title_font_size", 23, "8,64,1")
  509. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/help/class_reference_examples", 0, "GDScript,C#,GDScript and C#")
  510. /* Editors */
  511. // GridMap
  512. _initial_set("editors/grid_map/pick_distance", 5000.0);
  513. // 3D
  514. EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d/primary_grid_color", Color(0.56, 0.56, 0.56, 0.5), "")
  515. EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d/secondary_grid_color", Color(0.38, 0.38, 0.38, 0.5), "")
  516. // Use a similar color to the 2D editor selection.
  517. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d/selection_box_color", Color(1.0, 0.5, 0), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  518. _initial_set("editors/3d_gizmos/gizmo_colors/instantiated", Color(0.7, 0.7, 0.7, 0.6));
  519. _initial_set("editors/3d_gizmos/gizmo_colors/joint", Color(0.5, 0.8, 1));
  520. _initial_set("editors/3d_gizmos/gizmo_colors/shape", Color(0.5, 0.7, 1));
  521. // If a line is a multiple of this, it uses the primary grid color.
  522. // Use a power of 2 value by default as it's more common to use powers of 2 in level design.
  523. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "editors/3d/primary_grid_steps", 8, "1,100,1")
  524. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "editors/3d/grid_size", 200, "1,2000,1")
  525. // Higher values produce graphical artifacts when far away unless View Z-Far
  526. // is increased significantly more than it really should need to be.
  527. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "editors/3d/grid_division_level_max", 2, "-1,3,1")
  528. // Lower values produce graphical artifacts regardless of view clipping planes, so limit to -2 as a lower bound.
  529. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "editors/3d/grid_division_level_min", 0, "-2,2,1")
  530. // -0.2 seems like a sensible default. -1.0 gives Blender-like behavior, 0.5 gives huge grids.
  531. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/grid_division_level_bias", -0.2, "-1.0,0.5,0.1")
  532. _initial_set("editors/3d/grid_xz_plane", true);
  533. _initial_set("editors/3d/grid_xy_plane", false);
  534. _initial_set("editors/3d/grid_yz_plane", false);
  535. // Use a lower default FOV for the 3D camera compared to the
  536. // Camera3D node as the 3D viewport doesn't span the whole screen.
  537. // This means it's technically viewed from a further distance, which warrants a narrower FOV.
  538. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/default_fov", 70.0, "1,179,0.1,degrees")
  539. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/default_z_near", 0.05, "0.01,10,0.01,or_greater,suffix:m")
  540. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/default_z_far", 4000.0, "0.1,4000,0.1,or_greater,suffix:m")
  541. // 3D: Navigation
  542. _initial_set("editors/3d/navigation/invert_x_axis", false);
  543. _initial_set("editors/3d/navigation/invert_y_axis", false);
  544. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/navigation_scheme", 0, "Godot,Maya,Modo")
  545. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/zoom_style", 0, "Vertical,Horizontal")
  546. _initial_set("editors/3d/navigation/emulate_numpad", false);
  547. _initial_set("editors/3d/navigation/emulate_3_button_mouse", false);
  548. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/orbit_modifier", 0, "None,Shift,Alt,Meta,Ctrl")
  549. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/pan_modifier", 1, "None,Shift,Alt,Meta,Ctrl")
  550. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/zoom_modifier", 4, "None,Shift,Alt,Meta,Ctrl")
  551. _initial_set("editors/3d/navigation/warped_mouse_panning", true);
  552. // 3D: Navigation feel
  553. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/navigation_feel/orbit_sensitivity", 0.25, "0.01,2,0.001")
  554. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/navigation_feel/orbit_inertia", 0.0, "0,1,0.001")
  555. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/navigation_feel/translation_inertia", 0.05, "0,1,0.001")
  556. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/navigation_feel/zoom_inertia", 0.05, "0,1,0.001")
  557. // 3D: Freelook
  558. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/freelook/freelook_navigation_scheme", 0, "Default,Partially Axis-Locked (id Tech),Fully Axis-Locked (Minecraft)")
  559. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/freelook/freelook_sensitivity", 0.25, "0.01,2,0.001")
  560. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/freelook/freelook_inertia", 0.0, "0,1,0.001")
  561. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/freelook/freelook_base_speed", 5.0, "0,10,0.01")
  562. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/freelook/freelook_activation_modifier", 0, "None,Shift,Alt,Meta,Ctrl")
  563. _initial_set("editors/3d/freelook/freelook_speed_zoom_link", false);
  564. // 2D
  565. _initial_set("editors/2d/grid_color", Color(1.0, 1.0, 1.0, 0.07));
  566. _initial_set("editors/2d/guides_color", Color(0.6, 0.0, 0.8));
  567. _initial_set("editors/2d/smart_snapping_line_color", Color(0.9, 0.1, 0.1));
  568. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/2d/bone_width", 5.0, "0.01,20,0.01,or_greater")
  569. _initial_set("editors/2d/bone_color1", Color(1.0, 1.0, 1.0, 0.7));
  570. _initial_set("editors/2d/bone_color2", Color(0.6, 0.6, 0.6, 0.7));
  571. _initial_set("editors/2d/bone_selected_color", Color(0.9, 0.45, 0.45, 0.7));
  572. _initial_set("editors/2d/bone_ik_color", Color(0.9, 0.9, 0.45, 0.7));
  573. _initial_set("editors/2d/bone_outline_color", Color(0.35, 0.35, 0.35, 0.5));
  574. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/2d/bone_outline_size", 2.0, "0.01,8,0.01,or_greater")
  575. _initial_set("editors/2d/viewport_border_color", Color(0.4, 0.4, 1.0, 0.4));
  576. // Panning
  577. // Enum should be in sync with ControlScheme in ViewPanner.
  578. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/panning/2d_editor_panning_scheme", 0, "Scroll Zooms,Scroll Pans");
  579. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/panning/sub_editors_panning_scheme", 0, "Scroll Zooms,Scroll Pans");
  580. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/panning/animation_editors_panning_scheme", 1, "Scroll Zooms,Scroll Pans");
  581. _initial_set("editors/panning/simple_panning", false);
  582. _initial_set("editors/panning/warped_mouse_panning", true);
  583. _initial_set("editors/panning/2d_editor_pan_speed", 20);
  584. // Tiles editor
  585. _initial_set("editors/tiles_editor/display_grid", true);
  586. _initial_set("editors/tiles_editor/grid_color", Color(1.0, 0.5, 0.2, 0.5));
  587. // Polygon editor
  588. _initial_set("editors/polygon_editor/point_grab_radius", has_touchscreen_ui ? 32 : 8);
  589. _initial_set("editors/polygon_editor/show_previous_outline", true);
  590. // Animation
  591. _initial_set("editors/animation/autorename_animation_tracks", true);
  592. _initial_set("editors/animation/confirm_insert_track", true);
  593. _initial_set("editors/animation/default_create_bezier_tracks", false);
  594. _initial_set("editors/animation/default_create_reset_tracks", true);
  595. _initial_set("editors/animation/onion_layers_past_color", Color(1, 0, 0));
  596. _initial_set("editors/animation/onion_layers_future_color", Color(0, 1, 0));
  597. // Shader editor
  598. _initial_set("editors/shader_editor/behavior/files/restore_shaders_on_load", true);
  599. // Visual editors
  600. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/visual_editors/minimap_opacity", 0.85, "0.0,1.0,0.01")
  601. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/visual_editors/lines_curvature", 0.5, "0.0,1.0,0.01")
  602. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "editors/visual_editors/visual_shader/port_preview_size", 160, "100,400,0.01")
  603. /* Run */
  604. // Window placement
  605. #ifndef ANDROID_ENABLED
  606. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "run/window_placement/rect", 1, "Top Left,Centered,Custom Position,Force Maximized,Force Fullscreen")
  607. // Keep the enum values in sync with the `DisplayServer::SCREEN_` enum.
  608. String screen_hints = "Same as Editor:-5,Previous Screen:-4,Next Screen:-3,Primary Screen:-2"; // Note: Main Window Screen:-1 is not used for the main window.
  609. for (int i = 0; i < DisplayServer::get_singleton()->get_screen_count(); i++) {
  610. screen_hints += ",Screen " + itos(i + 1) + ":" + itos(i);
  611. }
  612. _initial_set("run/window_placement/rect_custom_position", Vector2());
  613. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "run/window_placement/screen", -5, screen_hints)
  614. #endif
  615. // Should match the ANDROID_WINDOW_* constants in 'platform/android/java/editor/src/main/java/org/godotengine/editor/GodotEditor.kt'
  616. String android_window_hints = "Auto (based on screen size):0,Same as Editor:1,Side-by-side with Editor:2";
  617. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "run/window_placement/android_window", 0, android_window_hints)
  618. // Auto save
  619. _initial_set("run/auto_save/save_before_running", true);
  620. // Output
  621. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "run/output/font_size", 13, "8,48,1")
  622. _initial_set("run/output/always_clear_output_on_play", true);
  623. _initial_set("run/output/always_open_output_on_play", true);
  624. _initial_set("run/output/always_close_output_on_stop", false);
  625. /* Network */
  626. // Debug
  627. _initial_set("network/debug/remote_host", "127.0.0.1"); // Hints provided in setup_network
  628. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "network/debug/remote_port", 6007, "1,65535,1")
  629. // SSL
  630. EDITOR_SETTING_USAGE(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "network/tls/editor_tls_certificates", _SYSTEM_CERTS_PATH, "*.crt,*.pem", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
  631. // Debugger/profiler
  632. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "debugger/auto_switch_to_remote_scene_tree", false, "")
  633. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "debugger/profiler_frame_history_size", 3600, "60,10000,1")
  634. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "debugger/profiler_frame_max_functions", 64, "16,512,1")
  635. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "debugger/remote_scene_tree_refresh_interval", 1.0, "0.1,10,0.01,or_greater")
  636. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "debugger/remote_inspect_refresh_interval", 0.2, "0.02,10,0.01,or_greater")
  637. // HTTP Proxy
  638. _initial_set("network/http_proxy/host", "");
  639. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "network/http_proxy/port", 8080, "1,65535,1")
  640. /* Extra config */
  641. // TRANSLATORS: Project Manager here refers to the tool used to create/manage Godot projects.
  642. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "project_manager/sorting_order", 0, "Last Edited,Name,Path")
  643. #if defined(WEB_ENABLED)
  644. // Web platform only supports `gl_compatibility`.
  645. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_ENUM, "project_manager/default_renderer", "gl_compatibility", "forward_plus,mobile,gl_compatibility")
  646. #elif defined(ANDROID_ENABLED)
  647. // Use more suitable rendering method by default.
  648. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_ENUM, "project_manager/default_renderer", "mobile", "forward_plus,mobile,gl_compatibility")
  649. #else
  650. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_ENUM, "project_manager/default_renderer", "forward_plus", "forward_plus,mobile,gl_compatibility")
  651. #endif
  652. if (p_extra_config.is_valid()) {
  653. if (p_extra_config->has_section("init_projects") && p_extra_config->has_section_key("init_projects", "list")) {
  654. Vector<String> list = p_extra_config->get_value("init_projects", "list");
  655. for (int i = 0; i < list.size(); i++) {
  656. String proj_name = list[i].replace("/", "::");
  657. set("projects/" + proj_name, list[i]);
  658. }
  659. }
  660. if (p_extra_config->has_section("presets")) {
  661. List<String> keys;
  662. p_extra_config->get_section_keys("presets", &keys);
  663. for (const String &key : keys) {
  664. Variant val = p_extra_config->get_value("presets", key);
  665. set(key, val);
  666. }
  667. }
  668. }
  669. }
  670. void EditorSettings::_load_godot2_text_editor_theme() {
  671. // Godot 2 is only a dark theme; it doesn't have a light theme counterpart.
  672. _initial_set("text_editor/theme/highlighting/symbol_color", Color(0.73, 0.87, 1.0));
  673. _initial_set("text_editor/theme/highlighting/keyword_color", Color(1.0, 1.0, 0.7));
  674. _initial_set("text_editor/theme/highlighting/control_flow_keyword_color", Color(1.0, 0.85, 0.7));
  675. _initial_set("text_editor/theme/highlighting/base_type_color", Color(0.64, 1.0, 0.83));
  676. _initial_set("text_editor/theme/highlighting/engine_type_color", Color(0.51, 0.83, 1.0));
  677. _initial_set("text_editor/theme/highlighting/user_type_color", Color(0.42, 0.67, 0.93));
  678. _initial_set("text_editor/theme/highlighting/comment_color", Color(0.4, 0.4, 0.4));
  679. _initial_set("text_editor/theme/highlighting/string_color", Color(0.94, 0.43, 0.75));
  680. _initial_set("text_editor/theme/highlighting/background_color", Color(0.13, 0.12, 0.15));
  681. _initial_set("text_editor/theme/highlighting/completion_background_color", Color(0.17, 0.16, 0.2));
  682. _initial_set("text_editor/theme/highlighting/completion_selected_color", Color(0.26, 0.26, 0.27));
  683. _initial_set("text_editor/theme/highlighting/completion_existing_color", Color(0.87, 0.87, 0.87, 0.13));
  684. _initial_set("text_editor/theme/highlighting/completion_scroll_color", Color(1, 1, 1, 0.29));
  685. _initial_set("text_editor/theme/highlighting/completion_scroll_hovered_color", Color(1, 1, 1, 0.4));
  686. _initial_set("text_editor/theme/highlighting/completion_font_color", Color(0.67, 0.67, 0.67));
  687. _initial_set("text_editor/theme/highlighting/text_color", Color(0.67, 0.67, 0.67));
  688. _initial_set("text_editor/theme/highlighting/line_number_color", Color(0.67, 0.67, 0.67, 0.4));
  689. _initial_set("text_editor/theme/highlighting/safe_line_number_color", Color(0.67, 0.78, 0.67, 0.6));
  690. _initial_set("text_editor/theme/highlighting/caret_color", Color(0.67, 0.67, 0.67));
  691. _initial_set("text_editor/theme/highlighting/caret_background_color", Color(0, 0, 0));
  692. _initial_set("text_editor/theme/highlighting/text_selected_color", Color(0, 0, 0, 0));
  693. _initial_set("text_editor/theme/highlighting/selection_color", Color(0.41, 0.61, 0.91, 0.35));
  694. _initial_set("text_editor/theme/highlighting/brace_mismatch_color", Color(1, 0.2, 0.2));
  695. _initial_set("text_editor/theme/highlighting/current_line_color", Color(0.3, 0.5, 0.8, 0.15));
  696. _initial_set("text_editor/theme/highlighting/line_length_guideline_color", Color(0.3, 0.5, 0.8, 0.1));
  697. _initial_set("text_editor/theme/highlighting/word_highlighted_color", Color(0.8, 0.9, 0.9, 0.15));
  698. _initial_set("text_editor/theme/highlighting/number_color", Color(0.92, 0.58, 0.2));
  699. _initial_set("text_editor/theme/highlighting/function_color", Color(0.4, 0.64, 0.81));
  700. _initial_set("text_editor/theme/highlighting/member_variable_color", Color(0.9, 0.31, 0.35));
  701. _initial_set("text_editor/theme/highlighting/mark_color", Color(1.0, 0.4, 0.4, 0.4));
  702. _initial_set("text_editor/theme/highlighting/bookmark_color", Color(0.08, 0.49, 0.98));
  703. _initial_set("text_editor/theme/highlighting/breakpoint_color", Color(0.9, 0.29, 0.3));
  704. _initial_set("text_editor/theme/highlighting/executing_line_color", Color(0.98, 0.89, 0.27));
  705. _initial_set("text_editor/theme/highlighting/code_folding_color", Color(0.8, 0.8, 0.8, 0.8));
  706. _initial_set("text_editor/theme/highlighting/search_result_color", Color(0.05, 0.25, 0.05, 1));
  707. _initial_set("text_editor/theme/highlighting/search_result_border_color", Color(0.41, 0.61, 0.91, 0.38));
  708. }
  709. bool EditorSettings::_save_text_editor_theme(String p_file) {
  710. String theme_section = "color_theme";
  711. Ref<ConfigFile> cf = memnew(ConfigFile); // hex is better?
  712. List<String> keys;
  713. for (const KeyValue<String, VariantContainer> &E : props) {
  714. keys.push_back(E.key);
  715. }
  716. keys.sort();
  717. for (const String &key : keys) {
  718. if (key.begins_with("text_editor/theme/highlighting/") && key.find("color") >= 0) {
  719. cf->set_value(theme_section, key.replace("text_editor/theme/highlighting/", ""), ((Color)props[key].variant).to_html());
  720. }
  721. }
  722. Error err = cf->save(p_file);
  723. return err == OK;
  724. }
  725. bool EditorSettings::_is_default_text_editor_theme(String p_theme_name) {
  726. return p_theme_name == "default" || p_theme_name == "godot 2" || p_theme_name == "custom";
  727. }
  728. // PUBLIC METHODS
  729. EditorSettings *EditorSettings::get_singleton() {
  730. return singleton.ptr();
  731. }
  732. void EditorSettings::create() {
  733. // IMPORTANT: create() *must* create a valid EditorSettings singleton,
  734. // as the rest of the engine code will assume it. As such, it should never
  735. // return (incl. via ERR_FAIL) without initializing the singleton member.
  736. if (singleton.ptr()) {
  737. ERR_PRINT("Can't recreate EditorSettings as it already exists.");
  738. return;
  739. }
  740. GDREGISTER_CLASS(EditorSettings); // Otherwise it can't be unserialized.
  741. String config_file_path;
  742. Ref<ConfigFile> extra_config = memnew(ConfigFile);
  743. if (!EditorPaths::get_singleton()) {
  744. ERR_PRINT("Bug (please report): EditorPaths haven't been initialized, EditorSettings cannot be created properly.");
  745. goto fail;
  746. }
  747. if (EditorPaths::get_singleton()->is_self_contained()) {
  748. Error err = extra_config->load(EditorPaths::get_singleton()->get_self_contained_file());
  749. if (err != OK) {
  750. ERR_PRINT("Can't load extra config from path: " + EditorPaths::get_singleton()->get_self_contained_file());
  751. }
  752. }
  753. if (EditorPaths::get_singleton()->are_paths_valid()) {
  754. // Validate editor config file.
  755. Ref<DirAccess> dir = DirAccess::open(EditorPaths::get_singleton()->get_config_dir());
  756. String config_file_name = "editor_settings-" + itos(VERSION_MAJOR) + ".tres";
  757. config_file_path = EditorPaths::get_singleton()->get_config_dir().path_join(config_file_name);
  758. if (!dir->file_exists(config_file_name)) {
  759. goto fail;
  760. }
  761. singleton = ResourceLoader::load(config_file_path, "EditorSettings");
  762. if (singleton.is_null()) {
  763. ERR_PRINT("Could not load editor settings from path: " + config_file_path);
  764. goto fail;
  765. }
  766. singleton->save_changed_setting = true;
  767. print_verbose("EditorSettings: Load OK!");
  768. singleton->setup_language();
  769. singleton->setup_network();
  770. singleton->load_favorites_and_recent_dirs();
  771. singleton->list_text_editor_themes();
  772. return;
  773. }
  774. fail:
  775. // patch init projects
  776. String exe_path = OS::get_singleton()->get_executable_path().get_base_dir();
  777. if (extra_config->has_section("init_projects")) {
  778. Vector<String> list = extra_config->get_value("init_projects", "list");
  779. for (int i = 0; i < list.size(); i++) {
  780. list.write[i] = exe_path.path_join(list[i]);
  781. }
  782. extra_config->set_value("init_projects", "list", list);
  783. }
  784. singleton = Ref<EditorSettings>(memnew(EditorSettings));
  785. singleton->set_path(config_file_path, true);
  786. singleton->save_changed_setting = true;
  787. singleton->_load_defaults(extra_config);
  788. singleton->setup_language();
  789. singleton->setup_network();
  790. singleton->list_text_editor_themes();
  791. }
  792. void EditorSettings::setup_language() {
  793. TranslationServer::get_singleton()->set_editor_pseudolocalization(get("interface/editor/debug/enable_pseudolocalization"));
  794. String lang = get("interface/editor/editor_language");
  795. if (lang == "en") {
  796. return; // Default, nothing to do.
  797. }
  798. // Load editor translation for configured/detected locale.
  799. load_editor_translations(lang);
  800. load_property_translations(lang);
  801. // Load class reference translation.
  802. load_doc_translations(lang);
  803. }
  804. void EditorSettings::setup_network() {
  805. List<IPAddress> local_ip;
  806. IP::get_singleton()->get_local_addresses(&local_ip);
  807. String hint;
  808. String current = has_setting("network/debug/remote_host") ? get("network/debug/remote_host") : "";
  809. String selected = "127.0.0.1";
  810. // Check that current remote_host is a valid interface address and populate hints.
  811. for (const IPAddress &ip : local_ip) {
  812. // link-local IPv6 addresses don't work, skipping them
  813. if (String(ip).begins_with("fe80:0:0:0:")) { // fe80::/64
  814. continue;
  815. }
  816. // Same goes for IPv4 link-local (APIPA) addresses.
  817. if (String(ip).begins_with("169.254.")) { // 169.254.0.0/16
  818. continue;
  819. }
  820. // Select current IP (found)
  821. if (ip == current) {
  822. selected = ip;
  823. }
  824. if (!hint.is_empty()) {
  825. hint += ",";
  826. }
  827. hint += ip;
  828. }
  829. // Add hints with valid IP addresses to remote_host property.
  830. add_property_hint(PropertyInfo(Variant::STRING, "network/debug/remote_host", PROPERTY_HINT_ENUM, hint));
  831. // Fix potentially invalid remote_host due to network change.
  832. set("network/debug/remote_host", selected);
  833. }
  834. void EditorSettings::save() {
  835. //_THREAD_SAFE_METHOD_
  836. if (!singleton.ptr()) {
  837. return;
  838. }
  839. Error err = ResourceSaver::save(singleton);
  840. if (err != OK) {
  841. ERR_PRINT("Error saving editor settings to " + singleton->get_path());
  842. } else {
  843. singleton->changed_settings.clear();
  844. print_verbose("EditorSettings: Save OK!");
  845. }
  846. }
  847. PackedStringArray EditorSettings::get_changed_settings() const {
  848. PackedStringArray arr;
  849. for (const String &setting : changed_settings) {
  850. arr.push_back(setting);
  851. }
  852. return arr;
  853. }
  854. bool EditorSettings::check_changed_settings_in_group(const String &p_setting_prefix) const {
  855. for (const String &setting : changed_settings) {
  856. if (setting.begins_with(p_setting_prefix)) {
  857. return true;
  858. }
  859. }
  860. return false;
  861. }
  862. void EditorSettings::mark_setting_changed(const String &p_setting) {
  863. changed_settings.insert(p_setting);
  864. }
  865. void EditorSettings::destroy() {
  866. if (!singleton.ptr()) {
  867. return;
  868. }
  869. save();
  870. singleton = Ref<EditorSettings>();
  871. }
  872. void EditorSettings::set_optimize_save(bool p_optimize) {
  873. optimize_save = p_optimize;
  874. }
  875. // Properties
  876. void EditorSettings::set_setting(const String &p_setting, const Variant &p_value) {
  877. _THREAD_SAFE_METHOD_
  878. set(p_setting, p_value);
  879. }
  880. Variant EditorSettings::get_setting(const String &p_setting) const {
  881. _THREAD_SAFE_METHOD_
  882. return get(p_setting);
  883. }
  884. bool EditorSettings::has_setting(const String &p_setting) const {
  885. _THREAD_SAFE_METHOD_
  886. return props.has(p_setting);
  887. }
  888. void EditorSettings::erase(const String &p_setting) {
  889. _THREAD_SAFE_METHOD_
  890. props.erase(p_setting);
  891. }
  892. void EditorSettings::raise_order(const String &p_setting) {
  893. _THREAD_SAFE_METHOD_
  894. ERR_FAIL_COND(!props.has(p_setting));
  895. props[p_setting].order = ++last_order;
  896. }
  897. void EditorSettings::set_restart_if_changed(const StringName &p_setting, bool p_restart) {
  898. _THREAD_SAFE_METHOD_
  899. if (!props.has(p_setting)) {
  900. return;
  901. }
  902. props[p_setting].restart_if_changed = p_restart;
  903. }
  904. void EditorSettings::set_initial_value(const StringName &p_setting, const Variant &p_value, bool p_update_current) {
  905. _THREAD_SAFE_METHOD_
  906. if (!props.has(p_setting)) {
  907. return;
  908. }
  909. props[p_setting].initial = p_value;
  910. props[p_setting].has_default_value = true;
  911. if (p_update_current) {
  912. set(p_setting, p_value);
  913. }
  914. }
  915. Variant _EDITOR_DEF(const String &p_setting, const Variant &p_default, bool p_restart_if_changed) {
  916. ERR_FAIL_NULL_V_MSG(EditorSettings::get_singleton(), p_default, "EditorSettings not instantiated yet.");
  917. Variant ret = p_default;
  918. if (EditorSettings::get_singleton()->has_setting(p_setting)) {
  919. ret = EDITOR_GET(p_setting);
  920. } else {
  921. EditorSettings::get_singleton()->set_manually(p_setting, p_default);
  922. EditorSettings::get_singleton()->set_restart_if_changed(p_setting, p_restart_if_changed);
  923. }
  924. if (!EditorSettings::get_singleton()->has_default_value(p_setting)) {
  925. EditorSettings::get_singleton()->set_initial_value(p_setting, p_default);
  926. }
  927. return ret;
  928. }
  929. Variant _EDITOR_GET(const String &p_setting) {
  930. ERR_FAIL_COND_V(!EditorSettings::get_singleton() || !EditorSettings::get_singleton()->has_setting(p_setting), Variant());
  931. return EditorSettings::get_singleton()->get(p_setting);
  932. }
  933. bool EditorSettings::_property_can_revert(const StringName &p_name) const {
  934. if (!props.has(p_name)) {
  935. return false;
  936. }
  937. if (!props[p_name].has_default_value) {
  938. return false;
  939. }
  940. return props[p_name].initial != props[p_name].variant;
  941. }
  942. bool EditorSettings::_property_get_revert(const StringName &p_name, Variant &r_property) const {
  943. if (!props.has(p_name) || !props[p_name].has_default_value) {
  944. return false;
  945. }
  946. r_property = props[p_name].initial;
  947. return true;
  948. }
  949. void EditorSettings::add_property_hint(const PropertyInfo &p_hint) {
  950. _THREAD_SAFE_METHOD_
  951. hints[p_hint.name] = p_hint;
  952. }
  953. // Metadata
  954. void EditorSettings::set_project_metadata(const String &p_section, const String &p_key, Variant p_data) {
  955. Ref<ConfigFile> cf = memnew(ConfigFile);
  956. String path = EditorPaths::get_singleton()->get_project_settings_dir().path_join("project_metadata.cfg");
  957. Error err;
  958. err = cf->load(path);
  959. ERR_FAIL_COND_MSG(err != OK && err != ERR_FILE_NOT_FOUND, "Cannot load editor settings from file '" + path + "'.");
  960. cf->set_value(p_section, p_key, p_data);
  961. err = cf->save(path);
  962. ERR_FAIL_COND_MSG(err != OK, "Cannot save editor settings to file '" + path + "'.");
  963. }
  964. Variant EditorSettings::get_project_metadata(const String &p_section, const String &p_key, Variant p_default) const {
  965. Ref<ConfigFile> cf = memnew(ConfigFile);
  966. String path = EditorPaths::get_singleton()->get_project_settings_dir().path_join("project_metadata.cfg");
  967. Error err = cf->load(path);
  968. if (err != OK) {
  969. return p_default;
  970. }
  971. return cf->get_value(p_section, p_key, p_default);
  972. }
  973. void EditorSettings::set_favorites(const Vector<String> &p_favorites) {
  974. favorites = p_favorites;
  975. String favorites_file;
  976. if (Engine::get_singleton()->is_project_manager_hint()) {
  977. favorites_file = EditorPaths::get_singleton()->get_config_dir().path_join("favorite_dirs");
  978. } else {
  979. favorites_file = EditorPaths::get_singleton()->get_project_settings_dir().path_join("favorites");
  980. }
  981. Ref<FileAccess> f = FileAccess::open(favorites_file, FileAccess::WRITE);
  982. if (f.is_valid()) {
  983. for (int i = 0; i < favorites.size(); i++) {
  984. f->store_line(favorites[i]);
  985. }
  986. }
  987. }
  988. Vector<String> EditorSettings::get_favorites() const {
  989. return favorites;
  990. }
  991. void EditorSettings::set_recent_dirs(const Vector<String> &p_recent_dirs) {
  992. recent_dirs = p_recent_dirs;
  993. String recent_dirs_file;
  994. if (Engine::get_singleton()->is_project_manager_hint()) {
  995. recent_dirs_file = EditorPaths::get_singleton()->get_config_dir().path_join("recent_dirs");
  996. } else {
  997. recent_dirs_file = EditorPaths::get_singleton()->get_project_settings_dir().path_join("recent_dirs");
  998. }
  999. Ref<FileAccess> f = FileAccess::open(recent_dirs_file, FileAccess::WRITE);
  1000. if (f.is_valid()) {
  1001. for (int i = 0; i < recent_dirs.size(); i++) {
  1002. f->store_line(recent_dirs[i]);
  1003. }
  1004. }
  1005. }
  1006. Vector<String> EditorSettings::get_recent_dirs() const {
  1007. return recent_dirs;
  1008. }
  1009. void EditorSettings::load_favorites_and_recent_dirs() {
  1010. String favorites_file;
  1011. String recent_dirs_file;
  1012. if (Engine::get_singleton()->is_project_manager_hint()) {
  1013. favorites_file = EditorPaths::get_singleton()->get_config_dir().path_join("favorite_dirs");
  1014. recent_dirs_file = EditorPaths::get_singleton()->get_config_dir().path_join("recent_dirs");
  1015. } else {
  1016. favorites_file = EditorPaths::get_singleton()->get_project_settings_dir().path_join("favorites");
  1017. recent_dirs_file = EditorPaths::get_singleton()->get_project_settings_dir().path_join("recent_dirs");
  1018. }
  1019. Ref<FileAccess> f = FileAccess::open(favorites_file, FileAccess::READ);
  1020. if (f.is_valid()) {
  1021. String line = f->get_line().strip_edges();
  1022. while (!line.is_empty()) {
  1023. favorites.push_back(line);
  1024. line = f->get_line().strip_edges();
  1025. }
  1026. }
  1027. f = FileAccess::open(recent_dirs_file, FileAccess::READ);
  1028. if (f.is_valid()) {
  1029. String line = f->get_line().strip_edges();
  1030. while (!line.is_empty()) {
  1031. recent_dirs.push_back(line);
  1032. line = f->get_line().strip_edges();
  1033. }
  1034. }
  1035. }
  1036. bool EditorSettings::is_dark_theme() {
  1037. int AUTO_COLOR = 0;
  1038. int LIGHT_COLOR = 2;
  1039. Color base_color = get("interface/theme/base_color");
  1040. int icon_font_color_setting = get("interface/theme/icon_and_font_color");
  1041. return (icon_font_color_setting == AUTO_COLOR && base_color.get_luminance() < 0.5) || icon_font_color_setting == LIGHT_COLOR;
  1042. }
  1043. void EditorSettings::list_text_editor_themes() {
  1044. String themes = "Default,Godot 2,Custom";
  1045. Ref<DirAccess> d = DirAccess::open(EditorPaths::get_singleton()->get_text_editor_themes_dir());
  1046. if (d.is_valid()) {
  1047. List<String> custom_themes;
  1048. d->list_dir_begin();
  1049. String file = d->get_next();
  1050. while (!file.is_empty()) {
  1051. if (file.get_extension() == "tet" && !_is_default_text_editor_theme(file.get_basename().to_lower())) {
  1052. custom_themes.push_back(file.get_basename());
  1053. }
  1054. file = d->get_next();
  1055. }
  1056. d->list_dir_end();
  1057. custom_themes.sort();
  1058. for (const String &E : custom_themes) {
  1059. themes += "," + E;
  1060. }
  1061. }
  1062. add_property_hint(PropertyInfo(Variant::STRING, "text_editor/theme/color_theme", PROPERTY_HINT_ENUM, themes));
  1063. }
  1064. void EditorSettings::load_text_editor_theme() {
  1065. String p_file = get("text_editor/theme/color_theme");
  1066. if (_is_default_text_editor_theme(p_file.get_file().to_lower())) {
  1067. if (p_file == "Godot 2") {
  1068. _load_godot2_text_editor_theme();
  1069. }
  1070. return; // sorry for "Settings changed" console spam
  1071. }
  1072. String theme_path = EditorPaths::get_singleton()->get_text_editor_themes_dir().path_join(p_file + ".tet");
  1073. Ref<ConfigFile> cf = memnew(ConfigFile);
  1074. Error err = cf->load(theme_path);
  1075. if (err != OK) {
  1076. return;
  1077. }
  1078. List<String> keys;
  1079. cf->get_section_keys("color_theme", &keys);
  1080. for (const String &key : keys) {
  1081. String val = cf->get_value("color_theme", key);
  1082. // don't load if it's not already there!
  1083. if (has_setting("text_editor/theme/highlighting/" + key)) {
  1084. // make sure it is actually a color
  1085. if (val.is_valid_html_color() && key.find("color") >= 0) {
  1086. props["text_editor/theme/highlighting/" + key].variant = Color::html(val); // change manually to prevent "Settings changed" console spam
  1087. }
  1088. }
  1089. }
  1090. emit_signal(SNAME("settings_changed"));
  1091. // if it doesn't load just use what is currently loaded
  1092. }
  1093. bool EditorSettings::import_text_editor_theme(String p_file) {
  1094. if (!p_file.ends_with(".tet")) {
  1095. return false;
  1096. } else {
  1097. if (p_file.get_file().to_lower() == "default.tet") {
  1098. return false;
  1099. }
  1100. Ref<DirAccess> d = DirAccess::open(EditorPaths::get_singleton()->get_text_editor_themes_dir());
  1101. if (d.is_valid()) {
  1102. d->copy(p_file, EditorPaths::get_singleton()->get_text_editor_themes_dir().path_join(p_file.get_file()));
  1103. return true;
  1104. }
  1105. }
  1106. return false;
  1107. }
  1108. bool EditorSettings::save_text_editor_theme() {
  1109. String p_file = get("text_editor/theme/color_theme");
  1110. if (_is_default_text_editor_theme(p_file.get_file().to_lower())) {
  1111. return false;
  1112. }
  1113. String theme_path = EditorPaths::get_singleton()->get_text_editor_themes_dir().path_join(p_file + ".tet");
  1114. return _save_text_editor_theme(theme_path);
  1115. }
  1116. bool EditorSettings::save_text_editor_theme_as(String p_file) {
  1117. if (!p_file.ends_with(".tet")) {
  1118. p_file += ".tet";
  1119. }
  1120. if (_is_default_text_editor_theme(p_file.get_file().to_lower().trim_suffix(".tet"))) {
  1121. return false;
  1122. }
  1123. if (_save_text_editor_theme(p_file)) {
  1124. // switch to theme is saved in the theme directory
  1125. list_text_editor_themes();
  1126. String theme_name = p_file.substr(0, p_file.length() - 4).get_file();
  1127. if (p_file.get_base_dir() == EditorPaths::get_singleton()->get_text_editor_themes_dir()) {
  1128. _initial_set("text_editor/theme/color_theme", theme_name);
  1129. load_text_editor_theme();
  1130. }
  1131. return true;
  1132. }
  1133. return false;
  1134. }
  1135. bool EditorSettings::is_default_text_editor_theme() {
  1136. String p_file = get("text_editor/theme/color_theme");
  1137. return _is_default_text_editor_theme(p_file.get_file().to_lower());
  1138. }
  1139. Vector<String> EditorSettings::get_script_templates(const String &p_extension, const String &p_custom_path) {
  1140. Vector<String> templates;
  1141. String template_dir = EditorPaths::get_singleton()->get_script_templates_dir();
  1142. if (!p_custom_path.is_empty()) {
  1143. template_dir = p_custom_path;
  1144. }
  1145. Ref<DirAccess> d = DirAccess::open(template_dir);
  1146. if (d.is_valid()) {
  1147. d->list_dir_begin();
  1148. String file = d->get_next();
  1149. while (!file.is_empty()) {
  1150. if (file.get_extension() == p_extension) {
  1151. templates.push_back(file.get_basename());
  1152. }
  1153. file = d->get_next();
  1154. }
  1155. d->list_dir_end();
  1156. }
  1157. return templates;
  1158. }
  1159. String EditorSettings::get_editor_layouts_config() const {
  1160. return EditorPaths::get_singleton()->get_config_dir().path_join("editor_layouts.cfg");
  1161. }
  1162. float EditorSettings::get_auto_display_scale() const {
  1163. #if defined(MACOS_ENABLED) || defined(ANDROID_ENABLED)
  1164. return DisplayServer::get_singleton()->screen_get_max_scale();
  1165. #else
  1166. const int screen = DisplayServer::get_singleton()->window_get_current_screen();
  1167. if (DisplayServer::get_singleton()->screen_get_size(screen) == Vector2i()) {
  1168. // Invalid screen size, skip.
  1169. return 1.0;
  1170. }
  1171. // Use the smallest dimension to use a correct display scale on portrait displays.
  1172. const int smallest_dimension = MIN(DisplayServer::get_singleton()->screen_get_size(screen).x, DisplayServer::get_singleton()->screen_get_size(screen).y);
  1173. if (DisplayServer::get_singleton()->screen_get_dpi(screen) >= 192 && smallest_dimension >= 1400) {
  1174. // hiDPI display.
  1175. return 2.0;
  1176. } else if (smallest_dimension >= 1700) {
  1177. // Likely a hiDPI display, but we aren't certain due to the returned DPI.
  1178. // Use an intermediate scale to handle this situation.
  1179. return 1.5;
  1180. } else if (smallest_dimension <= 800) {
  1181. // Small loDPI display. Use a smaller display scale so that editor elements fit more easily.
  1182. // Icons won't look great, but this is better than having editor elements overflow from its window.
  1183. return 0.75;
  1184. }
  1185. return 1.0;
  1186. #endif
  1187. }
  1188. // Shortcuts
  1189. void EditorSettings::_add_shortcut_default(const String &p_name, const Ref<Shortcut> &p_shortcut) {
  1190. shortcuts[p_name] = p_shortcut;
  1191. }
  1192. void EditorSettings::add_shortcut(const String &p_name, const Ref<Shortcut> &p_shortcut) {
  1193. shortcuts[p_name] = p_shortcut;
  1194. shortcuts[p_name]->set_meta("customized", true);
  1195. }
  1196. bool EditorSettings::is_shortcut(const String &p_name, const Ref<InputEvent> &p_event) const {
  1197. HashMap<String, Ref<Shortcut>>::ConstIterator E = shortcuts.find(p_name);
  1198. ERR_FAIL_COND_V_MSG(!E, false, "Unknown Shortcut: " + p_name + ".");
  1199. return E->value->matches_event(p_event);
  1200. }
  1201. Ref<Shortcut> EditorSettings::get_shortcut(const String &p_name) const {
  1202. HashMap<String, Ref<Shortcut>>::ConstIterator SC = shortcuts.find(p_name);
  1203. if (SC) {
  1204. return SC->value;
  1205. }
  1206. // If no shortcut with the provided name is found in the list, check the built-in shortcuts.
  1207. // Use the first item in the action list for the shortcut event, since a shortcut can only have 1 linked event.
  1208. Ref<Shortcut> sc;
  1209. HashMap<String, List<Ref<InputEvent>>>::ConstIterator builtin_override = builtin_action_overrides.find(p_name);
  1210. if (builtin_override) {
  1211. sc.instantiate();
  1212. sc->set_events_list(&builtin_override->value);
  1213. sc->set_name(InputMap::get_singleton()->get_builtin_display_name(p_name));
  1214. }
  1215. // If there was no override, check the default builtins to see if it has an InputEvent for the provided name.
  1216. if (sc.is_null()) {
  1217. HashMap<String, List<Ref<InputEvent>>>::ConstIterator builtin_default = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied().find(p_name);
  1218. if (builtin_default) {
  1219. sc.instantiate();
  1220. sc->set_events_list(&builtin_default->value);
  1221. sc->set_name(InputMap::get_singleton()->get_builtin_display_name(p_name));
  1222. }
  1223. }
  1224. if (sc.is_valid()) {
  1225. // Add the shortcut to the list.
  1226. shortcuts[p_name] = sc;
  1227. return sc;
  1228. }
  1229. return Ref<Shortcut>();
  1230. }
  1231. void EditorSettings::get_shortcut_list(List<String> *r_shortcuts) {
  1232. for (const KeyValue<String, Ref<Shortcut>> &E : shortcuts) {
  1233. r_shortcuts->push_back(E.key);
  1234. }
  1235. }
  1236. Ref<Shortcut> ED_GET_SHORTCUT(const String &p_path) {
  1237. ERR_FAIL_NULL_V_MSG(EditorSettings::get_singleton(), nullptr, "EditorSettings not instantiated yet.");
  1238. Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
  1239. ERR_FAIL_COND_V_MSG(!sc.is_valid(), sc, "Used ED_GET_SHORTCUT with invalid shortcut: " + p_path + ".");
  1240. return sc;
  1241. }
  1242. void ED_SHORTCUT_OVERRIDE(const String &p_path, const String &p_feature, Key p_keycode, bool p_physical) {
  1243. ERR_FAIL_NULL_MSG(EditorSettings::get_singleton(), "EditorSettings not instantiated yet.");
  1244. Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
  1245. ERR_FAIL_COND_MSG(!sc.is_valid(), "Used ED_SHORTCUT_OVERRIDE with invalid shortcut: " + p_path + ".");
  1246. PackedInt32Array arr;
  1247. arr.push_back((int32_t)p_keycode);
  1248. ED_SHORTCUT_OVERRIDE_ARRAY(p_path, p_feature, arr, p_physical);
  1249. }
  1250. void ED_SHORTCUT_OVERRIDE_ARRAY(const String &p_path, const String &p_feature, const PackedInt32Array &p_keycodes, bool p_physical) {
  1251. ERR_FAIL_NULL_MSG(EditorSettings::get_singleton(), "EditorSettings not instantiated yet.");
  1252. Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
  1253. ERR_FAIL_COND_MSG(!sc.is_valid(), "Used ED_SHORTCUT_OVERRIDE_ARRAY with invalid shortcut: " + p_path + ".");
  1254. // Only add the override if the OS supports the provided feature.
  1255. if (!OS::get_singleton()->has_feature(p_feature)) {
  1256. if (!(p_feature == "macos" && (OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios")))) {
  1257. return;
  1258. }
  1259. }
  1260. Array events;
  1261. for (int i = 0; i < p_keycodes.size(); i++) {
  1262. Key keycode = (Key)p_keycodes[i];
  1263. if (OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios")) {
  1264. // Use Cmd+Backspace as a general replacement for Delete shortcuts on macOS
  1265. if (keycode == Key::KEY_DELETE) {
  1266. keycode = KeyModifierMask::META | Key::BACKSPACE;
  1267. }
  1268. }
  1269. Ref<InputEventKey> ie;
  1270. if (keycode != Key::NONE) {
  1271. ie = InputEventKey::create_reference(keycode, p_physical);
  1272. events.push_back(ie);
  1273. }
  1274. }
  1275. // Override the existing shortcut only if it wasn't customized by the user.
  1276. if (!sc->has_meta("customized")) {
  1277. sc->set_events(events);
  1278. }
  1279. sc->set_meta("original", events.duplicate(true));
  1280. }
  1281. Ref<Shortcut> ED_SHORTCUT(const String &p_path, const String &p_name, Key p_keycode, bool p_physical) {
  1282. PackedInt32Array arr;
  1283. arr.push_back((int32_t)p_keycode);
  1284. return ED_SHORTCUT_ARRAY(p_path, p_name, arr, p_physical);
  1285. }
  1286. Ref<Shortcut> ED_SHORTCUT_ARRAY(const String &p_path, const String &p_name, const PackedInt32Array &p_keycodes, bool p_physical) {
  1287. Array events;
  1288. for (int i = 0; i < p_keycodes.size(); i++) {
  1289. Key keycode = (Key)p_keycodes[i];
  1290. if (OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios")) {
  1291. // Use Cmd+Backspace as a general replacement for Delete shortcuts on macOS
  1292. if (keycode == Key::KEY_DELETE) {
  1293. keycode = KeyModifierMask::META | Key::BACKSPACE;
  1294. }
  1295. }
  1296. Ref<InputEventKey> ie;
  1297. if (keycode != Key::NONE) {
  1298. ie = InputEventKey::create_reference(keycode, p_physical);
  1299. events.push_back(ie);
  1300. }
  1301. }
  1302. if (!EditorSettings::get_singleton()) {
  1303. Ref<Shortcut> sc;
  1304. sc.instantiate();
  1305. sc->set_name(p_name);
  1306. sc->set_events(events);
  1307. sc->set_meta("original", events.duplicate(true));
  1308. return sc;
  1309. }
  1310. Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
  1311. if (sc.is_valid()) {
  1312. sc->set_name(p_name); //keep name (the ones that come from disk have no name)
  1313. sc->set_meta("original", events.duplicate(true)); //to compare against changes
  1314. return sc;
  1315. }
  1316. sc.instantiate();
  1317. sc->set_name(p_name);
  1318. sc->set_events(events);
  1319. sc->set_meta("original", events.duplicate(true)); //to compare against changes
  1320. EditorSettings::get_singleton()->_add_shortcut_default(p_path, sc);
  1321. return sc;
  1322. }
  1323. void EditorSettings::set_builtin_action_override(const String &p_name, const TypedArray<InputEvent> &p_events) {
  1324. List<Ref<InputEvent>> event_list;
  1325. // Override the whole list, since events may have their order changed or be added, removed or edited.
  1326. InputMap::get_singleton()->action_erase_events(p_name);
  1327. for (int i = 0; i < p_events.size(); i++) {
  1328. event_list.push_back(p_events[i]);
  1329. InputMap::get_singleton()->action_add_event(p_name, p_events[i]);
  1330. }
  1331. // Check if the provided event array is same as built-in. If it is, it does not need to be added to the overrides.
  1332. // Note that event order must also be the same.
  1333. bool same_as_builtin = true;
  1334. HashMap<String, List<Ref<InputEvent>>>::ConstIterator builtin_default = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied().find(p_name);
  1335. if (builtin_default) {
  1336. const List<Ref<InputEvent>> &builtin_events = builtin_default->value;
  1337. // In the editor we only care about key events.
  1338. List<Ref<InputEventKey>> builtin_key_events;
  1339. for (Ref<InputEventKey> iek : builtin_events) {
  1340. if (iek.is_valid()) {
  1341. builtin_key_events.push_back(iek);
  1342. }
  1343. }
  1344. if (p_events.size() == builtin_key_events.size()) {
  1345. int event_idx = 0;
  1346. // Check equality of each event.
  1347. for (const Ref<InputEventKey> &E : builtin_key_events) {
  1348. if (!E->is_match(p_events[event_idx])) {
  1349. same_as_builtin = false;
  1350. break;
  1351. }
  1352. event_idx++;
  1353. }
  1354. } else {
  1355. same_as_builtin = false;
  1356. }
  1357. }
  1358. if (same_as_builtin && builtin_action_overrides.has(p_name)) {
  1359. builtin_action_overrides.erase(p_name);
  1360. } else {
  1361. builtin_action_overrides[p_name] = event_list;
  1362. }
  1363. // Update the shortcut (if it is used somewhere in the editor) to be the first event of the new list.
  1364. if (shortcuts.has(p_name)) {
  1365. shortcuts[p_name]->set_events_list(&event_list);
  1366. }
  1367. }
  1368. const Array EditorSettings::get_builtin_action_overrides(const String &p_name) const {
  1369. HashMap<String, List<Ref<InputEvent>>>::ConstIterator AO = builtin_action_overrides.find(p_name);
  1370. if (AO) {
  1371. Array event_array;
  1372. List<Ref<InputEvent>> events_list = AO->value;
  1373. for (const Ref<InputEvent> &E : events_list) {
  1374. event_array.push_back(E);
  1375. }
  1376. return event_array;
  1377. }
  1378. return Array();
  1379. }
  1380. void EditorSettings::notify_changes() {
  1381. _THREAD_SAFE_METHOD_
  1382. SceneTree *sml = Object::cast_to<SceneTree>(OS::get_singleton()->get_main_loop());
  1383. if (!sml) {
  1384. return;
  1385. }
  1386. Node *root = sml->get_root()->get_child(0);
  1387. if (!root) {
  1388. return;
  1389. }
  1390. root->propagate_notification(NOTIFICATION_EDITOR_SETTINGS_CHANGED);
  1391. }
  1392. void EditorSettings::_bind_methods() {
  1393. ClassDB::bind_method(D_METHOD("has_setting", "name"), &EditorSettings::has_setting);
  1394. ClassDB::bind_method(D_METHOD("set_setting", "name", "value"), &EditorSettings::set_setting);
  1395. ClassDB::bind_method(D_METHOD("get_setting", "name"), &EditorSettings::get_setting);
  1396. ClassDB::bind_method(D_METHOD("erase", "property"), &EditorSettings::erase);
  1397. ClassDB::bind_method(D_METHOD("set_initial_value", "name", "value", "update_current"), &EditorSettings::set_initial_value);
  1398. ClassDB::bind_method(D_METHOD("add_property_info", "info"), &EditorSettings::_add_property_info_bind);
  1399. ClassDB::bind_method(D_METHOD("set_project_metadata", "section", "key", "data"), &EditorSettings::set_project_metadata);
  1400. ClassDB::bind_method(D_METHOD("get_project_metadata", "section", "key", "default"), &EditorSettings::get_project_metadata, DEFVAL(Variant()));
  1401. ClassDB::bind_method(D_METHOD("set_favorites", "dirs"), &EditorSettings::set_favorites);
  1402. ClassDB::bind_method(D_METHOD("get_favorites"), &EditorSettings::get_favorites);
  1403. ClassDB::bind_method(D_METHOD("set_recent_dirs", "dirs"), &EditorSettings::set_recent_dirs);
  1404. ClassDB::bind_method(D_METHOD("get_recent_dirs"), &EditorSettings::get_recent_dirs);
  1405. ClassDB::bind_method(D_METHOD("set_builtin_action_override", "name", "actions_list"), &EditorSettings::set_builtin_action_override);
  1406. ClassDB::bind_method(D_METHOD("check_changed_settings_in_group", "setting_prefix"), &EditorSettings::check_changed_settings_in_group);
  1407. ClassDB::bind_method(D_METHOD("get_changed_settings"), &EditorSettings::get_changed_settings);
  1408. ClassDB::bind_method(D_METHOD("mark_setting_changed", "setting"), &EditorSettings::mark_setting_changed);
  1409. ADD_SIGNAL(MethodInfo("settings_changed"));
  1410. BIND_CONSTANT(NOTIFICATION_EDITOR_SETTINGS_CHANGED);
  1411. }
  1412. EditorSettings::EditorSettings() {
  1413. last_order = 0;
  1414. _load_defaults();
  1415. }
  1416. EditorSettings::~EditorSettings() {
  1417. }