2.4 KiB
2.4 KiB
ProjectProject Settings...Input Map
Define action + button there
!
Next, select a button, and open Shortcut section
!
Click the <empty> Shortcut field, then select New Shortcut
The Shortcut resource takes an array of inputs as its data because in case you'd want to trigger the same button with multiple different inputs or input actions.
sadfs
!
Click on the created InputEventAction to expand it.
!
Set action to advance_text ( The action we created in the very first screenshot of this page)
![[Pasted image 20240713080125.png]]
Now all input defined for advance_text action will trigger the button.
Disabling button until tween finished
func show_text() -> void:
# We first extract data for the current dialogue item and apply it to the UI
# elements.
# ...
next_button.disabled = true
tween.finished.connect(func() -> void:
next_button.disabled = false
)
Note to self: It seems to be possible to connect an event to more than 1 function. Here the full function from the tutorial. Note the tween.connect re-use
func show_text() -> void:
# We first extract data for the current dialogue item and apply it to the UI
# elements.
var current_item := dialogue_items[current_item_index]
rich_text_label.text = current_item["text"]
expression_texture_rect.texture = current_item["expression"]
body.texture = current_item["character"]
# We then hide the text and animate it appearing.
rich_text_label.visible_ratio = 0.0
var tween := create_tween()
var text_appearing_duration: float = current_item["text"].length() / 30.0
tween.tween_property(rich_text_label, "visible_ratio", 1.0, text_appearing_duration)
# We randomize the audio playback's start time to make it sound different
# every time and play the sound until the text finishes displaying.
var sound_max_length := audio_stream_player.stream.get_length() - text_appearing_duration
var sound_start_position := randf() * sound_max_length
audio_stream_player.play(sound_start_position)
tween.finished.connect(audio_stream_player.stop)
# We animate the character sliding in.
slide_in()
# Finally, we disable the next button until the text finishes displaying.
next_button.disabled = true
tween.finished.connect(func() -> void:
next_button.disabled = false
)
