Bläddra i källkod

:tada: Make input for slide customizable

DricomDragon 2 år sedan
förälder
incheckning
b4831961e6
2 ändrade filer med 23 tillägg och 4 borttagningar
  1. 17 3
      godot/projector/show/Show.gd
  2. 6 1
      godot/projector/slide/Slide.gd

+ 17 - 3
godot/projector/show/Show.gd

@@ -7,9 +7,16 @@ 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
 
@@ -23,6 +30,8 @@ func _ready() -> void:
 	if hide_slides:
 		_hide_every_slide()
 
+	_global_slide_setup()
+
 	go_slowly_to_next_slide()
 
 
@@ -60,6 +69,11 @@ func _hide_every_slide() -> void:
 		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()
@@ -118,13 +132,13 @@ func _unhandled_key_input(event: InputEvent) -> void:
 	if !event.is_pressed():
 		return
 
-	if event.is_action("ui_right"):
+	if event.is_action(action_skip_slide):
 		get_viewport().set_input_as_handled()
 		go_fast_to_next_slide()
-	elif event.is_action("ui_left"):
+	elif event.is_action(action_previous_slide):
 		get_viewport().set_input_as_handled()
 		go_fast_to_previous_slide()
-	elif event.is_action("ui_cancel"):
+	elif event.is_action(action_home_slide):
 		get_viewport().set_input_as_handled()
 		_reset_id()
 		go_slowly_to_next_slide()

+ 6 - 1
godot/projector/slide/Slide.gd

@@ -8,6 +8,7 @@ signal finished
 
 @export var always_visible: bool = false
 
+var action_finish := "ui_accept"
 var center_offset: Vector2
 
 
@@ -36,8 +37,12 @@ func gently_hide() -> void:
 	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("ui_accept") and event.is_pressed():
+	if event.is_action(action_finish) and event.is_pressed():
 		finished.emit()
 		get_viewport().set_input_as_handled()