editor_settings.cpp 83 KB

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