Sfoglia il codice sorgente

:truck: Import custom types from standalone project

ssh://gituser@gogs.jovian-hersemeule.eu:7025/DricomDragon/WaitForGdSpeech.git
DricomDragon 2 anni fa
parent
commit
c96ac7f68f

+ 89 - 0
godot/addons/slide_show/projector/focus/Focus.gd

@@ -0,0 +1,89 @@
+class_name Focus
+extends Camera2D
+# Transition to next slide and focus current slide
+
+
+signal ended
+
+enum Transit {
+	BEAM,
+	SMOOTH,
+}
+
+@export_group("Tween caracteristics", "tween_")
+@export var tween_is_parallel: bool = false
+
+@export_group("Move", "move_")
+@export var move_duration: float = 1.0
+@export var move_trans: Tween.TransitionType = Tween.TRANS_SINE
+@export var move_ease: Tween.EaseType = Tween.EASE_IN_OUT
+
+@export_group("Scope", "scope_")
+@export var scope_duration: float = 1.0
+@export var scope_trans: Tween.TransitionType = Tween.TRANS_SINE
+@export var scope_closer_ease: Tween.EaseType = Tween.EASE_IN
+@export var scope_wider_ease: Tween.EaseType = Tween.EASE_OUT
+
+var tween: Tween
+var scope: Vector2 : get = get_scope, set = set_scope
+
+var target_pos: Vector2 = Vector2.ZERO
+var target_scope: Vector2 = Vector2.ONE
+
+
+func focus_on(pos: Vector2, scalar_scale: float, trans: Transit) -> void:
+	target_pos = pos
+	target_scope = Vector2.ONE * scalar_scale
+
+	if Transit.BEAM == trans:
+		_beam_to_focus()
+	elif Transit.SMOOTH == trans:
+		_smooth_transit_to_focus()
+	else:
+		assert(false, "Trans %s is not implemented." % trans)
+
+
+func end() -> void:
+	ended.emit()
+
+
+func get_scope() -> Vector2:
+	return _invert_vector(get_zoom())
+
+
+func set_scope(new_scope: Vector2) -> void:
+	set_zoom(_invert_vector(new_scope))
+
+
+func _beam_to_focus() -> void:
+	_abort_ongoing_transit()
+
+	set_position(target_pos)
+	set_scope(target_scope)
+
+
+func _smooth_transit_to_focus() -> void:
+	_abort_ongoing_transit()
+
+	var is_wider: bool = target_scope.x > get_scope().x
+	var scope_ease: Tween.EaseType = scope_wider_ease if is_wider else scope_closer_ease
+
+	tween = create_tween().set_parallel(tween_is_parallel)
+	tween.tween_property(self, "position", target_pos, move_duration).set_trans(move_trans).set_ease(move_ease)
+	tween.tween_property(self, "scope", target_scope, scope_duration).set_trans(scope_trans).set_ease(scope_ease)
+	tween.tween_callback(end)
+
+
+func _abort_ongoing_transit() -> void:
+	if tween:
+		tween.kill()
+
+
+func _invert_vector(vec: Vector2) -> Vector2:
+	assert(vec.x > 0)
+	assert(vec.y > 0)
+	return Vector2(1.0 / vec.x, 1.0 / vec.y)
+
+
+func _on_show_new_focus(pos: Vector2, scalar_scale: float, trans: Transit) -> void:
+	focus_on(pos, scalar_scale, trans)

+ 171 - 0
godot/addons/slide_show/projector/show/Show.gd

