Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/settings/editor_settings_dialog.cpp
9902 views
1
/**************************************************************************/
2
/* editor_settings_dialog.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
31
#include "editor_settings_dialog.h"
32
33
#include "core/config/project_settings.h"
34
#include "core/input/input_map.h"
35
#include "core/os/keyboard.h"
36
#include "editor/debugger/editor_debugger_node.h"
37
#include "editor/editor_log.h"
38
#include "editor/editor_node.h"
39
#include "editor/editor_string_names.h"
40
#include "editor/editor_undo_redo_manager.h"
41
#include "editor/inspector/editor_property_name_processor.h"
42
#include "editor/inspector/editor_sectioned_inspector.h"
43
#include "editor/scene/3d/node_3d_editor_plugin.h"
44
#include "editor/settings/editor_event_search_bar.h"
45
#include "editor/settings/editor_settings.h"
46
#include "editor/settings/event_listener_line_edit.h"
47
#include "editor/settings/input_event_configuration_dialog.h"
48
#include "editor/settings/project_settings_editor.h"
49
#include "editor/themes/editor_scale.h"
50
#include "editor/themes/editor_theme_manager.h"
51
#include "scene/gui/check_button.h"
52
#include "scene/gui/panel_container.h"
53
#include "scene/gui/tab_container.h"
54
#include "scene/gui/texture_rect.h"
55
#include "scene/gui/tree.h"
56
57
void EditorSettingsDialog::ok_pressed() {
58
if (!EditorSettings::get_singleton()) {
59
return;
60
}
61
_settings_save();
62
}
63
64
void EditorSettingsDialog::_settings_changed() {
65
if (is_visible()) {
66
timer->start();
67
}
68
}
69
70
void EditorSettingsDialog::_settings_property_edited(const String &p_name) {
71
String full_name = inspector->get_full_item_path(p_name);
72
73
// Set theme presets to Custom when controlled settings change.
74
75
if (full_name == "interface/theme/accent_color" || full_name == "interface/theme/base_color" || full_name == "interface/theme/contrast" || full_name == "interface/theme/draw_extra_borders") {
76
EditorSettings::get_singleton()->set_manually("interface/theme/preset", "Custom");
77
} else if (full_name == "interface/theme/base_spacing" || full_name == "interface/theme/additional_spacing") {
78
EditorSettings::get_singleton()->set_manually("interface/theme/spacing_preset", "Custom");
79
} else if (full_name.begins_with("text_editor/theme/highlighting")) {
80
EditorSettings::get_singleton()->set_manually("text_editor/theme/color_theme", "Custom");
81
} else if (full_name.begins_with("editors/visual_editors/connection_colors") || full_name.begins_with("editors/visual_editors/category_colors")) {
82
EditorSettings::get_singleton()->set_manually("editors/visual_editors/color_theme", "Custom");
83
} else if (full_name == "editors/3d/navigation/orbit_mouse_button" || full_name == "editors/3d/navigation/pan_mouse_button" || full_name == "editors/3d/navigation/zoom_mouse_button" || full_name == "editors/3d/navigation/emulate_3_button_mouse") {
84
EditorSettings::get_singleton()->set_manually("editors/3d/navigation/navigation_scheme", (int)Node3DEditorViewport::NAVIGATION_CUSTOM);
85
} else if (full_name == "editors/3d/navigation/navigation_scheme") {
86
update_navigation_preset();
87
}
88
}
89
90
void EditorSettingsDialog::update_navigation_preset() {
91
Node3DEditorViewport::NavigationScheme nav_scheme = (Node3DEditorViewport::NavigationScheme)EDITOR_GET("editors/3d/navigation/navigation_scheme").operator int();
92
Node3DEditorViewport::ViewportNavMouseButton set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
93
Node3DEditorViewport::ViewportNavMouseButton set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
94
Node3DEditorViewport::ViewportNavMouseButton set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
95
bool set_3_button_mouse = false;
96
Ref<InputEventKey> orbit_mod_key_1;
97
Ref<InputEventKey> orbit_mod_key_2;
98
Ref<InputEventKey> pan_mod_key_1;
99
Ref<InputEventKey> pan_mod_key_2;
100
Ref<InputEventKey> zoom_mod_key_1;
101
Ref<InputEventKey> zoom_mod_key_2;
102
bool set_preset = false;
103
104
if (nav_scheme == Node3DEditorViewport::NAVIGATION_GODOT) {
105
set_preset = true;
106
set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;
107
set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;
108
set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;
109
set_3_button_mouse = false;
110
orbit_mod_key_1 = InputEventKey::create_reference(Key::NONE);
111
orbit_mod_key_2 = InputEventKey::create_reference(Key::NONE);
112
pan_mod_key_1 = InputEventKey::create_reference(Key::SHIFT);
113
pan_mod_key_2 = InputEventKey::create_reference(Key::NONE);
114
zoom_mod_key_1 = InputEventKey::create_reference(Key::CTRL);
115
zoom_mod_key_2 = InputEventKey::create_reference(Key::NONE);
116
} else if (nav_scheme == Node3DEditorViewport::NAVIGATION_MAYA) {
117
set_preset = true;
118
set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
119
set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;
120
set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_RIGHT_MOUSE;
121
set_3_button_mouse = false;
122
orbit_mod_key_1 = InputEventKey::create_reference(Key::ALT);
123
orbit_mod_key_2 = InputEventKey::create_reference(Key::NONE);
124
pan_mod_key_1 = InputEventKey::create_reference(Key::NONE);
125
pan_mod_key_2 = InputEventKey::create_reference(Key::NONE);
126
zoom_mod_key_1 = InputEventKey::create_reference(Key::ALT);
127
zoom_mod_key_2 = InputEventKey::create_reference(Key::NONE);
128
} else if (nav_scheme == Node3DEditorViewport::NAVIGATION_MODO) {
129
set_preset = true;
130
set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
131
set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
132
set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
133
set_3_button_mouse = false;
134
orbit_mod_key_1 = InputEventKey::create_reference(Key::ALT);
135
orbit_mod_key_2 = InputEventKey::create_reference(Key::NONE);
136
pan_mod_key_1 = InputEventKey::create_reference(Key::SHIFT);
137
pan_mod_key_2 = InputEventKey::create_reference(Key::ALT);
138
zoom_mod_key_1 = InputEventKey::create_reference(Key::ALT);
139
zoom_mod_key_2 = InputEventKey::create_reference(Key::CTRL);
140
} else if (nav_scheme == Node3DEditorViewport::NAVIGATION_TABLET) {
141
set_preset = true;
142
set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;
143
set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;
144
set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;
145
set_3_button_mouse = true;
146
orbit_mod_key_1 = InputEventKey::create_reference(Key::ALT);
147
orbit_mod_key_2 = InputEventKey::create_reference(Key::NONE);
148
pan_mod_key_1 = InputEventKey::create_reference(Key::SHIFT);
149
pan_mod_key_2 = InputEventKey::create_reference(Key::NONE);
150
zoom_mod_key_1 = InputEventKey::create_reference(Key::CTRL);
151
zoom_mod_key_2 = InputEventKey::create_reference(Key::NONE);
152
}
153
// Set settings to the desired preset values.
154
if (set_preset) {
155
EditorSettings::get_singleton()->set_manually("editors/3d/navigation/orbit_mouse_button", (int)set_orbit_mouse_button);
156
EditorSettings::get_singleton()->set_manually("editors/3d/navigation/pan_mouse_button", (int)set_pan_mouse_button);
157
EditorSettings::get_singleton()->set_manually("editors/3d/navigation/zoom_mouse_button", (int)set_zoom_mouse_button);
158
EditorSettings::get_singleton()->set_manually("editors/3d/navigation/emulate_3_button_mouse", set_3_button_mouse);
159
_set_shortcut_input("spatial_editor/viewport_orbit_modifier_1", orbit_mod_key_1);
160
_set_shortcut_input("spatial_editor/viewport_orbit_modifier_2", orbit_mod_key_2);
161
_set_shortcut_input("spatial_editor/viewport_pan_modifier_1", pan_mod_key_1);
162
_set_shortcut_input("spatial_editor/viewport_pan_modifier_2", pan_mod_key_2);
163
_set_shortcut_input("spatial_editor/viewport_zoom_modifier_1", zoom_mod_key_1);
164
_set_shortcut_input("spatial_editor/viewport_zoom_modifier_2", zoom_mod_key_2);
165
}
166
}
167
168
void EditorSettingsDialog::_set_shortcut_input(const String &p_name, Ref<InputEventKey> &p_event) {
169
Array sc_events;
170
if (p_event->get_keycode() != Key::NONE) {
171
sc_events.push_back((Variant)p_event);
172
}
173
174
Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_name);
175
sc->set_events(sc_events);
176
}
177
178
void EditorSettingsDialog::_settings_save() {
179
if (!timer->is_stopped()) {
180
timer->stop();
181
}
182
EditorSettings::get_singleton()->notify_changes();
183
EditorSettings::get_singleton()->save();
184
}
185
186
void EditorSettingsDialog::cancel_pressed() {
187
if (!EditorSettings::get_singleton()) {
188
return;
189
}
190
191
EditorSettings::get_singleton()->notify_changes();
192
}
193
194
void EditorSettingsDialog::popup_edit_settings() {
195
if (!EditorSettings::get_singleton()) {
196
return;
197
}
198
199
EditorSettings::get_singleton()->update_text_editor_themes_list(); // Make sure we have an up to date list of themes.
200
201
_update_dynamic_property_hints();
202
203
inspector->edit(EditorSettings::get_singleton());
204
inspector->get_inspector()->update_tree();
205
206
_update_shortcuts();
207
set_process_shortcut_input(true);
208
209
// Restore valid window bounds or pop up at default size.
210
Rect2 saved_size = EditorSettings::get_singleton()->get_project_metadata("dialog_bounds", "editor_settings", Rect2());
211
if (saved_size != Rect2()) {
212
popup(saved_size);
213
} else {
214
popup_centered_clamped(Size2(900, 700) * EDSCALE, 0.8);
215
}
216
217
_focus_current_search_box();
218
}
219
220
void EditorSettingsDialog::_undo_redo_callback(void *p_self, const String &p_name) {
221
EditorNode::get_log()->add_message(p_name, EditorLog::MSG_TYPE_EDITOR);
222
}
223
224
void EditorSettingsDialog::_notification(int p_what) {
225
switch (p_what) {
226
case NOTIFICATION_VISIBILITY_CHANGED: {
227
if (!is_visible()) {
228
EditorSettings::get_singleton()->set_project_metadata("dialog_bounds", "editor_settings", Rect2(get_position(), get_size()));
229
set_process_shortcut_input(false);
230
}
231
} break;
232
233
case NOTIFICATION_READY: {
234
EditorSettingsPropertyWrapper::restart_request_callback = callable_mp(this, &EditorSettingsDialog::_editor_restart_request);
235
236
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
237
undo_redo->get_or_create_history(EditorUndoRedoManager::GLOBAL_HISTORY).undo_redo->set_method_notify_callback(EditorDebuggerNode::_methods_changed, nullptr);
238
undo_redo->get_or_create_history(EditorUndoRedoManager::GLOBAL_HISTORY).undo_redo->set_property_notify_callback(EditorDebuggerNode::_properties_changed, nullptr);
239
undo_redo->get_or_create_history(EditorUndoRedoManager::GLOBAL_HISTORY).undo_redo->set_commit_notify_callback(_undo_redo_callback, this);
240
} break;
241
242
case NOTIFICATION_ENTER_TREE: {
243
_update_icons();
244
} break;
245
246
case NOTIFICATION_THEME_CHANGED: {
247
_update_shortcuts();
248
} break;
249
250
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
251
if (EditorThemeManager::is_generated_theme_outdated()) {
252
_update_icons();
253
}
254
255
bool update_shortcuts_tab =
256
EditorSettings::get_singleton()->check_changed_settings_in_group("shortcuts") ||
257
EditorSettings::get_singleton()->check_changed_settings_in_group("builtin_action_overrides");
258
if (update_shortcuts_tab) {
259
_update_shortcuts();
260
}
261
262
if (EditorSettings::get_singleton()->check_changed_settings_in_group("editors/3d/navigation")) {
263
// Shortcuts may have changed, so dynamic hint values must update.
264
_update_dynamic_property_hints();
265
inspector->get_inspector()->update_tree();
266
}
267
268
if (EditorSettings::get_singleton()->check_changed_settings_in_group("interface/editor/localize_settings")) {
269
inspector->update_category_list();
270
}
271
} break;
272
}
273
}
274
275
void EditorSettingsDialog::shortcut_input(const Ref<InputEvent> &p_event) {
276
const Ref<InputEventKey> k = p_event;
277
if (k.is_valid() && k->is_pressed()) {
278
bool handled = false;
279
280
if (ED_IS_SHORTCUT("ui_undo", p_event)) {
281
EditorNode::get_singleton()->undo();
282
handled = true;
283
}
284
285
if (ED_IS_SHORTCUT("ui_redo", p_event)) {
286
EditorNode::get_singleton()->redo();
287
handled = true;
288
}
289
290
if (k->is_match(InputEventKey::create_reference(KeyModifierMask::CMD_OR_CTRL | Key::F))) {
291
_focus_current_search_box();
292
handled = true;
293
}
294
295
if (handled) {
296
set_input_as_handled();
297
}
298
}
299
}
300
301
void EditorSettingsDialog::_update_icons() {
302
search_box->set_right_icon(get_editor_theme_icon(SNAME("Search")));
303
search_box->set_clear_button_enabled(true);
304
305
restart_close_button->set_button_icon(get_editor_theme_icon(SNAME("Close")));
306
restart_container->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SceneStringName(panel), SNAME("Tree")));
307
restart_icon->set_texture(get_editor_theme_icon(SNAME("StatusWarning")));
308
restart_label->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("warning_color"), EditorStringName(Editor)));
309
}
310
311
void EditorSettingsDialog::_event_config_confirmed() {
312
Ref<InputEventKey> k = shortcut_editor->get_event();
313
if (k.is_null()) {
314
return;
315
}
316
317
if (current_event_index == -1) {
318
// Add new event
319
current_events.push_back(k);
320
} else {
321
// Edit existing event
322
current_events[current_event_index] = k;
323
}
324
325
if (is_editing_action) {
326
_update_builtin_action(current_edited_identifier, current_events);
327
} else {
328
_update_shortcut_events(current_edited_identifier, current_events);
329
}
330
}
331
332
void EditorSettingsDialog::_update_builtin_action(const String &p_name, const Array &p_events) {
333
Array old_input_array = EditorSettings::get_singleton()->get_builtin_action_overrides(p_name);
334
if (old_input_array.is_empty()) {
335
List<Ref<InputEvent>> defaults = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied()[current_edited_identifier];
336
old_input_array = _event_list_to_array_helper(defaults);
337
}
338
339
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
340
undo_redo->create_action(vformat(TTR("Edit Built-in Action: %s"), p_name));
341
undo_redo->add_do_method(EditorSettings::get_singleton(), "mark_setting_changed", "builtin_action_overrides");
342
undo_redo->add_undo_method(EditorSettings::get_singleton(), "mark_setting_changed", "builtin_action_overrides");
343
undo_redo->add_do_method(EditorSettings::get_singleton(), "set_builtin_action_override", p_name, p_events);
344
undo_redo->add_undo_method(EditorSettings::get_singleton(), "set_builtin_action_override", p_name, old_input_array);
345
undo_redo->add_do_method(this, "_update_shortcuts");
346
undo_redo->add_undo_method(this, "_update_shortcuts");
347
undo_redo->add_do_method(this, "_settings_changed");
348
undo_redo->add_undo_method(this, "_settings_changed");
349
undo_redo->commit_action();
350
}
351
352
void EditorSettingsDialog::_update_shortcut_events(const String &p_path, const Array &p_events) {
353
Ref<Shortcut> current_sc = EditorSettings::get_singleton()->get_shortcut(p_path);
354
355
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
356
undo_redo->create_action(vformat(TTR("Edit Shortcut: %s"), p_path), UndoRedo::MERGE_DISABLE, EditorSettings::get_singleton());
357
// History must be fixed based on the EditorSettings object because current_sc would
358
// incorrectly make this action use the scene history.
359
undo_redo->force_fixed_history();
360
undo_redo->add_do_method(current_sc.ptr(), "set_events", p_events);
361
undo_redo->add_undo_method(current_sc.ptr(), "set_events", current_sc->get_events());
362
undo_redo->add_do_method(EditorSettings::get_singleton(), "mark_setting_changed", "shortcuts");
363
undo_redo->add_undo_method(EditorSettings::get_singleton(), "mark_setting_changed", "shortcuts");
364
undo_redo->add_do_method(this, "_update_shortcuts");
365
undo_redo->add_undo_method(this, "_update_shortcuts");
366
undo_redo->add_do_method(this, "_settings_changed");
367
undo_redo->add_undo_method(this, "_settings_changed");
368
undo_redo->commit_action();
369
370
bool path_is_orbit_mod = p_path == "spatial_editor/viewport_orbit_modifier_1" || p_path == "spatial_editor/viewport_orbit_modifier_2";
371
bool path_is_pan_mod = p_path == "spatial_editor/viewport_pan_modifier_1" || p_path == "spatial_editor/viewport_pan_modifier_2";
372
bool path_is_zoom_mod = p_path == "spatial_editor/viewport_zoom_modifier_1" || p_path == "spatial_editor/viewport_zoom_modifier_2";
373
if (path_is_orbit_mod || path_is_pan_mod || path_is_zoom_mod) {
374
EditorSettings::get_singleton()->set_manually("editors/3d/navigation/navigation_scheme", (int)Node3DEditorViewport::NAVIGATION_CUSTOM);
375
}
376
}
377
378
Array EditorSettingsDialog::_event_list_to_array_helper(const List<Ref<InputEvent>> &p_events) {
379
Array events;
380
381
// Convert the list to an array, and only keep key events as this is for the editor.
382
for (const List<Ref<InputEvent>>::Element *E = p_events.front(); E; E = E->next()) {
383
Ref<InputEventKey> k = E->get();
384
if (k.is_valid()) {
385
events.append(E->get());
386
}
387
}
388
389
return events;
390
}
391
392
TreeItem *EditorSettingsDialog::_create_shortcut_treeitem(TreeItem *p_parent, const String &p_shortcut_identifier, const String &p_display, Array &p_events, bool p_allow_revert, bool p_is_action, bool p_is_collapsed) {
393
TreeItem *shortcut_item = shortcuts->create_item(p_parent);
394
shortcut_item->set_collapsed(p_is_collapsed);
395
shortcut_item->set_text(0, p_display);
396
397
Ref<InputEvent> primary = p_events.size() > 0 ? Ref<InputEvent>(p_events[0]) : Ref<InputEvent>();
398
Ref<InputEvent> secondary = p_events.size() > 1 ? Ref<InputEvent>(p_events[1]) : Ref<InputEvent>();
399
400
String sc_text = TTRC("None");
401
if (primary.is_valid()) {
402
sc_text = primary->as_text();
403
404
if (secondary.is_valid()) {
405
sc_text += ", " + secondary->as_text();
406
407
if (p_events.size() > 2) {
408
sc_text += " (+" + itos(p_events.size() - 2) + ")";
409
}
410
}
411
shortcut_item->set_auto_translate_mode(1, AUTO_TRANSLATE_MODE_DISABLED);
412
}
413
414
shortcut_item->set_text(1, sc_text);
415
if (sc_text == "None") {
416
// Fade out unassigned shortcut labels for easier visual grepping.
417
shortcut_item->set_custom_color(1, get_theme_color(SceneStringName(font_color), SNAME("Label")) * Color(1, 1, 1, 0.5));
418
}
419
420
if (p_allow_revert) {
421
shortcut_item->add_button(1, get_editor_theme_icon(SNAME("Reload")), SHORTCUT_REVERT);
422
}
423
424
shortcut_item->add_button(1, get_editor_theme_icon(SNAME("Add")), SHORTCUT_ADD);
425
shortcut_item->add_button(1, get_editor_theme_icon(SNAME("Close")), SHORTCUT_ERASE, p_events.is_empty());
426
427
shortcut_item->set_meta("is_action", p_is_action);
428
shortcut_item->set_meta("type", "shortcut");
429
shortcut_item->set_meta("shortcut_identifier", p_shortcut_identifier);
430
shortcut_item->set_meta("events", p_events);
431
432
// Shortcut Input Events
433
for (int i = 0; i < p_events.size(); i++) {
434
Ref<InputEvent> ie = p_events[i];
435
if (ie.is_null()) {
436
continue;
437
}
438
439
TreeItem *event_item = shortcuts->create_item(shortcut_item);
440
441
// TRANSLATORS: This is the label for the main input event of a shortcut.
442
event_item->set_text(0, shortcut_item->get_child_count() == 1 ? TTRC("Primary") : "");
443
event_item->set_text(1, ie->as_text());
444
event_item->set_auto_translate_mode(1, AUTO_TRANSLATE_MODE_DISABLED);
445
446
event_item->add_button(1, get_editor_theme_icon(SNAME("Edit")), SHORTCUT_EDIT);
447
event_item->add_button(1, get_editor_theme_icon(SNAME("Close")), SHORTCUT_ERASE);
448
449
event_item->set_custom_bg_color(0, get_theme_color(SNAME("dark_color_3"), EditorStringName(Editor)));
450
event_item->set_custom_bg_color(1, get_theme_color(SNAME("dark_color_3"), EditorStringName(Editor)));
451
452
event_item->set_meta("is_action", p_is_action);
453
event_item->set_meta("type", "event");
454
event_item->set_meta("event_index", i);
455
}
456
457
return shortcut_item;
458
}
459
460
bool EditorSettingsDialog::_should_display_shortcut(const String &p_name, const Array &p_events, bool p_match_localized_name) const {
461
const Ref<InputEvent> search_ev = shortcut_search_bar->get_event();
462
if (search_ev.is_valid()) {
463
bool event_match = false;
464
for (int i = 0; i < p_events.size(); ++i) {
465
const Ref<InputEvent> ev = p_events[i];
466
if (ev.is_valid() && ev->is_match(search_ev, true)) {
467
event_match = true;
468
break;
469
}
470
}
471
if (!event_match) {
472
return false;
473
}
474
}
475
476
const String &search_text = shortcut_search_bar->get_name();
477
if (search_text.is_empty()) {
478
return true;
479
}
480
if (search_text.is_subsequence_ofn(p_name)) {
481
return true;
482
}
483
if (p_match_localized_name && search_text.is_subsequence_ofn(TTR(p_name))) {
484
return true;
485
}
486
487
return false;
488
}
489
490
void EditorSettingsDialog::_update_shortcuts() {
491
// Before clearing the tree, take note of which categories are collapsed so that this state can be maintained when the tree is repopulated.
492
HashMap<String, bool> collapsed;
493
494
if (shortcuts->get_root() && shortcuts->get_root()->get_first_child()) {
495
TreeItem *ti = shortcuts->get_root()->get_first_child();
496
while (ti) {
497
// Not all items have valid or unique text in the first column - so if it has an identifier, use that, as it should be unique.
498
if (ti->get_first_child() && ti->has_meta("shortcut_identifier")) {
499
collapsed[ti->get_meta("shortcut_identifier")] = ti->is_collapsed();
500
} else {
501
collapsed[ti->get_text(0)] = ti->is_collapsed();
502
}
503
504
// Try go down tree
505
TreeItem *ti_next = ti->get_first_child();
506
// Try go to the next node via in-order traversal
507
if (!ti_next) {
508
ti_next = ti;
509
while (ti_next && !ti_next->get_next()) {
510
ti_next = ti_next->get_parent();
511
}
512
if (ti_next) {
513
ti_next = ti_next->get_next();
514
}
515
}
516
517
ti = ti_next;
518
}
519
}
520
521
shortcuts->clear();
522
523
TreeItem *root = shortcuts->create_item();
524
HashMap<String, TreeItem *> sections;
525
526
// Set up section for Common/Built-in actions
527
TreeItem *common_section = shortcuts->create_item(root);
528
sections["Common"] = common_section;
529
common_section->set_text(0, TTRC("Common"));
530
common_section->set_selectable(0, false);
531
common_section->set_selectable(1, false);
532
if (collapsed.has("Common")) {
533
common_section->set_collapsed(collapsed["Common"]);
534
}
535
common_section->set_custom_bg_color(0, get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
536
common_section->set_custom_bg_color(1, get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
537
538
// Get the action map for the editor, and add each item to the "Common" section.
539
for (const KeyValue<StringName, InputMap::Action> &E : InputMap::get_singleton()->get_action_map()) {
540
const String &action_name = E.key;
541
const InputMap::Action &action = E.value;
542
543
// Skip non-builtin actions.
544
if (!InputMap::get_singleton()->get_builtins_with_feature_overrides_applied().has(action_name)) {
545
continue;
546
}
547
548
const List<Ref<InputEvent>> &all_default_events = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied().find(action_name)->value;
549
Array action_events = _event_list_to_array_helper(action.inputs);
550
if (!_should_display_shortcut(action_name, action_events, false)) {
551
continue;
552
}
553
554
Array default_events = _event_list_to_array_helper(all_default_events);
555
bool same_as_defaults = Shortcut::is_event_array_equal(default_events, action_events);
556
bool collapse = !collapsed.has(action_name) || (collapsed.has(action_name) && collapsed[action_name]);
557
558
TreeItem *item = _create_shortcut_treeitem(common_section, action_name, action_name, action_events, !same_as_defaults, true, collapse);
559
item->set_auto_translate_mode(0, AUTO_TRANSLATE_MODE_DISABLED); // `ui_*` input action names are untranslatable identifiers.
560
}
561
562
// Editor Shortcuts
563
564
List<String> slist;
565
EditorSettings::get_singleton()->get_shortcut_list(&slist);
566
slist.sort(); // Sort alphabetically.
567
568
const EditorPropertyNameProcessor::Style name_style = EditorPropertyNameProcessor::get_settings_style();
569
const EditorPropertyNameProcessor::Style tooltip_style = EditorPropertyNameProcessor::get_tooltip_style(name_style);
570
571
// Create all sections first.
572
for (const String &E : slist) {
573
Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(E);
574
String section_name = E.get_slicec('/', 0);
575
576
if (sections.has(section_name)) {
577
continue;
578
}
579
580
TreeItem *section = shortcuts->create_item(root);
581
582
const String item_name = EditorPropertyNameProcessor::get_singleton()->process_name(section_name, name_style, E);
583
const String tooltip = EditorPropertyNameProcessor::get_singleton()->process_name(section_name, tooltip_style, E);
584
585
section->set_auto_translate_mode(0, AUTO_TRANSLATE_MODE_DISABLED); // Already translated manually.
586
section->set_text(0, item_name);
587
section->set_tooltip_text(0, tooltip);
588
section->set_selectable(0, false);
589
section->set_selectable(1, false);
590
section->set_custom_bg_color(0, get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
591
section->set_custom_bg_color(1, get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
592
593
if (collapsed.has(item_name)) {
594
section->set_collapsed(collapsed[item_name]);
595
}
596
597
sections[section_name] = section;
598
}
599
600
// Add shortcuts to sections.
601
for (const String &E : slist) {
602
Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(E);
603
if (!sc->has_meta("original")) {
604
continue;
605
}
606
607
String section_name = E.get_slicec('/', 0);
608
TreeItem *section = sections[section_name];
609
610
if (!_should_display_shortcut(sc->get_name(), sc->get_events(), true)) {
611
continue;
612
}
613
614
Array original = sc->get_meta("original");
615
Array shortcuts_array = sc->get_events().duplicate(true);
616
bool same_as_defaults = Shortcut::is_event_array_equal(original, shortcuts_array);
617
bool collapse = !collapsed.has(E) || (collapsed.has(E) && collapsed[E]);
618
619
_create_shortcut_treeitem(section, E, sc->get_name(), shortcuts_array, !same_as_defaults, false, collapse);
620
}
621
622
// remove sections with no shortcuts
623
for (KeyValue<String, TreeItem *> &E : sections) {
624
TreeItem *section = E.value;
625
if (section->get_first_child() == nullptr) {
626
root->remove_child(section);
627
memdelete(section);
628
}
629
}
630
}
631
632
void EditorSettingsDialog::_shortcut_button_pressed(Object *p_item, int p_column, int p_idx, MouseButton p_button) {
633
if (p_button != MouseButton::LEFT) {
634
return;
635
}
636
TreeItem *ti = Object::cast_to<TreeItem>(p_item);
637
ERR_FAIL_NULL_MSG(ti, "Object passed is not a TreeItem.");
638
639
ShortcutButton button_idx = (ShortcutButton)p_idx;
640
641
is_editing_action = ti->get_meta("is_action");
642
643
String type = ti->get_meta("type");
644
645
if (type == "event") {
646
current_edited_identifier = ti->get_parent()->get_meta("shortcut_identifier");
647
current_events = ti->get_parent()->get_meta("events");
648
current_event_index = ti->get_meta("event_index");
649
} else { // Type is "shortcut"
650
current_edited_identifier = ti->get_meta("shortcut_identifier");
651
current_events = ti->get_meta("events");
652
current_event_index = -1;
653
}
654
655
switch (button_idx) {
656
case EditorSettingsDialog::SHORTCUT_ADD: {
657
// Only for "shortcut" types
658
shortcut_editor->popup_and_configure();
659
} break;
660
case EditorSettingsDialog::SHORTCUT_EDIT: {
661
// Only for "event" types
662
shortcut_editor->popup_and_configure(current_events[current_event_index]);
663
} break;
664
case EditorSettingsDialog::SHORTCUT_ERASE: {
665
if (type == "shortcut") {
666
if (is_editing_action) {
667
_update_builtin_action(current_edited_identifier, Array());
668
} else {
669
_update_shortcut_events(current_edited_identifier, Array());
670
}
671
} else if (type == "event") {
672
current_events.remove_at(current_event_index);
673
674
if (is_editing_action) {
675
_update_builtin_action(current_edited_identifier, current_events);
676
} else {
677
_update_shortcut_events(current_edited_identifier, current_events);
678
}
679
}
680
} break;
681
case EditorSettingsDialog::SHORTCUT_REVERT: {
682
// Only for "shortcut" types
683
if (is_editing_action) {
684
List<Ref<InputEvent>> defaults = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied()[current_edited_identifier];
685
Array events = _event_list_to_array_helper(defaults);
686
687
_update_builtin_action(current_edited_identifier, events);
688
} else {
689
Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(current_edited_identifier);
690
Array original = sc->get_meta("original");
691
_update_shortcut_events(current_edited_identifier, original);
692
}
693
} break;
694
default:
695
break;
696
}
697
}
698
699
void EditorSettingsDialog::_shortcut_cell_double_clicked() {
700
// When a shortcut cell is double clicked:
701
// If the cell has children and is in the bindings column, and if its first child is editable,
702
// then uncollapse the cell, and if the first child is the only child, then edit that child.
703
// If the cell is in the bindings column and can be edited, then edit it.
704
// If the cell is in the name column, then toggle collapse.
705
const ShortcutButton edit_btn_id = EditorSettingsDialog::SHORTCUT_EDIT;
706
const int edit_btn_col = 1;
707
TreeItem *ti = shortcuts->get_selected();
708
if (ti == nullptr) {
709
return;
710
}
711
712
String type = ti->get_meta("type");
713
int col = shortcuts->get_selected_column();
714
if (type == "shortcut" && col == 0) {
715
if (ti->get_first_child()) {
716
ti->set_collapsed(!ti->is_collapsed());
717
}
718
} else if (type == "shortcut" && col == 1) {
719
if (ti->get_first_child()) {
720
TreeItem *child_ti = ti->get_first_child();
721
if (child_ti->get_button_by_id(edit_btn_col, edit_btn_id) != -1) {
722
ti->set_collapsed(false);
723
if (ti->get_child_count() == 1) {
724
_shortcut_button_pressed(child_ti, edit_btn_col, edit_btn_id);
725
}
726
}
727
}
728
} else if (type == "event" && col == 1) {
729
if (ti->get_button_by_id(edit_btn_col, edit_btn_id) != -1) {
730
_shortcut_button_pressed(ti, edit_btn_col, edit_btn_id);
731
}
732
}
733
}
734
735
Variant EditorSettingsDialog::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
736
TreeItem *selected = shortcuts->get_selected();
737
738
// Only allow drag for events
739
if (!selected || (String)selected->get_meta("type", "") != "event") {
740
return Variant();
741
}
742
743
String label_text = vformat(TTRC("Event %d"), selected->get_meta("event_index"));
744
Label *label = memnew(Label(label_text));
745
label->set_modulate(Color(1, 1, 1, 1.0f));
746
shortcuts->set_drag_preview(label);
747
748
shortcuts->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN);
749
750
return Dictionary(); // No data required
751
}
752
753
bool EditorSettingsDialog::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
754
TreeItem *selected = shortcuts->get_selected();
755
TreeItem *item = (p_point == Vector2(Math::INF, Math::INF)) ? shortcuts->get_selected() : shortcuts->get_item_at_position(p_point);
756
if (!selected || !item || item == selected || (String)item->get_meta("type", "") != "event") {
757
return false;
758
}
759
760
// Don't allow moving an events in-between shortcuts.
761
if (selected->get_parent()->get_meta("shortcut_identifier") != item->get_parent()->get_meta("shortcut_identifier")) {
762
return false;
763
}
764
765
return true;
766
}
767
768
void EditorSettingsDialog::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
769
if (!can_drop_data_fw(p_point, p_data, p_from)) {
770
return;
771
}
772
773
TreeItem *selected = shortcuts->get_selected();
774
TreeItem *target = (p_point == Vector2(Math::INF, Math::INF)) ? shortcuts->get_selected() : shortcuts->get_item_at_position(p_point);
775
776
if (!target) {
777
return;
778
}
779
780
int target_event_index = target->get_meta("event_index");
781
int index_moving_from = selected->get_meta("event_index");
782
783
Array events = selected->get_parent()->get_meta("events");
784
785
Variant event_moved = events[index_moving_from];
786
events.remove_at(index_moving_from);
787
events.insert(target_event_index, event_moved);
788
789
String ident = selected->get_parent()->get_meta("shortcut_identifier");
790
if (selected->get_meta("is_action")) {
791
_update_builtin_action(ident, events);
792
} else {
793
_update_shortcut_events(ident, events);
794
}
795
}
796
797
void EditorSettingsDialog::_tabs_tab_changed(int p_tab) {
798
_focus_current_search_box();
799
800
// When tab has switched, shortcuts may have changed.
801
_update_dynamic_property_hints();
802
inspector->get_inspector()->update_tree();
803
}
804
805
void EditorSettingsDialog::_update_dynamic_property_hints() {
806
// Calling add_property_hint overrides the existing hint.
807
EditorSettings *settings = EditorSettings::get_singleton();
808
settings->add_property_hint(_create_mouse_shortcut_property_info("editors/3d/navigation/orbit_mouse_button", "spatial_editor/viewport_orbit_modifier_1", "spatial_editor/viewport_orbit_modifier_2"));
809
settings->add_property_hint(_create_mouse_shortcut_property_info("editors/3d/navigation/pan_mouse_button", "spatial_editor/viewport_pan_modifier_1", "spatial_editor/viewport_pan_modifier_2"));
810
settings->add_property_hint(_create_mouse_shortcut_property_info("editors/3d/navigation/zoom_mouse_button", "spatial_editor/viewport_zoom_modifier_1", "spatial_editor/viewport_zoom_modifier_2"));
811
}
812
813
PropertyInfo EditorSettingsDialog::_create_mouse_shortcut_property_info(const String &p_property_name, const String &p_shortcut_1_name, const String &p_shortcut_2_name) {
814
String hint_string;
815
hint_string += _get_shortcut_button_string(p_shortcut_1_name) + _get_shortcut_button_string(p_shortcut_2_name);
816
hint_string += "Left Mouse,";
817
hint_string += _get_shortcut_button_string(p_shortcut_1_name) + _get_shortcut_button_string(p_shortcut_2_name);
818
hint_string += "Middle Mouse,";
819
hint_string += _get_shortcut_button_string(p_shortcut_1_name) + _get_shortcut_button_string(p_shortcut_2_name);
820
hint_string += "Right Mouse,";
821
hint_string += _get_shortcut_button_string(p_shortcut_1_name) + _get_shortcut_button_string(p_shortcut_2_name);
822
hint_string += "Mouse Button 4,";
823
hint_string += _get_shortcut_button_string(p_shortcut_1_name) + _get_shortcut_button_string(p_shortcut_2_name);
824
hint_string += "Mouse Button 5";
825
826
return PropertyInfo(Variant::INT, p_property_name, PROPERTY_HINT_ENUM, hint_string);
827
}
828
829
String EditorSettingsDialog::_get_shortcut_button_string(const String &p_shortcut_name) {
830
String button_string;
831
Ref<Shortcut> shortcut_ref = EditorSettings::get_singleton()->get_shortcut(p_shortcut_name);
832
Array events = shortcut_ref->get_events();
833
for (Ref<InputEvent> input_event : events) {
834
button_string += input_event->as_text() + " + ";
835
}
836
return button_string;
837
}
838
839
void EditorSettingsDialog::_focus_current_search_box() {
840
Control *tab = tabs->get_current_tab_control();
841
LineEdit *current_search_box = nullptr;
842
if (tab == tab_general) {
843
current_search_box = search_box;
844
} else if (tab == tab_shortcuts) {
845
current_search_box = shortcut_search_bar->get_name_search_box();
846
}
847
848
if (current_search_box) {
849
current_search_box->grab_focus();
850
current_search_box->select_all();
851
}
852
}
853
854
void EditorSettingsDialog::_advanced_toggled(bool p_button_pressed) {
855
EditorSettings::get_singleton()->set("_editor_settings_advanced_mode", p_button_pressed);
856
}
857
858
void EditorSettingsDialog::_editor_restart() {
859
EditorNode::get_singleton()->save_all_scenes();
860
EditorNode::get_singleton()->restart_editor();
861
}
862
863
void EditorSettingsDialog::_editor_restart_request() {
864
restart_container->show();
865
}
866
867
void EditorSettingsDialog::_editor_restart_close() {
868
restart_container->hide();
869
}
870
871
void EditorSettingsDialog::_bind_methods() {
872
ClassDB::bind_method(D_METHOD("_update_shortcuts"), &EditorSettingsDialog::_update_shortcuts);
873
ClassDB::bind_method(D_METHOD("_settings_changed"), &EditorSettingsDialog::_settings_changed);
874
}
875
876
EditorSettingsDialog::EditorSettingsDialog() {
877
set_title(TTRC("Editor Settings"));
878
set_clamp_to_embedder(true);
879
880
tabs = memnew(TabContainer);
881
tabs->set_theme_type_variation("TabContainerOdd");
882
tabs->connect("tab_changed", callable_mp(this, &EditorSettingsDialog::_tabs_tab_changed));
883
add_child(tabs);
884
885
// General Tab
886
887
tab_general = memnew(VBoxContainer);
888
tabs->add_child(tab_general);
889
tab_general->set_name(TTRC("General"));
890
891
HBoxContainer *hbc = memnew(HBoxContainer);
892
hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
893
tab_general->add_child(hbc);
894
895
search_box = memnew(LineEdit);
896
search_box->set_placeholder(TTRC("Filter Settings"));
897
search_box->set_accessibility_name(TTRC("Filter Settings"));
898
search_box->set_virtual_keyboard_show_on_focus(false);
899
search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
900
hbc->add_child(search_box);
901
902
advanced_switch = memnew(CheckButton(TTRC("Advanced Settings")));
903
hbc->add_child(advanced_switch);
904
905
bool use_advanced = EDITOR_DEF("_editor_settings_advanced_mode", false);
906
advanced_switch->set_pressed(use_advanced);
907
advanced_switch->connect(SceneStringName(toggled), callable_mp(this, &EditorSettingsDialog::_advanced_toggled));
908
909
inspector = memnew(SectionedInspector);
910
inspector->get_inspector()->set_use_filter(true);
911
inspector->get_inspector()->set_mark_unsaved(false);
912
inspector->register_search_box(search_box);
913
inspector->register_advanced_toggle(advanced_switch);
914
inspector->set_v_size_flags(Control::SIZE_EXPAND_FILL);
915
tab_general->add_child(inspector);
916
inspector->get_inspector()->connect("property_edited", callable_mp(this, &EditorSettingsDialog::_settings_property_edited));
917
inspector->get_inspector()->connect("restart_requested", callable_mp(this, &EditorSettingsDialog::_editor_restart_request));
918
919
if (EDITOR_GET("interface/touchscreen/enable_touch_optimizations")) {
920
inspector->set_touch_dragger_enabled(true);
921
}
922
923
restart_container = memnew(PanelContainer);
924
tab_general->add_child(restart_container);
925
HBoxContainer *restart_hb = memnew(HBoxContainer);
926
restart_container->add_child(restart_hb);
927
restart_icon = memnew(TextureRect);
928
restart_icon->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
929
restart_hb->add_child(restart_icon);
930
restart_label = memnew(Label);
931
restart_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
932
restart_label->set_text(TTRC("The editor must be restarted for changes to take effect."));
933
restart_hb->add_child(restart_label);
934
restart_hb->add_spacer();
935
Button *restart_button = memnew(Button);
936
restart_button->connect(SceneStringName(pressed), callable_mp(this, &EditorSettingsDialog::_editor_restart));
937
restart_hb->add_child(restart_button);
938
restart_button->set_text(TTRC("Save & Restart"));
939
restart_close_button = memnew(Button);
940
restart_close_button->set_accessibility_name(TTRC("Close"));
941
restart_close_button->set_flat(true);
942
restart_close_button->connect(SceneStringName(pressed), callable_mp(this, &EditorSettingsDialog::_editor_restart_close));
943
restart_hb->add_child(restart_close_button);
944
restart_container->hide();
945
946
// Shortcuts Tab
947
948
tab_shortcuts = memnew(VBoxContainer);
949
950
tabs->add_child(tab_shortcuts);
951
tab_shortcuts->set_name(TTRC("Shortcuts"));
952
953
shortcut_search_bar = memnew(EditorEventSearchBar);
954
shortcut_search_bar->connect(SceneStringName(value_changed), callable_mp(this, &EditorSettingsDialog::_update_shortcuts));
955
tab_shortcuts->add_child(shortcut_search_bar);
956
957
shortcuts = memnew(Tree);
958
shortcuts->set_accessibility_name(TTRC("Shortcuts"));
959
shortcuts->set_v_size_flags(Control::SIZE_EXPAND_FILL);
960
shortcuts->set_columns(2);
961
shortcuts->set_hide_root(true);
962
shortcuts->set_column_titles_visible(true);
963
shortcuts->set_column_title(0, TTRC("Name"));
964
shortcuts->set_column_title(1, TTRC("Binding"));
965
shortcuts->connect("button_clicked", callable_mp(this, &EditorSettingsDialog::_shortcut_button_pressed));
966
shortcuts->connect("item_activated", callable_mp(this, &EditorSettingsDialog::_shortcut_cell_double_clicked));
967
tab_shortcuts->add_child(shortcuts);
968
969
SET_DRAG_FORWARDING_GCD(shortcuts, EditorSettingsDialog);
970
971
// Adding event dialog
972
shortcut_editor = memnew(InputEventConfigurationDialog);
973
shortcut_editor->connect(SceneStringName(confirmed), callable_mp(this, &EditorSettingsDialog::_event_config_confirmed));
974
shortcut_editor->set_allowed_input_types(INPUT_KEY);
975
add_child(shortcut_editor);
976
977
set_hide_on_ok(true);
978
979
timer = memnew(Timer);
980
timer->set_wait_time(1.5);
981
timer->connect("timeout", callable_mp(this, &EditorSettingsDialog::_settings_save));
982
timer->set_one_shot(true);
983
add_child(timer);
984
EditorSettings::get_singleton()->connect("settings_changed", callable_mp(this, &EditorSettingsDialog::_settings_changed));
985
set_ok_button_text(TTRC("Close"));
986
987
Ref<EditorSettingsInspectorPlugin> plugin;
988
plugin.instantiate();
989
plugin->inspector = inspector;
990
EditorInspector::add_inspector_plugin(plugin);
991
}
992
993
void EditorSettingsPropertyWrapper::_update_override() {
994
// Don't allow overriding theme properties, because it causes problems. Overriding Project Manager settings makes no sense.
995
// TODO: Find a better way to define exception prefixes (if the list happens to grow).
996
if (property.begins_with("interface/theme") || property.begins_with("project_manager")) {
997
can_override = false;
998
return;
999
}
1000
1001
const bool has_override = ProjectSettings::get_singleton()->has_editor_setting_override(property);
1002
if (has_override) {
1003
const Variant override_value = EDITOR_GET(property);
1004
override_label->set_text(vformat(TTR("Overridden in project: %s"), override_value));
1005
// In case the text is too long and trimmed.
1006
override_label->set_tooltip_text(override_value);
1007
}
1008
override_info->set_visible(has_override);
1009
can_override = !has_override;
1010
}
1011
1012
void EditorSettingsPropertyWrapper::_create_override() {
1013
ProjectSettings::get_singleton()->set_editor_setting_override(property, EDITOR_GET(property));
1014
ProjectSettings::get_singleton()->save();
1015
_update_override();
1016
}
1017
1018
void EditorSettingsPropertyWrapper::_remove_override() {
1019
ProjectSettings::get_singleton()->set_editor_setting_override(property, Variant());
1020
ProjectSettings::get_singleton()->save();
1021
EditorSettings::get_singleton()->mark_setting_changed(property);
1022
EditorNode::get_singleton()->notify_settings_overrides_changed();
1023
_update_override();
1024
1025
if (requires_restart) {
1026
restart_request_callback.call();
1027
}
1028
}
1029
1030
void EditorSettingsPropertyWrapper::_notification(int p_what) {
1031
if (p_what == NOTIFICATION_THEME_CHANGED) {
1032
goto_button->set_button_icon(get_editor_theme_icon(SNAME("MethodOverride")));
1033
remove_button->set_button_icon(get_editor_theme_icon(SNAME("Close")));
1034
}
1035
}
1036
1037
void EditorSettingsPropertyWrapper::update_property() {
1038
editor_property->update_property();
1039
}
1040
1041
void EditorSettingsPropertyWrapper::setup(const String &p_property, EditorProperty *p_editor_property, bool p_requires_restart) {
1042
requires_restart = p_requires_restart;
1043
1044
property = p_property;
1045
container = memnew(VBoxContainer);
1046
1047
editor_property = p_editor_property;
1048
editor_property->set_h_size_flags(SIZE_EXPAND_FILL);
1049
container->add_child(editor_property);
1050
1051
override_info = memnew(HBoxContainer);
1052
override_info->hide();
1053
container->add_child(override_info);
1054
1055
override_label = memnew(Label);
1056
override_label->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS);
1057
override_label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
1058
override_label->set_mouse_filter(MOUSE_FILTER_STOP); // For tooltip.
1059
override_label->set_h_size_flags(SIZE_EXPAND_FILL);
1060
override_info->add_child(override_label);
1061
1062
goto_button = memnew(Button);
1063
goto_button->set_tooltip_text(TTRC("Go to the override in the Project Settings."));
1064
override_info->add_child(goto_button);
1065
goto_button->connect(SceneStringName(pressed), callable_mp(EditorNode::get_singleton(), &EditorNode::open_setting_override).bind(property), CONNECT_DEFERRED);
1066
1067
remove_button = memnew(Button);
1068
remove_button->set_tooltip_text(TTRC("Remove this override."));
1069
override_info->add_child(remove_button);
1070
remove_button->connect(SceneStringName(pressed), callable_mp(this, &EditorSettingsPropertyWrapper::_remove_override));
1071
1072
add_child(container);
1073
_update_override();
1074
1075
connect(SNAME("property_overridden"), callable_mp(this, &EditorSettingsPropertyWrapper::_create_override));
1076
editor_property->connect("property_changed", callable_mp((EditorProperty *)this, &EditorProperty::emit_changed));
1077
}
1078
1079
bool EditorSettingsInspectorPlugin::can_handle(Object *p_object) {
1080
return p_object && p_object->is_class("SectionedInspectorFilter") && p_object != current_object;
1081
}
1082
1083
bool EditorSettingsInspectorPlugin::parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const BitField<PropertyUsageFlags> p_usage, const bool p_wide) {
1084
if (!p_object->is_class("SectionedInspectorFilter")) {
1085
return false;
1086
}
1087
1088
const String property = inspector->get_full_item_path(p_path);
1089
if (!EditorSettings::get_singleton()->has_setting(property)) {
1090
return false;
1091
}
1092
current_object = p_object;
1093
1094
EditorSettingsPropertyWrapper *editor = memnew(EditorSettingsPropertyWrapper);
1095
EditorProperty *real_property = inspector->get_inspector()->instantiate_property_editor(p_object, p_type, p_path, p_hint, p_hint_text, p_usage, p_wide);
1096
real_property->set_object_and_property(p_object, p_path);
1097
real_property->set_name_split_ratio(0.0);
1098
editor->setup(property, real_property, bool(p_usage & PROPERTY_USAGE_RESTART_IF_CHANGED));
1099
1100
add_property_editor(p_path, editor);
1101
current_object = nullptr;
1102
return true;
1103
}
1104
1105