Sfoglia il codice sorgente

:tada: Create parameter to set up home-slide

In case you need a intro, and you want a home slide different from the
start slide.
DricomDragon 2 settimane fa
parent
commit
10391f4a98
1 ha cambiato i file con 24 aggiunte e 6 eliminazioni
  1. 24 6
      godot/addons/slide_show/projector/show/Show.gd

+ 24 - 6
godot/addons/slide_show/projector/show/Show.gd

@@ -9,6 +9,7 @@ const VOID_SLIDE_ID := -1
 
 @export_group("Slide management")
 @export var start_slide := 0 ## Id of the slide focused at startup
+@export var home_slide := -1 ## Id of the slide to focus when triggering "Home Slide" action ; fallback to start_slide id when negative
 @export var hide_slides := false ## Hide every slide at startup (except the ones with always_visible enabled)
 
 @export_group("Input setup", "action_")
@@ -80,7 +81,7 @@ func next_slide_at(next_id: int, trans: Focus.Transit) -> void:
 
 
 func is_last_slide() -> bool:
-	return current_id == slides.size() - 1
+	return current_id == _last_slide_id()
 
 
 func _focus_slide(id: int, trans: Focus.Transit) -> Slide:
@@ -120,7 +121,9 @@ 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))
+		"start_slide index is out of bound (max is %s)" % (_last_slide_id()))
+	assert(home_slide < slides.size(),
+		"home_slide index is out of bound (max is %s)" % (_last_slide_id()))
 
 
 func _enforce_children() -> void:
@@ -142,13 +145,13 @@ func _previous_id() -> int:
 	var next_id: int = current_id - 1
 
 	if next_id < 0:
-		return slides.size() - 1
+		return _last_slide_id()
 
 	return next_id
 
 
-func _reset_id() -> void:
-		current_id = VOID_SLIDE_ID
+func _last_slide_id() -> int:
+	return slides.size() - 1
 
 
 func _unhandled_key_input(event: InputEvent) -> void:
@@ -163,7 +166,7 @@ func _unhandled_key_input(event: InputEvent) -> void:
 		go_fast_to_previous_slide()
 	elif event.is_action(action_home_slide):
 		get_viewport().set_input_as_handled()
-		_reset_id()
+		_reset_id_just_before_home()
 		go_slowly_to_next_slide()
 
 
@@ -190,5 +193,20 @@ func _search_nearest_slide_from(target_pos: Vector2) -> Slide:
 	return nearest_slide
 
 
+func _reset_id_just_before_home() -> void:
+	var home_id = _get_home_slide_id()
+	current_id = home_id - 1
+
+
+## Get Home slide id, with backup
+func _get_home_slide_id() -> int:
+	if home_slide >= 0:
+		return home_slide
+	elif start_slide >= 0:
+		return start_slide
+	else:
+		return 0
+
+
 func _on_current_slide_finished() -> void:
 	go_slowly_to_next_slide()