First work on dialogic, resized guild, and started implementing portraits.

This commit is contained in:
2025-08-14 10:26:24 -04:00
parent 95a7db036b
commit 3aeb3d44e6
959 changed files with 47688 additions and 46 deletions

View File

@@ -0,0 +1,105 @@
@tool
## Event that can change the currently playing background music.
## This event won't play new music if it's already playing.
class_name DialogicMusicEvent
extends DialogicEvent
### Settings
## The file to play. If empty, the previous music will be faded out.
var file_path := "":
set(value):
if file_path != value:
file_path = value
ui_update_needed.emit()
## The channel to use.
var channel_id: int = 0
## The length of the fade. If 0 (by default) it's an instant change.
var fade_length: float = 0
## The volume the music will be played at.
var volume: float = 0
## The audio bus the music will be played at.
var audio_bus := ""
## If true, the audio will loop, otherwise only play once.
var loop := true
################################################################################
## EXECUTE
################################################################################
func _execute() -> void:
if not dialogic.Audio.is_music_playing_resource(file_path, channel_id):
dialogic.Audio.update_music(file_path, volume, audio_bus, fade_length, loop, channel_id)
finish()
################################################################################
## INITIALIZE
################################################################################
func _init() -> void:
event_name = "Music"
set_default_color('Color7')
event_category = "Audio"
event_sorting_index = 2
func _get_icon() -> Resource:
return load(self.get_script().get_path().get_base_dir().path_join('icon_music.png'))
################################################################################
## SAVING/LOADING
################################################################################
func get_shortcode() -> String:
return "music"
func get_shortcode_parameters() -> Dictionary:
return {
#param_name : property_info
"path" : {"property": "file_path", "default": ""},
"channel" : {"property": "channel_id", "default": 0},
"fade" : {"property": "fade_length", "default": 0},
"volume" : {"property": "volume", "default": 0},
"bus" : {"property": "audio_bus", "default": "",
"suggestions": get_bus_suggestions},
"loop" : {"property": "loop", "default": true},
}
################################################################################
## EDITOR REPRESENTATION
################################################################################
func build_event_editor() -> void:
add_header_edit('file_path', ValueType.FILE, {
'left_text' : 'Play',
'file_filter' : "*.mp3, *.ogg, *.wav; Supported Audio Files",
'placeholder' : "No music",
'editor_icon' : ["AudioStreamPlayer", "EditorIcons"]})
add_header_edit('channel_id', ValueType.FIXED_OPTIONS, {'left_text':'on:', 'options': get_channel_list()})
add_header_edit('file_path', ValueType.AUDIO_PREVIEW)
add_body_edit('fade_length', ValueType.NUMBER, {'left_text':'Fade Time:'})
add_body_edit('volume', ValueType.NUMBER, {'left_text':'Volume:', 'mode':2}, '!file_path.is_empty()')
add_body_edit('audio_bus', ValueType.SINGLELINE_TEXT, {'left_text':'Audio Bus:'}, '!file_path.is_empty()')
add_body_edit('loop', ValueType.BOOL, {'left_text':'Loop:'}, '!file_path.is_empty() and not file_path.to_lower().ends_with(".wav")')
func get_bus_suggestions() -> Dictionary:
var bus_name_list := {}
for i in range(AudioServer.bus_count):
bus_name_list[AudioServer.get_bus_name(i)] = {'value':AudioServer.get_bus_name(i)}
return bus_name_list
func get_channel_list() -> Array:
var channel_name_list := []
for i in ProjectSettings.get_setting('dialogic/audio/max_channels', 4):
channel_name_list.append({
'label': 'Channel %s' % (i + 1),
'value': i,
})
return channel_name_list

View File

@@ -0,0 +1 @@
uid://bqvbfkocj66c1

View File

