-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
/
editor_settings.cpp
1682 lines (1383 loc) · 65 KB
/
editor_settings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*************************************************************************/
/* editor_settings.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "editor_settings.h"
#include "core/config/project_settings.h"
#include "core/input/input_event.h"
#include "core/input/input_map.h"
#include "core/input/shortcut.h"
#include "core/io/certs_compressed.gen.h"
#include "core/io/dir_access.h"
#include "core/io/file_access.h"
#include "core/io/ip.h"
#include "core/io/resource_loader.h"
#include "core/io/resource_saver.h"
#include "core/object/class_db.h"
#include "core/os/keyboard.h"
#include "core/os/os.h"
#include "core/string/translation.h"
#include "core/version.h"
#include "editor/editor_node.h"
#include "editor/editor_paths.h"
#include "editor/editor_translation.h"
#include "scene/main/node.h"
#include "scene/main/scene_tree.h"
#include "scene/main/window.h"
// PRIVATE METHODS
Ref<EditorSettings> EditorSettings::singleton = nullptr;
// Properties
bool EditorSettings::_set(const StringName &p_name, const Variant &p_value) {
_THREAD_SAFE_METHOD_
bool changed = _set_only(p_name, p_value);
if (changed) {
changed_settings.insert(p_name);
emit_signal(SNAME("settings_changed"));
}
return true;
}
bool EditorSettings::_set_only(const StringName &p_name, const Variant &p_value) {
_THREAD_SAFE_METHOD_
if (p_name == "shortcuts") {
Array arr = p_value;
for (int i = 0; i < arr.size(); i++) {
Dictionary dict = arr[i];
String name = dict["name"];
Array shortcut_events = dict["shortcuts"];
Ref<Shortcut> sc;
sc.instantiate();
sc->set_events(shortcut_events);
add_shortcut(name, sc);
}
return false;
} else if (p_name == "builtin_action_overrides") {
Array actions_arr = p_value;
for (int i = 0; i < actions_arr.size(); i++) {
Dictionary action_dict = actions_arr[i];
String name = action_dict["name"];
Array events = action_dict["events"];
InputMap *im = InputMap::get_singleton();
im->action_erase_events(name);
builtin_action_overrides[name].clear();
for (int ev_idx = 0; ev_idx < events.size(); ev_idx++) {
im->action_add_event(name, events[ev_idx]);
builtin_action_overrides[name].push_back(events[ev_idx]);
}
}
return false;
}
bool changed = false;
if (p_value.get_type() == Variant::NIL) {
if (props.has(p_name)) {
props.erase(p_name);
changed = true;
}
} else {
if (props.has(p_name)) {
if (p_value != props[p_name].variant) {
props[p_name].variant = p_value;
changed = true;
}
} else {
props[p_name] = VariantContainer(p_value, last_order++);
changed = true;
}
if (save_changed_setting) {
if (!props[p_name].save) {
props[p_name].save = true;
changed = true;
}
}
}
return changed;
}
bool EditorSettings::_get(const StringName &p_name, Variant &r_ret) const {
_THREAD_SAFE_METHOD_
if (p_name == "shortcuts") {
Array save_array;
const HashMap<String, List<Ref<InputEvent>>> &builtin_list = InputMap::get_singleton()->get_builtins();
for (const KeyValue<String, Ref<Shortcut>> &shortcut_definition : shortcuts) {
Ref<Shortcut> sc = shortcut_definition.value;
if (builtin_list.has(shortcut_definition.key)) {
// This shortcut was auto-generated from built in actions: don't save.
// If the builtin is overridden, it will be saved in the "builtin_action_overrides" section below.
continue;
}
Array shortcut_events = sc->get_events();
Dictionary dict;
dict["name"] = shortcut_definition.key;
dict["shortcuts"] = shortcut_events;
if (!sc->has_meta("original")) {
// Getting the meta when it doesn't exist will return an empty array. If the 'shortcut_events' have been cleared,
// we still want save the shortcut in this case so that shortcuts that the user has customised are not reset,
// even if the 'original' has not been populated yet. This can happen when calling save() from the Project Manager.
save_array.push_back(dict);
continue;
}
Array original_events = sc->get_meta("original");
bool is_same = Shortcut::is_event_array_equal(original_events, shortcut_events);
if (is_same) {
continue; // Not changed from default; don't save.
}
save_array.push_back(dict);
}
r_ret = save_array;
return true;
} else if (p_name == "builtin_action_overrides") {
Array actions_arr;
for (const KeyValue<String, List<Ref<InputEvent>>> &action_override : builtin_action_overrides) {
List<Ref<InputEvent>> events = action_override.value;
Dictionary action_dict;
action_dict["name"] = action_override.key;
// Convert the list to an array, and only keep key events as this is for the editor.
Array events_arr;
for (const Ref<InputEvent> &ie : events) {
Ref<InputEventKey> iek = ie;
if (iek.is_valid()) {
events_arr.append(iek);
}
}
Array defaults_arr;
List<Ref<InputEvent>> defaults = InputMap::get_singleton()->get_builtins()[action_override.key];
for (const Ref<InputEvent> &default_input_event : defaults) {
if (default_input_event.is_valid()) {
defaults_arr.append(default_input_event);
}
}
bool same = Shortcut::is_event_array_equal(events_arr, defaults_arr);
// Don't save if same as default.
if (same) {
continue;
}
action_dict["events"] = events_arr;
actions_arr.push_back(action_dict);
}
r_ret = actions_arr;
return true;
}
const VariantContainer *v = props.getptr(p_name);
if (!v) {
WARN_PRINT("EditorSettings::_get - Property not found: " + String(p_name));
return false;
}
r_ret = v->variant;
return true;
}
void EditorSettings::_initial_set(const StringName &p_name, const Variant &p_value) {
set(p_name, p_value);
props[p_name].initial = p_value;
props[p_name].has_default_value = true;
}
struct _EVCSort {
String name;
Variant::Type type = Variant::Type::NIL;
int order = 0;
bool save = false;
bool restart_if_changed = false;
bool operator<(const _EVCSort &p_vcs) const { return order < p_vcs.order; }
};
void EditorSettings::_get_property_list(List<PropertyInfo> *p_list) const {
_THREAD_SAFE_METHOD_
RBSet<_EVCSort> vclist;
for (const KeyValue<String, VariantContainer> &E : props) {
const VariantContainer *v = &E.value;
if (v->hide_from_editor) {
continue;
}
_EVCSort vc;
vc.name = E.key;
vc.order = v->order;
vc.type = v->variant.get_type();
vc.save = v->save;
/*if (vc.save) { this should be implemented, but lets do after 3.1 is out.
if (v->initial.get_type() != Variant::NIL && v->initial == v->variant) {
vc.save = false;
}
}*/
vc.restart_if_changed = v->restart_if_changed;
vclist.insert(vc);
}
for (const _EVCSort &E : vclist) {
uint32_t pusage = PROPERTY_USAGE_NONE;
if (E.save || !optimize_save) {
pusage |= PROPERTY_USAGE_STORAGE;
}
if (!E.name.begins_with("_") && !E.name.begins_with("projects/")) {
pusage |= PROPERTY_USAGE_EDITOR;
} else {
pusage |= PROPERTY_USAGE_STORAGE; //hiddens must always be saved
}
PropertyInfo pi(E.type, E.name);
pi.usage = pusage;
if (hints.has(E.name)) {
pi = hints[E.name];
}
if (E.restart_if_changed) {
pi.usage |= PROPERTY_USAGE_RESTART_IF_CHANGED;
}
p_list->push_back(pi);
}
p_list->push_back(PropertyInfo(Variant::ARRAY, "shortcuts", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL)); //do not edit
p_list->push_back(PropertyInfo(Variant::ARRAY, "builtin_action_overrides", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));
}
void EditorSettings::_add_property_info_bind(const Dictionary &p_info) {
ERR_FAIL_COND(!p_info.has("name"));
ERR_FAIL_COND(!p_info.has("type"));
PropertyInfo pinfo;
pinfo.name = p_info["name"];
ERR_FAIL_COND(!props.has(pinfo.name));
pinfo.type = Variant::Type(p_info["type"].operator int());
ERR_FAIL_INDEX(pinfo.type, Variant::VARIANT_MAX);
if (p_info.has("hint")) {
pinfo.hint = PropertyHint(p_info["hint"].operator int());
}
if (p_info.has("hint_string")) {
pinfo.hint_string = p_info["hint_string"];
}
add_property_hint(pinfo);
}
// Default configs
bool EditorSettings::has_default_value(const String &p_setting) const {
_THREAD_SAFE_METHOD_
if (!props.has(p_setting)) {
return false;
}
return props[p_setting].has_default_value;
}
void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
_THREAD_SAFE_METHOD_
// Sets up the editor setting with a default value and hint PropertyInfo.
#define EDITOR_SETTING(m_type, m_property_hint, m_name, m_default_value, m_hint_string) \
_initial_set(m_name, m_default_value); \
hints[m_name] = PropertyInfo(m_type, m_name, m_property_hint, m_hint_string);
#define EDITOR_SETTING_USAGE(m_type, m_property_hint, m_name, m_default_value, m_hint_string, m_usage) \
_initial_set(m_name, m_default_value); \
hints[m_name] = PropertyInfo(m_type, m_name, m_property_hint, m_hint_string, m_usage);
/* Languages */
{
String lang_hint = "en";
String host_lang = OS::get_singleton()->get_locale();
// Skip locales if Text server lack required features.
Vector<String> locales_to_skip;
if (!TS->has_feature(TextServer::FEATURE_BIDI_LAYOUT) || !TS->has_feature(TextServer::FEATURE_SHAPING)) {
locales_to_skip.push_back("ar"); // Arabic
locales_to_skip.push_back("fa"); // Persian
locales_to_skip.push_back("ur"); // Urdu
}
if (!TS->has_feature(TextServer::FEATURE_BIDI_LAYOUT)) {
locales_to_skip.push_back("he"); // Hebrew
}
if (!TS->has_feature(TextServer::FEATURE_SHAPING)) {
locales_to_skip.push_back("bn"); // Bengali
locales_to_skip.push_back("hi"); // Hindi
locales_to_skip.push_back("ml"); // Malayalam
locales_to_skip.push_back("si"); // Sinhala
locales_to_skip.push_back("ta"); // Tamil
locales_to_skip.push_back("te"); // Telugu
}
if (!locales_to_skip.is_empty()) {
WARN_PRINT("Some locales are not properly supported by selected Text Server and are disabled.");
}
String best;
int best_score = 0;
for (const String &locale : get_editor_locales()) {
// Skip locales which we can't render properly (see above comment).
// Test against language code without regional variants (e.g. ur_PK).
String lang_code = locale.get_slice("_", 0);
if (locales_to_skip.has(lang_code)) {
continue;
}
lang_hint += ",";
lang_hint += locale;
int score = TranslationServer::get_singleton()->compare_locales(host_lang, locale);
if (score > 0 && score >= best_score) {
best = locale;
best_score = score;
if (score == 10) {
break; // Exact match, skip the rest.
}
}
}
if (best_score == 0) {
best = "en";
}
EDITOR_SETTING_USAGE(Variant::STRING, PROPERTY_HINT_ENUM, "interface/editor/editor_language", best, lang_hint, PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
}
/* Interface */
// Editor
// Display what the Auto display scale setting effectively corresponds to.
const String display_scale_hint_string = vformat("Auto (%d%%),75%%,100%%,125%%,150%%,175%%,200%%,Custom", Math::round(get_auto_display_scale() * 100));
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)
_initial_set("interface/editor/debug/enable_pseudolocalization", false);
set_restart_if_changed("interface/editor/debug/enable_pseudolocalization", true);
// Use pseudolocalization in editor.
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)
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/editor/main_font_size", 14, "8,48,1")
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/editor/code_font_size", 14, "8,48,1")
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/code_font_contextual_ligatures", 0, "Default,Disable Contextual Alternates (Coding Ligatures),Use Custom OpenType Feature Set")
_initial_set("interface/editor/code_font_custom_opentype_features", "");
_initial_set("interface/editor/code_font_custom_variations", "");
_initial_set("interface/editor/font_antialiased", true);
#ifdef OSX_ENABLED
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/font_hinting", 0, "Auto (None),None,Light,Normal")
#else
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/font_hinting", 0, "Auto (Light),None,Light,Normal")
#endif
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")
EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "interface/editor/main_font", "", "*.ttf,*.otf,*.woff,*.woff2,*.pfb,*.pfm")
EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "interface/editor/main_font_bold", "", "*.ttf,*.otf,*.woff,*.woff2,*.pfb,*.pfm")
EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "interface/editor/code_font", "", "*.ttf,*.otf,*.woff,*.woff2,*.pfb,*.pfm")
EDITOR_SETTING_USAGE(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/editor/low_processor_mode_sleep_usec", 6900, "1,100000,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
// Default unfocused usec sleep is for 10 FPS. Allow an unfocused FPS limit
// as low as 1 FPS for those who really need low power usage (but don't need
// to preview particles or shaders while the editor is unfocused). With very
// low FPS limits, the editor can take a small while to become usable after
// being focused again, so this should be used at the user's discretion.
EDITOR_SETTING_USAGE(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/editor/unfocused_low_processor_mode_sleep_usec", 100000, "1,1000000,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
_initial_set("interface/editor/separate_distraction_mode", false);
_initial_set("interface/editor/automatically_open_screenshots", true);
EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/single_window_mode", false, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
_initial_set("interface/editor/mouse_extra_buttons_navigate_history", true);
_initial_set("interface/editor/save_each_scene_on_quit", true); // Regression
#ifdef DEV_ENABLED
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/show_internal_errors_in_toast_notifications", 0, "Auto (Enabled),Enabled,Disabled")
#else
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/show_internal_errors_in_toast_notifications", 0, "Auto (Disabled),Enabled,Disabled")
#endif
// Inspector
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/inspector/max_array_dictionary_items_per_page", 20, "10,100,1")
// Theme
EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_ENUM, "interface/theme/preset", "Default", "Default,Breeze Dark,Godot 2,Gray,Light,Solarized (Dark),Solarized (Light),Custom")
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/theme/icon_and_font_color", 0, "Auto,Dark,Light")
EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "interface/theme/base_color", Color(0.2, 0.23, 0.31), "")
EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "interface/theme/accent_color", Color(0.41, 0.61, 0.91), "")
EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/theme/contrast", 0.3, "-1,1,0.01")
EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/theme/icon_saturation", 1.0, "0,2,0.01")
EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/theme/relationship_line_opacity", 0.1, "0.00,1,0.01")
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/theme/border_size", 0, "0,2,1")
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/theme/corner_radius", 3, "0,6,1")
EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/theme/additional_spacing", 0.0, "0,5,0.1")
EDITOR_SETTING_USAGE(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "interface/theme/custom_theme", "", "*.res,*.tres,*.theme", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
// Scene tabs
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "interface/scene_tabs/display_close_button", 1, "Never,If Tab Active,Always"); // TabBar::CloseButtonDisplayPolicy
_initial_set("interface/scene_tabs/show_thumbnail_on_hover", true);
EDITOR_SETTING_USAGE(Variant::INT, PROPERTY_HINT_RANGE, "interface/scene_tabs/maximum_width", 350, "0,9999,1", PROPERTY_USAGE_DEFAULT)
_initial_set("interface/scene_tabs/show_script_button", false);
/* Filesystem */
// Directories
EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_DIR, "filesystem/directories/autoscan_project_path", "", "")
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);
EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_DIR, "filesystem/directories/default_project_path", fs_dir_default_project_path, "")
// On save
_initial_set("filesystem/on_save/compress_binary_resources", true);
_initial_set("filesystem/on_save/safe_save_on_backup_then_rename", true);
// File dialog
_initial_set("filesystem/file_dialog/show_hidden_files", false);
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "filesystem/file_dialog/display_mode", 0, "Thumbnails,List")
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "filesystem/file_dialog/thumbnail_size", 64, "32,128,16")
/* Docks */
// SceneTree
_initial_set("docks/scene_tree/start_create_dialog_fully_expanded", false);
_initial_set("docks/scene_tree/auto_expand_to_selected", true);
// FileSystem
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "docks/filesystem/thumbnail_size", 64, "32,128,16")
_initial_set("docks/filesystem/always_show_folders", true);
_initial_set("docks/filesystem/textfile_extensions", "txt,md,cfg,ini,log,json,yml,yaml,toml");
// Property editor
_initial_set("docks/property_editor/auto_refresh_interval", 0.2); //update 5 times per second by default
EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "docks/property_editor/subresource_hue_tint", 0.75, "0,1,0.01")
/* Text editor */
// Theme
EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_ENUM, "text_editor/theme/color_theme", "Default", "Default,Godot 2,Custom")
// Theme: Highlighting
_load_godot2_text_editor_theme();
// Appearance
// Appearance: Caret
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/appearance/caret/type", 0, "Line,Block")
_initial_set("text_editor/appearance/caret/caret_blink", true);
EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "text_editor/appearance/caret/caret_blink_speed", 0.5, "0.1,10,0.01")
_initial_set("text_editor/appearance/caret/highlight_current_line", true);
_initial_set("text_editor/appearance/caret/highlight_all_occurrences", true);
// Appearance: Guidelines
_initial_set("text_editor/appearance/guidelines/show_line_length_guidelines", true);
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/appearance/guidelines/line_length_guideline_soft_column", 80, "20,160,1")
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/appearance/guidelines/line_length_guideline_hard_column", 100, "20,160,1")
// Appearance: Gutters
_initial_set("text_editor/appearance/gutters/show_line_numbers", true);
_initial_set("text_editor/appearance/gutters/line_numbers_zero_padded", false);
_initial_set("text_editor/appearance/gutters/highlight_type_safe_lines", true);
_initial_set("text_editor/appearance/gutters/show_bookmark_gutter", true);
_initial_set("text_editor/appearance/gutters/show_info_gutter", true);
// Appearance: Minimap
_initial_set("text_editor/appearance/minimap/show_minimap", true);
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/appearance/minimap/minimap_width", 80, "50,250,1")
// Appearance: Lines
_initial_set("text_editor/appearance/lines/code_folding", true);
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/appearance/lines/word_wrap", 0, "None,Boundary")
// Appearance: Whitespace
_initial_set("text_editor/appearance/whitespace/draw_tabs", true);
_initial_set("text_editor/appearance/whitespace/draw_spaces", false);
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/appearance/whitespace/line_spacing", 4, "0,50,1")
// Behavior
// Behavior: Navigation
_initial_set("text_editor/behavior/navigation/move_caret_on_right_click", true);
_initial_set("text_editor/behavior/navigation/scroll_past_end_of_file", false);
_initial_set("text_editor/behavior/navigation/smooth_scrolling", true);
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/behavior/navigation/v_scroll_speed", 80, "1,10000,1")
_initial_set("text_editor/behavior/navigation/drag_and_drop_selection", true);
// Behavior: Indent
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/behavior/indent/type", 0, "Tabs,Spaces")
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/behavior/indent/size", 4, "1,64,1") // size of 0 crashes.
_initial_set("text_editor/behavior/indent/auto_indent", true);
// Behavior: Files
_initial_set("text_editor/behavior/files/trim_trailing_whitespace_on_save", false);
_initial_set("text_editor/behavior/files/autosave_interval_secs", 0);
_initial_set("text_editor/behavior/files/restore_scripts_on_load", true);
_initial_set("text_editor/behavior/files/convert_indent_on_save", true);
_initial_set("text_editor/behavior/files/auto_reload_scripts_on_external_change", false);
// Script list
_initial_set("text_editor/script_list/show_members_overview", true);
_initial_set("text_editor/script_list/sort_members_outline_alphabetically", false);
// Completion
EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "text_editor/completion/idle_parse_delay", 2.0, "0.1,10,0.01")
_initial_set("text_editor/completion/auto_brace_complete", true);
EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "text_editor/completion/code_complete_delay", 0.3, "0.01,5,0.01")
_initial_set("text_editor/completion/put_callhint_tooltip_below_current_line", true);
_initial_set("text_editor/completion/complete_file_paths", true);
_initial_set("text_editor/completion/add_type_hints", false);
_initial_set("text_editor/completion/use_single_quotes", false);
// Help
_initial_set("text_editor/help/show_help_index", true);
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/help/help_font_size", 15, "8,48,1")
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/help/help_source_font_size", 14, "8,48,1")
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/help/help_title_font_size", 23, "8,48,1")
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/help/class_reference_examples", 0, "GDScript,C#,GDScript and C#")
/* Editors */
// GridMap
_initial_set("editors/grid_map/pick_distance", 5000.0);
// 3D
EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d/primary_grid_color", Color(0.56, 0.56, 0.56, 0.5), "")
EDITOR_SETTING(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d/secondary_grid_color", Color(0.38, 0.38, 0.38, 0.5), "")
// Use a similar color to the 2D editor selection.
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)
_initial_set("editors/3d_gizmos/gizmo_colors/instantiated", Color(0.7, 0.7, 0.7, 0.6));
_initial_set("editors/3d_gizmos/gizmo_colors/joint", Color(0.5, 0.8, 1));
_initial_set("editors/3d_gizmos/gizmo_colors/shape", Color(0.5, 0.7, 1));
// If a line is a multiple of this, it uses the primary grid color.
// Use a power of 2 value by default as it's more common to use powers of 2 in level design.
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "editors/3d/primary_grid_steps", 8, "1,100,1")
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "editors/3d/grid_size", 200, "1,2000,1")
// Higher values produce graphical artifacts when far away unless View Z-Far
// is increased significantly more than it really should need to be.
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "editors/3d/grid_division_level_max", 2, "-1,3,1")
// Lower values produce graphical artifacts regardless of view clipping planes, so limit to -2 as a lower bound.
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "editors/3d/grid_division_level_min", 0, "-2,2,1")
// -0.2 seems like a sensible default. -1.0 gives Blender-like behavior, 0.5 gives huge grids.
EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/grid_division_level_bias", -0.2, "-1.0,0.5,0.1")
_initial_set("editors/3d/grid_xz_plane", true);
_initial_set("editors/3d/grid_xy_plane", false);
_initial_set("editors/3d/grid_yz_plane", false);
// Use a lower default FOV for the 3D camera compared to the
// Camera3D node as the 3D viewport doesn't span the whole screen.
// This means it's technically viewed from a further distance, which warrants a narrower FOV.
EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/default_fov", 70.0, "1,179,0.1,degrees")
EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/default_z_near", 0.05, "0.01,10,0.01,or_greater,suffix:m")
EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/default_z_far", 4000.0, "0.1,4000,0.1,or_greater,suffix:m")
// 3D: Navigation
_initial_set("editors/3d/navigation/invert_x_axis", false);
_initial_set("editors/3d/navigation/invert_y_axis", false);
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/navigation_scheme", 0, "Godot,Maya,Modo")
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/zoom_style", 0, "Vertical,Horizontal")
_initial_set("editors/3d/navigation/emulate_numpad", false);
_initial_set("editors/3d/navigation/emulate_3_button_mouse", false);
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/orbit_modifier", 0, "None,Shift,Alt,Meta,Ctrl")
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/pan_modifier", 1, "None,Shift,Alt,Meta,Ctrl")
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/zoom_modifier", 4, "None,Shift,Alt,Meta,Ctrl")
_initial_set("editors/3d/navigation/warped_mouse_panning", true);
// 3D: Navigation feel
EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/navigation_feel/orbit_sensitivity", 0.25, "0.01,2,0.001")
EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/navigation_feel/orbit_inertia", 0.0, "0,1,0.001")
EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/navigation_feel/translation_inertia", 0.05, "0,1,0.001")
EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/navigation_feel/zoom_inertia", 0.05, "0,1,0.001")
// 3D: Freelook
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/freelook/freelook_navigation_scheme", 0, "Default,Partially Axis-Locked (id Tech),Fully Axis-Locked (Minecraft)")
EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/freelook/freelook_sensitivity", 0.25, "0.01,2,0.001")
EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/freelook/freelook_inertia", 0.0, "0,1,0.001")
EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/3d/freelook/freelook_base_speed", 5.0, "0,10,0.01")
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/freelook/freelook_activation_modifier", 0, "None,Shift,Alt,Meta,Ctrl")
_initial_set("editors/3d/freelook/freelook_speed_zoom_link", false);
// 2D
_initial_set("editors/2d/grid_color", Color(1.0, 1.0, 1.0, 0.07));
_initial_set("editors/2d/guides_color", Color(0.6, 0.0, 0.8));
_initial_set("editors/2d/smart_snapping_line_color", Color(0.9, 0.1, 0.1));
_initial_set("editors/2d/bone_width", 5);
_initial_set("editors/2d/bone_color1", Color(1.0, 1.0, 1.0, 0.7));
_initial_set("editors/2d/bone_color2", Color(0.6, 0.6, 0.6, 0.7));
_initial_set("editors/2d/bone_selected_color", Color(0.9, 0.45, 0.45, 0.7));
_initial_set("editors/2d/bone_ik_color", Color(0.9, 0.9, 0.45, 0.7));
_initial_set("editors/2d/bone_outline_color", Color(0.35, 0.35, 0.35, 0.5));
_initial_set("editors/2d/bone_outline_size", 2);
_initial_set("editors/2d/viewport_border_color", Color(0.4, 0.4, 1.0, 0.4));
_initial_set("editors/2d/constrain_editor_view", true);
// Panning
// Enum should be in sync with ControlScheme in ViewPanner.
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/panning/2d_editor_panning_scheme", 0, "Scroll Zooms,Scroll Pans");
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/panning/sub_editors_panning_scheme", 0, "Scroll Zooms,Scroll Pans");
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "editors/panning/animation_editors_panning_scheme", 1, "Scroll Zooms,Scroll Pans");
_initial_set("editors/panning/simple_panning", false);
_initial_set("editors/panning/warped_mouse_panning", true);
_initial_set("editors/panning/2d_editor_pan_speed", 20);
// Tiles editor
_initial_set("editors/tiles_editor/display_grid", true);
_initial_set("editors/tiles_editor/grid_color", Color(1.0, 0.5, 0.2, 0.5));
// Polygon editor
_initial_set("editors/polygon_editor/point_grab_radius", 8);
_initial_set("editors/polygon_editor/show_previous_outline", true);
// Animation
_initial_set("editors/animation/autorename_animation_tracks", true);
_initial_set("editors/animation/confirm_insert_track", true);
_initial_set("editors/animation/default_create_bezier_tracks", false);
_initial_set("editors/animation/default_create_reset_tracks", true);
_initial_set("editors/animation/onion_layers_past_color", Color(1, 0, 0));
_initial_set("editors/animation/onion_layers_future_color", Color(0, 1, 0));
// Visual editors
EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/visual_editors/minimap_opacity", 0.85, "0.0,1.0,0.01")
EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/visual_editors/lines_curvature", 0.5, "0.0,1.0,0.01")
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "editors/visual_editors/visualshader/port_preview_size", 160, "100,400,0.01")
/* Run */
// Window placement
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "run/window_placement/rect", 1, "Top Left,Centered,Custom Position,Force Maximized,Force Fullscreen")
String screen_hints = "Same as Editor,Previous Monitor,Next Monitor";
for (int i = 0; i < DisplayServer::get_singleton()->get_screen_count(); i++) {
screen_hints += ",Monitor " + itos(i + 1);
}
_initial_set("run/window_placement/rect_custom_position", Vector2());
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "run/window_placement/screen", 0, screen_hints)
// Auto save
_initial_set("run/auto_save/save_before_running", true);
// Output
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "run/output/font_size", 13, "8,48,1")
_initial_set("run/output/always_clear_output_on_play", true);
_initial_set("run/output/always_open_output_on_play", true);
_initial_set("run/output/always_close_output_on_stop", false);
/* Network */
// Debug
_initial_set("network/debug/remote_host", "127.0.0.1"); // Hints provided in setup_network
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "network/debug/remote_port", 6007, "1,65535,1")
// SSL
EDITOR_SETTING_USAGE(Variant::STRING, PROPERTY_HINT_GLOBAL_FILE, "network/ssl/editor_ssl_certificates", _SYSTEM_CERTS_PATH, "*.crt,*.pem", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
// Profiler
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "debugger/profiler_frame_history_size", 3600, "60,10000,1")
// HTTP Proxy
_initial_set("network/http_proxy/host", "");
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "network/http_proxy/port", 8080, "1,65535,1")
/* Extra config */
// TRANSLATORS: Project Manager here refers to the tool used to create/manage Godot projects.
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "project_manager/sorting_order", 0, "Last Edited,Name,Path")
if (p_extra_config.is_valid()) {
if (p_extra_config->has_section("init_projects") && p_extra_config->has_section_key("init_projects", "list")) {
Vector<String> list = p_extra_config->get_value("init_projects", "list");
for (int i = 0; i < list.size(); i++) {
String name = list[i].replace("/", "::");
set("projects/" + name, list[i]);
}
}
if (p_extra_config->has_section("presets")) {
List<String> keys;
p_extra_config->get_section_keys("presets", &keys);
for (const String &key : keys) {
Variant val = p_extra_config->get_value("presets", key);
set(key, val);
}
}
}
}
void EditorSettings::_load_godot2_text_editor_theme() {
// Godot 2 is only a dark theme; it doesn't have a light theme counterpart.
_initial_set("text_editor/theme/highlighting/symbol_color", Color(0.73, 0.87, 1.0));
_initial_set("text_editor/theme/highlighting/keyword_color", Color(1.0, 1.0, 0.7));
_initial_set("text_editor/theme/highlighting/control_flow_keyword_color", Color(1.0, 0.85, 0.7));
_initial_set("text_editor/theme/highlighting/base_type_color", Color(0.64, 1.0, 0.83));
_initial_set("text_editor/theme/highlighting/engine_type_color", Color(0.51, 0.83, 1.0));
_initial_set("text_editor/theme/highlighting/user_type_color", Color(0.42, 0.67, 0.93));
_initial_set("text_editor/theme/highlighting/comment_color", Color(0.4, 0.4, 0.4));
_initial_set("text_editor/theme/highlighting/string_color", Color(0.94, 0.43, 0.75));
_initial_set("text_editor/theme/highlighting/background_color", Color(0.13, 0.12, 0.15));
_initial_set("text_editor/theme/highlighting/completion_background_color", Color(0.17, 0.16, 0.2));
_initial_set("text_editor/theme/highlighting/completion_selected_color", Color(0.26, 0.26, 0.27));
_initial_set("text_editor/theme/highlighting/completion_existing_color", Color(0.87, 0.87, 0.87, 0.13));
_initial_set("text_editor/theme/highlighting/completion_scroll_color", Color(1, 1, 1, 0.29));
_initial_set("text_editor/theme/highlighting/completion_font_color", Color(0.67, 0.67, 0.67));
_initial_set("text_editor/theme/highlighting/text_color", Color(0.67, 0.67, 0.67));
_initial_set("text_editor/theme/highlighting/line_number_color", Color(0.67, 0.67, 0.67, 0.4));
_initial_set("text_editor/theme/highlighting/safe_line_number_color", Color(0.67, 0.78, 0.67, 0.6));
_initial_set("text_editor/theme/highlighting/caret_color", Color(0.67, 0.67, 0.67));
_initial_set("text_editor/theme/highlighting/caret_background_color", Color(0, 0, 0));
_initial_set("text_editor/theme/highlighting/text_selected_color", Color(0, 0, 0));
_initial_set("text_editor/theme/highlighting/selection_color", Color(0.41, 0.61, 0.91, 0.35));
_initial_set("text_editor/theme/highlighting/brace_mismatch_color", Color(1, 0.2, 0.2));
_initial_set("text_editor/theme/highlighting/current_line_color", Color(0.3, 0.5, 0.8, 0.15));
_initial_set("text_editor/theme/highlighting/line_length_guideline_color", Color(0.3, 0.5, 0.8, 0.1));
_initial_set("text_editor/theme/highlighting/word_highlighted_color", Color(0.8, 0.9, 0.9, 0.15));
_initial_set("text_editor/theme/highlighting/number_color", Color(0.92, 0.58, 0.2));
_initial_set("text_editor/theme/highlighting/function_color", Color(0.4, 0.64, 0.81));
_initial_set("text_editor/theme/highlighting/member_variable_color", Color(0.9, 0.31, 0.35));
_initial_set("text_editor/theme/highlighting/mark_color", Color(1.0, 0.4, 0.4, 0.4));
_initial_set("text_editor/theme/highlighting/bookmark_color", Color(0.08, 0.49, 0.98));
_initial_set("text_editor/theme/highlighting/breakpoint_color", Color(0.9, 0.29, 0.3));
_initial_set("text_editor/theme/highlighting/executing_line_color", Color(0.98, 0.89, 0.27));
_initial_set("text_editor/theme/highlighting/code_folding_color", Color(0.8, 0.8, 0.8, 0.8));
_initial_set("text_editor/theme/highlighting/search_result_color", Color(0.05, 0.25, 0.05, 1));
_initial_set("text_editor/theme/highlighting/search_result_border_color", Color(0.41, 0.61, 0.91, 0.38));
}
bool EditorSettings::_save_text_editor_theme(String p_file) {
String theme_section = "color_theme";
Ref<ConfigFile> cf = memnew(ConfigFile); // hex is better?
List<String> keys;
for (const KeyValue<String, VariantContainer> &E : props) {
keys.push_back(E.key);
}
keys.sort();
for (const String &key : keys) {
if (key.begins_with("text_editor/theme/highlighting/") && key.find("color") >= 0) {
cf->set_value(theme_section, key.replace("text_editor/theme/highlighting/", ""), ((Color)props[key].variant).to_html());
}
}
Error err = cf->save(p_file);
return err == OK;
}
bool EditorSettings::_is_default_text_editor_theme(String p_theme_name) {
return p_theme_name == "default" || p_theme_name == "godot 2" || p_theme_name == "custom";
}
// PUBLIC METHODS
EditorSettings *EditorSettings::get_singleton() {
return singleton.ptr();
}
void EditorSettings::create() {
// IMPORTANT: create() *must* create a valid EditorSettings singleton,
// as the rest of the engine code will assume it. As such, it should never
// return (incl. via ERR_FAIL) without initializing the singleton member.
if (singleton.ptr()) {
ERR_PRINT("Can't recreate EditorSettings as it already exists.");
return;
}
GDREGISTER_CLASS(EditorSettings); // Otherwise it can't be unserialized.
String config_file_path;
Ref<ConfigFile> extra_config = memnew(ConfigFile);
if (!EditorPaths::get_singleton()) {
ERR_PRINT("Bug (please report): EditorPaths haven't been initialized, EditorSettings cannot be created properly.");
goto fail;
}
if (EditorPaths::get_singleton()->is_self_contained()) {
Error err = extra_config->load(EditorPaths::get_singleton()->get_self_contained_file());
if (err != OK) {
ERR_PRINT("Can't load extra config from path: " + EditorPaths::get_singleton()->get_self_contained_file());
}
}
if (EditorPaths::get_singleton()->are_paths_valid()) {
// Validate editor config file.
Ref<DirAccess> dir = DirAccess::open(EditorPaths::get_singleton()->get_config_dir());
String config_file_name = "editor_settings-" + itos(VERSION_MAJOR) + ".tres";
config_file_path = EditorPaths::get_singleton()->get_config_dir().plus_file(config_file_name);
if (!dir->file_exists(config_file_name)) {
goto fail;
}
singleton = ResourceLoader::load(config_file_path, "EditorSettings");
if (singleton.is_null()) {
ERR_PRINT("Could not load editor settings from path: " + config_file_path);
goto fail;
}
singleton->save_changed_setting = true;
singleton->config_file_path = config_file_path;
print_verbose("EditorSettings: Load OK!");
singleton->setup_language();
singleton->setup_network();
singleton->load_favorites_and_recent_dirs();
singleton->list_text_editor_themes();
return;
}
fail:
// patch init projects
String exe_path = OS::get_singleton()->get_executable_path().get_base_dir();
if (extra_config->has_section("init_projects")) {
Vector<String> list = extra_config->get_value("init_projects", "list");
for (int i = 0; i < list.size(); i++) {
list.write[i] = exe_path.plus_file(list[i]);
}
extra_config->set_value("init_projects", "list", list);
}
singleton = Ref<EditorSettings>(memnew(EditorSettings));
singleton->save_changed_setting = true;
singleton->config_file_path = config_file_path;
singleton->_load_defaults(extra_config);
singleton->setup_language();
singleton->setup_network();
singleton->list_text_editor_themes();
}
void EditorSettings::setup_language() {
TranslationServer::get_singleton()->set_editor_pseudolocalization(get("interface/editor/debug/enable_pseudolocalization"));
String lang = get("interface/editor/editor_language");
if (lang == "en") {
return; // Default, nothing to do.
}
// Load editor translation for configured/detected locale.
load_editor_translations(lang);
// Load class reference translation.
load_doc_translations(lang);
}
void EditorSettings::setup_network() {
List<IPAddress> local_ip;
IP::get_singleton()->get_local_addresses(&local_ip);
String hint;
String current = has_setting("network/debug/remote_host") ? get("network/debug/remote_host") : "";
String selected = "127.0.0.1";
// Check that current remote_host is a valid interface address and populate hints.
for (const IPAddress &ip : local_ip) {
// link-local IPv6 addresses don't work, skipping them
if (String(ip).begins_with("fe80:0:0:0:")) { // fe80::/64
continue;
}
// Same goes for IPv4 link-local (APIPA) addresses.
if (String(ip).begins_with("169.254.")) { // 169.254.0.0/16
continue;
}
// Select current IP (found)
if (ip == current) {
selected = ip;
}
if (!hint.is_empty()) {
hint += ",";
}
hint += ip;
}
// Add hints with valid IP addresses to remote_host property.
add_property_hint(PropertyInfo(Variant::STRING, "network/debug/remote_host", PROPERTY_HINT_ENUM, hint));
// Fix potentially invalid remote_host due to network change.
set("network/debug/remote_host", selected);
}
void EditorSettings::save() {
//_THREAD_SAFE_METHOD_
if (!singleton.ptr()) {
return;
}
if (singleton->config_file_path.is_empty()) {
ERR_PRINT("Cannot save EditorSettings config, no valid path");
return;
}
Error err = ResourceSaver::save(singleton->config_file_path, singleton);
if (err != OK) {
ERR_PRINT("Error saving editor settings to " + singleton->config_file_path);
} else {
singleton->changed_settings.clear();
print_verbose("EditorSettings: Save OK!");
}
}
Array EditorSettings::get_changed_settings() const {
Array arr;
for (const String &setting : changed_settings) {
arr.push_back(setting);
}
return arr;
}
bool EditorSettings::check_changed_settings_in_group(const String &p_setting_prefix) const {
for (const String &setting : changed_settings) {
if (setting.begins_with(p_setting_prefix)) {
return true;
}
}
return false;
}
void EditorSettings::mark_setting_changed(const String &p_setting) {
changed_settings.insert(p_setting);
}
void EditorSettings::destroy() {
if (!singleton.ptr()) {
return;
}
save();
singleton = Ref<EditorSettings>();
}
void EditorSettings::set_optimize_save(bool p_optimize) {
optimize_save = p_optimize;