Path: blob/master/editor/settings/editor_settings_dialog.cpp
20907 views
/**************************************************************************/1/* editor_settings_dialog.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "editor_settings_dialog.h"3132#include "core/config/project_settings.h"33#include "core/input/input_map.h"34#include "core/os/keyboard.h"35#include "editor/debugger/editor_debugger_node.h"36#include "editor/editor_log.h"37#include "editor/editor_node.h"38#include "editor/editor_string_names.h"39#include "editor/editor_undo_redo_manager.h"40#include "editor/inspector/editor_property_name_processor.h"41#include "editor/inspector/editor_sectioned_inspector.h"42#include "editor/scene/3d/node_3d_editor_plugin.h"43#include "editor/settings/editor_event_search_bar.h"44#include "editor/settings/editor_settings.h"45#include "editor/settings/event_listener_line_edit.h"46#include "editor/settings/input_event_configuration_dialog.h"47#include "editor/themes/editor_scale.h"48#include "editor/themes/editor_theme_manager.h"49#include "scene/gui/check_button.h"50#include "scene/gui/panel_container.h"51#include "scene/gui/tab_container.h"52#include "scene/gui/texture_rect.h"53#include "scene/gui/tree.h"5455void EditorSettingsDialog::ok_pressed() {56if (!EditorSettings::get_singleton()) {57return;58}59_settings_save();60}6162void EditorSettingsDialog::_settings_changed() {63timer->start();64}6566void EditorSettingsDialog::_settings_property_edited() {67Vector<String> changed = EditorSettings::get_singleton()->get_changed_settings();68if (changed.is_empty()) {69return;70}7172const String full_name = changed[changed.size() - 1];7374// Set theme presets to Custom when controlled settings change.7576if (full_name == "interface/theme/accent_color" || full_name == "interface/theme/base_color" || full_name == "interface/theme/contrast" || full_name == "interface/theme/draw_extra_borders" || full_name == "interface/theme/icon_saturation" || full_name == "interface/theme/draw_relationship_lines" || full_name == "interface/theme/corner_radius") {77EditorSettings::get_singleton()->set_manually("interface/theme/color_preset", "Custom");78} else if (full_name == "interface/theme/base_spacing" || full_name == "interface/theme/additional_spacing") {79EditorSettings::get_singleton()->set_manually("interface/theme/spacing_preset", "Custom");80} else if (full_name.begins_with("text_editor/theme/highlighting")) {81EditorSettings::get_singleton()->set_manually("text_editor/theme/color_theme", "Custom");82} else if (full_name.begins_with("editors/visual_editors/connection_colors") || full_name.begins_with("editors/visual_editors/category_colors")) {83EditorSettings::get_singleton()->set_manually("editors/visual_editors/color_theme", "Custom");84} 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") {85EditorSettings::get_singleton()->set_manually("editors/3d/navigation/navigation_scheme", (int)Node3DEditorViewport::NAVIGATION_CUSTOM);86} else if (full_name == "editors/3d/navigation/navigation_scheme") {87update_navigation_preset();88_update_shortcuts();89}90}9192void EditorSettingsDialog::update_navigation_preset() {93Node3DEditorViewport::NavigationScheme nav_scheme = (Node3DEditorViewport::NavigationScheme)EDITOR_GET("editors/3d/navigation/navigation_scheme").operator int();94Node3DEditorViewport::ViewportNavMouseButton set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;95Node3DEditorViewport::ViewportNavMouseButton set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;96Node3DEditorViewport::ViewportNavMouseButton set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;97bool set_3_button_mouse = false;98Ref<InputEventKey> orbit_mod_key_1;99Ref<InputEventKey> orbit_mod_key_2;100Ref<InputEventKey> pan_mod_key_1;101Ref<InputEventKey> pan_mod_key_2;102Ref<InputEventKey> zoom_mod_key_1;103Ref<InputEventKey> zoom_mod_key_2;104Ref<InputEventKey> orbit_snap_mod_key_1;105Ref<InputEventKey> orbit_snap_mod_key_2;106bool set_preset = false;107108if (nav_scheme == Node3DEditorViewport::NAVIGATION_GODOT) {109set_preset = true;110set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;111set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;112set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;113set_3_button_mouse = false;114orbit_mod_key_1 = InputEventKey::create_reference(Key::NONE);115orbit_mod_key_2 = InputEventKey::create_reference(Key::NONE);116pan_mod_key_1 = InputEventKey::create_reference(Key::SHIFT);117pan_mod_key_2 = InputEventKey::create_reference(Key::NONE);118zoom_mod_key_1 = InputEventKey::create_reference(Key::CTRL);119zoom_mod_key_2 = InputEventKey::create_reference(Key::NONE);120orbit_snap_mod_key_1 = InputEventKey::create_reference(Key::ALT);121orbit_snap_mod_key_2 = InputEventKey::create_reference(Key::NONE);122} else if (nav_scheme == Node3DEditorViewport::NAVIGATION_MAYA) {123set_preset = true;124set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;125set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;126set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_RIGHT_MOUSE;127set_3_button_mouse = false;128orbit_mod_key_1 = InputEventKey::create_reference(Key::ALT);129orbit_mod_key_2 = InputEventKey::create_reference(Key::NONE);130pan_mod_key_1 = InputEventKey::create_reference(Key::NONE);131pan_mod_key_2 = InputEventKey::create_reference(Key::NONE);132zoom_mod_key_1 = InputEventKey::create_reference(Key::ALT);133zoom_mod_key_2 = InputEventKey::create_reference(Key::NONE);134orbit_snap_mod_key_1 = InputEventKey::create_reference(Key::NONE);135orbit_snap_mod_key_2 = InputEventKey::create_reference(Key::NONE);136} else if (nav_scheme == Node3DEditorViewport::NAVIGATION_MODO) {137set_preset = true;138set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;139set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;140set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;141set_3_button_mouse = false;142orbit_mod_key_1 = InputEventKey::create_reference(Key::ALT);143orbit_mod_key_2 = InputEventKey::create_reference(Key::NONE);144pan_mod_key_1 = InputEventKey::create_reference(Key::SHIFT);145pan_mod_key_2 = InputEventKey::create_reference(Key::ALT);146zoom_mod_key_1 = InputEventKey::create_reference(Key::ALT);147zoom_mod_key_2 = InputEventKey::create_reference(Key::CTRL);148orbit_snap_mod_key_1 = InputEventKey::create_reference(Key::NONE);149orbit_snap_mod_key_2 = InputEventKey::create_reference(Key::NONE);150} else if (nav_scheme == Node3DEditorViewport::NAVIGATION_TABLET) {151set_preset = true;152set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;153set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;154set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;155set_3_button_mouse = true;156orbit_mod_key_1 = InputEventKey::create_reference(Key::ALT);157orbit_mod_key_2 = InputEventKey::create_reference(Key::NONE);158pan_mod_key_1 = InputEventKey::create_reference(Key::SHIFT);159pan_mod_key_2 = InputEventKey::create_reference(Key::NONE);160zoom_mod_key_1 = InputEventKey::create_reference(Key::CTRL);161zoom_mod_key_2 = InputEventKey::create_reference(Key::NONE);162orbit_snap_mod_key_1 = InputEventKey::create_reference(Key::NONE);163orbit_snap_mod_key_2 = InputEventKey::create_reference(Key::NONE);164}165// Set settings to the desired preset values.166if (set_preset) {167EditorSettings::get_singleton()->set_manually("editors/3d/navigation/orbit_mouse_button", (int)set_orbit_mouse_button);168EditorSettings::get_singleton()->set_manually("editors/3d/navigation/pan_mouse_button", (int)set_pan_mouse_button);169EditorSettings::get_singleton()->set_manually("editors/3d/navigation/zoom_mouse_button", (int)set_zoom_mouse_button);170EditorSettings::get_singleton()->set_manually("editors/3d/navigation/emulate_3_button_mouse", set_3_button_mouse);171_set_shortcut_input("spatial_editor/viewport_orbit_modifier_1", orbit_mod_key_1);172_set_shortcut_input("spatial_editor/viewport_orbit_modifier_2", orbit_mod_key_2);173_set_shortcut_input("spatial_editor/viewport_pan_modifier_1", pan_mod_key_1);174_set_shortcut_input("spatial_editor/viewport_pan_modifier_2", pan_mod_key_2);175_set_shortcut_input("spatial_editor/viewport_zoom_modifier_1", zoom_mod_key_1);176_set_shortcut_input("spatial_editor/viewport_zoom_modifier_2", zoom_mod_key_2);177_set_shortcut_input("spatial_editor/viewport_orbit_snap_modifier_1", orbit_snap_mod_key_1);178_set_shortcut_input("spatial_editor/viewport_orbit_snap_modifier_2", orbit_snap_mod_key_2);179}180}181182void EditorSettingsDialog::_set_shortcut_input(const String &p_name, Ref<InputEventKey> &p_event) {183Array sc_events;184if (p_event->get_keycode() != Key::NONE) {185sc_events.push_back((Variant)p_event);186}187188Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_name);189sc->set_events(sc_events);190}191192void EditorSettingsDialog::_settings_save() {193if (!timer->is_stopped()) {194timer->stop();195}196EditorSettings::get_singleton()->notify_changes();197EditorSettings::get_singleton()->save();198}199200void EditorSettingsDialog::cancel_pressed() {201if (!EditorSettings::get_singleton()) {202return;203}204205EditorSettings::get_singleton()->notify_changes();206}207208void EditorSettingsDialog::popup_edit_settings() {209if (!EditorSettings::get_singleton()) {210return;211}212213EditorSettings::get_singleton()->update_text_editor_themes_list(); // Make sure we have an up to date list of themes.214215_update_dynamic_property_hints();216217inspector->edit(EditorSettings::get_singleton());218inspector->get_inspector()->update_tree();219220_update_shortcuts();221set_process_shortcut_input(true);222223// Restore valid window bounds or pop up at default size.224Rect2 saved_size;225if (!_is_in_project_manager()) {226saved_size = EditorSettings::get_singleton()->get_project_metadata("dialog_bounds", "editor_settings", Rect2());227}228229if (saved_size != Rect2()) {230popup(saved_size);231} else if (_is_in_project_manager()) {232popup_centered_clamped(Size2(800, 600) * EDSCALE, 0.8); // Make it smaller that the default Project Manager size.233} else {234popup_centered_clamped(Size2(900, 700) * EDSCALE, 0.8);235}236237_focus_current_search_box();238}239240void EditorSettingsDialog::_undo_redo_callback(void *p_self, const String &p_name) {241EditorNode::get_log()->add_message(p_name, EditorLog::MSG_TYPE_EDITOR);242}243244void EditorSettingsDialog::_notification(int p_what) {245switch (p_what) {246case NOTIFICATION_VISIBILITY_CHANGED: {247if (!is_visible() && !_is_in_project_manager()) {248EditorSettings::get_singleton()->set_project_metadata("dialog_bounds", "editor_settings", Rect2(get_position(), get_size()));249set_process_shortcut_input(false);250}251} break;252253case NOTIFICATION_READY: {254EditorSettingsPropertyWrapper::restart_request_callback = callable_mp(this, &EditorSettingsDialog::_editor_restart_request);255256if (_is_in_project_manager()) {257return;258}259EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();260undo_redo->get_or_create_history(EditorUndoRedoManager::GLOBAL_HISTORY).undo_redo->set_method_notify_callback(EditorDebuggerNode::_methods_changed, nullptr);261undo_redo->get_or_create_history(EditorUndoRedoManager::GLOBAL_HISTORY).undo_redo->set_property_notify_callback(EditorDebuggerNode::_properties_changed, nullptr);262undo_redo->get_or_create_history(EditorUndoRedoManager::GLOBAL_HISTORY).undo_redo->set_commit_notify_callback(_undo_redo_callback, this);263} break;264265case NOTIFICATION_ENTER_TREE: {266_update_icons();267} break;268269case NOTIFICATION_THEME_CHANGED: {270_update_shortcuts();271} break;272273case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {274if (EditorThemeManager::is_generated_theme_outdated()) {275_update_icons();276}277278bool update_shortcuts_tab =279EditorSettings::get_singleton()->check_changed_settings_in_group("shortcuts") ||280EditorSettings::get_singleton()->check_changed_settings_in_group("builtin_action_overrides");281if (update_shortcuts_tab) {282_update_shortcuts();283}284285if (EditorSettings::get_singleton()->check_changed_settings_in_group("editors/3d/navigation")) {286// Shortcuts may have changed, so dynamic hint values must update.287_update_dynamic_property_hints();288inspector->get_inspector()->update_tree();289}290291if (EditorSettings::get_singleton()->check_changed_settings_in_group("interface/editor/localize_settings")) {292inspector->update_category_list();293}294} break;295}296}297298void EditorSettingsDialog::shortcut_input(const Ref<InputEvent> &p_event) {299const Ref<InputEventKey> k = p_event;300if (k.is_valid() && k->is_pressed()) {301bool handled = false;302303if (EditorNode::get_singleton()) {304if (ED_IS_SHORTCUT("ui_undo", p_event)) {305EditorNode::get_singleton()->undo();306handled = true;307}308309if (ED_IS_SHORTCUT("ui_redo", p_event)) {310EditorNode::get_singleton()->redo();311handled = true;312}313}314315if (k->is_match(InputEventKey::create_reference(KeyModifierMask::CMD_OR_CTRL | Key::F))) {316_focus_current_search_box();317handled = true;318}319320if (handled) {321set_input_as_handled();322}323}324}325326void EditorSettingsDialog::_update_icons() {327search_box->set_right_icon(get_editor_theme_icon(SNAME("Search")));328search_box->set_clear_button_enabled(true);329330restart_close_button->set_button_icon(get_editor_theme_icon(SNAME("Close")));331restart_container->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SceneStringName(panel), SNAME("Tree")));332restart_icon->set_texture(get_editor_theme_icon(SNAME("StatusWarning")));333restart_label->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("warning_color"), EditorStringName(Editor)));334}335336void EditorSettingsDialog::_event_config_confirmed() {337Ref<InputEventKey> k = shortcut_editor->get_event();338if (k.is_null()) {339return;340}341342if (current_event_index == -1) {343// Add new event344current_events.push_back(k);345} else {346// Edit existing event347current_events[current_event_index] = k;348}349350if (is_editing_action) {351_update_builtin_action(current_edited_identifier, current_events);352} else {353_update_shortcut_events(current_edited_identifier, current_events);354}355}356357bool EditorSettingsDialog::_is_in_project_manager() const {358return !ProjectSettings::get_singleton()->is_project_loaded();359}360361void EditorSettingsDialog::_update_builtin_action(const String &p_name, const Array &p_events) {362Array old_input_array = EditorSettings::get_singleton()->get_builtin_action_overrides(p_name);363if (old_input_array.is_empty()) {364List<Ref<InputEvent>> defaults = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied()[current_edited_identifier];365old_input_array = _event_list_to_array_helper(defaults);366}367368if (_is_in_project_manager()) {369// Project Manager doesn't have EditorUndoRedoManager, so apply changes directly.370EditorSettings::get_singleton()->mark_setting_changed("builtin_action_overrides");371EditorSettings::get_singleton()->set_builtin_action_override(p_name, p_events);372_update_shortcuts();373_settings_changed();374} else {375EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();376undo_redo->create_action(vformat(TTR("Edit Built-in Action: %s"), p_name));377undo_redo->add_do_method(EditorSettings::get_singleton(), "mark_setting_changed", "builtin_action_overrides");378undo_redo->add_undo_method(EditorSettings::get_singleton(), "mark_setting_changed", "builtin_action_overrides");379undo_redo->add_do_method(EditorSettings::get_singleton(), "set_builtin_action_override", p_name, p_events);380undo_redo->add_undo_method(EditorSettings::get_singleton(), "set_builtin_action_override", p_name, old_input_array);381undo_redo->add_do_method(this, "_update_shortcuts");382undo_redo->add_undo_method(this, "_update_shortcuts");383undo_redo->add_do_method(this, "_settings_changed");384undo_redo->add_undo_method(this, "_settings_changed");385undo_redo->commit_action();386}387}388389void EditorSettingsDialog::_update_shortcut_events(const String &p_path, const Array &p_events) {390Ref<Shortcut> current_sc = EditorSettings::get_singleton()->get_shortcut(p_path);391392if (_is_in_project_manager()) {393// Project Manager doesn't have EditorUndoRedoManager, so apply changes directly.394current_sc->set_events(p_events);395EditorSettings::get_singleton()->mark_setting_changed("shortcuts");396_update_shortcuts();397_settings_changed();398} else {399EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();400undo_redo->create_action(vformat(TTR("Edit Shortcut: %s"), p_path), UndoRedo::MERGE_DISABLE, EditorSettings::get_singleton());401// History must be fixed based on the EditorSettings object because current_sc would402// incorrectly make this action use the scene history.403undo_redo->force_fixed_history();404undo_redo->add_do_method(current_sc.ptr(), "set_events", p_events);405undo_redo->add_undo_method(current_sc.ptr(), "set_events", current_sc->get_events());406undo_redo->add_do_method(EditorSettings::get_singleton(), "mark_setting_changed", "shortcuts");407undo_redo->add_undo_method(EditorSettings::get_singleton(), "mark_setting_changed", "shortcuts");408undo_redo->add_do_method(this, "_update_shortcuts");409undo_redo->add_undo_method(this, "_update_shortcuts");410undo_redo->add_do_method(this, "_settings_changed");411undo_redo->add_undo_method(this, "_settings_changed");412undo_redo->commit_action();413}414415bool path_is_orbit_mod = p_path == "spatial_editor/viewport_orbit_modifier_1" || p_path == "spatial_editor/viewport_orbit_modifier_2";416bool path_is_pan_mod = p_path == "spatial_editor/viewport_pan_modifier_1" || p_path == "spatial_editor/viewport_pan_modifier_2";417bool path_is_zoom_mod = p_path == "spatial_editor/viewport_zoom_modifier_1" || p_path == "spatial_editor/viewport_zoom_modifier_2";418if (path_is_orbit_mod || path_is_pan_mod || path_is_zoom_mod) {419EditorSettings::get_singleton()->set_manually("editors/3d/navigation/navigation_scheme", (int)Node3DEditorViewport::NAVIGATION_CUSTOM);420}421}422423Array EditorSettingsDialog::_event_list_to_array_helper(const List<Ref<InputEvent>> &p_events) {424Array events;425426// Convert the list to an array, and only keep key events as this is for the editor.427for (const List<Ref<InputEvent>>::Element *E = p_events.front(); E; E = E->next()) {428Ref<InputEventKey> k = E->get();429if (k.is_valid()) {430events.append(E->get());431}432}433434return events;435}436437TreeItem *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) {438TreeItem *shortcut_item = shortcuts->create_item(p_parent);439shortcut_item->set_collapsed(p_is_collapsed);440shortcut_item->set_text(0, p_display);441442Ref<InputEvent> primary = p_events.size() > 0 ? Ref<InputEvent>(p_events[0]) : Ref<InputEvent>();443Ref<InputEvent> secondary = p_events.size() > 1 ? Ref<InputEvent>(p_events[1]) : Ref<InputEvent>();444445String sc_text = TTRC("None");446if (primary.is_valid()) {447sc_text = primary->as_text();448449if (secondary.is_valid()) {450sc_text += ", " + secondary->as_text();451452if (p_events.size() > 2) {453sc_text += " (+" + itos(p_events.size() - 2) + ")";454}455}456shortcut_item->set_auto_translate_mode(1, AUTO_TRANSLATE_MODE_DISABLED);457}458459shortcut_item->set_text(1, sc_text);460if (sc_text == "None") {461// Fade out unassigned shortcut labels for easier visual grepping.462shortcut_item->set_custom_color(1, get_theme_color(SceneStringName(font_color), SNAME("Label")) * Color(1, 1, 1, 0.5));463}464465if (p_allow_revert) {466shortcut_item->add_button(1, get_editor_theme_icon(SNAME("Reload")), SHORTCUT_REVERT);467}468469shortcut_item->add_button(1, get_editor_theme_icon(SNAME("Add")), SHORTCUT_ADD);470shortcut_item->add_button(1, get_editor_theme_icon(SNAME("Close")), SHORTCUT_ERASE, p_events.is_empty());471472shortcut_item->set_meta("is_action", p_is_action);473shortcut_item->set_meta("type", "shortcut");474shortcut_item->set_meta("shortcut_identifier", p_shortcut_identifier);475shortcut_item->set_meta("events", p_events);476477// Shortcut Input Events478for (int i = 0; i < p_events.size(); i++) {479Ref<InputEvent> ie = p_events[i];480if (ie.is_null()) {481continue;482}483484TreeItem *event_item = shortcuts->create_item(shortcut_item);485486// TRANSLATORS: This is the label for the main input event of a shortcut.487event_item->set_text(0, shortcut_item->get_child_count() == 1 ? TTRC("Primary") : "");488event_item->set_text(1, ie->as_text());489event_item->set_auto_translate_mode(1, AUTO_TRANSLATE_MODE_DISABLED);490491event_item->add_button(1, get_editor_theme_icon(SNAME("Edit")), SHORTCUT_EDIT);492event_item->add_button(1, get_editor_theme_icon(SNAME("Close")), SHORTCUT_ERASE);493494event_item->set_custom_bg_color(0, get_theme_color(SNAME("dark_color_3"), EditorStringName(Editor)));495event_item->set_custom_bg_color(1, get_theme_color(SNAME("dark_color_3"), EditorStringName(Editor)));496497event_item->set_meta("is_action", p_is_action);498event_item->set_meta("type", "event");499event_item->set_meta("event_index", i);500}501502return shortcut_item;503}504505bool EditorSettingsDialog::_should_display_shortcut(const String &p_name, const Array &p_events, bool p_match_localized_name) const {506const Ref<InputEvent> search_ev = shortcut_search_bar->get_event();507if (search_ev.is_valid()) {508bool event_match = false;509for (int i = 0; i < p_events.size(); ++i) {510const Ref<InputEvent> ev = p_events[i];511if (ev.is_valid() && ev->is_match(search_ev, true)) {512event_match = true;513break;514}515}516if (!event_match) {517return false;518}519}520521const String &search_text = shortcut_search_bar->get_name();522if (search_text.is_empty()) {523return true;524}525if (search_text.is_subsequence_ofn(p_name)) {526return true;527}528if (p_match_localized_name && search_text.is_subsequence_ofn(TTR(p_name))) {529return true;530}531532return false;533}534535void EditorSettingsDialog::_update_shortcuts() {536// Before clearing the tree, take note of which categories are collapsed so that this state can be maintained when the tree is repopulated.537HashMap<String, bool> collapsed;538539if (shortcuts->get_root() && shortcuts->get_root()->get_first_child()) {540TreeItem *ti = shortcuts->get_root()->get_first_child();541while (ti) {542// 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.543if (ti->get_first_child() && ti->has_meta("shortcut_identifier")) {544collapsed[ti->get_meta("shortcut_identifier")] = ti->is_collapsed();545} else {546collapsed[ti->get_text(0)] = ti->is_collapsed();547}548549// Try go down tree550TreeItem *ti_next = ti->get_first_child();551// Try go to the next node via in-order traversal552if (!ti_next) {553ti_next = ti;554while (ti_next && !ti_next->get_next()) {555ti_next = ti_next->get_parent();556}557if (ti_next) {558ti_next = ti_next->get_next();559}560}561562ti = ti_next;563}564}565566String prev_selected_shortcut;567if (shortcuts->get_selected()) {568prev_selected_shortcut = shortcuts->get_selected()->get_text(0);569}570571shortcuts->clear();572573TreeItem *root = shortcuts->create_item();574HashMap<String, TreeItem *> sections;575576// Set up section for Common/Built-in actions577TreeItem *common_section = shortcuts->create_item(root);578sections["Common"] = common_section;579common_section->set_text(0, TTRC("Common"));580common_section->set_selectable(0, false);581common_section->set_selectable(1, false);582if (collapsed.has("Common")) {583common_section->set_collapsed(collapsed["Common"]);584}585common_section->set_custom_bg_color(0, get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));586common_section->set_custom_bg_color(1, get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));587588// Get the action map for the editor, and add each item to the "Common" section.589for (const KeyValue<StringName, InputMap::Action> &E : InputMap::get_singleton()->get_action_map()) {590const String &action_name = E.key;591const InputMap::Action &action = E.value;592593// Skip non-builtin actions.594if (!InputMap::get_singleton()->get_builtins_with_feature_overrides_applied().has(action_name)) {595continue;596}597598const List<Ref<InputEvent>> &all_default_events = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied().find(action_name)->value;599Array action_events = _event_list_to_array_helper(action.inputs);600if (!_should_display_shortcut(action_name, action_events, false)) {601continue;602}603604Array default_events = _event_list_to_array_helper(all_default_events);605bool same_as_defaults = Shortcut::is_event_array_equal(default_events, action_events);606bool collapse = !collapsed.has(action_name) || (collapsed.has(action_name) && collapsed[action_name]);607608TreeItem *item = _create_shortcut_treeitem(common_section, action_name, action_name, action_events, !same_as_defaults, true, collapse);609item->set_auto_translate_mode(0, AUTO_TRANSLATE_MODE_DISABLED); // `ui_*` input action names are untranslatable identifiers.610if (!prev_selected_shortcut.is_empty() && action_name == prev_selected_shortcut) {611item->select(0);612}613}614615// Editor Shortcuts616617List<String> slist;618EditorSettings::get_singleton()->get_shortcut_list(&slist);619slist.sort(); // Sort alphabetically.620621const EditorPropertyNameProcessor::Style name_style = EditorPropertyNameProcessor::get_settings_style();622const EditorPropertyNameProcessor::Style tooltip_style = EditorPropertyNameProcessor::get_tooltip_style(name_style);623624// Create all sections first.625for (const String &E : slist) {626Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(E);627String section_name = E.get_slicec('/', 0);628629if (sections.has(section_name)) {630continue;631}632633TreeItem *section = shortcuts->create_item(root);634635const String item_name = EditorPropertyNameProcessor::get_singleton()->process_name(section_name, name_style, E);636const String tooltip = EditorPropertyNameProcessor::get_singleton()->process_name(section_name, tooltip_style, E);637638section->set_auto_translate_mode(0, AUTO_TRANSLATE_MODE_DISABLED); // Already translated manually.639section->set_text(0, item_name);640section->set_tooltip_text(0, tooltip);641section->set_selectable(0, false);642section->set_selectable(1, false);643section->set_custom_bg_color(0, get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));644section->set_custom_bg_color(1, get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));645646if (collapsed.has(item_name)) {647section->set_collapsed(collapsed[item_name]);648}649650sections[section_name] = section;651}652653// Add shortcuts to sections.654for (const String &E : slist) {655Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(E);656if (!sc->has_meta("original")) {657continue;658}659660String section_name = E.get_slicec('/', 0);661TreeItem *section = sections[section_name];662663if (!_should_display_shortcut(sc->get_name(), sc->get_events(), true)) {664continue;665}666667Array original = sc->get_meta("original");668Array shortcuts_array = sc->get_events().duplicate(true);669bool same_as_defaults = Shortcut::is_event_array_equal(original, shortcuts_array);670bool collapse = !collapsed.has(E) || (collapsed.has(E) && collapsed[E]);671672TreeItem *shortcut_item = _create_shortcut_treeitem(section, E, sc->get_name(), shortcuts_array, !same_as_defaults, false, collapse);673if (!prev_selected_shortcut.is_empty() && sc->get_name() == prev_selected_shortcut) {674shortcut_item->select(0);675}676}677678if (!prev_selected_shortcut.is_empty()) {679shortcuts->ensure_cursor_is_visible();680}681682// remove sections with no shortcuts683for (KeyValue<String, TreeItem *> &E : sections) {684TreeItem *section = E.value;685if (section->get_first_child() == nullptr) {686root->remove_child(section);687memdelete(section);688}689}690}691692void EditorSettingsDialog::_shortcut_button_pressed(Object *p_item, int p_column, int p_idx, MouseButton p_button) {693if (p_button != MouseButton::LEFT) {694return;695}696TreeItem *ti = Object::cast_to<TreeItem>(p_item);697ERR_FAIL_NULL_MSG(ti, "Object passed is not a TreeItem.");698699ShortcutButton button_idx = (ShortcutButton)p_idx;700701is_editing_action = ti->get_meta("is_action");702703String type = ti->get_meta("type");704705if (type == "event") {706current_edited_identifier = ti->get_parent()->get_meta("shortcut_identifier");707current_events = ti->get_parent()->get_meta("events");708current_event_index = ti->get_meta("event_index");709} else { // Type is "shortcut"710current_edited_identifier = ti->get_meta("shortcut_identifier");711current_events = ti->get_meta("events");712current_event_index = -1;713}714715switch (button_idx) {716case EditorSettingsDialog::SHORTCUT_ADD: {717// Only for "shortcut" types718shortcut_editor->popup_and_configure();719} break;720case EditorSettingsDialog::SHORTCUT_EDIT: {721// Only for "event" types722shortcut_editor->popup_and_configure(current_events[current_event_index]);723} break;724case EditorSettingsDialog::SHORTCUT_ERASE: {725if (type == "shortcut") {726if (is_editing_action) {727_update_builtin_action(current_edited_identifier, Array());728} else {729_update_shortcut_events(current_edited_identifier, Array());730}731} else if (type == "event") {732current_events.remove_at(current_event_index);733734if (is_editing_action) {735_update_builtin_action(current_edited_identifier, current_events);736} else {737_update_shortcut_events(current_edited_identifier, current_events);738}739}740} break;741case EditorSettingsDialog::SHORTCUT_REVERT: {742// Only for "shortcut" types743if (is_editing_action) {744List<Ref<InputEvent>> defaults = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied()[current_edited_identifier];745Array events = _event_list_to_array_helper(defaults);746747_update_builtin_action(current_edited_identifier, events);748} else {749Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(current_edited_identifier);750Array original = sc->get_meta("original");751_update_shortcut_events(current_edited_identifier, original);752}753} break;754default:755break;756}757}758759void EditorSettingsDialog::_shortcut_cell_double_clicked() {760// When a shortcut cell is double clicked:761// If the cell has children and is in the bindings column, and if its first child is editable,762// then uncollapse the cell, and if the first child is the only child, then edit that child.763// If the cell is in the bindings column and can be edited, then edit it.764// If the cell is in the name column, then toggle collapse.765const ShortcutButton edit_btn_id = EditorSettingsDialog::SHORTCUT_EDIT;766const int edit_btn_col = 1;767TreeItem *ti = shortcuts->get_selected();768if (ti == nullptr) {769return;770}771772String type = ti->get_meta("type");773int col = shortcuts->get_selected_column();774if (type == "shortcut" && col == 0) {775if (ti->get_first_child()) {776ti->set_collapsed(!ti->is_collapsed());777}778} else if (type == "shortcut" && col == 1) {779if (ti->get_first_child()) {780TreeItem *child_ti = ti->get_first_child();781if (child_ti->get_button_by_id(edit_btn_col, edit_btn_id) != -1) {782ti->set_collapsed(false);783if (ti->get_child_count() == 1) {784_shortcut_button_pressed(child_ti, edit_btn_col, edit_btn_id);785}786}787}788} else if (type == "event" && col == 1) {789if (ti->get_button_by_id(edit_btn_col, edit_btn_id) != -1) {790_shortcut_button_pressed(ti, edit_btn_col, edit_btn_id);791}792}793}794795Variant EditorSettingsDialog::get_drag_data_fw(const Point2 &p_point, Control *p_from) {796TreeItem *selected = shortcuts->get_selected();797798// Only allow drag for events799if (!selected || (String)selected->get_meta("type", "") != "event") {800return Variant();801}802803String label_text = vformat(TTR("Event %d"), selected->get_meta("event_index"));804Label *label = memnew(Label(label_text));805label->set_modulate(Color(1, 1, 1, 1.0f));806shortcuts->set_drag_preview(label);807808shortcuts->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN);809810return Dictionary(); // No data required811}812813bool EditorSettingsDialog::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {814TreeItem *selected = shortcuts->get_selected();815TreeItem *item = (p_point == Vector2(Math::INF, Math::INF)) ? shortcuts->get_selected() : shortcuts->get_item_at_position(p_point);816if (!selected || !item || item == selected || (String)item->get_meta("type", "") != "event") {817return false;818}819820// Don't allow moving an events in-between shortcuts.821if (selected->get_parent()->get_meta("shortcut_identifier") != item->get_parent()->get_meta("shortcut_identifier")) {822return false;823}824825return true;826}827828void EditorSettingsDialog::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {829if (!can_drop_data_fw(p_point, p_data, p_from)) {830return;831}832833TreeItem *selected = shortcuts->get_selected();834TreeItem *target = (p_point == Vector2(Math::INF, Math::INF)) ? shortcuts->get_selected() : shortcuts->get_item_at_position(p_point);835836if (!target) {837return;838}839840int target_event_index = target->get_meta("event_index");841int index_moving_from = selected->get_meta("event_index");842843Array events = selected->get_parent()->get_meta("events");844845Variant event_moved = events[index_moving_from];846events.remove_at(index_moving_from);847events.insert(target_event_index, event_moved);848849String ident = selected->get_parent()->get_meta("shortcut_identifier");850if (selected->get_meta("is_action")) {851_update_builtin_action(ident, events);852} else {853_update_shortcut_events(ident, events);854}855}856857void EditorSettingsDialog::_tabs_tab_changed(int p_tab) {858_focus_current_search_box();859860// When tab has switched, shortcuts may have changed.861_update_dynamic_property_hints();862inspector->get_inspector()->update_tree();863}864865void EditorSettingsDialog::_update_dynamic_property_hints() {866// Calling add_property_hint overrides the existing hint.867EditorSettings *settings = EditorSettings::get_singleton();868settings->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"));869settings->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"));870settings->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"));871}872873PropertyInfo EditorSettingsDialog::_create_mouse_shortcut_property_info(const String &p_property_name, const String &p_shortcut_1_name, const String &p_shortcut_2_name) {874String hint_string;875hint_string += _get_shortcut_button_string(p_shortcut_1_name) + _get_shortcut_button_string(p_shortcut_2_name);876hint_string += "Left Mouse,";877hint_string += _get_shortcut_button_string(p_shortcut_1_name) + _get_shortcut_button_string(p_shortcut_2_name);878hint_string += "Middle Mouse,";879hint_string += _get_shortcut_button_string(p_shortcut_1_name) + _get_shortcut_button_string(p_shortcut_2_name);880hint_string += "Right Mouse,";881hint_string += _get_shortcut_button_string(p_shortcut_1_name) + _get_shortcut_button_string(p_shortcut_2_name);882hint_string += "Mouse Button 4,";883hint_string += _get_shortcut_button_string(p_shortcut_1_name) + _get_shortcut_button_string(p_shortcut_2_name);884hint_string += "Mouse Button 5";885886return PropertyInfo(Variant::INT, p_property_name, PROPERTY_HINT_ENUM, hint_string);887}888889String EditorSettingsDialog::_get_shortcut_button_string(const String &p_shortcut_name) {890String button_string;891Ref<Shortcut> shortcut_ref = EditorSettings::get_singleton()->get_shortcut(p_shortcut_name);892if (shortcut_ref.is_null()) {893return String();894}895896Array events = shortcut_ref->get_events();897for (Ref<InputEvent> input_event : events) {898button_string += input_event->as_text() + " + ";899}900return button_string;901}902903void EditorSettingsDialog::_focus_current_search_box() {904Control *tab = tabs->get_current_tab_control();905LineEdit *current_search_box = nullptr;906if (tab == tab_general) {907current_search_box = search_box;908} else if (tab == tab_shortcuts) {909current_search_box = shortcut_search_bar->get_name_search_box();910}911912if (current_search_box) {913current_search_box->grab_focus();914current_search_box->select_all();915}916}917918void EditorSettingsDialog::_advanced_toggled(bool p_button_pressed) {919EditorSettings::get_singleton()->set("_editor_settings_advanced_mode", p_button_pressed);920}921922void EditorSettingsDialog::_editor_restart() {923emit_signal("restart_requested");924}925926void EditorSettingsDialog::_editor_restart_request() {927restart_container->show();928}929930void EditorSettingsDialog::_editor_restart_close() {931restart_container->hide();932}933934void EditorSettingsDialog::_bind_methods() {935ClassDB::bind_method(D_METHOD("_update_shortcuts"), &EditorSettingsDialog::_update_shortcuts);936ClassDB::bind_method(D_METHOD("_settings_changed"), &EditorSettingsDialog::_settings_changed);937938ADD_SIGNAL(MethodInfo("restart_requested"));939}940941EditorSettingsDialog::EditorSettingsDialog() {942set_title(TTRC("Editor Settings"));943set_flag(FLAG_MAXIMIZE_DISABLED, false);944set_clamp_to_embedder(true);945946tabs = memnew(TabContainer);947tabs->set_theme_type_variation("TabContainerOdd");948tabs->connect("tab_changed", callable_mp(this, &EditorSettingsDialog::_tabs_tab_changed));949add_child(tabs);950951// General Tab952953tab_general = memnew(VBoxContainer);954tabs->add_child(tab_general);955tab_general->set_name(TTRC("General"));956957HBoxContainer *hbc = memnew(HBoxContainer);958hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);959tab_general->add_child(hbc);960961search_box = memnew(LineEdit);962search_box->set_placeholder(TTRC("Filter Settings"));963search_box->set_accessibility_name(TTRC("Filter Settings"));964search_box->set_virtual_keyboard_show_on_focus(false);965search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);966hbc->add_child(search_box);967968advanced_switch = memnew(CheckButton(TTRC("Advanced Settings")));969hbc->add_child(advanced_switch);970971bool use_advanced = EDITOR_DEF("_editor_settings_advanced_mode", false);972advanced_switch->set_pressed(use_advanced);973advanced_switch->connect(SceneStringName(toggled), callable_mp(this, &EditorSettingsDialog::_advanced_toggled));974975inspector = memnew(SectionedInspector);976inspector->get_inspector()->set_use_filter(true);977inspector->get_inspector()->set_mark_unsaved(false);978inspector->register_search_box(search_box);979inspector->register_advanced_toggle(advanced_switch);980inspector->set_v_size_flags(Control::SIZE_EXPAND_FILL);981tab_general->add_child(inspector);982inspector->get_inspector()->connect("restart_requested", callable_mp(this, &EditorSettingsDialog::_editor_restart_request));983984if (EDITOR_GET("interface/touchscreen/enable_touch_optimizations")) {985inspector->set_touch_dragger_enabled(true);986}987988restart_container = memnew(PanelContainer);989tab_general->add_child(restart_container);990HBoxContainer *restart_hb = memnew(HBoxContainer);991restart_container->add_child(restart_hb);992restart_icon = memnew(TextureRect);993restart_icon->set_v_size_flags(Control::SIZE_SHRINK_CENTER);994restart_hb->add_child(restart_icon);995restart_label = memnew(Label);996restart_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);997if (_is_in_project_manager()) {998restart_label->set_text(TTRC("The Project Manager must be restarted for changes to take effect."));999} else {1000restart_label->set_text(TTRC("The editor must be restarted for changes to take effect."));1001}1002restart_hb->add_child(restart_label);1003restart_hb->add_spacer();1004Button *restart_button = memnew(Button);1005restart_button->connect(SceneStringName(pressed), callable_mp(this, &EditorSettingsDialog::_editor_restart));1006restart_hb->add_child(restart_button);1007restart_button->set_text(TTRC("Save & Restart"));1008restart_close_button = memnew(Button);1009restart_close_button->set_accessibility_name(TTRC("Close"));1010restart_close_button->set_flat(true);1011restart_close_button->connect(SceneStringName(pressed), callable_mp(this, &EditorSettingsDialog::_editor_restart_close));1012restart_hb->add_child(restart_close_button);1013restart_container->hide();10141015// Needs to be done via the signal instead of the notification, otherwise it happens too late.1016EditorSettings::get_singleton()->connect("settings_changed", callable_mp(this, &EditorSettingsDialog::_settings_property_edited));10171018// Shortcuts Tab10191020tab_shortcuts = memnew(VBoxContainer);10211022tabs->add_child(tab_shortcuts);1023tab_shortcuts->set_name(TTRC("Shortcuts"));10241025shortcut_search_bar = memnew(EditorEventSearchBar);1026shortcut_search_bar->connect(SceneStringName(value_changed), callable_mp(this, &EditorSettingsDialog::_update_shortcuts));1027tab_shortcuts->add_child(shortcut_search_bar);10281029MarginContainer *mc = memnew(MarginContainer);1030mc->set_v_size_flags(Control::SIZE_EXPAND_FILL);1031mc->set_theme_type_variation("NoBorderHorizontalBottom");1032tab_shortcuts->add_child(mc);10331034shortcuts = memnew(Tree);1035shortcuts->set_accessibility_name(TTRC("Shortcuts"));1036shortcuts->set_theme_type_variation("TreeTable");1037shortcuts->set_columns(2);1038shortcuts->set_hide_root(true);1039shortcuts->set_column_titles_visible(true);1040shortcuts->set_column_title(0, TTRC("Name"));1041shortcuts->set_column_title(1, TTRC("Binding"));1042shortcuts->connect("button_clicked", callable_mp(this, &EditorSettingsDialog::_shortcut_button_pressed));1043shortcuts->connect("item_activated", callable_mp(this, &EditorSettingsDialog::_shortcut_cell_double_clicked));1044mc->add_child(shortcuts);10451046SET_DRAG_FORWARDING_GCD(shortcuts, EditorSettingsDialog);10471048// Adding event dialog1049shortcut_editor = memnew(InputEventConfigurationDialog);1050shortcut_editor->connect(SceneStringName(confirmed), callable_mp(this, &EditorSettingsDialog::_event_config_confirmed));1051shortcut_editor->set_allowed_input_types(INPUT_KEY);1052add_child(shortcut_editor);10531054set_hide_on_ok(true);10551056timer = memnew(Timer);1057timer->set_wait_time(1.5);1058timer->connect("timeout", callable_mp(this, &EditorSettingsDialog::_settings_save));1059timer->set_one_shot(true);1060add_child(timer);1061EditorSettings::get_singleton()->connect("settings_changed", callable_mp(this, &EditorSettingsDialog::_settings_changed));1062set_ok_button_text(TTRC("Close"));10631064Ref<EditorSettingsInspectorPlugin> plugin;1065plugin.instantiate();1066plugin->inspector = inspector;1067EditorInspector::add_inspector_plugin(plugin);1068}10691070void EditorSettingsPropertyWrapper::_setup_override_info() {1071override_container = memnew(HBoxContainer);10721073override_icon = memnew(TextureRect);1074override_icon->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED);1075override_container->add_child(override_icon);10761077Variant::Type type = ProjectSettings::get_singleton()->get_editor_setting_override(property).get_type();1078override_editor_property = get_parent_inspector()->instantiate_property_editor(ProjectSettings::get_singleton(), type, ProjectSettings::EDITOR_SETTING_OVERRIDE_PREFIX + property, hint, hint_text, usage);1079override_editor_property->set_object_and_property(ProjectSettings::get_singleton(), ProjectSettings::EDITOR_SETTING_OVERRIDE_PREFIX + property);1080override_editor_property->set_read_only(true);1081override_editor_property->set_label(TTR("Overridden in project"));1082override_editor_property->set_h_size_flags(SIZE_EXPAND_FILL);1083override_container->add_child(override_editor_property);10841085goto_button = memnew(Button);1086goto_button->set_tooltip_text(TTRC("Go to the override in the Project Settings."));1087override_container->add_child(goto_button);1088if (EditorNode::get_singleton()) {1089goto_button->connect(SceneStringName(pressed), callable_mp(EditorNode::get_singleton(), &EditorNode::open_setting_override).bind(property), CONNECT_DEFERRED);1090}10911092remove_button = memnew(Button);1093remove_button->set_tooltip_text(TTRC("Remove this override."));1094override_container->add_child(remove_button);1095remove_button->connect(SceneStringName(pressed), callable_mp(this, &EditorSettingsPropertyWrapper::_remove_override));10961097add_child(override_container);10981099if (is_ready()) {1100// Setup icons.1101_notification(NOTIFICATION_THEME_CHANGED);1102}1103}11041105void EditorSettingsPropertyWrapper::_update_override() {1106// Don't allow overriding theme properties, because it causes problems. Overriding Project Manager settings makes no sense.1107// TODO: Find a better way to define exception prefixes (if the list happens to grow).1108if (property.begins_with("interface/theme") || property.begins_with("project_manager") || Engine::get_singleton()->is_project_manager_hint()) {1109can_override = false;1110return;1111}11121113const bool has_override = ProjectSettings::get_singleton()->is_project_loaded() && ProjectSettings::get_singleton()->has_editor_setting_override(property);1114if (has_override) {1115if (!override_container) {1116_setup_override_info();1117}1118override_editor_property->update_property();1119set_bottom_editor(override_container);1120override_container->show();1121} else if (override_container) {1122override_container->hide();1123set_bottom_editor(nullptr);1124}1125can_override = !has_override;1126}11271128void EditorSettingsPropertyWrapper::_create_override() {1129ProjectSettings::get_singleton()->set_editor_setting_override(property, EDITOR_GET(property));1130ProjectSettings::get_singleton()->save();1131_update_override();1132}11331134void EditorSettingsPropertyWrapper::_remove_override() {1135ProjectSettings::get_singleton()->set_editor_setting_override(property, Variant());1136ProjectSettings::get_singleton()->save();1137EditorSettings::get_singleton()->mark_setting_changed(property);1138EditorNode::get_singleton()->notify_settings_overrides_changed();1139_update_override();11401141if (usage & PROPERTY_USAGE_RESTART_IF_CHANGED) {1142restart_request_callback.call();1143}1144}11451146void EditorSettingsPropertyWrapper::_notification(int p_what) {1147if (override_container && p_what == NOTIFICATION_THEME_CHANGED) {1148override_icon->set_texture(get_editor_theme_icon(SNAME("Hierarchy")));1149goto_button->set_button_icon(get_editor_theme_icon(SNAME("MethodOverride")));1150remove_button->set_button_icon(get_editor_theme_icon(SNAME("Close")));1151}1152}11531154void EditorSettingsPropertyWrapper::update_property() {1155editor_property->update_property();1156}11571158void EditorSettingsPropertyWrapper::setup(const String &p_property, EditorProperty *p_editor_property, PropertyHint p_hint, const String &p_hint_text, uint32_t p_usage) {1159hint = p_hint;1160hint_text = p_hint_text;1161usage = p_usage;11621163property = p_property;1164editor_property = p_editor_property;1165add_child(editor_property);11661167_update_override();11681169connect(SNAME("property_overridden"), callable_mp(this, &EditorSettingsPropertyWrapper::_create_override));1170editor_property->connect("property_changed", callable_mp((EditorProperty *)this, &EditorProperty::emit_changed));1171}11721173bool EditorSettingsInspectorPlugin::can_handle(Object *p_object) {1174return p_object && p_object->is_class("SectionedInspectorFilter") && p_object != current_object;1175}11761177bool 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) {1178if (!p_object->is_class("SectionedInspectorFilter")) {1179return false;1180}11811182const String property = inspector->get_full_item_path(p_path);1183if (!EditorSettings::get_singleton()->has_setting(property)) {1184return false;1185}1186current_object = p_object;11871188EditorSettingsPropertyWrapper *editor = memnew(EditorSettingsPropertyWrapper);1189EditorProperty *real_property = inspector->get_inspector()->instantiate_property_editor(p_object, p_type, p_path, p_hint, p_hint_text, p_usage, p_wide);1190real_property->set_object_and_property(p_object, p_path);1191real_property->set_h_size_flags(Control::SIZE_EXPAND_FILL);1192real_property->set_name_split_ratio(0.0);1193editor->setup(property, real_property, p_hint, p_hint_text, p_usage);11941195add_property_editor(p_path, editor);1196current_object = nullptr;1197return true;1198}119912001201