Browse Source

Update the visibility logic for the spatial editor navigation controls

Fredia Huya-Kouadio 2 years ago
parent
commit
0825859a94
2 changed files with 17 additions and 11 deletions
  1. 15 11
      editor/plugins/spatial_editor_plugin.cpp
  2. 2 0
      editor/plugins/spatial_editor_plugin.h

+ 15 - 11
editor/plugins/spatial_editor_plugin.cpp

@@ -457,6 +457,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;
 
@@ -2722,9 +2731,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) {
@@ -2742,6 +2748,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();
@@ -3508,9 +3515,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");
@@ -3531,9 +3537,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) {
@@ -7234,8 +7238,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());
 
 	over_gizmo_handle = -1;
 

+ 2 - 0
editor/plugins/spatial_editor_plugin.h

@@ -428,6 +428,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();
 
@@ -443,6 +444,7 @@ private:
 	Camera *previewing;
 	Camera *preview;
 
+	bool previewing_camera;
 	bool previewing_cinema;
 	bool _is_node_locked(const Node *p_node);
 	void _preview_exited_scene();