editor_settings.cpp 84 KB

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