@@ -0,0 +1,86 @@
@tool
class_name DialogicSoundEvent
extends DialogicEvent
## Event that allows to play a sound effect. Requires the Audio subsystem!
### Settings
## The path to the file to play.
var file_path := "":
set(value):
if file_path != value:
file_path = value
ui_update_needed.emit()
## The volume to play the sound at.
var volume: float = 0
## The bus to play the sound on.
var audio_bus := ""
## If true, the sound will loop infinitely. Not recommended (as there is no way to stop it).
var loop := false
################################################################################
## EXECUTE
################################################################################
func _execute() -> void:
dialogic.Audio.play_sound(file_path, volume, audio_bus, loop)
finish()
################################################################################
## INITIALIZE
################################################################################
func _init() -> void:
event_name = "Sound"
set_default_color('Color7')
event_category = "Audio"
event_sorting_index = 3
help_page_path = "https://dialogic.coppolaemilio.com"
func _get_icon() -> Resource:
return load(self.get_script().get_path().get_base_dir().path_join('icon_sound.png'))
################################################################################
## SAVING/LOADING
################################################################################
func get_shortcode() -> String:
return "sound"
func get_shortcode_parameters() -> Dictionary:
return {
#param_name : property_name
"path" : {"property": "file_path", "default": "",},
"volume" : {"property": "volume", "default": 0},
"bus" : {"property": "audio_bus", "default": "",
"suggestions": get_bus_suggestions},
"loop" : {"property": "loop", "default": false},
}
################################################################################
## EDITOR REPRESENTATION
################################################################################
func build_event_editor() -> void:
add_header_edit('file_path', ValueType.FILE,
{'left_text' : 'Play',
'file_filter' : '*.mp3, *.ogg, *.wav; Supported Audio Files',
'placeholder' : "Select file",
'editor_icon' : ["AudioStreamPlayer", "EditorIcons"]})
add_header_edit('file_path', ValueType.AUDIO_PREVIEW)
add_body_edit('volume', ValueType.NUMBER, {'left_text':'Volume:', 'mode':2}, '!file_path.is_empty()')
add_body_edit('audio_bus', ValueType.SINGLELINE_TEXT, {'left_text':'Audio Bus:'}, '!file_path.is_empty()')
func get_bus_suggestions() -> Dictionary:
var bus_name_list := {}
for i in range(AudioServer.bus_count):
bus_name_list[AudioServer.get_bus_name(i)] = {'value':AudioServer.get_bus_name(i)}
return bus_name_list

View File

@@ -0,0 +1 @@
uid://dt8y1dhcotaqk

Binary file not shown.

After

Width:  |  Height:  |  Size: 552 B

View File

