From f668ceb512deaa472a604fd5a4cf9b6786fa2953 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 22 Dec 2022 18:01:19 +0100 Subject: [PATCH] Ported: Update the visibility logic for the spatial editor navigation controls - m4gr3d https://github.com/godotengine/godot/commit/0825859a94dcb9e28a20195311718939f5f364f4 --- editor/plugins/spatial_editor_plugin.cpp | 26 ++++++++++++++---------- editor/plugins/spatial_editor_plugin.h | 2 ++ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index b152aca0f..8f44ff601 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -328,6 +328,15 @@ void SpatialEditorViewport::_view_settings_confirmed(real_t p_interp_delta) { _update_camera(p_interp_delta); } +void SpatialEditorViewport::_update_navigation_controls_visibility() { + bool show_viewport_rotation_gizmo = EditorSettings::get_singleton()->get("editors/3d/navigation/show_viewport_rotation_gizmo") && (!previewing_cinema && !previewing_camera); + rotation_control->set_visible(show_viewport_rotation_gizmo); + + bool show_viewport_navigation_gizmo = EditorSettings::get_singleton()->get("editors/3d/navigation/show_viewport_navigation_gizmo") && (!previewing_cinema && !previewing_camera); + position_control->set_visible(show_viewport_navigation_gizmo); + look_control->set_visible(show_viewport_navigation_gizmo); +} + void SpatialEditorViewport::_update_camera(float p_interp_delta) { bool is_orthogonal = camera->get_projection() == Camera::PROJECTION_ORTHOGONAL; @@ -2820,9 +2829,6 @@ void SpatialEditorViewport::_notification(int p_what) { set_freelook_active(false); } call_deferred("update_transform_gizmo_view"); - rotation_control->set_visible(EditorSettings::get_singleton()->get("editors/3d/navigation/show_viewport_rotation_gizmo")); - position_control->set_visible(EditorSettings::get_singleton()->get("editors/3d/navigation/show_viewport_navigation_gizmo")); - look_control->set_visible(EditorSettings::get_singleton()->get("editors/3d/navigation/show_viewport_navigation_gizmo")); } if (p_what == NOTIFICATION_RESIZED) { @@ -2840,6 +2846,7 @@ void SpatialEditorViewport::_notification(int p_what) { } } + _update_navigation_controls_visibility(); _update_freelook(delta); Node *scene_root = editor->get_scene_tree_dock()->get_editor_data()->get_edited_scene_root(); @@ -3606,9 +3613,8 @@ void SpatialEditorViewport::_toggle_camera_preview(bool p_activate) { ERR_FAIL_COND(p_activate && !preview); ERR_FAIL_COND(!p_activate && !previewing); - rotation_control->set_visible(!p_activate); - position_control->set_visible(!p_activate); - look_control->set_visible(!p_activate); + previewing_camera = p_activate; + _update_navigation_controls_visibility(); if (!p_activate) { previewing->disconnect("tree_exiting", this, "_preview_exited_scene"); @@ -3629,9 +3635,7 @@ void SpatialEditorViewport::_toggle_camera_preview(bool p_activate) { void SpatialEditorViewport::_toggle_cinema_preview(bool p_activate) { previewing_cinema = p_activate; - rotation_control->set_visible(!p_activate); - position_control->set_visible(!p_activate); - look_control->set_visible(!p_activate); + _update_navigation_controls_visibility(); if (!previewing_cinema) { if (previewing != nullptr) { @@ -7492,8 +7496,8 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "editors/3d/manipulator_gizmo_size", PROPERTY_HINT_RANGE, "16,160,1")); EDITOR_DEF("editors/3d/manipulator_gizmo_opacity", 0.9); EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::REAL, "editors/3d/manipulator_gizmo_opacity", PROPERTY_HINT_RANGE, "0,1,0.01")); - EDITOR_DEF_RST("editors/3d/navigation/show_viewport_rotation_gizmo", true); - EDITOR_DEF_RST("editors/3d/navigation/show_viewport_navigation_gizmo", OS::get_singleton()->has_touchscreen_ui_hint()); + EDITOR_DEF("editors/3d/navigation/show_viewport_rotation_gizmo", true); + EDITOR_DEF("editors/3d/navigation/show_viewport_navigation_gizmo", OS::get_singleton()->has_touchscreen_ui_hint()); current_hover_gizmo_handle = -1; current_hover_gizmo_handle_secondary = false; diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h index c5d9ba16e..ccc83de1b 100644 --- a/editor/plugins/spatial_editor_plugin.h +++ b/editor/plugins/spatial_editor_plugin.h @@ -387,6 +387,7 @@ private: void _view_settings_confirmed(float p_interp_delta); void _update_camera(float p_interp_delta); + void _update_navigation_controls_visibility(); Transform to_camera_transform(const Cursor &p_cursor) const; void _draw(); @@ -402,6 +403,7 @@ private: Camera *previewing; Camera *preview; + bool previewing_camera; bool previewing_cinema; bool _is_node_locked(const Node *p_node); void _preview_exited_scene();