Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add audio for Dialogue Message nodes #843

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions project/addons/orchestrator/scenes/dialogue_message.gd
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var _current_choices : Dictionary
@onready var speaker_text = $MarginContainer/PanelContainer/MarginContainer/VBoxContainer/SpeakerText
@onready var response_tpl = $MarginContainer/PanelContainer/MarginContainer/VBoxContainer/ResponseTemplate
@onready var next_button = $MarginContainer/PanelContainer/MarginContainer/VBoxContainer/NextButton
@onready var stream_player = $AudioStreamPlayer

func _ready() -> void:
response_tpl.visible = false
Expand All @@ -63,7 +64,9 @@ func _ready() -> void:
var character_name = dialogue_data["character_name"]
var message = dialogue_data["message"]
var options = dialogue_data["options"]
var audio = dialogue_data["audio"]
show_message(character_name, message, options)
play_audio(audio)


func _unhandled_input(event: InputEvent) -> void:
Expand All @@ -78,8 +81,8 @@ func _unhandled_input(event: InputEvent) -> void:

# ShowMessage is only allowed to process input when visible
_disable_player_movement()


func show_message(speaker_name: String, message: String, choices: Dictionary) -> void:
speaker.text = speaker_name
speaker_text.text = message
Expand All @@ -92,6 +95,17 @@ func show_message(speaker_name: String, message: String, choices: Dictionary) ->
_current_tween.finished.connect(Callable(_on_tween_finished).bind(choices))
show()


func play_audio(path: String) -> void:
if not ResourceLoader.exists(path):
return
var audio = load(path)
if audio is not AudioStream:
return
stream_player.stream = audio
stream_player.play()


## Callback when the tween typing has finished.
## This allows presenting the user choice options or Continue button.
func _on_tween_finished(choices: Dictionary) -> void:
Expand All @@ -108,13 +122,13 @@ func _on_tween_finished(choices: Dictionary) -> void:
button.pressed.connect(button_handler)
else:
next_button.show()


## Handles canceling the typing effect based on key codes
func _should_end_typing(keycode:int) -> bool:
return keycode == KEY_ESCAPE or keycode == KEY_SPACE


## Prevent user movement when the dialogue UI is shown
func _disable_player_movement() -> void:
var actions = InputMap.get_actions()
Expand Down
2 changes: 2 additions & 0 deletions project/addons/orchestrator/scenes/dialogue_message.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,5 @@ layout_mode = 2
size_flags_horizontal = 8
text = "Continue"
alignment = 2

[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
Loading