@@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://buvpjsvdt4evk"
path="res://.godot/imported/icon_music.png-ffc971ba1265164a55f745186974be5f.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://addons/dialogic/Modules/Audio/icon_music.png"
dest_files=["res://.godot/imported/icon_music.png-ffc971ba1265164a55f745186974be5f.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 524 B

View File

@@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://d3ookrkto0yh6"
path="res://.godot/imported/icon_sound.png-7a1a8a5533773d97969b6311b6a9133f.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://addons/dialogic/Modules/Audio/icon_sound.png"
dest_files=["res://.godot/imported/icon_sound.png-7a1a8a5533773d97969b6311b6a9133f.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View File

@@ -0,0 +1,14 @@
@tool
extends DialogicIndexer
func _get_events() -> Array:
return [this_folder.path_join('event_music.gd'), this_folder.path_join('event_sound.gd')]
func _get_subsystems() -> Array:
return [{'name':'Audio', 'script':this_folder.path_join('subsystem_audio.gd')}]
func _get_settings_pages() -> Array:
return [this_folder.path_join('settings_audio.tscn')]

View File

@@ -0,0 +1 @@
uid://v7jdps3ek0co

View File

@@ -0,0 +1,32 @@
@tool
extends DialogicSettingsPage
## Settings page that contains settings for the audio subsystem
const MUSIC_MAX_CHANNELS := "dialogic/audio/max_channels"
const TYPE_SOUND_AUDIO_BUS := "dialogic/audio/type_sound_bus"
func _ready() -> void:
%MusicChannelCount.value_changed.connect(_on_music_channel_count_value_changed)
%TypeSoundBus.item_selected.connect(_on_type_sound_bus_item_selected)
func _refresh() -> void:
%MusicChannelCount.value = ProjectSettings.get_setting(MUSIC_MAX_CHANNELS, 4)
%TypeSoundBus.clear()
var idx := 0
for i in range(AudioServer.bus_count):
%TypeSoundBus.add_item(AudioServer.get_bus_name(i))
if AudioServer.get_bus_name(i) == ProjectSettings.get_setting(TYPE_SOUND_AUDIO_BUS, ""):
idx = i
%TypeSoundBus.select(idx)
func _on_music_channel_count_value_changed(value:float) -> void:
ProjectSettings.set_setting(MUSIC_MAX_CHANNELS, value)
ProjectSettings.save()
func _on_type_sound_bus_item_selected(index:int) -> void:
ProjectSettings.set_setting(TYPE_SOUND_AUDIO_BUS, %TypeSoundBus.get_item_text(index))
ProjectSettings.save()

View File

@@ -0,0 +1 @@
uid://n0arpfy8kyhh

View File

@@ -0,0 +1,54 @@
[gd_scene load_steps=3 format=3 uid="uid://c2qgetjc3mfo3"]
[ext_resource type="Script" path="res://addons/dialogic/Modules/Audio/settings_audio.gd" id="1_2iyyr"]
[ext_resource type="PackedScene" uid="uid://dbpkta2tjsqim" path="res://addons/dialogic/Editor/Common/hint_tooltip_icon.tscn" id="2_o1ban"]
[node name="Audio" type="VBoxContainer"]
offset_right = 121.0
offset_bottom = 58.0
script = ExtResource("1_2iyyr")
[node name="Label" type="Label" parent="."]
layout_mode = 2
theme_type_variation = &"DialogicSettingsSection"
text = "Music Channels"
[node name="HBoxContainer" type="HBoxContainer" parent="."]
layout_mode = 2
[node name="Label" type="Label" parent="HBoxContainer"]
layout_mode = 2
text = "Max music channels"
[node name="HintTooltip" parent="HBoxContainer" instance=ExtResource("2_o1ban")]
layout_mode = 2
texture = null
hint_text = "Lowering this value may invalidate existing music events!"
[node name="MusicChannelCount" type="SpinBox" parent="HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
min_value = 1.0
value = 1.0
[node name="TypingSoundsTitle" type="Label" parent="."]
layout_mode = 2
theme_type_variation = &"DialogicSettingsSection"
text = "Typing Sounds"
[node name="HBoxContainer2" type="HBoxContainer" parent="."]
layout_mode = 2
[node name="Label" type="Label" parent="HBoxContainer2"]
layout_mode = 2
text = "Audio Bus"
[node name="HintTooltip" parent="HBoxContainer2" instance=ExtResource("2_o1ban")]
layout_mode = 2
tooltip_text = "Lowering this value may invalidate existing music events!"
texture = null
hint_text = "The default audio bus used by TypeSound nodes."
[node name="TypeSoundBus" type="OptionButton" parent="HBoxContainer2"]
unique_name_in_owner = true
layout_mode = 2

View File

@@ -0,0 +1,219 @@
extends DialogicSubsystem
## Subsystem for managing background music and one-shot sound effects.
##
## This subsystem has many different helper methods for managing audio
## in your timeline.
## For instance, you can listen to music changes via [signal music_started].
## Whenever a new background music is started, this signal is emitted and
## contains a dictionary with the following keys: [br]
## [br]
## Key | Value Type | Value [br]
## ----------- | ------------- | ----- [br]
## `path` | [type String] | The path to the audio resource file. [br]
## `volume` | [type float] | The volume of the audio resource that will be set to the [member base_music_player]. [br]
## `audio_bus` | [type String] | The audio bus name that the [member base_music_player] will use. [br]
## `loop` | [type bool] | Whether the audio resource will loop or not once it finishes playing. [br]
## `channel` | [type int] | The channel ID to play the audio on. [br]
signal music_started(info: Dictionary)
## Whenever a new sound effect is set, this signal is emitted and contains a
## dictionary with the following keys: [br]
## [br]
## Key | Value Type | Value [br]
## ----------- | ------------- | ----- [br]
## `path` | [type String] | The path to the audio resource file. [br]
## `volume` | [type float] | The volume of the audio resource that will be set to [member base_sound_player]. [br]
## `audio_bus` | [type String] | The audio bus name that the [member base_sound_player] will use. [br]
## `loop` | [type bool] | Whether the audio resource will loop or not once it finishes playing. [br]
signal sound_started(info: Dictionary)
var max_channels: int:
set(value):
if max_channels != value:
max_channels = value
ProjectSettings.set_setting('dialogic/audio/max_channels', value)
ProjectSettings.save()
current_music_player.resize(value)
get:
return ProjectSettings.get_setting('dialogic/audio/max_channels', 4)
## Audio player base duplicated to play background music.
##
## Background music is long audio.
var base_music_player := AudioStreamPlayer.new()
## Reference to the last used music player.
var current_music_player: Array[AudioStreamPlayer] = []
## Audio player base, that will be duplicated to play sound effects.
##
## Sound effects are short audio.
var base_sound_player := AudioStreamPlayer.new()
#region STATE
####################################################################################################
## Clears the state on this subsystem and stops all audio.
##
## If you want to stop sounds only, use [method stop_all_sounds].
func clear_game_state(_clear_flag := DialogicGameHandler.ClearFlags.FULL_CLEAR) -> void:
for idx in max_channels:
update_music('', 0.0, '', 0.0, true, idx)
stop_all_sounds()
## Loads the state on this subsystem from the current state info.
func load_game_state(load_flag:=LoadFlags.FULL_LOAD) -> void:
if load_flag == LoadFlags.ONLY_DNODES:
return
var info: Dictionary = dialogic.current_state_info.get("music", {})
if not info.is_empty() and info.has('path'):
update_music(info.path, info.volume, info.audio_bus, 0, info.loop, 0)
else:
for channel_id in info.keys():
if info[channel_id].is_empty() or info[channel_id].path.is_empty():
update_music('', 0.0, '', 0.0, true, channel_id)
else:
update_music(info[channel_id].path, info[channel_id].volume, info[channel_id].audio_bus, 0, info[channel_id].loop, channel_id)
## Pauses playing audio.
func pause() -> void:
for child in get_children():
child.stream_paused = true
## Resumes playing audio.
func resume() -> void:
for child in get_children():
child.stream_paused = false
func _on_dialogic_timeline_ended() -> void:
if not dialogic.Styles.get_layout_node():
clear_game_state()
pass
#endregion
#region MAIN METHODS
####################################################################################################
func _ready() -> void:
dialogic.timeline_ended.connect(_on_dialogic_timeline_ended)
base_music_player.name = "Music"
add_child(base_music_player)
base_sound_player.name = "Sound"
add_child(base_sound_player)
current_music_player.resize(max_channels)
## Updates the background music. Will fade out previous music.
func update_music(path := "", volume := 0.0, audio_bus := "", fade_time := 0.0, loop := true, channel_id := 0) -> void:
if channel_id > max_channels:
printerr("\tChannel ID (%s) higher than Max Music Channels (%s)" % [channel_id, max_channels])
dialogic.print_debug_moment()
return
if not dialogic.current_state_info.has('music'):
dialogic.current_state_info['music'] = {}
dialogic.current_state_info['music'][channel_id] = {'path':path, 'volume':volume, 'audio_bus':audio_bus, 'loop':loop, 'channel':channel_id}
music_started.emit(dialogic.current_state_info['music'][channel_id])
var fader: Tween = null
if is_instance_valid(current_music_player[channel_id]) and current_music_player[channel_id].playing or !path.is_empty():
fader = create_tween()
var prev_node: Node = null
if is_instance_valid(current_music_player[channel_id]) and current_music_player[channel_id].playing:
prev_node = current_music_player[channel_id]
fader.tween_method(interpolate_volume_linearly.bind(prev_node), db_to_linear(prev_node.volume_db),0.0,fade_time)
if path:
current_music_player[channel_id] = base_music_player.duplicate()
add_child(current_music_player[channel_id])
current_music_player[channel_id].stream = load(path)
current_music_player[channel_id].volume_db = volume
if audio_bus:
current_music_player[channel_id].bus = audio_bus
if not current_music_player[channel_id].stream is AudioStreamWAV:
if "loop" in current_music_player[channel_id].stream:
current_music_player[channel_id].stream.loop = loop
elif "loop_mode" in current_music_player[channel_id].stream:
if loop:
current_music_player[channel_id].stream.loop_mode = AudioStreamWAV.LOOP_FORWARD
else:
current_music_player[channel_id].stream.loop_mode = AudioStreamWAV.LOOP_DISABLED
current_music_player[channel_id].play(0)
fader.parallel().tween_method(interpolate_volume_linearly.bind(current_music_player[channel_id]), 0.0, db_to_linear(volume),fade_time)
if prev_node:
fader.tween_callback(prev_node.queue_free)
## Whether music is playing.
func has_music(channel_id := 0) -> bool:
return !dialogic.current_state_info.get('music', {}).get(channel_id, {}).get('path', '').is_empty()
## Plays a given sound file.
func play_sound(path: String, volume := 0.0, audio_bus := "", loop := false) -> void:
if base_sound_player != null and !path.is_empty():
sound_started.emit({'path':path, 'volume':volume, 'audio_bus':audio_bus, 'loop':loop})
var new_sound_node := base_sound_player.duplicate()
new_sound_node.name += "Sound"
new_sound_node.stream = load(path)
if "loop" in new_sound_node.stream:
new_sound_node.stream.loop = loop
elif "loop_mode" in new_sound_node.stream:
if loop:
new_sound_node.stream.loop_mode = AudioStreamWAV.LOOP_FORWARD
else:
new_sound_node.stream.loop_mode = AudioStreamWAV.LOOP_DISABLED
new_sound_node.volume_db = volume
if audio_bus:
new_sound_node.bus = audio_bus
add_child(new_sound_node)
new_sound_node.play()
new_sound_node.finished.connect(new_sound_node.queue_free)
## Stops all audio.
func stop_all_sounds() -> void:
for node in get_children():
if node == base_sound_player:
continue
if "Sound" in node.name:
node.queue_free()
## Converts a linear loudness value to decibel and sets that volume to
## the given [param node].
func interpolate_volume_linearly(value: float, node: Node) -> void:
node.volume_db = linear_to_db(value)
## Returns whether the currently playing audio resource is the same as this
## event's [param resource_path], for [param channel_id].
func is_music_playing_resource(resource_path: String, channel_id := 0) -> bool:
var is_playing_resource: bool = (current_music_player.size() > channel_id
and is_instance_valid(current_music_player[channel_id])
and current_music_player[channel_id].is_playing()
and current_music_player[channel_id].stream.resource_path == resource_path)
return is_playing_resource
#endregion

View File

@@ -0,0 +1 @@
uid://bb5wwgcuvsx0i