editor_settings.cpp 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804
  1. /*************************************************************************/
  2. /* editor_settings.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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_map.h"
  33. #include "core/io/certs_compressed.gen.h"
  34. #include "core/io/compression.h"
  35. #include "core/io/config_file.h"
  36. #include "core/io/file_access_memory.h"
  37. #include "core/io/ip.h"
  38. #include "core/io/resource_loader.h"
  39. #include "core/io/resource_saver.h"
  40. #include "core/io/translation_loader_po.h"
  41. #include "core/os/dir_access.h"
  42. #include "core/os/file_access.h"
  43. #include "core/os/keyboard.h"
  44. #include "core/os/os.h"
  45. #include "core/version.h"
  46. #include "editor/doc_translations.gen.h"
  47. #include "editor/editor_node.h"
  48. #include "editor/editor_translations.gen.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. emit_signal("settings_changed");
  60. }
  61. return true;
  62. }
  63. bool EditorSettings::_set_only(const StringName &p_name, const Variant &p_value) {
  64. _THREAD_SAFE_METHOD_
  65. if (p_name == "shortcuts") {
  66. Array arr = p_value;
  67. ERR_FAIL_COND_V(arr.size() && arr.size() & 1, true);
  68. for (int i = 0; i < arr.size(); i += 2) {
  69. String name = arr[i];
  70. Ref<InputEvent> shortcut = arr[i + 1];
  71. Ref<Shortcut> sc;
  72. sc.instance();
  73. sc->set_shortcut(shortcut);
  74. add_shortcut(name, sc);
  75. }
  76. return false;
  77. } else if (p_name == "builtin_action_overrides") {
  78. Array actions_arr = p_value;
  79. for (int i = 0; i < actions_arr.size(); i++) {
  80. Dictionary action_dict = actions_arr[i];
  81. String name = action_dict["name"];
  82. Array events = action_dict["events"];
  83. InputMap *im = InputMap::get_singleton();
  84. im->action_erase_events(name);
  85. builtin_action_overrides[name].clear();
  86. for (int ev_idx = 0; ev_idx < events.size(); ev_idx++) {
  87. im->action_add_event(name, events[ev_idx]);
  88. builtin_action_overrides[name].push_back(events[ev_idx]);
  89. }
  90. }
  91. return false;
  92. }
  93. bool changed = false;
  94. if (p_value.get_type() == Variant::NIL) {
  95. if (props.has(p_name)) {
  96. props.erase(p_name);
  97. changed = true;
  98. }
  99. } else {
  100. if (props.has(p_name)) {
  101. if (p_value != props[p_name].variant) {
  102. props[p_name].variant = p_value;
  103. changed = true;
  104. }
  105. } else {
  106. props[p_name] = VariantContainer(p_value, last_order++);
  107. changed = true;
  108. }
  109. if (save_changed_setting) {
  110. if (!props[p_name].save) {
  111. props[p_name].save = true;
  112. changed = true;
  113. }
  114. }
  115. }
  116. return changed;
  117. }
  118. bool EditorSettings::_get(const StringName &p_name, Variant &r_ret) const {
  119. _THREAD_SAFE_METHOD_
  120. if (p_name == "shortcuts") {
  121. Array arr;
  122. for (const Map<String, Ref<Shortcut>>::Element *E = shortcuts.front(); E; E = E->next()) {
  123. Ref<Shortcut> sc = E->get();
  124. if (builtin_action_overrides.has(E->key())) {
  125. // This shortcut was auto-generated from built in actions: don't save.
  126. continue;
  127. }
  128. if (optimize_save) {
  129. if (!sc->has_meta("original")) {
  130. continue; //this came from settings but is not any longer used
  131. }
  132. Ref<InputEvent> original = sc->get_meta("original");
  133. if (sc->is_shortcut(original) || (original.is_null() && sc->get_shortcut().is_null())) {
  134. continue; //not changed from default, don't save
  135. }
  136. }
  137. arr.push_back(E->key());
  138. arr.push_back(sc->get_shortcut());
  139. }
  140. r_ret = arr;
  141. return true;
  142. } else if (p_name == "builtin_action_overrides") {
  143. Array actions_arr;
  144. for (Map<String, List<Ref<InputEvent>>>::Element *E = builtin_action_overrides.front(); E; E = E->next()) {
  145. List<Ref<InputEvent>> events = E->get();
  146. // TODO: skip actions which are the same as the builtin.
  147. Dictionary action_dict;
  148. action_dict["name"] = E->key();
  149. Array events_arr;
  150. for (List<Ref<InputEvent>>::Element *I = events.front(); I; I = I->next()) {
  151. events_arr.push_back(I->get());
  152. }
  153. action_dict["events"] = events_arr;
  154. actions_arr.push_back(action_dict);
  155. }
  156. r_ret = actions_arr;
  157. return true;
  158. }
  159. const VariantContainer *v = props.getptr(p_name);
  160. if (!v) {
  161. WARN_PRINT("EditorSettings::_get - Property not found: " + String(p_name));
  162. return false;
  163. }
  164. r_ret = v->variant;
  165. return true;
  166. }
  167. void EditorSettings::_initial_set(const StringName &p_name, const Variant &p_value) {
  168. set(p_name, p_value);
  169. props[p_name].initial = p_value;
  170. props[p_name].has_default_value = true;
  171. }
  172. struct _EVCSort {
  173. String name;
  174. Variant::Type type = Variant::Type::NIL;
  175. int order = 0;
  176. bool save = false;
  177. bool restart_if_changed = false;
  178. bool operator<(const _EVCSort &p_vcs) const { return order < p_vcs.order; }
  179. };
  180. void EditorSettings::_get_property_list(List<PropertyInfo> *p_list) const {
  181. _THREAD_SAFE_METHOD_
  182. const String *k = nullptr;
  183. Set<_EVCSort> vclist;
  184. while ((k = props.next(k))) {
  185. const VariantContainer *v = props.getptr(*k);
  186. if (v->hide_from_editor) {
  187. continue;
  188. }
  189. _EVCSort vc;
  190. vc.name = *k;
  191. vc.order = v->order;
  192. vc.type = v->variant.get_type();
  193. vc.save = v->save;
  194. /*if (vc.save) { this should be implemented, but lets do after 3.1 is out.
  195. if (v->initial.get_type() != Variant::NIL && v->initial == v->variant) {
  196. vc.save = false;
  197. }
  198. }*/
  199. vc.restart_if_changed = v->restart_if_changed;
  200. vclist.insert(vc);
  201. }
  202. for (Set<_EVCSort>::Element *E = vclist.front(); E; E = E->next()) {
  203. int pinfo = 0;
  204. if (E->get().save || !optimize_save) {
  205. pinfo |= PROPERTY_USAGE_STORAGE;
  206. }
  207. if (!E->get().name.begins_with("_") && !E->get().name.begins_with("projects/")) {
  208. pinfo |= PROPERTY_USAGE_EDITOR;
  209. } else {
  210. pinfo |= PROPERTY_USAGE_STORAGE; //hiddens must always be saved
  211. }
  212. PropertyInfo pi(E->get().type, E->get().name);
  213. pi.usage = pinfo;
  214. if (hints.has(E->get().name)) {
  215. pi = hints[E->get().name];
  216. }
  217. if (E->get().restart_if_changed) {
  218. pi.usage |= PROPERTY_USAGE_RESTART_IF_CHANGED;
  219. }
  220. p_list->push_back(pi);
  221. }
  222. p_list->push_back(PropertyInfo(Variant::ARRAY, "shortcuts", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); //do not edit
  223. p_list->push_back(PropertyInfo(Variant::ARRAY, "builtin_action_overrides", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
  224. }
  225. void EditorSettings::_add_property_info_bind(const Dictionary &p_info) {
  226. ERR_FAIL_COND(!p_info.has("name"));
  227. ERR_FAIL_COND(!p_info.has("type"));
  228. PropertyInfo pinfo;
  229. pinfo.name = p_info["name"];
  230. ERR_FAIL_COND(!props.has(pinfo.name));
  231. pinfo.type = Variant::Type(p_info["type"].operator int());
  232. ERR_FAIL_INDEX(pinfo.type, Variant::VARIANT_MAX);
  233. if (p_info.has("hint")) {
  234. pinfo.hint = PropertyHint(p_info["hint"].operator int());
  235. }
  236. if (p_info.has("hint_string")) {
  237. pinfo.hint_string = p_info["hint_string"];
  238. }
  239. add_property_hint(pinfo);
  240. }
  241. // Default configs
  242. bool EditorSettings::has_default_value(const String &p_setting) const {
  243. _THREAD_SAFE_METHOD_
  244. if (!props.has(p_setting)) {
  245. return false;
  246. }
  247. return props[p_setting].has_default_value;
  248. }
  249. void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
  250. _THREAD_SAFE_METHOD_
  251. /* Languages */
  252. {
  253. String lang_hint = "en";
  254. String host_lang = OS::get_singleton()->get_locale();
  255. host_lang = TranslationServer::standardize_locale(host_lang);
  256. // Skip locales if Text server lack required features.
  257. Vector<String> locales_to_skip;
  258. if (!TS->has_feature(TextServer::FEATURE_BIDI_LAYOUT) || !TS->has_feature(TextServer::FEATURE_SHAPING)) {
  259. locales_to_skip.push_back("ar"); // Arabic
  260. locales_to_skip.push_back("fa"); // Persian
  261. locales_to_skip.push_back("ur"); // Urdu
  262. }
  263. if (!TS->has_feature(TextServer::FEATURE_BIDI_LAYOUT)) {
  264. locales_to_skip.push_back("he"); // Hebrew
  265. }
  266. if (!TS->has_feature(TextServer::FEATURE_SHAPING)) {
  267. locales_to_skip.push_back("bn"); // Bengali
  268. locales_to_skip.push_back("hi"); // Hindi
  269. locales_to_skip.push_back("ml"); // Malayalam
  270. locales_to_skip.push_back("si"); // Sinhala
  271. locales_to_skip.push_back("ta"); // Tamil
  272. locales_to_skip.push_back("te"); // Telugu
  273. }
  274. if (!locales_to_skip.is_empty()) {
  275. WARN_PRINT("Some locales are not properly supported by selected Text Server and are disabled.");
  276. }
  277. String best;
  278. EditorTranslationList *etl = _editor_translations;
  279. while (etl->data) {
  280. const String &locale = etl->lang;
  281. // Skip locales which we can't render properly (see above comment).
  282. // Test against language code without regional variants (e.g. ur_PK).
  283. String lang_code = locale.get_slice("_", 0);
  284. if (locales_to_skip.find(lang_code) != -1) {
  285. etl++;
  286. continue;
  287. }
  288. lang_hint += ",";
  289. lang_hint += locale;
  290. if (host_lang == locale) {
  291. best = locale;
  292. }
  293. if (best == String() && host_lang.begins_with(locale)) {
  294. best = locale;
  295. }
  296. etl++;
  297. }
  298. if (best == String()) {
  299. best = "en";
  300. }
  301. _initial_set("interface/editor/editor_language", best);
  302. set_restart_if_changed("interface/editor/editor_language", true);
  303. hints["interface/editor/editor_language"] = PropertyInfo(Variant::STRING, "interface/editor/editor_language", PROPERTY_HINT_ENUM, lang_hint, PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
  304. }
  305. /* Interface */
  306. // Editor
  307. _initial_set("interface/editor/display_scale", 0);
  308. // Display what the Auto display scale setting effectively corresponds to.
  309. // The code below is adapted in `editor/editor_node.cpp` and `editor/project_manager.cpp`.
  310. // Make sure to update those when modifying the code below.
  311. #ifdef OSX_ENABLED
  312. float scale = DisplayServer::get_singleton()->screen_get_max_scale();
  313. #else
  314. const int screen = DisplayServer::get_singleton()->window_get_current_screen();
  315. float scale;
  316. if (DisplayServer::get_singleton()->screen_get_dpi(screen) >= 192 && DisplayServer::get_singleton()->screen_get_size(screen).y >= 1400) {
  317. // hiDPI display.
  318. scale = 2.0;
  319. } else if (DisplayServer::get_singleton()->screen_get_size(screen).y >= 1700) {
  320. // Likely a hiDPI display, but we aren't certain due to the returned DPI.
  321. // Use an intermediate scale to handle this situation.
  322. scale = 1.5;
  323. } else if (DisplayServer::get_singleton()->screen_get_size(screen).y <= 800) {
  324. // Small loDPI display. Use a smaller display scale so that editor elements fit more easily.
  325. // Icons won't look great, but this is better than having editor elements overflow from its window.
  326. scale = 0.75;
  327. } else {
  328. scale = 1.0;
  329. }
  330. #endif
  331. hints["interface/editor/display_scale"] = PropertyInfo(Variant::INT, "interface/editor/display_scale", PROPERTY_HINT_ENUM, vformat("Auto (%d%%),75%%,100%%,125%%,150%%,175%%,200%%,Custom", Math::round(scale * 100)), PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
  332. _initial_set("interface/editor/custom_display_scale", 1.0f);
  333. hints["interface/editor/custom_display_scale"] = PropertyInfo(Variant::FLOAT, "interface/editor/custom_display_scale", PROPERTY_HINT_RANGE, "0.5,3,0.01", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
  334. _initial_set("interface/editor/main_font_size", 14);
  335. hints["interface/editor/main_font_size"] = PropertyInfo(Variant::INT, "interface/editor/main_font_size", PROPERTY_HINT_RANGE, "8,48,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
  336. _initial_set("interface/editor/code_font_size", 14);
  337. hints["interface/editor/code_font_size"] = PropertyInfo(Variant::INT, "interface/editor/code_font_size", PROPERTY_HINT_RANGE, "8,48,1", PROPERTY_USAGE_DEFAULT);
  338. _initial_set("interface/editor/code_font_contextual_ligatures", 0);
  339. hints["interface/editor/code_font_contextual_ligatures"] = PropertyInfo(Variant::INT, "interface/editor/code_font_contextual_ligatures", PROPERTY_HINT_ENUM, "Default,Disable Contextual Alternates (Coding Ligatures),Use Custom OpenType Feature Set", PROPERTY_USAGE_DEFAULT);
  340. _initial_set("interface/editor/code_font_custom_opentype_features", "");
  341. _initial_set("interface/editor/code_font_custom_variations", "");
  342. _initial_set("interface/editor/font_antialiased", true);
  343. _initial_set("interface/editor/font_hinting", 0);
  344. #ifdef OSX_ENABLED
  345. hints["interface/editor/font_hinting"] = PropertyInfo(Variant::INT, "interface/editor/font_hinting", PROPERTY_HINT_ENUM, "Auto (None),None,Light,Normal", PROPERTY_USAGE_DEFAULT);
  346. #else
  347. hints["interface/editor/font_hinting"] = PropertyInfo(Variant::INT, "interface/editor/font_hinting", PROPERTY_HINT_ENUM, "Auto (Light),None,Light,Normal", PROPERTY_USAGE_DEFAULT);
  348. #endif
  349. _initial_set("interface/editor/main_font", "");
  350. hints["interface/editor/main_font"] = PropertyInfo(Variant::STRING, "interface/editor/main_font", PROPERTY_HINT_GLOBAL_FILE, "*.ttf,*.otf", PROPERTY_USAGE_DEFAULT);
  351. _initial_set("interface/editor/main_font_bold", "");
  352. hints["interface/editor/main_font_bold"] = PropertyInfo(Variant::STRING, "interface/editor/main_font_bold", PROPERTY_HINT_GLOBAL_FILE, "*.ttf,*.otf", PROPERTY_USAGE_DEFAULT);
  353. _initial_set("interface/editor/code_font", "");
  354. hints["interface/editor/code_font"] = PropertyInfo(Variant::STRING, "interface/editor/code_font", PROPERTY_HINT_GLOBAL_FILE, "*.ttf,*.otf", PROPERTY_USAGE_DEFAULT);
  355. _initial_set("interface/editor/dim_editor_on_dialog_popup", true);
  356. _initial_set("interface/editor/low_processor_mode_sleep_usec", 6900); // ~144 FPS
  357. hints["interface/editor/low_processor_mode_sleep_usec"] = PropertyInfo(Variant::FLOAT, "interface/editor/low_processor_mode_sleep_usec", PROPERTY_HINT_RANGE, "1,100000,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
  358. _initial_set("interface/editor/unfocused_low_processor_mode_sleep_usec", 50000); // 20 FPS
  359. hints["interface/editor/unfocused_low_processor_mode_sleep_usec"] = PropertyInfo(Variant::FLOAT, "interface/editor/unfocused_low_processor_mode_sleep_usec", PROPERTY_HINT_RANGE, "1,100000,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
  360. _initial_set("interface/editor/separate_distraction_mode", false);
  361. _initial_set("interface/editor/automatically_open_screenshots", true);
  362. _initial_set("interface/editor/single_window_mode", false);
  363. hints["interface/editor/single_window_mode"] = PropertyInfo(Variant::BOOL, "interface/editor/single_window_mode", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
  364. _initial_set("interface/editor/hide_console_window", false);
  365. _initial_set("interface/editor/save_each_scene_on_quit", true); // Regression
  366. // Inspector
  367. _initial_set("interface/inspector/max_array_dictionary_items_per_page", 20);
  368. hints["interface/inspector/max_array_dictionary_items_per_page"] = PropertyInfo(Variant::INT, "interface/inspector/max_array_dictionary_items_per_page", PROPERTY_HINT_RANGE, "10,100,1", PROPERTY_USAGE_DEFAULT);
  369. // Theme
  370. _initial_set("interface/theme/preset", "Default");
  371. hints["interface/theme/preset"] = PropertyInfo(Variant::STRING, "interface/theme/preset", PROPERTY_HINT_ENUM, "Default,Alien,Arc,Godot 2,Grey,Light,Solarized (Dark),Solarized (Light),Custom", PROPERTY_USAGE_DEFAULT);
  372. _initial_set("interface/theme/icon_and_font_color", 0);
  373. hints["interface/theme/icon_and_font_color"] = PropertyInfo(Variant::INT, "interface/theme/icon_and_font_color", PROPERTY_HINT_ENUM, "Auto,Dark,Light", PROPERTY_USAGE_DEFAULT);
  374. _initial_set("interface/theme/base_color", Color(0.2, 0.23, 0.31));
  375. hints["interface/theme/base_color"] = PropertyInfo(Variant::COLOR, "interface/theme/base_color", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT);
  376. _initial_set("interface/theme/accent_color", Color(0.41, 0.61, 0.91));
  377. hints["interface/theme/accent_color"] = PropertyInfo(Variant::COLOR, "interface/theme/accent_color", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT);
  378. _initial_set("interface/theme/contrast", 0.25);
  379. hints["interface/theme/contrast"] = PropertyInfo(Variant::FLOAT, "interface/theme/contrast", PROPERTY_HINT_RANGE, "0.01, 1, 0.01");
  380. _initial_set("interface/theme/icon_saturation", 1.0);
  381. hints["interface/theme/icon_saturation"] = PropertyInfo(Variant::FLOAT, "interface/theme/icon_saturation", PROPERTY_HINT_RANGE, "0,2,0.01", PROPERTY_USAGE_DEFAULT);
  382. _initial_set("interface/theme/relationship_line_opacity", 0.1);
  383. hints["interface/theme/relationship_line_opacity"] = PropertyInfo(Variant::FLOAT, "interface/theme/relationship_line_opacity", PROPERTY_HINT_RANGE, "0.00, 1, 0.01");
  384. _initial_set("interface/theme/highlight_tabs", false);
  385. _initial_set("interface/theme/border_size", 1);
  386. _initial_set("interface/theme/use_graph_node_headers", false);
  387. hints["interface/theme/border_size"] = PropertyInfo(Variant::INT, "interface/theme/border_size", PROPERTY_HINT_RANGE, "0,2,1", PROPERTY_USAGE_DEFAULT);
  388. _initial_set("interface/theme/additional_spacing", 0);
  389. hints["interface/theme/additional_spacing"] = PropertyInfo(Variant::FLOAT, "interface/theme/additional_spacing", PROPERTY_HINT_RANGE, "0,5,0.1", PROPERTY_USAGE_DEFAULT);
  390. _initial_set("interface/theme/custom_theme", "");
  391. hints["interface/theme/custom_theme"] = PropertyInfo(Variant::STRING, "interface/theme/custom_theme", PROPERTY_HINT_GLOBAL_FILE, "*.res,*.tres,*.theme", PROPERTY_USAGE_DEFAULT);
  392. // Scene tabs
  393. _initial_set("interface/scene_tabs/show_extension", false);
  394. _initial_set("interface/scene_tabs/show_thumbnail_on_hover", true);
  395. _initial_set("interface/scene_tabs/resize_if_many_tabs", true);
  396. _initial_set("interface/scene_tabs/minimum_width", 50);
  397. hints["interface/scene_tabs/minimum_width"] = PropertyInfo(Variant::INT, "interface/scene_tabs/minimum_width", PROPERTY_HINT_RANGE, "50,500,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
  398. _initial_set("interface/scene_tabs/show_script_button", false);
  399. /* Filesystem */
  400. // Directories
  401. _initial_set("filesystem/directories/autoscan_project_path", "");
  402. hints["filesystem/directories/autoscan_project_path"] = PropertyInfo(Variant::STRING, "filesystem/directories/autoscan_project_path", PROPERTY_HINT_GLOBAL_DIR);
  403. _initial_set("filesystem/directories/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));
  404. hints["filesystem/directories/default_project_path"] = PropertyInfo(Variant::STRING, "filesystem/directories/default_project_path", PROPERTY_HINT_GLOBAL_DIR);
  405. // On save
  406. _initial_set("filesystem/on_save/compress_binary_resources", true);
  407. _initial_set("filesystem/on_save/safe_save_on_backup_then_rename", true);
  408. // File dialog
  409. _initial_set("filesystem/file_dialog/show_hidden_files", false);
  410. _initial_set("filesystem/file_dialog/display_mode", 0);
  411. hints["filesystem/file_dialog/display_mode"] = PropertyInfo(Variant::INT, "filesystem/file_dialog/display_mode", PROPERTY_HINT_ENUM, "Thumbnails,List");
  412. _initial_set("filesystem/file_dialog/thumbnail_size", 64);
  413. hints["filesystem/file_dialog/thumbnail_size"] = PropertyInfo(Variant::INT, "filesystem/file_dialog/thumbnail_size", PROPERTY_HINT_RANGE, "32,128,16");
  414. /* Docks */
  415. // SceneTree
  416. _initial_set("docks/scene_tree/start_create_dialog_fully_expanded", false);
  417. // FileSystem
  418. _initial_set("docks/filesystem/thumbnail_size", 64);
  419. hints["docks/filesystem/thumbnail_size"] = PropertyInfo(Variant::INT, "docks/filesystem/thumbnail_size", PROPERTY_HINT_RANGE, "32,128,16");
  420. _initial_set("docks/filesystem/always_show_folders", true);
  421. // Property editor
  422. _initial_set("docks/property_editor/auto_refresh_interval", 0.2); //update 5 times per second by default
  423. _initial_set("docks/property_editor/subresource_hue_tint", 0.75);
  424. hints["docks/property_editor/subresource_hue_tint"] = PropertyInfo(Variant::FLOAT, "docks/property_editor/subresource_hue_tint", PROPERTY_HINT_RANGE, "0,1,0.01", PROPERTY_USAGE_DEFAULT);
  425. /* Text editor */
  426. // Theme
  427. _initial_set("text_editor/theme/color_theme", "Adaptive");
  428. hints["text_editor/theme/color_theme"] = PropertyInfo(Variant::STRING, "text_editor/theme/color_theme", PROPERTY_HINT_ENUM, "Adaptive,Default,Custom");
  429. _initial_set("text_editor/theme/line_spacing", 6);
  430. hints["text_editor/theme/line_spacing"] = PropertyInfo(Variant::INT, "text_editor/theme/line_spacing", PROPERTY_HINT_RANGE, "0,50,1");
  431. _load_default_text_editor_theme();
  432. // Highlighting
  433. _initial_set("text_editor/highlighting/highlight_all_occurrences", true);
  434. _initial_set("text_editor/highlighting/highlight_current_line", true);
  435. _initial_set("text_editor/highlighting/highlight_type_safe_lines", true);
  436. // Indent
  437. _initial_set("text_editor/indent/type", 0);
  438. hints["text_editor/indent/type"] = PropertyInfo(Variant::INT, "text_editor/indent/type", PROPERTY_HINT_ENUM, "Tabs,Spaces");
  439. _initial_set("text_editor/indent/size", 4);
  440. hints["text_editor/indent/size"] = PropertyInfo(Variant::INT, "text_editor/indent/size", PROPERTY_HINT_RANGE, "1, 64, 1"); // size of 0 crashes.
  441. _initial_set("text_editor/indent/auto_indent", true);
  442. _initial_set("text_editor/indent/convert_indent_on_save", true);
  443. _initial_set("text_editor/indent/draw_tabs", true);
  444. _initial_set("text_editor/indent/draw_spaces", false);
  445. // Navigation
  446. _initial_set("text_editor/navigation/smooth_scrolling", true);
  447. _initial_set("text_editor/navigation/v_scroll_speed", 80);
  448. _initial_set("text_editor/navigation/show_minimap", true);
  449. _initial_set("text_editor/navigation/minimap_width", 80);
  450. hints["text_editor/navigation/minimap_width"] = PropertyInfo(Variant::INT, "text_editor/navigation/minimap_width", PROPERTY_HINT_RANGE, "50,250,1");
  451. // Appearance
  452. _initial_set("text_editor/appearance/show_line_numbers", true);
  453. _initial_set("text_editor/appearance/line_numbers_zero_padded", false);
  454. _initial_set("text_editor/appearance/show_bookmark_gutter", true);
  455. _initial_set("text_editor/appearance/show_info_gutter", true);
  456. _initial_set("text_editor/appearance/code_folding", true);
  457. _initial_set("text_editor/appearance/word_wrap", false);
  458. _initial_set("text_editor/appearance/show_line_length_guidelines", true);
  459. _initial_set("text_editor/appearance/line_length_guideline_soft_column", 80);
  460. hints["text_editor/appearance/line_length_guideline_soft_column"] = PropertyInfo(Variant::INT, "text_editor/appearance/line_length_guideline_soft_column", PROPERTY_HINT_RANGE, "20, 160, 1");
  461. _initial_set("text_editor/appearance/line_length_guideline_hard_column", 100);
  462. hints["text_editor/appearance/line_length_guideline_hard_column"] = PropertyInfo(Variant::INT, "text_editor/appearance/line_length_guideline_hard_column", PROPERTY_HINT_RANGE, "20, 160, 1");
  463. // Script list
  464. _initial_set("text_editor/script_list/show_members_overview", true);
  465. // Files
  466. _initial_set("text_editor/files/trim_trailing_whitespace_on_save", false);
  467. _initial_set("text_editor/files/autosave_interval_secs", 0);
  468. _initial_set("text_editor/files/restore_scripts_on_load", true);
  469. // Tools
  470. _initial_set("text_editor/tools/create_signal_callbacks", true);
  471. _initial_set("text_editor/tools/sort_members_outline_alphabetically", false);
  472. // Cursor
  473. _initial_set("text_editor/cursor/scroll_past_end_of_file", false);
  474. _initial_set("text_editor/cursor/block_caret", false);
  475. _initial_set("text_editor/cursor/caret_blink", true);
  476. _initial_set("text_editor/cursor/caret_blink_speed", 0.5);
  477. hints["text_editor/cursor/caret_blink_speed"] = PropertyInfo(Variant::FLOAT, "text_editor/cursor/caret_blink_speed", PROPERTY_HINT_RANGE, "0.1, 10, 0.01");
  478. _initial_set("text_editor/cursor/right_click_moves_caret", true);
  479. // Completion
  480. _initial_set("text_editor/completion/idle_parse_delay", 2.0);
  481. hints["text_editor/completion/idle_parse_delay"] = PropertyInfo(Variant::FLOAT, "text_editor/completion/idle_parse_delay", PROPERTY_HINT_RANGE, "0.1, 10, 0.01");
  482. _initial_set("text_editor/completion/auto_brace_complete", true);
  483. _initial_set("text_editor/completion/code_complete_delay", 0.3);
  484. hints["text_editor/completion/code_complete_delay"] = PropertyInfo(Variant::FLOAT, "text_editor/completion/code_complete_delay", PROPERTY_HINT_RANGE, "0.01, 5, 0.01");
  485. _initial_set("text_editor/completion/put_callhint_tooltip_below_current_line", true);
  486. _initial_set("text_editor/completion/callhint_tooltip_offset", Vector2());
  487. _initial_set("text_editor/completion/complete_file_paths", true);
  488. _initial_set("text_editor/completion/add_type_hints", false);
  489. _initial_set("text_editor/completion/use_single_quotes", false);
  490. // Help
  491. _initial_set("text_editor/help/show_help_index", true);
  492. _initial_set("text_editor/help/help_font_size", 15);
  493. hints["text_editor/help/help_font_size"] = PropertyInfo(Variant::INT, "text_editor/help/help_font_size", PROPERTY_HINT_RANGE, "8,48,1");
  494. _initial_set("text_editor/help/help_source_font_size", 14);
  495. hints["text_editor/help/help_source_font_size"] = PropertyInfo(Variant::INT, "text_editor/help/help_source_font_size", PROPERTY_HINT_RANGE, "8,48,1");
  496. _initial_set("text_editor/help/help_title_font_size", 23);
  497. hints["text_editor/help/help_title_font_size"] = PropertyInfo(Variant::INT, "text_editor/help/help_title_font_size", PROPERTY_HINT_RANGE, "8,48,1");
  498. _initial_set("text_editor/help/class_reference_examples", 0);
  499. hints["text_editor/help/class_reference_examples"] = PropertyInfo(Variant::INT, "text_editor/help/class_reference_examples", PROPERTY_HINT_ENUM, "GDScript,C#,GDScript and C#");
  500. /* Editors */
  501. // GridMap
  502. _initial_set("editors/grid_map/pick_distance", 5000.0);
  503. // 3D
  504. _initial_set("editors/3d/primary_grid_color", Color(0.56, 0.56, 0.56, 0.5));
  505. hints["editors/3d/primary_grid_color"] = PropertyInfo(Variant::COLOR, "editors/3d/primary_grid_color", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT);
  506. _initial_set("editors/3d/secondary_grid_color", Color(0.38, 0.38, 0.38, 0.5));
  507. hints["editors/3d/secondary_grid_color"] = PropertyInfo(Variant::COLOR, "editors/3d/secondary_grid_color", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT);
  508. // Use a similar color to the 2D editor selection.
  509. _initial_set("editors/3d/selection_box_color", Color(1.0, 0.5, 0));
  510. hints["editors/3d/selection_box_color"] = PropertyInfo(Variant::COLOR, "editors/3d/selection_box_color", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
  511. // If a line is a multiple of this, it uses the primary grid color.
  512. // Use a power of 2 value by default as it's more common to use powers of 2 in level design.
  513. _initial_set("editors/3d/primary_grid_steps", 8);
  514. hints["editors/3d/primary_grid_steps"] = PropertyInfo(Variant::INT, "editors/3d/primary_grid_steps", PROPERTY_HINT_RANGE, "1,100,1", PROPERTY_USAGE_DEFAULT);
  515. // At 1000, the grid mostly looks like it has no edge.
  516. _initial_set("editors/3d/grid_size", 200);
  517. hints["editors/3d/grid_size"] = PropertyInfo(Variant::INT, "editors/3d/grid_size", PROPERTY_HINT_RANGE, "1,2000,1", PROPERTY_USAGE_DEFAULT);
  518. // Default largest grid size is 100m, 10^2 (primary grid lines are 1km apart when primary_grid_steps is 10).
  519. _initial_set("editors/3d/grid_division_level_max", 2);
  520. // Higher values produce graphical artifacts when far away unless View Z-Far
  521. // is increased significantly more than it really should need to be.
  522. hints["editors/3d/grid_division_level_max"] = PropertyInfo(Variant::INT, "editors/3d/grid_division_level_max", PROPERTY_HINT_RANGE, "-1,3,1", PROPERTY_USAGE_DEFAULT);
  523. // Default smallest grid size is 1cm, 10^-2.
  524. _initial_set("editors/3d/grid_division_level_min", -2);
  525. // Lower values produce graphical artifacts regardless of view clipping planes, so limit to -2 as a lower bound.
  526. hints["editors/3d/grid_division_level_min"] = PropertyInfo(Variant::INT, "editors/3d/grid_division_level_min", PROPERTY_HINT_RANGE, "-2,2,1", PROPERTY_USAGE_DEFAULT);
  527. // -0.2 seems like a sensible default. -1.0 gives Blender-like behavior, 0.5 gives huge grids.
  528. _initial_set("editors/3d/grid_division_level_bias", -0.2);
  529. hints["editors/3d/grid_division_level_bias"] = PropertyInfo(Variant::FLOAT, "editors/3d/grid_division_level_bias", PROPERTY_HINT_RANGE, "-1.0,0.5,0.1", PROPERTY_USAGE_DEFAULT);
  530. _initial_set("editors/3d/grid_xz_plane", true);
  531. _initial_set("editors/3d/grid_xy_plane", false);
  532. _initial_set("editors/3d/grid_yz_plane", false);
  533. // Use a lower default FOV for the 3D camera compared to the
  534. // Camera3D node as the 3D viewport doesn't span the whole screen.
  535. // This means it's technically viewed from a further distance, which warrants a narrower FOV.
  536. _initial_set("editors/3d/default_fov", 70.0);
  537. hints["editors/3d/default_fov"] = PropertyInfo(Variant::FLOAT, "editors/3d/default_fov", PROPERTY_HINT_RANGE, "1,179,0.1");
  538. _initial_set("editors/3d/default_z_near", 0.05);
  539. hints["editors/3d/default_z_near"] = PropertyInfo(Variant::FLOAT, "editors/3d/default_z_near", PROPERTY_HINT_RANGE, "0.01,10,0.01,or_greater");
  540. _initial_set("editors/3d/default_z_far", 4000.0);
  541. hints["editors/3d/default_z_far"] = PropertyInfo(Variant::FLOAT, "editors/3d/default_z_far", PROPERTY_HINT_RANGE, "0.1,4000,0.1,or_greater");
  542. // 3D: Navigation
  543. _initial_set("editors/3d/navigation/navigation_scheme", 0);
  544. _initial_set("editors/3d/navigation/invert_y_axis", false);
  545. _initial_set("editors/3d/navigation/invert_x_axis", false);
  546. hints["editors/3d/navigation/navigation_scheme"] = PropertyInfo(Variant::INT, "editors/3d/navigation/navigation_scheme", PROPERTY_HINT_ENUM, "Godot,Maya,Modo");
  547. _initial_set("editors/3d/navigation/zoom_style", 0);
  548. hints["editors/3d/navigation/zoom_style"] = PropertyInfo(Variant::INT, "editors/3d/navigation/zoom_style", PROPERTY_HINT_ENUM, "Vertical, Horizontal");
  549. _initial_set("editors/3d/navigation/emulate_3_button_mouse", false);
  550. _initial_set("editors/3d/navigation/orbit_modifier", 0);
  551. hints["editors/3d/navigation/orbit_modifier"] = PropertyInfo(Variant::INT, "editors/3d/navigation/orbit_modifier", PROPERTY_HINT_ENUM, "None,Shift,Alt,Meta,Ctrl");
  552. _initial_set("editors/3d/navigation/pan_modifier", 1);
  553. hints["editors/3d/navigation/pan_modifier"] = PropertyInfo(Variant::INT, "editors/3d/navigation/pan_modifier", PROPERTY_HINT_ENUM, "None,Shift,Alt,Meta,Ctrl");
  554. _initial_set("editors/3d/navigation/zoom_modifier", 4);
  555. hints["editors/3d/navigation/zoom_modifier"] = PropertyInfo(Variant::INT, "editors/3d/navigation/zoom_modifier", PROPERTY_HINT_ENUM, "None,Shift,Alt,Meta,Ctrl");
  556. _initial_set("editors/3d/navigation/warped_mouse_panning", true);
  557. // 3D: Navigation feel
  558. _initial_set("editors/3d/navigation_feel/orbit_sensitivity", 0.4);
  559. hints["editors/3d/navigation_feel/orbit_sensitivity"] = PropertyInfo(Variant::FLOAT, "editors/3d/navigation_feel/orbit_sensitivity", PROPERTY_HINT_RANGE, "0.0, 2, 0.01");
  560. _initial_set("editors/3d/navigation_feel/orbit_inertia", 0.05);
  561. hints["editors/3d/navigation_feel/orbit_inertia"] = PropertyInfo(Variant::FLOAT, "editors/3d/navigation_feel/orbit_inertia", PROPERTY_HINT_RANGE, "0.0, 1, 0.01");
  562. _initial_set("editors/3d/navigation_feel/translation_inertia", 0.15);
  563. hints["editors/3d/navigation_feel/translation_inertia"] = PropertyInfo(Variant::FLOAT, "editors/3d/navigation_feel/translation_inertia", PROPERTY_HINT_RANGE, "0.0, 1, 0.01");
  564. _initial_set("editors/3d/navigation_feel/zoom_inertia", 0.075);
  565. hints["editors/3d/navigation_feel/zoom_inertia"] = PropertyInfo(Variant::FLOAT, "editors/3d/navigation_feel/zoom_inertia", PROPERTY_HINT_RANGE, "0.0, 1, 0.01");
  566. _initial_set("editors/3d/navigation_feel/manipulation_orbit_inertia", 0.075);
  567. hints["editors/3d/navigation_feel/manipulation_orbit_inertia"] = PropertyInfo(Variant::FLOAT, "editors/3d/navigation_feel/manipulation_orbit_inertia", PROPERTY_HINT_RANGE, "0.0, 1, 0.01");
  568. _initial_set("editors/3d/navigation_feel/manipulation_translation_inertia", 0.075);
  569. hints["editors/3d/navigation_feel/manipulation_translation_inertia"] = PropertyInfo(Variant::FLOAT, "editors/3d/navigation_feel/manipulation_translation_inertia", PROPERTY_HINT_RANGE, "0.0, 1, 0.01");
  570. // 3D: Freelook
  571. _initial_set("editors/3d/freelook/freelook_navigation_scheme", false);
  572. hints["editors/3d/freelook/freelook_navigation_scheme"] = PropertyInfo(Variant::INT, "editors/3d/freelook/freelook_navigation_scheme", PROPERTY_HINT_ENUM, "Default,Partially Axis-Locked (id Tech),Fully Axis-Locked (Minecraft)");
  573. _initial_set("editors/3d/freelook/freelook_sensitivity", 0.4);
  574. hints["editors/3d/freelook/freelook_sensitivity"] = PropertyInfo(Variant::FLOAT, "editors/3d/freelook/freelook_sensitivity", PROPERTY_HINT_RANGE, "0.0, 2, 0.01");
  575. _initial_set("editors/3d/freelook/freelook_inertia", 0.1);
  576. hints["editors/3d/freelook/freelook_inertia"] = PropertyInfo(Variant::FLOAT, "editors/3d/freelook/freelook_inertia", PROPERTY_HINT_RANGE, "0.0, 1, 0.01");
  577. _initial_set("editors/3d/freelook/freelook_base_speed", 5.0);
  578. hints["editors/3d/freelook/freelook_base_speed"] = PropertyInfo(Variant::FLOAT, "editors/3d/freelook/freelook_base_speed", PROPERTY_HINT_RANGE, "0.0, 10, 0.01");
  579. _initial_set("editors/3d/freelook/freelook_activation_modifier", 0);
  580. hints["editors/3d/freelook/freelook_activation_modifier"] = PropertyInfo(Variant::INT, "editors/3d/freelook/freelook_activation_modifier", PROPERTY_HINT_ENUM, "None,Shift,Alt,Meta,Ctrl");
  581. _initial_set("editors/3d/freelook/freelook_speed_zoom_link", false);
  582. // 2D
  583. _initial_set("editors/2d/grid_color", Color(1.0, 1.0, 1.0, 0.07));
  584. _initial_set("editors/2d/guides_color", Color(0.6, 0.0, 0.8));
  585. _initial_set("editors/2d/smart_snapping_line_color", Color(0.9, 0.1, 0.1));
  586. _initial_set("editors/2d/bone_width", 5);
  587. _initial_set("editors/2d/bone_color1", Color(1.0, 1.0, 1.0, 0.9));
  588. _initial_set("editors/2d/bone_color2", Color(0.6, 0.6, 0.6, 0.9));
  589. _initial_set("editors/2d/bone_selected_color", Color(0.9, 0.45, 0.45, 0.9));
  590. _initial_set("editors/2d/bone_ik_color", Color(0.9, 0.9, 0.45, 0.9));
  591. _initial_set("editors/2d/bone_outline_color", Color(0.35, 0.35, 0.35));
  592. _initial_set("editors/2d/bone_outline_size", 2);
  593. _initial_set("editors/2d/viewport_border_color", Color(0.4, 0.4, 1.0, 0.4));
  594. _initial_set("editors/2d/constrain_editor_view", true);
  595. _initial_set("editors/2d/warped_mouse_panning", true);
  596. _initial_set("editors/2d/simple_panning", false);
  597. _initial_set("editors/2d/scroll_to_pan", false);
  598. _initial_set("editors/2d/pan_speed", 20);
  599. // Polygon editor
  600. _initial_set("editors/poly_editor/point_grab_radius", 8);
  601. _initial_set("editors/poly_editor/show_previous_outline", true);
  602. // Animation
  603. _initial_set("editors/animation/autorename_animation_tracks", true);
  604. _initial_set("editors/animation/confirm_insert_track", true);
  605. _initial_set("editors/animation/default_create_bezier_tracks", false);
  606. _initial_set("editors/animation/default_create_reset_tracks", true);
  607. _initial_set("editors/animation/onion_layers_past_color", Color(1, 0, 0));
  608. _initial_set("editors/animation/onion_layers_future_color", Color(0, 1, 0));
  609. // Visual editors
  610. _initial_set("editors/visual_editors/minimap_opacity", 0.85);
  611. hints["editors/visual_editors/minimap_opacity"] = PropertyInfo(Variant::FLOAT, "editors/visual_editors/minimap_opacity", PROPERTY_HINT_RANGE, "0.0,1.0,0.01", PROPERTY_USAGE_DEFAULT);
  612. /* Run */
  613. // Window placement
  614. _initial_set("run/window_placement/rect", 1);
  615. hints["run/window_placement/rect"] = PropertyInfo(Variant::INT, "run/window_placement/rect", PROPERTY_HINT_ENUM, "Top Left,Centered,Custom Position,Force Maximized,Force Fullscreen");
  616. String screen_hints = "Same as Editor,Previous Monitor,Next Monitor";
  617. for (int i = 0; i < DisplayServer::get_singleton()->get_screen_count(); i++) {
  618. screen_hints += ",Monitor " + itos(i + 1);
  619. }
  620. _initial_set("run/window_placement/rect_custom_position", Vector2());
  621. _initial_set("run/window_placement/screen", 0);
  622. hints["run/window_placement/screen"] = PropertyInfo(Variant::INT, "run/window_placement/screen", PROPERTY_HINT_ENUM, screen_hints);
  623. // Auto save
  624. _initial_set("run/auto_save/save_before_running", true);
  625. // Output
  626. _initial_set("run/output/font_size", 13);
  627. hints["run/output/font_size"] = PropertyInfo(Variant::INT, "run/output/font_size", PROPERTY_HINT_RANGE, "8,48,1");
  628. _initial_set("run/output/always_clear_output_on_play", true);
  629. _initial_set("run/output/always_open_output_on_play", true);
  630. _initial_set("run/output/always_close_output_on_stop", false);
  631. /* Network */
  632. // Debug
  633. _initial_set("network/debug/remote_host", "127.0.0.1"); // Hints provided in setup_network
  634. _initial_set("network/debug/remote_port", 6007);
  635. hints["network/debug/remote_port"] = PropertyInfo(Variant::INT, "network/debug/remote_port", PROPERTY_HINT_RANGE, "1,65535,1");
  636. // SSL
  637. _initial_set("network/ssl/editor_ssl_certificates", _SYSTEM_CERTS_PATH);
  638. hints["network/ssl/editor_ssl_certificates"] = PropertyInfo(Variant::STRING, "network/ssl/editor_ssl_certificates", PROPERTY_HINT_GLOBAL_FILE, "*.crt,*.pem");
  639. /* Extra config */
  640. _initial_set("project_manager/sorting_order", 0);
  641. hints["project_manager/sorting_order"] = PropertyInfo(Variant::INT, "project_manager/sorting_order", PROPERTY_HINT_ENUM, "Name,Path,Last Edited");
  642. if (p_extra_config.is_valid()) {
  643. if (p_extra_config->has_section("init_projects") && p_extra_config->has_section_key("init_projects", "list")) {
  644. Vector<String> list = p_extra_config->get_value("init_projects", "list");
  645. for (int i = 0; i < list.size(); i++) {
  646. String name = list[i].replace("/", "::");
  647. set("projects/" + name, list[i]);
  648. };
  649. };
  650. if (p_extra_config->has_section("presets")) {
  651. List<String> keys;
  652. p_extra_config->get_section_keys("presets", &keys);
  653. for (List<String>::Element *E = keys.front(); E; E = E->next()) {
  654. String key = E->get();
  655. Variant val = p_extra_config->get_value("presets", key);
  656. set(key, val);
  657. };
  658. };
  659. };
  660. }
  661. void EditorSettings::_load_default_text_editor_theme() {
  662. bool dark_theme = is_dark_theme();
  663. _initial_set("text_editor/highlighting/symbol_color", Color(0.73, 0.87, 1.0));
  664. _initial_set("text_editor/highlighting/keyword_color", Color(1.0, 1.0, 0.7));
  665. _initial_set("text_editor/highlighting/base_type_color", Color(0.64, 1.0, 0.83));
  666. _initial_set("text_editor/highlighting/engine_type_color", Color(0.51, 0.83, 1.0));
  667. _initial_set("text_editor/highlighting/user_type_color", Color(0.42, 0.67, 0.93));
  668. _initial_set("text_editor/highlighting/comment_color", Color(0.4, 0.4, 0.4));
  669. _initial_set("text_editor/highlighting/string_color", Color(0.94, 0.43, 0.75));
  670. _initial_set("text_editor/highlighting/background_color", dark_theme ? Color(0.0, 0.0, 0.0, 0.23) : Color(0.2, 0.23, 0.31));
  671. _initial_set("text_editor/highlighting/completion_background_color", Color(0.17, 0.16, 0.2));
  672. _initial_set("text_editor/highlighting/completion_selected_color", Color(0.26, 0.26, 0.27));
  673. _initial_set("text_editor/highlighting/completion_existing_color", Color(0.13, 0.87, 0.87, 0.87));
  674. _initial_set("text_editor/highlighting/completion_scroll_color", Color(1, 1, 1));
  675. _initial_set("text_editor/highlighting/completion_font_color", Color(0.67, 0.67, 0.67));
  676. _initial_set("text_editor/highlighting/text_color", Color(0.67, 0.67, 0.67));
  677. _initial_set("text_editor/highlighting/line_number_color", Color(0.67, 0.67, 0.67, 0.4));
  678. _initial_set("text_editor/highlighting/safe_line_number_color", Color(0.67, 0.78, 0.67, 0.6));
  679. _initial_set("text_editor/highlighting/caret_color", Color(0.67, 0.67, 0.67));
  680. _initial_set("text_editor/highlighting/caret_background_color", Color(0, 0, 0));
  681. _initial_set("text_editor/highlighting/text_selected_color", Color(0, 0, 0));
  682. _initial_set("text_editor/highlighting/selection_color", Color(0.41, 0.61, 0.91, 0.35));
  683. _initial_set("text_editor/highlighting/brace_mismatch_color", Color(1, 0.2, 0.2));
  684. _initial_set("text_editor/highlighting/current_line_color", Color(0.3, 0.5, 0.8, 0.15));
  685. _initial_set("text_editor/highlighting/line_length_guideline_color", Color(0.3, 0.5, 0.8, 0.1));
  686. _initial_set("text_editor/highlighting/word_highlighted_color", Color(0.8, 0.9, 0.9, 0.15));
  687. _initial_set("text_editor/highlighting/number_color", Color(0.92, 0.58, 0.2));
  688. _initial_set("text_editor/highlighting/function_color", Color(0.4, 0.64, 0.81));
  689. _initial_set("text_editor/highlighting/member_variable_color", Color(0.9, 0.31, 0.35));
  690. _initial_set("text_editor/highlighting/mark_color", Color(1.0, 0.4, 0.4, 0.4));
  691. _initial_set("text_editor/highlighting/bookmark_color", Color(0.08, 0.49, 0.98));
  692. _initial_set("text_editor/highlighting/breakpoint_color", Color(0.9, 0.29, 0.3));
  693. _initial_set("text_editor/highlighting/executing_line_color", Color(0.98, 0.89, 0.27));
  694. _initial_set("text_editor/highlighting/code_folding_color", Color(0.8, 0.8, 0.8, 0.8));
  695. _initial_set("text_editor/highlighting/search_result_color", Color(0.05, 0.25, 0.05, 1));
  696. _initial_set("text_editor/highlighting/search_result_border_color", Color(0.41, 0.61, 0.91, 0.38));
  697. }
  698. bool EditorSettings::_save_text_editor_theme(String p_file) {
  699. String theme_section = "color_theme";
  700. Ref<ConfigFile> cf = memnew(ConfigFile); // hex is better?
  701. List<String> keys;
  702. props.get_key_list(&keys);
  703. keys.sort();
  704. for (const List<String>::Element *E = keys.front(); E; E = E->next()) {
  705. const String &key = E->get();
  706. if (key.begins_with("text_editor/highlighting/") && key.find("color") >= 0) {
  707. cf->set_value(theme_section, key.replace("text_editor/highlighting/", ""), ((Color)props[key].variant).to_html());
  708. }
  709. }
  710. Error err = cf->save(p_file);
  711. return err == OK;
  712. }
  713. bool EditorSettings::_is_default_text_editor_theme(String p_theme_name) {
  714. return p_theme_name == "default" || p_theme_name == "adaptive" || p_theme_name == "custom";
  715. }
  716. static Dictionary _get_builtin_script_templates() {
  717. Dictionary templates;
  718. // No Comments
  719. templates["no_comments.gd"] =
  720. "extends %BASE%\n"
  721. "\n"
  722. "\n"
  723. "func _ready()%VOID_RETURN%:\n"
  724. "%TS%pass\n";
  725. // Empty
  726. templates["empty.gd"] =
  727. "extends %BASE%"
  728. "\n"
  729. "\n";
  730. return templates;
  731. }
  732. static void _create_script_templates(const String &p_path) {
  733. Dictionary templates = _get_builtin_script_templates();
  734. List<Variant> keys;
  735. templates.get_key_list(&keys);
  736. FileAccess *file = FileAccess::create(FileAccess::ACCESS_FILESYSTEM);
  737. DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  738. dir->change_dir(p_path);
  739. for (int i = 0; i < keys.size(); i++) {
  740. if (!dir->file_exists(keys[i])) {
  741. Error err = file->reopen(p_path.plus_file((String)keys[i]), FileAccess::WRITE);
  742. ERR_FAIL_COND(err != OK);
  743. file->store_string(templates[keys[i]]);
  744. file->close();
  745. }
  746. }
  747. memdelete(dir);
  748. memdelete(file);
  749. }
  750. // PUBLIC METHODS
  751. EditorSettings *EditorSettings::get_singleton() {
  752. return singleton.ptr();
  753. }
  754. void EditorSettings::create() {
  755. if (singleton.ptr()) {
  756. return; //pointless
  757. }
  758. DirAccess *dir = nullptr;
  759. String data_path;
  760. String data_dir;
  761. String config_path;
  762. String config_dir;
  763. String cache_path;
  764. String cache_dir;
  765. Ref<ConfigFile> extra_config = memnew(ConfigFile);
  766. String exe_path = OS::get_singleton()->get_executable_path().get_base_dir();
  767. DirAccess *d = DirAccess::create_for_path(exe_path);
  768. bool self_contained = false;
  769. if (d->file_exists(exe_path + "/._sc_")) {
  770. self_contained = true;
  771. Error err = extra_config->load(exe_path + "/._sc_");
  772. if (err != OK) {
  773. ERR_PRINT("Can't load config from path '" + exe_path + "/._sc_'.");
  774. }
  775. } else if (d->file_exists(exe_path + "/_sc_")) {
  776. self_contained = true;
  777. Error err = extra_config->load(exe_path + "/_sc_");
  778. if (err != OK) {
  779. ERR_PRINT("Can't load config from path '" + exe_path + "/_sc_'.");
  780. }
  781. }
  782. memdelete(d);
  783. if (self_contained) {
  784. // editor is self contained, all in same folder
  785. data_path = exe_path;
  786. data_dir = data_path.plus_file("editor_data");
  787. config_path = exe_path;
  788. config_dir = data_dir;
  789. cache_path = exe_path;
  790. cache_dir = data_dir.plus_file("cache");
  791. } else {
  792. // Typically XDG_DATA_HOME or %APPDATA%
  793. data_path = OS::get_singleton()->get_data_path();
  794. data_dir = data_path.plus_file(OS::get_singleton()->get_godot_dir_name());
  795. // Can be different from data_path e.g. on Linux or macOS
  796. config_path = OS::get_singleton()->get_config_path();
  797. config_dir = config_path.plus_file(OS::get_singleton()->get_godot_dir_name());
  798. // Can be different from above paths, otherwise a subfolder of data_dir
  799. cache_path = OS::get_singleton()->get_cache_path();
  800. if (cache_path == data_path) {
  801. cache_dir = data_dir.plus_file("cache");
  802. } else {
  803. cache_dir = cache_path.plus_file(OS::get_singleton()->get_godot_dir_name());
  804. }
  805. }
  806. ClassDB::register_class<EditorSettings>(); //otherwise it can't be unserialized
  807. String config_file_path;
  808. if (data_path != "" && config_path != "" && cache_path != "") {
  809. // Validate/create data dir and subdirectories
  810. dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  811. if (dir->change_dir(data_dir) != OK) {
  812. dir->make_dir_recursive(data_dir);
  813. if (dir->change_dir(data_dir) != OK) {
  814. ERR_PRINT("Cannot create data directory!");
  815. memdelete(dir);
  816. goto fail;
  817. }
  818. }
  819. if (dir->change_dir("templates") != OK) {
  820. dir->make_dir("templates");
  821. } else {
  822. dir->change_dir("..");
  823. }
  824. // Validate/create cache dir
  825. if (dir->change_dir(cache_dir) != OK) {
  826. dir->make_dir_recursive(cache_dir);
  827. if (dir->change_dir(cache_dir) != OK) {
  828. ERR_PRINT("Cannot create cache directory!");
  829. memdelete(dir);
  830. goto fail;
  831. }
  832. }
  833. // Validate/create config dir and subdirectories
  834. if (dir->change_dir(config_dir) != OK) {
  835. dir->make_dir_recursive(config_dir);
  836. if (dir->change_dir(config_dir) != OK) {
  837. ERR_PRINT("Cannot create config directory!");
  838. memdelete(dir);
  839. goto fail;
  840. }
  841. }
  842. if (dir->change_dir("text_editor_themes") != OK) {
  843. dir->make_dir("text_editor_themes");
  844. } else {
  845. dir->change_dir("..");
  846. }
  847. if (dir->change_dir("script_templates") != OK) {
  848. dir->make_dir("script_templates");
  849. } else {
  850. dir->change_dir("..");
  851. }
  852. if (dir->change_dir("feature_profiles") != OK) {
  853. dir->make_dir("feature_profiles");
  854. } else {
  855. dir->change_dir("..");
  856. }
  857. _create_script_templates(dir->get_current_dir().plus_file("script_templates"));
  858. {
  859. // Validate/create project-specific editor settings dir.
  860. DirAccessRef da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  861. if (da->change_dir(EditorSettings::PROJECT_EDITOR_SETTINGS_PATH) != OK) {
  862. Error err = da->make_dir_recursive(EditorSettings::PROJECT_EDITOR_SETTINGS_PATH);
  863. if (err || da->change_dir(EditorSettings::PROJECT_EDITOR_SETTINGS_PATH) != OK) {
  864. ERR_FAIL_MSG("Failed to create '" + EditorSettings::PROJECT_EDITOR_SETTINGS_PATH + "' folder.");
  865. }
  866. }
  867. }
  868. // Validate editor config file
  869. String config_file_name = "editor_settings-" + itos(VERSION_MAJOR) + ".tres";
  870. config_file_path = config_dir.plus_file(config_file_name);
  871. if (!dir->file_exists(config_file_name)) {
  872. memdelete(dir);
  873. goto fail;
  874. }
  875. memdelete(dir);
  876. singleton = ResourceLoader::load(config_file_path, "EditorSettings");
  877. if (singleton.is_null()) {
  878. WARN_PRINT("Could not open config file.");
  879. goto fail;
  880. }
  881. singleton->save_changed_setting = true;
  882. singleton->config_file_path = config_file_path;
  883. singleton->settings_dir = config_dir;
  884. singleton->data_dir = data_dir;
  885. singleton->cache_dir = cache_dir;
  886. print_verbose("EditorSettings: Load OK!");
  887. singleton->setup_language();
  888. singleton->setup_network();
  889. singleton->load_favorites();
  890. singleton->list_text_editor_themes();
  891. return;
  892. }
  893. fail:
  894. // patch init projects
  895. if (extra_config->has_section("init_projects")) {
  896. Vector<String> list = extra_config->get_value("init_projects", "list");
  897. for (int i = 0; i < list.size(); i++) {
  898. list.write[i] = exe_path.plus_file(list[i]);
  899. };
  900. extra_config->set_value("init_projects", "list", list);
  901. };
  902. singleton = Ref<EditorSettings>(memnew(EditorSettings));
  903. singleton->save_changed_setting = true;
  904. singleton->config_file_path = config_file_path;
  905. singleton->settings_dir = config_dir;
  906. singleton->data_dir = data_dir;
  907. singleton->cache_dir = cache_dir;
  908. singleton->_load_defaults(extra_config);
  909. singleton->setup_language();
  910. singleton->setup_network();
  911. singleton->list_text_editor_themes();
  912. }
  913. void EditorSettings::setup_language() {
  914. String lang = get("interface/editor/editor_language");
  915. if (lang == "en") {
  916. return; // Default, nothing to do.
  917. }
  918. // Load editor translation for configured/detected locale.
  919. EditorTranslationList *etl = _editor_translations;
  920. while (etl->data) {
  921. if (etl->lang == lang) {
  922. Vector<uint8_t> data;
  923. data.resize(etl->uncomp_size);
  924. Compression::decompress(data.ptrw(), etl->uncomp_size, etl->data, etl->comp_size, Compression::MODE_DEFLATE);
  925. FileAccessMemory *fa = memnew(FileAccessMemory);
  926. fa->open_custom(data.ptr(), data.size());
  927. Ref<Translation> tr = TranslationLoaderPO::load_translation(fa);
  928. if (tr.is_valid()) {
  929. tr->set_locale(etl->lang);
  930. TranslationServer::get_singleton()->set_tool_translation(tr);
  931. break;
  932. }
  933. }
  934. etl++;
  935. }
  936. // Load class reference translation.
  937. DocTranslationList *dtl = _doc_translations;
  938. while (dtl->data) {
  939. if (dtl->lang == lang) {
  940. Vector<uint8_t> data;
  941. data.resize(dtl->uncomp_size);
  942. Compression::decompress(data.ptrw(), dtl->uncomp_size, dtl->data, dtl->comp_size, Compression::MODE_DEFLATE);
  943. FileAccessMemory *fa = memnew(FileAccessMemory);
  944. fa->open_custom(data.ptr(), data.size());
  945. Ref<Translation> tr = TranslationLoaderPO::load_translation(fa);
  946. if (tr.is_valid()) {
  947. tr->set_locale(dtl->lang);
  948. TranslationServer::get_singleton()->set_doc_translation(tr);
  949. break;
  950. }
  951. }
  952. dtl++;
  953. }
  954. }
  955. void EditorSettings::setup_network() {
  956. List<IP_Address> local_ip;
  957. IP::get_singleton()->get_local_addresses(&local_ip);
  958. String hint;
  959. String current = has_setting("network/debug/remote_host") ? get("network/debug/remote_host") : "";
  960. String selected = "127.0.0.1";
  961. // Check that current remote_host is a valid interface address and populate hints.
  962. for (List<IP_Address>::Element *E = local_ip.front(); E; E = E->next()) {
  963. String ip = E->get();
  964. // link-local IPv6 addresses don't work, skipping them
  965. if (ip.begins_with("fe80:0:0:0:")) { // fe80::/64
  966. continue;
  967. }
  968. // Same goes for IPv4 link-local (APIPA) addresses.
  969. if (ip.begins_with("169.254.")) { // 169.254.0.0/16
  970. continue;
  971. }
  972. // Select current IP (found)
  973. if (ip == current) {
  974. selected = ip;
  975. }
  976. if (hint != "") {
  977. hint += ",";
  978. }
  979. hint += ip;
  980. }
  981. // Add hints with valid IP addresses to remote_host property.
  982. add_property_hint(PropertyInfo(Variant::STRING, "network/debug/remote_host", PROPERTY_HINT_ENUM, hint));
  983. // Fix potentially invalid remote_host due to network change.
  984. set("network/debug/remote_host", selected);
  985. }
  986. void EditorSettings::save() {
  987. //_THREAD_SAFE_METHOD_
  988. if (!singleton.ptr()) {
  989. return;
  990. }
  991. if (singleton->config_file_path == "") {
  992. ERR_PRINT("Cannot save EditorSettings config, no valid path");
  993. return;
  994. }
  995. Error err = ResourceSaver::save(singleton->config_file_path, singleton);
  996. if (err != OK) {
  997. ERR_PRINT("Error saving editor settings to " + singleton->config_file_path);
  998. } else {
  999. print_verbose("EditorSettings: Save OK!");
  1000. }
  1001. }
  1002. void EditorSettings::destroy() {
  1003. if (!singleton.ptr()) {
  1004. return;
  1005. }
  1006. save();
  1007. singleton = Ref<EditorSettings>();
  1008. }
  1009. void EditorSettings::set_optimize_save(bool p_optimize) {
  1010. optimize_save = p_optimize;
  1011. }
  1012. // Properties
  1013. void EditorSettings::set_setting(const String &p_setting, const Variant &p_value) {
  1014. _THREAD_SAFE_METHOD_
  1015. set(p_setting, p_value);
  1016. }
  1017. Variant EditorSettings::get_setting(const String &p_setting) const {
  1018. _THREAD_SAFE_METHOD_
  1019. return get(p_setting);
  1020. }
  1021. bool EditorSettings::has_setting(const String &p_setting) const {
  1022. _THREAD_SAFE_METHOD_
  1023. return props.has(p_setting);
  1024. }
  1025. void EditorSettings::erase(const String &p_setting) {
  1026. _THREAD_SAFE_METHOD_
  1027. props.erase(p_setting);
  1028. }
  1029. void EditorSettings::raise_order(const String &p_setting) {
  1030. _THREAD_SAFE_METHOD_
  1031. ERR_FAIL_COND(!props.has(p_setting));
  1032. props[p_setting].order = ++last_order;
  1033. }
  1034. void EditorSettings::set_restart_if_changed(const StringName &p_setting, bool p_restart) {
  1035. _THREAD_SAFE_METHOD_
  1036. if (!props.has(p_setting)) {
  1037. return;
  1038. }
  1039. props[p_setting].restart_if_changed = p_restart;
  1040. }
  1041. void EditorSettings::set_initial_value(const StringName &p_setting, const Variant &p_value, bool p_update_current) {
  1042. _THREAD_SAFE_METHOD_
  1043. if (!props.has(p_setting)) {
  1044. return;
  1045. }
  1046. props[p_setting].initial = p_value;
  1047. props[p_setting].has_default_value = true;
  1048. if (p_update_current) {
  1049. set(p_setting, p_value);
  1050. }
  1051. }
  1052. Variant _EDITOR_DEF(const String &p_setting, const Variant &p_default, bool p_restart_if_changed) {
  1053. Variant ret = p_default;
  1054. if (EditorSettings::get_singleton()->has_setting(p_setting)) {
  1055. ret = EditorSettings::get_singleton()->get(p_setting);
  1056. } else {
  1057. EditorSettings::get_singleton()->set_manually(p_setting, p_default);
  1058. EditorSettings::get_singleton()->set_restart_if_changed(p_setting, p_restart_if_changed);
  1059. }
  1060. if (!EditorSettings::get_singleton()->has_default_value(p_setting)) {
  1061. EditorSettings::get_singleton()->set_initial_value(p_setting, p_default);
  1062. }
  1063. return ret;
  1064. }
  1065. Variant _EDITOR_GET(const String &p_setting) {
  1066. ERR_FAIL_COND_V(!EditorSettings::get_singleton()->has_setting(p_setting), Variant());
  1067. return EditorSettings::get_singleton()->get(p_setting);
  1068. }
  1069. bool EditorSettings::property_can_revert(const String &p_setting) {
  1070. if (!props.has(p_setting)) {
  1071. return false;
  1072. }
  1073. if (!props[p_setting].has_default_value) {
  1074. return false;
  1075. }
  1076. return props[p_setting].initial != props[p_setting].variant;
  1077. }
  1078. Variant EditorSettings::property_get_revert(const String &p_setting) {
  1079. if (!props.has(p_setting) || !props[p_setting].has_default_value) {
  1080. return Variant();
  1081. }
  1082. return props[p_setting].initial;
  1083. }
  1084. void EditorSettings::add_property_hint(const PropertyInfo &p_hint) {
  1085. _THREAD_SAFE_METHOD_
  1086. hints[p_hint.name] = p_hint;
  1087. }
  1088. // Data directories
  1089. String EditorSettings::get_data_dir() const {
  1090. return data_dir;
  1091. }
  1092. String EditorSettings::get_templates_dir() const {
  1093. return get_data_dir().plus_file("templates");
  1094. }
  1095. // Config directories
  1096. String EditorSettings::get_settings_dir() const {
  1097. return settings_dir;
  1098. }
  1099. String EditorSettings::get_project_settings_dir() const {
  1100. return EditorSettings::PROJECT_EDITOR_SETTINGS_PATH;
  1101. }
  1102. String EditorSettings::get_text_editor_themes_dir() const {
  1103. return get_settings_dir().plus_file("text_editor_themes");
  1104. }
  1105. String EditorSettings::get_script_templates_dir() const {
  1106. return get_settings_dir().plus_file("script_templates");
  1107. }
  1108. String EditorSettings::get_project_script_templates_dir() const {
  1109. return ProjectSettings::get_singleton()->get("editor/script/templates_search_path");
  1110. }
  1111. // Cache directory
  1112. String EditorSettings::get_cache_dir() const {
  1113. return cache_dir;
  1114. }
  1115. String EditorSettings::get_feature_profiles_dir() const {
  1116. return get_settings_dir().plus_file("feature_profiles");
  1117. }
  1118. // Metadata
  1119. void EditorSettings::set_project_metadata(const String &p_section, const String &p_key, Variant p_data) {
  1120. Ref<ConfigFile> cf = memnew(ConfigFile);
  1121. String path = get_project_settings_dir().plus_file("project_metadata.cfg");
  1122. Error err;
  1123. err = cf->load(path);
  1124. ERR_FAIL_COND_MSG(err != OK && err != ERR_FILE_NOT_FOUND, "Cannot load editor settings from file '" + path + "'.");
  1125. cf->set_value(p_section, p_key, p_data);
  1126. err = cf->save(path);
  1127. ERR_FAIL_COND_MSG(err != OK, "Cannot save editor settings to file '" + path + "'.");
  1128. }
  1129. Variant EditorSettings::get_project_metadata(const String &p_section, const String &p_key, Variant p_default) const {
  1130. Ref<ConfigFile> cf = memnew(ConfigFile);
  1131. String path = get_project_settings_dir().plus_file("project_metadata.cfg");
  1132. Error err = cf->load(path);
  1133. if (err != OK) {
  1134. return p_default;
  1135. }
  1136. return cf->get_value(p_section, p_key, p_default);
  1137. }
  1138. void EditorSettings::set_favorites(const Vector<String> &p_favorites) {
  1139. favorites = p_favorites;
  1140. FileAccess *f = FileAccess::open(get_project_settings_dir().plus_file("favorites"), FileAccess::WRITE);
  1141. if (f) {
  1142. for (int i = 0; i < favorites.size(); i++) {
  1143. f->store_line(favorites[i]);
  1144. }
  1145. memdelete(f);
  1146. }
  1147. }
  1148. Vector<String> EditorSettings::get_favorites() const {
  1149. return favorites;
  1150. }
  1151. void EditorSettings::set_recent_dirs(const Vector<String> &p_recent_dirs) {
  1152. recent_dirs = p_recent_dirs;
  1153. FileAccess *f = FileAccess::open(get_project_settings_dir().plus_file("recent_dirs"), FileAccess::WRITE);
  1154. if (f) {
  1155. for (int i = 0; i < recent_dirs.size(); i++) {
  1156. f->store_line(recent_dirs[i]);
  1157. }
  1158. memdelete(f);
  1159. }
  1160. }
  1161. Vector<String> EditorSettings::get_recent_dirs() const {
  1162. return recent_dirs;
  1163. }
  1164. void EditorSettings::load_favorites() {
  1165. FileAccess *f = FileAccess::open(get_project_settings_dir().plus_file("favorites"), FileAccess::READ);
  1166. if (f) {
  1167. String line = f->get_line().strip_edges();
  1168. while (line != "") {
  1169. favorites.push_back(line);
  1170. line = f->get_line().strip_edges();
  1171. }
  1172. memdelete(f);
  1173. }
  1174. f = FileAccess::open(get_project_settings_dir().plus_file("recent_dirs"), FileAccess::READ);
  1175. if (f) {
  1176. String line = f->get_line().strip_edges();
  1177. while (line != "") {
  1178. recent_dirs.push_back(line);
  1179. line = f->get_line().strip_edges();
  1180. }
  1181. memdelete(f);
  1182. }
  1183. }
  1184. bool EditorSettings::is_dark_theme() {
  1185. int AUTO_COLOR = 0;
  1186. int LIGHT_COLOR = 2;
  1187. Color base_color = get("interface/theme/base_color");
  1188. int icon_font_color_setting = get("interface/theme/icon_and_font_color");
  1189. return (icon_font_color_setting == AUTO_COLOR && ((base_color.r + base_color.g + base_color.b) / 3.0) < 0.5) || icon_font_color_setting == LIGHT_COLOR;
  1190. }
  1191. void EditorSettings::list_text_editor_themes() {
  1192. String themes = "Adaptive,Default,Custom";
  1193. DirAccess *d = DirAccess::open(get_text_editor_themes_dir());
  1194. if (d) {
  1195. List<String> custom_themes;
  1196. d->list_dir_begin();
  1197. String file = d->get_next();
  1198. while (file != String()) {
  1199. if (file.get_extension() == "tet" && !_is_default_text_editor_theme(file.get_basename().to_lower())) {
  1200. custom_themes.push_back(file.get_basename());
  1201. }
  1202. file = d->get_next();
  1203. }
  1204. d->list_dir_end();
  1205. memdelete(d);
  1206. custom_themes.sort();
  1207. for (List<String>::Element *E = custom_themes.front(); E; E = E->next()) {
  1208. themes += "," + E->get();
  1209. }
  1210. }
  1211. add_property_hint(PropertyInfo(Variant::STRING, "text_editor/theme/color_theme", PROPERTY_HINT_ENUM, themes));
  1212. }
  1213. void EditorSettings::load_text_editor_theme() {
  1214. String p_file = get("text_editor/theme/color_theme");
  1215. if (_is_default_text_editor_theme(p_file.get_file().to_lower())) {
  1216. if (p_file == "Default") {
  1217. _load_default_text_editor_theme();
  1218. }
  1219. return; // sorry for "Settings changed" console spam
  1220. }
  1221. String theme_path = get_text_editor_themes_dir().plus_file(p_file + ".tet");
  1222. Ref<ConfigFile> cf = memnew(ConfigFile);
  1223. Error err = cf->load(theme_path);
  1224. if (err != OK) {
  1225. return;
  1226. }
  1227. List<String> keys;
  1228. cf->get_section_keys("color_theme", &keys);
  1229. for (List<String>::Element *E = keys.front(); E; E = E->next()) {
  1230. String key = E->get();
  1231. String val = cf->get_value("color_theme", key);
  1232. // don't load if it's not already there!
  1233. if (has_setting("text_editor/highlighting/" + key)) {
  1234. // make sure it is actually a color
  1235. if (val.is_valid_html_color() && key.find("color") >= 0) {
  1236. props["text_editor/highlighting/" + key].variant = Color::html(val); // change manually to prevent "Settings changed" console spam
  1237. }
  1238. }
  1239. }
  1240. emit_signal("settings_changed");
  1241. // if it doesn't load just use what is currently loaded
  1242. }
  1243. bool EditorSettings::import_text_editor_theme(String p_file) {
  1244. if (!p_file.ends_with(".tet")) {
  1245. return false;
  1246. } else {
  1247. if (p_file.get_file().to_lower() == "default.tet") {
  1248. return false;
  1249. }
  1250. DirAccess *d = DirAccess::open(get_text_editor_themes_dir());
  1251. if (d) {
  1252. d->copy(p_file, get_text_editor_themes_dir().plus_file(p_file.get_file()));
  1253. memdelete(d);
  1254. return true;
  1255. }
  1256. }
  1257. return false;
  1258. }
  1259. bool EditorSettings::save_text_editor_theme() {
  1260. String p_file = get("text_editor/theme/color_theme");
  1261. if (_is_default_text_editor_theme(p_file.get_file().to_lower())) {
  1262. return false;
  1263. }
  1264. String theme_path = get_text_editor_themes_dir().plus_file(p_file + ".tet");
  1265. return _save_text_editor_theme(theme_path);
  1266. }
  1267. bool EditorSettings::save_text_editor_theme_as(String p_file) {
  1268. if (!p_file.ends_with(".tet")) {
  1269. p_file += ".tet";
  1270. }
  1271. if (_is_default_text_editor_theme(p_file.get_file().to_lower().trim_suffix(".tet"))) {
  1272. return false;
  1273. }
  1274. if (_save_text_editor_theme(p_file)) {
  1275. // switch to theme is saved in the theme directory
  1276. list_text_editor_themes();
  1277. String theme_name = p_file.substr(0, p_file.length() - 4).get_file();
  1278. if (p_file.get_base_dir() == get_text_editor_themes_dir()) {
  1279. _initial_set("text_editor/theme/color_theme", theme_name);
  1280. load_text_editor_theme();
  1281. }
  1282. return true;
  1283. }
  1284. return false;
  1285. }
  1286. bool EditorSettings::is_default_text_editor_theme() {
  1287. String p_file = get("text_editor/theme/color_theme");
  1288. return _is_default_text_editor_theme(p_file.get_file().to_lower());
  1289. }
  1290. Vector<String> EditorSettings::get_script_templates(const String &p_extension, const String &p_custom_path) {
  1291. Vector<String> templates;
  1292. String template_dir = get_script_templates_dir();
  1293. if (!p_custom_path.is_empty()) {
  1294. template_dir = p_custom_path;
  1295. }
  1296. DirAccess *d = DirAccess::open(template_dir);
  1297. if (d) {
  1298. d->list_dir_begin();
  1299. String file = d->get_next();
  1300. while (file != String()) {
  1301. if (file.get_extension() == p_extension) {
  1302. templates.push_back(file.get_basename());
  1303. }
  1304. file = d->get_next();
  1305. }
  1306. d->list_dir_end();
  1307. memdelete(d);
  1308. }
  1309. return templates;
  1310. }
  1311. String EditorSettings::get_editor_layouts_config() const {
  1312. return get_settings_dir().plus_file("editor_layouts.cfg");
  1313. }
  1314. // Shortcuts
  1315. void EditorSettings::add_shortcut(const String &p_name, Ref<Shortcut> &p_shortcut) {
  1316. shortcuts[p_name] = p_shortcut;
  1317. }
  1318. bool EditorSettings::is_shortcut(const String &p_name, const Ref<InputEvent> &p_event) const {
  1319. const Map<String, Ref<Shortcut>>::Element *E = shortcuts.find(p_name);
  1320. ERR_FAIL_COND_V_MSG(!E, false, "Unknown Shortcut: " + p_name + ".");
  1321. return E->get()->is_shortcut(p_event);
  1322. }
  1323. Ref<Shortcut> EditorSettings::get_shortcut(const String &p_name) const {
  1324. const Map<String, Ref<Shortcut>>::Element *SC = shortcuts.find(p_name);
  1325. if (SC) {
  1326. return SC->get();
  1327. }
  1328. // If no shortcut with the provided name is found in the list, check the built-in shortcuts.
  1329. // Use the first item in the action list for the shortcut event, since a shortcut can only have 1 linked event.
  1330. Ref<Shortcut> sc;
  1331. const Map<String, List<Ref<InputEvent>>>::Element *builtin_override = builtin_action_overrides.find(p_name);
  1332. if (builtin_override) {
  1333. sc.instance();
  1334. sc->set_shortcut(builtin_override->get().front()->get());
  1335. sc->set_name(InputMap::get_singleton()->get_builtin_display_name(p_name));
  1336. }
  1337. // If there was no override, check the default builtins to see if it has an InputEvent for the provided name.
  1338. if (sc.is_null()) {
  1339. const OrderedHashMap<String, List<Ref<InputEvent>>>::ConstElement builtin_default = InputMap::get_singleton()->get_builtins().find(p_name);
  1340. if (builtin_default) {
  1341. sc.instance();
  1342. sc->set_shortcut(builtin_default.get().front()->get());
  1343. sc->set_name(InputMap::get_singleton()->get_builtin_display_name(p_name));
  1344. }
  1345. }
  1346. if (sc.is_valid()) {
  1347. // Add the shortcut to the list.
  1348. shortcuts[p_name] = sc;
  1349. return sc;
  1350. }
  1351. return Ref<Shortcut>();
  1352. }
  1353. void EditorSettings::get_shortcut_list(List<String> *r_shortcuts) {
  1354. for (const Map<String, Ref<Shortcut>>::Element *E = shortcuts.front(); E; E = E->next()) {
  1355. r_shortcuts->push_back(E->key());
  1356. }
  1357. }
  1358. Ref<Shortcut> ED_GET_SHORTCUT(const String &p_path) {
  1359. if (!EditorSettings::get_singleton()) {
  1360. return nullptr;
  1361. }
  1362. Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
  1363. ERR_FAIL_COND_V_MSG(!sc.is_valid(), sc, "Used ED_GET_SHORTCUT with invalid shortcut: " + p_path + ".");
  1364. return sc;
  1365. }
  1366. Ref<Shortcut> ED_SHORTCUT(const String &p_path, const String &p_name, uint32_t p_keycode) {
  1367. #ifdef OSX_ENABLED
  1368. // Use Cmd+Backspace as a general replacement for Delete shortcuts on macOS
  1369. if (p_keycode == KEY_DELETE) {
  1370. p_keycode = KEY_MASK_CMD | KEY_BACKSPACE;
  1371. }
  1372. #endif
  1373. Ref<InputEventKey> ie;
  1374. if (p_keycode) {
  1375. ie.instance();
  1376. ie->set_unicode(p_keycode & KEY_CODE_MASK);
  1377. ie->set_keycode(p_keycode & KEY_CODE_MASK);
  1378. ie->set_shift(bool(p_keycode & KEY_MASK_SHIFT));
  1379. ie->set_alt(bool(p_keycode & KEY_MASK_ALT));
  1380. ie->set_control(bool(p_keycode & KEY_MASK_CTRL));
  1381. ie->set_metakey(bool(p_keycode & KEY_MASK_META));
  1382. }
  1383. if (!EditorSettings::get_singleton()) {
  1384. Ref<Shortcut> sc;
  1385. sc.instance();
  1386. sc->set_name(p_name);
  1387. sc->set_shortcut(ie);
  1388. sc->set_meta("original", ie);
  1389. return sc;
  1390. }
  1391. Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
  1392. if (sc.is_valid()) {
  1393. sc->set_name(p_name); //keep name (the ones that come from disk have no name)
  1394. sc->set_meta("original", ie); //to compare against changes
  1395. return sc;
  1396. }
  1397. sc.instance();
  1398. sc->set_name(p_name);
  1399. sc->set_shortcut(ie);
  1400. sc->set_meta("original", ie); //to compare against changes
  1401. EditorSettings::get_singleton()->add_shortcut(p_path, sc);
  1402. return sc;
  1403. }
  1404. void EditorSettings::set_builtin_action_override(const String &p_name, const Array &p_events) {
  1405. List<Ref<InputEvent>> event_list;
  1406. // Override the whole list, since events may have their order changed or be added, removed or edited.
  1407. InputMap::get_singleton()->action_erase_events(p_name);
  1408. for (int i = 0; i < p_events.size(); i++) {
  1409. event_list.push_back(p_events[i]);
  1410. InputMap::get_singleton()->action_add_event(p_name, p_events[i]);
  1411. }
  1412. // Check if the provided event array is same as built-in. If it is, it does not need to be added to the overrides.
  1413. // Note that event order must also be the same.
  1414. bool same_as_builtin = true;
  1415. OrderedHashMap<String, List<Ref<InputEvent>>>::ConstElement builtin_default = InputMap::get_singleton()->get_builtins().find(p_name);
  1416. if (builtin_default) {
  1417. List<Ref<InputEvent>> builtin_events = builtin_default.get();
  1418. if (p_events.size() == builtin_events.size()) {
  1419. int event_idx = 0;
  1420. // Check equality of each event.
  1421. for (List<Ref<InputEvent>>::Element *E = builtin_events.front(); E; E = E->next()) {
  1422. if (!E->get()->shortcut_match(p_events[event_idx])) {
  1423. same_as_builtin = false;
  1424. break;
  1425. }
  1426. event_idx++;
  1427. }
  1428. } else {
  1429. same_as_builtin = false;
  1430. }
  1431. }
  1432. if (same_as_builtin && builtin_action_overrides.has(p_name)) {
  1433. builtin_action_overrides.erase(p_name);
  1434. } else {
  1435. builtin_action_overrides[p_name] = event_list;
  1436. }
  1437. // Update the shortcut (if it is used somewhere in the editor) to be the first event of the new list.
  1438. if (shortcuts.has(p_name)) {
  1439. shortcuts[p_name]->set_shortcut(event_list.front()->get());
  1440. }
  1441. }
  1442. const Array EditorSettings::get_builtin_action_overrides(const String &p_name) const {
  1443. const Map<String, List<Ref<InputEvent>>>::Element *AO = builtin_action_overrides.find(p_name);
  1444. if (AO) {
  1445. Array event_array;
  1446. List<Ref<InputEvent>> events_list = AO->get();
  1447. for (List<Ref<InputEvent>>::Element *E = events_list.front(); E; E = E->next()) {
  1448. event_array.push_back(E->get());
  1449. }
  1450. return event_array;
  1451. }
  1452. return Array();
  1453. }
  1454. void EditorSettings::notify_changes() {
  1455. _THREAD_SAFE_METHOD_
  1456. SceneTree *sml = Object::cast_to<SceneTree>(OS::get_singleton()->get_main_loop());
  1457. if (!sml) {
  1458. return;
  1459. }
  1460. Node *root = sml->get_root()->get_child(0);
  1461. if (!root) {
  1462. return;
  1463. }
  1464. root->propagate_notification(NOTIFICATION_EDITOR_SETTINGS_CHANGED);
  1465. }
  1466. void EditorSettings::_bind_methods() {
  1467. ClassDB::bind_method(D_METHOD("has_setting", "name"), &EditorSettings::has_setting);
  1468. ClassDB::bind_method(D_METHOD("set_setting", "name", "value"), &EditorSettings::set_setting);
  1469. ClassDB::bind_method(D_METHOD("get_setting", "name"), &EditorSettings::get_setting);
  1470. ClassDB::bind_method(D_METHOD("erase", "property"), &EditorSettings::erase);
  1471. ClassDB::bind_method(D_METHOD("set_initial_value", "name", "value", "update_current"), &EditorSettings::set_initial_value);
  1472. ClassDB::bind_method(D_METHOD("property_can_revert", "name"), &EditorSettings::property_can_revert);
  1473. ClassDB::bind_method(D_METHOD("property_get_revert", "name"), &EditorSettings::property_get_revert);
  1474. ClassDB::bind_method(D_METHOD("add_property_info", "info"), &EditorSettings::_add_property_info_bind);
  1475. ClassDB::bind_method(D_METHOD("get_settings_dir"), &EditorSettings::get_settings_dir);
  1476. ClassDB::bind_method(D_METHOD("get_project_settings_dir"), &EditorSettings::get_project_settings_dir);
  1477. ClassDB::bind_method(D_METHOD("set_project_metadata", "section", "key", "data"), &EditorSettings::set_project_metadata);
  1478. ClassDB::bind_method(D_METHOD("get_project_metadata", "section", "key", "default"), &EditorSettings::get_project_metadata, DEFVAL(Variant()));
  1479. ClassDB::bind_method(D_METHOD("set_favorites", "dirs"), &EditorSettings::set_favorites);
  1480. ClassDB::bind_method(D_METHOD("get_favorites"), &EditorSettings::get_favorites);
  1481. ClassDB::bind_method(D_METHOD("set_recent_dirs", "dirs"), &EditorSettings::set_recent_dirs);
  1482. ClassDB::bind_method(D_METHOD("get_recent_dirs"), &EditorSettings::get_recent_dirs);
  1483. ClassDB::bind_method(D_METHOD("set_builtin_action_override", "name", "actions_list"), &EditorSettings::set_builtin_action_override);
  1484. ADD_SIGNAL(MethodInfo("settings_changed"));
  1485. BIND_CONSTANT(NOTIFICATION_EDITOR_SETTINGS_CHANGED);
  1486. }
  1487. EditorSettings::EditorSettings() {
  1488. last_order = 0;
  1489. optimize_save = true;
  1490. save_changed_setting = true;
  1491. _load_defaults();
  1492. }
  1493. EditorSettings::~EditorSettings() {
  1494. }