Bläddra i källkod

:tada: Create first implementation for slide transition

DricomDragon 2 år sedan
förälder
incheckning
aa93f5ff58

+ 1 - 0
godot/project.godot

@@ -20,6 +20,7 @@ config/icon="res://icon.svg"
 window/size/viewport_width=1920
 window/size/viewport_height=1080
 window/size/mode=3
+window/size/initial_position_type=2
 
 [rendering]
 

+ 29 - 2
godot/projector/focus/Focus.gd

@@ -5,10 +5,37 @@ extends Camera2D
 
 signal ended
 
+@export_group("Tween caracteristics", "tween_")
+@export var tween_is_parallel: bool = false
+
+@export_group("Step backward", "back_")
+@export var back_zoom_multiplier: float = 0.8
+@export var back_duration: float = 1.0
+
+@export_group("Move focus", "move_")
+@export var move_duration: float = 1.0
+
+@export_group("Step inward", "in_")
+@export var in_duration: float = 1.0
+
+var tween: Tween
+
 
 func focus_on(pos: Vector2, scope: float) -> void:
-	set_position(pos)
-	set_zoom(Vector2.ONE / scope)
+	if tween:
+		tween.kill()
+
+	var target_zoom = Vector2.ONE / scope
+	var min_zoom = target_zoom if target_zoom.x < get_zoom().x else get_zoom()
+
+	tween = create_tween().set_parallel(tween_is_parallel)
+	tween.tween_property(self, "zoom", min_zoom * back_zoom_multiplier, back_duration)
+	tween.tween_property(self, "position", pos, move_duration)
+	tween.tween_property(self, "zoom", target_zoom, in_duration)
+	tween.tween_callback(end)
+
+
+func end():
 	ended.emit()
 
 

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

@@ -29,7 +29,7 @@ func next_slide():
 
 func focus_slide(id: int) -> Slide:
 	var slide: Slide = slides[id]
-	new_focus.emit(slide.get_position(), slide.get_scale().x)
+	new_focus.emit(slide.get_center(), slide.get_scale().x)
 	return slide
 
 

+ 16 - 0
godot/projector/slide/Slide.gd

@@ -6,7 +6,23 @@ extends Node2D
 
 signal finished
 
+var center_offset: Vector2
+
+
+func _ready():
+	center_offset = _compute_center_offset()
+
+
+func get_center():
+	return get_position() + center_offset
+
 
 func _unhandled_key_input(event: InputEvent):
 	if event.is_action("ui_accept") and event.is_pressed():
 		finished.emit()
+
+
+func _compute_center_offset() -> Vector2:
+	var w: float = ProjectSettings.get("display/window/size/viewport_width")
+	var h: float = ProjectSettings.get("display/window/size/viewport_height")
+	return Vector2(w * scale.x / 2, h * scale.y / 2)

+ 3 - 2
godot/run/root.tscn

@@ -25,7 +25,7 @@
 [ext_resource type="PackedScene" uid="uid://cbccs71it0k4n" path="res://slides/203/RenderingEngine.tscn" id="19_big3n"]
 [ext_resource type="PackedScene" uid="uid://lqtctegvdflo" path="res://slides/121/Godot1.tscn" id="19_hixyf"]
 [ext_resource type="PackedScene" uid="uid://cfr23honh8ul7" path="res://slides/204/PhysicsEngine.tscn" id="20_5wgdd"]
-[ext_resource type="PackedScene" path="res://slides/122/Godot2.tscn" id="20_hqo1t"]
+[ext_resource type="PackedScene" uid="uid://cf4ctewx8qjvb" path="res://slides/122/Godot2.tscn" id="20_hqo1t"]
 [ext_resource type="PackedScene" uid="uid://cc3ubpf7j5od3" path="res://slides/205/Peripherics.tscn" id="21_1l4n1"]
 [ext_resource type="PackedScene" uid="uid://ce00m1pjp4ajx" path="res://slides/130/Godot3.tscn" id="21_qv6t5"]
 [ext_resource type="PackedScene" uid="uid://c5x3t6e5yy050" path="res://slides/140/Godot4.tscn" id="22_v7gdm"]
@@ -89,7 +89,8 @@ metadata/_edit_vertical_guides_ = []
 position = Vector2(2, 0)
 
 [node name="Focus" parent="Board" instance=ExtResource("1_a17yu")]
-position = Vector2(-291, -187)
+position = Vector2(8904, 4626)
+anchor_mode = 1
 zoom = Vector2(0.1, 0.1)
 
 [node name="Show" parent="Board" instance=ExtResource("2_cih7e")]