editor_settings.cpp 68 KB

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