Restore previous mouse position when leaving the editor freelook mode
- Remove the crosshair as it no longer serves a purpose (the cursor will now appear where the user "expects" it to). This closes https://github.com/godotengine/godot-proposals/issues/1076.
This commit is contained in:
parent
d341181f30
commit
4a542e0007
|
@ -1 +0,0 @@
|
||||||
<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m6 1v5h-5v1 3h5v5h4v-5h5v-4h-5v-5z" fill-opacity=".627451"/><path d="m2 7v2l5.0000803.0000197-.0000803 4.9999803h2l-.0000803-4.9999803 5.0000803-.0000197v-2l-5.0000803.0001803.0000803-5.0001803h-2l.0000803 5.0001803z" fill="#fefefe" fill-opacity=".862745"/></svg>
|
|
Before Width: | Height: | Size: 355 B |
|
@ -2174,6 +2174,8 @@ void Node3DEditorViewport::set_freelook_active(bool active_now) {
|
||||||
freelook_speed = base_speed * cursor.distance;
|
freelook_speed = base_speed * cursor.distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
previous_mouse_position = get_local_mouse_position();
|
||||||
|
|
||||||
// Hide mouse like in an FPS (warping doesn't work)
|
// Hide mouse like in an FPS (warping doesn't work)
|
||||||
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED);
|
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED);
|
||||||
|
|
||||||
|
@ -2183,6 +2185,11 @@ void Node3DEditorViewport::set_freelook_active(bool active_now) {
|
||||||
|
|
||||||
// Restore mouse
|
// Restore mouse
|
||||||
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
|
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
|
||||||
|
|
||||||
|
// Restore the previous mouse position when leaving freelook mode.
|
||||||
|
// This is done because leaving `Input.MOUSE_MODE_CAPTURED` will center the cursor
|
||||||
|
// due to OS limitations.
|
||||||
|
warp_mouse(previous_mouse_position);
|
||||||
}
|
}
|
||||||
|
|
||||||
freelook_active = active_now;
|
freelook_active = active_now;
|
||||||
|
@ -2341,13 +2348,6 @@ void Node3DEditorViewport::_notification(int p_what) {
|
||||||
call_deferred("update_transform_gizmo_view");
|
call_deferred("update_transform_gizmo_view");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p_what == NOTIFICATION_READY) {
|
|
||||||
// The crosshair icon doesn't depend on the editor theme.
|
|
||||||
crosshair->set_texture(get_theme_icon("Crosshair", "EditorIcons"));
|
|
||||||
// Set the anchors and margins after changing the icon to ensure it's centered correctly.
|
|
||||||
crosshair->set_anchors_and_margins_preset(PRESET_CENTER);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p_what == NOTIFICATION_PROCESS) {
|
if (p_what == NOTIFICATION_PROCESS) {
|
||||||
real_t delta = get_process_delta_time();
|
real_t delta = get_process_delta_time();
|
||||||
|
|
||||||
|
@ -2473,10 +2473,6 @@ void Node3DEditorViewport::_notification(int p_what) {
|
||||||
current_camera = camera;
|
current_camera = camera;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display the crosshair only while freelooking. Hide it otherwise,
|
|
||||||
// as the crosshair can be distracting.
|
|
||||||
crosshair->set_visible(freelook_active);
|
|
||||||
|
|
||||||
if (show_info) {
|
if (show_info) {
|
||||||
String text;
|
String text;
|
||||||
text += "X: " + rtos(current_camera->get_translation().x).pad_decimals(1) + "\n";
|
text += "X: " + rtos(current_camera->get_translation().x).pad_decimals(1) + "\n";
|
||||||
|
@ -3866,10 +3862,6 @@ Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, Edito
|
||||||
camera->make_current();
|
camera->make_current();
|
||||||
surface->set_focus_mode(FOCUS_ALL);
|
surface->set_focus_mode(FOCUS_ALL);
|
||||||
|
|
||||||
crosshair = memnew(TextureRect);
|
|
||||||
crosshair->set_mouse_filter(MOUSE_FILTER_IGNORE);
|
|
||||||
surface->add_child(crosshair);
|
|
||||||
|
|
||||||
VBoxContainer *vbox = memnew(VBoxContainer);
|
VBoxContainer *vbox = memnew(VBoxContainer);
|
||||||
surface->add_child(vbox);
|
surface->add_child(vbox);
|
||||||
vbox->set_position(Point2(10, 10) * EDSCALE);
|
vbox->set_position(Point2(10, 10) * EDSCALE);
|
||||||
|
|
|
@ -284,8 +284,8 @@ private:
|
||||||
|
|
||||||
bool freelook_active;
|
bool freelook_active;
|
||||||
real_t freelook_speed;
|
real_t freelook_speed;
|
||||||
|
Vector2 previous_mouse_position;
|
||||||
|
|
||||||
TextureRect *crosshair;
|
|
||||||
Label *info_label;
|
Label *info_label;
|
||||||
Label *cinema_label;
|
Label *cinema_label;
|
||||||
Label *locked_label;
|
Label *locked_label;
|
||||||
|
|
Loading…
Reference in New Issue