editor_settings.cpp 63 KB

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