editor_settings.cpp 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693
  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. _initial_set("interface/editor/debug/enable_pseudolocalization", false);
  334. set_restart_if_changed("interface/editor/debug/enable_pseudolocalization", true);
  335. // Use pseudolocalization in editor.
  336. EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/use_embedded_menu", false, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  337. EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/expand_to_title", true, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  338. 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)
  339. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/editor/main_font_size", 14, "8,48,1")
  340. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/editor/code_font_size", 14, "8,48,1")
  341. 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")
  342. _initial_set("interface/editor/code_font_custom_opentype_features", "");
  343. _initial_set("interface/editor/code_font_custom_variations", "");
  344. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/font_antialiasing", 1, "None,Grayscale,LCD Subpixel")
  345. #ifdef MACOS_ENABLED
  346. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/font_hinting", 0, "Auto (None),None,Light,Normal")
  347. #else
  348. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/font_hinting", 0, "Auto (Light),None,Light,Normal")
  349. #endif
  350. 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")
  351. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "interface/editor/main_font", "", "*.ttf,*.otf,*.woff,*.woff2,*.pfb,*.pfm")
  352. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "interface/editor/main_font_bold", "", "*.ttf,*.otf,*.woff,*.woff2,*.pfb,*.pfm")
  353. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "interface/editor/code_font", "", "*.ttf,*.otf,*.woff,*.woff2,*.pfb,*.pfm")
  354. 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)
  355. // Default unfocused usec sleep is for 10 FPS. Allow an unfocused FPS limit
  356. // as low as 1 FPS for those who really need low power usage (but don't need
  357. // to preview particles or shaders while the editor is unfocused). With very
  358. // low FPS limits, the editor can take a small while to become usable after
  359. // being focused again, so this should be used at the user's discretion.
  360. 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)
  361. _initial_set("interface/editor/separate_distraction_mode", false);
  362. _initial_set("interface/editor/automatically_open_screenshots", true);
  363. EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/single_window_mode", false, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  364. _initial_set("interface/editor/mouse_extra_buttons_navigate_history", true);
  365. _initial_set("interface/editor/save_each_scene_on_quit", true); // Regression
  366. EDITOR_SETTING_USAGE(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/accept_dialog_cancel_ok_buttons", 0,
  367. vformat("Auto (%s),Cancel First,OK First", DisplayServer::get_singleton()->get_swap_cancel_ok() ? "OK First" : "Cancel First"),
  368. PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
  369. #ifdef DEV_ENABLED
  370. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/show_internal_errors_in_toast_notifications", 0, "Auto (Enabled),Enabled,Disabled")
  371. #else
  372. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/show_internal_errors_in_toast_notifications", 0, "Auto (Disabled),Enabled,Disabled")
  373. #endif
  374. // Inspector
  375. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/inspector/max_array_dictionary_items_per_page", 20, "10,100,1")
  376. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/inspector/show_low_level_opentype_features", false, "")
  377. // Theme
  378. 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")
  379. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/theme/icon_and_font_color", 0, "Auto,Dark,Light")
  380. EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "interface/theme/base_color", Color(0.2, 0.23, 0.31), "")
  381. EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "interface/theme/accent_color", Color(0.41, 0.61, 0.91), "")
  382. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/theme/contrast", 0.3, "-1,1,0.01")
  383. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/theme/draw_extra_borders", false, "")
  384. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/theme/icon_saturation", 1.0, "0,2,0.01")
  385. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/theme/relationship_line_opacity", 0.1, "0.00,1,0.01")
  386. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/theme/border_size", 0, "0,2,1")
  387. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/theme/corner_radius", 3, "0,6,1")
  388. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/theme/additional_spacing", 0.0, "0,5,0.1")
  389. EDITOR_SETTING_USAGE(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "interface/theme/custom_theme", "", "*.res,*.tres,*.theme", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  390. // Touchscreen
  391. bool has_touchscreen_ui = DisplayServer::get_singleton()->is_touchscreen_available();
  392. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/touchscreen/increase_scrollbar_touch_area", has_touchscreen_ui, "")
  393. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/touchscreen/enable_long_press_as_right_click", has_touchscreen_ui, "")
  394. set_restart_if_changed("interface/touchscreen/enable_long_press_as_right_click", true);
  395. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/touchscreen/enable_pan_and_scale_gestures", has_touchscreen_ui, "")
  396. set_restart_if_changed("interface/touchscreen/enable_pan_and_scale_gestures", true);
  397. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/touchscreen/scale_gizmo_handles", has_touchscreen_ui ? 3 : 1, "1,5,1")
  398. // Scene tabs
  399. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/scene_tabs/display_close_button", 1, "Never,If Tab Active,Always"); // TabBar::CloseButtonDisplayPolicy
  400. _initial_set("interface/scene_tabs/show_thumbnail_on_hover", true);
  401. EDITOR_SETTING_USAGE(Variant::INT, PROPERTY_HINT_RANGE, "interface/scene_tabs/maximum_width", 350, "0,9999,1", PROPERTY_USAGE_DEFAULT)
  402. _initial_set("interface/scene_tabs/show_script_button", false);
  403. /* Filesystem */
  404. // External Programs
  405. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "filesystem/external_programs/raster_image_editor", "", "")
  406. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "filesystem/external_programs/vector_image_editor", "", "")
  407. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "filesystem/external_programs/audio_editor", "", "")
  408. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "filesystem/external_programs/3d_model_editor", "", "")
  409. // Directories
  410. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_DIR, "filesystem/directories/autoscan_project_path", "", "")
  411. 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);
  412. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_DIR, "filesystem/directories/default_project_path", fs_dir_default_project_path, "")
  413. // On save
  414. _initial_set("filesystem/on_save/compress_binary_resources", true);
  415. _initial_set("filesystem/on_save/safe_save_on_backup_then_rename", true);
  416. // File dialog
  417. _initial_set("filesystem/file_dialog/show_hidden_files", false);
  418. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "filesystem/file_dialog/display_mode", 0, "Thumbnails,List")
  419. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "filesystem/file_dialog/thumbnail_size", 64, "32,128,16")
  420. /* Docks */
  421. // SceneTree
  422. _initial_set("docks/scene_tree/start_create_dialog_fully_expanded", false);
  423. _initial_set("docks/scene_tree/auto_expand_to_selected", true);
  424. // FileSystem
  425. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "docks/filesystem/thumbnail_size", 64, "32,128,16")
  426. _initial_set("docks/filesystem/always_show_folders", true);
  427. _initial_set("docks/filesystem/textfile_extensions", "txt,md,cfg,ini,log,json,yml,yaml,toml");
  428. // Property editor
  429. _initial_set("docks/property_editor/auto_refresh_interval", 0.2); //update 5 times per second by default
  430. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "docks/property_editor/subresource_hue_tint", 0.75, "0,1,0.01")
  431. /* Text editor */
  432. // Theme
  433. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_ENUM, "text_editor/theme/color_theme", "Default", "Default,Godot 2,Custom")
  434. // Theme: Highlighting
  435. _load_godot2_text_editor_theme();
  436. // Appearance
  437. // Appearance: Caret
  438. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/appearance/caret/type", 0, "Line,Block")
  439. _initial_set("text_editor/appearance/caret/caret_blink", true);
  440. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "text_editor/appearance/caret/caret_blink_interval", 0.5, "0.1,10,0.01")
  441. _initial_set("text_editor/appearance/caret/highlight_current_line", true);
  442. _initial_set("text_editor/appearance/caret/highlight_all_occurrences", true);
  443. // Appearance: Guidelines
  444. _initial_set("text_editor/appearance/guidelines/show_line_length_guidelines", true);
  445. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/appearance/guidelines/line_length_guideline_soft_column", 80, "20,160,1")
  446. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/appearance/guidelines/line_length_guideline_hard_column", 100, "20,160,1")
  447. // Appearance: Gutters
  448. _initial_set("text_editor/appearance/gutters/show_line_numbers", true);
  449. _initial_set("text_editor/appearance/gutters/line_numbers_zero_padded", false);
  450. _initial_set("text_editor/appearance/gutters/highlight_type_safe_lines", true);
  451. _initial_set("text_editor/appearance/gutters/show_bookmark_gutter", true);
  452. _initial_set("text_editor/appearance/gutters/show_info_gutter", true);
  453. // Appearance: Minimap
  454. _initial_set("text_editor/appearance/minimap/show_minimap", true);
  455. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/appearance/minimap/minimap_width", 80, "50,250,1")
  456. // Appearance: Lines
  457. _initial_set("text_editor/appearance/lines/code_folding", true);
  458. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/appearance/lines/word_wrap", 0, "None,Boundary")
  459. // Appearance: Whitespace
  460. _initial_set("text_editor/appearance/whitespace/draw_tabs", true);
  461. _initial_set("text_editor/appearance/whitespace/draw_spaces", false);
  462. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/appearance/whitespace/line_spacing", 4, "0,50,1")
  463. // Behavior
  464. // Behavior: Navigation
  465. _initial_set("text_editor/behavior/navigation/move_caret_on_right_click", true);
  466. _initial_set("text_editor/behavior/navigation/scroll_past_end_of_file", false);
  467. _initial_set("text_editor/behavior/navigation/smooth_scrolling", true);
  468. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/behavior/navigation/v_scroll_speed", 80, "1,10000,1")
  469. _initial_set("text_editor/behavior/navigation/drag_and_drop_selection", true);
  470. _initial_set("text_editor/behavior/navigation/stay_in_script_editor_on_node_selected", true);
  471. // Behavior: Indent
  472. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/behavior/indent/type", 0, "Tabs,Spaces")
  473. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/behavior/indent/size", 4, "1,64,1") // size of 0 crashes.
  474. _initial_set("text_editor/behavior/indent/auto_indent", true);
  475. // Behavior: Files
  476. _initial_set("text_editor/behavior/files/trim_trailing_whitespace_on_save", false);
  477. _initial_set("text_editor/behavior/files/autosave_interval_secs", 0);
  478. _initial_set("text_editor/behavior/files/restore_scripts_on_load", true);
  479. _initial_set("text_editor/behavior/files/convert_indent_on_save", true);
  480. _initial_set("text_editor/behavior/files/auto_reload_scripts_on_external_change", false);
  481. // Script list
  482. _initial_set("text_editor/script_list/show_members_overview", true);
  483. _initial_set("text_editor/script_list/sort_members_outline_alphabetically", false);
  484. // Completion
  485. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "text_editor/completion/idle_parse_delay", 2.0, "0.1,10,0.01")
  486. _initial_set("text_editor/completion/auto_brace_complete", true);
  487. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "text_editor/completion/code_complete_delay", 0.3, "0.01,5,0.01")
  488. _initial_set("text_editor/completion/put_callhint_tooltip_below_current_line", true);
  489. _initial_set("text_editor/completion/complete_file_paths", true);
  490. _initial_set("text_editor/completion/add_type_hints", false);
  491. _initial_set("text_editor/completion/use_single_quotes", false);
  492. // Help
  493. _initial_set("text_editor/help/show_help_index", true);
  494. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/help/help_font_size", 16, "8,48,1")
  495. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/help/help_source_font_size", 15, "8,48,1")
  496. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/help/help_title_font_size", 23, "8,64,1")
  497. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/help/class_reference_examples", 0, "GDScript,C#,GDScript and C#")
  498. /* Editors */
  499. // GridMap
  500. _initial_set("editors/grid_map/pick_distance", 5000.0);
  501. // 3D
  502. EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d/primary_grid_color", Color(0.56, 0.56, 0.56, 0.5), "")
  503. EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d/secondary_grid_color", Color(0.38, 0.38, 0.38, 0.5), "")
  504. // Use a similar color to the 2D editor selection.
  505. 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)
  506. _initial_set("editors/3d_gizmos/gizmo_colors/instantiated", Color(0.7, 0.7, 0.7, 0.6));
  507. _initial_set("editors/3d_gizmos/gizmo_colors/joint", Color(0.5, 0.8, 1));
  508. _initial_set("editors/3d_gizmos/gizmo_colors/shape", Color(0.5, 0.7, 1));
  509. // If a line is a multiple of this, it uses the primary grid color.
  510. // Use a power of 2 value by default as it's more common to use powers of 2 in level design.
  511. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "editors/3d/primary_grid_steps", 8, "1,100,1")
  512. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "editors/3d/grid_size", 200, "1,2000,1")
  513. // Higher values produce graphical artifacts when far away unless View Z-Far
  514. // is increased significantly more than it really should need to be.
  515. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "editors/3d/grid_division_level_max", 2, "-1,3,1")
  516. // Lower values produce graphical artifacts regardless of view clipping planes, so limit to -2 as a lower bound.
  517. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "editors/3d/grid_division_level_min", 0, "-2,2,1")
  518. // -0.2 seems like a sensible default. -1.0 gives Blender-like behavior, 0.5 gives huge grids.
  519. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/grid_division_level_bias", -0.2, "-1.0,0.5,0.1")
  520. _initial_set("editors/3d/grid_xz_plane", true);
  521. _initial_set("editors/3d/grid_xy_plane", false);
  522. _initial_set("editors/3d/grid_yz_plane", false);
  523. // Use a lower default FOV for the 3D camera compared to the
  524. // Camera3D node as the 3D viewport doesn't span the whole screen.
  525. // This means it's technically viewed from a further distance, which warrants a narrower FOV.
  526. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/default_fov", 70.0, "1,179,0.1,degrees")
  527. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/default_z_near", 0.05, "0.01,10,0.01,or_greater,suffix:m")
  528. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/default_z_far", 4000.0, "0.1,4000,0.1,or_greater,suffix:m")
  529. // 3D: Navigation
  530. _initial_set("editors/3d/navigation/invert_x_axis", false);
  531. _initial_set("editors/3d/navigation/invert_y_axis", false);
  532. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/navigation_scheme", 0, "Godot,Maya,Modo")
  533. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/zoom_style", 0, "Vertical,Horizontal")
  534. _initial_set("editors/3d/navigation/emulate_numpad", false);
  535. _initial_set("editors/3d/navigation/emulate_3_button_mouse", false);
  536. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/orbit_modifier", 0, "None,Shift,Alt,Meta,Ctrl")
  537. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/pan_modifier", 1, "None,Shift,Alt,Meta,Ctrl")
  538. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/zoom_modifier", 4, "None,Shift,Alt,Meta,Ctrl")
  539. _initial_set("editors/3d/navigation/warped_mouse_panning", true);
  540. // 3D: Navigation feel
  541. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/navigation_feel/orbit_sensitivity", 0.25, "0.01,2,0.001")
  542. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/navigation_feel/orbit_inertia", 0.0, "0,1,0.001")
  543. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/navigation_feel/translation_inertia", 0.05, "0,1,0.001")
  544. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/navigation_feel/zoom_inertia", 0.05, "0,1,0.001")
  545. // 3D: Freelook
  546. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/freelook/freelook_navigation_scheme", 0, "Default,Partially Axis-Locked (id Tech),Fully Axis-Locked (Minecraft)")
  547. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/freelook/freelook_sensitivity", 0.25, "0.01,2,0.001")
  548. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/freelook/freelook_inertia", 0.0, "0,1,0.001")
  549. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/freelook/freelook_base_speed", 5.0, "0,10,0.01")
  550. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/freelook/freelook_activation_modifier", 0, "None,Shift,Alt,Meta,Ctrl")
  551. _initial_set("editors/3d/freelook/freelook_speed_zoom_link", false);
  552. // 2D
  553. _initial_set("editors/2d/grid_color", Color(1.0, 1.0, 1.0, 0.07));
  554. _initial_set("editors/2d/guides_color", Color(0.6, 0.0, 0.8));
  555. _initial_set("editors/2d/smart_snapping_line_color", Color(0.9, 0.1, 0.1));
  556. _initial_set("editors/2d/bone_width", 5);
  557. _initial_set("editors/2d/bone_color1", Color(1.0, 1.0, 1.0, 0.7));
  558. _initial_set("editors/2d/bone_color2", Color(0.6, 0.6, 0.6, 0.7));
  559. _initial_set("editors/2d/bone_selected_color", Color(0.9, 0.45, 0.45, 0.7));
  560. _initial_set("editors/2d/bone_ik_color", Color(0.9, 0.9, 0.45, 0.7));
  561. _initial_set("editors/2d/bone_outline_color", Color(0.35, 0.35, 0.35, 0.5));
  562. _initial_set("editors/2d/bone_outline_size", 2);
  563. _initial_set("editors/2d/viewport_border_color", Color(0.4, 0.4, 1.0, 0.4));
  564. _initial_set("editors/2d/constrain_editor_view", true);
  565. // Panning
  566. // Enum should be in sync with ControlScheme in ViewPanner.
  567. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/panning/2d_editor_panning_scheme", 0, "Scroll Zooms,Scroll Pans");
  568. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/panning/sub_editors_panning_scheme", 0, "Scroll Zooms,Scroll Pans");
  569. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/panning/animation_editors_panning_scheme", 1, "Scroll Zooms,Scroll Pans");
  570. _initial_set("editors/panning/simple_panning", false);
  571. _initial_set("editors/panning/warped_mouse_panning", true);
  572. _initial_set("editors/panning/2d_editor_pan_speed", 20);
  573. // Tiles editor
  574. _initial_set("editors/tiles_editor/display_grid", true);
  575. _initial_set("editors/tiles_editor/grid_color", Color(1.0, 0.5, 0.2, 0.5));
  576. // Polygon editor
  577. _initial_set("editors/polygon_editor/point_grab_radius", has_touchscreen_ui ? 32 : 8);
  578. _initial_set("editors/polygon_editor/show_previous_outline", true);
  579. // Animation
  580. _initial_set("editors/animation/autorename_animation_tracks", true);
  581. _initial_set("editors/animation/confirm_insert_track", true);
  582. _initial_set("editors/animation/default_create_bezier_tracks", false);
  583. _initial_set("editors/animation/default_create_reset_tracks", true);
  584. _initial_set("editors/animation/onion_layers_past_color", Color(1, 0, 0));
  585. _initial_set("editors/animation/onion_layers_future_color", Color(0, 1, 0));
  586. // Visual editors
  587. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/visual_editors/minimap_opacity", 0.85, "0.0,1.0,0.01")
  588. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/visual_editors/lines_curvature", 0.5, "0.0,1.0,0.01")
  589. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "editors/visual_editors/visual_shader/port_preview_size", 160, "100,400,0.01")
  590. /* Run */
  591. // Window placement
  592. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "run/window_placement/rect", 1, "Top Left,Centered,Custom Position,Force Maximized,Force Fullscreen")
  593. // Keep the enum values in sync with the `DisplayServer::SCREEN_` enum.
  594. String screen_hints = "Same as Editor:-5,Previous Monitor:-4,Next Monitor:-3,Primary Monitor:-2"; // Note: Main Window Screen:-1 is not used for the main window.
  595. for (int i = 0; i < DisplayServer::get_singleton()->get_screen_count(); i++) {
  596. screen_hints += ",Monitor " + itos(i + 1) + ":" + itos(i);
  597. }
  598. _initial_set("run/window_placement/rect_custom_position", Vector2());
  599. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "run/window_placement/screen", -5, screen_hints)
  600. // Auto save
  601. _initial_set("run/auto_save/save_before_running", true);
  602. // Output
  603. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "run/output/font_size", 13, "8,48,1")
  604. _initial_set("run/output/always_clear_output_on_play", true);
  605. _initial_set("run/output/always_open_output_on_play", true);
  606. _initial_set("run/output/always_close_output_on_stop", false);
  607. /* Network */
  608. // Debug
  609. _initial_set("network/debug/remote_host", "127.0.0.1"); // Hints provided in setup_network
  610. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "network/debug/remote_port", 6007, "1,65535,1")
  611. // SSL
  612. 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);
  613. // Profiler
  614. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "debugger/profiler_frame_history_size", 3600, "60,10000,1")
  615. // HTTP Proxy
  616. _initial_set("network/http_proxy/host", "");
  617. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "network/http_proxy/port", 8080, "1,65535,1")
  618. /* Extra config */
  619. // TRANSLATORS: Project Manager here refers to the tool used to create/manage Godot projects.
  620. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "project_manager/sorting_order", 0, "Last Edited,Name,Path")
  621. #if defined(WEB_ENABLED)
  622. // Web platform only supports `gl_compatibility`.
  623. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_ENUM, "project_manager/default_renderer", "gl_compatibility", "forward_plus,mobile,gl_compatibility")
  624. #elif defined(ANDROID_ENABLED)
  625. // Use more suitable rendering method by default.
  626. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_ENUM, "project_manager/default_renderer", "mobile", "forward_plus,mobile,gl_compatibility")
  627. #else
  628. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_ENUM, "project_manager/default_renderer", "forward_plus", "forward_plus,mobile,gl_compatibility")
  629. #endif
  630. if (p_extra_config.is_valid()) {
  631. if (p_extra_config->has_section("init_projects") && p_extra_config->has_section_key("init_projects", "list")) {
  632. Vector<String> list = p_extra_config->get_value("init_projects", "list");
  633. for (int i = 0; i < list.size(); i++) {
  634. String proj_name = list[i].replace("/", "::");
  635. set("projects/" + proj_name, list[i]);
  636. }
  637. }
  638. if (p_extra_config->has_section("presets")) {
  639. List<String> keys;
  640. p_extra_config->get_section_keys("presets", &keys);
  641. for (const String &key : keys) {
  642. Variant val = p_extra_config->get_value("presets", key);
  643. set(key, val);
  644. }
  645. }
  646. }
  647. }
  648. void EditorSettings::_load_godot2_text_editor_theme() {
  649. // Godot 2 is only a dark theme; it doesn't have a light theme counterpart.
  650. _initial_set("text_editor/theme/highlighting/symbol_color", Color(0.73, 0.87, 1.0));
  651. _initial_set("text_editor/theme/highlighting/keyword_color", Color(1.0, 1.0, 0.7));
  652. _initial_set("text_editor/theme/highlighting/control_flow_keyword_color", Color(1.0, 0.85, 0.7));
  653. _initial_set("text_editor/theme/highlighting/base_type_color", Color(0.64, 1.0, 0.83));
  654. _initial_set("text_editor/theme/highlighting/engine_type_color", Color(0.51, 0.83, 1.0));
  655. _initial_set("text_editor/theme/highlighting/user_type_color", Color(0.42, 0.67, 0.93));
  656. _initial_set("text_editor/theme/highlighting/comment_color", Color(0.4, 0.4, 0.4));
  657. _initial_set("text_editor/theme/highlighting/string_color", Color(0.94, 0.43, 0.75));
  658. _initial_set("text_editor/theme/highlighting/background_color", Color(0.13, 0.12, 0.15));
  659. _initial_set("text_editor/theme/highlighting/completion_background_color", Color(0.17, 0.16, 0.2));
  660. _initial_set("text_editor/theme/highlighting/completion_selected_color", Color(0.26, 0.26, 0.27));
  661. _initial_set("text_editor/theme/highlighting/completion_existing_color", Color(0.87, 0.87, 0.87, 0.13));
  662. _initial_set("text_editor/theme/highlighting/completion_scroll_color", Color(1, 1, 1, 0.29));
  663. _initial_set("text_editor/theme/highlighting/completion_scroll_hovered_color", Color(1, 1, 1, 0.4));
  664. _initial_set("text_editor/theme/highlighting/completion_font_color", Color(0.67, 0.67, 0.67));
  665. _initial_set("text_editor/theme/highlighting/text_color", Color(0.67, 0.67, 0.67));
  666. _initial_set("text_editor/theme/highlighting/line_number_color", Color(0.67, 0.67, 0.67, 0.4));
  667. _initial_set("text_editor/theme/highlighting/safe_line_number_color", Color(0.67, 0.78, 0.67, 0.6));
  668. _initial_set("text_editor/theme/highlighting/caret_color", Color(0.67, 0.67, 0.67));
  669. _initial_set("text_editor/theme/highlighting/caret_background_color", Color(0, 0, 0));
  670. _initial_set("text_editor/theme/highlighting/text_selected_color", Color(0, 0, 0, 0));
  671. _initial_set("text_editor/theme/highlighting/selection_color", Color(0.41, 0.61, 0.91, 0.35));
  672. _initial_set("text_editor/theme/highlighting/brace_mismatch_color", Color(1, 0.2, 0.2));
  673. _initial_set("text_editor/theme/highlighting/current_line_color", Color(0.3, 0.5, 0.8, 0.15));
  674. _initial_set("text_editor/theme/highlighting/line_length_guideline_color", Color(0.3, 0.5, 0.8, 0.1));
  675. _initial_set("text_editor/theme/highlighting/word_highlighted_color", Color(0.8, 0.9, 0.9, 0.15));
  676. _initial_set("text_editor/theme/highlighting/number_color", Color(0.92, 0.58, 0.2));
  677. _initial_set("text_editor/theme/highlighting/function_color", Color(0.4, 0.64, 0.81));
  678. _initial_set("text_editor/theme/highlighting/member_variable_color", Color(0.9, 0.31, 0.35));
  679. _initial_set("text_editor/theme/highlighting/mark_color", Color(1.0, 0.4, 0.4, 0.4));
  680. _initial_set("text_editor/theme/highlighting/bookmark_color", Color(0.08, 0.49, 0.98));
  681. _initial_set("text_editor/theme/highlighting/breakpoint_color", Color(0.9, 0.29, 0.3));
  682. _initial_set("text_editor/theme/highlighting/executing_line_color", Color(0.98, 0.89, 0.27));
  683. _initial_set("text_editor/theme/highlighting/code_folding_color", Color(0.8, 0.8, 0.8, 0.8));
  684. _initial_set("text_editor/theme/highlighting/search_result_color", Color(0.05, 0.25, 0.05, 1));
  685. _initial_set("text_editor/theme/highlighting/search_result_border_color", Color(0.41, 0.61, 0.91, 0.38));
  686. }
  687. bool EditorSettings::_save_text_editor_theme(String p_file) {
  688. String theme_section = "color_theme";
  689. Ref<ConfigFile> cf = memnew(ConfigFile); // hex is better?
  690. List<String> keys;
  691. for (const KeyValue<String, VariantContainer> &E : props) {
  692. keys.push_back(E.key);
  693. }
  694. keys.sort();
  695. for (const String &key : keys) {
  696. if (key.begins_with("text_editor/theme/highlighting/") && key.find("color") >= 0) {
  697. cf->set_value(theme_section, key.replace("text_editor/theme/highlighting/", ""), ((Color)props[key].variant).to_html());
  698. }
  699. }
  700. Error err = cf->save(p_file);
  701. return err == OK;
  702. }
  703. bool EditorSettings::_is_default_text_editor_theme(String p_theme_name) {
  704. return p_theme_name == "default" || p_theme_name == "godot 2" || p_theme_name == "custom";
  705. }
  706. // PUBLIC METHODS
  707. EditorSettings *EditorSettings::get_singleton() {
  708. return singleton.ptr();
  709. }
  710. void EditorSettings::create() {
  711. // IMPORTANT: create() *must* create a valid EditorSettings singleton,
  712. // as the rest of the engine code will assume it. As such, it should never
  713. // return (incl. via ERR_FAIL) without initializing the singleton member.
  714. if (singleton.ptr()) {
  715. ERR_PRINT("Can't recreate EditorSettings as it already exists.");
  716. return;
  717. }
  718. GDREGISTER_CLASS(EditorSettings); // Otherwise it can't be unserialized.
  719. String config_file_path;
  720. Ref<ConfigFile> extra_config = memnew(ConfigFile);
  721. if (!EditorPaths::get_singleton()) {
  722. ERR_PRINT("Bug (please report): EditorPaths haven't been initialized, EditorSettings cannot be created properly.");
  723. goto fail;
  724. }
  725. if (EditorPaths::get_singleton()->is_self_contained()) {
  726. Error err = extra_config->load(EditorPaths::get_singleton()->get_self_contained_file());
  727. if (err != OK) {
  728. ERR_PRINT("Can't load extra config from path: " + EditorPaths::get_singleton()->get_self_contained_file());
  729. }
  730. }
  731. if (EditorPaths::get_singleton()->are_paths_valid()) {
  732. // Validate editor config file.
  733. Ref<DirAccess> dir = DirAccess::open(EditorPaths::get_singleton()->get_config_dir());
  734. String config_file_name = "editor_settings-" + itos(VERSION_MAJOR) + ".tres";
  735. config_file_path = EditorPaths::get_singleton()->get_config_dir().path_join(config_file_name);
  736. if (!dir->file_exists(config_file_name)) {
  737. goto fail;
  738. }
  739. singleton = ResourceLoader::load(config_file_path, "EditorSettings");
  740. if (singleton.is_null()) {
  741. ERR_PRINT("Could not load editor settings from path: " + config_file_path);
  742. goto fail;
  743. }
  744. singleton->save_changed_setting = true;
  745. print_verbose("EditorSettings: Load OK!");
  746. singleton->setup_language();
  747. singleton->setup_network();
  748. singleton->load_favorites_and_recent_dirs();
  749. singleton->list_text_editor_themes();
  750. return;
  751. }
  752. fail:
  753. // patch init projects
  754. String exe_path = OS::get_singleton()->get_executable_path().get_base_dir();
  755. if (extra_config->has_section("init_projects")) {
  756. Vector<String> list = extra_config->get_value("init_projects", "list");
  757. for (int i = 0; i < list.size(); i++) {
  758. list.write[i] = exe_path.path_join(list[i]);
  759. }
  760. extra_config->set_value("init_projects", "list", list);
  761. }
  762. singleton = Ref<EditorSettings>(memnew(EditorSettings));
  763. singleton->set_path(config_file_path, true);
  764. singleton->save_changed_setting = true;
  765. singleton->_load_defaults(extra_config);
  766. singleton->setup_language();
  767. singleton->setup_network();
  768. singleton->list_text_editor_themes();
  769. }
  770. void EditorSettings::setup_language() {
  771. TranslationServer::get_singleton()->set_editor_pseudolocalization(get("interface/editor/debug/enable_pseudolocalization"));
  772. String lang = get("interface/editor/editor_language");
  773. if (lang == "en") {
  774. return; // Default, nothing to do.
  775. }
  776. // Load editor translation for configured/detected locale.
  777. load_editor_translations(lang);
  778. load_property_translations(lang);
  779. // Load class reference translation.
  780. load_doc_translations(lang);
  781. }
  782. void EditorSettings::setup_network() {
  783. List<IPAddress> local_ip;
  784. IP::get_singleton()->get_local_addresses(&local_ip);
  785. String hint;
  786. String current = has_setting("network/debug/remote_host") ? get("network/debug/remote_host") : "";
  787. String selected = "127.0.0.1";
  788. // Check that current remote_host is a valid interface address and populate hints.
  789. for (const IPAddress &ip : local_ip) {
  790. // link-local IPv6 addresses don't work, skipping them
  791. if (String(ip).begins_with("fe80:0:0:0:")) { // fe80::/64
  792. continue;
  793. }
  794. // Same goes for IPv4 link-local (APIPA) addresses.
  795. if (String(ip).begins_with("169.254.")) { // 169.254.0.0/16
  796. continue;
  797. }
  798. // Select current IP (found)
  799. if (ip == current) {
  800. selected = ip;
  801. }
  802. if (!hint.is_empty()) {
  803. hint += ",";
  804. }
  805. hint += ip;
  806. }
  807. // Add hints with valid IP addresses to remote_host property.
  808. add_property_hint(PropertyInfo(Variant::STRING, "network/debug/remote_host", PROPERTY_HINT_ENUM, hint));
  809. // Fix potentially invalid remote_host due to network change.
  810. set("network/debug/remote_host", selected);
  811. }
  812. void EditorSettings::save() {
  813. //_THREAD_SAFE_METHOD_
  814. if (!singleton.ptr()) {
  815. return;
  816. }
  817. Error err = ResourceSaver::save(singleton);
  818. if (err != OK) {
  819. ERR_PRINT("Error saving editor settings to " + singleton->get_path());
  820. } else {
  821. singleton->changed_settings.clear();
  822. print_verbose("EditorSettings: Save OK!");
  823. }
  824. }
  825. PackedStringArray EditorSettings::get_changed_settings() const {
  826. PackedStringArray arr;
  827. for (const String &setting : changed_settings) {
  828. arr.push_back(setting);
  829. }
  830. return arr;
  831. }
  832. bool EditorSettings::check_changed_settings_in_group(const String &p_setting_prefix) const {
  833. for (const String &setting : changed_settings) {
  834. if (setting.begins_with(p_setting_prefix)) {
  835. return true;
  836. }
  837. }
  838. return false;
  839. }
  840. void EditorSettings::mark_setting_changed(const String &p_setting) {
  841. changed_settings.insert(p_setting);
  842. }
  843. void EditorSettings::destroy() {
  844. if (!singleton.ptr()) {
  845. return;
  846. }
  847. save();
  848. singleton = Ref<EditorSettings>();
  849. }
  850. void EditorSettings::set_optimize_save(bool p_optimize) {
  851. optimize_save = p_optimize;
  852. }
  853. // Properties
  854. void EditorSettings::set_setting(const String &p_setting, const Variant &p_value) {
  855. _THREAD_SAFE_METHOD_
  856. set(p_setting, p_value);
  857. }
  858. Variant EditorSettings::get_setting(const String &p_setting) const {
  859. _THREAD_SAFE_METHOD_
  860. return get(p_setting);
  861. }
  862. bool EditorSettings::has_setting(const String &p_setting) const {
  863. _THREAD_SAFE_METHOD_
  864. return props.has(p_setting);
  865. }
  866. void EditorSettings::erase(const String &p_setting) {
  867. _THREAD_SAFE_METHOD_
  868. props.erase(p_setting);
  869. }
  870. void EditorSettings::raise_order(const String &p_setting) {
  871. _THREAD_SAFE_METHOD_
  872. ERR_FAIL_COND(!props.has(p_setting));
  873. props[p_setting].order = ++last_order;
  874. }
  875. void EditorSettings::set_restart_if_changed(const StringName &p_setting, bool p_restart) {
  876. _THREAD_SAFE_METHOD_
  877. if (!props.has(p_setting)) {
  878. return;
  879. }
  880. props[p_setting].restart_if_changed = p_restart;
  881. }
  882. void EditorSettings::set_initial_value(const StringName &p_setting, const Variant &p_value, bool p_update_current) {
  883. _THREAD_SAFE_METHOD_
  884. if (!props.has(p_setting)) {
  885. return;
  886. }
  887. props[p_setting].initial = p_value;
  888. props[p_setting].has_default_value = true;
  889. if (p_update_current) {
  890. set(p_setting, p_value);
  891. }
  892. }
  893. Variant _EDITOR_DEF(const String &p_setting, const Variant &p_default, bool p_restart_if_changed) {
  894. ERR_FAIL_NULL_V_MSG(EditorSettings::get_singleton(), p_default, "EditorSettings not instantiated yet.");
  895. Variant ret = p_default;
  896. if (EditorSettings::get_singleton()->has_setting(p_setting)) {
  897. ret = EDITOR_GET(p_setting);
  898. } else {
  899. EditorSettings::get_singleton()->set_manually(p_setting, p_default);
  900. EditorSettings::get_singleton()->set_restart_if_changed(p_setting, p_restart_if_changed);
  901. }
  902. if (!EditorSettings::get_singleton()->has_default_value(p_setting)) {
  903. EditorSettings::get_singleton()->set_initial_value(p_setting, p_default);
  904. }
  905. return ret;
  906. }
  907. Variant _EDITOR_GET(const String &p_setting) {
  908. ERR_FAIL_COND_V(!EditorSettings::get_singleton() || !EditorSettings::get_singleton()->has_setting(p_setting), Variant());
  909. return EditorSettings::get_singleton()->get(p_setting);
  910. }
  911. bool EditorSettings::_property_can_revert(const StringName &p_name) const {
  912. if (!props.has(p_name)) {
  913. return false;
  914. }
  915. if (!props[p_name].has_default_value) {
  916. return false;
  917. }
  918. return props[p_name].initial != props[p_name].variant;
  919. }
  920. bool EditorSettings::_property_get_revert(const StringName &p_name, Variant &r_property) const {
  921. if (!props.has(p_name) || !props[p_name].has_default_value) {
  922. return false;
  923. }
  924. r_property = props[p_name].initial;
  925. return true;
  926. }
  927. void EditorSettings::add_property_hint(const PropertyInfo &p_hint) {
  928. _THREAD_SAFE_METHOD_
  929. hints[p_hint.name] = p_hint;
  930. }
  931. // Metadata
  932. void EditorSettings::set_project_metadata(const String &p_section, const String &p_key, Variant p_data) {
  933. Ref<ConfigFile> cf = memnew(ConfigFile);
  934. String path = EditorPaths::get_singleton()->get_project_settings_dir().path_join("project_metadata.cfg");
  935. Error err;
  936. err = cf->load(path);
  937. ERR_FAIL_COND_MSG(err != OK && err != ERR_FILE_NOT_FOUND, "Cannot load editor settings from file '" + path + "'.");
  938. cf->set_value(p_section, p_key, p_data);
  939. err = cf->save(path);
  940. ERR_FAIL_COND_MSG(err != OK, "Cannot save editor settings to file '" + path + "'.");
  941. }
  942. Variant EditorSettings::get_project_metadata(const String &p_section, const String &p_key, Variant p_default) const {
  943. Ref<ConfigFile> cf = memnew(ConfigFile);
  944. String path = EditorPaths::get_singleton()->get_project_settings_dir().path_join("project_metadata.cfg");
  945. Error err = cf->load(path);
  946. if (err != OK) {
  947. return p_default;
  948. }
  949. return cf->get_value(p_section, p_key, p_default);
  950. }
  951. void EditorSettings::set_favorites(const Vector<String> &p_favorites) {
  952. favorites = p_favorites;
  953. String favorites_file;
  954. if (Engine::get_singleton()->is_project_manager_hint()) {
  955. favorites_file = EditorPaths::get_singleton()->get_config_dir().path_join("favorite_dirs");
  956. } else {
  957. favorites_file = EditorPaths::get_singleton()->get_project_settings_dir().path_join("favorites");
  958. }
  959. Ref<FileAccess> f = FileAccess::open(favorites_file, FileAccess::WRITE);
  960. if (f.is_valid()) {
  961. for (int i = 0; i < favorites.size(); i++) {
  962. f->store_line(favorites[i]);
  963. }
  964. }
  965. }
  966. Vector<String> EditorSettings::get_favorites() const {
  967. return favorites;
  968. }
  969. void EditorSettings::set_recent_dirs(const Vector<String> &p_recent_dirs) {
  970. recent_dirs = p_recent_dirs;
  971. String recent_dirs_file;
  972. if (Engine::get_singleton()->is_project_manager_hint()) {
  973. recent_dirs_file = EditorPaths::get_singleton()->get_config_dir().path_join("recent_dirs");
  974. } else {
  975. recent_dirs_file = EditorPaths::get_singleton()->get_project_settings_dir().path_join("recent_dirs");
  976. }
  977. Ref<FileAccess> f = FileAccess::open(recent_dirs_file, FileAccess::WRITE);
  978. if (f.is_valid()) {
  979. for (int i = 0; i < recent_dirs.size(); i++) {
  980. f->store_line(recent_dirs[i]);
  981. }
  982. }
  983. }
  984. Vector<String> EditorSettings::get_recent_dirs() const {
  985. return recent_dirs;
  986. }
  987. void EditorSettings::load_favorites_and_recent_dirs() {
  988. String favorites_file;
  989. String recent_dirs_file;
  990. if (Engine::get_singleton()->is_project_manager_hint()) {
  991. favorites_file = EditorPaths::get_singleton()->get_config_dir().path_join("favorite_dirs");
  992. recent_dirs_file = EditorPaths::get_singleton()->get_config_dir().path_join("recent_dirs");
  993. } else {
  994. favorites_file = EditorPaths::get_singleton()->get_project_settings_dir().path_join("favorites");
  995. recent_dirs_file = EditorPaths::get_singleton()->get_project_settings_dir().path_join("recent_dirs");
  996. }
  997. Ref<FileAccess> f = FileAccess::open(favorites_file, FileAccess::READ);
  998. if (f.is_valid()) {
  999. String line = f->get_line().strip_edges();
  1000. while (!line.is_empty()) {
  1001. favorites.push_back(line);
  1002. line = f->get_line().strip_edges();
  1003. }
  1004. }
  1005. f = FileAccess::open(recent_dirs_file, FileAccess::READ);
  1006. if (f.is_valid()) {
  1007. String line = f->get_line().strip_edges();
  1008. while (!line.is_empty()) {
  1009. recent_dirs.push_back(line);
  1010. line = f->get_line().strip_edges();
  1011. }
  1012. }
  1013. }
  1014. bool EditorSettings::is_dark_theme() {
  1015. int AUTO_COLOR = 0;
  1016. int LIGHT_COLOR = 2;
  1017. Color base_color = get("interface/theme/base_color");
  1018. int icon_font_color_setting = get("interface/theme/icon_and_font_color");
  1019. return (icon_font_color_setting == AUTO_COLOR && base_color.get_luminance() < 0.5) || icon_font_color_setting == LIGHT_COLOR;
  1020. }
  1021. void EditorSettings::list_text_editor_themes() {
  1022. String themes = "Default,Godot 2,Custom";
  1023. Ref<DirAccess> d = DirAccess::open(EditorPaths::get_singleton()->get_text_editor_themes_dir());
  1024. if (d.is_valid()) {
  1025. List<String> custom_themes;
  1026. d->list_dir_begin();
  1027. String file = d->get_next();
  1028. while (!file.is_empty()) {
  1029. if (file.get_extension() == "tet" && !_is_default_text_editor_theme(file.get_basename().to_lower())) {
  1030. custom_themes.push_back(file.get_basename());
  1031. }
  1032. file = d->get_next();
  1033. }
  1034. d->list_dir_end();
  1035. custom_themes.sort();
  1036. for (const String &E : custom_themes) {
  1037. themes += "," + E;
  1038. }
  1039. }
  1040. add_property_hint(PropertyInfo(Variant::STRING, "text_editor/theme/color_theme", PROPERTY_HINT_ENUM, themes));
  1041. }
  1042. void EditorSettings::load_text_editor_theme() {
  1043. String p_file = get("text_editor/theme/color_theme");
  1044. if (_is_default_text_editor_theme(p_file.get_file().to_lower())) {
  1045. if (p_file == "Godot 2") {
  1046. _load_godot2_text_editor_theme();
  1047. }
  1048. return; // sorry for "Settings changed" console spam
  1049. }
  1050. String theme_path = EditorPaths::get_singleton()->get_text_editor_themes_dir().path_join(p_file + ".tet");
  1051. Ref<ConfigFile> cf = memnew(ConfigFile);
  1052. Error err = cf->load(theme_path);
  1053. if (err != OK) {
  1054. return;
  1055. }
  1056. List<String> keys;
  1057. cf->get_section_keys("color_theme", &keys);
  1058. for (const String &key : keys) {
  1059. String val = cf->get_value("color_theme", key);
  1060. // don't load if it's not already there!
  1061. if (has_setting("text_editor/theme/highlighting/" + key)) {
  1062. // make sure it is actually a color
  1063. if (val.is_valid_html_color() && key.find("color") >= 0) {
  1064. props["text_editor/theme/highlighting/" + key].variant = Color::html(val); // change manually to prevent "Settings changed" console spam
  1065. }
  1066. }
  1067. }
  1068. emit_signal(SNAME("settings_changed"));
  1069. // if it doesn't load just use what is currently loaded
  1070. }
  1071. bool EditorSettings::import_text_editor_theme(String p_file) {
  1072. if (!p_file.ends_with(".tet")) {
  1073. return false;
  1074. } else {
  1075. if (p_file.get_file().to_lower() == "default.tet") {
  1076. return false;
  1077. }
  1078. Ref<DirAccess> d = DirAccess::open(EditorPaths::get_singleton()->get_text_editor_themes_dir());
  1079. if (d.is_valid()) {
  1080. d->copy(p_file, EditorPaths::get_singleton()->get_text_editor_themes_dir().path_join(p_file.get_file()));
  1081. return true;
  1082. }
  1083. }
  1084. return false;
  1085. }
  1086. bool EditorSettings::save_text_editor_theme() {
  1087. String p_file = get("text_editor/theme/color_theme");
  1088. if (_is_default_text_editor_theme(p_file.get_file().to_lower())) {
  1089. return false;
  1090. }
  1091. String theme_path = EditorPaths::get_singleton()->get_text_editor_themes_dir().path_join(p_file + ".tet");
  1092. return _save_text_editor_theme(theme_path);
  1093. }
  1094. bool EditorSettings::save_text_editor_theme_as(String p_file) {
  1095. if (!p_file.ends_with(".tet")) {
  1096. p_file += ".tet";
  1097. }
  1098. if (_is_default_text_editor_theme(p_file.get_file().to_lower().trim_suffix(".tet"))) {
  1099. return false;
  1100. }
  1101. if (_save_text_editor_theme(p_file)) {
  1102. // switch to theme is saved in the theme directory
  1103. list_text_editor_themes();
  1104. String theme_name = p_file.substr(0, p_file.length() - 4).get_file();
  1105. if (p_file.get_base_dir() == EditorPaths::get_singleton()->get_text_editor_themes_dir()) {
  1106. _initial_set("text_editor/theme/color_theme", theme_name);
  1107. load_text_editor_theme();
  1108. }
  1109. return true;
  1110. }
  1111. return false;
  1112. }
  1113. bool EditorSettings::is_default_text_editor_theme() {
  1114. String p_file = get("text_editor/theme/color_theme");
  1115. return _is_default_text_editor_theme(p_file.get_file().to_lower());
  1116. }
  1117. Vector<String> EditorSettings::get_script_templates(const String &p_extension, const String &p_custom_path) {
  1118. Vector<String> templates;
  1119. String template_dir = EditorPaths::get_singleton()->get_script_templates_dir();
  1120. if (!p_custom_path.is_empty()) {
  1121. template_dir = p_custom_path;
  1122. }
  1123. Ref<DirAccess> d = DirAccess::open(template_dir);
  1124. if (d.is_valid()) {
  1125. d->list_dir_begin();
  1126. String file = d->get_next();
  1127. while (!file.is_empty()) {
  1128. if (file.get_extension() == p_extension) {
  1129. templates.push_back(file.get_basename());
  1130. }
  1131. file = d->get_next();
  1132. }
  1133. d->list_dir_end();
  1134. }
  1135. return templates;
  1136. }
  1137. String EditorSettings::get_editor_layouts_config() const {
  1138. return EditorPaths::get_singleton()->get_config_dir().path_join("editor_layouts.cfg");
  1139. }
  1140. float EditorSettings::get_auto_display_scale() const {
  1141. #if defined(MACOS_ENABLED) || defined(ANDROID_ENABLED)
  1142. return DisplayServer::get_singleton()->screen_get_max_scale();
  1143. #else
  1144. const int screen = DisplayServer::get_singleton()->window_get_current_screen();
  1145. if (DisplayServer::get_singleton()->screen_get_size(screen) == Vector2i()) {
  1146. // Invalid screen size, skip.
  1147. return 1.0;
  1148. }
  1149. // Use the smallest dimension to use a correct display scale on portrait displays.
  1150. const int smallest_dimension = MIN(DisplayServer::get_singleton()->screen_get_size(screen).x, DisplayServer::get_singleton()->screen_get_size(screen).y);
  1151. if (DisplayServer::get_singleton()->screen_get_dpi(screen) >= 192 && smallest_dimension >= 1400) {
  1152. // hiDPI display.
  1153. return 2.0;
  1154. } else if (smallest_dimension >= 1700) {
  1155. // Likely a hiDPI display, but we aren't certain due to the returned DPI.
  1156. // Use an intermediate scale to handle this situation.
  1157. return 1.5;
  1158. } else if (smallest_dimension <= 800) {
  1159. // Small loDPI display. Use a smaller display scale so that editor elements fit more easily.
  1160. // Icons won't look great, but this is better than having editor elements overflow from its window.
  1161. return 0.75;
  1162. }
  1163. return 1.0;
  1164. #endif
  1165. }
  1166. // Shortcuts
  1167. void EditorSettings::_add_shortcut_default(const String &p_name, const Ref<Shortcut> &p_shortcut) {
  1168. shortcuts[p_name] = p_shortcut;
  1169. }
  1170. void EditorSettings::add_shortcut(const String &p_name, const Ref<Shortcut> &p_shortcut) {
  1171. shortcuts[p_name] = p_shortcut;
  1172. shortcuts[p_name]->set_meta("customized", true);
  1173. }
  1174. bool EditorSettings::is_shortcut(const String &p_name, const Ref<InputEvent> &p_event) const {
  1175. HashMap<String, Ref<Shortcut>>::ConstIterator E = shortcuts.find(p_name);
  1176. ERR_FAIL_COND_V_MSG(!E, false, "Unknown Shortcut: " + p_name + ".");
  1177. return E->value->matches_event(p_event);
  1178. }
  1179. Ref<Shortcut> EditorSettings::get_shortcut(const String &p_name) const {
  1180. HashMap<String, Ref<Shortcut>>::ConstIterator SC = shortcuts.find(p_name);
  1181. if (SC) {
  1182. return SC->value;
  1183. }
  1184. // If no shortcut with the provided name is found in the list, check the built-in shortcuts.
  1185. // Use the first item in the action list for the shortcut event, since a shortcut can only have 1 linked event.
  1186. Ref<Shortcut> sc;
  1187. HashMap<String, List<Ref<InputEvent>>>::ConstIterator builtin_override = builtin_action_overrides.find(p_name);
  1188. if (builtin_override) {
  1189. sc.instantiate();
  1190. sc->set_events_list(&builtin_override->value);
  1191. sc->set_name(InputMap::get_singleton()->get_builtin_display_name(p_name));
  1192. }
  1193. // If there was no override, check the default builtins to see if it has an InputEvent for the provided name.
  1194. if (sc.is_null()) {
  1195. HashMap<String, List<Ref<InputEvent>>>::ConstIterator builtin_default = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied().find(p_name);
  1196. if (builtin_default) {
  1197. sc.instantiate();
  1198. sc->set_events_list(&builtin_default->value);
  1199. sc->set_name(InputMap::get_singleton()->get_builtin_display_name(p_name));
  1200. }
  1201. }
  1202. if (sc.is_valid()) {
  1203. // Add the shortcut to the list.
  1204. shortcuts[p_name] = sc;
  1205. return sc;
  1206. }
  1207. return Ref<Shortcut>();
  1208. }
  1209. void EditorSettings::get_shortcut_list(List<String> *r_shortcuts) {
  1210. for (const KeyValue<String, Ref<Shortcut>> &E : shortcuts) {
  1211. r_shortcuts->push_back(E.key);
  1212. }
  1213. }
  1214. Ref<Shortcut> ED_GET_SHORTCUT(const String &p_path) {
  1215. ERR_FAIL_NULL_V_MSG(EditorSettings::get_singleton(), nullptr, "EditorSettings not instantiated yet.");
  1216. Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
  1217. ERR_FAIL_COND_V_MSG(!sc.is_valid(), sc, "Used ED_GET_SHORTCUT with invalid shortcut: " + p_path + ".");
  1218. return sc;
  1219. }
  1220. void ED_SHORTCUT_OVERRIDE(const String &p_path, const String &p_feature, Key p_keycode, bool p_physical) {
  1221. ERR_FAIL_NULL_MSG(EditorSettings::get_singleton(), "EditorSettings not instantiated yet.");
  1222. Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
  1223. ERR_FAIL_COND_MSG(!sc.is_valid(), "Used ED_SHORTCUT_OVERRIDE with invalid shortcut: " + p_path + ".");
  1224. PackedInt32Array arr;
  1225. arr.push_back((int32_t)p_keycode);
  1226. ED_SHORTCUT_OVERRIDE_ARRAY(p_path, p_feature, arr, p_physical);
  1227. }
  1228. void ED_SHORTCUT_OVERRIDE_ARRAY(const String &p_path, const String &p_feature, const PackedInt32Array &p_keycodes, bool p_physical) {
  1229. ERR_FAIL_NULL_MSG(EditorSettings::get_singleton(), "EditorSettings not instantiated yet.");
  1230. Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
  1231. ERR_FAIL_COND_MSG(!sc.is_valid(), "Used ED_SHORTCUT_OVERRIDE_ARRAY with invalid shortcut: " + p_path + ".");
  1232. // Only add the override if the OS supports the provided feature.
  1233. if (!OS::get_singleton()->has_feature(p_feature)) {
  1234. return;
  1235. }
  1236. Array events;
  1237. for (int i = 0; i < p_keycodes.size(); i++) {
  1238. Key keycode = (Key)p_keycodes[i];
  1239. #ifdef MACOS_ENABLED
  1240. // Use Cmd+Backspace as a general replacement for Delete shortcuts on macOS
  1241. if (keycode == Key::KEY_DELETE) {
  1242. keycode = KeyModifierMask::META | Key::BACKSPACE;
  1243. }
  1244. #endif
  1245. Ref<InputEventKey> ie;
  1246. if (keycode != Key::NONE) {
  1247. ie = InputEventKey::create_reference(keycode, p_physical);
  1248. events.push_back(ie);
  1249. }
  1250. }
  1251. // Override the existing shortcut only if it wasn't customized by the user.
  1252. if (!sc->has_meta("customized")) {
  1253. sc->set_events(events);
  1254. }
  1255. sc->set_meta("original", events.duplicate(true));
  1256. }
  1257. Ref<Shortcut> ED_SHORTCUT(const String &p_path, const String &p_name, Key p_keycode, bool p_physical) {
  1258. PackedInt32Array arr;
  1259. arr.push_back((int32_t)p_keycode);
  1260. return ED_SHORTCUT_ARRAY(p_path, p_name, arr, p_physical);
  1261. }
  1262. Ref<Shortcut> ED_SHORTCUT_ARRAY(const String &p_path, const String &p_name, const PackedInt32Array &p_keycodes, bool p_physical) {
  1263. Array events;
  1264. for (int i = 0; i < p_keycodes.size(); i++) {
  1265. Key keycode = (Key)p_keycodes[i];
  1266. #ifdef MACOS_ENABLED
  1267. // Use Cmd+Backspace as a general replacement for Delete shortcuts on macOS
  1268. if (keycode == Key::KEY_DELETE) {
  1269. keycode = KeyModifierMask::META | Key::BACKSPACE;
  1270. }
  1271. #endif
  1272. Ref<InputEventKey> ie;
  1273. if (keycode != Key::NONE) {
  1274. ie = InputEventKey::create_reference(keycode, p_physical);
  1275. events.push_back(ie);
  1276. }
  1277. }
  1278. if (!EditorSettings::get_singleton()) {
  1279. Ref<Shortcut> sc;
  1280. sc.instantiate();
  1281. sc->set_name(p_name);
  1282. sc->set_events(events);
  1283. sc->set_meta("original", events.duplicate(true));
  1284. return sc;
  1285. }
  1286. Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
  1287. if (sc.is_valid()) {
  1288. sc->set_name(p_name); //keep name (the ones that come from disk have no name)
  1289. sc->set_meta("original", events.duplicate(true)); //to compare against changes
  1290. return sc;
  1291. }
  1292. sc.instantiate();
  1293. sc->set_name(p_name);
  1294. sc->set_events(events);
  1295. sc->set_meta("original", events.duplicate(true)); //to compare against changes
  1296. EditorSettings::get_singleton()->_add_shortcut_default(p_path, sc);
  1297. return sc;
  1298. }
  1299. void EditorSettings::set_builtin_action_override(const String &p_name, const TypedArray<InputEvent> &p_events) {
  1300. List<Ref<InputEvent>> event_list;
  1301. // Override the whole list, since events may have their order changed or be added, removed or edited.
  1302. InputMap::get_singleton()->action_erase_events(p_name);
  1303. for (int i = 0; i < p_events.size(); i++) {
  1304. event_list.push_back(p_events[i]);
  1305. InputMap::get_singleton()->action_add_event(p_name, p_events[i]);
  1306. }
  1307. // Check if the provided event array is same as built-in. If it is, it does not need to be added to the overrides.
  1308. // Note that event order must also be the same.
  1309. bool same_as_builtin = true;
  1310. HashMap<String, List<Ref<InputEvent>>>::ConstIterator builtin_default = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied().find(p_name);
  1311. if (builtin_default) {
  1312. const List<Ref<InputEvent>> &builtin_events = builtin_default->value;
  1313. // In the editor we only care about key events.
  1314. List<Ref<InputEventKey>> builtin_key_events;
  1315. for (Ref<InputEventKey> iek : builtin_events) {
  1316. if (iek.is_valid()) {
  1317. builtin_key_events.push_back(iek);
  1318. }
  1319. }
  1320. if (p_events.size() == builtin_key_events.size()) {
  1321. int event_idx = 0;
  1322. // Check equality of each event.
  1323. for (const Ref<InputEventKey> &E : builtin_key_events) {
  1324. if (!E->is_match(p_events[event_idx])) {
  1325. same_as_builtin = false;
  1326. break;
  1327. }
  1328. event_idx++;
  1329. }
  1330. } else {
  1331. same_as_builtin = false;
  1332. }
  1333. }
  1334. if (same_as_builtin && builtin_action_overrides.has(p_name)) {
  1335. builtin_action_overrides.erase(p_name);
  1336. } else {
  1337. builtin_action_overrides[p_name] = event_list;
  1338. }
  1339. // Update the shortcut (if it is used somewhere in the editor) to be the first event of the new list.
  1340. if (shortcuts.has(p_name)) {
  1341. shortcuts[p_name]->set_events_list(&event_list);
  1342. }
  1343. }
  1344. const Array EditorSettings::get_builtin_action_overrides(const String &p_name) const {
  1345. HashMap<String, List<Ref<InputEvent>>>::ConstIterator AO = builtin_action_overrides.find(p_name);
  1346. if (AO) {
  1347. Array event_array;
  1348. List<Ref<InputEvent>> events_list = AO->value;
  1349. for (const Ref<InputEvent> &E : events_list) {
  1350. event_array.push_back(E);
  1351. }
  1352. return event_array;
  1353. }
  1354. return Array();
  1355. }
  1356. void EditorSettings::notify_changes() {
  1357. _THREAD_SAFE_METHOD_
  1358. SceneTree *sml = Object::cast_to<SceneTree>(OS::get_singleton()->get_main_loop());
  1359. if (!sml) {
  1360. return;
  1361. }
  1362. Node *root = sml->get_root()->get_child(0);
  1363. if (!root) {
  1364. return;
  1365. }
  1366. root->propagate_notification(NOTIFICATION_EDITOR_SETTINGS_CHANGED);
  1367. }
  1368. void EditorSettings::_bind_methods() {
  1369. ClassDB::bind_method(D_METHOD("has_setting", "name"), &EditorSettings::has_setting);
  1370. ClassDB::bind_method(D_METHOD("set_setting", "name", "value"), &EditorSettings::set_setting);
  1371. ClassDB::bind_method(D_METHOD("get_setting", "name"), &EditorSettings::get_setting);
  1372. ClassDB::bind_method(D_METHOD("erase", "property"), &EditorSettings::erase);
  1373. ClassDB::bind_method(D_METHOD("set_initial_value", "name", "value", "update_current"), &EditorSettings::set_initial_value);
  1374. ClassDB::bind_method(D_METHOD("add_property_info", "info"), &EditorSettings::_add_property_info_bind);
  1375. ClassDB::bind_method(D_METHOD("set_project_metadata", "section", "key", "data"), &EditorSettings::set_project_metadata);
  1376. ClassDB::bind_method(D_METHOD("get_project_metadata", "section", "key", "default"), &EditorSettings::get_project_metadata, DEFVAL(Variant()));
  1377. ClassDB::bind_method(D_METHOD("set_favorites", "dirs"), &EditorSettings::set_favorites);
  1378. ClassDB::bind_method(D_METHOD("get_favorites"), &EditorSettings::get_favorites);
  1379. ClassDB::bind_method(D_METHOD("set_recent_dirs", "dirs"), &EditorSettings::set_recent_dirs);
  1380. ClassDB::bind_method(D_METHOD("get_recent_dirs"), &EditorSettings::get_recent_dirs);
  1381. ClassDB::bind_method(D_METHOD("set_builtin_action_override", "name", "actions_list"), &EditorSettings::set_builtin_action_override);
  1382. ClassDB::bind_method(D_METHOD("check_changed_settings_in_group", "setting_prefix"), &EditorSettings::check_changed_settings_in_group);
  1383. ClassDB::bind_method(D_METHOD("get_changed_settings"), &EditorSettings::get_changed_settings);
  1384. ClassDB::bind_method(D_METHOD("mark_setting_changed", "setting"), &EditorSettings::mark_setting_changed);
  1385. ADD_SIGNAL(MethodInfo("settings_changed"));
  1386. BIND_CONSTANT(NOTIFICATION_EDITOR_SETTINGS_CHANGED);
  1387. }
  1388. EditorSettings::EditorSettings() {
  1389. last_order = 0;
  1390. _load_defaults();
  1391. }
  1392. EditorSettings::~EditorSettings() {
  1393. }