editor_settings.cpp 65 KB

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