editor_settings.cpp 65 KB

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