editor_settings.cpp 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109
  1. /**************************************************************************/
  2. /* editor_settings.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "editor_settings.h"
  31. #include "core/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_server.h"
  45. #include "core/version.h"
  46. #include "editor/editor_node.h"
  47. #include "editor/editor_paths.h"
  48. #include "editor/editor_property_name_processor.h"
  49. #include "editor/editor_translation.h"
  50. #include "editor/engine_update_label.h"
  51. #include "scene/gui/color_picker.h"
  52. #include "scene/main/node.h"
  53. #include "scene/main/scene_tree.h"
  54. #include "scene/main/window.h"
  55. // PRIVATE METHODS
  56. Ref<EditorSettings> EditorSettings::singleton = nullptr;
  57. // Properties
  58. bool EditorSettings::_set(const StringName &p_name, const Variant &p_value) {
  59. _THREAD_SAFE_METHOD_
  60. bool changed = _set_only(p_name, p_value);
  61. if (changed && initialized) {
  62. changed_settings.insert(p_name);
  63. emit_signal(SNAME("settings_changed"));
  64. }
  65. return true;
  66. }
  67. bool EditorSettings::_set_only(const StringName &p_name, const Variant &p_value) {
  68. _THREAD_SAFE_METHOD_
  69. if (p_name == "shortcuts") {
  70. Array arr = p_value;
  71. for (int i = 0; i < arr.size(); i++) {
  72. Dictionary dict = arr[i];
  73. String shortcut_name = dict["name"];
  74. Array shortcut_events = dict["shortcuts"];
  75. Ref<Shortcut> sc;
  76. sc.instantiate();
  77. sc->set_events(shortcut_events);
  78. add_shortcut(shortcut_name, sc);
  79. }
  80. return false;
  81. } else if (p_name == "builtin_action_overrides") {
  82. Array actions_arr = p_value;
  83. for (int i = 0; i < actions_arr.size(); i++) {
  84. Dictionary action_dict = actions_arr[i];
  85. String action_name = action_dict["name"];
  86. Array events = action_dict["events"];
  87. InputMap *im = InputMap::get_singleton();
  88. im->action_erase_events(action_name);
  89. builtin_action_overrides[action_name].clear();
  90. for (int ev_idx = 0; ev_idx < events.size(); ev_idx++) {
  91. im->action_add_event(action_name, events[ev_idx]);
  92. builtin_action_overrides[action_name].push_back(events[ev_idx]);
  93. }
  94. }
  95. return false;
  96. }
  97. bool changed = false;
  98. if (p_value.get_type() == Variant::NIL) {
  99. if (props.has(p_name)) {
  100. props.erase(p_name);
  101. changed = true;
  102. }
  103. } else {
  104. if (props.has(p_name)) {
  105. if (p_value != props[p_name].variant) {
  106. props[p_name].variant = p_value;
  107. changed = true;
  108. }
  109. } else {
  110. props[p_name] = VariantContainer(p_value, last_order++);
  111. changed = true;
  112. }
  113. if (save_changed_setting) {
  114. if (!props[p_name].save) {
  115. props[p_name].save = true;
  116. changed = true;
  117. }
  118. }
  119. }
  120. return changed;
  121. }
  122. bool EditorSettings::_get(const StringName &p_name, Variant &r_ret) const {
  123. _THREAD_SAFE_METHOD_
  124. if (p_name == "shortcuts") {
  125. Array save_array;
  126. const HashMap<String, List<Ref<InputEvent>>> &builtin_list = InputMap::get_singleton()->get_builtins();
  127. for (const KeyValue<String, Ref<Shortcut>> &shortcut_definition : shortcuts) {
  128. Ref<Shortcut> sc = shortcut_definition.value;
  129. if (builtin_list.has(shortcut_definition.key)) {
  130. // This shortcut was auto-generated from built in actions: don't save.
  131. // If the builtin is overridden, it will be saved in the "builtin_action_overrides" section below.
  132. continue;
  133. }
  134. Array shortcut_events = sc->get_events();
  135. Dictionary dict;
  136. dict["name"] = shortcut_definition.key;
  137. dict["shortcuts"] = shortcut_events;
  138. if (!sc->has_meta("original")) {
  139. // Getting the meta when it doesn't exist will return an empty array. If the 'shortcut_events' have been cleared,
  140. // we still want save the shortcut in this case so that shortcuts that the user has customized are not reset,
  141. // even if the 'original' has not been populated yet. This can happen when calling save() from the Project Manager.
  142. save_array.push_back(dict);
  143. continue;
  144. }
  145. Array original_events = sc->get_meta("original");
  146. bool is_same = Shortcut::is_event_array_equal(original_events, shortcut_events);
  147. if (is_same) {
  148. continue; // Not changed from default; don't save.
  149. }
  150. save_array.push_back(dict);
  151. }
  152. r_ret = save_array;
  153. return true;
  154. } else if (p_name == "builtin_action_overrides") {
  155. Array actions_arr;
  156. for (const KeyValue<String, List<Ref<InputEvent>>> &action_override : builtin_action_overrides) {
  157. List<Ref<InputEvent>> events = action_override.value;
  158. Dictionary action_dict;
  159. action_dict["name"] = action_override.key;
  160. // Convert the list to an array, and only keep key events as this is for the editor.
  161. Array events_arr;
  162. for (const Ref<InputEvent> &ie : events) {
  163. Ref<InputEventKey> iek = ie;
  164. if (iek.is_valid()) {
  165. events_arr.append(iek);
  166. }
  167. }
  168. Array defaults_arr;
  169. List<Ref<InputEvent>> defaults = InputMap::get_singleton()->get_builtins()[action_override.key];
  170. for (const Ref<InputEvent> &default_input_event : defaults) {
  171. if (default_input_event.is_valid()) {
  172. defaults_arr.append(default_input_event);
  173. }
  174. }
  175. bool same = Shortcut::is_event_array_equal(events_arr, defaults_arr);
  176. // Don't save if same as default.
  177. if (same) {
  178. continue;
  179. }
  180. action_dict["events"] = events_arr;
  181. actions_arr.push_back(action_dict);
  182. }
  183. r_ret = actions_arr;
  184. return true;
  185. }
  186. const VariantContainer *v = props.getptr(p_name);
  187. if (!v) {
  188. return false;
  189. }
  190. r_ret = v->variant;
  191. return true;
  192. }
  193. void EditorSettings::_initial_set(const StringName &p_name, const Variant &p_value, bool p_basic) {
  194. set(p_name, p_value);
  195. props[p_name].initial = p_value;
  196. props[p_name].has_default_value = true;
  197. props[p_name].basic = p_basic;
  198. }
  199. struct _EVCSort {
  200. String name;
  201. Variant::Type type = Variant::Type::NIL;
  202. int order = 0;
  203. bool basic = false;
  204. bool save = false;
  205. bool restart_if_changed = false;
  206. bool operator<(const _EVCSort &p_vcs) const { return order < p_vcs.order; }
  207. };
  208. void EditorSettings::_get_property_list(List<PropertyInfo> *p_list) const {
  209. _THREAD_SAFE_METHOD_
  210. RBSet<_EVCSort> vclist;
  211. for (const KeyValue<String, VariantContainer> &E : props) {
  212. const VariantContainer *v = &E.value;
  213. if (v->hide_from_editor) {
  214. continue;
  215. }
  216. _EVCSort vc;
  217. vc.name = E.key;
  218. vc.order = v->order;
  219. vc.type = v->variant.get_type();
  220. vc.basic = v->basic;
  221. vc.save = v->save;
  222. if (vc.save) {
  223. if (v->initial.get_type() != Variant::NIL && v->initial == v->variant) {
  224. vc.save = false;
  225. }
  226. }
  227. vc.restart_if_changed = v->restart_if_changed;
  228. vclist.insert(vc);
  229. }
  230. for (const _EVCSort &E : vclist) {
  231. uint32_t pusage = PROPERTY_USAGE_NONE;
  232. if (E.save || !optimize_save) {
  233. pusage |= PROPERTY_USAGE_STORAGE;
  234. }
  235. if (!E.name.begins_with("_") && !E.name.begins_with("projects/")) {
  236. pusage |= PROPERTY_USAGE_EDITOR;
  237. } else {
  238. pusage |= PROPERTY_USAGE_STORAGE; //hiddens must always be saved
  239. }
  240. PropertyInfo pi(E.type, E.name);
  241. pi.usage = pusage;
  242. if (hints.has(E.name)) {
  243. pi = hints[E.name];
  244. }
  245. if (E.basic) {
  246. pi.usage |= PROPERTY_USAGE_EDITOR_BASIC_SETTING;
  247. }
  248. if (E.restart_if_changed) {
  249. pi.usage |= PROPERTY_USAGE_RESTART_IF_CHANGED;
  250. }
  251. p_list->push_back(pi);
  252. }
  253. p_list->push_back(PropertyInfo(Variant::ARRAY, "shortcuts", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL)); //do not edit
  254. p_list->push_back(PropertyInfo(Variant::ARRAY, "builtin_action_overrides", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));
  255. }
  256. void EditorSettings::_add_property_info_bind(const Dictionary &p_info) {
  257. ERR_FAIL_COND(!p_info.has("name"));
  258. ERR_FAIL_COND(!p_info.has("type"));
  259. PropertyInfo pinfo;
  260. pinfo.name = p_info["name"];
  261. ERR_FAIL_COND(!props.has(pinfo.name));
  262. pinfo.type = Variant::Type(p_info["type"].operator int());
  263. ERR_FAIL_INDEX(pinfo.type, Variant::VARIANT_MAX);
  264. if (p_info.has("hint")) {
  265. pinfo.hint = PropertyHint(p_info["hint"].operator int());
  266. }
  267. if (p_info.has("hint_string")) {
  268. pinfo.hint_string = p_info["hint_string"];
  269. }
  270. add_property_hint(pinfo);
  271. }
  272. // Default configs
  273. bool EditorSettings::has_default_value(const String &p_setting) const {
  274. _THREAD_SAFE_METHOD_
  275. if (!props.has(p_setting)) {
  276. return false;
  277. }
  278. return props[p_setting].has_default_value;
  279. }
  280. void EditorSettings::_set_initialized() {
  281. initialized = true;
  282. }
  283. void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
  284. _THREAD_SAFE_METHOD_
  285. // Sets up the editor setting with a default value and hint PropertyInfo.
  286. #define EDITOR_SETTING(m_type, m_property_hint, m_name, m_default_value, m_hint_string) \
  287. _initial_set(m_name, m_default_value); \
  288. hints[m_name] = PropertyInfo(m_type, m_name, m_property_hint, m_hint_string);
  289. #define EDITOR_SETTING_BASIC(m_type, m_property_hint, m_name, m_default_value, m_hint_string) \
  290. _initial_set(m_name, m_default_value, true); \
  291. hints[m_name] = PropertyInfo(m_type, m_name, m_property_hint, m_hint_string);
  292. #define EDITOR_SETTING_USAGE(m_type, m_property_hint, m_name, m_default_value, m_hint_string, m_usage) \
  293. _initial_set(m_name, m_default_value); \
  294. hints[m_name] = PropertyInfo(m_type, m_name, m_property_hint, m_hint_string, m_usage);
  295. /* Languages */
  296. {
  297. String lang_hint = "en";
  298. String host_lang = OS::get_singleton()->get_locale();
  299. // Skip locales if Text server lack required features.
  300. Vector<String> locales_to_skip;
  301. if (!TS->has_feature(TextServer::FEATURE_BIDI_LAYOUT) || !TS->has_feature(TextServer::FEATURE_SHAPING)) {
  302. locales_to_skip.push_back("ar"); // Arabic
  303. locales_to_skip.push_back("fa"); // Persian
  304. locales_to_skip.push_back("ur"); // Urdu
  305. }
  306. if (!TS->has_feature(TextServer::FEATURE_BIDI_LAYOUT)) {
  307. locales_to_skip.push_back("he"); // Hebrew
  308. }
  309. if (!TS->has_feature(TextServer::FEATURE_SHAPING)) {
  310. locales_to_skip.push_back("bn"); // Bengali
  311. locales_to_skip.push_back("hi"); // Hindi
  312. locales_to_skip.push_back("ml"); // Malayalam
  313. locales_to_skip.push_back("si"); // Sinhala
  314. locales_to_skip.push_back("ta"); // Tamil
  315. locales_to_skip.push_back("te"); // Telugu
  316. }
  317. if (!locales_to_skip.is_empty()) {
  318. WARN_PRINT("Some locales are not properly supported by selected Text Server and are disabled.");
  319. }
  320. String best;
  321. int best_score = 0;
  322. for (const String &locale : get_editor_locales()) {
  323. // Skip locales which we can't render properly (see above comment).
  324. // Test against language code without regional variants (e.g. ur_PK).
  325. String lang_code = locale.get_slice("_", 0);
  326. if (locales_to_skip.has(lang_code)) {
  327. continue;
  328. }
  329. lang_hint += ",";
  330. lang_hint += locale;
  331. int score = TranslationServer::get_singleton()->compare_locales(host_lang, locale);
  332. if (score > 0 && score >= best_score) {
  333. best = locale;
  334. best_score = score;
  335. }
  336. }
  337. if (best_score == 0) {
  338. best = "en";
  339. }
  340. EDITOR_SETTING_USAGE(Variant::STRING, PROPERTY_HINT_ENUM, "interface/editor/editor_language", best, lang_hint, PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED | PROPERTY_USAGE_EDITOR_BASIC_SETTING);
  341. }
  342. // Asset library
  343. _initial_set("asset_library/use_threads", true);
  344. /* Interface */
  345. // Editor
  346. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/localize_settings", true, "")
  347. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/dock_tab_style", 0, "Text Only,Icon Only,Text and Icon")
  348. EDITOR_SETTING_USAGE(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/ui_layout_direction", 0, "Based on Application Locale,Left-to-Right,Right-to-Left,Based on System Locale", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  349. // Display what the Auto display scale setting effectively corresponds to.
  350. const String display_scale_hint_string = vformat("Auto (%d%%),75%%,100%%,125%%,150%%,175%%,200%%,Custom", Math::round(get_auto_display_scale() * 100));
  351. 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 | PROPERTY_USAGE_EDITOR_BASIC_SETTING)
  352. 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 | PROPERTY_USAGE_EDITOR_BASIC_SETTING)
  353. String ed_screen_hints = "Auto (Remembers last position):-5,Screen With Mouse Pointer:-4,Screen With Keyboard Focus:-3,Primary Screen:-2";
  354. for (int i = 0; i < DisplayServer::get_singleton()->get_screen_count(); i++) {
  355. ed_screen_hints += ",Screen " + itos(i + 1) + ":" + itos(i);
  356. }
  357. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/editor_screen", EditorSettings::InitialScreen::INITIAL_SCREEN_AUTO, ed_screen_hints)
  358. String project_manager_screen_hints = "Screen With Mouse Pointer:-4,Screen With Keyboard Focus:-3,Primary Screen:-2";
  359. for (int i = 0; i < DisplayServer::get_singleton()->get_screen_count(); i++) {
  360. project_manager_screen_hints += ",Screen " + itos(i + 1) + ":" + itos(i);
  361. }
  362. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/project_manager_screen", EditorSettings::InitialScreen::INITIAL_SCREEN_PRIMARY, project_manager_screen_hints)
  363. {
  364. EngineUpdateLabel::UpdateMode default_update_mode = EngineUpdateLabel::UpdateMode::NEWEST_UNSTABLE;
  365. if (String(VERSION_STATUS) == String("stable")) {
  366. default_update_mode = EngineUpdateLabel::UpdateMode::NEWEST_STABLE;
  367. }
  368. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "network/connection/engine_version_update_mode", int(default_update_mode), "Disable Update Checks,Check Newest Preview,Check Newest Stable,Check Newest Patch"); // Uses EngineUpdateLabel::UpdateMode.
  369. }
  370. EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/use_embedded_menu", false, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED | PROPERTY_USAGE_EDITOR_BASIC_SETTING)
  371. EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/use_native_file_dialogs", false, "", PROPERTY_USAGE_DEFAULT)
  372. EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/expand_to_title", true, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED | PROPERTY_USAGE_EDITOR_BASIC_SETTING)
  373. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_RANGE, "interface/editor/main_font_size", 14, "8,48,1")
  374. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_RANGE, "interface/editor/code_font_size", 14, "8,48,1")
  375. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/code_font_contextual_ligatures", 1, "Enabled,Disable Contextual Alternates (Coding Ligatures),Use Custom OpenType Feature Set")
  376. _initial_set("interface/editor/code_font_custom_opentype_features", "");
  377. _initial_set("interface/editor/code_font_custom_variations", "");
  378. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/font_antialiasing", 1, "None,Grayscale,LCD Subpixel")
  379. #ifdef MACOS_ENABLED
  380. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/font_hinting", 0, "Auto (None),None,Light,Normal")
  381. #else
  382. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/font_hinting", 0, "Auto (Light),None,Light,Normal")
  383. #endif
  384. 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")
  385. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/font_disable_embedded_bitmaps", true, "");
  386. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/font_allow_msdf", true, "")
  387. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "interface/editor/main_font", "", "*.ttf,*.otf,*.woff,*.woff2,*.pfb,*.pfm")
  388. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "interface/editor/main_font_bold", "", "*.ttf,*.otf,*.woff,*.woff2,*.pfb,*.pfm")
  389. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "interface/editor/code_font", "", "*.ttf,*.otf,*.woff,*.woff2,*.pfb,*.pfm")
  390. _initial_set("interface/editor/separate_distraction_mode", false, true);
  391. _initial_set("interface/editor/automatically_open_screenshots", true, true);
  392. EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/single_window_mode", false, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED | PROPERTY_USAGE_EDITOR_BASIC_SETTING)
  393. _initial_set("interface/editor/mouse_extra_buttons_navigate_history", true);
  394. _initial_set("interface/editor/save_each_scene_on_quit", true, true); // Regression
  395. EDITOR_SETTING_BASIC(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/save_on_focus_loss", false, "")
  396. EDITOR_SETTING_USAGE(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/accept_dialog_cancel_ok_buttons", 0,
  397. vformat("Auto (%s),Cancel First,OK First", DisplayServer::get_singleton()->get_swap_cancel_ok() ? "OK First" : "Cancel First"),
  398. PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
  399. #ifdef DEV_ENABLED
  400. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/show_internal_errors_in_toast_notifications", 0, "Auto (Enabled),Enabled,Disabled")
  401. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/show_update_spinner", 0, "Auto (Enabled),Enabled,Disabled")
  402. #else
  403. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/show_internal_errors_in_toast_notifications", 0, "Auto (Disabled),Enabled,Disabled")
  404. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/show_update_spinner", 0, "Auto (Disabled),Enabled,Disabled")
  405. #endif
  406. _initial_set("interface/editor/keep_screen_on", false, true);
  407. EDITOR_SETTING_USAGE(Variant::INT, PROPERTY_HINT_RANGE, "interface/editor/low_processor_mode_sleep_usec", 6900, "1,100000,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  408. // Default unfocused usec sleep is for 10 FPS. Allow an unfocused FPS limit
  409. // as low as 1 FPS for those who really need low power usage (but don't need
  410. // to preview particles or shaders while the editor is unfocused). With very
  411. // low FPS limits, the editor can take a small while to become usable after
  412. // being focused again, so this should be used at the user's discretion.
  413. EDITOR_SETTING_USAGE(Variant::INT, PROPERTY_HINT_RANGE, "interface/editor/unfocused_low_processor_mode_sleep_usec", 100000, "1,1000000,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  414. EDITOR_SETTING_BASIC(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/import_resources_when_unfocused", false, "")
  415. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/vsync_mode", 1, "Disabled,Enabled,Adaptive,Mailbox")
  416. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/update_continuously", false, "")
  417. _initial_set("interface/editors/show_scene_tree_root_selection", true);
  418. _initial_set("interface/editors/derive_script_globals_by_name", true);
  419. _initial_set("docks/scene_tree/ask_before_revoking_unique_name", true);
  420. // Inspector
  421. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_RANGE, "interface/inspector/max_array_dictionary_items_per_page", 20, "10,100,1")
  422. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/inspector/show_low_level_opentype_features", false, "")
  423. EDITOR_SETTING_BASIC(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/inspector/float_drag_speed", 5.0, "0.1,100,0.01")
  424. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "interface/inspector/nested_color_mode", 0, "Containers & Resources,Resources,External Resources")
  425. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/inspector/delimitate_all_container_and_resources", true, "")
  426. EDITOR_SETTING_USAGE(Variant::INT, PROPERTY_HINT_ENUM, "interface/inspector/default_property_name_style", EditorPropertyNameProcessor::STYLE_CAPITALIZED, "Raw (e.g. \"z_index\"),Capitalized (e.g. \"Z Index\"),Localized (e.g. \"Z Index\")", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
  427. // The lowest value is equal to the minimum float step for 32-bit floats.
  428. // The step must be set manually, as changing this setting should not change the step here.
  429. EDITOR_SETTING_USAGE(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/inspector/default_float_step", 0.001, "0.0000001,1,0.0000001", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED | PROPERTY_USAGE_EDITOR_BASIC_SETTING);
  430. EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/inspector/disable_folding", false, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
  431. EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/inspector/auto_unfold_foreign_scenes", true, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  432. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/inspector/horizontal_vector2_editing", false, "")
  433. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/inspector/horizontal_vector_types_editing", true, "")
  434. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/inspector/open_resources_in_current_inspector", true, "")
  435. PackedStringArray open_in_new_inspector_defaults;
  436. // Required for the script editor to work.
  437. open_in_new_inspector_defaults.push_back("Script");
  438. // Required for the GridMap editor to work.
  439. open_in_new_inspector_defaults.push_back("MeshLibrary");
  440. _initial_set("interface/inspector/resources_to_open_in_new_inspector", open_in_new_inspector_defaults);
  441. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "interface/inspector/default_color_picker_mode", (int32_t)ColorPicker::MODE_RGB, "RGB,HSV,RAW,OKHSL")
  442. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "interface/inspector/default_color_picker_shape", (int32_t)ColorPicker::SHAPE_OKHSL_CIRCLE, "HSV Rectangle,HSV Rectangle Wheel,VHS Circle,OKHSL Circle")
  443. // Theme
  444. EDITOR_SETTING_BASIC(Variant::BOOL, PROPERTY_HINT_ENUM, "interface/theme/follow_system_theme", false, "")
  445. EDITOR_SETTING_BASIC(Variant::STRING, PROPERTY_HINT_ENUM, "interface/theme/preset", "Default", "Default,Breeze Dark,Godot 2,Gray,Light,Solarized (Dark),Solarized (Light),Black (OLED),Custom")
  446. EDITOR_SETTING_BASIC(Variant::STRING, PROPERTY_HINT_ENUM, "interface/theme/spacing_preset", "Default", "Compact,Default,Spacious,Custom")
  447. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/theme/icon_and_font_color", 0, "Auto,Dark,Light")
  448. EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "interface/theme/base_color", Color(0.2, 0.23, 0.31), "")
  449. EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "interface/theme/accent_color", Color(0.41, 0.61, 0.91), "")
  450. EDITOR_SETTING_BASIC(Variant::BOOL, PROPERTY_HINT_NONE, "interface/theme/use_system_accent_color", false, "")
  451. EDITOR_SETTING_BASIC(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/theme/contrast", 0.3, "-1,1,0.01")
  452. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/theme/draw_extra_borders", false, "")
  453. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/theme/icon_saturation", 1.0, "0,2,0.01")
  454. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/theme/relationship_line_opacity", 0.1, "0.00,1,0.01")
  455. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/theme/border_size", 0, "0,2,1")
  456. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/theme/corner_radius", 3, "0,6,1")
  457. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/theme/base_spacing", 4, "0,8,1")
  458. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/theme/additional_spacing", 0, "0,8,1")
  459. EDITOR_SETTING_USAGE(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "interface/theme/custom_theme", "", "*.res,*.tres,*.theme", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  460. // Touchscreen
  461. bool has_touchscreen_ui = DisplayServer::get_singleton()->is_touchscreen_available();
  462. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/touchscreen/enable_pan_and_scale_gestures", has_touchscreen_ui, "")
  463. set_restart_if_changed("interface/touchscreen/enable_pan_and_scale_gestures", true);
  464. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/touchscreen/scale_gizmo_handles", has_touchscreen_ui ? 3 : 1, "1,5,1")
  465. set_restart_if_changed("interface/touchscreen/scale_gizmo_handles", true);
  466. // Disable some touchscreen settings by default for the XR Editor.
  467. bool is_native_touchscreen = has_touchscreen_ui && !OS::get_singleton()->has_feature("xr_editor");
  468. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/touchscreen/enable_long_press_as_right_click", is_native_touchscreen, "")
  469. set_restart_if_changed("interface/touchscreen/enable_long_press_as_right_click", true);
  470. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/touchscreen/increase_scrollbar_touch_area", is_native_touchscreen, "")
  471. set_restart_if_changed("interface/touchscreen/increase_scrollbar_touch_area", true);
  472. // Scene tabs
  473. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/scene_tabs/display_close_button", 1, "Never,If Tab Active,Always"); // TabBar::CloseButtonDisplayPolicy
  474. _initial_set("interface/scene_tabs/show_thumbnail_on_hover", true);
  475. EDITOR_SETTING_USAGE(Variant::INT, PROPERTY_HINT_RANGE, "interface/scene_tabs/maximum_width", 350, "0,9999,1", PROPERTY_USAGE_DEFAULT)
  476. _initial_set("interface/scene_tabs/show_script_button", false, true);
  477. _initial_set("interface/scene_tabs/restore_scenes_on_load", true, true);
  478. // Multi Window
  479. EDITOR_SETTING_BASIC(Variant::BOOL, PROPERTY_HINT_NONE, "interface/multi_window/enable", true, "");
  480. EDITOR_SETTING_BASIC(Variant::BOOL, PROPERTY_HINT_NONE, "interface/multi_window/restore_windows_on_load", true, "");
  481. EDITOR_SETTING_BASIC(Variant::BOOL, PROPERTY_HINT_NONE, "interface/multi_window/maximize_window", false, "");
  482. set_restart_if_changed("interface/multi_window/enable", true);
  483. /* Filesystem */
  484. // External Programs
  485. EDITOR_SETTING_BASIC(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "filesystem/external_programs/raster_image_editor", "", "")
  486. EDITOR_SETTING_BASIC(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "filesystem/external_programs/vector_image_editor", "", "")
  487. EDITOR_SETTING_BASIC(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "filesystem/external_programs/audio_editor", "", "")
  488. EDITOR_SETTING_BASIC(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "filesystem/external_programs/3d_model_editor", "", "")
  489. EDITOR_SETTING_BASIC(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "filesystem/external_programs/terminal_emulator", "", "")
  490. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_PLACEHOLDER_TEXT, "filesystem/external_programs/terminal_emulator_flags", "", "Call flags with placeholder: {directory}.");
  491. // Directories
  492. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_DIR, "filesystem/directories/autoscan_project_path", "", "")
  493. 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);
  494. EDITOR_SETTING_BASIC(Variant::STRING, PROPERTY_HINT_GLOBAL_DIR, "filesystem/directories/default_project_path", fs_dir_default_project_path, "")
  495. // On save
  496. _initial_set("filesystem/on_save/compress_binary_resources", true);
  497. _initial_set("filesystem/on_save/safe_save_on_backup_then_rename", true);
  498. // EditorFileServer
  499. _initial_set("filesystem/file_server/port", 6010);
  500. _initial_set("filesystem/file_server/password", "");
  501. // File dialog
  502. _initial_set("filesystem/file_dialog/show_hidden_files", false);
  503. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "filesystem/file_dialog/display_mode", 0, "Thumbnails,List")
  504. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "filesystem/file_dialog/thumbnail_size", 64, "32,128,16")
  505. // Quick Open dialog
  506. EDITOR_SETTING_USAGE(Variant::INT, PROPERTY_HINT_RANGE, "filesystem/quick_open_dialog/max_results", 100, "0,10000,1", PROPERTY_USAGE_DEFAULT)
  507. _initial_set("filesystem/quick_open_dialog/show_search_highlight", true);
  508. _initial_set("filesystem/quick_open_dialog/enable_fuzzy_matching", true);
  509. EDITOR_SETTING_USAGE(Variant::INT, PROPERTY_HINT_RANGE, "filesystem/quick_open_dialog/max_fuzzy_misses", 2, "0,10,1", PROPERTY_USAGE_DEFAULT)
  510. _initial_set("filesystem/quick_open_dialog/include_addons", false);
  511. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "filesystem/quick_open_dialog/default_display_mode", 0, "Adaptive,Last Used")
  512. // Import (for glft module)
  513. EDITOR_SETTING_USAGE(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "filesystem/import/blender/blender_path", "", "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED | PROPERTY_USAGE_EDITOR_BASIC_SETTING)
  514. EDITOR_SETTING_USAGE(Variant::INT, PROPERTY_HINT_RANGE, "filesystem/import/blender/rpc_port", 6011, "0,65535,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  515. EDITOR_SETTING_USAGE(Variant::FLOAT, PROPERTY_HINT_RANGE, "filesystem/import/blender/rpc_server_uptime", 5, "0,300,1,or_greater,suffix:s", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  516. EDITOR_SETTING_USAGE(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "filesystem/import/fbx/fbx2gltf_path", "", "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  517. // Tools (denoise)
  518. EDITOR_SETTING_USAGE(Variant::STRING, PROPERTY_HINT_GLOBAL_DIR, "filesystem/tools/oidn/oidn_denoise_path", "", "", PROPERTY_USAGE_DEFAULT)
  519. /* Docks */
  520. // SceneTree
  521. _initial_set("docks/scene_tree/ask_before_deleting_related_animation_tracks", true);
  522. _initial_set("docks/scene_tree/start_create_dialog_fully_expanded", false);
  523. _initial_set("docks/scene_tree/auto_expand_to_selected", true);
  524. _initial_set("docks/scene_tree/center_node_on_reparent", false);
  525. // FileSystem
  526. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "docks/filesystem/thumbnail_size", 64, "32,128,16")
  527. _initial_set("docks/filesystem/always_show_folders", true);
  528. _initial_set("docks/filesystem/textfile_extensions", "txt,md,cfg,ini,log,json,yml,yaml,toml,xml");
  529. _initial_set("docks/filesystem/other_file_extensions", "ico,icns");
  530. // Property editor
  531. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "docks/property_editor/auto_refresh_interval", 0.2, "0.01,1,0.001"); // Update 5 times per second by default.
  532. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "docks/property_editor/subresource_hue_tint", 0.75, "0,1,0.01")
  533. /* Text editor */
  534. // Theme
  535. _initial_set("text_editor/theme/line_spacing", 6);
  536. EDITOR_SETTING_BASIC(Variant::STRING, PROPERTY_HINT_ENUM, "text_editor/theme/color_theme", "Default", "Default,Godot 2,Custom")
  537. // Theme: Highlighting
  538. _load_godot2_text_editor_theme();
  539. // Appearance
  540. // Appearance: Caret
  541. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/appearance/caret/type", 0, "Line,Block")
  542. _initial_set("text_editor/appearance/caret/caret_blink", true, true);
  543. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "text_editor/appearance/caret/caret_blink_interval", 0.5, "0.1,10,0.01")
  544. _initial_set("text_editor/appearance/caret/highlight_current_line", true, true);
  545. _initial_set("text_editor/appearance/caret/highlight_all_occurrences", true, true);
  546. // Appearance: Guidelines
  547. _initial_set("text_editor/appearance/guidelines/show_line_length_guidelines", true, true);
  548. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/appearance/guidelines/line_length_guideline_soft_column", 80, "20,160,1")
  549. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/appearance/guidelines/line_length_guideline_hard_column", 100, "20,160,1")
  550. // Appearance: Gutters
  551. _initial_set("text_editor/appearance/gutters/show_line_numbers", true, true);
  552. _initial_set("text_editor/appearance/gutters/line_numbers_zero_padded", false, true);
  553. _initial_set("text_editor/appearance/gutters/highlight_type_safe_lines", true, true);
  554. _initial_set("text_editor/appearance/gutters/show_info_gutter", true, true);
  555. // Appearance: Minimap
  556. _initial_set("text_editor/appearance/minimap/show_minimap", true, true);
  557. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/appearance/minimap/minimap_width", 80, "50,250,1")
  558. // Appearance: Lines
  559. _initial_set("text_editor/appearance/lines/code_folding", true, true);
  560. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/appearance/lines/word_wrap", 0, "None,Boundary")
  561. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/appearance/lines/autowrap_mode", 3, "Arbitrary:1,Word:2,Word (Smart):3")
  562. // Appearance: Whitespace
  563. _initial_set("text_editor/appearance/whitespace/draw_tabs", true, true);
  564. _initial_set("text_editor/appearance/whitespace/draw_spaces", false, true);
  565. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/appearance/whitespace/line_spacing", 4, "0,50,1")
  566. // Behavior
  567. // Behavior: General
  568. _initial_set("text_editor/behavior/general/empty_selection_clipboard", true);
  569. // Behavior: Navigation
  570. _initial_set("text_editor/behavior/navigation/move_caret_on_right_click", true, true);
  571. _initial_set("text_editor/behavior/navigation/scroll_past_end_of_file", false, true);
  572. _initial_set("text_editor/behavior/navigation/smooth_scrolling", true, true);
  573. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/behavior/navigation/v_scroll_speed", 80, "1,10000,1")
  574. _initial_set("text_editor/behavior/navigation/drag_and_drop_selection", true, true);
  575. _initial_set("text_editor/behavior/navigation/stay_in_script_editor_on_node_selected", true, true);
  576. _initial_set("text_editor/behavior/navigation/open_script_when_connecting_signal_to_existing_method", true, true);
  577. _initial_set("text_editor/behavior/navigation/use_default_word_separators", true); // Includes ´`~$^=+|<> General punctuation and CJK punctuation.
  578. _initial_set("text_editor/behavior/navigation/use_custom_word_separators", false);
  579. _initial_set("text_editor/behavior/navigation/custom_word_separators", ""); // Custom word separators.
  580. // Behavior: Indent
  581. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/behavior/indent/type", 0, "Tabs,Spaces")
  582. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/behavior/indent/size", 4, "1,64,1") // size of 0 crashes.
  583. _initial_set("text_editor/behavior/indent/auto_indent", true);
  584. _initial_set("text_editor/behavior/indent/indent_wrapped_lines", true);
  585. // Behavior: Files
  586. _initial_set("text_editor/behavior/files/trim_trailing_whitespace_on_save", false);
  587. _initial_set("text_editor/behavior/files/trim_final_newlines_on_save", true);
  588. _initial_set("text_editor/behavior/files/autosave_interval_secs", 0);
  589. _initial_set("text_editor/behavior/files/restore_scripts_on_load", true);
  590. _initial_set("text_editor/behavior/files/convert_indent_on_save", true);
  591. _initial_set("text_editor/behavior/files/auto_reload_scripts_on_external_change", false);
  592. _initial_set("text_editor/behavior/files/auto_reload_and_parse_scripts_on_save", true);
  593. _initial_set("text_editor/behavior/files/open_dominant_script_on_scene_change", false, true);
  594. // Script list
  595. _initial_set("text_editor/script_list/show_members_overview", true, true);
  596. _initial_set("text_editor/script_list/sort_members_outline_alphabetically", false, true);
  597. _initial_set("text_editor/script_list/script_temperature_enabled", true);
  598. _initial_set("text_editor/script_list/script_temperature_history_size", 15);
  599. _initial_set("text_editor/script_list/highlight_scene_scripts", true);
  600. _initial_set("text_editor/script_list/group_help_pages", true);
  601. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/script_list/sort_scripts_by", 0, "Name,Path,None");
  602. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/script_list/list_script_names_as", 0, "Name,Parent Directory And Name,Full Path");
  603. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "text_editor/external/exec_path", "", "");
  604. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_PLACEHOLDER_TEXT, "text_editor/external/exec_flags", "{file}", "Call flags with placeholders: {project}, {file}, {col}, {line}.");
  605. // Completion
  606. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "text_editor/completion/idle_parse_delay", 1.5, "0.1,10,0.01")
  607. _initial_set("text_editor/completion/auto_brace_complete", true, true);
  608. _initial_set("text_editor/completion/code_complete_enabled", true, true);
  609. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "text_editor/completion/code_complete_delay", 0.3, "0.01,5,0.01,or_greater")
  610. _initial_set("text_editor/completion/put_callhint_tooltip_below_current_line", true);
  611. _initial_set("text_editor/completion/complete_file_paths", true);
  612. _initial_set("text_editor/completion/add_type_hints", true, true);
  613. _initial_set("text_editor/completion/add_string_name_literals", false, true);
  614. _initial_set("text_editor/completion/add_node_path_literals", false, true);
  615. _initial_set("text_editor/completion/use_single_quotes", false, true);
  616. _initial_set("text_editor/completion/colorize_suggestions", true);
  617. // External editor (ScriptEditorPlugin)
  618. _initial_set("text_editor/external/use_external_editor", false, true);
  619. _initial_set("text_editor/external/exec_path", "");
  620. // Help
  621. _initial_set("text_editor/help/show_help_index", true);
  622. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/help/help_font_size", 16, "8,48,1")
  623. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/help/help_source_font_size", 15, "8,48,1")
  624. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/help/help_title_font_size", 23, "8,64,1")
  625. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/help/class_reference_examples", 0, "GDScript,C#,GDScript and C#")
  626. _initial_set("text_editor/help/sort_functions_alphabetically", true);
  627. /* Editors */
  628. // GridMap
  629. // GridMapEditor
  630. _initial_set("editors/grid_map/pick_distance", 5000.0);
  631. _initial_set("editors/grid_map/palette_min_width", 230);
  632. set_restart_if_changed("editors/grid_map/palette_min_width", true);
  633. _initial_set("editors/grid_map/preview_size", 64);
  634. // GridMapEditorPlugin
  635. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/grid_map/editor_side", 1, "Left,Right");
  636. // 3D
  637. EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d/primary_grid_color", Color(0.56, 0.56, 0.56, 0.5), "")
  638. EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d/secondary_grid_color", Color(0.38, 0.38, 0.38, 0.5), "")
  639. // Use a similar color to the 2D editor selection.
  640. 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)
  641. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/instantiated", Color(0.7, 0.7, 0.7, 0.6), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  642. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/joint", Color(0.5, 0.8, 1), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  643. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/aabb", Color(0.28, 0.8, 0.82), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  644. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/stream_player_3d", Color(0.4, 0.8, 1), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  645. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/camera", Color(0.8, 0.4, 0.8), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  646. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/decal", Color(0.6, 0.5, 1.0), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  647. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/fog_volume", Color(0.5, 0.7, 1), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  648. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/particles", Color(0.8, 0.7, 0.4), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  649. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/particle_attractor", Color(1, 0.7, 0.5), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  650. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/particle_collision", Color(0.5, 0.7, 1), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  651. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/joint_body_a", Color(0.6, 0.8, 1), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  652. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/joint_body_b", Color(0.6, 0.9, 1), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  653. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/lightmap_lines", Color(0.5, 0.6, 1), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  654. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/lightprobe_lines", Color(0.5, 0.6, 1), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  655. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/occluder", Color(0.8, 0.5, 1), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  656. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/reflection_probe", Color(0.6, 1, 0.5), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  657. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/visibility_notifier", Color(0.8, 0.5, 0.7), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  658. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/voxel_gi", Color(0.5, 1, 0.6), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  659. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/path_tilt", Color(1.0, 1.0, 0.4, 0.9), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  660. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/skeleton", Color(1, 0.8, 0.4), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  661. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/selected_bone", Color(0.8, 0.3, 0.0), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  662. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/csg", Color(0.0, 0.4, 1, 0.15), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  663. _initial_set("editors/3d_gizmos/gizmo_settings/bone_axis_length", (float)0.1);
  664. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d_gizmos/gizmo_settings/bone_shape", 1, "Wire,Octahedron");
  665. EDITOR_SETTING_USAGE(Variant::FLOAT, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_settings/path3d_tilt_disk_size", 0.8, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  666. // If a line is a multiple of this, it uses the primary grid color.
  667. // Use a power of 2 value by default as it's more common to use powers of 2 in level design.
  668. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_RANGE, "editors/3d/primary_grid_steps", 8, "1,100,1")
  669. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_RANGE, "editors/3d/grid_size", 200, "1,2000,1")
  670. // Higher values produce graphical artifacts when far away unless View Z-Far
  671. // is increased significantly more than it really should need to be.
  672. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "editors/3d/grid_division_level_max", 2, "-1,3,1")
  673. // Lower values produce graphical artifacts regardless of view clipping planes, so limit to -2 as a lower bound.
  674. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "editors/3d/grid_division_level_min", 0, "-2,2,1")
  675. // -0.2 seems like a sensible default. -1.0 gives Blender-like behavior, 0.5 gives huge grids.
  676. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/grid_division_level_bias", -0.2, "-1.0,0.5,0.1")
  677. _initial_set("editors/3d/grid_xz_plane", true);
  678. _initial_set("editors/3d/grid_xy_plane", false);
  679. _initial_set("editors/3d/grid_yz_plane", false);
  680. // Use a lower default FOV for the 3D camera compared to the
  681. // Camera3D node as the 3D viewport doesn't span the whole screen.
  682. // This means it's technically viewed from a further distance, which warrants a narrower FOV.
  683. EDITOR_SETTING_BASIC(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/default_fov", 70.0, "1,179,0.1,degrees")
  684. EDITOR_SETTING_BASIC(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/default_z_near", 0.05, "0.01,10,0.01,or_greater,suffix:m")
  685. EDITOR_SETTING_BASIC(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/default_z_far", 4000.0, "0.1,4000,0.1,or_greater,suffix:m")
  686. // 3D: Navigation
  687. _initial_set("editors/3d/navigation/invert_x_axis", false, true);
  688. _initial_set("editors/3d/navigation/invert_y_axis", false, true);
  689. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/navigation_scheme", 0, "Godot,Maya,Modo,Custom")
  690. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/orbit_mouse_button", 1, "Left Mouse,Middle Mouse,Right Mouse")
  691. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/pan_mouse_button", 1, "Left Mouse,Middle Mouse,Right Mouse")
  692. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/zoom_mouse_button", 1, "Left Mouse,Middle Mouse,Right Mouse")
  693. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/zoom_style", 0, "Vertical,Horizontal")
  694. _initial_set("editors/3d/navigation/emulate_numpad", false, true);
  695. _initial_set("editors/3d/navigation/emulate_3_button_mouse", false, true);
  696. _initial_set("editors/3d/navigation/warped_mouse_panning", true, true);
  697. // 3D: Navigation feel
  698. EDITOR_SETTING_BASIC(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/navigation_feel/orbit_sensitivity", 0.25, "0.01,2,0.001")
  699. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/navigation_feel/orbit_inertia", 0.0, "0,1,0.001")
  700. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/navigation_feel/translation_inertia", 0.05, "0,1,0.001")
  701. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/navigation_feel/zoom_inertia", 0.05, "0,1,0.001")
  702. _initial_set("editors/3d/navigation/show_viewport_rotation_gizmo", true);
  703. _initial_set("editors/3d/navigation/show_viewport_navigation_gizmo", DisplayServer::get_singleton()->is_touchscreen_available());
  704. // 3D: Freelook
  705. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/freelook/freelook_navigation_scheme", 0, "Default,Partially Axis-Locked (id Tech),Fully Axis-Locked (Minecraft)")
  706. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/freelook/freelook_sensitivity", 0.25, "0.01,2,0.001")
  707. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/freelook/freelook_inertia", 0.0, "0,1,0.001")
  708. EDITOR_SETTING_BASIC(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/freelook/freelook_base_speed", 5.0, "0,10,0.01")
  709. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/freelook/freelook_activation_modifier", 0, "None,Shift,Alt,Meta,Ctrl")
  710. _initial_set("editors/3d/freelook/freelook_speed_zoom_link", false);
  711. // 3D: Manipulator
  712. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "editors/3d/manipulator_gizmo_size", 80, "16,160,1");
  713. EDITOR_SETTING_USAGE(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/manipulator_gizmo_opacity", 0.9, "0,1,0.01", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  714. // 2D
  715. _initial_set("editors/2d/grid_color", Color(1.0, 1.0, 1.0, 0.07), true);
  716. _initial_set("editors/2d/guides_color", Color(0.6, 0.0, 0.8), true);
  717. _initial_set("editors/2d/smart_snapping_line_color", Color(0.9, 0.1, 0.1), true);
  718. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/2d/bone_width", 5.0, "0.01,20,0.01,or_greater")
  719. _initial_set("editors/2d/bone_color1", Color(1.0, 1.0, 1.0, 0.7));
  720. _initial_set("editors/2d/bone_color2", Color(0.6, 0.6, 0.6, 0.7));
  721. _initial_set("editors/2d/bone_selected_color", Color(0.9, 0.45, 0.45, 0.7));
  722. _initial_set("editors/2d/bone_ik_color", Color(0.9, 0.9, 0.45, 0.7));
  723. _initial_set("editors/2d/bone_outline_color", Color(0.35, 0.35, 0.35, 0.5));
  724. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/2d/bone_outline_size", 2.0, "0.01,8,0.01,or_greater")
  725. _initial_set("editors/2d/viewport_border_color", Color(0.4, 0.4, 1.0, 0.4), true);
  726. _initial_set("editors/2d/use_integer_zoom_by_default", false, true);
  727. EDITOR_SETTING_BASIC(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/2d/zoom_speed_factor", 1.1, "1.01,2,0.01")
  728. // Bone mapper (BoneMapEditorPlugin)
  729. _initial_set("editors/bone_mapper/handle_colors/unset", Color(0.3, 0.3, 0.3));
  730. _initial_set("editors/bone_mapper/handle_colors/set", Color(0.1, 0.6, 0.25));
  731. _initial_set("editors/bone_mapper/handle_colors/missing", Color(0.8, 0.2, 0.8));
  732. _initial_set("editors/bone_mapper/handle_colors/error", Color(0.8, 0.2, 0.2));
  733. // Panning
  734. // Enum should be in sync with ControlScheme in ViewPanner.
  735. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "editors/panning/2d_editor_panning_scheme", 0, "Scroll Zooms,Scroll Pans");
  736. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "editors/panning/sub_editors_panning_scheme", 0, "Scroll Zooms,Scroll Pans");
  737. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "editors/panning/animation_editors_panning_scheme", 1, "Scroll Zooms,Scroll Pans");
  738. _initial_set("editors/panning/simple_panning", false);
  739. _initial_set("editors/panning/warped_mouse_panning", true);
  740. _initial_set("editors/panning/2d_editor_pan_speed", 20, true);
  741. // Tiles editor
  742. _initial_set("editors/tiles_editor/display_grid", true);
  743. _initial_set("editors/tiles_editor/highlight_selected_layer", true);
  744. _initial_set("editors/tiles_editor/grid_color", Color(1.0, 0.5, 0.2, 0.5));
  745. // Polygon editor
  746. _initial_set("editors/polygon_editor/point_grab_radius", has_touchscreen_ui ? 32 : 8);
  747. _initial_set("editors/polygon_editor/show_previous_outline", true);
  748. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/polygon_editor/auto_bake_delay", 1.5, "-1.0,10.0,0.01");
  749. // Animation
  750. _initial_set("editors/animation/autorename_animation_tracks", true);
  751. _initial_set("editors/animation/confirm_insert_track", true, true);
  752. _initial_set("editors/animation/default_create_bezier_tracks", false, true);
  753. _initial_set("editors/animation/default_create_reset_tracks", true, true);
  754. _initial_set("editors/animation/onion_layers_past_color", Color(1, 0, 0));
  755. _initial_set("editors/animation/onion_layers_future_color", Color(0, 1, 0));
  756. // Shader editor
  757. _initial_set("editors/shader_editor/behavior/files/restore_shaders_on_load", true, true);
  758. // Visual editors
  759. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_ENUM, "editors/visual_editors/color_theme", "Default", "Default,Legacy,Custom")
  760. _load_default_visual_shader_editor_theme();
  761. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/visual_editors/minimap_opacity", 0.85, "0.0,1.0,0.01")
  762. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/visual_editors/lines_curvature", 0.5, "0.0,1.0,0.01")
  763. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/visual_editors/grid_pattern", 1, "Lines,Dots")
  764. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "editors/visual_editors/visual_shader/port_preview_size", 160, "100,400,0.01")
  765. // Export (EditorExportPlugin)
  766. _initial_set("export/ssh/ssh", "");
  767. _initial_set("export/ssh/scp", "");
  768. /* Run */
  769. // Window placement
  770. #ifndef ANDROID_ENABLED
  771. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "run/window_placement/rect", 1, "Top Left,Centered,Custom Position,Force Maximized,Force Fullscreen")
  772. // Keep the enum values in sync with the `DisplayServer::SCREEN_` enum.
  773. String screen_hints = "Same as Editor:-5,Previous Screen:-4,Next Screen:-3,Primary Screen:-2"; // Note: Main Window Screen:-1 is not used for the main window.
  774. for (int i = 0; i < DisplayServer::get_singleton()->get_screen_count(); i++) {
  775. screen_hints += ",Screen " + itos(i + 1) + ":" + itos(i);
  776. }
  777. _initial_set("run/window_placement/rect_custom_position", Vector2());
  778. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "run/window_placement/screen", -5, screen_hints)
  779. #endif
  780. // Should match the ANDROID_WINDOW_* constants in 'platform/android/java/editor/src/main/java/org/godotengine/editor/GodotEditor.kt'
  781. String android_window_hints = "Auto (based on screen size):0,Same as Editor:1,Side-by-side with Editor:2,Launch in PiP mode:3";
  782. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "run/window_placement/android_window", 0, android_window_hints)
  783. int default_play_window_pip_mode = 0;
  784. #ifdef ANDROID_ENABLED
  785. default_play_window_pip_mode = 2;
  786. #endif
  787. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "run/window_placement/play_window_pip_mode", default_play_window_pip_mode, "Disabled:0,Enabled:1,Enabled when Play window is same as Editor:2")
  788. // Auto save
  789. _initial_set("run/auto_save/save_before_running", true, true);
  790. // Bottom panel
  791. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "run/bottom_panel/action_on_play", EditorNode::ACTION_ON_PLAY_OPEN_OUTPUT, "Do Nothing,Open Output,Open Debugger")
  792. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "run/bottom_panel/action_on_stop", EditorNode::ACTION_ON_STOP_DO_NOTHING, "Do Nothing,Close Bottom Panel")
  793. // Output
  794. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_RANGE, "run/output/font_size", 13, "8,48,1")
  795. _initial_set("run/output/always_clear_output_on_play", true, true);
  796. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "run/output/max_lines", 10000, "100,100000,1")
  797. // Platform
  798. _initial_set("run/platforms/linuxbsd/prefer_wayland", false, true);
  799. set_restart_if_changed("run/platforms/linuxbsd/prefer_wayland", true);
  800. /* Network */
  801. // General
  802. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "network/connection/network_mode", 0, "Offline,Online");
  803. // HTTP Proxy
  804. _initial_set("network/http_proxy/host", "");
  805. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "network/http_proxy/port", 8080, "1,65535,1")
  806. // SSL
  807. 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);
  808. // Debug
  809. _initial_set("network/debug/remote_host", "127.0.0.1"); // Hints provided in setup_network
  810. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "network/debug/remote_port", 6007, "1,65535,1")
  811. /* Debugger/profiler */
  812. EDITOR_SETTING_BASIC(Variant::BOOL, PROPERTY_HINT_NONE, "debugger/auto_switch_to_remote_scene_tree", false, "")
  813. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "debugger/profiler_frame_history_size", 3600, "60,10000,1")
  814. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "debugger/profiler_frame_max_functions", 64, "16,512,1")
  815. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "debugger/profiler_target_fps", 60, "1,1000,1")
  816. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "debugger/remote_scene_tree_refresh_interval", 1.0, "0.1,10,0.01,or_greater")
  817. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "debugger/remote_inspect_refresh_interval", 0.2, "0.02,10,0.01,or_greater")
  818. EDITOR_SETTING_BASIC(Variant::BOOL, PROPERTY_HINT_NONE, "debugger/profile_native_calls", false, "")
  819. // Version control (VersionControlEditorPlugin)
  820. _initial_set("version_control/username", "", true);
  821. _initial_set("version_control/ssh_public_key_path", "");
  822. _initial_set("version_control/ssh_private_key_path", "");
  823. /* Extra config */
  824. EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "input/buffering/agile_event_flushing", false, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED | PROPERTY_USAGE_EDITOR_BASIC_SETTING)
  825. EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "input/buffering/use_accumulated_input", true, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED | PROPERTY_USAGE_EDITOR_BASIC_SETTING)
  826. // TRANSLATORS: Project Manager here refers to the tool used to create/manage Godot projects.
  827. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "project_manager/sorting_order", 0, "Last Edited,Name,Path")
  828. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "project_manager/directory_naming_convention", 1, "No convention,kebab-case,snake_case,camelCase,PascalCase,Title Case")
  829. #if defined(WEB_ENABLED)
  830. // Web platform only supports `gl_compatibility`.
  831. const String default_renderer = "gl_compatibility";
  832. #elif defined(ANDROID_ENABLED)
  833. // Use more suitable rendering method by default.
  834. const String default_renderer = "mobile";
  835. #else
  836. const String default_renderer = "forward_plus";
  837. #endif
  838. EDITOR_SETTING_BASIC(Variant::STRING, PROPERTY_HINT_ENUM, "project_manager/default_renderer", default_renderer, "forward_plus,mobile,gl_compatibility")
  839. #undef EDITOR_SETTING
  840. #undef EDITOR_SETTING_BASIC
  841. #undef EDITOR_SETTING_USAGE
  842. if (p_extra_config.is_valid()) {
  843. if (p_extra_config->has_section("init_projects") && p_extra_config->has_section_key("init_projects", "list")) {
  844. Vector<String> list = p_extra_config->get_value("init_projects", "list");
  845. for (int i = 0; i < list.size(); i++) {
  846. String proj_name = list[i].replace("/", "::");
  847. set("projects/" + proj_name, list[i]);
  848. }
  849. }
  850. if (p_extra_config->has_section("presets")) {
  851. List<String> keys;
  852. p_extra_config->get_section_keys("presets", &keys);
  853. for (const String &key : keys) {
  854. Variant val = p_extra_config->get_value("presets", key);
  855. set(key, val);
  856. }
  857. }
  858. }
  859. }
  860. void EditorSettings::_load_godot2_text_editor_theme() {
  861. // Godot 2 is only a dark theme; it doesn't have a light theme counterpart.
  862. _initial_set("text_editor/theme/highlighting/symbol_color", Color(0.73, 0.87, 1.0), true);
  863. _initial_set("text_editor/theme/highlighting/keyword_color", Color(1.0, 1.0, 0.7), true);
  864. _initial_set("text_editor/theme/highlighting/control_flow_keyword_color", Color(1.0, 0.85, 0.7), true);
  865. _initial_set("text_editor/theme/highlighting/base_type_color", Color(0.64, 1.0, 0.83), true);
  866. _initial_set("text_editor/theme/highlighting/engine_type_color", Color(0.51, 0.83, 1.0), true);
  867. _initial_set("text_editor/theme/highlighting/user_type_color", Color(0.42, 0.67, 0.93), true);
  868. _initial_set("text_editor/theme/highlighting/comment_color", Color(0.4, 0.4, 0.4), true);
  869. _initial_set("text_editor/theme/highlighting/doc_comment_color", Color(0.5, 0.6, 0.7), true);
  870. _initial_set("text_editor/theme/highlighting/string_color", Color(0.94, 0.43, 0.75), true);
  871. _initial_set("text_editor/theme/highlighting/background_color", Color(0.13, 0.12, 0.15), true);
  872. _initial_set("text_editor/theme/highlighting/completion_background_color", Color(0.17, 0.16, 0.2));
  873. _initial_set("text_editor/theme/highlighting/completion_selected_color", Color(0.26, 0.26, 0.27));
  874. _initial_set("text_editor/theme/highlighting/completion_existing_color", Color(0.87, 0.87, 0.87, 0.13));
  875. _initial_set("text_editor/theme/highlighting/completion_scroll_color", Color(1, 1, 1, 0.29));
  876. _initial_set("text_editor/theme/highlighting/completion_scroll_hovered_color", Color(1, 1, 1, 0.4));
  877. _initial_set("text_editor/theme/highlighting/completion_font_color", Color(0.67, 0.67, 0.67));
  878. _initial_set("text_editor/theme/highlighting/text_color", Color(0.67, 0.67, 0.67), true);
  879. _initial_set("text_editor/theme/highlighting/line_number_color", Color(0.67, 0.67, 0.67, 0.4), true);
  880. _initial_set("text_editor/theme/highlighting/safe_line_number_color", Color(0.67, 0.78, 0.67, 0.6), true);
  881. _initial_set("text_editor/theme/highlighting/caret_color", Color(0.67, 0.67, 0.67), true);
  882. _initial_set("text_editor/theme/highlighting/caret_background_color", Color(0, 0, 0), true);
  883. _initial_set("text_editor/theme/highlighting/text_selected_color", Color(0, 0, 0, 0), true);
  884. _initial_set("text_editor/theme/highlighting/selection_color", Color(0.41, 0.61, 0.91, 0.35), true);
  885. _initial_set("text_editor/theme/highlighting/brace_mismatch_color", Color(1, 0.2, 0.2), true);
  886. _initial_set("text_editor/theme/highlighting/current_line_color", Color(0.3, 0.5, 0.8, 0.15), true);
  887. _initial_set("text_editor/theme/highlighting/line_length_guideline_color", Color(0.3, 0.5, 0.8, 0.1), true);
  888. _initial_set("text_editor/theme/highlighting/word_highlighted_color", Color(0.8, 0.9, 0.9, 0.15), true);
  889. _initial_set("text_editor/theme/highlighting/number_color", Color(0.92, 0.58, 0.2), true);
  890. _initial_set("text_editor/theme/highlighting/function_color", Color(0.4, 0.64, 0.81), true);
  891. _initial_set("text_editor/theme/highlighting/member_variable_color", Color(0.9, 0.31, 0.35), true);
  892. _initial_set("text_editor/theme/highlighting/mark_color", Color(1.0, 0.4, 0.4, 0.4), true);
  893. _initial_set("text_editor/theme/highlighting/bookmark_color", Color(0.08, 0.49, 0.98));
  894. _initial_set("text_editor/theme/highlighting/breakpoint_color", Color(0.9, 0.29, 0.3));
  895. _initial_set("text_editor/theme/highlighting/executing_line_color", Color(0.98, 0.89, 0.27));
  896. _initial_set("text_editor/theme/highlighting/code_folding_color", Color(0.8, 0.8, 0.8, 0.8));
  897. _initial_set("text_editor/theme/highlighting/folded_code_region_color", Color(0.68, 0.46, 0.77, 0.2));
  898. _initial_set("text_editor/theme/highlighting/search_result_color", Color(0.05, 0.25, 0.05, 1));
  899. _initial_set("text_editor/theme/highlighting/search_result_border_color", Color(0.41, 0.61, 0.91, 0.38));
  900. }
  901. void EditorSettings::_load_default_visual_shader_editor_theme() {
  902. // Connection type colors
  903. _initial_set("editors/visual_editors/connection_colors/scalar_color", Color(0.55, 0.55, 0.55));
  904. _initial_set("editors/visual_editors/connection_colors/vector2_color", Color(0.44, 0.43, 0.64));
  905. _initial_set("editors/visual_editors/connection_colors/vector3_color", Color(0.337, 0.314, 0.71));
  906. _initial_set("editors/visual_editors/connection_colors/vector4_color", Color(0.7, 0.65, 0.147));
  907. _initial_set("editors/visual_editors/connection_colors/boolean_color", Color(0.243, 0.612, 0.349));
  908. _initial_set("editors/visual_editors/connection_colors/transform_color", Color(0.71, 0.357, 0.64));
  909. _initial_set("editors/visual_editors/connection_colors/sampler_color", Color(0.659, 0.4, 0.137));
  910. // Node category colors (used for the node headers)
  911. _initial_set("editors/visual_editors/category_colors/output_color", Color(0.26, 0.10, 0.15));
  912. _initial_set("editors/visual_editors/category_colors/color_color", Color(0.5, 0.5, 0.1));
  913. _initial_set("editors/visual_editors/category_colors/conditional_color", Color(0.208, 0.522, 0.298));
  914. _initial_set("editors/visual_editors/category_colors/input_color", Color(0.502, 0.2, 0.204));
  915. _initial_set("editors/visual_editors/category_colors/scalar_color", Color(0.1, 0.5, 0.6));
  916. _initial_set("editors/visual_editors/category_colors/textures_color", Color(0.5, 0.3, 0.1));
  917. _initial_set("editors/visual_editors/category_colors/transform_color", Color(0.5, 0.3, 0.5));
  918. _initial_set("editors/visual_editors/category_colors/utility_color", Color(0.2, 0.2, 0.2));
  919. _initial_set("editors/visual_editors/category_colors/vector_color", Color(0.2, 0.2, 0.5));
  920. _initial_set("editors/visual_editors/category_colors/special_color", Color(0.098, 0.361, 0.294));
  921. _initial_set("editors/visual_editors/category_colors/particle_color", Color(0.12, 0.358, 0.8));
  922. }
  923. bool EditorSettings::_save_text_editor_theme(const String &p_file) {
  924. String theme_section = "color_theme";
  925. Ref<ConfigFile> cf = memnew(ConfigFile); // hex is better?
  926. List<String> keys;
  927. for (const KeyValue<String, VariantContainer> &E : props) {
  928. keys.push_back(E.key);
  929. }
  930. keys.sort();
  931. for (const String &key : keys) {
  932. if (key.begins_with("text_editor/theme/highlighting/") && key.contains("color")) {
  933. cf->set_value(theme_section, key.replace("text_editor/theme/highlighting/", ""), ((Color)props[key].variant).to_html());
  934. }
  935. }
  936. Error err = cf->save(p_file);
  937. return err == OK;
  938. }
  939. bool EditorSettings::_is_default_text_editor_theme(const String &p_theme_name) {
  940. return p_theme_name == "default" || p_theme_name == "godot 2" || p_theme_name == "custom";
  941. }
  942. const String EditorSettings::_get_project_metadata_path() const {
  943. return EditorPaths::get_singleton()->get_project_settings_dir().path_join("project_metadata.cfg");
  944. }
  945. #ifndef DISABLE_DEPRECATED
  946. void EditorSettings::_remove_deprecated_settings() {
  947. erase("run/output/always_open_output_on_play");
  948. erase("run/output/always_close_output_on_stop");
  949. }
  950. #endif
  951. // PUBLIC METHODS
  952. EditorSettings *EditorSettings::get_singleton() {
  953. return singleton.ptr();
  954. }
  955. String EditorSettings::get_existing_settings_path() {
  956. const String config_dir = EditorPaths::get_singleton()->get_config_dir();
  957. int minor = VERSION_MINOR;
  958. String filename;
  959. do {
  960. if (VERSION_MAJOR == 4 && minor < 3) {
  961. // Minor version is used since 4.3, so special case to load older settings.
  962. filename = vformat("editor_settings-%d.tres", VERSION_MAJOR);
  963. minor = -1;
  964. } else {
  965. filename = vformat("editor_settings-%d.%d.tres", VERSION_MAJOR, minor);
  966. minor--;
  967. }
  968. } while (minor >= 0 && !FileAccess::exists(config_dir.path_join(filename)));
  969. return config_dir.path_join(filename);
  970. }
  971. String EditorSettings::get_newest_settings_path() {
  972. const String config_file_name = vformat("editor_settings-%d.%d.tres", VERSION_MAJOR, VERSION_MINOR);
  973. return EditorPaths::get_singleton()->get_config_dir().path_join(config_file_name);
  974. }
  975. void EditorSettings::create() {
  976. // IMPORTANT: create() *must* create a valid EditorSettings singleton,
  977. // as the rest of the engine code will assume it. As such, it should never
  978. // return (incl. via ERR_FAIL) without initializing the singleton member.
  979. if (singleton.ptr()) {
  980. ERR_PRINT("Can't recreate EditorSettings as it already exists.");
  981. return;
  982. }
  983. String config_file_path;
  984. Ref<ConfigFile> extra_config = memnew(ConfigFile);
  985. if (!EditorPaths::get_singleton()) {
  986. ERR_PRINT("Bug (please report): EditorPaths haven't been initialized, EditorSettings cannot be created properly.");
  987. goto fail;
  988. }
  989. if (EditorPaths::get_singleton()->is_self_contained()) {
  990. Error err = extra_config->load(EditorPaths::get_singleton()->get_self_contained_file());
  991. if (err != OK) {
  992. ERR_PRINT("Can't load extra config from path: " + EditorPaths::get_singleton()->get_self_contained_file());
  993. }
  994. }
  995. if (EditorPaths::get_singleton()->are_paths_valid()) {
  996. // Validate editor config file.
  997. ERR_FAIL_COND(!DirAccess::dir_exists_absolute(EditorPaths::get_singleton()->get_config_dir()));
  998. config_file_path = get_existing_settings_path();
  999. if (!FileAccess::exists(config_file_path)) {
  1000. config_file_path = get_newest_settings_path();
  1001. goto fail;
  1002. }
  1003. singleton = ResourceLoader::load(config_file_path, "EditorSettings");
  1004. if (singleton.is_null()) {
  1005. ERR_PRINT("Could not load editor settings from path: " + config_file_path);
  1006. config_file_path = get_newest_settings_path();
  1007. goto fail;
  1008. }
  1009. singleton->set_path(get_newest_settings_path()); // Settings can be loaded from older version file, so make sure it's newest.
  1010. singleton->save_changed_setting = true;
  1011. print_verbose("EditorSettings: Load OK!");
  1012. singleton->setup_language();
  1013. singleton->setup_network();
  1014. singleton->load_favorites_and_recent_dirs();
  1015. singleton->list_text_editor_themes();
  1016. #ifndef DISABLE_DEPRECATED
  1017. singleton->_remove_deprecated_settings();
  1018. #endif
  1019. return;
  1020. }
  1021. fail:
  1022. // patch init projects
  1023. String exe_path = OS::get_singleton()->get_executable_path().get_base_dir();
  1024. if (extra_config->has_section("init_projects")) {
  1025. Vector<String> list = extra_config->get_value("init_projects", "list");
  1026. for (int i = 0; i < list.size(); i++) {
  1027. list.write[i] = exe_path.path_join(list[i]);
  1028. }
  1029. extra_config->set_value("init_projects", "list", list);
  1030. }
  1031. singleton.instantiate();
  1032. singleton->set_path(config_file_path, true);
  1033. singleton->save_changed_setting = true;
  1034. singleton->_load_defaults(extra_config);
  1035. singleton->setup_language();
  1036. singleton->setup_network();
  1037. singleton->list_text_editor_themes();
  1038. }
  1039. void EditorSettings::setup_language() {
  1040. String lang = get("interface/editor/editor_language");
  1041. TranslationServer::get_singleton()->set_locale(lang);
  1042. if (lang == "en") {
  1043. return; // Default, nothing to do.
  1044. }
  1045. // Load editor translation for configured/detected locale.
  1046. load_editor_translations(lang);
  1047. load_property_translations(lang);
  1048. // Load class reference translation.
  1049. load_doc_translations(lang);
  1050. // Load extractable translation for projects.
  1051. load_extractable_translations(lang);
  1052. }
  1053. void EditorSettings::setup_network() {
  1054. List<IPAddress> local_ip;
  1055. IP::get_singleton()->get_local_addresses(&local_ip);
  1056. String hint;
  1057. String current = has_setting("network/debug/remote_host") ? get("network/debug/remote_host") : "";
  1058. String selected = "127.0.0.1";
  1059. // Check that current remote_host is a valid interface address and populate hints.
  1060. for (const IPAddress &ip : local_ip) {
  1061. // link-local IPv6 addresses don't work, skipping them
  1062. if (String(ip).begins_with("fe80:0:0:0:")) { // fe80::/64
  1063. continue;
  1064. }
  1065. // Same goes for IPv4 link-local (APIPA) addresses.
  1066. if (String(ip).begins_with("169.254.")) { // 169.254.0.0/16
  1067. continue;
  1068. }
  1069. // Select current IP (found)
  1070. if (ip == current) {
  1071. selected = ip;
  1072. }
  1073. if (!hint.is_empty()) {
  1074. hint += ",";
  1075. }
  1076. hint += ip;
  1077. }
  1078. // Add hints with valid IP addresses to remote_host property.
  1079. add_property_hint(PropertyInfo(Variant::STRING, "network/debug/remote_host", PROPERTY_HINT_ENUM, hint));
  1080. // Fix potentially invalid remote_host due to network change.
  1081. set("network/debug/remote_host", selected);
  1082. }
  1083. void EditorSettings::save() {
  1084. //_THREAD_SAFE_METHOD_
  1085. if (!singleton.ptr()) {
  1086. return;
  1087. }
  1088. Error err = ResourceSaver::save(singleton);
  1089. if (err != OK) {
  1090. ERR_PRINT("Error saving editor settings to " + singleton->get_path());
  1091. } else {
  1092. singleton->changed_settings.clear();
  1093. print_verbose("EditorSettings: Save OK!");
  1094. }
  1095. }
  1096. PackedStringArray EditorSettings::get_changed_settings() const {
  1097. PackedStringArray arr;
  1098. for (const String &setting : changed_settings) {
  1099. arr.push_back(setting);
  1100. }
  1101. return arr;
  1102. }
  1103. bool EditorSettings::check_changed_settings_in_group(const String &p_setting_prefix) const {
  1104. for (const String &setting : changed_settings) {
  1105. if (setting.begins_with(p_setting_prefix)) {
  1106. return true;
  1107. }
  1108. }
  1109. return false;
  1110. }
  1111. void EditorSettings::mark_setting_changed(const String &p_setting) {
  1112. changed_settings.insert(p_setting);
  1113. }
  1114. void EditorSettings::destroy() {
  1115. if (!singleton.ptr()) {
  1116. return;
  1117. }
  1118. save();
  1119. singleton = Ref<EditorSettings>();
  1120. }
  1121. void EditorSettings::set_optimize_save(bool p_optimize) {
  1122. optimize_save = p_optimize;
  1123. }
  1124. // Properties
  1125. void EditorSettings::set_setting(const String &p_setting, const Variant &p_value) {
  1126. _THREAD_SAFE_METHOD_
  1127. set(p_setting, p_value);
  1128. }
  1129. Variant EditorSettings::get_setting(const String &p_setting) const {
  1130. _THREAD_SAFE_METHOD_
  1131. return get(p_setting);
  1132. }
  1133. bool EditorSettings::has_setting(const String &p_setting) const {
  1134. _THREAD_SAFE_METHOD_
  1135. return props.has(p_setting);
  1136. }
  1137. void EditorSettings::erase(const String &p_setting) {
  1138. _THREAD_SAFE_METHOD_
  1139. props.erase(p_setting);
  1140. }
  1141. void EditorSettings::raise_order(const String &p_setting) {
  1142. _THREAD_SAFE_METHOD_
  1143. ERR_FAIL_COND(!props.has(p_setting));
  1144. props[p_setting].order = ++last_order;
  1145. }
  1146. void EditorSettings::set_restart_if_changed(const StringName &p_setting, bool p_restart) {
  1147. _THREAD_SAFE_METHOD_
  1148. if (!props.has(p_setting)) {
  1149. return;
  1150. }
  1151. props[p_setting].restart_if_changed = p_restart;
  1152. }
  1153. void EditorSettings::set_basic(const StringName &p_setting, bool p_basic) {
  1154. _THREAD_SAFE_METHOD_
  1155. if (!props.has(p_setting)) {
  1156. return;
  1157. }
  1158. props[p_setting].basic = p_basic;
  1159. }
  1160. void EditorSettings::set_initial_value(const StringName &p_setting, const Variant &p_value, bool p_update_current) {
  1161. _THREAD_SAFE_METHOD_
  1162. if (!props.has(p_setting)) {
  1163. return;
  1164. }
  1165. props[p_setting].initial = p_value;
  1166. props[p_setting].has_default_value = true;
  1167. if (p_update_current) {
  1168. set(p_setting, p_value);
  1169. }
  1170. }
  1171. Variant _EDITOR_DEF(const String &p_setting, const Variant &p_default, bool p_restart_if_changed, bool p_basic) {
  1172. ERR_FAIL_NULL_V_MSG(EditorSettings::get_singleton(), p_default, "EditorSettings not instantiated yet.");
  1173. Variant ret = p_default;
  1174. if (EditorSettings::get_singleton()->has_setting(p_setting)) {
  1175. ret = EDITOR_GET(p_setting);
  1176. } else {
  1177. EditorSettings::get_singleton()->set_manually(p_setting, p_default);
  1178. }
  1179. EditorSettings::get_singleton()->set_restart_if_changed(p_setting, p_restart_if_changed);
  1180. EditorSettings::get_singleton()->set_basic(p_setting, p_basic);
  1181. if (!EditorSettings::get_singleton()->has_default_value(p_setting)) {
  1182. EditorSettings::get_singleton()->set_initial_value(p_setting, p_default);
  1183. }
  1184. return ret;
  1185. }
  1186. Variant _EDITOR_GET(const String &p_setting) {
  1187. ERR_FAIL_COND_V(!EditorSettings::get_singleton() || !EditorSettings::get_singleton()->has_setting(p_setting), Variant());
  1188. return EditorSettings::get_singleton()->get(p_setting);
  1189. }
  1190. bool EditorSettings::_property_can_revert(const StringName &p_name) const {
  1191. const VariantContainer *property = props.getptr(p_name);
  1192. if (property) {
  1193. return property->has_default_value;
  1194. }
  1195. return false;
  1196. }
  1197. bool EditorSettings::_property_get_revert(const StringName &p_name, Variant &r_property) const {
  1198. const VariantContainer *value = props.getptr(p_name);
  1199. if (value && value->has_default_value) {
  1200. r_property = value->initial;
  1201. return true;
  1202. }
  1203. return false;
  1204. }
  1205. void EditorSettings::add_property_hint(const PropertyInfo &p_hint) {
  1206. _THREAD_SAFE_METHOD_
  1207. hints[p_hint.name] = p_hint;
  1208. }
  1209. // Metadata
  1210. void EditorSettings::set_project_metadata(const String &p_section, const String &p_key, const Variant &p_data) {
  1211. const String path = _get_project_metadata_path();
  1212. if (project_metadata.is_null()) {
  1213. project_metadata.instantiate();
  1214. Error err = project_metadata->load(path);
  1215. if (err != OK && err != ERR_FILE_NOT_FOUND) {
  1216. ERR_PRINT("Cannot load project metadata from file '" + path + "'.");
  1217. }
  1218. }
  1219. project_metadata->set_value(p_section, p_key, p_data);
  1220. Error err = project_metadata->save(path);
  1221. ERR_FAIL_COND_MSG(err != OK, "Cannot save project metadata to file '" + path + "'.");
  1222. }
  1223. Variant EditorSettings::get_project_metadata(const String &p_section, const String &p_key, const Variant &p_default) const {
  1224. if (project_metadata.is_null()) {
  1225. project_metadata.instantiate();
  1226. const String path = _get_project_metadata_path();
  1227. Error err = project_metadata->load(path);
  1228. ERR_FAIL_COND_V_MSG(err != OK && err != ERR_FILE_NOT_FOUND, p_default, "Cannot load project metadata from file '" + path + "'.");
  1229. }
  1230. return project_metadata->get_value(p_section, p_key, p_default);
  1231. }
  1232. void EditorSettings::set_favorites(const Vector<String> &p_favorites) {
  1233. favorites = p_favorites;
  1234. String favorites_file;
  1235. if (Engine::get_singleton()->is_project_manager_hint()) {
  1236. favorites_file = EditorPaths::get_singleton()->get_config_dir().path_join("favorite_dirs");
  1237. } else {
  1238. favorites_file = EditorPaths::get_singleton()->get_project_settings_dir().path_join("favorites");
  1239. }
  1240. Ref<FileAccess> f = FileAccess::open(favorites_file, FileAccess::WRITE);
  1241. if (f.is_valid()) {
  1242. for (int i = 0; i < favorites.size(); i++) {
  1243. f->store_line(favorites[i]);
  1244. }
  1245. }
  1246. }
  1247. void EditorSettings::set_favorite_properties(const HashMap<String, PackedStringArray> &p_favorite_properties) {
  1248. favorite_properties = p_favorite_properties;
  1249. String favorite_properties_file = EditorPaths::get_singleton()->get_project_settings_dir().path_join("favorite_properties");
  1250. Ref<ConfigFile> cf;
  1251. cf.instantiate();
  1252. for (const KeyValue<String, PackedStringArray> &kv : p_favorite_properties) {
  1253. cf->set_value(kv.key, "properties", kv.value);
  1254. }
  1255. cf->save(favorite_properties_file);
  1256. }
  1257. Vector<String> EditorSettings::get_favorites() const {
  1258. return favorites;
  1259. }
  1260. HashMap<String, PackedStringArray> EditorSettings::get_favorite_properties() const {
  1261. return favorite_properties;
  1262. }
  1263. void EditorSettings::set_recent_dirs(const Vector<String> &p_recent_dirs) {
  1264. recent_dirs = p_recent_dirs;
  1265. String recent_dirs_file;
  1266. if (Engine::get_singleton()->is_project_manager_hint()) {
  1267. recent_dirs_file = EditorPaths::get_singleton()->get_config_dir().path_join("recent_dirs");
  1268. } else {
  1269. recent_dirs_file = EditorPaths::get_singleton()->get_project_settings_dir().path_join("recent_dirs");
  1270. }
  1271. Ref<FileAccess> f = FileAccess::open(recent_dirs_file, FileAccess::WRITE);
  1272. if (f.is_valid()) {
  1273. for (int i = 0; i < recent_dirs.size(); i++) {
  1274. f->store_line(recent_dirs[i]);
  1275. }
  1276. }
  1277. }
  1278. Vector<String> EditorSettings::get_recent_dirs() const {
  1279. return recent_dirs;
  1280. }
  1281. void EditorSettings::load_favorites_and_recent_dirs() {
  1282. String favorites_file;
  1283. String favorite_properties_file;
  1284. String recent_dirs_file;
  1285. if (Engine::get_singleton()->is_project_manager_hint()) {
  1286. favorites_file = EditorPaths::get_singleton()->get_config_dir().path_join("favorite_dirs");
  1287. favorite_properties_file = EditorPaths::get_singleton()->get_config_dir().path_join("favorite_properties");
  1288. recent_dirs_file = EditorPaths::get_singleton()->get_config_dir().path_join("recent_dirs");
  1289. } else {
  1290. favorites_file = EditorPaths::get_singleton()->get_project_settings_dir().path_join("favorites");
  1291. favorite_properties_file = EditorPaths::get_singleton()->get_project_settings_dir().path_join("favorite_properties");
  1292. recent_dirs_file = EditorPaths::get_singleton()->get_project_settings_dir().path_join("recent_dirs");
  1293. }
  1294. /// File Favorites
  1295. Ref<FileAccess> f = FileAccess::open(favorites_file, FileAccess::READ);
  1296. if (f.is_valid()) {
  1297. String line = f->get_line().strip_edges();
  1298. while (!line.is_empty()) {
  1299. favorites.append(line);
  1300. line = f->get_line().strip_edges();
  1301. }
  1302. }
  1303. /// Inspector Favorites
  1304. Ref<ConfigFile> cf;
  1305. cf.instantiate();
  1306. if (cf->load(favorite_properties_file) == OK) {
  1307. List<String> secs;
  1308. cf->get_sections(&secs);
  1309. for (String &E : secs) {
  1310. PackedStringArray properties = PackedStringArray(cf->get_value(E, "properties"));
  1311. if (EditorNode::get_editor_data().is_type_recognized(E) || ResourceLoader::exists(E, "Script")) {
  1312. for (const String &property : properties) {
  1313. if (!favorite_properties[E].has(property)) {
  1314. favorite_properties[E].push_back(property);
  1315. }
  1316. }
  1317. }
  1318. }
  1319. }
  1320. /// Recent Directories
  1321. f = FileAccess::open(recent_dirs_file, FileAccess::READ);
  1322. if (f.is_valid()) {
  1323. String line = f->get_line().strip_edges();
  1324. while (!line.is_empty()) {
  1325. recent_dirs.push_back(line);
  1326. line = f->get_line().strip_edges();
  1327. }
  1328. }
  1329. }
  1330. void EditorSettings::list_text_editor_themes() {
  1331. String themes = "Default,Godot 2,Custom";
  1332. Ref<DirAccess> d = DirAccess::open(EditorPaths::get_singleton()->get_text_editor_themes_dir());
  1333. if (d.is_valid()) {
  1334. List<String> custom_themes;
  1335. d->list_dir_begin();
  1336. String file = d->get_next();
  1337. while (!file.is_empty()) {
  1338. if (file.get_extension() == "tet" && !_is_default_text_editor_theme(file.get_basename().to_lower())) {
  1339. custom_themes.push_back(file.get_basename());
  1340. }
  1341. file = d->get_next();
  1342. }
  1343. d->list_dir_end();
  1344. custom_themes.sort();
  1345. for (const String &E : custom_themes) {
  1346. themes += "," + E;
  1347. }
  1348. }
  1349. add_property_hint(PropertyInfo(Variant::STRING, "text_editor/theme/color_theme", PROPERTY_HINT_ENUM, themes));
  1350. }
  1351. void EditorSettings::load_text_editor_theme() {
  1352. String p_file = get("text_editor/theme/color_theme");
  1353. if (_is_default_text_editor_theme(p_file.get_file().to_lower())) {
  1354. if (p_file == "Godot 2") {
  1355. _load_godot2_text_editor_theme();
  1356. }
  1357. return; // sorry for "Settings changed" console spam
  1358. }
  1359. String theme_path = EditorPaths::get_singleton()->get_text_editor_themes_dir().path_join(p_file + ".tet");
  1360. Ref<ConfigFile> cf = memnew(ConfigFile);
  1361. Error err = cf->load(theme_path);
  1362. if (err != OK) {
  1363. return;
  1364. }
  1365. List<String> keys;
  1366. cf->get_section_keys("color_theme", &keys);
  1367. for (const String &key : keys) {
  1368. String val = cf->get_value("color_theme", key);
  1369. // don't load if it's not already there!
  1370. if (has_setting("text_editor/theme/highlighting/" + key)) {
  1371. // make sure it is actually a color
  1372. if (val.is_valid_html_color() && key.contains("color")) {
  1373. props["text_editor/theme/highlighting/" + key].variant = Color::html(val); // change manually to prevent "Settings changed" console spam
  1374. }
  1375. }
  1376. }
  1377. emit_signal(SNAME("settings_changed"));
  1378. // if it doesn't load just use what is currently loaded
  1379. }
  1380. bool EditorSettings::import_text_editor_theme(const String &p_file) {
  1381. if (!p_file.ends_with(".tet")) {
  1382. return false;
  1383. } else {
  1384. if (p_file.get_file().to_lower() == "default.tet") {
  1385. return false;
  1386. }
  1387. Ref<DirAccess> d = DirAccess::open(EditorPaths::get_singleton()->get_text_editor_themes_dir());
  1388. if (d.is_valid()) {
  1389. d->copy(p_file, EditorPaths::get_singleton()->get_text_editor_themes_dir().path_join(p_file.get_file()));
  1390. return true;
  1391. }
  1392. }
  1393. return false;
  1394. }
  1395. bool EditorSettings::save_text_editor_theme() {
  1396. String p_file = get("text_editor/theme/color_theme");
  1397. if (_is_default_text_editor_theme(p_file.get_file().to_lower())) {
  1398. return false;
  1399. }
  1400. String theme_path = EditorPaths::get_singleton()->get_text_editor_themes_dir().path_join(p_file + ".tet");
  1401. return _save_text_editor_theme(theme_path);
  1402. }
  1403. bool EditorSettings::save_text_editor_theme_as(String p_file) {
  1404. if (!p_file.ends_with(".tet")) {
  1405. p_file += ".tet";
  1406. }
  1407. if (_is_default_text_editor_theme(p_file.get_file().to_lower().trim_suffix(".tet"))) {
  1408. return false;
  1409. }
  1410. if (_save_text_editor_theme(p_file)) {
  1411. // switch to theme is saved in the theme directory
  1412. list_text_editor_themes();
  1413. String theme_name = p_file.substr(0, p_file.length() - 4).get_file();
  1414. if (p_file.get_base_dir() == EditorPaths::get_singleton()->get_text_editor_themes_dir()) {
  1415. _initial_set("text_editor/theme/color_theme", theme_name);
  1416. load_text_editor_theme();
  1417. }
  1418. return true;
  1419. }
  1420. return false;
  1421. }
  1422. bool EditorSettings::is_default_text_editor_theme() {
  1423. String p_file = get("text_editor/theme/color_theme");
  1424. return _is_default_text_editor_theme(p_file.get_file().to_lower());
  1425. }
  1426. Vector<String> EditorSettings::get_script_templates(const String &p_extension, const String &p_custom_path) {
  1427. Vector<String> templates;
  1428. String template_dir = EditorPaths::get_singleton()->get_script_templates_dir();
  1429. if (!p_custom_path.is_empty()) {
  1430. template_dir = p_custom_path;
  1431. }
  1432. Ref<DirAccess> d = DirAccess::open(template_dir);
  1433. if (d.is_valid()) {
  1434. d->list_dir_begin();
  1435. String file = d->get_next();
  1436. while (!file.is_empty()) {
  1437. if (file.get_extension() == p_extension) {
  1438. templates.push_back(file.get_basename());
  1439. }
  1440. file = d->get_next();
  1441. }
  1442. d->list_dir_end();
  1443. }
  1444. return templates;
  1445. }
  1446. String EditorSettings::get_editor_layouts_config() const {
  1447. return EditorPaths::get_singleton()->get_config_dir().path_join("editor_layouts.cfg");
  1448. }
  1449. float EditorSettings::get_auto_display_scale() const {
  1450. #ifdef LINUXBSD_ENABLED
  1451. if (DisplayServer::get_singleton()->get_name() == "Wayland") {
  1452. float main_window_scale = DisplayServer::get_singleton()->screen_get_scale(DisplayServer::SCREEN_OF_MAIN_WINDOW);
  1453. if (DisplayServer::get_singleton()->get_screen_count() == 1 || Math::fract(main_window_scale) != 0) {
  1454. // If we have a single screen or the screen of the window is fractional, all
  1455. // bets are off. At this point, let's just return the current's window scale,
  1456. // which is special-cased to the scale of `SCREEN_OF_MAIN_WINDOW`.
  1457. return main_window_scale;
  1458. }
  1459. // If the above branch didn't fire, fractional scaling isn't going to work
  1460. // properly anyways (we're need the ability to change the UI scale at runtime).
  1461. // At this point it's more convenient to "supersample" like we do with other
  1462. // platforms, hoping that the user is only using integer-scaled screens.
  1463. return DisplayServer::get_singleton()->screen_get_max_scale();
  1464. }
  1465. #endif
  1466. #if defined(MACOS_ENABLED) || defined(ANDROID_ENABLED)
  1467. return DisplayServer::get_singleton()->screen_get_max_scale();
  1468. #else
  1469. const int screen = DisplayServer::get_singleton()->window_get_current_screen();
  1470. if (DisplayServer::get_singleton()->screen_get_size(screen) == Vector2i()) {
  1471. // Invalid screen size, skip.
  1472. return 1.0;
  1473. }
  1474. // Use the smallest dimension to use a correct display scale on portrait displays.
  1475. const int smallest_dimension = MIN(DisplayServer::get_singleton()->screen_get_size(screen).x, DisplayServer::get_singleton()->screen_get_size(screen).y);
  1476. if (DisplayServer::get_singleton()->screen_get_dpi(screen) >= 192 && smallest_dimension >= 1400) {
  1477. // hiDPI display.
  1478. return 2.0;
  1479. } else if (smallest_dimension >= 1700) {
  1480. // Likely a hiDPI display, but we aren't certain due to the returned DPI.
  1481. // Use an intermediate scale to handle this situation.
  1482. return 1.5;
  1483. } else if (smallest_dimension <= 800) {
  1484. // Small loDPI display. Use a smaller display scale so that editor elements fit more easily.
  1485. // Icons won't look great, but this is better than having editor elements overflow from its window.
  1486. return 0.75;
  1487. }
  1488. return 1.0;
  1489. #endif
  1490. }
  1491. // Shortcuts
  1492. void EditorSettings::_add_shortcut_default(const String &p_name, const Ref<Shortcut> &p_shortcut) {
  1493. shortcuts[p_name] = p_shortcut;
  1494. }
  1495. void EditorSettings::add_shortcut(const String &p_name, const Ref<Shortcut> &p_shortcut) {
  1496. shortcuts[p_name] = p_shortcut;
  1497. shortcuts[p_name]->set_meta("customized", true);
  1498. }
  1499. bool EditorSettings::is_shortcut(const String &p_name, const Ref<InputEvent> &p_event) const {
  1500. HashMap<String, Ref<Shortcut>>::ConstIterator E = shortcuts.find(p_name);
  1501. ERR_FAIL_COND_V_MSG(!E, false, "Unknown Shortcut: " + p_name + ".");
  1502. return E->value->matches_event(p_event);
  1503. }
  1504. Ref<Shortcut> EditorSettings::get_shortcut(const String &p_name) const {
  1505. HashMap<String, Ref<Shortcut>>::ConstIterator SC = shortcuts.find(p_name);
  1506. if (SC) {
  1507. return SC->value;
  1508. }
  1509. // If no shortcut with the provided name is found in the list, check the built-in shortcuts.
  1510. // Use the first item in the action list for the shortcut event, since a shortcut can only have 1 linked event.
  1511. Ref<Shortcut> sc;
  1512. HashMap<String, List<Ref<InputEvent>>>::ConstIterator builtin_override = builtin_action_overrides.find(p_name);
  1513. if (builtin_override) {
  1514. sc.instantiate();
  1515. sc->set_events_list(&builtin_override->value);
  1516. sc->set_name(InputMap::get_singleton()->get_builtin_display_name(p_name));
  1517. }
  1518. // If there was no override, check the default builtins to see if it has an InputEvent for the provided name.
  1519. if (sc.is_null()) {
  1520. HashMap<String, List<Ref<InputEvent>>>::ConstIterator builtin_default = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied().find(p_name);
  1521. if (builtin_default) {
  1522. sc.instantiate();
  1523. sc->set_events_list(&builtin_default->value);
  1524. sc->set_name(InputMap::get_singleton()->get_builtin_display_name(p_name));
  1525. }
  1526. }
  1527. if (sc.is_valid()) {
  1528. // Add the shortcut to the list.
  1529. shortcuts[p_name] = sc;
  1530. return sc;
  1531. }
  1532. return Ref<Shortcut>();
  1533. }
  1534. void EditorSettings::get_shortcut_list(List<String> *r_shortcuts) {
  1535. for (const KeyValue<String, Ref<Shortcut>> &E : shortcuts) {
  1536. r_shortcuts->push_back(E.key);
  1537. }
  1538. }
  1539. Ref<Shortcut> ED_GET_SHORTCUT(const String &p_path) {
  1540. ERR_FAIL_NULL_V_MSG(EditorSettings::get_singleton(), nullptr, "EditorSettings not instantiated yet.");
  1541. Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
  1542. ERR_FAIL_COND_V_MSG(!sc.is_valid(), sc, "Used ED_GET_SHORTCUT with invalid shortcut: " + p_path);
  1543. return sc;
  1544. }
  1545. void ED_SHORTCUT_OVERRIDE(const String &p_path, const String &p_feature, Key p_keycode, bool p_physical) {
  1546. if (!EditorSettings::get_singleton()) {
  1547. return;
  1548. }
  1549. Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
  1550. ERR_FAIL_COND_MSG(!sc.is_valid(), "Used ED_SHORTCUT_OVERRIDE with invalid shortcut: " + p_path);
  1551. PackedInt32Array arr;
  1552. arr.push_back((int32_t)p_keycode);
  1553. ED_SHORTCUT_OVERRIDE_ARRAY(p_path, p_feature, arr, p_physical);
  1554. }
  1555. void ED_SHORTCUT_OVERRIDE_ARRAY(const String &p_path, const String &p_feature, const PackedInt32Array &p_keycodes, bool p_physical) {
  1556. if (!EditorSettings::get_singleton()) {
  1557. return;
  1558. }
  1559. Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
  1560. ERR_FAIL_COND_MSG(!sc.is_valid(), "Used ED_SHORTCUT_OVERRIDE_ARRAY with invalid shortcut: " + p_path);
  1561. // Only add the override if the OS supports the provided feature.
  1562. if (!OS::get_singleton()->has_feature(p_feature)) {
  1563. if (!(p_feature == "macos" && (OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios")))) {
  1564. return;
  1565. }
  1566. }
  1567. Array events;
  1568. for (int i = 0; i < p_keycodes.size(); i++) {
  1569. Key keycode = (Key)p_keycodes[i];
  1570. if (OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios")) {
  1571. // Use Cmd+Backspace as a general replacement for Delete shortcuts on macOS
  1572. if (keycode == Key::KEY_DELETE) {
  1573. keycode = KeyModifierMask::META | Key::BACKSPACE;
  1574. }
  1575. }
  1576. Ref<InputEventKey> ie;
  1577. if (keycode != Key::NONE) {
  1578. ie = InputEventKey::create_reference(keycode, p_physical);
  1579. events.push_back(ie);
  1580. }
  1581. }
  1582. // Override the existing shortcut only if it wasn't customized by the user.
  1583. if (!sc->has_meta("customized")) {
  1584. sc->set_events(events);
  1585. }
  1586. sc->set_meta("original", events.duplicate(true));
  1587. }
  1588. Ref<Shortcut> ED_SHORTCUT(const String &p_path, const String &p_name, Key p_keycode, bool p_physical) {
  1589. PackedInt32Array arr;
  1590. arr.push_back((int32_t)p_keycode);
  1591. return ED_SHORTCUT_ARRAY(p_path, p_name, arr, p_physical);
  1592. }
  1593. Ref<Shortcut> ED_SHORTCUT_ARRAY(const String &p_path, const String &p_name, const PackedInt32Array &p_keycodes, bool p_physical) {
  1594. Array events;
  1595. for (int i = 0; i < p_keycodes.size(); i++) {
  1596. Key keycode = (Key)p_keycodes[i];
  1597. if (OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios")) {
  1598. // Use Cmd+Backspace as a general replacement for Delete shortcuts on macOS
  1599. if (keycode == Key::KEY_DELETE) {
  1600. keycode = KeyModifierMask::META | Key::BACKSPACE;
  1601. }
  1602. }
  1603. Ref<InputEventKey> ie;
  1604. if (keycode != Key::NONE) {
  1605. ie = InputEventKey::create_reference(keycode, p_physical);
  1606. events.push_back(ie);
  1607. }
  1608. }
  1609. if (!EditorSettings::get_singleton()) {
  1610. Ref<Shortcut> sc;
  1611. sc.instantiate();
  1612. sc->set_name(p_name);
  1613. sc->set_events(events);
  1614. sc->set_meta("original", events.duplicate(true));
  1615. return sc;
  1616. }
  1617. Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
  1618. if (sc.is_valid()) {
  1619. sc->set_name(p_name); //keep name (the ones that come from disk have no name)
  1620. sc->set_meta("original", events.duplicate(true)); //to compare against changes
  1621. return sc;
  1622. }
  1623. sc.instantiate();
  1624. sc->set_name(p_name);
  1625. sc->set_events(events);
  1626. sc->set_meta("original", events.duplicate(true)); //to compare against changes
  1627. EditorSettings::get_singleton()->_add_shortcut_default(p_path, sc);
  1628. return sc;
  1629. }
  1630. void EditorSettings::set_builtin_action_override(const String &p_name, const TypedArray<InputEvent> &p_events) {
  1631. List<Ref<InputEvent>> event_list;
  1632. // Override the whole list, since events may have their order changed or be added, removed or edited.
  1633. InputMap::get_singleton()->action_erase_events(p_name);
  1634. for (int i = 0; i < p_events.size(); i++) {
  1635. event_list.push_back(p_events[i]);
  1636. InputMap::get_singleton()->action_add_event(p_name, p_events[i]);
  1637. }
  1638. // Check if the provided event array is same as built-in. If it is, it does not need to be added to the overrides.
  1639. // Note that event order must also be the same.
  1640. bool same_as_builtin = true;
  1641. HashMap<String, List<Ref<InputEvent>>>::ConstIterator builtin_default = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied().find(p_name);
  1642. if (builtin_default) {
  1643. const List<Ref<InputEvent>> &builtin_events = builtin_default->value;
  1644. // In the editor we only care about key events.
  1645. List<Ref<InputEventKey>> builtin_key_events;
  1646. for (Ref<InputEventKey> iek : builtin_events) {
  1647. if (iek.is_valid()) {
  1648. builtin_key_events.push_back(iek);
  1649. }
  1650. }
  1651. if (p_events.size() == builtin_key_events.size()) {
  1652. int event_idx = 0;
  1653. // Check equality of each event.
  1654. for (const Ref<InputEventKey> &E : builtin_key_events) {
  1655. if (!E->is_match(p_events[event_idx])) {
  1656. same_as_builtin = false;
  1657. break;
  1658. }
  1659. event_idx++;
  1660. }
  1661. } else {
  1662. same_as_builtin = false;
  1663. }
  1664. }
  1665. if (same_as_builtin && builtin_action_overrides.has(p_name)) {
  1666. builtin_action_overrides.erase(p_name);
  1667. } else {
  1668. builtin_action_overrides[p_name] = event_list;
  1669. }
  1670. // Update the shortcut (if it is used somewhere in the editor) to be the first event of the new list.
  1671. if (shortcuts.has(p_name)) {
  1672. shortcuts[p_name]->set_events_list(&event_list);
  1673. }
  1674. }
  1675. const Array EditorSettings::get_builtin_action_overrides(const String &p_name) const {
  1676. HashMap<String, List<Ref<InputEvent>>>::ConstIterator AO = builtin_action_overrides.find(p_name);
  1677. if (AO) {
  1678. Array event_array;
  1679. List<Ref<InputEvent>> events_list = AO->value;
  1680. for (const Ref<InputEvent> &E : events_list) {
  1681. event_array.push_back(E);
  1682. }
  1683. return event_array;
  1684. }
  1685. return Array();
  1686. }
  1687. void EditorSettings::notify_changes() {
  1688. _THREAD_SAFE_METHOD_
  1689. SceneTree *sml = Object::cast_to<SceneTree>(OS::get_singleton()->get_main_loop());
  1690. if (!sml) {
  1691. return;
  1692. }
  1693. Node *root = sml->get_root()->get_child(0);
  1694. if (!root) {
  1695. return;
  1696. }
  1697. root->propagate_notification(NOTIFICATION_EDITOR_SETTINGS_CHANGED);
  1698. }
  1699. #ifdef TOOLS_ENABLED
  1700. void EditorSettings::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
  1701. const String pf = p_function;
  1702. if (p_idx == 0) {
  1703. if (pf == "has_setting" || pf == "set_setting" || pf == "get_setting" || pf == "erase" ||
  1704. pf == "set_initial_value" || pf == "set_as_basic" || pf == "mark_setting_changed") {
  1705. for (const KeyValue<String, VariantContainer> &E : props) {
  1706. if (E.value.hide_from_editor) {
  1707. continue;
  1708. }
  1709. r_options->push_back(E.key.quote());
  1710. }
  1711. } else if (pf == "get_project_metadata" && project_metadata.is_valid()) {
  1712. List<String> sections;
  1713. project_metadata->get_sections(&sections);
  1714. for (const String &section : sections) {
  1715. r_options->push_back(section.quote());
  1716. }
  1717. } else if (pf == "set_builtin_action_override") {
  1718. for (const StringName &action : InputMap::get_singleton()->get_actions()) {
  1719. r_options->push_back(String(action).quote());
  1720. }
  1721. }
  1722. }
  1723. Object::get_argument_options(p_function, p_idx, r_options);
  1724. }
  1725. #endif
  1726. void EditorSettings::_bind_methods() {
  1727. ClassDB::bind_method(D_METHOD("has_setting", "name"), &EditorSettings::has_setting);
  1728. ClassDB::bind_method(D_METHOD("set_setting", "name", "value"), &EditorSettings::set_setting);
  1729. ClassDB::bind_method(D_METHOD("get_setting", "name"), &EditorSettings::get_setting);
  1730. ClassDB::bind_method(D_METHOD("erase", "property"), &EditorSettings::erase);
  1731. ClassDB::bind_method(D_METHOD("set_initial_value", "name", "value", "update_current"), &EditorSettings::set_initial_value);
  1732. ClassDB::bind_method(D_METHOD("add_property_info", "info"), &EditorSettings::_add_property_info_bind);
  1733. ClassDB::bind_method(D_METHOD("set_project_metadata", "section", "key", "data"), &EditorSettings::set_project_metadata);
  1734. ClassDB::bind_method(D_METHOD("get_project_metadata", "section", "key", "default"), &EditorSettings::get_project_metadata, DEFVAL(Variant()));
  1735. ClassDB::bind_method(D_METHOD("set_favorites", "dirs"), &EditorSettings::set_favorites);
  1736. ClassDB::bind_method(D_METHOD("get_favorites"), &EditorSettings::get_favorites);
  1737. ClassDB::bind_method(D_METHOD("set_recent_dirs", "dirs"), &EditorSettings::set_recent_dirs);
  1738. ClassDB::bind_method(D_METHOD("get_recent_dirs"), &EditorSettings::get_recent_dirs);
  1739. ClassDB::bind_method(D_METHOD("set_builtin_action_override", "name", "actions_list"), &EditorSettings::set_builtin_action_override);
  1740. ClassDB::bind_method(D_METHOD("check_changed_settings_in_group", "setting_prefix"), &EditorSettings::check_changed_settings_in_group);
  1741. ClassDB::bind_method(D_METHOD("get_changed_settings"), &EditorSettings::get_changed_settings);
  1742. ClassDB::bind_method(D_METHOD("mark_setting_changed", "setting"), &EditorSettings::mark_setting_changed);
  1743. ADD_SIGNAL(MethodInfo("settings_changed"));
  1744. BIND_CONSTANT(NOTIFICATION_EDITOR_SETTINGS_CHANGED);
  1745. }
  1746. EditorSettings::EditorSettings() {
  1747. last_order = 0;
  1748. _load_defaults();
  1749. callable_mp(this, &EditorSettings::_set_initialized).call_deferred();
  1750. }