editor_settings.cpp 63 KB

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