editor_settings.cpp 61 KB

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