From 46ec1deba579c7b3c073201324d241b498eacb15 Mon Sep 17 00:00:00 2001 From: Kyle Dayton Date: Sun, 24 Jun 2018 20:24:31 -0500 Subject: Add lock rotation feature to spatial editor viewport --- editor/plugins/spatial_editor_plugin.cpp | 29 +++++++++++++++++++++++++++++ editor/plugins/spatial_editor_plugin.h | 4 +++- 2 files changed, 32 insertions(+), 1 deletion(-) (limited to 'editor/plugins') diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index 30fff474d7..ecdc67e04c 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -1918,6 +1918,11 @@ void SpatialEditorViewport::_nav_zoom(Ref p_event, cons void SpatialEditorViewport::_nav_orbit(Ref p_event, const Vector2 &p_relative) { + if (lock_rotation) { + _nav_pan(p_event, p_relative); + return; + } + real_t degrees_per_pixel = EditorSettings::get_singleton()->get("editors/3d/navigation_feel/orbit_sensitivity"); real_t radians_per_pixel = Math::deg2rad(degrees_per_pixel); bool invert_y_axis = EditorSettings::get_singleton()->get("editors/3d/navigation/invert_y-axis"); @@ -2552,6 +2557,19 @@ void SpatialEditorViewport::_menu_option(int p_option) { call_deferred("update_transform_gizmo_view"); _update_name(); + } break; + case VIEW_LOCK_ROTATION: { + + int idx = view_menu->get_popup()->get_item_index(VIEW_LOCK_ROTATION); + bool current = view_menu->get_popup()->is_item_checked(idx); + lock_rotation = !current; + view_menu->get_popup()->set_item_checked(idx, !current); + if (lock_rotation) { + view_menu->set_icon(get_icon("Lock", "EditorIcons")); + } else { + view_menu->set_icon(Ref()); + } + } break; case VIEW_AUDIO_LISTENER: { @@ -2826,6 +2844,12 @@ void SpatialEditorViewport::set_state(const Dictionary &p_state) { if (!view_menu->get_popup()->is_item_checked(idx)) _menu_option(display); } + if (p_state.has("lock_rotation")) { + lock_rotation = p_state["lock_rotation"]; + + int idx = view_menu->get_popup()->get_item_index(VIEW_LOCK_ROTATION); + view_menu->get_popup()->set_item_checked(idx, lock_rotation); + } if (p_state.has("use_environment")) { bool env = p_state["use_environment"]; @@ -2913,6 +2937,8 @@ Dictionary SpatialEditorViewport::get_state() const { d["half_res"] = viewport_container->get_stretch_shrink() > 1; if (previewing) d["previewing"] = EditorNode::get_singleton()->get_edited_scene()->get_path_to(previewing); + if (lock_rotation) + d["lock_rotation"] = lock_rotation; return d; } @@ -2941,6 +2967,7 @@ void SpatialEditorViewport::_bind_methods() { void SpatialEditorViewport::reset() { orthogonal = false; + lock_rotation = false; message_time = 0; message = ""; last_message = ""; @@ -3367,6 +3394,8 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed view_menu->get_popup()->add_radio_check_item(TTR("Orthogonal") + " (" + ED_GET_SHORTCUT("spatial_editor/switch_perspective_orthogonal")->get_as_text() + ")", VIEW_ORTHOGONAL); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_PERSPECTIVE), true); view_menu->get_popup()->add_separator(); + view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_lock_rotation", TTR("Lock View Rotation")), VIEW_LOCK_ROTATION); + view_menu->get_popup()->add_separator(); view_menu->get_popup()->add_radio_check_shortcut(ED_SHORTCUT("spatial_editor/view_display_normal", TTR("Display Normal")), VIEW_DISPLAY_NORMAL); view_menu->get_popup()->add_radio_check_shortcut(ED_SHORTCUT("spatial_editor/view_display_wireframe", TTR("Display Wireframe")), VIEW_DISPLAY_WIREFRAME); view_menu->get_popup()->add_radio_check_shortcut(ED_SHORTCUT("spatial_editor/view_display_overdraw", TTR("Display Overdraw")), VIEW_DISPLAY_OVERDRAW); diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h index 637926a913..ed95a9a602 100644 --- a/editor/plugins/spatial_editor_plugin.h +++ b/editor/plugins/spatial_editor_plugin.h @@ -93,7 +93,8 @@ class SpatialEditorViewport : public Control { VIEW_DISPLAY_NORMAL, VIEW_DISPLAY_WIREFRAME, VIEW_DISPLAY_OVERDRAW, - VIEW_DISPLAY_SHADELESS + VIEW_DISPLAY_SHADELESS, + VIEW_LOCK_ROTATION }; public: @@ -131,6 +132,7 @@ private: Camera *camera; bool transforming; bool orthogonal; + bool lock_rotation; float gizmo_scale; bool freelook_active; -- cgit v1.2.3