editor_settings.cpp 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659
  1. /*************************************************************************/
  2. /* editor_settings.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "editor_settings.h"
  31. #include "core/config/project_settings.h"
  32. #include "core/input/input_event.h"
  33. #include "core/input/input_map.h"
  34. #include "core/input/shortcut.h"
  35. #include "core/io/certs_compressed.gen.h"
  36. #include "core/io/dir_access.h"
  37. #include "core/io/file_access.h"
  38. #include "core/io/ip.h"
  39. #include "core/io/resource_loader.h"
  40. #include "core/io/resource_saver.h"
  41. #include "core/object/class_db.h"
  42. #include "core/os/keyboard.h"
  43. #include "core/os/os.h"
  44. #include "core/string/translation.h"
  45. #include "core/version.h"
  46. #include "editor/editor_node.h"
  47. #include "editor/editor_paths.h"
  48. #include "editor/editor_translation.h"
  49. #include "scene/main/node.h"
  50. #include "scene/main/scene_tree.h"
  51. #include "scene/main/window.h"
  52. // PRIVATE METHODS
  53. Ref<EditorSettings> EditorSettings::singleton = nullptr;
  54. // Properties
  55. bool EditorSettings::_set(const StringName &p_name, const Variant &p_value) {
  56. _THREAD_SAFE_METHOD_
  57. bool changed = _set_only(p_name, p_value);
  58. if (changed) {
  59. changed_settings.insert(p_name);
  60. emit_signal(SNAME("settings_changed"));
  61. }
  62. return true;
  63. }
  64. bool EditorSettings::_set_only(const StringName &p_name, const Variant &p_value) {
  65. _THREAD_SAFE_METHOD_
  66. if (p_name == "shortcuts") {
  67. Array arr = p_value;
  68. for (int i = 0; i < arr.size(); i++) {
  69. Dictionary dict = arr[i];
  70. String shortcut_name = dict["name"];
  71. Array shortcut_events = dict["shortcuts"];
  72. Ref<Shortcut> sc;
  73. sc.instantiate();
  74. sc->set_events(shortcut_events);
  75. add_shortcut(shortcut_name, sc);
  76. }
  77. return false;
  78. } else if (p_name == "builtin_action_overrides") {
  79. Array actions_arr = p_value;
  80. for (int i = 0; i < actions_arr.size(); i++) {
  81. Dictionary action_dict = actions_arr[i];
  82. String action_name = action_dict["name"];
  83. Array events = action_dict["events"];
  84. InputMap *im = InputMap::get_singleton();
  85. im->action_erase_events(action_name);
  86. builtin_action_overrides[action_name].clear();
  87. for (int ev_idx = 0; ev_idx < events.size(); ev_idx++) {
  88. im->action_add_event(action_name, events[ev_idx]);
  89. builtin_action_overrides[action_name].push_back(events[ev_idx]);
  90. }
  91. }
  92. return false;
  93. }
  94. bool changed = false;
  95. if (p_value.get_type() == Variant::NIL) {
  96. if (props.has(p_name)) {
  97. props.erase(p_name);
  98. changed = true;
  99. }
  100. } else {
  101. if (props.has(p_name)) {
  102. if (p_value != props[p_name].variant) {
  103. props[p_name].variant = p_value;
  104. changed = true;
  105. }
  106. } else {
  107. props[p_name] = VariantContainer(p_value, last_order++);
  108. changed = true;
  109. }
  110. if (save_changed_setting) {
  111. if (!props[p_name].save) {
  112. props[p_name].save = true;
  113. changed = true;
  114. }
  115. }
  116. }
  117. return changed;
  118. }
  119. bool EditorSettings::_get(const StringName &p_name, Variant &r_ret) const {
  120. _THREAD_SAFE_METHOD_
  121. if (p_name == "shortcuts") {
  122. Array save_array;
  123. const HashMap<String, List<Ref<InputEvent>>> &builtin_list = InputMap::get_singleton()->get_builtins();
  124. for (const KeyValue<String, Ref<Shortcut>> &shortcut_definition : shortcuts) {
  125. Ref<Shortcut> sc = shortcut_definition.value;
  126. if (builtin_list.has(shortcut_definition.key)) {
  127. // This shortcut was auto-generated from built in actions: don't save.
  128. // If the builtin is overridden, it will be saved in the "builtin_action_overrides" section below.
  129. continue;
  130. }
  131. Array shortcut_events = sc->get_events();
  132. Dictionary dict;
  133. dict["name"] = shortcut_definition.key;
  134. dict["shortcuts"] = shortcut_events;
  135. if (!sc->has_meta("original")) {
  136. // Getting the meta when it doesn't exist will return an empty array. If the 'shortcut_events' have been cleared,
  137. // we still want save the shortcut in this case so that shortcuts that the user has customised are not reset,
  138. // even if the 'original' has not been populated yet. This can happen when calling save() from the Project Manager.
  139. save_array.push_back(dict);
  140. continue;
  141. }
  142. Array original_events = sc->get_meta("original");
  143. bool is_same = Shortcut::is_event_array_equal(original_events, shortcut_events);
  144. if (is_same) {
  145. continue; // Not changed from default; don't save.
  146. }
  147. save_array.push_back(dict);
  148. }
  149. r_ret = save_array;
  150. return true;
  151. } else if (p_name == "builtin_action_overrides") {
  152. Array actions_arr;
  153. for (const KeyValue<String, List<Ref<InputEvent>>> &action_override : builtin_action_overrides) {
  154. List<Ref<InputEvent>> events = action_override.value;
  155. Dictionary action_dict;
  156. action_dict["name"] = action_override.key;
  157. // Convert the list to an array, and only keep key events as this is for the editor.
  158. Array events_arr;
  159. for (const Ref<InputEvent> &ie : events) {
  160. Ref<InputEventKey> iek = ie;
  161. if (iek.is_valid()) {
  162. events_arr.append(iek);
  163. }
  164. }
  165. Array defaults_arr;
  166. List<Ref<InputEvent>> defaults = InputMap::get_singleton()->get_builtins()[action_override.key];
  167. for (const Ref<InputEvent> &default_input_event : defaults) {
  168. if (default_input_event.is_valid()) {
  169. defaults_arr.append(default_input_event);
  170. }
  171. }
  172. bool same = Shortcut::is_event_array_equal(events_arr, defaults_arr);
  173. // Don't save if same as default.
  174. if (same) {
  175. continue;
  176. }
  177. action_dict["events"] = events_arr;
  178. actions_arr.push_back(action_dict);
  179. }
  180. r_ret = actions_arr;
  181. return true;
  182. }
  183. const VariantContainer *v = props.getptr(p_name);
  184. if (!v) {
  185. WARN_PRINT("EditorSettings::_get - Property not found: " + String(p_name));
  186. return false;
  187. }
  188. r_ret = v->variant;
  189. return true;
  190. }
  191. void EditorSettings::_initial_set(const StringName &p_name, const Variant &p_value) {
  192. set(p_name, p_value);
  193. props[p_name].initial = p_value;
  194. props[p_name].has_default_value = true;
  195. }
  196. struct _EVCSort {
  197. String name;
  198. Variant::Type type = Variant::Type::NIL;
  199. int order = 0;
  200. bool save = false;
  201. bool restart_if_changed = false;
  202. bool operator<(const _EVCSort &p_vcs) const { return order < p_vcs.order; }
  203. };
  204. void EditorSettings::_get_property_list(List<PropertyInfo> *p_list) const {
  205. _THREAD_SAFE_METHOD_
  206. RBSet<_EVCSort> vclist;
  207. for (const KeyValue<String, VariantContainer> &E : props) {
  208. const VariantContainer *v = &E.value;
  209. if (v->hide_from_editor) {
  210. continue;
  211. }
  212. _EVCSort vc;
  213. vc.name = E.key;
  214. vc.order = v->order;
  215. vc.type = v->variant.get_type();
  216. vc.save = v->save;
  217. /*if (vc.save) { this should be implemented, but lets do after 3.1 is out.
  218. if (v->initial.get_type() != Variant::NIL && v->initial == v->variant) {
  219. vc.save = false;
  220. }
  221. }*/
  222. vc.restart_if_changed = v->restart_if_changed;
  223. vclist.insert(vc);
  224. }
  225. for (const _EVCSort &E : vclist) {
  226. uint32_t pusage = PROPERTY_USAGE_NONE;
  227. if (E.save || !optimize_save) {
  228. pusage |= PROPERTY_USAGE_STORAGE;
  229. }
  230. if (!E.name.begins_with("_") && !E.name.begins_with("projects/")) {
  231. pusage |= PROPERTY_USAGE_EDITOR;
  232. } else {
  233. pusage |= PROPERTY_USAGE_STORAGE; //hiddens must always be saved
  234. }
  235. PropertyInfo pi(E.type, E.name);
  236. pi.usage = pusage;
  237. if (hints.has(E.name)) {
  238. pi = hints[E.name];
  239. }
  240. if (E.restart_if_changed) {
  241. pi.usage |= PROPERTY_USAGE_RESTART_IF_CHANGED;
  242. }
  243. p_list->push_back(pi);
  244. }
  245. p_list->push_back(PropertyInfo(Variant::ARRAY, "shortcuts", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL)); //do not edit
  246. p_list->push_back(PropertyInfo(Variant::ARRAY, "builtin_action_overrides", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));
  247. }
  248. void EditorSettings::_add_property_info_bind(const Dictionary &p_info) {
  249. ERR_FAIL_COND(!p_info.has("name"));
  250. ERR_FAIL_COND(!p_info.has("type"));
  251. PropertyInfo pinfo;
  252. pinfo.name = p_info["name"];
  253. ERR_FAIL_COND(!props.has(pinfo.name));
  254. pinfo.type = Variant::Type(p_info["type"].operator int());
  255. ERR_FAIL_INDEX(pinfo.type, Variant::VARIANT_MAX);
  256. if (p_info.has("hint")) {
  257. pinfo.hint = PropertyHint(p_info["hint"].operator int());
  258. }
  259. if (p_info.has("hint_string")) {
  260. pinfo.hint_string = p_info["hint_string"];
  261. }
  262. add_property_hint(pinfo);
  263. }
  264. // Default configs
  265. bool EditorSettings::has_default_value(const String &p_setting) const {
  266. _THREAD_SAFE_METHOD_
  267. if (!props.has(p_setting)) {
  268. return false;
  269. }
  270. return props[p_setting].has_default_value;
  271. }
  272. void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
  273. _THREAD_SAFE_METHOD_
  274. // Sets up the editor setting with a default value and hint PropertyInfo.
  275. #define EDITOR_SETTING(m_type, m_property_hint, m_name, m_default_value, m_hint_string) \
  276. _initial_set(m_name, m_default_value); \
  277. hints[m_name] = PropertyInfo(m_type, m_name, m_property_hint, m_hint_string);
  278. #define EDITOR_SETTING_USAGE(m_type, m_property_hint, m_name, m_default_value, m_hint_string, m_usage) \
  279. _initial_set(m_name, m_default_value); \
  280. hints[m_name] = PropertyInfo(m_type, m_name, m_property_hint, m_hint_string, m_usage);
  281. /* Languages */
  282. {
  283. String lang_hint = "en";
  284. String host_lang = OS::get_singleton()->get_locale();
  285. // Skip locales if Text server lack required features.
  286. Vector<String> locales_to_skip;
  287. if (!TS->has_feature(TextServer::FEATURE_BIDI_LAYOUT) || !TS->has_feature(TextServer::FEATURE_SHAPING)) {
  288. locales_to_skip.push_back("ar"); // Arabic
  289. locales_to_skip.push_back("fa"); // Persian
  290. locales_to_skip.push_back("ur"); // Urdu
  291. }
  292. if (!TS->has_feature(TextServer::FEATURE_BIDI_LAYOUT)) {
  293. locales_to_skip.push_back("he"); // Hebrew
  294. }
  295. if (!TS->has_feature(TextServer::FEATURE_SHAPING)) {
  296. locales_to_skip.push_back("bn"); // Bengali
  297. locales_to_skip.push_back("hi"); // Hindi
  298. locales_to_skip.push_back("ml"); // Malayalam
  299. locales_to_skip.push_back("si"); // Sinhala
  300. locales_to_skip.push_back("ta"); // Tamil
  301. locales_to_skip.push_back("te"); // Telugu
  302. }
  303. if (!locales_to_skip.is_empty()) {
  304. WARN_PRINT("Some locales are not properly supported by selected Text Server and are disabled.");
  305. }
  306. String best;
  307. int best_score = 0;
  308. for (const String &locale : get_editor_locales()) {
  309. // Skip locales which we can't render properly (see above comment).
  310. // Test against language code without regional variants (e.g. ur_PK).
  311. String lang_code = locale.get_slice("_", 0);
  312. if (locales_to_skip.has(lang_code)) {
  313. continue;
  314. }
  315. lang_hint += ",";
  316. lang_hint += locale;
  317. int score = TranslationServer::get_singleton()->compare_locales(host_lang, locale);
  318. if (score > 0 && score >= best_score) {
  319. best = locale;
  320. best_score = score;
  321. if (score == 10) {
  322. break; // Exact match, skip the rest.
  323. }
  324. }
  325. }
  326. if (best_score == 0) {
  327. best = "en";
  328. }
  329. EDITOR_SETTING_USAGE(Variant::STRING, PROPERTY_HINT_ENUM, "interface/editor/editor_language", best, lang_hint, PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
  330. }
  331. /* Interface */
  332. // Editor
  333. // Display what the Auto display scale setting effectively corresponds to.
  334. const String display_scale_hint_string = vformat("Auto (%d%%),75%%,100%%,125%%,150%%,175%%,200%%,Custom", Math::round(get_auto_display_scale() * 100));
  335. EDITOR_SETTING_USAGE(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/display_scale", 0, display_scale_hint_string, PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  336. _initial_set("interface/editor/debug/enable_pseudolocalization", false);
  337. set_restart_if_changed("interface/editor/debug/enable_pseudolocalization", true);
  338. // Use pseudolocalization in editor.
  339. EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/use_embedded_menu", false, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  340. EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/expand_to_title", true, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  341. EDITOR_SETTING_USAGE(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/editor/custom_display_scale", 1.0, "0.5,3,0.01", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  342. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/editor/main_font_size", 14, "8,48,1")
  343. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/editor/code_font_size", 14, "8,48,1")
  344. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/code_font_contextual_ligatures", 0, "Default,Disable Contextual Alternates (Coding Ligatures),Use Custom OpenType Feature Set")
  345. _initial_set("interface/editor/code_font_custom_opentype_features", "");
  346. _initial_set("interface/editor/code_font_custom_variations", "");
  347. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/font_antialiasing", 1, "None,Grayscale,LCD sub-pixel")
  348. #ifdef MACOS_ENABLED
  349. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/font_hinting", 0, "Auto (None),None,Light,Normal")
  350. #else
  351. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/font_hinting", 0, "Auto (Light),None,Light,Normal")
  352. #endif
  353. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/font_subpixel_positioning", 1, "Disabled,Auto,One half of a pixel,One quarter of a pixel")
  354. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "interface/editor/main_font", "", "*.ttf,*.otf,*.woff,*.woff2,*.pfb,*.pfm")
  355. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "interface/editor/main_font_bold", "", "*.ttf,*.otf,*.woff,*.woff2,*.pfb,*.pfm")
  356. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "interface/editor/code_font", "", "*.ttf,*.otf,*.woff,*.woff2,*.pfb,*.pfm")
  357. EDITOR_SETTING_USAGE(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/editor/low_processor_mode_sleep_usec", 6900, "1,100000,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  358. // Default unfocused usec sleep is for 10 FPS. Allow an unfocused FPS limit
  359. // as low as 1 FPS for those who really need low power usage (but don't need
  360. // to preview particles or shaders while the editor is unfocused). With very
  361. // low FPS limits, the editor can take a small while to become usable after
  362. // being focused again, so this should be used at the user's discretion.
  363. EDITOR_SETTING_USAGE(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/editor/unfocused_low_processor_mode_sleep_usec", 100000, "1,1000000,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  364. _initial_set("interface/editor/separate_distraction_mode", false);
  365. _initial_set("interface/editor/automatically_open_screenshots", true);
  366. EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/single_window_mode", false, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  367. _initial_set("interface/editor/mouse_extra_buttons_navigate_history", true);
  368. _initial_set("interface/editor/save_each_scene_on_quit", true); // Regression
  369. #ifdef DEV_ENABLED
  370. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/show_internal_errors_in_toast_notifications", 0, "Auto (Enabled),Enabled,Disabled")
  371. #else
  372. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/show_internal_errors_in_toast_notifications", 0, "Auto (Disabled),Enabled,Disabled")
  373. #endif
  374. // Inspector
  375. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/inspector/max_array_dictionary_items_per_page", 20, "10,100,1")
  376. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/inspector/show_low_level_opentype_features", false, "")
  377. // Theme
  378. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_ENUM, "interface/theme/preset", "Default", "Default,Breeze Dark,Godot 2,Gray,Light,Solarized (Dark),Solarized (Light),Custom")
  379. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/theme/icon_and_font_color", 0, "Auto,Dark,Light")
  380. EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "interface/theme/base_color", Color(0.2, 0.23, 0.31), "")
  381. EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "interface/theme/accent_color", Color(0.41, 0.61, 0.91), "")
  382. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/theme/contrast", 0.3, "-1,1,0.01")
  383. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/theme/icon_saturation", 1.0, "0,2,0.01")
  384. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/theme/relationship_line_opacity", 0.1, "0.00,1,0.01")
  385. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/theme/border_size", 0, "0,2,1")
  386. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/theme/corner_radius", 3, "0,6,1")
  387. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/theme/additional_spacing", 0.0, "0,5,0.1")
  388. EDITOR_SETTING_USAGE(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "interface/theme/custom_theme", "", "*.res,*.tres,*.theme", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  389. // Scene tabs
  390. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/scene_tabs/display_close_button", 1, "Never,If Tab Active,Always"); // TabBar::CloseButtonDisplayPolicy
  391. _initial_set("interface/scene_tabs/show_thumbnail_on_hover", true);
  392. EDITOR_SETTING_USAGE(Variant::INT, PROPERTY_HINT_RANGE, "interface/scene_tabs/maximum_width", 350, "0,9999,1", PROPERTY_USAGE_DEFAULT)
  393. _initial_set("interface/scene_tabs/show_script_button", false);
  394. /* Filesystem */
  395. // Directories
  396. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_DIR, "filesystem/directories/autoscan_project_path", "", "")
  397. const String fs_dir_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);
  398. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_DIR, "filesystem/directories/default_project_path", fs_dir_default_project_path, "")
  399. // On save
  400. _initial_set("filesystem/on_save/compress_binary_resources", true);
  401. _initial_set("filesystem/on_save/safe_save_on_backup_then_rename", true);
  402. // File dialog
  403. _initial_set("filesystem/file_dialog/show_hidden_files", false);
  404. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "filesystem/file_dialog/display_mode", 0, "Thumbnails,List")
  405. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "filesystem/file_dialog/thumbnail_size", 64, "32,128,16")
  406. /* Docks */
  407. // SceneTree
  408. _initial_set("docks/scene_tree/start_create_dialog_fully_expanded", false);
  409. _initial_set("docks/scene_tree/auto_expand_to_selected", true);
  410. // FileSystem
  411. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "docks/filesystem/thumbnail_size", 64, "32,128,16")
  412. _initial_set("docks/filesystem/always_show_folders", true);
  413. _initial_set("docks/filesystem/textfile_extensions", "txt,md,cfg,ini,log,json,yml,yaml,toml");
  414. // Property editor
  415. _initial_set("docks/property_editor/auto_refresh_interval", 0.2); //update 5 times per second by default
  416. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "docks/property_editor/subresource_hue_tint", 0.75, "0,1,0.01")
  417. /* Text editor */
  418. // Theme
  419. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_ENUM, "text_editor/theme/color_theme", "Default", "Default,Godot 2,Custom")
  420. // Theme: Highlighting
  421. _load_godot2_text_editor_theme();
  422. // Appearance
  423. // Appearance: Caret
  424. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/appearance/caret/type", 0, "Line,Block")
  425. _initial_set("text_editor/appearance/caret/caret_blink", true);
  426. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "text_editor/appearance/caret/caret_blink_interval", 0.5, "0.1,10,0.01")
  427. _initial_set("text_editor/appearance/caret/highlight_current_line", true);
  428. _initial_set("text_editor/appearance/caret/highlight_all_occurrences", true);
  429. // Appearance: Guidelines
  430. _initial_set("text_editor/appearance/guidelines/show_line_length_guidelines", true);
  431. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/appearance/guidelines/line_length_guideline_soft_column", 80, "20,160,1")
  432. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/appearance/guidelines/line_length_guideline_hard_column", 100, "20,160,1")
  433. // Appearance: Gutters
  434. _initial_set("text_editor/appearance/gutters/show_line_numbers", true);
  435. _initial_set("text_editor/appearance/gutters/line_numbers_zero_padded", false);
  436. _initial_set("text_editor/appearance/gutters/highlight_type_safe_lines", true);
  437. _initial_set("text_editor/appearance/gutters/show_bookmark_gutter", true);
  438. _initial_set("text_editor/appearance/gutters/show_info_gutter", true);
  439. // Appearance: Minimap
  440. _initial_set("text_editor/appearance/minimap/show_minimap", true);
  441. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/appearance/minimap/minimap_width", 80, "50,250,1")
  442. // Appearance: Lines
  443. _initial_set("text_editor/appearance/lines/code_folding", true);
  444. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/appearance/lines/word_wrap", 0, "None,Boundary")
  445. // Appearance: Whitespace
  446. _initial_set("text_editor/appearance/whitespace/draw_tabs", true);
  447. _initial_set("text_editor/appearance/whitespace/draw_spaces", false);
  448. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/appearance/whitespace/line_spacing", 4, "0,50,1")
  449. // Behavior
  450. // Behavior: Navigation
  451. _initial_set("text_editor/behavior/navigation/move_caret_on_right_click", true);
  452. _initial_set("text_editor/behavior/navigation/scroll_past_end_of_file", false);
  453. _initial_set("text_editor/behavior/navigation/smooth_scrolling", true);
  454. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/behavior/navigation/v_scroll_speed", 80, "1,10000,1")
  455. _initial_set("text_editor/behavior/navigation/drag_and_drop_selection", true);
  456. _initial_set("text_editor/behavior/navigation/stay_in_script_editor_on_node_selected", true);
  457. // Behavior: Indent
  458. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/behavior/indent/type", 0, "Tabs,Spaces")
  459. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/behavior/indent/size", 4, "1,64,1") // size of 0 crashes.
  460. _initial_set("text_editor/behavior/indent/auto_indent", true);
  461. // Behavior: Files
  462. _initial_set("text_editor/behavior/files/trim_trailing_whitespace_on_save", false);
  463. _initial_set("text_editor/behavior/files/autosave_interval_secs", 0);
  464. _initial_set("text_editor/behavior/files/restore_scripts_on_load", true);
  465. _initial_set("text_editor/behavior/files/convert_indent_on_save", true);
  466. _initial_set("text_editor/behavior/files/auto_reload_scripts_on_external_change", false);
  467. // Script list
  468. _initial_set("text_editor/script_list/show_members_overview", true);
  469. _initial_set("text_editor/script_list/sort_members_outline_alphabetically", false);
  470. // Completion
  471. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "text_editor/completion/idle_parse_delay", 2.0, "0.1,10,0.01")
  472. _initial_set("text_editor/completion/auto_brace_complete", true);
  473. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "text_editor/completion/code_complete_delay", 0.3, "0.01,5,0.01")
  474. _initial_set("text_editor/completion/put_callhint_tooltip_below_current_line", true);
  475. _initial_set("text_editor/completion/complete_file_paths", true);
  476. _initial_set("text_editor/completion/add_type_hints", false);
  477. _initial_set("text_editor/completion/use_single_quotes", false);
  478. // Help
  479. _initial_set("text_editor/help/show_help_index", true);
  480. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/help/help_font_size", 15, "8,48,1")
  481. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/help/help_source_font_size", 14, "8,48,1")
  482. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/help/help_title_font_size", 23, "8,48,1")
  483. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/help/class_reference_examples", 0, "GDScript,C#,GDScript and C#")
  484. /* Editors */
  485. // GridMap
  486. _initial_set("editors/grid_map/pick_distance", 5000.0);
  487. // 3D
  488. EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d/primary_grid_color", Color(0.56, 0.56, 0.56, 0.5), "")
  489. EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d/secondary_grid_color", Color(0.38, 0.38, 0.38, 0.5), "")
  490. // Use a similar color to the 2D editor selection.
  491. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d/selection_box_color", Color(1.0, 0.5, 0), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  492. _initial_set("editors/3d_gizmos/gizmo_colors/instantiated", Color(0.7, 0.7, 0.7, 0.6));
  493. _initial_set("editors/3d_gizmos/gizmo_colors/joint", Color(0.5, 0.8, 1));
  494. _initial_set("editors/3d_gizmos/gizmo_colors/shape", Color(0.5, 0.7, 1));
  495. // If a line is a multiple of this, it uses the primary grid color.
  496. // Use a power of 2 value by default as it's more common to use powers of 2 in level design.
  497. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "editors/3d/primary_grid_steps", 8, "1,100,1")
  498. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "editors/3d/grid_size", 200, "1,2000,1")
  499. // Higher values produce graphical artifacts when far away unless View Z-Far
  500. // is increased significantly more than it really should need to be.
  501. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "editors/3d/grid_division_level_max", 2, "-1,3,1")
  502. // Lower values produce graphical artifacts regardless of view clipping planes, so limit to -2 as a lower bound.
  503. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "editors/3d/grid_division_level_min", 0, "-2,2,1")
  504. // -0.2 seems like a sensible default. -1.0 gives Blender-like behavior, 0.5 gives huge grids.
  505. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/grid_division_level_bias", -0.2, "-1.0,0.5,0.1")
  506. _initial_set("editors/3d/grid_xz_plane", true);
  507. _initial_set("editors/3d/grid_xy_plane", false);
  508. _initial_set("editors/3d/grid_yz_plane", false);
  509. // Use a lower default FOV for the 3D camera compared to the
  510. // Camera3D node as the 3D viewport doesn't span the whole screen.
  511. // This means it's technically viewed from a further distance, which warrants a narrower FOV.
  512. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/default_fov", 70.0, "1,179,0.1,degrees")
  513. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/default_z_near", 0.05, "0.01,10,0.01,or_greater,suffix:m")
  514. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/default_z_far", 4000.0, "0.1,4000,0.1,or_greater,suffix:m")
  515. // 3D: Navigation
  516. _initial_set("editors/3d/navigation/invert_x_axis", false);
  517. _initial_set("editors/3d/navigation/invert_y_axis", false);
  518. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/navigation_scheme", 0, "Godot,Maya,Modo")
  519. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/zoom_style", 0, "Vertical,Horizontal")
  520. _initial_set("editors/3d/navigation/emulate_numpad", false);
  521. _initial_set("editors/3d/navigation/emulate_3_button_mouse", false);
  522. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/orbit_modifier", 0, "None,Shift,Alt,Meta,Ctrl")
  523. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/pan_modifier", 1, "None,Shift,Alt,Meta,Ctrl")
  524. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/zoom_modifier", 4, "None,Shift,Alt,Meta,Ctrl")
  525. _initial_set("editors/3d/navigation/warped_mouse_panning", true);
  526. // 3D: Navigation feel
  527. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/navigation_feel/orbit_sensitivity", 0.25, "0.01,2,0.001")
  528. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/navigation_feel/orbit_inertia", 0.0, "0,1,0.001")
  529. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/navigation_feel/translation_inertia", 0.05, "0,1,0.001")
  530. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/navigation_feel/zoom_inertia", 0.05, "0,1,0.001")
  531. // 3D: Freelook
  532. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/freelook/freelook_navigation_scheme", 0, "Default,Partially Axis-Locked (id Tech),Fully Axis-Locked (Minecraft)")
  533. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/freelook/freelook_sensitivity", 0.25, "0.01,2,0.001")
  534. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/freelook/freelook_inertia", 0.0, "0,1,0.001")
  535. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/freelook/freelook_base_speed", 5.0, "0,10,0.01")
  536. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/freelook/freelook_activation_modifier", 0, "None,Shift,Alt,Meta,Ctrl")
  537. _initial_set("editors/3d/freelook/freelook_speed_zoom_link", false);
  538. // 2D
  539. _initial_set("editors/2d/grid_color", Color(1.0, 1.0, 1.0, 0.07));
  540. _initial_set("editors/2d/guides_color", Color(0.6, 0.0, 0.8));
  541. _initial_set("editors/2d/smart_snapping_line_color", Color(0.9, 0.1, 0.1));
  542. _initial_set("editors/2d/bone_width", 5);
  543. _initial_set("editors/2d/bone_color1", Color(1.0, 1.0, 1.0, 0.7));
  544. _initial_set("editors/2d/bone_color2", Color(0.6, 0.6, 0.6, 0.7));
  545. _initial_set("editors/2d/bone_selected_color", Color(0.9, 0.45, 0.45, 0.7));
  546. _initial_set("editors/2d/bone_ik_color", Color(0.9, 0.9, 0.45, 0.7));
  547. _initial_set("editors/2d/bone_outline_color", Color(0.35, 0.35, 0.35, 0.5));
  548. _initial_set("editors/2d/bone_outline_size", 2);
  549. _initial_set("editors/2d/viewport_border_color", Color(0.4, 0.4, 1.0, 0.4));
  550. _initial_set("editors/2d/constrain_editor_view", true);
  551. // Panning
  552. // Enum should be in sync with ControlScheme in ViewPanner.
  553. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/panning/2d_editor_panning_scheme", 0, "Scroll Zooms,Scroll Pans");
  554. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/panning/sub_editors_panning_scheme", 0, "Scroll Zooms,Scroll Pans");
  555. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/panning/animation_editors_panning_scheme", 1, "Scroll Zooms,Scroll Pans");
  556. _initial_set("editors/panning/simple_panning", false);
  557. _initial_set("editors/panning/warped_mouse_panning", true);
  558. _initial_set("editors/panning/2d_editor_pan_speed", 20);
  559. // Tiles editor
  560. _initial_set("editors/tiles_editor/display_grid", true);
  561. _initial_set("editors/tiles_editor/grid_color", Color(1.0, 0.5, 0.2, 0.5));
  562. // Polygon editor
  563. _initial_set("editors/polygon_editor/point_grab_radius", 8);
  564. _initial_set("editors/polygon_editor/show_previous_outline", true);
  565. // Animation
  566. _initial_set("editors/animation/autorename_animation_tracks", true);
  567. _initial_set("editors/animation/confirm_insert_track", true);
  568. _initial_set("editors/animation/default_create_bezier_tracks", false);
  569. _initial_set("editors/animation/default_create_reset_tracks", true);
  570. _initial_set("editors/animation/onion_layers_past_color", Color(1, 0, 0));
  571. _initial_set("editors/animation/onion_layers_future_color", Color(0, 1, 0));
  572. // Visual editors
  573. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/visual_editors/minimap_opacity", 0.85, "0.0,1.0,0.01")
  574. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/visual_editors/lines_curvature", 0.5, "0.0,1.0,0.01")
  575. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "editors/visual_editors/visual_shader/port_preview_size", 160, "100,400,0.01")
  576. /* Run */
  577. // Window placement
  578. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "run/window_placement/rect", 1, "Top Left,Centered,Custom Position,Force Maximized,Force Fullscreen")
  579. String screen_hints = "Same as Editor,Previous Monitor,Next Monitor";
  580. for (int i = 0; i < DisplayServer::get_singleton()->get_screen_count(); i++) {
  581. screen_hints += ",Monitor " + itos(i + 1);
  582. }
  583. _initial_set("run/window_placement/rect_custom_position", Vector2());
  584. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "run/window_placement/screen", 0, screen_hints)
  585. // Auto save
  586. _initial_set("run/auto_save/save_before_running", true);
  587. // Output
  588. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "run/output/font_size", 13, "8,48,1")
  589. _initial_set("run/output/always_clear_output_on_play", true);
  590. _initial_set("run/output/always_open_output_on_play", true);
  591. _initial_set("run/output/always_close_output_on_stop", false);
  592. /* Network */
  593. // Debug
  594. _initial_set("network/debug/remote_host", "127.0.0.1"); // Hints provided in setup_network
  595. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "network/debug/remote_port", 6007, "1,65535,1")
  596. // SSL
  597. EDITOR_SETTING_USAGE(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "network/tls/editor_tls_certificates", _SYSTEM_CERTS_PATH, "*.crt,*.pem", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
  598. // Profiler
  599. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "debugger/profiler_frame_history_size", 3600, "60,10000,1")
  600. // HTTP Proxy
  601. _initial_set("network/http_proxy/host", "");
  602. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "network/http_proxy/port", 8080, "1,65535,1")
  603. /* Extra config */
  604. // TRANSLATORS: Project Manager here refers to the tool used to create/manage Godot projects.
  605. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "project_manager/sorting_order", 0, "Last Edited,Name,Path")
  606. if (p_extra_config.is_valid()) {
  607. if (p_extra_config->has_section("init_projects") && p_extra_config->has_section_key("init_projects", "list")) {
  608. Vector<String> list = p_extra_config->get_value("init_projects", "list");
  609. for (int i = 0; i < list.size(); i++) {
  610. String proj_name = list[i].replace("/", "::");
  611. set("projects/" + proj_name, list[i]);
  612. }
  613. }
  614. if (p_extra_config->has_section("presets")) {
  615. List<String> keys;
  616. p_extra_config->get_section_keys("presets", &keys);
  617. for (const String &key : keys) {
  618. Variant val = p_extra_config->get_value("presets", key);
  619. set(key, val);
  620. }
  621. }
  622. }
  623. }
  624. void EditorSettings::_load_godot2_text_editor_theme() {
  625. // Godot 2 is only a dark theme; it doesn't have a light theme counterpart.
  626. _initial_set("text_editor/theme/highlighting/symbol_color", Color(0.73, 0.87, 1.0));
  627. _initial_set("text_editor/theme/highlighting/keyword_color", Color(1.0, 1.0, 0.7));
  628. _initial_set("text_editor/theme/highlighting/control_flow_keyword_color", Color(1.0, 0.85, 0.7));
  629. _initial_set("text_editor/theme/highlighting/base_type_color", Color(0.64, 1.0, 0.83));
  630. _initial_set("text_editor/theme/highlighting/engine_type_color", Color(0.51, 0.83, 1.0));
  631. _initial_set("text_editor/theme/highlighting/user_type_color", Color(0.42, 0.67, 0.93));
  632. _initial_set("text_editor/theme/highlighting/comment_color", Color(0.4, 0.4, 0.4));
  633. _initial_set("text_editor/theme/highlighting/string_color", Color(0.94, 0.43, 0.75));
  634. _initial_set("text_editor/theme/highlighting/background_color", Color(0.13, 0.12, 0.15));
  635. _initial_set("text_editor/theme/highlighting/completion_background_color", Color(0.17, 0.16, 0.2));
  636. _initial_set("text_editor/theme/highlighting/completion_selected_color", Color(0.26, 0.26, 0.27));
  637. _initial_set("text_editor/theme/highlighting/completion_existing_color", Color(0.87, 0.87, 0.87, 0.13));
  638. _initial_set("text_editor/theme/highlighting/completion_scroll_color", Color(1, 1, 1, 0.29));
  639. _initial_set("text_editor/theme/highlighting/completion_scroll_hovered_color", Color(1, 1, 1, 0.4));
  640. _initial_set("text_editor/theme/highlighting/completion_font_color", Color(0.67, 0.67, 0.67));
  641. _initial_set("text_editor/theme/highlighting/text_color", Color(0.67, 0.67, 0.67));
  642. _initial_set("text_editor/theme/highlighting/line_number_color", Color(0.67, 0.67, 0.67, 0.4));
  643. _initial_set("text_editor/theme/highlighting/safe_line_number_color", Color(0.67, 0.78, 0.67, 0.6));
  644. _initial_set("text_editor/theme/highlighting/caret_color", Color(0.67, 0.67, 0.67));
  645. _initial_set("text_editor/theme/highlighting/caret_background_color", Color(0, 0, 0));
  646. _initial_set("text_editor/theme/highlighting/text_selected_color", Color(0, 0, 0));
  647. _initial_set("text_editor/theme/highlighting/selection_color", Color(0.41, 0.61, 0.91, 0.35));
  648. _initial_set("text_editor/theme/highlighting/brace_mismatch_color", Color(1, 0.2, 0.2));
  649. _initial_set("text_editor/theme/highlighting/current_line_color", Color(0.3, 0.5, 0.8, 0.15));
  650. _initial_set("text_editor/theme/highlighting/line_length_guideline_color", Color(0.3, 0.5, 0.8, 0.1));
  651. _initial_set("text_editor/theme/highlighting/word_highlighted_color", Color(0.8, 0.9, 0.9, 0.15));
  652. _initial_set("text_editor/theme/highlighting/number_color", Color(0.92, 0.58, 0.2));
  653. _initial_set("text_editor/theme/highlighting/function_color", Color(0.4, 0.64, 0.81));
  654. _initial_set("text_editor/theme/highlighting/member_variable_color", Color(0.9, 0.31, 0.35));
  655. _initial_set("text_editor/theme/highlighting/mark_color", Color(1.0, 0.4, 0.4, 0.4));
  656. _initial_set("text_editor/theme/highlighting/bookmark_color", Color(0.08, 0.49, 0.98));
  657. _initial_set("text_editor/theme/highlighting/breakpoint_color", Color(0.9, 0.29, 0.3));
  658. _initial_set("text_editor/theme/highlighting/executing_line_color", Color(0.98, 0.89, 0.27));
  659. _initial_set("text_editor/theme/highlighting/code_folding_color", Color(0.8, 0.8, 0.8, 0.8));
  660. _initial_set("text_editor/theme/highlighting/search_result_color", Color(0.05, 0.25, 0.05, 1));
  661. _initial_set("text_editor/theme/highlighting/search_result_border_color", Color(0.41, 0.61, 0.91, 0.38));
  662. }
  663. bool EditorSettings::_save_text_editor_theme(String p_file) {
  664. String theme_section = "color_theme";
  665. Ref<ConfigFile> cf = memnew(ConfigFile); // hex is better?
  666. List<String> keys;
  667. for (const KeyValue<String, VariantContainer> &E : props) {
  668. keys.push_back(E.key);
  669. }
  670. keys.sort();
  671. for (const String &key : keys) {
  672. if (key.begins_with("text_editor/theme/highlighting/") && key.find("color") >= 0) {
  673. cf->set_value(theme_section, key.replace("text_editor/theme/highlighting/", ""), ((Color)props[key].variant).to_html());
  674. }
  675. }
  676. Error err = cf->save(p_file);
  677. return err == OK;
  678. }
  679. bool EditorSettings::_is_default_text_editor_theme(String p_theme_name) {
  680. return p_theme_name == "default" || p_theme_name == "godot 2" || p_theme_name == "custom";
  681. }
  682. // PUBLIC METHODS
  683. EditorSettings *EditorSettings::get_singleton() {
  684. return singleton.ptr();
  685. }
  686. void EditorSettings::create() {
  687. // IMPORTANT: create() *must* create a valid EditorSettings singleton,
  688. // as the rest of the engine code will assume it. As such, it should never
  689. // return (incl. via ERR_FAIL) without initializing the singleton member.
  690. if (singleton.ptr()) {
  691. ERR_PRINT("Can't recreate EditorSettings as it already exists.");
  692. return;
  693. }
  694. GDREGISTER_CLASS(EditorSettings); // Otherwise it can't be unserialized.
  695. String config_file_path;
  696. Ref<ConfigFile> extra_config = memnew(ConfigFile);
  697. if (!EditorPaths::get_singleton()) {
  698. ERR_PRINT("Bug (please report): EditorPaths haven't been initialized, EditorSettings cannot be created properly.");
  699. goto fail;
  700. }
  701. if (EditorPaths::get_singleton()->is_self_contained()) {
  702. Error err = extra_config->load(EditorPaths::get_singleton()->get_self_contained_file());
  703. if (err != OK) {
  704. ERR_PRINT("Can't load extra config from path: " + EditorPaths::get_singleton()->get_self_contained_file());
  705. }
  706. }
  707. if (EditorPaths::get_singleton()->are_paths_valid()) {
  708. // Validate editor config file.
  709. Ref<DirAccess> dir = DirAccess::open(EditorPaths::get_singleton()->get_config_dir());
  710. String config_file_name = "editor_settings-" + itos(VERSION_MAJOR) + ".tres";
  711. config_file_path = EditorPaths::get_singleton()->get_config_dir().path_join(config_file_name);
  712. if (!dir->file_exists(config_file_name)) {
  713. goto fail;
  714. }
  715. singleton = ResourceLoader::load(config_file_path, "EditorSettings");
  716. if (singleton.is_null()) {
  717. ERR_PRINT("Could not load editor settings from path: " + config_file_path);
  718. goto fail;
  719. }
  720. singleton->save_changed_setting = true;
  721. print_verbose("EditorSettings: Load OK!");
  722. singleton->setup_language();
  723. singleton->setup_network();
  724. singleton->load_favorites_and_recent_dirs();
  725. singleton->list_text_editor_themes();
  726. return;
  727. }
  728. fail:
  729. // patch init projects
  730. String exe_path = OS::get_singleton()->get_executable_path().get_base_dir();
  731. if (extra_config->has_section("init_projects")) {
  732. Vector<String> list = extra_config->get_value("init_projects", "list");
  733. for (int i = 0; i < list.size(); i++) {
  734. list.write[i] = exe_path.path_join(list[i]);
  735. }
  736. extra_config->set_value("init_projects", "list", list);
  737. }
  738. singleton = Ref<EditorSettings>(memnew(EditorSettings));
  739. singleton->set_path(config_file_path, true);
  740. singleton->save_changed_setting = true;
  741. singleton->_load_defaults(extra_config);
  742. singleton->setup_language();
  743. singleton->setup_network();
  744. singleton->list_text_editor_themes();
  745. }
  746. void EditorSettings::setup_language() {
  747. TranslationServer::get_singleton()->set_editor_pseudolocalization(get("interface/editor/debug/enable_pseudolocalization"));
  748. String lang = get("interface/editor/editor_language");
  749. if (lang == "en") {
  750. return; // Default, nothing to do.
  751. }
  752. // Load editor translation for configured/detected locale.
  753. load_editor_translations(lang);
  754. // Load class reference translation.
  755. load_doc_translations(lang);
  756. }
  757. void EditorSettings::setup_network() {
  758. List<IPAddress> local_ip;
  759. IP::get_singleton()->get_local_addresses(&local_ip);
  760. String hint;
  761. String current = has_setting("network/debug/remote_host") ? get("network/debug/remote_host") : "";
  762. String selected = "127.0.0.1";
  763. // Check that current remote_host is a valid interface address and populate hints.
  764. for (const IPAddress &ip : local_ip) {
  765. // link-local IPv6 addresses don't work, skipping them
  766. if (String(ip).begins_with("fe80:0:0:0:")) { // fe80::/64
  767. continue;
  768. }
  769. // Same goes for IPv4 link-local (APIPA) addresses.
  770. if (String(ip).begins_with("169.254.")) { // 169.254.0.0/16
  771. continue;
  772. }
  773. // Select current IP (found)
  774. if (ip == current) {
  775. selected = ip;
  776. }
  777. if (!hint.is_empty()) {
  778. hint += ",";
  779. }
  780. hint += ip;
  781. }
  782. // Add hints with valid IP addresses to remote_host property.
  783. add_property_hint(PropertyInfo(Variant::STRING, "network/debug/remote_host", PROPERTY_HINT_ENUM, hint));
  784. // Fix potentially invalid remote_host due to network change.
  785. set("network/debug/remote_host", selected);
  786. }
  787. void EditorSettings::save() {
  788. //_THREAD_SAFE_METHOD_
  789. if (!singleton.ptr()) {
  790. return;
  791. }
  792. Error err = ResourceSaver::save(singleton);
  793. if (err != OK) {
  794. ERR_PRINT("Error saving editor settings to " + singleton->get_path());
  795. } else {
  796. singleton->changed_settings.clear();
  797. print_verbose("EditorSettings: Save OK!");
  798. }
  799. }
  800. PackedStringArray EditorSettings::get_changed_settings() const {
  801. PackedStringArray arr;
  802. for (const String &setting : changed_settings) {
  803. arr.push_back(setting);
  804. }
  805. return arr;
  806. }
  807. bool EditorSettings::check_changed_settings_in_group(const String &p_setting_prefix) const {
  808. for (const String &setting : changed_settings) {
  809. if (setting.begins_with(p_setting_prefix)) {
  810. return true;
  811. }
  812. }
  813. return false;
  814. }
  815. void EditorSettings::mark_setting_changed(const String &p_setting) {
  816. changed_settings.insert(p_setting);
  817. }
  818. void EditorSettings::destroy() {
  819. if (!singleton.ptr()) {
  820. return;
  821. }
  822. save();
  823. singleton = Ref<EditorSettings>();
  824. }
  825. void EditorSettings::set_optimize_save(bool p_optimize) {
  826. optimize_save = p_optimize;
  827. }
  828. // Properties
  829. void EditorSettings::set_setting(const String &p_setting, const Variant &p_value) {
  830. _THREAD_SAFE_METHOD_
  831. set(p_setting, p_value);
  832. }
  833. Variant EditorSettings::get_setting(const String &p_setting) const {
  834. _THREAD_SAFE_METHOD_
  835. return get(p_setting);
  836. }
  837. bool EditorSettings::has_setting(const String &p_setting) const {
  838. _THREAD_SAFE_METHOD_
  839. return props.has(p_setting);
  840. }
  841. void EditorSettings::erase(const String &p_setting) {
  842. _THREAD_SAFE_METHOD_
  843. props.erase(p_setting);
  844. }
  845. void EditorSettings::raise_order(const String &p_setting) {
  846. _THREAD_SAFE_METHOD_
  847. ERR_FAIL_COND(!props.has(p_setting));
  848. props[p_setting].order = ++last_order;
  849. }
  850. void EditorSettings::set_restart_if_changed(const StringName &p_setting, bool p_restart) {
  851. _THREAD_SAFE_METHOD_
  852. if (!props.has(p_setting)) {
  853. return;
  854. }
  855. props[p_setting].restart_if_changed = p_restart;
  856. }
  857. void EditorSettings::set_initial_value(const StringName &p_setting, const Variant &p_value, bool p_update_current) {
  858. _THREAD_SAFE_METHOD_
  859. if (!props.has(p_setting)) {
  860. return;
  861. }
  862. props[p_setting].initial = p_value;
  863. props[p_setting].has_default_value = true;
  864. if (p_update_current) {
  865. set(p_setting, p_value);
  866. }
  867. }
  868. Variant _EDITOR_DEF(const String &p_setting, const Variant &p_default, bool p_restart_if_changed) {
  869. ERR_FAIL_NULL_V_MSG(EditorSettings::get_singleton(), p_default, "EditorSettings not instantiated yet.");
  870. Variant ret = p_default;
  871. if (EditorSettings::get_singleton()->has_setting(p_setting)) {
  872. ret = EditorSettings::get_singleton()->get(p_setting);
  873. } else {
  874. EditorSettings::get_singleton()->set_manually(p_setting, p_default);
  875. EditorSettings::get_singleton()->set_restart_if_changed(p_setting, p_restart_if_changed);
  876. }
  877. if (!EditorSettings::get_singleton()->has_default_value(p_setting)) {
  878. EditorSettings::get_singleton()->set_initial_value(p_setting, p_default);
  879. }
  880. return ret;
  881. }
  882. Variant _EDITOR_GET(const String &p_setting) {
  883. ERR_FAIL_COND_V(!EditorSettings::get_singleton() || !EditorSettings::get_singleton()->has_setting(p_setting), Variant());
  884. return EditorSettings::get_singleton()->get(p_setting);
  885. }
  886. bool EditorSettings::_property_can_revert(const StringName &p_name) const {
  887. if (!props.has(p_name)) {
  888. return false;
  889. }
  890. if (!props[p_name].has_default_value) {
  891. return false;
  892. }
  893. return props[p_name].initial != props[p_name].variant;
  894. }
  895. bool EditorSettings::_property_get_revert(const StringName &p_name, Variant &r_property) const {
  896. if (!props.has(p_name) || !props[p_name].has_default_value) {
  897. return false;
  898. }
  899. r_property = props[p_name].initial;
  900. return true;
  901. }
  902. void EditorSettings::add_property_hint(const PropertyInfo &p_hint) {
  903. _THREAD_SAFE_METHOD_
  904. hints[p_hint.name] = p_hint;
  905. }
  906. // Metadata
  907. void EditorSettings::set_project_metadata(const String &p_section, const String &p_key, Variant p_data) {
  908. Ref<ConfigFile> cf = memnew(ConfigFile);
  909. String path = EditorPaths::get_singleton()->get_project_settings_dir().path_join("project_metadata.cfg");
  910. Error err;
  911. err = cf->load(path);
  912. ERR_FAIL_COND_MSG(err != OK && err != ERR_FILE_NOT_FOUND, "Cannot load editor settings from file '" + path + "'.");
  913. cf->set_value(p_section, p_key, p_data);
  914. err = cf->save(path);
  915. ERR_FAIL_COND_MSG(err != OK, "Cannot save editor settings to file '" + path + "'.");
  916. }
  917. Variant EditorSettings::get_project_metadata(const String &p_section, const String &p_key, Variant p_default) const {
  918. Ref<ConfigFile> cf = memnew(ConfigFile);
  919. String path = EditorPaths::get_singleton()->get_project_settings_dir().path_join("project_metadata.cfg");
  920. Error err = cf->load(path);
  921. if (err != OK) {
  922. return p_default;
  923. }
  924. return cf->get_value(p_section, p_key, p_default);
  925. }
  926. void EditorSettings::set_favorites(const Vector<String> &p_favorites) {
  927. favorites = p_favorites;
  928. String favorites_file;
  929. if (Engine::get_singleton()->is_project_manager_hint()) {
  930. favorites_file = EditorPaths::get_singleton()->get_config_dir().path_join("favorite_dirs");
  931. } else {
  932. favorites_file = EditorPaths::get_singleton()->get_project_settings_dir().path_join("favorites");
  933. }
  934. Ref<FileAccess> f = FileAccess::open(favorites_file, FileAccess::WRITE);
  935. if (f.is_valid()) {
  936. for (int i = 0; i < favorites.size(); i++) {
  937. f->store_line(favorites[i]);
  938. }
  939. }
  940. }
  941. Vector<String> EditorSettings::get_favorites() const {
  942. return favorites;
  943. }
  944. void EditorSettings::set_recent_dirs(const Vector<String> &p_recent_dirs) {
  945. recent_dirs = p_recent_dirs;
  946. String recent_dirs_file;
  947. if (Engine::get_singleton()->is_project_manager_hint()) {
  948. recent_dirs_file = EditorPaths::get_singleton()->get_config_dir().path_join("recent_dirs");
  949. } else {
  950. recent_dirs_file = EditorPaths::get_singleton()->get_project_settings_dir().path_join("recent_dirs");
  951. }
  952. Ref<FileAccess> f = FileAccess::open(recent_dirs_file, FileAccess::WRITE);
  953. if (f.is_valid()) {
  954. for (int i = 0; i < recent_dirs.size(); i++) {
  955. f->store_line(recent_dirs[i]);
  956. }
  957. }
  958. }
  959. Vector<String> EditorSettings::get_recent_dirs() const {
  960. return recent_dirs;
  961. }
  962. void EditorSettings::load_favorites_and_recent_dirs() {
  963. String favorites_file;
  964. String recent_dirs_file;
  965. if (Engine::get_singleton()->is_project_manager_hint()) {
  966. favorites_file = EditorPaths::get_singleton()->get_config_dir().path_join("favorite_dirs");
  967. recent_dirs_file = EditorPaths::get_singleton()->get_config_dir().path_join("recent_dirs");
  968. } else {
  969. favorites_file = EditorPaths::get_singleton()->get_project_settings_dir().path_join("favorites");
  970. recent_dirs_file = EditorPaths::get_singleton()->get_project_settings_dir().path_join("recent_dirs");
  971. }
  972. Ref<FileAccess> f = FileAccess::open(favorites_file, FileAccess::READ);
  973. if (f.is_valid()) {
  974. String line = f->get_line().strip_edges();
  975. while (!line.is_empty()) {
  976. favorites.push_back(line);
  977. line = f->get_line().strip_edges();
  978. }
  979. }
  980. f = FileAccess::open(recent_dirs_file, FileAccess::READ);
  981. if (f.is_valid()) {
  982. String line = f->get_line().strip_edges();
  983. while (!line.is_empty()) {
  984. recent_dirs.push_back(line);
  985. line = f->get_line().strip_edges();
  986. }
  987. }
  988. }
  989. bool EditorSettings::is_dark_theme() {
  990. int AUTO_COLOR = 0;
  991. int LIGHT_COLOR = 2;
  992. Color base_color = get("interface/theme/base_color");
  993. int icon_font_color_setting = get("interface/theme/icon_and_font_color");
  994. return (icon_font_color_setting == AUTO_COLOR && base_color.get_luminance() < 0.5) || icon_font_color_setting == LIGHT_COLOR;
  995. }
  996. void EditorSettings::list_text_editor_themes() {
  997. String themes = "Default,Godot 2,Custom";
  998. Ref<DirAccess> d = DirAccess::open(EditorPaths::get_singleton()->get_text_editor_themes_dir());
  999. if (d.is_valid()) {
  1000. List<String> custom_themes;
  1001. d->list_dir_begin();
  1002. String file = d->get_next();
  1003. while (!file.is_empty()) {
  1004. if (file.get_extension() == "tet" && !_is_default_text_editor_theme(file.get_basename().to_lower())) {
  1005. custom_themes.push_back(file.get_basename());
  1006. }
  1007. file = d->get_next();
  1008. }
  1009. d->list_dir_end();
  1010. custom_themes.sort();
  1011. for (const String &E : custom_themes) {
  1012. themes += "," + E;
  1013. }
  1014. }
  1015. add_property_hint(PropertyInfo(Variant::STRING, "text_editor/theme/color_theme", PROPERTY_HINT_ENUM, themes));
  1016. }
  1017. void EditorSettings::load_text_editor_theme() {
  1018. String p_file = get("text_editor/theme/color_theme");
  1019. if (_is_default_text_editor_theme(p_file.get_file().to_lower())) {
  1020. if (p_file == "Godot 2") {
  1021. _load_godot2_text_editor_theme();
  1022. }
  1023. return; // sorry for "Settings changed" console spam
  1024. }
  1025. String theme_path = EditorPaths::get_singleton()->get_text_editor_themes_dir().path_join(p_file + ".tet");
  1026. Ref<ConfigFile> cf = memnew(ConfigFile);
  1027. Error err = cf->load(theme_path);
  1028. if (err != OK) {
  1029. return;
  1030. }
  1031. List<String> keys;
  1032. cf->get_section_keys("color_theme", &keys);
  1033. for (const String &key : keys) {
  1034. String val = cf->get_value("color_theme", key);
  1035. // don't load if it's not already there!
  1036. if (has_setting("text_editor/theme/highlighting/" + key)) {
  1037. // make sure it is actually a color
  1038. if (val.is_valid_html_color() && key.find("color") >= 0) {
  1039. props["text_editor/theme/highlighting/" + key].variant = Color::html(val); // change manually to prevent "Settings changed" console spam
  1040. }
  1041. }
  1042. }
  1043. emit_signal(SNAME("settings_changed"));
  1044. // if it doesn't load just use what is currently loaded
  1045. }
  1046. bool EditorSettings::import_text_editor_theme(String p_file) {
  1047. if (!p_file.ends_with(".tet")) {
  1048. return false;
  1049. } else {
  1050. if (p_file.get_file().to_lower() == "default.tet") {
  1051. return false;
  1052. }
  1053. Ref<DirAccess> d = DirAccess::open(EditorPaths::get_singleton()->get_text_editor_themes_dir());
  1054. if (d.is_valid()) {
  1055. d->copy(p_file, EditorPaths::get_singleton()->get_text_editor_themes_dir().path_join(p_file.get_file()));
  1056. return true;
  1057. }
  1058. }
  1059. return false;
  1060. }
  1061. bool EditorSettings::save_text_editor_theme() {
  1062. String p_file = get("text_editor/theme/color_theme");
  1063. if (_is_default_text_editor_theme(p_file.get_file().to_lower())) {
  1064. return false;
  1065. }
  1066. String theme_path = EditorPaths::get_singleton()->get_text_editor_themes_dir().path_join(p_file + ".tet");
  1067. return _save_text_editor_theme(theme_path);
  1068. }
  1069. bool EditorSettings::save_text_editor_theme_as(String p_file) {
  1070. if (!p_file.ends_with(".tet")) {
  1071. p_file += ".tet";
  1072. }
  1073. if (_is_default_text_editor_theme(p_file.get_file().to_lower().trim_suffix(".tet"))) {
  1074. return false;
  1075. }
  1076. if (_save_text_editor_theme(p_file)) {
  1077. // switch to theme is saved in the theme directory
  1078. list_text_editor_themes();
  1079. String theme_name = p_file.substr(0, p_file.length() - 4).get_file();
  1080. if (p_file.get_base_dir() == EditorPaths::get_singleton()->get_text_editor_themes_dir()) {
  1081. _initial_set("text_editor/theme/color_theme", theme_name);
  1082. load_text_editor_theme();
  1083. }
  1084. return true;
  1085. }
  1086. return false;
  1087. }
  1088. bool EditorSettings::is_default_text_editor_theme() {
  1089. String p_file = get("text_editor/theme/color_theme");
  1090. return _is_default_text_editor_theme(p_file.get_file().to_lower());
  1091. }
  1092. Vector<String> EditorSettings::get_script_templates(const String &p_extension, const String &p_custom_path) {
  1093. Vector<String> templates;
  1094. String template_dir = EditorPaths::get_singleton()->get_script_templates_dir();
  1095. if (!p_custom_path.is_empty()) {
  1096. template_dir = p_custom_path;
  1097. }
  1098. Ref<DirAccess> d = DirAccess::open(template_dir);
  1099. if (d.is_valid()) {
  1100. d->list_dir_begin();
  1101. String file = d->get_next();
  1102. while (!file.is_empty()) {
  1103. if (file.get_extension() == p_extension) {
  1104. templates.push_back(file.get_basename());
  1105. }
  1106. file = d->get_next();
  1107. }
  1108. d->list_dir_end();
  1109. }
  1110. return templates;
  1111. }
  1112. String EditorSettings::get_editor_layouts_config() const {
  1113. return EditorPaths::get_singleton()->get_config_dir().path_join("editor_layouts.cfg");
  1114. }
  1115. float EditorSettings::get_auto_display_scale() const {
  1116. #if defined(MACOS_ENABLED) || defined(ANDROID_ENABLED)
  1117. return DisplayServer::get_singleton()->screen_get_max_scale();
  1118. #else
  1119. const int screen = DisplayServer::get_singleton()->window_get_current_screen();
  1120. if (DisplayServer::get_singleton()->screen_get_size(screen) == Vector2i()) {
  1121. // Invalid screen size, skip.
  1122. return 1.0;
  1123. }
  1124. // Use the smallest dimension to use a correct display scale on portrait displays.
  1125. const int smallest_dimension = MIN(DisplayServer::get_singleton()->screen_get_size(screen).x, DisplayServer::get_singleton()->screen_get_size(screen).y);
  1126. if (DisplayServer::get_singleton()->screen_get_dpi(screen) >= 192 && smallest_dimension >= 1400) {
  1127. // hiDPI display.
  1128. return 2.0;
  1129. } else if (smallest_dimension >= 1700) {
  1130. // Likely a hiDPI display, but we aren't certain due to the returned DPI.
  1131. // Use an intermediate scale to handle this situation.
  1132. return 1.5;
  1133. } else if (smallest_dimension <= 800) {
  1134. // Small loDPI display. Use a smaller display scale so that editor elements fit more easily.
  1135. // Icons won't look great, but this is better than having editor elements overflow from its window.
  1136. return 0.75;
  1137. }
  1138. return 1.0;
  1139. #endif
  1140. }
  1141. // Shortcuts
  1142. void EditorSettings::add_shortcut(const String &p_name, const Ref<Shortcut> &p_shortcut) {
  1143. shortcuts[p_name] = p_shortcut;
  1144. }
  1145. bool EditorSettings::is_shortcut(const String &p_name, const Ref<InputEvent> &p_event) const {
  1146. HashMap<String, Ref<Shortcut>>::ConstIterator E = shortcuts.find(p_name);
  1147. ERR_FAIL_COND_V_MSG(!E, false, "Unknown Shortcut: " + p_name + ".");
  1148. return E->value->matches_event(p_event);
  1149. }
  1150. Ref<Shortcut> EditorSettings::get_shortcut(const String &p_name) const {
  1151. HashMap<String, Ref<Shortcut>>::ConstIterator SC = shortcuts.find(p_name);
  1152. if (SC) {
  1153. return SC->value;
  1154. }
  1155. // If no shortcut with the provided name is found in the list, check the built-in shortcuts.
  1156. // Use the first item in the action list for the shortcut event, since a shortcut can only have 1 linked event.
  1157. Ref<Shortcut> sc;
  1158. HashMap<String, List<Ref<InputEvent>>>::ConstIterator builtin_override = builtin_action_overrides.find(p_name);
  1159. if (builtin_override) {
  1160. sc.instantiate();
  1161. sc->set_events_list(&builtin_override->value);
  1162. sc->set_name(InputMap::get_singleton()->get_builtin_display_name(p_name));
  1163. }
  1164. // If there was no override, check the default builtins to see if it has an InputEvent for the provided name.
  1165. if (sc.is_null()) {
  1166. HashMap<String, List<Ref<InputEvent>>>::ConstIterator builtin_default = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied().find(p_name);
  1167. if (builtin_default) {
  1168. sc.instantiate();
  1169. sc->set_events_list(&builtin_default->value);
  1170. sc->set_name(InputMap::get_singleton()->get_builtin_display_name(p_name));
  1171. }
  1172. }
  1173. if (sc.is_valid()) {
  1174. // Add the shortcut to the list.
  1175. shortcuts[p_name] = sc;
  1176. return sc;
  1177. }
  1178. return Ref<Shortcut>();
  1179. }
  1180. void EditorSettings::get_shortcut_list(List<String> *r_shortcuts) {
  1181. for (const KeyValue<String, Ref<Shortcut>> &E : shortcuts) {
  1182. r_shortcuts->push_back(E.key);
  1183. }
  1184. }
  1185. Ref<Shortcut> ED_GET_SHORTCUT(const String &p_path) {
  1186. ERR_FAIL_NULL_V_MSG(EditorSettings::get_singleton(), nullptr, "EditorSettings not instantiated yet.");
  1187. Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
  1188. ERR_FAIL_COND_V_MSG(!sc.is_valid(), sc, "Used ED_GET_SHORTCUT with invalid shortcut: " + p_path + ".");
  1189. return sc;
  1190. }
  1191. void ED_SHORTCUT_OVERRIDE(const String &p_path, const String &p_feature, Key p_keycode) {
  1192. ERR_FAIL_NULL_MSG(EditorSettings::get_singleton(), "EditorSettings not instantiated yet.");
  1193. Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
  1194. ERR_FAIL_COND_MSG(!sc.is_valid(), "Used ED_SHORTCUT_OVERRIDE with invalid shortcut: " + p_path + ".");
  1195. PackedInt32Array arr;
  1196. arr.push_back((int32_t)p_keycode);
  1197. ED_SHORTCUT_OVERRIDE_ARRAY(p_path, p_feature, arr);
  1198. }
  1199. void ED_SHORTCUT_OVERRIDE_ARRAY(const String &p_path, const String &p_feature, const PackedInt32Array &p_keycodes) {
  1200. ERR_FAIL_NULL_MSG(EditorSettings::get_singleton(), "EditorSettings not instantiated yet.");
  1201. Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
  1202. ERR_FAIL_COND_MSG(!sc.is_valid(), "Used ED_SHORTCUT_OVERRIDE_ARRAY with invalid shortcut: " + p_path + ".");
  1203. // Only add the override if the OS supports the provided feature.
  1204. if (!OS::get_singleton()->has_feature(p_feature)) {
  1205. return;
  1206. }
  1207. Array events;
  1208. for (int i = 0; i < p_keycodes.size(); i++) {
  1209. Key keycode = (Key)p_keycodes[i];
  1210. #ifdef MACOS_ENABLED
  1211. // Use Cmd+Backspace as a general replacement for Delete shortcuts on macOS
  1212. if (keycode == Key::KEY_DELETE) {
  1213. keycode = KeyModifierMask::META | Key::BACKSPACE;
  1214. }
  1215. #endif
  1216. Ref<InputEventKey> ie;
  1217. if (keycode != Key::NONE) {
  1218. ie = InputEventKey::create_reference(keycode);
  1219. events.push_back(ie);
  1220. }
  1221. }
  1222. // Override the existing shortcut only if it wasn't customized by the user (i.e. still "original").
  1223. if (Shortcut::is_event_array_equal(sc->get_events(), sc->get_meta("original"))) {
  1224. sc->set_events(events);
  1225. }
  1226. sc->set_meta("original", events.duplicate(true));
  1227. }
  1228. Ref<Shortcut> ED_SHORTCUT(const String &p_path, const String &p_name, Key p_keycode) {
  1229. PackedInt32Array arr;
  1230. arr.push_back((int32_t)p_keycode);
  1231. return ED_SHORTCUT_ARRAY(p_path, p_name, arr);
  1232. }
  1233. Ref<Shortcut> ED_SHORTCUT_ARRAY(const String &p_path, const String &p_name, const PackedInt32Array &p_keycodes) {
  1234. Array events;
  1235. for (int i = 0; i < p_keycodes.size(); i++) {
  1236. Key keycode = (Key)p_keycodes[i];
  1237. #ifdef MACOS_ENABLED
  1238. // Use Cmd+Backspace as a general replacement for Delete shortcuts on macOS
  1239. if (keycode == Key::KEY_DELETE) {
  1240. keycode = KeyModifierMask::META | Key::BACKSPACE;
  1241. }
  1242. #endif
  1243. Ref<InputEventKey> ie;
  1244. if (keycode != Key::NONE) {
  1245. ie = InputEventKey::create_reference(keycode);
  1246. events.push_back(ie);
  1247. }
  1248. }
  1249. if (!EditorSettings::get_singleton()) {
  1250. Ref<Shortcut> sc;
  1251. sc.instantiate();
  1252. sc->set_name(p_name);
  1253. sc->set_events(events);
  1254. sc->set_meta("original", events.duplicate(true));
  1255. return sc;
  1256. }
  1257. Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
  1258. if (sc.is_valid()) {
  1259. sc->set_name(p_name); //keep name (the ones that come from disk have no name)
  1260. sc->set_meta("original", events.duplicate(true)); //to compare against changes
  1261. return sc;
  1262. }
  1263. sc.instantiate();
  1264. sc->set_name(p_name);
  1265. sc->set_events(events);
  1266. sc->set_meta("original", events.duplicate(true)); //to compare against changes
  1267. EditorSettings::get_singleton()->add_shortcut(p_path, sc);
  1268. return sc;
  1269. }
  1270. void EditorSettings::set_builtin_action_override(const String &p_name, const TypedArray<InputEvent> &p_events) {
  1271. List<Ref<InputEvent>> event_list;
  1272. // Override the whole list, since events may have their order changed or be added, removed or edited.
  1273. InputMap::get_singleton()->action_erase_events(p_name);
  1274. for (int i = 0; i < p_events.size(); i++) {
  1275. event_list.push_back(p_events[i]);
  1276. InputMap::get_singleton()->action_add_event(p_name, p_events[i]);
  1277. }
  1278. // Check if the provided event array is same as built-in. If it is, it does not need to be added to the overrides.
  1279. // Note that event order must also be the same.
  1280. bool same_as_builtin = true;
  1281. HashMap<String, List<Ref<InputEvent>>>::ConstIterator builtin_default = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied().find(p_name);
  1282. if (builtin_default) {
  1283. const List<Ref<InputEvent>> &builtin_events = builtin_default->value;
  1284. // In the editor we only care about key events.
  1285. List<Ref<InputEventKey>> builtin_key_events;
  1286. for (Ref<InputEventKey> iek : builtin_events) {
  1287. if (iek.is_valid()) {
  1288. builtin_key_events.push_back(iek);
  1289. }
  1290. }
  1291. if (p_events.size() == builtin_key_events.size()) {
  1292. int event_idx = 0;
  1293. // Check equality of each event.
  1294. for (const Ref<InputEventKey> &E : builtin_key_events) {
  1295. if (!E->is_match(p_events[event_idx])) {
  1296. same_as_builtin = false;
  1297. break;
  1298. }
  1299. event_idx++;
  1300. }
  1301. } else {
  1302. same_as_builtin = false;
  1303. }
  1304. }
  1305. if (same_as_builtin && builtin_action_overrides.has(p_name)) {
  1306. builtin_action_overrides.erase(p_name);
  1307. } else {
  1308. builtin_action_overrides[p_name] = event_list;
  1309. }
  1310. // Update the shortcut (if it is used somewhere in the editor) to be the first event of the new list.
  1311. if (shortcuts.has(p_name)) {
  1312. shortcuts[p_name]->set_events_list(&event_list);
  1313. }
  1314. }
  1315. const Array EditorSettings::get_builtin_action_overrides(const String &p_name) const {
  1316. HashMap<String, List<Ref<InputEvent>>>::ConstIterator AO = builtin_action_overrides.find(p_name);
  1317. if (AO) {
  1318. Array event_array;
  1319. List<Ref<InputEvent>> events_list = AO->value;
  1320. for (const Ref<InputEvent> &E : events_list) {
  1321. event_array.push_back(E);
  1322. }
  1323. return event_array;
  1324. }
  1325. return Array();
  1326. }
  1327. void EditorSettings::notify_changes() {
  1328. _THREAD_SAFE_METHOD_
  1329. SceneTree *sml = Object::cast_to<SceneTree>(OS::get_singleton()->get_main_loop());
  1330. if (!sml) {
  1331. return;
  1332. }
  1333. Node *root = sml->get_root()->get_child(0);
  1334. if (!root) {
  1335. return;
  1336. }
  1337. root->propagate_notification(NOTIFICATION_EDITOR_SETTINGS_CHANGED);
  1338. }
  1339. void EditorSettings::_bind_methods() {
  1340. ClassDB::bind_method(D_METHOD("has_setting", "name"), &EditorSettings::has_setting);
  1341. ClassDB::bind_method(D_METHOD("set_setting", "name", "value"), &EditorSettings::set_setting);
  1342. ClassDB::bind_method(D_METHOD("get_setting", "name"), &EditorSettings::get_setting);
  1343. ClassDB::bind_method(D_METHOD("erase", "property"), &EditorSettings::erase);
  1344. ClassDB::bind_method(D_METHOD("set_initial_value", "name", "value", "update_current"), &EditorSettings::set_initial_value);
  1345. ClassDB::bind_method(D_METHOD("add_property_info", "info"), &EditorSettings::_add_property_info_bind);
  1346. ClassDB::bind_method(D_METHOD("set_project_metadata", "section", "key", "data"), &EditorSettings::set_project_metadata);
  1347. ClassDB::bind_method(D_METHOD("get_project_metadata", "section", "key", "default"), &EditorSettings::get_project_metadata, DEFVAL(Variant()));
  1348. ClassDB::bind_method(D_METHOD("set_favorites", "dirs"), &EditorSettings::set_favorites);
  1349. ClassDB::bind_method(D_METHOD("get_favorites"), &EditorSettings::get_favorites);
  1350. ClassDB::bind_method(D_METHOD("set_recent_dirs", "dirs"), &EditorSettings::set_recent_dirs);
  1351. ClassDB::bind_method(D_METHOD("get_recent_dirs"), &EditorSettings::get_recent_dirs);
  1352. ClassDB::bind_method(D_METHOD("set_builtin_action_override", "name", "actions_list"), &EditorSettings::set_builtin_action_override);
  1353. ClassDB::bind_method(D_METHOD("check_changed_settings_in_group", "setting_prefix"), &EditorSettings::check_changed_settings_in_group);
  1354. ClassDB::bind_method(D_METHOD("get_changed_settings"), &EditorSettings::get_changed_settings);
  1355. ClassDB::bind_method(D_METHOD("mark_setting_changed", "setting"), &EditorSettings::mark_setting_changed);
  1356. ADD_SIGNAL(MethodInfo("settings_changed"));
  1357. BIND_CONSTANT(NOTIFICATION_EDITOR_SETTINGS_CHANGED);
  1358. }
  1359. EditorSettings::EditorSettings() {
  1360. last_order = 0;
  1361. _load_defaults();
  1362. }
  1363. EditorSettings::~EditorSettings() {
  1364. }