editor_settings.cpp 62 KB

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