editor_settings.cpp 63 KB

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