editor_settings.cpp 97 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111
  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_server.h"
  45. #include "core/version.h"
  46. #include "editor/editor_node.h"
  47. #include "editor/editor_paths.h"
  48. #include "editor/editor_property_name_processor.h"
  49. #include "editor/editor_translation.h"
  50. #include "editor/engine_update_label.h"
  51. #include "scene/gui/color_picker.h"
  52. #include "scene/main/node.h"
  53. #include "scene/main/scene_tree.h"
  54. #include "scene/main/window.h"
  55. // PRIVATE METHODS
  56. Ref<EditorSettings> EditorSettings::singleton = nullptr;
  57. // Properties
  58. bool EditorSettings::_set(const StringName &p_name, const Variant &p_value) {
  59. _THREAD_SAFE_METHOD_
  60. bool changed = _set_only(p_name, p_value);
  61. if (changed && initialized) {
  62. changed_settings.insert(p_name);
  63. emit_signal(SNAME("settings_changed"));
  64. }
  65. return true;
  66. }
  67. bool EditorSettings::_set_only(const StringName &p_name, const Variant &p_value) {
  68. _THREAD_SAFE_METHOD_
  69. if (p_name == "shortcuts") {
  70. Array arr = p_value;
  71. for (int i = 0; i < arr.size(); i++) {
  72. Dictionary dict = arr[i];
  73. String shortcut_name = dict["name"];
  74. Array shortcut_events = dict["shortcuts"];
  75. Ref<Shortcut> sc;
  76. sc.instantiate();
  77. sc->set_events(shortcut_events);
  78. add_shortcut(shortcut_name, sc);
  79. }
  80. return false;
  81. } else if (p_name == "builtin_action_overrides") {
  82. Array actions_arr = p_value;
  83. for (int i = 0; i < actions_arr.size(); i++) {
  84. Dictionary action_dict = actions_arr[i];
  85. String action_name = action_dict["name"];
  86. Array events = action_dict["events"];
  87. InputMap *im = InputMap::get_singleton();
  88. im->action_erase_events(action_name);
  89. builtin_action_overrides[action_name].clear();
  90. for (int ev_idx = 0; ev_idx < events.size(); ev_idx++) {
  91. im->action_add_event(action_name, events[ev_idx]);
  92. builtin_action_overrides[action_name].push_back(events[ev_idx]);
  93. }
  94. }
  95. return false;
  96. }
  97. bool changed = false;
  98. if (p_value.get_type() == Variant::NIL) {
  99. if (props.has(p_name)) {
  100. props.erase(p_name);
  101. changed = true;
  102. }
  103. } else {
  104. if (props.has(p_name)) {
  105. if (p_value != props[p_name].variant) {
  106. props[p_name].variant = p_value;
  107. changed = true;
  108. }
  109. } else {
  110. props[p_name] = VariantContainer(p_value, last_order++);
  111. changed = true;
  112. }
  113. if (save_changed_setting) {
  114. if (!props[p_name].save) {
  115. props[p_name].save = true;
  116. changed = true;
  117. }
  118. }
  119. }
  120. return changed;
  121. }
  122. bool EditorSettings::_get(const StringName &p_name, Variant &r_ret) const {
  123. _THREAD_SAFE_METHOD_
  124. if (p_name == "shortcuts") {
  125. Array save_array;
  126. const HashMap<String, List<Ref<InputEvent>>> &builtin_list = InputMap::get_singleton()->get_builtins();
  127. for (const KeyValue<String, Ref<Shortcut>> &shortcut_definition : shortcuts) {
  128. Ref<Shortcut> sc = shortcut_definition.value;
  129. if (builtin_list.has(shortcut_definition.key)) {
  130. // This shortcut was auto-generated from built in actions: don't save.
  131. // If the builtin is overridden, it will be saved in the "builtin_action_overrides" section below.
  132. continue;
  133. }
  134. Array shortcut_events = sc->get_events();
  135. Dictionary dict;
  136. dict["name"] = shortcut_definition.key;
  137. dict["shortcuts"] = shortcut_events;
  138. if (!sc->has_meta("original")) {
  139. // Getting the meta when it doesn't exist will return an empty array. If the 'shortcut_events' have been cleared,
  140. // we still want save the shortcut in this case so that shortcuts that the user has customized are not reset,
  141. // even if the 'original' has not been populated yet. This can happen when calling save() from the Project Manager.
  142. save_array.push_back(dict);
  143. continue;
  144. }
  145. Array original_events = sc->get_meta("original");
  146. bool is_same = Shortcut::is_event_array_equal(original_events, shortcut_events);
  147. if (is_same) {
  148. continue; // Not changed from default; don't save.
  149. }
  150. save_array.push_back(dict);
  151. }
  152. r_ret = save_array;
  153. return true;
  154. } else if (p_name == "builtin_action_overrides") {
  155. Array actions_arr;
  156. for (const KeyValue<String, List<Ref<InputEvent>>> &action_override : builtin_action_overrides) {
  157. List<Ref<InputEvent>> events = action_override.value;
  158. Dictionary action_dict;
  159. action_dict["name"] = action_override.key;
  160. // Convert the list to an array, and only keep key events as this is for the editor.
  161. Array events_arr;
  162. for (const Ref<InputEvent> &ie : events) {
  163. Ref<InputEventKey> iek = ie;
  164. if (iek.is_valid()) {
  165. events_arr.append(iek);
  166. }
  167. }
  168. Array defaults_arr;
  169. List<Ref<InputEvent>> defaults = InputMap::get_singleton()->get_builtins()[action_override.key];
  170. for (const Ref<InputEvent> &default_input_event : defaults) {
  171. if (default_input_event.is_valid()) {
  172. defaults_arr.append(default_input_event);
  173. }
  174. }
  175. bool same = Shortcut::is_event_array_equal(events_arr, defaults_arr);
  176. // Don't save if same as default.
  177. if (same) {
  178. continue;
  179. }
  180. action_dict["events"] = events_arr;
  181. actions_arr.push_back(action_dict);
  182. }
  183. r_ret = actions_arr;
  184. return true;
  185. }
  186. const VariantContainer *v = props.getptr(p_name);
  187. if (!v) {
  188. return false;
  189. }
  190. r_ret = v->variant;
  191. return true;
  192. }
  193. void EditorSettings::_initial_set(const StringName &p_name, const Variant &p_value, bool p_basic) {
  194. set(p_name, p_value);
  195. props[p_name].initial = p_value;
  196. props[p_name].has_default_value = true;
  197. props[p_name].basic = p_basic;
  198. }
  199. struct _EVCSort {
  200. String name;
  201. Variant::Type type = Variant::Type::NIL;
  202. int order = 0;
  203. bool basic = false;
  204. bool save = false;
  205. bool restart_if_changed = false;
  206. bool operator<(const _EVCSort &p_vcs) const { return order < p_vcs.order; }
  207. };
  208. void EditorSettings::_get_property_list(List<PropertyInfo> *p_list) const {
  209. _THREAD_SAFE_METHOD_
  210. RBSet<_EVCSort> vclist;
  211. for (const KeyValue<String, VariantContainer> &E : props) {
  212. const VariantContainer *v = &E.value;
  213. if (v->hide_from_editor) {
  214. continue;
  215. }
  216. _EVCSort vc;
  217. vc.name = E.key;
  218. vc.order = v->order;
  219. vc.type = v->variant.get_type();
  220. vc.basic = v->basic;
  221. vc.save = v->save;
  222. if (vc.save) {
  223. if (v->initial.get_type() != Variant::NIL && v->initial == v->variant) {
  224. vc.save = false;
  225. }
  226. }
  227. vc.restart_if_changed = v->restart_if_changed;
  228. vclist.insert(vc);
  229. }
  230. for (const _EVCSort &E : vclist) {
  231. uint32_t pusage = PROPERTY_USAGE_NONE;
  232. if (E.save || !optimize_save) {
  233. pusage |= PROPERTY_USAGE_STORAGE;
  234. }
  235. if (!E.name.begins_with("_") && !E.name.begins_with("projects/")) {
  236. pusage |= PROPERTY_USAGE_EDITOR;
  237. } else {
  238. pusage |= PROPERTY_USAGE_STORAGE; //hiddens must always be saved
  239. }
  240. PropertyInfo pi(E.type, E.name);
  241. pi.usage = pusage;
  242. if (hints.has(E.name)) {
  243. pi = hints[E.name];
  244. }
  245. if (E.basic) {
  246. pi.usage |= PROPERTY_USAGE_EDITOR_BASIC_SETTING;
  247. }
  248. if (E.restart_if_changed) {
  249. pi.usage |= PROPERTY_USAGE_RESTART_IF_CHANGED;
  250. }
  251. p_list->push_back(pi);
  252. }
  253. p_list->push_back(PropertyInfo(Variant::ARRAY, "shortcuts", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL)); //do not edit
  254. p_list->push_back(PropertyInfo(Variant::ARRAY, "builtin_action_overrides", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));
  255. }
  256. void EditorSettings::_add_property_info_bind(const Dictionary &p_info) {
  257. ERR_FAIL_COND(!p_info.has("name"));
  258. ERR_FAIL_COND(!p_info.has("type"));
  259. PropertyInfo pinfo;
  260. pinfo.name = p_info["name"];
  261. ERR_FAIL_COND(!props.has(pinfo.name));
  262. pinfo.type = Variant::Type(p_info["type"].operator int());
  263. ERR_FAIL_INDEX(pinfo.type, Variant::VARIANT_MAX);
  264. if (p_info.has("hint")) {
  265. pinfo.hint = PropertyHint(p_info["hint"].operator int());
  266. }
  267. if (p_info.has("hint_string")) {
  268. pinfo.hint_string = p_info["hint_string"];
  269. }
  270. add_property_hint(pinfo);
  271. }
  272. // Default configs
  273. bool EditorSettings::has_default_value(const String &p_setting) const {
  274. _THREAD_SAFE_METHOD_
  275. if (!props.has(p_setting)) {
  276. return false;
  277. }
  278. return props[p_setting].has_default_value;
  279. }
  280. void EditorSettings::_set_initialized() {
  281. initialized = true;
  282. }
  283. void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
  284. _THREAD_SAFE_METHOD_
  285. // Sets up the editor setting with a default value and hint PropertyInfo.
  286. #define EDITOR_SETTING(m_type, m_property_hint, m_name, m_default_value, m_hint_string) \
  287. _initial_set(m_name, m_default_value); \
  288. hints[m_name] = PropertyInfo(m_type, m_name, m_property_hint, m_hint_string);
  289. #define EDITOR_SETTING_BASIC(m_type, m_property_hint, m_name, m_default_value, m_hint_string) \
  290. _initial_set(m_name, m_default_value, true); \
  291. hints[m_name] = PropertyInfo(m_type, m_name, m_property_hint, m_hint_string);
  292. #define EDITOR_SETTING_USAGE(m_type, m_property_hint, m_name, m_default_value, m_hint_string, m_usage) \
  293. _initial_set(m_name, m_default_value); \
  294. hints[m_name] = PropertyInfo(m_type, m_name, m_property_hint, m_hint_string, m_usage);
  295. /* Languages */
  296. {
  297. String lang_hint = "en";
  298. String host_lang = OS::get_singleton()->get_locale();
  299. // Skip locales if Text server lack required features.
  300. Vector<String> locales_to_skip;
  301. if (!TS->has_feature(TextServer::FEATURE_BIDI_LAYOUT) || !TS->has_feature(TextServer::FEATURE_SHAPING)) {
  302. locales_to_skip.push_back("ar"); // Arabic
  303. locales_to_skip.push_back("fa"); // Persian
  304. locales_to_skip.push_back("ur"); // Urdu
  305. }
  306. if (!TS->has_feature(TextServer::FEATURE_BIDI_LAYOUT)) {
  307. locales_to_skip.push_back("he"); // Hebrew
  308. }
  309. if (!TS->has_feature(TextServer::FEATURE_SHAPING)) {
  310. locales_to_skip.push_back("bn"); // Bengali
  311. locales_to_skip.push_back("hi"); // Hindi
  312. locales_to_skip.push_back("ml"); // Malayalam
  313. locales_to_skip.push_back("si"); // Sinhala
  314. locales_to_skip.push_back("ta"); // Tamil
  315. locales_to_skip.push_back("te"); // Telugu
  316. }
  317. if (!locales_to_skip.is_empty()) {
  318. WARN_PRINT("Some locales are not properly supported by selected Text Server and are disabled.");
  319. }
  320. String best;
  321. int best_score = 0;
  322. for (const String &locale : get_editor_locales()) {
  323. // Skip locales which we can't render properly (see above comment).
  324. // Test against language code without regional variants (e.g. ur_PK).
  325. String lang_code = locale.get_slice("_", 0);
  326. if (locales_to_skip.has(lang_code)) {
  327. continue;
  328. }
  329. lang_hint += ",";
  330. lang_hint += locale;
  331. int score = TranslationServer::get_singleton()->compare_locales(host_lang, locale);
  332. if (score > 0 && score >= best_score) {
  333. best = locale;
  334. best_score = score;
  335. }
  336. }
  337. if (best_score == 0) {
  338. best = "en";
  339. }
  340. EDITOR_SETTING_USAGE(Variant::STRING, PROPERTY_HINT_ENUM, "interface/editor/editor_language", best, lang_hint, PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED | PROPERTY_USAGE_EDITOR_BASIC_SETTING);
  341. }
  342. // Asset library
  343. _initial_set("asset_library/use_threads", true);
  344. /* Interface */
  345. // Editor
  346. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/localize_settings", true, "")
  347. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/dock_tab_style", 0, "Text Only,Icon Only,Text and Icon")
  348. EDITOR_SETTING_USAGE(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/ui_layout_direction", 0, "Based on Application Locale,Left-to-Right,Right-to-Left,Based on System Locale", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  349. // Display what the Auto display scale setting effectively corresponds to.
  350. const String display_scale_hint_string = vformat("Auto (%d%%),75%%,100%%,125%%,150%%,175%%,200%%,Custom", Math::round(get_auto_display_scale() * 100));
  351. 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 | PROPERTY_USAGE_EDITOR_BASIC_SETTING)
  352. 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 | PROPERTY_USAGE_EDITOR_BASIC_SETTING)
  353. String ed_screen_hints = "Auto (Remembers last position):-5,Screen With Mouse Pointer:-4,Screen With Keyboard Focus:-3,Primary Screen:-2";
  354. for (int i = 0; i < DisplayServer::get_singleton()->get_screen_count(); i++) {
  355. ed_screen_hints += ",Screen " + itos(i + 1) + ":" + itos(i);
  356. }
  357. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/editor_screen", EditorSettings::InitialScreen::INITIAL_SCREEN_AUTO, ed_screen_hints)
  358. String project_manager_screen_hints = "Screen With Mouse Pointer:-4,Screen With Keyboard Focus:-3,Primary Screen:-2";
  359. for (int i = 0; i < DisplayServer::get_singleton()->get_screen_count(); i++) {
  360. project_manager_screen_hints += ",Screen " + itos(i + 1) + ":" + itos(i);
  361. }
  362. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/project_manager_screen", EditorSettings::InitialScreen::INITIAL_SCREEN_PRIMARY, project_manager_screen_hints)
  363. {
  364. EngineUpdateLabel::UpdateMode default_update_mode = EngineUpdateLabel::UpdateMode::NEWEST_UNSTABLE;
  365. if (String(VERSION_STATUS) == String("stable")) {
  366. default_update_mode = EngineUpdateLabel::UpdateMode::NEWEST_STABLE;
  367. }
  368. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "network/connection/engine_version_update_mode", int(default_update_mode), "Disable Update Checks,Check Newest Preview,Check Newest Stable,Check Newest Patch"); // Uses EngineUpdateLabel::UpdateMode.
  369. }
  370. EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/use_embedded_menu", false, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED | PROPERTY_USAGE_EDITOR_BASIC_SETTING)
  371. EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/use_native_file_dialogs", false, "", PROPERTY_USAGE_DEFAULT)
  372. EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/expand_to_title", true, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED | PROPERTY_USAGE_EDITOR_BASIC_SETTING)
  373. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_RANGE, "interface/editor/main_font_size", 14, "8,48,1")
  374. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_RANGE, "interface/editor/code_font_size", 14, "8,48,1")
  375. 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")
  376. _initial_set("interface/editor/code_font_custom_opentype_features", "");
  377. _initial_set("interface/editor/code_font_custom_variations", "");
  378. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/font_antialiasing", 1, "None,Grayscale,LCD Subpixel")
  379. #ifdef MACOS_ENABLED
  380. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/font_hinting", 0, "Auto (None),None,Light,Normal")
  381. #else
  382. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/font_hinting", 0, "Auto (Light),None,Light,Normal")
  383. #endif
  384. 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")
  385. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/font_disable_embedded_bitmaps", true, "");
  386. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/font_allow_msdf", true, "")
  387. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "interface/editor/main_font", "", "*.ttf,*.otf,*.woff,*.woff2,*.pfb,*.pfm")
  388. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "interface/editor/main_font_bold", "", "*.ttf,*.otf,*.woff,*.woff2,*.pfb,*.pfm")
  389. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "interface/editor/code_font", "", "*.ttf,*.otf,*.woff,*.woff2,*.pfb,*.pfm")
  390. _initial_set("interface/editor/separate_distraction_mode", false, true);
  391. _initial_set("interface/editor/automatically_open_screenshots", true, true);
  392. EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/single_window_mode", false, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED | PROPERTY_USAGE_EDITOR_BASIC_SETTING)
  393. _initial_set("interface/editor/mouse_extra_buttons_navigate_history", true);
  394. _initial_set("interface/editor/save_each_scene_on_quit", true, true); // Regression
  395. EDITOR_SETTING_BASIC(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/save_on_focus_loss", false, "")
  396. EDITOR_SETTING_USAGE(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/accept_dialog_cancel_ok_buttons", 0,
  397. vformat("Auto (%s),Cancel First,OK First", DisplayServer::get_singleton()->get_swap_cancel_ok() ? "OK First" : "Cancel First"),
  398. PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
  399. #ifdef DEV_ENABLED
  400. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/show_internal_errors_in_toast_notifications", 0, "Auto (Enabled),Enabled,Disabled")
  401. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/show_update_spinner", 0, "Auto (Enabled),Enabled,Disabled")
  402. #else
  403. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/show_internal_errors_in_toast_notifications", 0, "Auto (Disabled),Enabled,Disabled")
  404. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/show_update_spinner", 0, "Auto (Disabled),Enabled,Disabled")
  405. #endif
  406. _initial_set("interface/editor/keep_screen_on", false, true);
  407. EDITOR_SETTING_USAGE(Variant::INT, PROPERTY_HINT_RANGE, "interface/editor/low_processor_mode_sleep_usec", 6900, "1,100000,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  408. // Default unfocused usec sleep is for 10 FPS. Allow an unfocused FPS limit
  409. // as low as 1 FPS for those who really need low power usage (but don't need
  410. // to preview particles or shaders while the editor is unfocused). With very
  411. // low FPS limits, the editor can take a small while to become usable after
  412. // being focused again, so this should be used at the user's discretion.
  413. EDITOR_SETTING_USAGE(Variant::INT, PROPERTY_HINT_RANGE, "interface/editor/unfocused_low_processor_mode_sleep_usec", 100000, "1,1000000,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  414. EDITOR_SETTING_BASIC(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/import_resources_when_unfocused", false, "")
  415. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/vsync_mode", 1, "Disabled,Enabled,Adaptive,Mailbox")
  416. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/update_continuously", false, "")
  417. _initial_set("interface/editors/show_scene_tree_root_selection", true);
  418. _initial_set("interface/editors/derive_script_globals_by_name", true);
  419. _initial_set("docks/scene_tree/ask_before_revoking_unique_name", true);
  420. // Inspector
  421. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_RANGE, "interface/inspector/max_array_dictionary_items_per_page", 20, "10,100,1")
  422. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/inspector/show_low_level_opentype_features", false, "")
  423. EDITOR_SETTING_BASIC(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/inspector/float_drag_speed", 5.0, "0.1,100,0.01")
  424. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "interface/inspector/nested_color_mode", 0, "Containers & Resources,Resources,External Resources")
  425. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/inspector/delimitate_all_container_and_resources", true, "")
  426. EDITOR_SETTING_USAGE(Variant::INT, PROPERTY_HINT_ENUM, "interface/inspector/default_property_name_style", EditorPropertyNameProcessor::STYLE_CAPITALIZED, "Raw (e.g. \"z_index\"),Capitalized (e.g. \"Z Index\"),Localized (e.g. \"Z Index\")", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
  427. // The lowest value is equal to the minimum float step for 32-bit floats.
  428. // The step must be set manually, as changing this setting should not change the step here.
  429. EDITOR_SETTING_USAGE(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/inspector/default_float_step", 0.001, "0.0000001,1,0.0000001", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED | PROPERTY_USAGE_EDITOR_BASIC_SETTING);
  430. EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/inspector/disable_folding", false, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
  431. EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/inspector/auto_unfold_foreign_scenes", true, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  432. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/inspector/horizontal_vector2_editing", false, "")
  433. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/inspector/horizontal_vector_types_editing", true, "")
  434. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/inspector/open_resources_in_current_inspector", true, "")
  435. PackedStringArray open_in_new_inspector_defaults;
  436. // Required for the script editor to work.
  437. open_in_new_inspector_defaults.push_back("Script");
  438. // Required for the GridMap editor to work.
  439. open_in_new_inspector_defaults.push_back("MeshLibrary");
  440. _initial_set("interface/inspector/resources_to_open_in_new_inspector", open_in_new_inspector_defaults);
  441. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "interface/inspector/default_color_picker_mode", (int32_t)ColorPicker::MODE_RGB, "RGB,HSV,RAW,OKHSL")
  442. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "interface/inspector/default_color_picker_shape", (int32_t)ColorPicker::SHAPE_OKHSL_CIRCLE, "HSV Rectangle,HSV Rectangle Wheel,VHS Circle,OKHSL Circle")
  443. // Theme
  444. EDITOR_SETTING_BASIC(Variant::BOOL, PROPERTY_HINT_ENUM, "interface/theme/follow_system_theme", false, "")
  445. EDITOR_SETTING_BASIC(Variant::STRING, PROPERTY_HINT_ENUM, "interface/theme/preset", "Default", "Default,Breeze Dark,Godot 2,Gray,Light,Solarized (Dark),Solarized (Light),Black (OLED),Custom")
  446. EDITOR_SETTING_BASIC(Variant::STRING, PROPERTY_HINT_ENUM, "interface/theme/spacing_preset", "Default", "Compact,Default,Spacious,Custom")
  447. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/theme/icon_and_font_color", 0, "Auto,Dark,Light")
  448. EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "interface/theme/base_color", Color(0.2, 0.23, 0.31), "")
  449. EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "interface/theme/accent_color", Color(0.41, 0.61, 0.91), "")
  450. EDITOR_SETTING_BASIC(Variant::BOOL, PROPERTY_HINT_NONE, "interface/theme/use_system_accent_color", false, "")
  451. EDITOR_SETTING_BASIC(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/theme/contrast", 0.3, "-1,1,0.01")
  452. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/theme/draw_extra_borders", false, "")
  453. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/theme/icon_saturation", 1.0, "0,2,0.01")
  454. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/theme/relationship_line_opacity", 0.1, "0.00,1,0.01")
  455. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/theme/border_size", 0, "0,2,1")
  456. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/theme/corner_radius", 3, "0,6,1")
  457. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/theme/base_spacing", 4, "0,8,1")
  458. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/theme/additional_spacing", 0, "0,8,1")
  459. EDITOR_SETTING_USAGE(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "interface/theme/custom_theme", "", "*.res,*.tres,*.theme", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  460. // Touchscreen
  461. bool has_touchscreen_ui = DisplayServer::get_singleton()->is_touchscreen_available();
  462. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/touchscreen/enable_pan_and_scale_gestures", has_touchscreen_ui, "")
  463. set_restart_if_changed("interface/touchscreen/enable_pan_and_scale_gestures", true);
  464. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/touchscreen/scale_gizmo_handles", has_touchscreen_ui ? 3 : 1, "1,5,1")
  465. set_restart_if_changed("interface/touchscreen/scale_gizmo_handles", true);
  466. // Disable some touchscreen settings by default for the XR Editor.
  467. bool is_native_touchscreen = has_touchscreen_ui && !OS::get_singleton()->has_feature("xr_editor");
  468. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/touchscreen/enable_long_press_as_right_click", is_native_touchscreen, "")
  469. set_restart_if_changed("interface/touchscreen/enable_long_press_as_right_click", true);
  470. EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/touchscreen/increase_scrollbar_touch_area", is_native_touchscreen, "")
  471. set_restart_if_changed("interface/touchscreen/increase_scrollbar_touch_area", true);
  472. // Scene tabs
  473. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/scene_tabs/display_close_button", 1, "Never,If Tab Active,Always"); // TabBar::CloseButtonDisplayPolicy
  474. _initial_set("interface/scene_tabs/show_thumbnail_on_hover", true);
  475. EDITOR_SETTING_USAGE(Variant::INT, PROPERTY_HINT_RANGE, "interface/scene_tabs/maximum_width", 350, "0,9999,1", PROPERTY_USAGE_DEFAULT)
  476. _initial_set("interface/scene_tabs/show_script_button", false, true);
  477. _initial_set("interface/scene_tabs/restore_scenes_on_load", true, true);
  478. // Multi Window
  479. EDITOR_SETTING_BASIC(Variant::BOOL, PROPERTY_HINT_NONE, "interface/multi_window/enable", true, "");
  480. EDITOR_SETTING_BASIC(Variant::BOOL, PROPERTY_HINT_NONE, "interface/multi_window/restore_windows_on_load", true, "");
  481. EDITOR_SETTING_BASIC(Variant::BOOL, PROPERTY_HINT_NONE, "interface/multi_window/maximize_window", false, "");
  482. set_restart_if_changed("interface/multi_window/enable", true);
  483. /* Filesystem */
  484. // External Programs
  485. EDITOR_SETTING_BASIC(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "filesystem/external_programs/raster_image_editor", "", "")
  486. EDITOR_SETTING_BASIC(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "filesystem/external_programs/vector_image_editor", "", "")
  487. EDITOR_SETTING_BASIC(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "filesystem/external_programs/audio_editor", "", "")
  488. EDITOR_SETTING_BASIC(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "filesystem/external_programs/3d_model_editor", "", "")
  489. EDITOR_SETTING_BASIC(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "filesystem/external_programs/terminal_emulator", "", "")
  490. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_PLACEHOLDER_TEXT, "filesystem/external_programs/terminal_emulator_flags", "", "Call flags with placeholder: {directory}.");
  491. // Directories
  492. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_DIR, "filesystem/directories/autoscan_project_path", "", "")
  493. 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);
  494. EDITOR_SETTING_BASIC(Variant::STRING, PROPERTY_HINT_GLOBAL_DIR, "filesystem/directories/default_project_path", fs_dir_default_project_path, "")
  495. // On save
  496. _initial_set("filesystem/on_save/compress_binary_resources", true);
  497. _initial_set("filesystem/on_save/safe_save_on_backup_then_rename", true);
  498. // EditorFileServer
  499. _initial_set("filesystem/file_server/port", 6010);
  500. _initial_set("filesystem/file_server/password", "");
  501. // File dialog
  502. _initial_set("filesystem/file_dialog/show_hidden_files", false);
  503. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "filesystem/file_dialog/display_mode", 0, "Thumbnails,List")
  504. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "filesystem/file_dialog/thumbnail_size", 64, "32,128,16")
  505. // Quick Open dialog
  506. EDITOR_SETTING_USAGE(Variant::INT, PROPERTY_HINT_RANGE, "filesystem/quick_open_dialog/max_results", 100, "0,10000,1", PROPERTY_USAGE_DEFAULT)
  507. _initial_set("filesystem/quick_open_dialog/show_search_highlight", true);
  508. _initial_set("filesystem/quick_open_dialog/enable_fuzzy_matching", true);
  509. EDITOR_SETTING_USAGE(Variant::INT, PROPERTY_HINT_RANGE, "filesystem/quick_open_dialog/max_fuzzy_misses", 2, "0,10,1", PROPERTY_USAGE_DEFAULT)
  510. _initial_set("filesystem/quick_open_dialog/include_addons", false);
  511. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "filesystem/quick_open_dialog/default_display_mode", 0, "Adaptive,Last Used")
  512. // Import (for glft module)
  513. EDITOR_SETTING_USAGE(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "filesystem/import/blender/blender_path", "", "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED | PROPERTY_USAGE_EDITOR_BASIC_SETTING)
  514. EDITOR_SETTING_USAGE(Variant::INT, PROPERTY_HINT_RANGE, "filesystem/import/blender/rpc_port", 6011, "0,65535,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  515. EDITOR_SETTING_USAGE(Variant::FLOAT, PROPERTY_HINT_RANGE, "filesystem/import/blender/rpc_server_uptime", 5, "0,300,1,or_greater,suffix:s", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  516. EDITOR_SETTING_USAGE(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "filesystem/import/fbx/fbx2gltf_path", "", "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  517. // Tools (denoise)
  518. EDITOR_SETTING_USAGE(Variant::STRING, PROPERTY_HINT_GLOBAL_DIR, "filesystem/tools/oidn/oidn_denoise_path", "", "", PROPERTY_USAGE_DEFAULT)
  519. /* Docks */
  520. // SceneTree
  521. _initial_set("docks/scene_tree/ask_before_deleting_related_animation_tracks", true);
  522. _initial_set("docks/scene_tree/start_create_dialog_fully_expanded", false);
  523. _initial_set("docks/scene_tree/auto_expand_to_selected", true);
  524. _initial_set("docks/scene_tree/center_node_on_reparent", false);
  525. // FileSystem
  526. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "docks/filesystem/thumbnail_size", 64, "32,128,16")
  527. _initial_set("docks/filesystem/always_show_folders", true);
  528. _initial_set("docks/filesystem/textfile_extensions", "txt,md,cfg,ini,log,json,yml,yaml,toml,xml");
  529. _initial_set("docks/filesystem/other_file_extensions", "ico,icns");
  530. // Property editor
  531. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "docks/property_editor/auto_refresh_interval", 0.2, "0.01,1,0.001"); // Update 5 times per second by default.
  532. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "docks/property_editor/subresource_hue_tint", 0.75, "0,1,0.01")
  533. /* Text editor */
  534. // Theme
  535. _initial_set("text_editor/theme/line_spacing", 6);
  536. EDITOR_SETTING_BASIC(Variant::STRING, PROPERTY_HINT_ENUM, "text_editor/theme/color_theme", "Default", "Default,Godot 2,Custom")
  537. // Theme: Highlighting
  538. _load_godot2_text_editor_theme();
  539. // Appearance
  540. // Appearance: Caret
  541. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/appearance/caret/type", 0, "Line,Block")
  542. _initial_set("text_editor/appearance/caret/caret_blink", true, true);
  543. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "text_editor/appearance/caret/caret_blink_interval", 0.5, "0.1,10,0.01")
  544. _initial_set("text_editor/appearance/caret/highlight_current_line", true, true);
  545. _initial_set("text_editor/appearance/caret/highlight_all_occurrences", true, true);
  546. // Appearance: Guidelines
  547. _initial_set("text_editor/appearance/guidelines/show_line_length_guidelines", true, true);
  548. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/appearance/guidelines/line_length_guideline_soft_column", 80, "20,160,1")
  549. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/appearance/guidelines/line_length_guideline_hard_column", 100, "20,160,1")
  550. // Appearance: Gutters
  551. _initial_set("text_editor/appearance/gutters/show_line_numbers", true, true);
  552. _initial_set("text_editor/appearance/gutters/line_numbers_zero_padded", false, true);
  553. _initial_set("text_editor/appearance/gutters/highlight_type_safe_lines", true, true);
  554. _initial_set("text_editor/appearance/gutters/show_info_gutter", true, true);
  555. // Appearance: Minimap
  556. _initial_set("text_editor/appearance/minimap/show_minimap", true, true);
  557. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/appearance/minimap/minimap_width", 80, "50,250,1")
  558. // Appearance: Lines
  559. _initial_set("text_editor/appearance/lines/code_folding", true, true);
  560. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/appearance/lines/word_wrap", 0, "None,Boundary")
  561. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/appearance/lines/autowrap_mode", 3, "Arbitrary:1,Word:2,Word (Smart):3")
  562. // Appearance: Whitespace
  563. _initial_set("text_editor/appearance/whitespace/draw_tabs", true, true);
  564. _initial_set("text_editor/appearance/whitespace/draw_spaces", false, true);
  565. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/appearance/whitespace/line_spacing", 4, "0,50,1")
  566. // Behavior
  567. // Behavior: General
  568. _initial_set("text_editor/behavior/general/empty_selection_clipboard", true);
  569. // Behavior: Navigation
  570. _initial_set("text_editor/behavior/navigation/move_caret_on_right_click", true, true);
  571. _initial_set("text_editor/behavior/navigation/scroll_past_end_of_file", false, true);
  572. _initial_set("text_editor/behavior/navigation/smooth_scrolling", true, true);
  573. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/behavior/navigation/v_scroll_speed", 80, "1,10000,1")
  574. _initial_set("text_editor/behavior/navigation/drag_and_drop_selection", true, true);
  575. _initial_set("text_editor/behavior/navigation/stay_in_script_editor_on_node_selected", true, true);
  576. _initial_set("text_editor/behavior/navigation/open_script_when_connecting_signal_to_existing_method", true, true);
  577. _initial_set("text_editor/behavior/navigation/use_default_word_separators", true); // Includes ´`~$^=+|<> General punctuation and CJK punctuation.
  578. _initial_set("text_editor/behavior/navigation/use_custom_word_separators", false);
  579. _initial_set("text_editor/behavior/navigation/custom_word_separators", ""); // Custom word separators.
  580. // Behavior: Indent
  581. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/behavior/indent/type", 0, "Tabs,Spaces")
  582. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/behavior/indent/size", 4, "1,64,1") // size of 0 crashes.
  583. _initial_set("text_editor/behavior/indent/auto_indent", true);
  584. _initial_set("text_editor/behavior/indent/indent_wrapped_lines", true);
  585. // Behavior: Files
  586. _initial_set("text_editor/behavior/files/trim_trailing_whitespace_on_save", false);
  587. _initial_set("text_editor/behavior/files/trim_final_newlines_on_save", true);
  588. _initial_set("text_editor/behavior/files/autosave_interval_secs", 0);
  589. _initial_set("text_editor/behavior/files/restore_scripts_on_load", true);
  590. _initial_set("text_editor/behavior/files/convert_indent_on_save", true);
  591. _initial_set("text_editor/behavior/files/auto_reload_scripts_on_external_change", false);
  592. _initial_set("text_editor/behavior/files/auto_reload_and_parse_scripts_on_save", true);
  593. _initial_set("text_editor/behavior/files/open_dominant_script_on_scene_change", false, true);
  594. // Script list
  595. _initial_set("text_editor/script_list/show_members_overview", true, true);
  596. _initial_set("text_editor/script_list/sort_members_outline_alphabetically", false, true);
  597. _initial_set("text_editor/script_list/script_temperature_enabled", true);
  598. _initial_set("text_editor/script_list/script_temperature_history_size", 15);
  599. _initial_set("text_editor/script_list/highlight_scene_scripts", true);
  600. _initial_set("text_editor/script_list/group_help_pages", true);
  601. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/script_list/sort_scripts_by", 0, "Name,Path,None");
  602. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/script_list/list_script_names_as", 0, "Name,Parent Directory And Name,Full Path");
  603. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "text_editor/external/exec_path", "", "");
  604. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_PLACEHOLDER_TEXT, "text_editor/external/exec_flags", "{file}", "Call flags with placeholders: {project}, {file}, {col}, {line}.");
  605. // Completion
  606. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "text_editor/completion/idle_parse_delay", 1.5, "0.1,10,0.01")
  607. _initial_set("text_editor/completion/auto_brace_complete", true, true);
  608. _initial_set("text_editor/completion/code_complete_enabled", true, true);
  609. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "text_editor/completion/code_complete_delay", 0.3, "0.01,5,0.01,or_greater")
  610. _initial_set("text_editor/completion/put_callhint_tooltip_below_current_line", true);
  611. _initial_set("text_editor/completion/complete_file_paths", true);
  612. _initial_set("text_editor/completion/add_type_hints", true, true);
  613. _initial_set("text_editor/completion/add_string_name_literals", false, true);
  614. _initial_set("text_editor/completion/add_node_path_literals", false, true);
  615. _initial_set("text_editor/completion/use_single_quotes", false, true);
  616. _initial_set("text_editor/completion/colorize_suggestions", true);
  617. // External editor (ScriptEditorPlugin)
  618. _initial_set("text_editor/external/use_external_editor", false, true);
  619. _initial_set("text_editor/external/exec_path", "");
  620. // Help
  621. _initial_set("text_editor/help/show_help_index", true);
  622. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/help/help_font_size", 16, "8,48,1")
  623. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/help/help_source_font_size", 15, "8,48,1")
  624. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/help/help_title_font_size", 23, "8,64,1")
  625. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/help/class_reference_examples", 0, "GDScript,C#,GDScript and C#")
  626. _initial_set("text_editor/help/sort_functions_alphabetically", true);
  627. /* Editors */
  628. // GridMap
  629. // GridMapEditor
  630. _initial_set("editors/grid_map/pick_distance", 5000.0);
  631. _initial_set("editors/grid_map/palette_min_width", 230);
  632. set_restart_if_changed("editors/grid_map/palette_min_width", true);
  633. _initial_set("editors/grid_map/preview_size", 64);
  634. // GridMapEditorPlugin
  635. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/grid_map/editor_side", 1, "Left,Right");
  636. // 3D
  637. EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d/primary_grid_color", Color(0.56, 0.56, 0.56, 0.5), "")
  638. EDITOR_SETTING_BASIC(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d/secondary_grid_color", Color(0.38, 0.38, 0.38, 0.5), "")
  639. // Use a similar color to the 2D editor selection.
  640. 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)
  641. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/instantiated", Color(0.7, 0.7, 0.7, 0.6), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  642. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/joint", Color(0.5, 0.8, 1), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  643. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/aabb", Color(0.28, 0.8, 0.82), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  644. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/stream_player_3d", Color(0.4, 0.8, 1), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  645. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/camera", Color(0.8, 0.4, 0.8), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  646. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/decal", Color(0.6, 0.5, 1.0), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  647. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/fog_volume", Color(0.5, 0.7, 1), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  648. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/particles", Color(0.8, 0.7, 0.4), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  649. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/particle_attractor", Color(1, 0.7, 0.5), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  650. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/particle_collision", Color(0.5, 0.7, 1), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  651. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/joint_body_a", Color(0.6, 0.8, 1), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  652. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/joint_body_b", Color(0.6, 0.9, 1), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  653. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/lightmap_lines", Color(0.5, 0.6, 1), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  654. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/lightprobe_lines", Color(0.5, 0.6, 1), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  655. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/occluder", Color(0.8, 0.5, 1), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  656. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/reflection_probe", Color(0.6, 1, 0.5), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  657. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/visibility_notifier", Color(0.8, 0.5, 0.7), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  658. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/voxel_gi", Color(0.5, 1, 0.6), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  659. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/path_tilt", Color(1.0, 1.0, 0.4, 0.9), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  660. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/skeleton", Color(1, 0.8, 0.4), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  661. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/selected_bone", Color(0.8, 0.3, 0.0), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  662. EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/csg", Color(0.0, 0.4, 1, 0.15), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  663. _initial_set("editors/3d_gizmos/gizmo_settings/bone_axis_length", (float)0.1);
  664. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d_gizmos/gizmo_settings/bone_shape", 1, "Wire,Octahedron");
  665. EDITOR_SETTING_USAGE(Variant::FLOAT, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_settings/path3d_tilt_disk_size", 0.8, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  666. // If a line is a multiple of this, it uses the primary grid color.
  667. // Use a power of 2 value by default as it's more common to use powers of 2 in level design.
  668. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_RANGE, "editors/3d/primary_grid_steps", 8, "1,100,1")
  669. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_RANGE, "editors/3d/grid_size", 200, "1,2000,1")
  670. // Higher values produce graphical artifacts when far away unless View Z-Far
  671. // is increased significantly more than it really should need to be.
  672. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "editors/3d/grid_division_level_max", 2, "-1,3,1")
  673. // Lower values produce graphical artifacts regardless of view clipping planes, so limit to -2 as a lower bound.
  674. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "editors/3d/grid_division_level_min", 0, "-2,2,1")
  675. // -0.2 seems like a sensible default. -1.0 gives Blender-like behavior, 0.5 gives huge grids.
  676. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/grid_division_level_bias", -0.2, "-1.0,0.5,0.1")
  677. _initial_set("editors/3d/grid_xz_plane", true);
  678. _initial_set("editors/3d/grid_xy_plane", false);
  679. _initial_set("editors/3d/grid_yz_plane", false);
  680. // Use a lower default FOV for the 3D camera compared to the
  681. // Camera3D node as the 3D viewport doesn't span the whole screen.
  682. // This means it's technically viewed from a further distance, which warrants a narrower FOV.
  683. EDITOR_SETTING_BASIC(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/default_fov", 70.0, "1,179,0.1,degrees")
  684. EDITOR_SETTING_BASIC(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/default_z_near", 0.05, "0.01,10,0.01,or_greater,suffix:m")
  685. EDITOR_SETTING_BASIC(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/default_z_far", 4000.0, "0.1,4000,0.1,or_greater,suffix:m")
  686. // 3D: Navigation
  687. _initial_set("editors/3d/navigation/invert_x_axis", false, true);
  688. _initial_set("editors/3d/navigation/invert_y_axis", false, true);
  689. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/navigation_scheme", 0, "Godot,Maya,Modo,Custom")
  690. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/orbit_mouse_button", 1, "Left Mouse,Middle Mouse,Right Mouse")
  691. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/pan_mouse_button", 1, "Left Mouse,Middle Mouse,Right Mouse")
  692. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/zoom_mouse_button", 1, "Left Mouse,Middle Mouse,Right Mouse")
  693. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/zoom_style", 0, "Vertical,Horizontal")
  694. _initial_set("editors/3d/navigation/emulate_numpad", false, true);
  695. _initial_set("editors/3d/navigation/emulate_3_button_mouse", false, true);
  696. _initial_set("editors/3d/navigation/warped_mouse_panning", true, true);
  697. // 3D: Navigation feel
  698. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/navigation_feel/orbit_sensitivity", 0.25, "0.01,20,0.001")
  699. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/navigation_feel/translation_sensitivity", 1.0, "0.01,20,0.001")
  700. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/navigation_feel/orbit_inertia", 0.0, "0,1,0.001")
  701. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/navigation_feel/translation_inertia", 0.05, "0,1,0.001")
  702. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/navigation_feel/zoom_inertia", 0.05, "0,1,0.001")
  703. _initial_set("editors/3d/navigation/show_viewport_rotation_gizmo", true);
  704. _initial_set("editors/3d/navigation/show_viewport_navigation_gizmo", DisplayServer::get_singleton()->is_touchscreen_available());
  705. // 3D: Freelook
  706. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/freelook/freelook_navigation_scheme", 0, "Default,Partially Axis-Locked (id Tech),Fully Axis-Locked (Minecraft)")
  707. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/freelook/freelook_sensitivity", 0.25, "0.01,2,0.001")
  708. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/freelook/freelook_inertia", 0.0, "0,1,0.001")
  709. EDITOR_SETTING_BASIC(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/freelook/freelook_base_speed", 5.0, "0,10,0.01")
  710. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/freelook/freelook_activation_modifier", 0, "None,Shift,Alt,Meta,Ctrl")
  711. _initial_set("editors/3d/freelook/freelook_speed_zoom_link", false);
  712. // 3D: Manipulator
  713. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "editors/3d/manipulator_gizmo_size", 80, "16,160,1");
  714. EDITOR_SETTING_USAGE(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/manipulator_gizmo_opacity", 0.9, "0,1,0.01", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
  715. // 2D
  716. _initial_set("editors/2d/grid_color", Color(1.0, 1.0, 1.0, 0.07), true);
  717. _initial_set("editors/2d/guides_color", Color(0.6, 0.0, 0.8), true);
  718. _initial_set("editors/2d/smart_snapping_line_color", Color(0.9, 0.1, 0.1), true);
  719. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/2d/bone_width", 5.0, "0.01,20,0.01,or_greater")
  720. _initial_set("editors/2d/bone_color1", Color(1.0, 1.0, 1.0, 0.7));
  721. _initial_set("editors/2d/bone_color2", Color(0.6, 0.6, 0.6, 0.7));
  722. _initial_set("editors/2d/bone_selected_color", Color(0.9, 0.45, 0.45, 0.7));
  723. _initial_set("editors/2d/bone_ik_color", Color(0.9, 0.9, 0.45, 0.7));
  724. _initial_set("editors/2d/bone_outline_color", Color(0.35, 0.35, 0.35, 0.5));
  725. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/2d/bone_outline_size", 2.0, "0.01,8,0.01,or_greater")
  726. _initial_set("editors/2d/viewport_border_color", Color(0.4, 0.4, 1.0, 0.4), true);
  727. _initial_set("editors/2d/use_integer_zoom_by_default", false, true);
  728. EDITOR_SETTING_BASIC(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/2d/zoom_speed_factor", 1.1, "1.01,2,0.01")
  729. // Bone mapper (BoneMapEditorPlugin)
  730. _initial_set("editors/bone_mapper/handle_colors/unset", Color(0.3, 0.3, 0.3));
  731. _initial_set("editors/bone_mapper/handle_colors/set", Color(0.1, 0.6, 0.25));
  732. _initial_set("editors/bone_mapper/handle_colors/missing", Color(0.8, 0.2, 0.8));
  733. _initial_set("editors/bone_mapper/handle_colors/error", Color(0.8, 0.2, 0.2));
  734. // Panning
  735. // Enum should be in sync with ControlScheme in ViewPanner.
  736. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "editors/panning/2d_editor_panning_scheme", 0, "Scroll Zooms,Scroll Pans");
  737. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "editors/panning/sub_editors_panning_scheme", 0, "Scroll Zooms,Scroll Pans");
  738. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "editors/panning/animation_editors_panning_scheme", 1, "Scroll Zooms,Scroll Pans");
  739. _initial_set("editors/panning/simple_panning", false);
  740. _initial_set("editors/panning/warped_mouse_panning", true);
  741. _initial_set("editors/panning/2d_editor_pan_speed", 20, true);
  742. // Tiles editor
  743. _initial_set("editors/tiles_editor/display_grid", true);
  744. _initial_set("editors/tiles_editor/highlight_selected_layer", true);
  745. _initial_set("editors/tiles_editor/grid_color", Color(1.0, 0.5, 0.2, 0.5));
  746. // Polygon editor
  747. _initial_set("editors/polygon_editor/point_grab_radius", has_touchscreen_ui ? 32 : 8);
  748. _initial_set("editors/polygon_editor/show_previous_outline", true);
  749. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/polygon_editor/auto_bake_delay", 1.5, "-1.0,10.0,0.01");
  750. // Animation
  751. _initial_set("editors/animation/autorename_animation_tracks", true);
  752. _initial_set("editors/animation/confirm_insert_track", true, true);
  753. _initial_set("editors/animation/default_create_bezier_tracks", false, true);
  754. _initial_set("editors/animation/default_create_reset_tracks", true, true);
  755. _initial_set("editors/animation/onion_layers_past_color", Color(1, 0, 0));
  756. _initial_set("editors/animation/onion_layers_future_color", Color(0, 1, 0));
  757. // Shader editor
  758. _initial_set("editors/shader_editor/behavior/files/restore_shaders_on_load", true, true);
  759. // Visual editors
  760. EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_ENUM, "editors/visual_editors/color_theme", "Default", "Default,Legacy,Custom")
  761. _load_default_visual_shader_editor_theme();
  762. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/visual_editors/minimap_opacity", 0.85, "0.0,1.0,0.01")
  763. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/visual_editors/lines_curvature", 0.5, "0.0,1.0,0.01")
  764. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/visual_editors/grid_pattern", 1, "Lines,Dots")
  765. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "editors/visual_editors/visual_shader/port_preview_size", 160, "100,400,0.01")
  766. // Export (EditorExportPlugin)
  767. _initial_set("export/ssh/ssh", "");
  768. _initial_set("export/ssh/scp", "");
  769. /* Run */
  770. // Window placement
  771. #ifndef ANDROID_ENABLED
  772. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "run/window_placement/rect", 1, "Top Left,Centered,Custom Position,Force Maximized,Force Fullscreen")
  773. // Keep the enum values in sync with the `DisplayServer::SCREEN_` enum.
  774. 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.
  775. for (int i = 0; i < DisplayServer::get_singleton()->get_screen_count(); i++) {
  776. screen_hints += ",Screen " + itos(i + 1) + ":" + itos(i);
  777. }
  778. _initial_set("run/window_placement/rect_custom_position", Vector2());
  779. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "run/window_placement/screen", -5, screen_hints)
  780. #endif
  781. // Should match the ANDROID_WINDOW_* constants in 'platform/android/java/editor/src/main/java/org/godotengine/editor/GodotEditor.kt'
  782. String android_window_hints = "Auto (based on screen size):0,Same as Editor:1,Side-by-side with Editor:2,Launch in PiP mode:3";
  783. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "run/window_placement/android_window", 0, android_window_hints)
  784. int default_play_window_pip_mode = 0;
  785. #ifdef ANDROID_ENABLED
  786. default_play_window_pip_mode = 2;
  787. #endif
  788. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "run/window_placement/play_window_pip_mode", default_play_window_pip_mode, "Disabled:0,Enabled:1,Enabled when Play window is same as Editor:2")
  789. // Auto save
  790. _initial_set("run/auto_save/save_before_running", true, true);
  791. // Bottom panel
  792. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "run/bottom_panel/action_on_play", EditorNode::ACTION_ON_PLAY_OPEN_OUTPUT, "Do Nothing,Open Output,Open Debugger")
  793. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "run/bottom_panel/action_on_stop", EditorNode::ACTION_ON_STOP_DO_NOTHING, "Do Nothing,Close Bottom Panel")
  794. // Output
  795. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_RANGE, "run/output/font_size", 13, "8,48,1")
  796. _initial_set("run/output/always_clear_output_on_play", true, true);
  797. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "run/output/max_lines", 10000, "100,100000,1")
  798. // Platform
  799. _initial_set("run/platforms/linuxbsd/prefer_wayland", false, true);
  800. set_restart_if_changed("run/platforms/linuxbsd/prefer_wayland", true);
  801. /* Network */
  802. // General
  803. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "network/connection/network_mode", 0, "Offline,Online");
  804. // HTTP Proxy
  805. _initial_set("network/http_proxy/host", "");
  806. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "network/http_proxy/port", 8080, "1,65535,1")
  807. // SSL
  808. 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);
  809. // Debug
  810. _initial_set("network/debug/remote_host", "127.0.0.1"); // Hints provided in setup_network
  811. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "network/debug/remote_port", 6007, "1,65535,1")
  812. /* Debugger/profiler */
  813. EDITOR_SETTING_BASIC(Variant::BOOL, PROPERTY_HINT_NONE, "debugger/auto_switch_to_remote_scene_tree", false, "")
  814. EDITOR_SETTING_BASIC(Variant::BOOL, PROPERTY_HINT_NONE, "debugger/auto_switch_to_stack_trace", true, "")
  815. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "debugger/profiler_frame_history_size", 3600, "60,10000,1")
  816. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "debugger/profiler_frame_max_functions", 64, "16,512,1")
  817. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "debugger/profiler_target_fps", 60, "1,1000,1")
  818. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "debugger/remote_scene_tree_refresh_interval", 1.0, "0.1,10,0.01,or_greater")
  819. EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "debugger/remote_inspect_refresh_interval", 0.2, "0.02,10,0.01,or_greater")
  820. EDITOR_SETTING_BASIC(Variant::BOOL, PROPERTY_HINT_NONE, "debugger/profile_native_calls", false, "")
  821. // Version control (VersionControlEditorPlugin)
  822. _initial_set("version_control/username", "", true);
  823. _initial_set("version_control/ssh_public_key_path", "");
  824. _initial_set("version_control/ssh_private_key_path", "");
  825. /* Extra config */
  826. EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "input/buffering/agile_event_flushing", false, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED | PROPERTY_USAGE_EDITOR_BASIC_SETTING)
  827. EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "input/buffering/use_accumulated_input", true, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED | PROPERTY_USAGE_EDITOR_BASIC_SETTING)
  828. // TRANSLATORS: Project Manager here refers to the tool used to create/manage Godot projects.
  829. EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "project_manager/sorting_order", 0, "Last Edited,Name,Path")
  830. EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "project_manager/directory_naming_convention", 1, "No convention,kebab-case,snake_case,camelCase,PascalCase,Title Case")
  831. #if defined(WEB_ENABLED)
  832. // Web platform only supports `gl_compatibility`.
  833. const String default_renderer = "gl_compatibility";
  834. #elif defined(ANDROID_ENABLED)
  835. // Use more suitable rendering method by default.
  836. const String default_renderer = "mobile";
  837. #else
  838. const String default_renderer = "forward_plus";
  839. #endif
  840. EDITOR_SETTING_BASIC(Variant::STRING, PROPERTY_HINT_ENUM, "project_manager/default_renderer", default_renderer, "forward_plus,mobile,gl_compatibility")
  841. #undef EDITOR_SETTING
  842. #undef EDITOR_SETTING_BASIC
  843. #undef EDITOR_SETTING_USAGE
  844. if (p_extra_config.is_valid()) {
  845. if (p_extra_config->has_section("init_projects") && p_extra_config->has_section_key("init_projects", "list")) {
  846. Vector<String> list = p_extra_config->get_value("init_projects", "list");
  847. for (int i = 0; i < list.size(); i++) {
  848. String proj_name = list[i].replace("/", "::");
  849. set("projects/" + proj_name, list[i]);
  850. }
  851. }
  852. if (p_extra_config->has_section("presets")) {
  853. List<String> keys;
  854. p_extra_config->get_section_keys("presets", &keys);
  855. for (const String &key : keys) {
  856. Variant val = p_extra_config->get_value("presets", key);
  857. set(key, val);
  858. }
  859. }
  860. }
  861. }
  862. void EditorSettings::_load_godot2_text_editor_theme() {
  863. // Godot 2 is only a dark theme; it doesn't have a light theme counterpart.
  864. _initial_set("text_editor/theme/highlighting/symbol_color", Color(0.73, 0.87, 1.0), true);
  865. _initial_set("text_editor/theme/highlighting/keyword_color", Color(1.0, 1.0, 0.7), true);
  866. _initial_set("text_editor/theme/highlighting/control_flow_keyword_color", Color(1.0, 0.85, 0.7), true);
  867. _initial_set("text_editor/theme/highlighting/base_type_color", Color(0.64, 1.0, 0.83), true);
  868. _initial_set("text_editor/theme/highlighting/engine_type_color", Color(0.51, 0.83, 1.0), true);
  869. _initial_set("text_editor/theme/highlighting/user_type_color", Color(0.42, 0.67, 0.93), true);
  870. _initial_set("text_editor/theme/highlighting/comment_color", Color(0.4, 0.4, 0.4), true);
  871. _initial_set("text_editor/theme/highlighting/doc_comment_color", Color(0.5, 0.6, 0.7), true);
  872. _initial_set("text_editor/theme/highlighting/string_color", Color(0.94, 0.43, 0.75), true);
  873. _initial_set("text_editor/theme/highlighting/background_color", Color(0.13, 0.12, 0.15), true);
  874. _initial_set("text_editor/theme/highlighting/completion_background_color", Color(0.17, 0.16, 0.2));
  875. _initial_set("text_editor/theme/highlighting/completion_selected_color", Color(0.26, 0.26, 0.27));
  876. _initial_set("text_editor/theme/highlighting/completion_existing_color", Color(0.87, 0.87, 0.87, 0.13));
  877. _initial_set("text_editor/theme/highlighting/completion_scroll_color", Color(1, 1, 1, 0.29));
  878. _initial_set("text_editor/theme/highlighting/completion_scroll_hovered_color", Color(1, 1, 1, 0.4));
  879. _initial_set("text_editor/theme/highlighting/completion_font_color", Color(0.67, 0.67, 0.67));
  880. _initial_set("text_editor/theme/highlighting/text_color", Color(0.67, 0.67, 0.67), true);
  881. _initial_set("text_editor/theme/highlighting/line_number_color", Color(0.67, 0.67, 0.67, 0.4), true);
  882. _initial_set("text_editor/theme/highlighting/safe_line_number_color", Color(0.67, 0.78, 0.67, 0.6), true);
  883. _initial_set("text_editor/theme/highlighting/caret_color", Color(0.67, 0.67, 0.67), true);
  884. _initial_set("text_editor/theme/highlighting/caret_background_color", Color(0, 0, 0), true);
  885. _initial_set("text_editor/theme/highlighting/text_selected_color", Color(0, 0, 0, 0), true);
  886. _initial_set("text_editor/theme/highlighting/selection_color", Color(0.41, 0.61, 0.91, 0.35), true);
  887. _initial_set("text_editor/theme/highlighting/brace_mismatch_color", Color(1, 0.2, 0.2), true);
  888. _initial_set("text_editor/theme/highlighting/current_line_color", Color(0.3, 0.5, 0.8, 0.15), true);
  889. _initial_set("text_editor/theme/highlighting/line_length_guideline_color", Color(0.3, 0.5, 0.8, 0.1), true);
  890. _initial_set("text_editor/theme/highlighting/word_highlighted_color", Color(0.8, 0.9, 0.9, 0.15), true);
  891. _initial_set("text_editor/theme/highlighting/number_color", Color(0.92, 0.58, 0.2), true);
  892. _initial_set("text_editor/theme/highlighting/function_color", Color(0.4, 0.64, 0.81), true);
  893. _initial_set("text_editor/theme/highlighting/member_variable_color", Color(0.9, 0.31, 0.35), true);
  894. _initial_set("text_editor/theme/highlighting/mark_color", Color(1.0, 0.4, 0.4, 0.4), true);
  895. _initial_set("text_editor/theme/highlighting/bookmark_color", Color(0.08, 0.49, 0.98));
  896. _initial_set("text_editor/theme/highlighting/breakpoint_color", Color(0.9, 0.29, 0.3));
  897. _initial_set("text_editor/theme/highlighting/executing_line_color", Color(0.98, 0.89, 0.27));
  898. _initial_set("text_editor/theme/highlighting/code_folding_color", Color(0.8, 0.8, 0.8, 0.8));
  899. _initial_set("text_editor/theme/highlighting/folded_code_region_color", Color(0.68, 0.46, 0.77, 0.2));
  900. _initial_set("text_editor/theme/highlighting/search_result_color", Color(0.05, 0.25, 0.05, 1));
  901. _initial_set("text_editor/theme/highlighting/search_result_border_color", Color(0.41, 0.61, 0.91, 0.38));
  902. }
  903. void EditorSettings::_load_default_visual_shader_editor_theme() {
  904. // Connection type colors
  905. _initial_set("editors/visual_editors/connection_colors/scalar_color", Color(0.55, 0.55, 0.55));
  906. _initial_set("editors/visual_editors/connection_colors/vector2_color", Color(0.44, 0.43, 0.64));
  907. _initial_set("editors/visual_editors/connection_colors/vector3_color", Color(0.337, 0.314, 0.71));
  908. _initial_set("editors/visual_editors/connection_colors/vector4_color", Color(0.7, 0.65, 0.147));
  909. _initial_set("editors/visual_editors/connection_colors/boolean_color", Color(0.243, 0.612, 0.349));
  910. _initial_set("editors/visual_editors/connection_colors/transform_color", Color(0.71, 0.357, 0.64));
  911. _initial_set("editors/visual_editors/connection_colors/sampler_color", Color(0.659, 0.4, 0.137));
  912. // Node category colors (used for the node headers)
  913. _initial_set("editors/visual_editors/category_colors/output_color", Color(0.26, 0.10, 0.15));
  914. _initial_set("editors/visual_editors/category_colors/color_color", Color(0.5, 0.5, 0.1));
  915. _initial_set("editors/visual_editors/category_colors/conditional_color", Color(0.208, 0.522, 0.298));
  916. _initial_set("editors/visual_editors/category_colors/input_color", Color(0.502, 0.2, 0.204));
  917. _initial_set("editors/visual_editors/category_colors/scalar_color", Color(0.1, 0.5, 0.6));
  918. _initial_set("editors/visual_editors/category_colors/textures_color", Color(0.5, 0.3, 0.1));
  919. _initial_set("editors/visual_editors/category_colors/transform_color", Color(0.5, 0.3, 0.5));
  920. _initial_set("editors/visual_editors/category_colors/utility_color", Color(0.2, 0.2, 0.2));
  921. _initial_set("editors/visual_editors/category_colors/vector_color", Color(0.2, 0.2, 0.5));
  922. _initial_set("editors/visual_editors/category_colors/special_color", Color(0.098, 0.361, 0.294));
  923. _initial_set("editors/visual_editors/category_colors/particle_color", Color(0.12, 0.358, 0.8));
  924. }
  925. bool EditorSettings::_save_text_editor_theme(const String &p_file) {
  926. String theme_section = "color_theme";
  927. Ref<ConfigFile> cf = memnew(ConfigFile); // hex is better?
  928. List<String> keys;
  929. for (const KeyValue<String, VariantContainer> &E : props) {
  930. keys.push_back(E.key);
  931. }
  932. keys.sort();
  933. for (const String &key : keys) {
  934. if (key.begins_with("text_editor/theme/highlighting/") && key.contains("color")) {
  935. cf->set_value(theme_section, key.replace("text_editor/theme/highlighting/", ""), ((Color)props[key].variant).to_html());
  936. }
  937. }
  938. Error err = cf->save(p_file);
  939. return err == OK;
  940. }
  941. bool EditorSettings::_is_default_text_editor_theme(const String &p_theme_name) {
  942. return p_theme_name == "default" || p_theme_name == "godot 2" || p_theme_name == "custom";
  943. }
  944. const String EditorSettings::_get_project_metadata_path() const {
  945. return EditorPaths::get_singleton()->get_project_settings_dir().path_join("project_metadata.cfg");
  946. }
  947. #ifndef DISABLE_DEPRECATED
  948. void EditorSettings::_remove_deprecated_settings() {
  949. erase("run/output/always_open_output_on_play");
  950. erase("run/output/always_close_output_on_stop");
  951. }
  952. #endif
  953. // PUBLIC METHODS
  954. EditorSettings *EditorSettings::get_singleton() {
  955. return singleton.ptr();
  956. }
  957. String EditorSettings::get_existing_settings_path() {
  958. const String config_dir = EditorPaths::get_singleton()->get_config_dir();
  959. int minor = VERSION_MINOR;
  960. String filename;
  961. do {
  962. if (VERSION_MAJOR == 4 && minor < 3) {
  963. // Minor version is used since 4.3, so special case to load older settings.
  964. filename = vformat("editor_settings-%d.tres", VERSION_MAJOR);
  965. minor = -1;
  966. } else {
  967. filename = vformat("editor_settings-%d.%d.tres", VERSION_MAJOR, minor);
  968. minor--;
  969. }
  970. } while (minor >= 0 && !FileAccess::exists(config_dir.path_join(filename)));
  971. return config_dir.path_join(filename);
  972. }
  973. String EditorSettings::get_newest_settings_path() {
  974. const String config_file_name = vformat("editor_settings-%d.%d.tres", VERSION_MAJOR, VERSION_MINOR);
  975. return EditorPaths::get_singleton()->get_config_dir().path_join(config_file_name);
  976. }
  977. void EditorSettings::create() {
  978. // IMPORTANT: create() *must* create a valid EditorSettings singleton,
  979. // as the rest of the engine code will assume it. As such, it should never
  980. // return (incl. via ERR_FAIL) without initializing the singleton member.
  981. if (singleton.ptr()) {
  982. ERR_PRINT("Can't recreate EditorSettings as it already exists.");
  983. return;
  984. }
  985. String config_file_path;
  986. Ref<ConfigFile> extra_config = memnew(ConfigFile);
  987. if (!EditorPaths::get_singleton()) {
  988. ERR_PRINT("Bug (please report): EditorPaths haven't been initialized, EditorSettings cannot be created properly.");
  989. goto fail;
  990. }
  991. if (EditorPaths::get_singleton()->is_self_contained()) {
  992. Error err = extra_config->load(EditorPaths::get_singleton()->get_self_contained_file());
  993. if (err != OK) {
  994. ERR_PRINT("Can't load extra config from path: " + EditorPaths::get_singleton()->get_self_contained_file());
  995. }
  996. }
  997. if (EditorPaths::get_singleton()->are_paths_valid()) {
  998. // Validate editor config file.
  999. ERR_FAIL_COND(!DirAccess::dir_exists_absolute(EditorPaths::get_singleton()->get_config_dir()));
  1000. config_file_path = get_existing_settings_path();
  1001. if (!FileAccess::exists(config_file_path)) {
  1002. config_file_path = get_newest_settings_path();
  1003. goto fail;
  1004. }
  1005. singleton = ResourceLoader::load(config_file_path, "EditorSettings");
  1006. if (singleton.is_null()) {
  1007. ERR_PRINT("Could not load editor settings from path: " + config_file_path);
  1008. config_file_path = get_newest_settings_path();
  1009. goto fail;
  1010. }
  1011. singleton->set_path(get_newest_settings_path()); // Settings can be loaded from older version file, so make sure it's newest.
  1012. singleton->save_changed_setting = true;
  1013. print_verbose("EditorSettings: Load OK!");
  1014. singleton->setup_language();
  1015. singleton->setup_network();
  1016. singleton->load_favorites_and_recent_dirs();
  1017. singleton->list_text_editor_themes();
  1018. #ifndef DISABLE_DEPRECATED
  1019. singleton->_remove_deprecated_settings();
  1020. #endif
  1021. return;
  1022. }
  1023. fail:
  1024. // patch init projects
  1025. String exe_path = OS::get_singleton()->get_executable_path().get_base_dir();
  1026. if (extra_config->has_section("init_projects")) {
  1027. Vector<String> list = extra_config->get_value("init_projects", "list");
  1028. for (int i = 0; i < list.size(); i++) {
  1029. list.write[i] = exe_path.path_join(list[i]);
  1030. }
  1031. extra_config->set_value("init_projects", "list", list);
  1032. }
  1033. singleton.instantiate();
  1034. singleton->set_path(config_file_path, true);
  1035. singleton->save_changed_setting = true;
  1036. singleton->_load_defaults(extra_config);
  1037. singleton->setup_language();
  1038. singleton->setup_network();
  1039. singleton->list_text_editor_themes();
  1040. }
  1041. void EditorSettings::setup_language() {
  1042. String lang = get("interface/editor/editor_language");
  1043. TranslationServer::get_singleton()->set_locale(lang);
  1044. if (lang == "en") {
  1045. return; // Default, nothing to do.
  1046. }
  1047. // Load editor translation for configured/detected locale.
  1048. load_editor_translations(lang);
  1049. load_property_translations(lang);
  1050. // Load class reference translation.
  1051. load_doc_translations(lang);
  1052. // Load extractable translation for projects.
  1053. load_extractable_translations(lang);
  1054. }
  1055. void EditorSettings::setup_network() {
  1056. List<IPAddress> local_ip;
  1057. IP::get_singleton()->get_local_addresses(&local_ip);
  1058. String hint;
  1059. String current = has_setting("network/debug/remote_host") ? get("network/debug/remote_host") : "";
  1060. String selected = "127.0.0.1";
  1061. // Check that current remote_host is a valid interface address and populate hints.
  1062. for (const IPAddress &ip : local_ip) {
  1063. // link-local IPv6 addresses don't work, skipping them
  1064. if (String(ip).begins_with("fe80:0:0:0:")) { // fe80::/64
  1065. continue;
  1066. }
  1067. // Same goes for IPv4 link-local (APIPA) addresses.
  1068. if (String(ip).begins_with("169.254.")) { // 169.254.0.0/16
  1069. continue;
  1070. }
  1071. // Select current IP (found)
  1072. if (ip == current) {
  1073. selected = ip;
  1074. }
  1075. if (!hint.is_empty()) {
  1076. hint += ",";
  1077. }
  1078. hint += ip;
  1079. }
  1080. // Add hints with valid IP addresses to remote_host property.
  1081. add_property_hint(PropertyInfo(Variant::STRING, "network/debug/remote_host", PROPERTY_HINT_ENUM, hint));
  1082. // Fix potentially invalid remote_host due to network change.
  1083. set("network/debug/remote_host", selected);
  1084. }
  1085. void EditorSettings::save() {
  1086. //_THREAD_SAFE_METHOD_
  1087. if (!singleton.ptr()) {
  1088. return;
  1089. }
  1090. Error err = ResourceSaver::save(singleton);
  1091. if (err != OK) {
  1092. ERR_PRINT("Error saving editor settings to " + singleton->get_path());
  1093. } else {
  1094. singleton->changed_settings.clear();
  1095. print_verbose("EditorSettings: Save OK!");
  1096. }
  1097. }
  1098. PackedStringArray EditorSettings::get_changed_settings() const {
  1099. PackedStringArray arr;
  1100. for (const String &setting : changed_settings) {
  1101. arr.push_back(setting);
  1102. }
  1103. return arr;
  1104. }
  1105. bool EditorSettings::check_changed_settings_in_group(const String &p_setting_prefix) const {
  1106. for (const String &setting : changed_settings) {
  1107. if (setting.begins_with(p_setting_prefix)) {
  1108. return true;
  1109. }
  1110. }
  1111. return false;
  1112. }
  1113. void EditorSettings::mark_setting_changed(const String &p_setting) {
  1114. changed_settings.insert(p_setting);
  1115. }
  1116. void EditorSettings::destroy() {
  1117. if (!singleton.ptr()) {
  1118. return;
  1119. }
  1120. save();
  1121. singleton = Ref<EditorSettings>();
  1122. }
  1123. void EditorSettings::set_optimize_save(bool p_optimize) {
  1124. optimize_save = p_optimize;
  1125. }
  1126. // Properties
  1127. void EditorSettings::set_setting(const String &p_setting, const Variant &p_value) {
  1128. _THREAD_SAFE_METHOD_
  1129. set(p_setting, p_value);
  1130. }
  1131. Variant EditorSettings::get_setting(const String &p_setting) const {
  1132. _THREAD_SAFE_METHOD_
  1133. return get(p_setting);
  1134. }
  1135. bool EditorSettings::has_setting(const String &p_setting) const {
  1136. _THREAD_SAFE_METHOD_
  1137. return props.has(p_setting);
  1138. }
  1139. void EditorSettings::erase(const String &p_setting) {
  1140. _THREAD_SAFE_METHOD_
  1141. props.erase(p_setting);
  1142. }
  1143. void EditorSettings::raise_order(const String &p_setting) {
  1144. _THREAD_SAFE_METHOD_
  1145. ERR_FAIL_COND(!props.has(p_setting));
  1146. props[p_setting].order = ++last_order;
  1147. }
  1148. void EditorSettings::set_restart_if_changed(const StringName &p_setting, bool p_restart) {
  1149. _THREAD_SAFE_METHOD_
  1150. if (!props.has(p_setting)) {
  1151. return;
  1152. }
  1153. props[p_setting].restart_if_changed = p_restart;
  1154. }
  1155. void EditorSettings::set_basic(const StringName &p_setting, bool p_basic) {
  1156. _THREAD_SAFE_METHOD_
  1157. if (!props.has(p_setting)) {
  1158. return;
  1159. }
  1160. props[p_setting].basic = p_basic;
  1161. }
  1162. void EditorSettings::set_initial_value(const StringName &p_setting, const Variant &p_value, bool p_update_current) {
  1163. _THREAD_SAFE_METHOD_
  1164. if (!props.has(p_setting)) {
  1165. return;
  1166. }
  1167. props[p_setting].initial = p_value;
  1168. props[p_setting].has_default_value = true;
  1169. if (p_update_current) {
  1170. set(p_setting, p_value);
  1171. }
  1172. }
  1173. Variant _EDITOR_DEF(const String &p_setting, const Variant &p_default, bool p_restart_if_changed, bool p_basic) {
  1174. ERR_FAIL_NULL_V_MSG(EditorSettings::get_singleton(), p_default, "EditorSettings not instantiated yet.");
  1175. Variant ret = p_default;
  1176. if (EditorSettings::get_singleton()->has_setting(p_setting)) {
  1177. ret = EDITOR_GET(p_setting);
  1178. } else {
  1179. EditorSettings::get_singleton()->set_manually(p_setting, p_default);
  1180. }
  1181. EditorSettings::get_singleton()->set_restart_if_changed(p_setting, p_restart_if_changed);
  1182. EditorSettings::get_singleton()->set_basic(p_setting, p_basic);
  1183. if (!EditorSettings::get_singleton()->has_default_value(p_setting)) {
  1184. EditorSettings::get_singleton()->set_initial_value(p_setting, p_default);
  1185. }
  1186. return ret;
  1187. }
  1188. Variant _EDITOR_GET(const String &p_setting) {
  1189. ERR_FAIL_COND_V(!EditorSettings::get_singleton() || !EditorSettings::get_singleton()->has_setting(p_setting), Variant());
  1190. return EditorSettings::get_singleton()->get(p_setting);
  1191. }
  1192. bool EditorSettings::_property_can_revert(const StringName &p_name) const {
  1193. const VariantContainer *property = props.getptr(p_name);
  1194. if (property) {
  1195. return property->has_default_value;
  1196. }
  1197. return false;
  1198. }
  1199. bool EditorSettings::_property_get_revert(const StringName &p_name, Variant &r_property) const {
  1200. const VariantContainer *value = props.getptr(p_name);
  1201. if (value && value->has_default_value) {
  1202. r_property = value->initial;
  1203. return true;
  1204. }
  1205. return false;
  1206. }
  1207. void EditorSettings::add_property_hint(const PropertyInfo &p_hint) {
  1208. _THREAD_SAFE_METHOD_
  1209. hints[p_hint.name] = p_hint;
  1210. }
  1211. // Metadata
  1212. void EditorSettings::set_project_metadata(const String &p_section, const String &p_key, const Variant &p_data) {
  1213. const String path = _get_project_metadata_path();
  1214. if (project_metadata.is_null()) {
  1215. project_metadata.instantiate();
  1216. Error err = project_metadata->load(path);
  1217. if (err != OK && err != ERR_FILE_NOT_FOUND) {
  1218. ERR_PRINT("Cannot load project metadata from file '" + path + "'.");
  1219. }
  1220. }
  1221. project_metadata->set_value(p_section, p_key, p_data);
  1222. Error err = project_metadata->save(path);
  1223. ERR_FAIL_COND_MSG(err != OK, "Cannot save project metadata to file '" + path + "'.");
  1224. }
  1225. Variant EditorSettings::get_project_metadata(const String &p_section, const String &p_key, const Variant &p_default) const {
  1226. if (project_metadata.is_null()) {
  1227. project_metadata.instantiate();
  1228. const String path = _get_project_metadata_path();
  1229. Error err = project_metadata->load(path);
  1230. ERR_FAIL_COND_V_MSG(err != OK && err != ERR_FILE_NOT_FOUND, p_default, "Cannot load project metadata from file '" + path + "'.");
  1231. }
  1232. return project_metadata->get_value(p_section, p_key, p_default);
  1233. }
  1234. void EditorSettings::set_favorites(const Vector<String> &p_favorites) {
  1235. favorites = p_favorites;
  1236. String favorites_file;
  1237. if (Engine::get_singleton()->is_project_manager_hint()) {
  1238. favorites_file = EditorPaths::get_singleton()->get_config_dir().path_join("favorite_dirs");
  1239. } else {
  1240. favorites_file = EditorPaths::get_singleton()->get_project_settings_dir().path_join("favorites");
  1241. }
  1242. Ref<FileAccess> f = FileAccess::open(favorites_file, FileAccess::WRITE);
  1243. if (f.is_valid()) {
  1244. for (int i = 0; i < favorites.size(); i++) {
  1245. f->store_line(favorites[i]);
  1246. }
  1247. }
  1248. }
  1249. void EditorSettings::set_favorite_properties(const HashMap<String, PackedStringArray> &p_favorite_properties) {
  1250. favorite_properties = p_favorite_properties;
  1251. String favorite_properties_file = EditorPaths::get_singleton()->get_project_settings_dir().path_join("favorite_properties");
  1252. Ref<ConfigFile> cf;
  1253. cf.instantiate();
  1254. for (const KeyValue<String, PackedStringArray> &kv : p_favorite_properties) {
  1255. cf->set_value(kv.key, "properties", kv.value);
  1256. }
  1257. cf->save(favorite_properties_file);
  1258. }
  1259. Vector<String> EditorSettings::get_favorites() const {
  1260. return favorites;
  1261. }
  1262. HashMap<String, PackedStringArray> EditorSettings::get_favorite_properties() const {
  1263. return favorite_properties;
  1264. }
  1265. void EditorSettings::set_recent_dirs(const Vector<String> &p_recent_dirs) {
  1266. recent_dirs = p_recent_dirs;
  1267. String recent_dirs_file;
  1268. if (Engine::get_singleton()->is_project_manager_hint()) {
  1269. recent_dirs_file = EditorPaths::get_singleton()->get_config_dir().path_join("recent_dirs");
  1270. } else {
  1271. recent_dirs_file = EditorPaths::get_singleton()->get_project_settings_dir().path_join("recent_dirs");
  1272. }
  1273. Ref<FileAccess> f = FileAccess::open(recent_dirs_file, FileAccess::WRITE);
  1274. if (f.is_valid()) {
  1275. for (int i = 0; i < recent_dirs.size(); i++) {
  1276. f->store_line(recent_dirs[i]);
  1277. }
  1278. }
  1279. }
  1280. Vector<String> EditorSettings::get_recent_dirs() const {
  1281. return recent_dirs;
  1282. }
  1283. void EditorSettings::load_favorites_and_recent_dirs() {
  1284. String favorites_file;
  1285. String favorite_properties_file;
  1286. String recent_dirs_file;
  1287. if (Engine::get_singleton()->is_project_manager_hint()) {
  1288. favorites_file = EditorPaths::get_singleton()->get_config_dir().path_join("favorite_dirs");
  1289. favorite_properties_file = EditorPaths::get_singleton()->get_config_dir().path_join("favorite_properties");
  1290. recent_dirs_file = EditorPaths::get_singleton()->get_config_dir().path_join("recent_dirs");
  1291. } else {
  1292. favorites_file = EditorPaths::get_singleton()->get_project_settings_dir().path_join("favorites");
  1293. favorite_properties_file = EditorPaths::get_singleton()->get_project_settings_dir().path_join("favorite_properties");
  1294. recent_dirs_file = EditorPaths::get_singleton()->get_project_settings_dir().path_join("recent_dirs");
  1295. }
  1296. /// File Favorites
  1297. Ref<FileAccess> f = FileAccess::open(favorites_file, FileAccess::READ);
  1298. if (f.is_valid()) {
  1299. String line = f->get_line().strip_edges();
  1300. while (!line.is_empty()) {
  1301. favorites.append(line);
  1302. line = f->get_line().strip_edges();
  1303. }
  1304. }
  1305. /// Inspector Favorites
  1306. Ref<ConfigFile> cf;
  1307. cf.instantiate();
  1308. if (cf->load(favorite_properties_file) == OK) {
  1309. List<String> secs;
  1310. cf->get_sections(&secs);
  1311. for (String &E : secs) {
  1312. PackedStringArray properties = PackedStringArray(cf->get_value(E, "properties"));
  1313. if (EditorNode::get_editor_data().is_type_recognized(E) || ResourceLoader::exists(E, "Script")) {
  1314. for (const String &property : properties) {
  1315. if (!favorite_properties[E].has(property)) {
  1316. favorite_properties[E].push_back(property);
  1317. }
  1318. }
  1319. }
  1320. }
  1321. }
  1322. /// Recent Directories
  1323. f = FileAccess::open(recent_dirs_file, FileAccess::READ);
  1324. if (f.is_valid()) {
  1325. String line = f->get_line().strip_edges();
  1326. while (!line.is_empty()) {
  1327. recent_dirs.push_back(line);
  1328. line = f->get_line().strip_edges();
  1329. }
  1330. }
  1331. }
  1332. void EditorSettings::list_text_editor_themes() {
  1333. String themes = "Default,Godot 2,Custom";
  1334. Ref<DirAccess> d = DirAccess::open(EditorPaths::get_singleton()->get_text_editor_themes_dir());
  1335. if (d.is_valid()) {
  1336. List<String> custom_themes;
  1337. d->list_dir_begin();
  1338. String file = d->get_next();
  1339. while (!file.is_empty()) {
  1340. if (file.get_extension() == "tet" && !_is_default_text_editor_theme(file.get_basename().to_lower())) {
  1341. custom_themes.push_back(file.get_basename());
  1342. }
  1343. file = d->get_next();
  1344. }
  1345. d->list_dir_end();
  1346. custom_themes.sort();
  1347. for (const String &E : custom_themes) {
  1348. themes += "," + E;
  1349. }
  1350. }
  1351. add_property_hint(PropertyInfo(Variant::STRING, "text_editor/theme/color_theme", PROPERTY_HINT_ENUM, themes));
  1352. }
  1353. void EditorSettings::load_text_editor_theme() {
  1354. String p_file = get("text_editor/theme/color_theme");
  1355. if (_is_default_text_editor_theme(p_file.get_file().to_lower())) {
  1356. if (p_file == "Godot 2") {
  1357. _load_godot2_text_editor_theme();
  1358. }
  1359. return; // sorry for "Settings changed" console spam
  1360. }
  1361. String theme_path = EditorPaths::get_singleton()->get_text_editor_themes_dir().path_join(p_file + ".tet");
  1362. Ref<ConfigFile> cf = memnew(ConfigFile);
  1363. Error err = cf->load(theme_path);
  1364. if (err != OK) {
  1365. return;
  1366. }
  1367. List<String> keys;
  1368. cf->get_section_keys("color_theme", &keys);
  1369. for (const String &key : keys) {
  1370. String val = cf->get_value("color_theme", key);
  1371. // don't load if it's not already there!
  1372. if (has_setting("text_editor/theme/highlighting/" + key)) {
  1373. // make sure it is actually a color
  1374. if (val.is_valid_html_color() && key.contains("color")) {
  1375. props["text_editor/theme/highlighting/" + key].variant = Color::html(val); // change manually to prevent "Settings changed" console spam
  1376. }
  1377. }
  1378. }
  1379. emit_signal(SNAME("settings_changed"));
  1380. // if it doesn't load just use what is currently loaded
  1381. }
  1382. bool EditorSettings::import_text_editor_theme(const String &p_file) {
  1383. if (!p_file.ends_with(".tet")) {
  1384. return false;
  1385. } else {
  1386. if (p_file.get_file().to_lower() == "default.tet") {
  1387. return false;
  1388. }
  1389. Ref<DirAccess> d = DirAccess::open(EditorPaths::get_singleton()->get_text_editor_themes_dir());
  1390. if (d.is_valid()) {
  1391. d->copy(p_file, EditorPaths::get_singleton()->get_text_editor_themes_dir().path_join(p_file.get_file()));
  1392. return true;
  1393. }
  1394. }
  1395. return false;
  1396. }
  1397. bool EditorSettings::save_text_editor_theme() {
  1398. String p_file = get("text_editor/theme/color_theme");
  1399. if (_is_default_text_editor_theme(p_file.get_file().to_lower())) {
  1400. return false;
  1401. }
  1402. String theme_path = EditorPaths::get_singleton()->get_text_editor_themes_dir().path_join(p_file + ".tet");
  1403. return _save_text_editor_theme(theme_path);
  1404. }
  1405. bool EditorSettings::save_text_editor_theme_as(String p_file) {
  1406. if (!p_file.ends_with(".tet")) {
  1407. p_file += ".tet";
  1408. }
  1409. if (_is_default_text_editor_theme(p_file.get_file().to_lower().trim_suffix(".tet"))) {
  1410. return false;
  1411. }
  1412. if (_save_text_editor_theme(p_file)) {
  1413. // switch to theme is saved in the theme directory
  1414. list_text_editor_themes();
  1415. String theme_name = p_file.substr(0, p_file.length() - 4).get_file();
  1416. if (p_file.get_base_dir() == EditorPaths::get_singleton()->get_text_editor_themes_dir()) {
  1417. _initial_set("text_editor/theme/color_theme", theme_name);
  1418. load_text_editor_theme();
  1419. }
  1420. return true;
  1421. }
  1422. return false;
  1423. }
  1424. bool EditorSettings::is_default_text_editor_theme() {
  1425. String p_file = get("text_editor/theme/color_theme");
  1426. return _is_default_text_editor_theme(p_file.get_file().to_lower());
  1427. }
  1428. Vector<String> EditorSettings::get_script_templates(const String &p_extension, const String &p_custom_path) {
  1429. Vector<String> templates;
  1430. String template_dir = EditorPaths::get_singleton()->get_script_templates_dir();
  1431. if (!p_custom_path.is_empty()) {
  1432. template_dir = p_custom_path;
  1433. }
  1434. Ref<DirAccess> d = DirAccess::open(template_dir);
  1435. if (d.is_valid()) {
  1436. d->list_dir_begin();
  1437. String file = d->get_next();
  1438. while (!file.is_empty()) {
  1439. if (file.get_extension() == p_extension) {
  1440. templates.push_back(file.get_basename());
  1441. }
  1442. file = d->get_next();
  1443. }
  1444. d->list_dir_end();
  1445. }
  1446. return templates;
  1447. }
  1448. String EditorSettings::get_editor_layouts_config() const {
  1449. return EditorPaths::get_singleton()->get_config_dir().path_join("editor_layouts.cfg");
  1450. }
  1451. float EditorSettings::get_auto_display_scale() const {
  1452. #ifdef LINUXBSD_ENABLED
  1453. if (DisplayServer::get_singleton()->get_name() == "Wayland") {
  1454. float main_window_scale = DisplayServer::get_singleton()->screen_get_scale(DisplayServer::SCREEN_OF_MAIN_WINDOW);
  1455. if (DisplayServer::get_singleton()->get_screen_count() == 1 || Math::fract(main_window_scale) != 0) {
  1456. // If we have a single screen or the screen of the window is fractional, all
  1457. // bets are off. At this point, let's just return the current's window scale,
  1458. // which is special-cased to the scale of `SCREEN_OF_MAIN_WINDOW`.
  1459. return main_window_scale;
  1460. }
  1461. // If the above branch didn't fire, fractional scaling isn't going to work
  1462. // properly anyways (we're need the ability to change the UI scale at runtime).
  1463. // At this point it's more convenient to "supersample" like we do with other
  1464. // platforms, hoping that the user is only using integer-scaled screens.
  1465. return DisplayServer::get_singleton()->screen_get_max_scale();
  1466. }
  1467. #endif
  1468. #if defined(MACOS_ENABLED) || defined(ANDROID_ENABLED)
  1469. return DisplayServer::get_singleton()->screen_get_max_scale();
  1470. #else
  1471. const int screen = DisplayServer::get_singleton()->window_get_current_screen();
  1472. if (DisplayServer::get_singleton()->screen_get_size(screen) == Vector2i()) {
  1473. // Invalid screen size, skip.
  1474. return 1.0;
  1475. }
  1476. // Use the smallest dimension to use a correct display scale on portrait displays.
  1477. const int smallest_dimension = MIN(DisplayServer::get_singleton()->screen_get_size(screen).x, DisplayServer::get_singleton()->screen_get_size(screen).y);
  1478. if (DisplayServer::get_singleton()->screen_get_dpi(screen) >= 192 && smallest_dimension >= 1400) {
  1479. // hiDPI display.
  1480. return 2.0;
  1481. } else if (smallest_dimension >= 1700) {
  1482. // Likely a hiDPI display, but we aren't certain due to the returned DPI.
  1483. // Use an intermediate scale to handle this situation.
  1484. return 1.5;
  1485. } else if (smallest_dimension <= 800) {
  1486. // Small loDPI display. Use a smaller display scale so that editor elements fit more easily.
  1487. // Icons won't look great, but this is better than having editor elements overflow from its window.
  1488. return 0.75;
  1489. }
  1490. return 1.0;
  1491. #endif
  1492. }
  1493. // Shortcuts
  1494. void EditorSettings::_add_shortcut_default(const String &p_name, const Ref<Shortcut> &p_shortcut) {
  1495. shortcuts[p_name] = p_shortcut;
  1496. }
  1497. void EditorSettings::add_shortcut(const String &p_name, const Ref<Shortcut> &p_shortcut) {
  1498. shortcuts[p_name] = p_shortcut;
  1499. shortcuts[p_name]->set_meta("customized", true);
  1500. }
  1501. bool EditorSettings::is_shortcut(const String &p_name, const Ref<InputEvent> &p_event) const {
  1502. HashMap<String, Ref<Shortcut>>::ConstIterator E = shortcuts.find(p_name);
  1503. ERR_FAIL_COND_V_MSG(!E, false, "Unknown Shortcut: " + p_name + ".");
  1504. return E->value->matches_event(p_event);
  1505. }
  1506. Ref<Shortcut> EditorSettings::get_shortcut(const String &p_name) const {
  1507. HashMap<String, Ref<Shortcut>>::ConstIterator SC = shortcuts.find(p_name);
  1508. if (SC) {
  1509. return SC->value;
  1510. }
  1511. // If no shortcut with the provided name is found in the list, check the built-in shortcuts.
  1512. // Use the first item in the action list for the shortcut event, since a shortcut can only have 1 linked event.
  1513. Ref<Shortcut> sc;
  1514. HashMap<String, List<Ref<InputEvent>>>::ConstIterator builtin_override = builtin_action_overrides.find(p_name);
  1515. if (builtin_override) {
  1516. sc.instantiate();
  1517. sc->set_events_list(&builtin_override->value);
  1518. sc->set_name(InputMap::get_singleton()->get_builtin_display_name(p_name));
  1519. }
  1520. // If there was no override, check the default builtins to see if it has an InputEvent for the provided name.
  1521. if (sc.is_null()) {
  1522. HashMap<String, List<Ref<InputEvent>>>::ConstIterator builtin_default = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied().find(p_name);
  1523. if (builtin_default) {
  1524. sc.instantiate();
  1525. sc->set_events_list(&builtin_default->value);
  1526. sc->set_name(InputMap::get_singleton()->get_builtin_display_name(p_name));
  1527. }
  1528. }
  1529. if (sc.is_valid()) {
  1530. // Add the shortcut to the list.
  1531. shortcuts[p_name] = sc;
  1532. return sc;
  1533. }
  1534. return Ref<Shortcut>();
  1535. }
  1536. void EditorSettings::get_shortcut_list(List<String> *r_shortcuts) {
  1537. for (const KeyValue<String, Ref<Shortcut>> &E : shortcuts) {
  1538. r_shortcuts->push_back(E.key);
  1539. }
  1540. }
  1541. Ref<Shortcut> ED_GET_SHORTCUT(const String &p_path) {
  1542. ERR_FAIL_NULL_V_MSG(EditorSettings::get_singleton(), nullptr, "EditorSettings not instantiated yet.");
  1543. Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
  1544. ERR_FAIL_COND_V_MSG(!sc.is_valid(), sc, "Used ED_GET_SHORTCUT with invalid shortcut: " + p_path);
  1545. return sc;
  1546. }
  1547. void ED_SHORTCUT_OVERRIDE(const String &p_path, const String &p_feature, Key p_keycode, bool p_physical) {
  1548. if (!EditorSettings::get_singleton()) {
  1549. return;
  1550. }
  1551. Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
  1552. ERR_FAIL_COND_MSG(!sc.is_valid(), "Used ED_SHORTCUT_OVERRIDE with invalid shortcut: " + p_path);
  1553. PackedInt32Array arr;
  1554. arr.push_back((int32_t)p_keycode);
  1555. ED_SHORTCUT_OVERRIDE_ARRAY(p_path, p_feature, arr, p_physical);
  1556. }
  1557. void ED_SHORTCUT_OVERRIDE_ARRAY(const String &p_path, const String &p_feature, const PackedInt32Array &p_keycodes, bool p_physical) {
  1558. if (!EditorSettings::get_singleton()) {
  1559. return;
  1560. }
  1561. Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
  1562. ERR_FAIL_COND_MSG(!sc.is_valid(), "Used ED_SHORTCUT_OVERRIDE_ARRAY with invalid shortcut: " + p_path);
  1563. // Only add the override if the OS supports the provided feature.
  1564. if (!OS::get_singleton()->has_feature(p_feature)) {
  1565. if (!(p_feature == "macos" && (OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios")))) {
  1566. return;
  1567. }
  1568. }
  1569. Array events;
  1570. for (int i = 0; i < p_keycodes.size(); i++) {
  1571. Key keycode = (Key)p_keycodes[i];
  1572. if (OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios")) {
  1573. // Use Cmd+Backspace as a general replacement for Delete shortcuts on macOS
  1574. if (keycode == Key::KEY_DELETE) {
  1575. keycode = KeyModifierMask::META | Key::BACKSPACE;
  1576. }
  1577. }
  1578. Ref<InputEventKey> ie;
  1579. if (keycode != Key::NONE) {
  1580. ie = InputEventKey::create_reference(keycode, p_physical);
  1581. events.push_back(ie);
  1582. }
  1583. }
  1584. // Override the existing shortcut only if it wasn't customized by the user.
  1585. if (!sc->has_meta("customized")) {
  1586. sc->set_events(events);
  1587. }
  1588. sc->set_meta("original", events.duplicate(true));
  1589. }
  1590. Ref<Shortcut> ED_SHORTCUT(const String &p_path, const String &p_name, Key p_keycode, bool p_physical) {
  1591. PackedInt32Array arr;
  1592. arr.push_back((int32_t)p_keycode);
  1593. return ED_SHORTCUT_ARRAY(p_path, p_name, arr, p_physical);
  1594. }
  1595. Ref<Shortcut> ED_SHORTCUT_ARRAY(const String &p_path, const String &p_name, const PackedInt32Array &p_keycodes, bool p_physical) {
  1596. Array events;
  1597. for (int i = 0; i < p_keycodes.size(); i++) {
  1598. Key keycode = (Key)p_keycodes[i];
  1599. if (OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios")) {
  1600. // Use Cmd+Backspace as a general replacement for Delete shortcuts on macOS
  1601. if (keycode == Key::KEY_DELETE) {
  1602. keycode = KeyModifierMask::META | Key::BACKSPACE;
  1603. }
  1604. }
  1605. Ref<InputEventKey> ie;
  1606. if (keycode != Key::NONE) {
  1607. ie = InputEventKey::create_reference(keycode, p_physical);
  1608. events.push_back(ie);
  1609. }
  1610. }
  1611. if (!EditorSettings::get_singleton()) {
  1612. Ref<Shortcut> sc;
  1613. sc.instantiate();
  1614. sc->set_name(p_name);
  1615. sc->set_events(events);
  1616. sc->set_meta("original", events.duplicate(true));
  1617. return sc;
  1618. }
  1619. Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
  1620. if (sc.is_valid()) {
  1621. sc->set_name(p_name); //keep name (the ones that come from disk have no name)
  1622. sc->set_meta("original", events.duplicate(true)); //to compare against changes
  1623. return sc;
  1624. }
  1625. sc.instantiate();
  1626. sc->set_name(p_name);
  1627. sc->set_events(events);
  1628. sc->set_meta("original", events.duplicate(true)); //to compare against changes
  1629. EditorSettings::get_singleton()->_add_shortcut_default(p_path, sc);
  1630. return sc;
  1631. }
  1632. void EditorSettings::set_builtin_action_override(const String &p_name, const TypedArray<InputEvent> &p_events) {
  1633. List<Ref<InputEvent>> event_list;
  1634. // Override the whole list, since events may have their order changed or be added, removed or edited.
  1635. InputMap::get_singleton()->action_erase_events(p_name);
  1636. for (int i = 0; i < p_events.size(); i++) {
  1637. event_list.push_back(p_events[i]);
  1638. InputMap::get_singleton()->action_add_event(p_name, p_events[i]);
  1639. }
  1640. // Check if the provided event array is same as built-in. If it is, it does not need to be added to the overrides.
  1641. // Note that event order must also be the same.
  1642. bool same_as_builtin = true;
  1643. HashMap<String, List<Ref<InputEvent>>>::ConstIterator builtin_default = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied().find(p_name);
  1644. if (builtin_default) {
  1645. const List<Ref<InputEvent>> &builtin_events = builtin_default->value;
  1646. // In the editor we only care about key events.
  1647. List<Ref<InputEventKey>> builtin_key_events;
  1648. for (Ref<InputEventKey> iek : builtin_events) {
  1649. if (iek.is_valid()) {
  1650. builtin_key_events.push_back(iek);
  1651. }
  1652. }
  1653. if (p_events.size() == builtin_key_events.size()) {
  1654. int event_idx = 0;
  1655. // Check equality of each event.
  1656. for (const Ref<InputEventKey> &E : builtin_key_events) {
  1657. if (!E->is_match(p_events[event_idx])) {
  1658. same_as_builtin = false;
  1659. break;
  1660. }
  1661. event_idx++;
  1662. }
  1663. } else {
  1664. same_as_builtin = false;
  1665. }
  1666. }
  1667. if (same_as_builtin && builtin_action_overrides.has(p_name)) {
  1668. builtin_action_overrides.erase(p_name);
  1669. } else {
  1670. builtin_action_overrides[p_name] = event_list;
  1671. }
  1672. // Update the shortcut (if it is used somewhere in the editor) to be the first event of the new list.
  1673. if (shortcuts.has(p_name)) {
  1674. shortcuts[p_name]->set_events_list(&event_list);
  1675. }
  1676. }
  1677. const Array EditorSettings::get_builtin_action_overrides(const String &p_name) const {
  1678. HashMap<String, List<Ref<InputEvent>>>::ConstIterator AO = builtin_action_overrides.find(p_name);
  1679. if (AO) {
  1680. Array event_array;
  1681. List<Ref<InputEvent>> events_list = AO->value;
  1682. for (const Ref<InputEvent> &E : events_list) {
  1683. event_array.push_back(E);
  1684. }
  1685. return event_array;
  1686. }
  1687. return Array();
  1688. }
  1689. void EditorSettings::notify_changes() {
  1690. _THREAD_SAFE_METHOD_
  1691. SceneTree *sml = Object::cast_to<SceneTree>(OS::get_singleton()->get_main_loop());
  1692. if (!sml) {
  1693. return;
  1694. }
  1695. Node *root = sml->get_root()->get_child(0);
  1696. if (!root) {
  1697. return;
  1698. }
  1699. root->propagate_notification(NOTIFICATION_EDITOR_SETTINGS_CHANGED);
  1700. }
  1701. #ifdef TOOLS_ENABLED
  1702. void EditorSettings::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
  1703. const String pf = p_function;
  1704. if (p_idx == 0) {
  1705. if (pf == "has_setting" || pf == "set_setting" || pf == "get_setting" || pf == "erase" ||
  1706. pf == "set_initial_value" || pf == "set_as_basic" || pf == "mark_setting_changed") {
  1707. for (const KeyValue<String, VariantContainer> &E : props) {
  1708. if (E.value.hide_from_editor) {
  1709. continue;
  1710. }
  1711. r_options->push_back(E.key.quote());
  1712. }
  1713. } else if (pf == "get_project_metadata" && project_metadata.is_valid()) {
  1714. List<String> sections;
  1715. project_metadata->get_sections(&sections);
  1716. for (const String &section : sections) {
  1717. r_options->push_back(section.quote());
  1718. }
  1719. } else if (pf == "set_builtin_action_override") {
  1720. for (const StringName &action : InputMap::get_singleton()->get_actions()) {
  1721. r_options->push_back(String(action).quote());
  1722. }
  1723. }
  1724. }
  1725. Object::get_argument_options(p_function, p_idx, r_options);
  1726. }
  1727. #endif
  1728. void EditorSettings::_bind_methods() {
  1729. ClassDB::bind_method(D_METHOD("has_setting", "name"), &EditorSettings::has_setting);
  1730. ClassDB::bind_method(D_METHOD("set_setting", "name", "value"), &EditorSettings::set_setting);
  1731. ClassDB::bind_method(D_METHOD("get_setting", "name"), &EditorSettings::get_setting);
  1732. ClassDB::bind_method(D_METHOD("erase", "property"), &EditorSettings::erase);
  1733. ClassDB::bind_method(D_METHOD("set_initial_value", "name", "value", "update_current"), &EditorSettings::set_initial_value);
  1734. ClassDB::bind_method(D_METHOD("add_property_info", "info"), &EditorSettings::_add_property_info_bind);
  1735. ClassDB::bind_method(D_METHOD("set_project_metadata", "section", "key", "data"), &EditorSettings::set_project_metadata);
  1736. ClassDB::bind_method(D_METHOD("get_project_metadata", "section", "key", "default"), &EditorSettings::get_project_metadata, DEFVAL(Variant()));
  1737. ClassDB::bind_method(D_METHOD("set_favorites", "dirs"), &EditorSettings::set_favorites);
  1738. ClassDB::bind_method(D_METHOD("get_favorites"), &EditorSettings::get_favorites);
  1739. ClassDB::bind_method(D_METHOD("set_recent_dirs", "dirs"), &EditorSettings::set_recent_dirs);
  1740. ClassDB::bind_method(D_METHOD("get_recent_dirs"), &EditorSettings::get_recent_dirs);
  1741. ClassDB::bind_method(D_METHOD("set_builtin_action_override", "name", "actions_list"), &EditorSettings::set_builtin_action_override);
  1742. ClassDB::bind_method(D_METHOD("check_changed_settings_in_group", "setting_prefix"), &EditorSettings::check_changed_settings_in_group);
  1743. ClassDB::bind_method(D_METHOD("get_changed_settings"), &EditorSettings::get_changed_settings);
  1744. ClassDB::bind_method(D_METHOD("mark_setting_changed", "setting"), &EditorSettings::mark_setting_changed);
  1745. ADD_SIGNAL(MethodInfo("settings_changed"));
  1746. BIND_CONSTANT(NOTIFICATION_EDITOR_SETTINGS_CHANGED);
  1747. }
  1748. EditorSettings::EditorSettings() {
  1749. last_order = 0;
  1750. _load_defaults();
  1751. callable_mp(this, &EditorSettings::_set_initialized).call_deferred();
  1752. }