editor_settings.cpp 69 KB

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