@@ -0,0 +1,171 @@
+class_name Show
+extends Node2D
+# Manage slide cycling
+
+
+signal new_focus(pos: Vector2, scale: float, trans: Focus.Transit)
+
+const VOID_SLIDE_ID := -1
+
+@export_group("Slide management")
+@export var start_slide := 0
+@export var hide_slides := false
+
+@export_group("Input setup", "action_")
+@export var action_finish_slide := "ui_accept"
+@export var action_skip_slide := "ui_right"
+@export var action_previous_slide := "ui_left"
+@export var action_home_slide := "ui_cancel"
+
+var current_id := VOID_SLIDE_ID
+var current_slide: Slide
+
+@onready var slides: Array = get_children()
+
+
+func _ready() -> void:
+	_enforce()
+	print("The show contains %s slides" % slides.size())
+
+	if hide_slides:
+		_hide_every_slide()
+
+	_global_slide_setup()
+
+	go_slowly_to_next_slide()
+
+
+func go_slowly_to_next_slide() -> void:
+	next_slide(Focus.Transit.SMOOTH)
+
+
+func go_fast_to_next_slide() -> void:
+	next_slide(Focus.Transit.BEAM)
+
+
+func go_fast_to_previous_slide() -> void:
+	next_slide_at(_previous_id(), Focus.Transit.BEAM)
+
+
+func next_slide(trans: Focus.Transit) -> void:
+	next_slide_at(_next_id(), trans)
+
+
+func next_slide_at(next_id: int, trans: Focus.Transit) -> void:
+	_disable_current_slide()
+	current_id = next_id
+	current_slide = _focus_slide(current_id, trans)
+	_enable_current_slide()
+
+
+func _focus_slide(id: int, trans: Focus.Transit) -> Slide:
+	var slide: Slide = slides[id]
+	new_focus.emit(slide.get_center(), slide.get_scale().x, trans)
+	return slide
+
+
+func _hide_every_slide() -> void:
+	for slide in slides:
+		slide.gently_hide()
+
+
+func _global_slide_setup() -> void:
+	for slide in slides:
+		slide.set_action_finish(action_finish_slide)
+
+
+func _disable_current_slide() -> void:
+	if current_slide != null:
+		current_slide.disable()
+		current_slide.finished.disconnect(_on_current_slide_finished)
+
+
+func _enable_current_slide() -> void:
+	current_slide.enable()
+	current_slide.finished.connect(_on_current_slide_finished)
+
+
+func _enforce() -> void:
+	_enforce_parameters()
+	_enforce_children()
+
+
+func _enforce_parameters() -> void:
+	assert(start_slide >= 0,
+		"Negative index is not supported for start_slide")
+	assert(start_slide < slides.size(),
+		"start_slide index is out of bound (max is %s)" % (slides.size() - 1))
+
+
+func _enforce_children() -> void:
+	assert(!slides.is_empty(), "A slideshow must contain slides")
+	for slide in slides:
+		assert(slide is Slide, "A slideshow can only contain slides")
+
+
+func _next_id() -> int:
+	if current_id == VOID_SLIDE_ID:
+		return start_slide
+
+	var next_id: int = current_id + 1
+
+	if next_id >= slides.size():
+		return 0
+
+	return next_id
+
+
+func _previous_id() -> int:
+	var next_id: int = current_id - 1
+
+	if next_id < 0:
+		return slides.size() - 1
+
+	return next_id
+
+
+func _reset_id() -> void:
+		current_id = VOID_SLIDE_ID
+
+
+func _unhandled_key_input(event: InputEvent) -> void:
+	if !event.is_pressed():
+		return
+
+	if event.is_action(action_skip_slide):
+		get_viewport().set_input_as_handled()
+		go_fast_to_next_slide()
+	elif event.is_action(action_previous_slide):
+		get_viewport().set_input_as_handled()
+		go_fast_to_previous_slide()
+	elif event.is_action(action_home_slide):
+		get_viewport().set_input_as_handled()
+		_reset_id()
+		go_slowly_to_next_slide()
+
+
+func _unhandled_input(event: InputEvent) -> void:
+	if event is InputEventMouseButton and event.is_pressed():
+		_focus_nearest_slide_from(get_global_mouse_position())
+
+
+func _focus_nearest_slide_from(target_pos: Vector2) -> void:
+	var next_slide = _search_nearest_slide_from(target_pos)
+	var next_id = slides.find(next_slide)
+	next_slide_at(next_id, Focus.Transit.SMOOTH)
+
+
+func _search_nearest_slide_from(target_pos: Vector2) -> Slide:
+	var nearest_slide = current_slide
+	var shortest_distance = target_pos.distance_squared_to(nearest_slide.get_center())
+	for current_slide in slides:
+		var current_distance = target_pos.distance_squared_to(current_slide.get_center())
+		if current_distance < shortest_distance:
+			nearest_slide = current_slide
+			shortest_distance = current_distance
+
+	return nearest_slide
+
+
+func _on_current_slide_finished() -> void:
+	go_slowly_to_next_slide()

+ 53 - 0
godot/addons/slide_show/projector/slide/Slide.gd

@@ -0,0 +1,53 @@
+@icon("res://common/graphics/icons/godot_icon_slide.svg")
+class_name Slide
+extends Node2D
+# Display slide content
+
+
+signal finished
+
+@export var always_visible: bool = false
+
+var action_finish := "ui_accept"
+var center_offset: Vector2
+
+
+func _ready() -> void:
+	center_offset = _compute_center_offset()
+	disable()
+
+
+func disable() -> void:
+	set_process_unhandled_key_input(false)
+
+
+func enable() -> void:
+	set_visible(true)
+	set_process_unhandled_key_input(true)
+
+
+func get_center() -> Vector2:
+	return get_position() + center_offset
+
+
+func gently_hide() -> void:
+	if always_visible:
+		return
+
+	set_visible(false)
+
+
+func set_action_finish(action_name: String) -> void:
+	action_finish = action_name
+
+
+func _unhandled_key_input(event: InputEvent) -> void:
+	if event.is_action(action_finish) and event.is_pressed():
+		finished.emit()
+		get_viewport().set_input_as_handled()
+
+
+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)