1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-08 12:40:44 +00:00

Add customizable 3D navigation settings

This commit adds 3 new editor settings for orbit, pan, and zoom mouse buttons, and 6 new shortcuts which act as modifiers for the navigation controls. These new shortcuts replace the old orbit, pan, and zoom modifier settings.

The `navigation_scheme` setting now acts as a preset which changes the new options added above, and the new settings are what drives 3D navigation instead. A new struct is used for ordering the navigation logic so that actions with fewer shortcuts are checked first. When the editor starts, the preset detection will run to automatically update user settings from old Godot versions. When the setting is changed, the hint values for the mouse buttons are dynamically updated to show the user the corresponding shortcut values.

The new doc fields have been generated and the description for the new settings are filled out. The `navigation_scheme` entry now has more consistent styling and added control descriptions that were missing before.
This commit is contained in:
Matt Enad
2023-11-24 15:40:54 -05:00
parent cae2f853dc
commit 9d343ced58
7 changed files with 287 additions and 80 deletions

View File

@@ -42,6 +42,7 @@
#include "editor/editor_undo_redo_manager.h"
#include "editor/event_listener_line_edit.h"
#include "editor/input_event_configuration_dialog.h"
#include "editor/plugins/node_3d_editor_plugin.h"
#include "editor/themes/editor_scale.h"
#include "editor/themes/editor_theme_manager.h"
#include "scene/gui/panel_container.h"
@@ -74,9 +75,84 @@ void EditorSettingsDialog::_settings_property_edited(const String &p_name) {
EditorSettings::get_singleton()->set_manually("text_editor/theme/color_theme", "Custom");
} else if (full_name.begins_with("editors/visual_editors/connection_colors") || full_name.begins_with("editors/visual_editors/category_colors")) {
EditorSettings::get_singleton()->set_manually("editors/visual_editors/color_theme", "Custom");
} 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") {
EditorSettings::get_singleton()->set_manually("editors/3d/navigation/navigation_scheme", (int)Node3DEditorViewport::NAVIGATION_CUSTOM);
} else if (full_name == "editors/3d/navigation/navigation_scheme") {
update_navigation_preset();
}
}
void EditorSettingsDialog::update_navigation_preset() {
Node3DEditorViewport::NavigationScheme nav_scheme = (Node3DEditorViewport::NavigationScheme)EDITOR_GET("editors/3d/navigation/navigation_scheme").operator int();
Node3DEditorViewport::ViewportNavMouseButton set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
Node3DEditorViewport::ViewportNavMouseButton set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
Node3DEditorViewport::ViewportNavMouseButton set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
Ref<InputEventKey> orbit_mod_key_1;
Ref<InputEventKey> orbit_mod_key_2;
Ref<InputEventKey> pan_mod_key_1;
Ref<InputEventKey> pan_mod_key_2;
Ref<InputEventKey> zoom_mod_key_1;
Ref<InputEventKey> zoom_mod_key_2;
bool set_preset = false;
if (nav_scheme == Node3DEditorViewport::NAVIGATION_GODOT) {
set_preset = true;
set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;
set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;
set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;
orbit_mod_key_1 = InputEventKey::create_reference(Key::NONE);
orbit_mod_key_2 = InputEventKey::create_reference(Key::NONE);
pan_mod_key_1 = InputEventKey::create_reference(Key::SHIFT);
pan_mod_key_2 = InputEventKey::create_reference(Key::NONE);
zoom_mod_key_1 = InputEventKey::create_reference(Key::SHIFT);
zoom_mod_key_2 = InputEventKey::create_reference(Key::CTRL);
} else if (nav_scheme == Node3DEditorViewport::NAVIGATION_MAYA) {
set_preset = true;
set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE;
set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_RIGHT_MOUSE;
orbit_mod_key_1 = InputEventKey::create_reference(Key::ALT);
orbit_mod_key_2 = InputEventKey::create_reference(Key::NONE);
pan_mod_key_1 = InputEventKey::create_reference(Key::NONE);
pan_mod_key_2 = InputEventKey::create_reference(Key::NONE);
zoom_mod_key_1 = InputEventKey::create_reference(Key::ALT);
zoom_mod_key_2 = InputEventKey::create_reference(Key::NONE);
} else if (nav_scheme == Node3DEditorViewport::NAVIGATION_MODO) {
set_preset = true;
set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
orbit_mod_key_1 = InputEventKey::create_reference(Key::ALT);
orbit_mod_key_2 = InputEventKey::create_reference(Key::NONE);
pan_mod_key_1 = InputEventKey::create_reference(Key::SHIFT);
pan_mod_key_2 = InputEventKey::create_reference(Key::ALT);
zoom_mod_key_1 = InputEventKey::create_reference(Key::ALT);
zoom_mod_key_2 = InputEventKey::create_reference(Key::CTRL);
}
// Set settings to the desired preset values.
if (set_preset) {
EditorSettings::get_singleton()->set_manually("editors/3d/navigation/orbit_mouse_button", (int)set_orbit_mouse_button);
EditorSettings::get_singleton()->set_manually("editors/3d/navigation/pan_mouse_button", (int)set_pan_mouse_button);
EditorSettings::get_singleton()->set_manually("editors/3d/navigation/zoom_mouse_button", (int)set_zoom_mouse_button);
_set_shortcut_input("spatial_editor/viewport_orbit_modifier_1", orbit_mod_key_1);
_set_shortcut_input("spatial_editor/viewport_orbit_modifier_2", orbit_mod_key_2);
_set_shortcut_input("spatial_editor/viewport_pan_modifier_1", pan_mod_key_1);
_set_shortcut_input("spatial_editor/viewport_pan_modifier_2", pan_mod_key_2);
_set_shortcut_input("spatial_editor/viewport_zoom_modifier_1", zoom_mod_key_1);
_set_shortcut_input("spatial_editor/viewport_zoom_modifier_2", zoom_mod_key_2);
}
}
void EditorSettingsDialog::_set_shortcut_input(const String &p_name, Ref<InputEventKey> &p_event) {
Array sc_events;
if (p_event->get_keycode() != Key::NONE) {
sc_events.push_back((Variant)p_event);
}
Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_name);
sc->set_events(sc_events);
}
void EditorSettingsDialog::_settings_save() {
EditorSettings::get_singleton()->notify_changes();
EditorSettings::get_singleton()->save();
@@ -97,6 +173,8 @@ void EditorSettingsDialog::popup_edit_settings() {
EditorSettings::get_singleton()->list_text_editor_themes(); // make sure we have an up to date list of themes
_update_dynamic_property_hints();
inspector->edit(EditorSettings::get_singleton());
inspector->get_inspector()->update_tree();
@@ -160,6 +238,12 @@ void EditorSettingsDialog::_notification(int p_what) {
_update_shortcuts();
}
if (EditorSettings::get_singleton()->check_changed_settings_in_group("editors/3d/navigation")) {
// Shortcuts may have changed, so dynamic hint values must update.
_update_dynamic_property_hints();
inspector->get_inspector()->update_tree();
}
if (EditorSettings::get_singleton()->check_changed_settings_in_group("interface/editor/localize_settings")) {
inspector->update_category_list();
}
@@ -267,6 +351,13 @@ void EditorSettingsDialog::_update_shortcut_events(const String &p_path, const A
undo_redo->add_do_method(this, "_settings_changed");
undo_redo->add_undo_method(this, "_settings_changed");
undo_redo->commit_action();
bool path_is_orbit_mod = p_path == "spatial_editor/viewport_orbit_modifier_1" || p_path == "spatial_editor/viewport_orbit_modifier_2";
bool path_is_pan_mod = p_path == "spatial_editor/viewport_pan_modifier_1" || p_path == "spatial_editor/viewport_pan_modifier_2";
bool path_is_zoom_mod = p_path == "spatial_editor/viewport_zoom_modifier_1" || p_path == "spatial_editor/viewport_zoom_modifier_2";
if (path_is_orbit_mod || path_is_pan_mod || path_is_zoom_mod) {
EditorSettings::get_singleton()->set_manually("editors/3d/navigation/navigation_scheme", (int)Node3DEditorViewport::NAVIGATION_CUSTOM);
}
}
Array EditorSettingsDialog::_event_list_to_array_helper(const List<Ref<InputEvent>> &p_events) {
@@ -672,6 +763,40 @@ void EditorSettingsDialog::drop_data_fw(const Point2 &p_point, const Variant &p_
void EditorSettingsDialog::_tabs_tab_changed(int p_tab) {
_focus_current_search_box();
// When tab has switched, shortcuts may have changed.
_update_dynamic_property_hints();
inspector->get_inspector()->update_tree();
}
void EditorSettingsDialog::_update_dynamic_property_hints() {
// Calling add_property_hint overrides the existing hint.
EditorSettings *settings = EditorSettings::get_singleton();
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"));
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"));
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"));
}
PropertyInfo EditorSettingsDialog::_create_mouse_shortcut_property_info(const String &p_property_name, const String &p_shortcut_1_name, const String &p_shortcut_2_name) {
String hint_string;
hint_string += _get_shortcut_button_string(p_shortcut_1_name) + _get_shortcut_button_string(p_shortcut_2_name);
hint_string += "Left Mouse,";
hint_string += _get_shortcut_button_string(p_shortcut_1_name) + _get_shortcut_button_string(p_shortcut_2_name);
hint_string += "Middle Mouse,";
hint_string += _get_shortcut_button_string(p_shortcut_1_name) + _get_shortcut_button_string(p_shortcut_2_name);
hint_string += "Right Mouse";
return PropertyInfo(Variant::INT, p_property_name, PROPERTY_HINT_ENUM, hint_string);
}
String EditorSettingsDialog::_get_shortcut_button_string(const String &p_shortcut_name) {
String button_string;
Ref<Shortcut> shortcut_ref = EditorSettings::get_singleton()->get_shortcut(p_shortcut_name);
Array events = shortcut_ref->get_events();
for (Ref<InputEvent> input_event : events) {
button_string += input_event->as_text() + " + ";
}
return button_string;
}
void EditorSettingsDialog::_focus_current_search_box() {