add button to toggle mouse confinement
This commit is contained in:
parent
411eafabf5
commit
d590c5cdf0
@ -72,3 +72,8 @@ reset_camera={
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194332,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
toggle_camera_navigation={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194333,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
@ -56,14 +56,6 @@ transform = Transform3D(1, 0, 0, 0, 0.819152, 0.573576, 0, -0.573576, 0.819152,
|
||||
current = true
|
||||
far = 200.0
|
||||
script = ExtResource("1_xl1ut")
|
||||
zoom_in_distance = null
|
||||
zoom_in_fov = null
|
||||
zoom_in_angle = null
|
||||
zoom_in_speed = null
|
||||
zoom_out_distance = null
|
||||
zoom_out_fov = null
|
||||
zoom_out_angle = null
|
||||
zoom_out_speed = null
|
||||
|
||||
[node name="Static" type="Node" parent="."]
|
||||
|
||||
|
||||
@ -5,6 +5,8 @@ const CURSOR_HOTSPOT = Vector2(32, 32)
|
||||
var cursor_normal := load("res://assets/textures/gui/cursor.png")
|
||||
var cursor_click := load("res://assets/textures/gui/cursor_click.png")
|
||||
|
||||
var disable_confinement: bool = false
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_CONFINED
|
||||
@ -22,6 +24,14 @@ func _input(event: InputEvent) -> void:
|
||||
else:
|
||||
_set_cursor(cursor_normal)
|
||||
|
||||
if event.is_action_pressed("toggle_camera_navigation"):
|
||||
disable_confinement = not disable_confinement
|
||||
if disable_confinement:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
||||
else:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_CONFINED
|
||||
|
||||
|
||||
|
||||
func _set_cursor(image: Resource) -> void:
|
||||
Input.set_custom_mouse_cursor(image, Input.CURSOR_ARROW, CURSOR_HOTSPOT)
|
||||
|
||||
@ -92,7 +92,11 @@ func head_to(to: Vector3, zoom: float = ZOOM_VALUE_DEFAULT) -> void:
|
||||
|
||||
|
||||
func _handle_movement(delta: float) -> void:
|
||||
if window_out_of_focus or state != CameraState.FREE:
|
||||
if (
|
||||
window_out_of_focus
|
||||
or state != CameraState.FREE
|
||||
or CursorManager.disable_confinement
|
||||
):
|
||||
return
|
||||
|
||||
var viewport_size := get_viewport().get_visible_rect().size
|
||||
@ -136,14 +140,14 @@ func _handle_heading_to(delta: float) -> void:
|
||||
heading_progress += HEADING_SPEED * delta
|
||||
var eased_progress := ease(heading_progress, -3)
|
||||
target_position = lerp(
|
||||
heading_from_position,
|
||||
heading_to_position,
|
||||
heading_from_position,
|
||||
heading_to_position,
|
||||
eased_progress,
|
||||
)
|
||||
zoom_raw = quadratic_bezier(
|
||||
heading_from_zoom,
|
||||
1,
|
||||
heading_to_zoom,
|
||||
heading_from_zoom,
|
||||
1,
|
||||
heading_to_zoom,
|
||||
eased_progress,
|
||||
)
|
||||
zoom_value = zoom_raw
|
||||
|
||||
Loading…
Reference in New Issue
Block a user