editor_settings.cpp 65 KB

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