Forráskód Böngészése

:tada: Focus slide on click

DricomDragon 2 éve
szülő
commit
26ec18ae9c
1 módosított fájl, 21 hozzáadás és 1 törlés
  1. 21 1
      godot/projector/show/Show.gd

+ 21 - 1
godot/projector/show/Show.gd

@@ -34,8 +34,12 @@ func go_fast_to_next_slide():
 
 
 func _next_slide():
+	_next_slide_at(_next_id())
+
+
+func _next_slide_at(next_id: int) -> void:
 	_disconnect_current_slide()
-	current_id = _next_id()
+	current_id = next_id
 	current_slide = focus_slide(current_id)
 	_connect_current_slide()
 
@@ -109,5 +113,21 @@ func _unhandled_key_input(event: InputEvent):
 		go_slowly_to_next_slide()
 
 
+func _unhandled_input(event: InputEvent) -> void:
+	if event is InputEventMouseButton and event.is_pressed():
+		var gpos: Vector2 = get_global_mouse_position()
+		var nearest_slide = current_slide
+		var shortest_distance = gpos.distance_squared_to(nearest_slide.get_center())
+		for current_slide in slides:
+			var current_distance = gpos.distance_squared_to(current_slide.get_center())
+			if current_distance < shortest_distance:
+				nearest_slide = current_slide
+				shortest_distance = current_distance
+
+		var next_id = slides.find(nearest_slide)
+		_next_slide_at(next_id)
+		slow_move.emit()
+
+
 func _on_current_slide_finished():
 	go_slowly_to_next_slide()