ajout du plugin dialogical
This commit is contained in:
397
addons/dialogic/Modules/Audio/event_audio.gd
Normal file
397
addons/dialogic/Modules/Audio/event_audio.gd
Normal file
@@ -0,0 +1,397 @@
|
||||
@tool
|
||||
## Event that can play audio on a channel. The channel can be prededinfed
|
||||
## (with default settings defined in the settings) or created on the spot.
|
||||
## If no channel is given will play as a One-Shot SFX.
|
||||
class_name DialogicAudioEvent
|
||||
extends DialogicEvent
|
||||
|
||||
### Settings
|
||||
|
||||
## The file to play. If empty, the previous audio will be faded out.
|
||||
var file_path := "":
|
||||
set(value):
|
||||
if file_path != value:
|
||||
file_path = value
|
||||
ui_update_needed.emit()
|
||||
## The channel name to use. If none given plays as a One-Shot SFX.
|
||||
var channel_name := "":
|
||||
set(value):
|
||||
if channel_name != channel_name_regex.sub(value, '', true):
|
||||
channel_name = channel_name_regex.sub(value, '', true)
|
||||
var defaults: Dictionary = DialogicUtil.get_audio_channel_defaults().get(channel_name, {})
|
||||
if defaults:
|
||||
fade_length = defaults.fade_length
|
||||
volume = defaults.volume
|
||||
audio_bus = defaults.audio_bus
|
||||
loop = defaults.loop
|
||||
ui_update_needed.emit()
|
||||
|
||||
## The length of the fade. If 0 it's an instant change.
|
||||
var fade_length: float = 0.0
|
||||
## The volume in decibel.
|
||||
var volume: float = 0.0
|
||||
## The audio bus the audio will be played on.
|
||||
var audio_bus := ""
|
||||
## If true, the audio will loop, otherwise only play once.
|
||||
var loop := true
|
||||
## Sync starting time with different channel (if playing audio on that channel)
|
||||
var sync_channel := ""
|
||||
|
||||
## Helpers. Set automatically
|
||||
var set_fade_length := false
|
||||
var set_volume := false
|
||||
var set_audio_bus := false
|
||||
var set_loop := false
|
||||
var set_sync_channel := false
|
||||
|
||||
var regex := RegEx.create_from_string(r'(?:audio)\s*(?<channel>[\w-]{2,}|[\w]*)?\s*(")?(?<file_path>(?(2)[^"\n]*|[^(: \n]*))(?(2)"|)(?:\s*\[(?<shortcode>.*)\])?')
|
||||
var channel_name_regex := RegEx.create_from_string(r'(?<dash_only>^-$)|(?<invalid>[^\w-]{1})')
|
||||
|
||||
################################################################################
|
||||
## EXECUTE
|
||||
################################################################################
|
||||
|
||||
func _execute() -> void:
|
||||
var audio_settings_overrides := {}
|
||||
if set_audio_bus:
|
||||
audio_settings_overrides["audio_bus"] = audio_bus
|
||||
if set_volume:
|
||||
audio_settings_overrides["volume"] = volume
|
||||
if set_fade_length:
|
||||
audio_settings_overrides["fade_length"] = fade_length
|
||||
if set_loop:
|
||||
audio_settings_overrides["loop"] = loop
|
||||
audio_settings_overrides["sync_channel"] = sync_channel
|
||||
dialogic.Audio.update_audio(channel_name, file_path, audio_settings_overrides)
|
||||
|
||||
finish()
|
||||
|
||||
################################################################################
|
||||
## INITIALIZE
|
||||
################################################################################
|
||||
|
||||
func _init() -> void:
|
||||
event_name = "Audio"
|
||||
set_default_color('Color7')
|
||||
event_category = "Audio"
|
||||
event_sorting_index = 2
|
||||
|
||||
|
||||
func _get_icon() -> Resource:
|
||||
return load(this_folder.path_join('icon_music.png'))
|
||||
|
||||
################################################################################
|
||||
## SAVING/LOADING
|
||||
################################################################################
|
||||
|
||||
func to_text () -> String:
|
||||
var result_string := "audio "
|
||||
|
||||
if not channel_name.is_empty():
|
||||
result_string += channel_name + " "
|
||||
else:
|
||||
loop = false
|
||||
|
||||
if not file_path.is_empty():
|
||||
result_string += "\"" + file_path + "\""
|
||||
else:
|
||||
result_string += "-"
|
||||
|
||||
var shortcode := store_to_shortcode_parameters()
|
||||
if not shortcode.is_empty():
|
||||
result_string += " [" + shortcode + "]"
|
||||
|
||||
return result_string
|
||||
|
||||
|
||||
func from_text(string:String) -> void:
|
||||
# Pre Alpha 17 Conversion
|
||||
if string.begins_with('[music'):
|
||||
_music_from_text(string)
|
||||
return
|
||||
elif string.begins_with('[sound'):
|
||||
_sound_from_text(string)
|
||||
return
|
||||
|
||||
var result := regex.search(string)
|
||||
|
||||
channel_name = result.get_string('channel')
|
||||
|
||||
if result.get_string('file_path') == '-':
|
||||
file_path = ""
|
||||
else:
|
||||
file_path = result.get_string('file_path')
|
||||
|
||||
if not result.get_string('shortcode'):
|
||||
return
|
||||
|
||||
load_from_shortcode_parameters(result.get_string('shortcode'))
|
||||
|
||||
|
||||
func get_shortcode_parameters() -> Dictionary:
|
||||
return {
|
||||
#param_name : property_info
|
||||
"path" : {"property": "file_path", "default": "", "custom_stored":true, "ext_file":true},
|
||||
"channel" : {"property": "channel_name", "default": "", "custom_stored":true},
|
||||
"fade" : {"property": "fade_length", "default": 0.0},
|
||||
"volume" : {"property": "volume", "default": 0.0},
|
||||
"bus" : {"property": "audio_bus", "default": "",
|
||||
"suggestions": DialogicUtil.get_audio_bus_suggestions},
|
||||
"loop" : {"property": "loop", "default": true},
|
||||
"sync" : {"property": "sync_channel", "default": "",
|
||||
"suggestions": get_sync_audio_channel_suggestions},
|
||||
}
|
||||
|
||||
|
||||
## Returns a string with all the shortcode parameters.
|
||||
func store_to_shortcode_parameters(params:Dictionary = {}) -> String:
|
||||
if params.is_empty():
|
||||
params = get_shortcode_parameters()
|
||||
var custom_defaults: Dictionary = DialogicUtil.get_custom_event_defaults(event_name)
|
||||
var channel_defaults := DialogicUtil.get_audio_channel_defaults()
|
||||
var result_string := ""
|
||||
for parameter in params.keys():
|
||||
var parameter_info: Dictionary = params[parameter]
|
||||
var value: Variant = get(parameter_info.property)
|
||||
var default_value: Variant = custom_defaults.get(parameter_info.property, parameter_info.default)
|
||||
|
||||
if parameter_info.get('custom_stored', false):
|
||||
continue
|
||||
|
||||
if "set_" + parameter_info.property in self and not get("set_" + parameter_info.property):
|
||||
continue
|
||||
|
||||
if channel_name in channel_defaults.keys():
|
||||
default_value = channel_defaults[channel_name].get(parameter_info.property, default_value)
|
||||
|
||||
if typeof(value) == typeof(default_value) and value == default_value:
|
||||
if not "set_" + parameter_info.property in self or not get("set_" + parameter_info.property):
|
||||
continue
|
||||
|
||||
result_string += " " + parameter + '="' + value_to_string(value, parameter_info.get("suggestions", Callable())) + '"'
|
||||
|
||||
return result_string.strip_edges()
|
||||
|
||||
|
||||
func is_valid_event(string:String) -> bool:
|
||||
if string.begins_with("audio"):
|
||||
return true
|
||||
# Pre Alpha 17 Converter
|
||||
if string.strip_edges().begins_with('[music '):
|
||||
return true
|
||||
if string.strip_edges().begins_with('[sound '):
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
#region PreAlpha17 Conversion
|
||||
|
||||
func _music_from_text(string:String) -> void:
|
||||
var data := parse_shortcode_parameters(string)
|
||||
|
||||
if data.has('channel') and data['channel'].to_int() > 0:
|
||||
channel_name = 'music' + str(data['channel'].to_int() + 1)
|
||||
else:
|
||||
channel_name = 'music'
|
||||
|
||||
# Reapply original defaults as setting channel name may have overridden them
|
||||
fade_length = 0.0
|
||||
volume = 0.0
|
||||
audio_bus = ''
|
||||
loop = true
|
||||
|
||||
# Apply any custom event defaults
|
||||
for default_prop in DialogicUtil.get_custom_event_defaults('music'):
|
||||
if default_prop in self:
|
||||
set(default_prop, DialogicUtil.get_custom_event_defaults('music')[default_prop])
|
||||
|
||||
# Apply shortcodes that exist
|
||||
if data.has('path'):
|
||||
file_path = data['path']
|
||||
if data.has('fade'):
|
||||
set_fade_length = true
|
||||
fade_length = data['fade'].to_float()
|
||||
if data.has('volume'):
|
||||
set_volume = true
|
||||
volume = data['volume'].to_float()
|
||||
if data.has('bus'):
|
||||
set_audio_bus = true
|
||||
audio_bus = data['bus']
|
||||
if data.has('loop'):
|
||||
set_loop = true
|
||||
loop = str_to_var(data['loop'])
|
||||
update_text_version()
|
||||
|
||||
|
||||
func _sound_from_text(string:String) -> void:
|
||||
var data := parse_shortcode_parameters(string)
|
||||
|
||||
channel_name = ''
|
||||
|
||||
# Reapply original defaults as setting channel name may have overridden them
|
||||
fade_length = 0.0
|
||||
volume = 0.0
|
||||
audio_bus = ''
|
||||
loop = false
|
||||
|
||||
# Apply any custom event defaults
|
||||
for default_prop in DialogicUtil.get_custom_event_defaults('sound'):
|
||||
if default_prop in self:
|
||||
set(default_prop, DialogicUtil.get_custom_event_defaults('sound')[default_prop])
|
||||
|
||||
# Apply shortcodes that exist
|
||||
if data.has('path'):
|
||||
file_path = data['path']
|
||||
if data.has('volume'):
|
||||
set_volume = true
|
||||
volume = data['volume'].to_float()
|
||||
if data.has('bus'):
|
||||
set_audio_bus = true
|
||||
audio_bus = data['bus']
|
||||
if data.has('loop'):
|
||||
set_loop = true
|
||||
loop = str_to_var(data['loop'])
|
||||
update_text_version()
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
################################################################################
|
||||
## 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' : "Nothing",
|
||||
'editor_icon' : ["AudioStreamMP3", "EditorIcons"]})
|
||||
add_header_edit('file_path', ValueType.AUDIO_PREVIEW)
|
||||
|
||||
add_header_edit('channel_name', ValueType.DYNAMIC_OPTIONS, {
|
||||
'left_text' :"on",
|
||||
"right_text" : "channel.",
|
||||
'placeholder' : '(One-Shot SFX)',
|
||||
'mode' : 3,
|
||||
'suggestions_func' : get_audio_channel_suggestions,
|
||||
'validation_func' : DialogicUtil.validate_audio_channel_name,
|
||||
'tooltip' : 'Use an existing channel or type the name for a new channel.',
|
||||
})
|
||||
|
||||
add_header_button('', _open_audio_settings, 'Edit Audio Channels',
|
||||
editor_node.get_theme_icon("ExternalLink", "EditorIcons"))
|
||||
|
||||
add_body_edit("set_fade_length", ValueType.BOOL_BUTTON,{
|
||||
"editor_icon" : ["FadeCross", "EditorIcons"],
|
||||
"tooltip" : "Overwrite Fade Length"
|
||||
},"!channel_name.is_empty() and has_channel_defaults()")
|
||||
add_body_edit('fade_length', ValueType.NUMBER, {'left_text':'Fade Time:'},
|
||||
'!channel_name.is_empty() and (not has_channel_defaults() or set_fade_length)')
|
||||
|
||||
add_body_edit("set_volume", ValueType.BOOL_BUTTON,{
|
||||
"editor_icon" : ["AudioStreamPlayer", "EditorIcons"],
|
||||
"tooltip" : "Overwrite Volume"
|
||||
},"!file_path.is_empty() and has_channel_defaults()")
|
||||
add_body_edit('volume', ValueType.NUMBER, {'left_text':'Volume:', 'mode':2},
|
||||
'!file_path.is_empty() and (not has_channel_defaults() or set_volume)')
|
||||
add_body_edit("set_audio_bus", ValueType.BOOL_BUTTON,{
|
||||
"editor_icon" : ["AudioBusBypass", "EditorIcons"],
|
||||
"tooltip" : "Overwrite Audio Bus"
|
||||
},"!file_path.is_empty() and has_channel_defaults()")
|
||||
add_body_edit('audio_bus', ValueType.DYNAMIC_OPTIONS, {
|
||||
'left_text':'Audio Bus:',
|
||||
'placeholder' : 'Master',
|
||||
'mode' : 2,
|
||||
'suggestions_func' : DialogicUtil.get_audio_bus_suggestions,
|
||||
}, '!file_path.is_empty() and (not has_channel_defaults() or set_audio_bus)')
|
||||
add_body_edit("set_loop", ValueType.BOOL_BUTTON,{
|
||||
"editor_icon" : ["Loop", "EditorIcons"],
|
||||
"tooltip" : "Overwrite Loop"
|
||||
},"!channel_name.is_empty() and !file_path.is_empty() and has_channel_defaults()")
|
||||
add_body_edit('loop', ValueType.BOOL, {'left_text':'Loop:'},
|
||||
'!channel_name.is_empty() and !file_path.is_empty() and (not has_channel_defaults() or set_loop)')
|
||||
add_body_line_break("!channel_name.is_empty() and !file_path.is_empty()")
|
||||
add_body_edit("set_sync_channel", ValueType.BOOL_BUTTON,{
|
||||
"editor_icon" : ["TransitionSync", "EditorIcons"],
|
||||
"tooltip" : "Enable Syncing"
|
||||
},"!channel_name.is_empty() and !file_path.is_empty()")
|
||||
|
||||
add_body_edit('sync_channel', ValueType.DYNAMIC_OPTIONS, {
|
||||
'left_text' :'Sync with:',
|
||||
'placeholder' : '(No Sync)',
|
||||
'mode' : 3,
|
||||
'suggestions_func' : get_sync_audio_channel_suggestions,
|
||||
'validation_func' : DialogicUtil.validate_audio_channel_name,
|
||||
'tooltip' : "Use an existing channel or type the name for a new channel. If channel doesn't exist, this setting will be ignored.",
|
||||
}, '!channel_name.is_empty() and !file_path.is_empty() and set_sync_channel')
|
||||
|
||||
|
||||
## Used by the button on the visual event
|
||||
func _open_audio_settings() -> void:
|
||||
var editor_manager := editor_node.find_parent('EditorsManager')
|
||||
if editor_manager:
|
||||
editor_manager.open_editor(editor_manager.editors['Settings']['node'], true, "Audio")
|
||||
|
||||
|
||||
## Helper for the visibility conditions
|
||||
func has_channel_defaults() -> bool:
|
||||
var defaults := DialogicUtil.get_audio_channel_defaults()
|
||||
return defaults.has(channel_name)
|
||||
|
||||
|
||||
func get_audio_channel_suggestions(filter:String) -> Dictionary:
|
||||
var suggestions := {}
|
||||
suggestions["(One-Shot SFX)"] = {
|
||||
"value":"",
|
||||
"tooltip": "Used for one shot sounds effects. Plays each sound in its own AudioStreamPlayer.",
|
||||
"editor_icon": ["GuiRadioUnchecked", "EditorIcons"]
|
||||
}
|
||||
# TODO use .merged after dropping 4.2 support
|
||||
suggestions.merge(DialogicUtil.get_audio_channel_suggestions(filter))
|
||||
return suggestions
|
||||
|
||||
func get_sync_audio_channel_suggestions(filter:="") -> Dictionary:
|
||||
return DialogicUtil.get_audio_channel_suggestions(filter)
|
||||
|
||||
|
||||
|
||||
####################### CODE COMPLETION ########################################
|
||||
################################################################################
|
||||
|
||||
func _get_code_completion(CodeCompletionHelper:Node, TextNode:TextEdit, line:String, word:String, symbol:String) -> void:
|
||||
var line_until: String = CodeCompletionHelper.get_line_untill_caret(line)
|
||||
if symbol == ' ':
|
||||
if line_until.count(' ') == 1:
|
||||
TextNode.add_code_completion_option(CodeEdit.KIND_MEMBER, "One-Shot SFX", ' ', event_color.lerp(TextNode.syntax_highlighter.normal_color, 0.6))
|
||||
for i in DialogicUtil.get_audio_channel_suggestions(""):
|
||||
TextNode.add_code_completion_option(CodeEdit.KIND_MEMBER, i, i, event_color.lerp(TextNode.syntax_highlighter.normal_color, 0.6), null, " ")
|
||||
elif line_until.count(" ") == 2:
|
||||
TextNode.add_code_completion_option(CodeEdit.KIND_MEMBER, '"', '"', event_color.lerp(TextNode.syntax_highlighter.normal_color, 0.6))
|
||||
|
||||
if symbol == "[" or (symbol == " " and line.count("[")):
|
||||
for i in ["fade", "volume", "bus", "loop", "sync"]:
|
||||
if not i+"=" in line:
|
||||
TextNode.add_code_completion_option(CodeEdit.KIND_MEMBER, i, i+'="', event_color.lerp(TextNode.syntax_highlighter.normal_color, 0.6))
|
||||
|
||||
if (symbol == '"' or symbol == "=") and line.count("["):
|
||||
CodeCompletionHelper.suggest_shortcode_values(TextNode, self, line, word)
|
||||
|
||||
|
||||
func _get_start_code_completion(_CodeCompletionHelper:Node, TextNode:TextEdit) -> void:
|
||||
TextNode.add_code_completion_option(CodeEdit.KIND_PLAIN_TEXT, 'audio', 'audio ', event_color.lerp(TextNode.syntax_highlighter.normal_color, 0.3))
|
||||
|
||||
|
||||
#################### SYNTAX HIGHLIGHTING #######################################
|
||||
################################################################################
|
||||
|
||||
func _get_syntax_highlighting(Highlighter:SyntaxHighlighter, dict:Dictionary, line:String) -> Dictionary:
|
||||
var result := regex.search(line)
|
||||
|
||||
dict[result.get_start()] = {"color":event_color.lerp(Highlighter.normal_color, 0.3)}
|
||||
dict[result.get_start("channel")] = {"color":event_color.lerp(Highlighter.normal_color, 0.8)}
|
||||
dict[result.get_start("file_path")] = {"color":event_color.lerp(Highlighter.string_color, 0.8)}
|
||||
if result.get_string("shortcode"):
|
||||
dict[result.get_start("shortcode")-1] = {"color":Highlighter.normal_color}
|
||||
dict = Highlighter.color_shortcode_content(dict, line, result.get_start("shortcode"), 0, event_color)
|
||||
|
||||
return dict
|
||||
1
addons/dialogic/Modules/Audio/event_audio.gd.uid
Normal file
1
addons/dialogic/Modules/Audio/event_audio.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://8p4qchmcuj68
|
||||
BIN
addons/dialogic/Modules/Audio/icon_music.png
Normal file
BIN
addons/dialogic/Modules/Audio/icon_music.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 552 B |
40
addons/dialogic/Modules/Audio/icon_music.png.import
Normal file
40
addons/dialogic/Modules/Audio/icon_music.png.import
Normal 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
|
||||
BIN
addons/dialogic/Modules/Audio/icon_sound.png
Normal file
BIN
addons/dialogic/Modules/Audio/icon_sound.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 524 B |
40
addons/dialogic/Modules/Audio/icon_sound.png.import
Normal file
40
addons/dialogic/Modules/Audio/icon_sound.png.import
Normal 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
|
||||
14
addons/dialogic/Modules/Audio/index.gd
Normal file
14
addons/dialogic/Modules/Audio/index.gd
Normal file
@@ -0,0 +1,14 @@
|
||||
@tool
|
||||
extends DialogicIndexer
|
||||
|
||||
|
||||
func _get_events() -> Array:
|
||||
return [this_folder.path_join('event_audio.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')]
|
||||
1
addons/dialogic/Modules/Audio/index.gd.uid
Normal file
1
addons/dialogic/Modules/Audio/index.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dk46l1toqeswc
|
||||
241
addons/dialogic/Modules/Audio/settings_audio.gd
Normal file
241
addons/dialogic/Modules/Audio/settings_audio.gd
Normal file
@@ -0,0 +1,241 @@
|
||||
@tool
|
||||
extends DialogicSettingsPage
|
||||
|
||||
## Settings page that contains settings for the audio subsystem
|
||||
|
||||
const TYPE_SOUND_AUDIO_BUS := "dialogic/audio/type_sound_bus"
|
||||
const CHANNEL_DEFAULTS := "dialogic/audio/channel_defaults"
|
||||
|
||||
var channel_defaults := {}
|
||||
var _revalidate_channel_names := false
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
%TypeSoundBus.item_selected.connect(_on_type_sound_bus_item_selected)
|
||||
$Panel.add_theme_stylebox_override('panel', get_theme_stylebox("Background", "EditorStyles"))
|
||||
|
||||
|
||||
func _refresh() -> void:
|
||||
%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)
|
||||
|
||||
load_channel_defaults(DialogicUtil.get_audio_channel_defaults())
|
||||
|
||||
|
||||
func _about_to_close() -> void:
|
||||
save_channel_defaults()
|
||||
|
||||
|
||||
## TYPE SOUND AUDIO BUS
|
||||
func _on_type_sound_bus_item_selected(index:int) -> void:
|
||||
ProjectSettings.set_setting(TYPE_SOUND_AUDIO_BUS, %TypeSoundBus.get_item_text(index))
|
||||
ProjectSettings.save()
|
||||
|
||||
|
||||
#region AUDIO CHANNELS
|
||||
################################################################################
|
||||
|
||||
func load_channel_defaults(dictionary:Dictionary) -> void:
|
||||
channel_defaults.clear()
|
||||
for i in %AudioChannelDefaults.get_children():
|
||||
i.queue_free()
|
||||
|
||||
var column_names := [
|
||||
"Channel Name",
|
||||
"Volume",
|
||||
"Audio Bus",
|
||||
"Fade",
|
||||
"Loop",
|
||||
""
|
||||
]
|
||||
|
||||
for column in column_names:
|
||||
var label := Label.new()
|
||||
label.text = column
|
||||
label.theme_type_variation = 'DialogicHintText2'
|
||||
%AudioChannelDefaults.add_child(label)
|
||||
|
||||
var channel_names := dictionary.keys()
|
||||
channel_names.sort()
|
||||
|
||||
for channel_name in channel_names:
|
||||
add_channel_defaults(
|
||||
channel_name,
|
||||
dictionary[channel_name].volume,
|
||||
dictionary[channel_name].audio_bus,
|
||||
dictionary[channel_name].fade_length,
|
||||
dictionary[channel_name].loop)
|
||||
|
||||
await get_tree().process_frame
|
||||
|
||||
_revalidate_channel_names = true
|
||||
revalidate_channel_names.call_deferred()
|
||||
|
||||
|
||||
func save_channel_defaults() -> void:
|
||||
var dictionary := {}
|
||||
|
||||
for i in channel_defaults:
|
||||
if is_instance_valid(channel_defaults[i].channel_name):
|
||||
var channel_name := ""
|
||||
if not channel_defaults[i].channel_name is Label:
|
||||
if channel_defaults[i].channel_name.current_value.is_empty():
|
||||
continue
|
||||
|
||||
channel_name = channel_defaults[i].channel_name.current_value
|
||||
#channel_name = DialogicUtil.channel_name_regex.sub(channel_name, '', true)
|
||||
|
||||
if channel_name.is_empty():
|
||||
dictionary[channel_name] = {
|
||||
'volume': channel_defaults[i].volume.get_value(),
|
||||
'audio_bus': channel_defaults[i].audio_bus.current_value,
|
||||
'fade_length': 0.0,
|
||||
'loop': false,
|
||||
}
|
||||
else:
|
||||
dictionary[channel_name] = {
|
||||
'volume': channel_defaults[i].volume.get_value(),
|
||||
'audio_bus': channel_defaults[i].audio_bus.current_value,
|
||||
'fade_length': channel_defaults[i].fade_length.get_value(),
|
||||
'loop': channel_defaults[i].loop.button_pressed,
|
||||
}
|
||||
|
||||
ProjectSettings.set_setting(CHANNEL_DEFAULTS, dictionary)
|
||||
ProjectSettings.save()
|
||||
|
||||
|
||||
func _on_add_channel_defaults_pressed() -> void:
|
||||
var added_node := add_channel_defaults('new_channel_name', 0.0, '', 0.0, true)
|
||||
if added_node:
|
||||
added_node.take_autofocus()
|
||||
_revalidate_channel_names = true
|
||||
revalidate_channel_names.call_deferred()
|
||||
|
||||
|
||||
func add_channel_defaults(channel_name: String, volume: float, audio_bus: String, fade_length: float, loop: bool) -> Control:
|
||||
var info := {}
|
||||
|
||||
for i in %AudioChannelDefaultRow.get_children():
|
||||
var x := i.duplicate()
|
||||
%AudioChannelDefaults.add_child(x)
|
||||
info[i.name] = x
|
||||
|
||||
|
||||
if channel_name.is_empty():
|
||||
var channel_label := Label.new()
|
||||
channel_label.text = &"One-Shot SFX"
|
||||
channel_label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
|
||||
%AudioChannelDefaults.add_child(channel_label)
|
||||
%AudioChannelDefaults.move_child(channel_label, info.channel_name.get_index())
|
||||
info.channel_name.queue_free()
|
||||
info.channel_name = channel_label
|
||||
|
||||
var HintTooltip := preload("res://addons/dialogic/Editor/Common/hint_tooltip_icon.tscn")
|
||||
var fade_hint := HintTooltip.instantiate()
|
||||
fade_hint.hint_text = "Fading is disabled for this channel."
|
||||
%AudioChannelDefaults.add_child(fade_hint)
|
||||
%AudioChannelDefaults.move_child(fade_hint, info.fade_length.get_index())
|
||||
info.fade_length.queue_free()
|
||||
info.fade_length = fade_hint
|
||||
|
||||
var loop_hint := HintTooltip.instantiate()
|
||||
loop_hint.hint_text = "Looping is disabled for this channel."
|
||||
%AudioChannelDefaults.add_child(loop_hint)
|
||||
%AudioChannelDefaults.move_child(loop_hint, info.loop.get_index())
|
||||
info.loop.queue_free()
|
||||
info.loop = loop_hint
|
||||
|
||||
info.delete.disabled = true
|
||||
|
||||
else:
|
||||
info.channel_name.suggestions_func = get_audio_channel_suggestions
|
||||
info.channel_name.validation_func = validate_channel_names.bind(info.channel_name)
|
||||
info.channel_name.set_value(channel_name)
|
||||
|
||||
info.fade_length.set_value(fade_length)
|
||||
|
||||
info.loop.set_pressed_no_signal(loop)
|
||||
|
||||
info.audio_bus.suggestions_func = DialogicUtil.get_audio_bus_suggestions
|
||||
info.audio_bus.set_value(audio_bus)
|
||||
|
||||
info.delete.icon = get_theme_icon(&"Remove", &"EditorIcons")
|
||||
|
||||
channel_defaults[len(channel_defaults)] = info
|
||||
return info['channel_name']
|
||||
|
||||
|
||||
func _on_remove_channel_defaults_pressed(index: int) -> void:
|
||||
for key in channel_defaults[index]:
|
||||
channel_defaults[index][key].queue_free()
|
||||
channel_defaults.erase(index)
|
||||
|
||||
|
||||
func get_audio_channel_suggestions(search_text:String) -> Dictionary:
|
||||
var suggestions := DialogicUtil.get_audio_channel_suggestions(search_text)
|
||||
|
||||
for i in channel_defaults.values():
|
||||
if i.channel_name is DialogicVisualEditorField:
|
||||
suggestions.erase(i.channel_name.current_value)
|
||||
|
||||
for key in suggestions.keys():
|
||||
suggestions[key].erase('tooltip')
|
||||
suggestions[key]['editor_icon'] = ["AudioStreamPlayer", "EditorIcons"]
|
||||
|
||||
return suggestions
|
||||
|
||||
|
||||
func revalidate_channel_names() -> void:
|
||||
_revalidate_channel_names = false
|
||||
for i in channel_defaults:
|
||||
if (is_instance_valid(channel_defaults[i].channel_name)
|
||||
and not channel_defaults[i].channel_name is Label):
|
||||
channel_defaults[i].channel_name.validate()
|
||||
|
||||
|
||||
func validate_channel_names(search_text: String, field_node: Control) -> Dictionary:
|
||||
var channel_cache = {}
|
||||
var result := {}
|
||||
var tooltips := []
|
||||
|
||||
if search_text.is_empty():
|
||||
result['error_tooltip'] = 'Must not be empty.'
|
||||
return result
|
||||
|
||||
if field_node:
|
||||
channel_cache[search_text] = [field_node]
|
||||
if field_node.current_value != search_text:
|
||||
_revalidate_channel_names = true
|
||||
revalidate_channel_names.call_deferred()
|
||||
|
||||
# Collect all channel names entered
|
||||
for i in channel_defaults:
|
||||
if (is_instance_valid(channel_defaults[i].channel_name)
|
||||
and not channel_defaults[i].channel_name is Label
|
||||
and channel_defaults[i].channel_name != field_node):
|
||||
var text := channel_defaults[i].channel_name.current_value as String
|
||||
if not channel_cache.has(text):
|
||||
channel_cache[text] = []
|
||||
|
||||
channel_cache[text].append(channel_defaults[i].channel_name)
|
||||
|
||||
# Check for duplicate names
|
||||
if channel_cache.has(search_text) and channel_cache[search_text].size() > 1:
|
||||
tooltips.append("Duplicate channel name.")
|
||||
|
||||
# Check for invalid characters
|
||||
result = DialogicUtil.validate_audio_channel_name(search_text)
|
||||
if result:
|
||||
tooltips.append(result.error_tooltip)
|
||||
result.error_tooltip = "\n".join(tooltips)
|
||||
elif not tooltips.is_empty():
|
||||
result['error_tooltip'] = "\n".join(tooltips)
|
||||
|
||||
return result
|
||||
#endregion
|
||||
1
addons/dialogic/Modules/Audio/settings_audio.gd.uid
Normal file
1
addons/dialogic/Modules/Audio/settings_audio.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cqyhm6offcitc
|
||||
113
addons/dialogic/Modules/Audio/settings_audio.tscn
Normal file
113
addons/dialogic/Modules/Audio/settings_audio.tscn
Normal file
@@ -0,0 +1,113 @@
|
||||
[gd_scene load_steps=6 format=3 uid="uid://c2qgetjc3mfo3"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cqyhm6offcitc" 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"]
|
||||
[ext_resource type="PackedScene" uid="uid://dpwhshre1n4t6" path="res://addons/dialogic/Editor/Events/Fields/field_options_dynamic.tscn" id="3_bx557"]
|
||||
[ext_resource type="PackedScene" uid="uid://kdpp3mibml33" path="res://addons/dialogic/Editor/Events/Fields/field_number.tscn" id="4_xfyvc"]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_m57ns"]
|
||||
content_margin_left = 4.0
|
||||
content_margin_top = 4.0
|
||||
content_margin_right = 4.0
|
||||
content_margin_bottom = 4.0
|
||||
bg_color = Color(1, 0.365, 0.365, 1)
|
||||
draw_center = false
|
||||
border_width_left = 2
|
||||
border_width_top = 2
|
||||
border_width_right = 2
|
||||
border_width_bottom = 2
|
||||
corner_detail = 1
|
||||
|
||||
[node name="Audio" type="VBoxContainer"]
|
||||
offset_right = 121.0
|
||||
offset_bottom = 58.0
|
||||
script = ExtResource("1_2iyyr")
|
||||
|
||||
[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
|
||||
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
|
||||
|
||||
[node name="HBoxContainer3" type="HBoxContainer" parent="."]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label" type="Label" parent="HBoxContainer3"]
|
||||
layout_mode = 2
|
||||
theme_type_variation = &"DialogicSettingsSection"
|
||||
text = "Audio Channel Defaults"
|
||||
|
||||
[node name="HintTooltip" parent="HBoxContainer3" instance=ExtResource("2_o1ban")]
|
||||
layout_mode = 2
|
||||
texture = null
|
||||
hint_text = "Default settings for named audio channels."
|
||||
|
||||
[node name="Panel" type="PanelContainer" parent="."]
|
||||
layout_mode = 2
|
||||
theme_override_styles/panel = SubResource("StyleBoxFlat_m57ns")
|
||||
|
||||
[node name="VBox" type="VBoxContainer" parent="Panel"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="AudioChannelDefaults" type="GridContainer" parent="Panel/VBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
columns = 6
|
||||
|
||||
[node name="AudioChannelDefaultRow" type="HBoxContainer" parent="Panel/VBox"]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
|
||||
[node name="channel_name" parent="Panel/VBox/AudioChannelDefaultRow" instance=ExtResource("3_bx557")]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
placeholder_text = "Enter Channel Name"
|
||||
mode = 3
|
||||
|
||||
[node name="volume" parent="Panel/VBox/AudioChannelDefaultRow" instance=ExtResource("4_xfyvc")]
|
||||
layout_mode = 2
|
||||
mode = 2
|
||||
min = -80.0
|
||||
max = 6.0
|
||||
suffix = "dB"
|
||||
|
||||
[node name="audio_bus" parent="Panel/VBox/AudioChannelDefaultRow" instance=ExtResource("3_bx557")]
|
||||
layout_mode = 2
|
||||
placeholder_text = "Master"
|
||||
mode = 2
|
||||
|
||||
[node name="fade_length" parent="Panel/VBox/AudioChannelDefaultRow" instance=ExtResource("4_xfyvc")]
|
||||
layout_mode = 2
|
||||
mode = 0
|
||||
enforce_step = false
|
||||
min = 0.0
|
||||
|
||||
[node name="loop" type="CheckButton" parent="Panel/VBox/AudioChannelDefaultRow"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="delete" type="Button" parent="Panel/VBox/AudioChannelDefaultRow"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Add" type="Button" parent="Panel/VBox"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 4
|
||||
text = "Add channel"
|
||||
|
||||
[connection signal="pressed" from="Panel/VBox/Add" to="." method="_on_add_channel_defaults_pressed"]
|
||||
284
addons/dialogic/Modules/Audio/subsystem_audio.gd
Normal file
284
addons/dialogic/Modules/Audio/subsystem_audio.gd
Normal file
@@ -0,0 +1,284 @@
|
||||
extends DialogicSubsystem
|
||||
## Subsystem for managing background audio and one-shot sound effects.
|
||||
##
|
||||
## This subsystem has many different helper methods for managing audio
|
||||
## in your timeline.
|
||||
## For instance, you can listen to audio changes via [signal audio_started].
|
||||
|
||||
|
||||
## Whenever a new audio event 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]
|
||||
## `channel` | [type String] | The channel name to play the audio on. [br]
|
||||
## `volume` | [type float] | The volume in `db` of the audio resource that will be set to the [AudioStreamPlayer]. [br]
|
||||
## `audio_bus` | [type String] | The audio bus name that the [AudioStreamPlayer] will use. [br]
|
||||
## `loop` | [type bool] | Whether the audio resource will loop or not once it finishes playing. [br]
|
||||
signal audio_started(info: Dictionary)
|
||||
|
||||
|
||||
## Audio node for holding audio players
|
||||
var audio_node := Node.new()
|
||||
## Sound node for holding sound players
|
||||
var one_shot_audio_node := Node.new()
|
||||
## Dictionary with info of all current audio channels
|
||||
var current_audio_channels: Dictionary = {}
|
||||
|
||||
#region STATE
|
||||
####################################################################################################
|
||||
|
||||
## Clears the state on this subsystem and stops all audio.
|
||||
func clear_game_state(_clear_flag := DialogicGameHandler.ClearFlags.FULL_CLEAR) -> void:
|
||||
stop_all_channels()
|
||||
stop_all_one_shot_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
|
||||
|
||||
# Pre Alpha 17 Converter
|
||||
_convert_state_info()
|
||||
|
||||
var info: Dictionary = dialogic.current_state_info.get("audio", {})
|
||||
|
||||
for channel_name in info.keys():
|
||||
if info[channel_name].path.is_empty():
|
||||
update_audio(channel_name)
|
||||
else:
|
||||
update_audio(channel_name, info[channel_name].path, info[channel_name].settings_overrides)
|
||||
|
||||
|
||||
## Pauses playing audio.
|
||||
func pause() -> void:
|
||||
for child in audio_node.get_children():
|
||||
child.stream_paused = true
|
||||
for child in one_shot_audio_node.get_children():
|
||||
child.stream_paused = true
|
||||
|
||||
|
||||
## Resumes playing audio.
|
||||
func resume() -> void:
|
||||
for child in audio_node.get_children():
|
||||
child.stream_paused = false
|
||||
for child in one_shot_audio_node.get_children():
|
||||
child.stream_paused = false
|
||||
|
||||
|
||||
func _on_dialogic_timeline_ended() -> void:
|
||||
if not dialogic.Styles.get_layout_node():
|
||||
clear_game_state()
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region MAIN METHODS
|
||||
####################################################################################################
|
||||
|
||||
func _ready() -> void:
|
||||
dialogic.timeline_ended.connect(_on_dialogic_timeline_ended)
|
||||
|
||||
audio_node.name = "Audio"
|
||||
add_child(audio_node)
|
||||
one_shot_audio_node.name = "OneShotAudios"
|
||||
add_child(one_shot_audio_node)
|
||||
|
||||
|
||||
## Plays the given file (or nothing) on the given channel.
|
||||
## No channel given defaults to the "One-Shot SFX" channel,
|
||||
## which does not save audio but can have multiple audios playing simultaneously.
|
||||
func update_audio(channel_name:= "", path := "", settings_overrides := {}) -> void:
|
||||
#volume := 0.0, audio_bus := "", fade_time := 0.0, loop := true, sync_channel := "") -> void:
|
||||
if not is_channel_playing(channel_name) and path.is_empty():
|
||||
return
|
||||
|
||||
## Determine audio settings
|
||||
## TODO use .merged after dropping 4.2 support
|
||||
var audio_settings: Dictionary = DialogicUtil.get_audio_channel_defaults().get(channel_name, {})
|
||||
audio_settings.merge(
|
||||
{"volume":0, "audio_bus":"", "fade_length":0.0, "loop":true, "sync_channel":""}
|
||||
)
|
||||
audio_settings.merge(settings_overrides, true)
|
||||
|
||||
## Handle previous audio on channel
|
||||
if is_channel_playing(channel_name):
|
||||
var prev_audio_node: AudioStreamPlayer = current_audio_channels[channel_name]
|
||||
prev_audio_node.name += "_Prev"
|
||||
if audio_settings.fade_length > 0.0:
|
||||
var fade_out_tween: Tween = create_tween()
|
||||
fade_out_tween.tween_method(
|
||||
interpolate_volume_linearly.bind(prev_audio_node),
|
||||
db_to_linear(prev_audio_node.volume_db),
|
||||
0.0,
|
||||
audio_settings.fade_length)
|
||||
fade_out_tween.tween_callback(prev_audio_node.queue_free)
|
||||
|
||||
else:
|
||||
prev_audio_node.queue_free()
|
||||
|
||||
## Set state
|
||||
if not dialogic.current_state_info.has('audio'):
|
||||
dialogic.current_state_info['audio'] = {}
|
||||
|
||||
if not path:
|
||||
dialogic.current_state_info['audio'].erase(channel_name)
|
||||
return
|
||||
|
||||
dialogic.current_state_info['audio'][channel_name] = {'path':path, 'settings_overrides':settings_overrides}
|
||||
audio_started.emit(dialogic.current_state_info['audio'][channel_name])
|
||||
|
||||
var new_player := AudioStreamPlayer.new()
|
||||
if channel_name:
|
||||
new_player.name = channel_name.validate_node_name()
|
||||
audio_node.add_child(new_player)
|
||||
else:
|
||||
new_player.name = "OneShotSFX"
|
||||
one_shot_audio_node.add_child(new_player)
|
||||
|
||||
var file := load(path)
|
||||
if file == null:
|
||||
printerr("[Dialogic] Audio file \"%s\" failed to load." % path)
|
||||
return
|
||||
|
||||
new_player.stream = load(path)
|
||||
|
||||
## Apply audio settings
|
||||
|
||||
## Volume & Fade
|
||||
if audio_settings.fade_length > 0.0:
|
||||
new_player.volume_db = linear_to_db(0.0)
|
||||
var fade_in_tween := create_tween()
|
||||
fade_in_tween.tween_method(
|
||||
interpolate_volume_linearly.bind(new_player),
|
||||
0.0,
|
||||
db_to_linear(audio_settings.volume),
|
||||
audio_settings.fade_length)
|
||||
|
||||
else:
|
||||
new_player.volume_db = audio_settings.volume
|
||||
|
||||
## Audio Bus
|
||||
new_player.bus = audio_settings.audio_bus
|
||||
|
||||
## Loop
|
||||
if "loop" in new_player.stream:
|
||||
new_player.stream.loop = audio_settings.loop
|
||||
elif "loop_mode" in new_player.stream:
|
||||
if audio_settings.loop:
|
||||
new_player.stream.loop_mode = AudioStreamWAV.LOOP_FORWARD
|
||||
new_player.stream.loop_begin = 0
|
||||
new_player.stream.loop_end = new_player.stream.mix_rate * new_player.stream.get_length()
|
||||
else:
|
||||
new_player.stream.loop_mode = AudioStreamWAV.LOOP_DISABLED
|
||||
|
||||
## Sync & start player
|
||||
if audio_settings.sync_channel and is_channel_playing(audio_settings.sync_channel):
|
||||
var play_position: float = current_audio_channels[audio_settings.sync_channel].get_playback_position()
|
||||
new_player.play(play_position)
|
||||
|
||||
# TODO Remove this once https://github.com/godotengine/godot/issues/18878 is fixed
|
||||
if new_player.stream is AudioStreamWAV and new_player.stream.format == AudioStreamWAV.FORMAT_IMA_ADPCM:
|
||||
printerr("[Dialogic] WAV files using Ima-ADPCM compression cannot be synced. Reimport the file using a different compression mode.")
|
||||
dialogic.print_debug_moment()
|
||||
else:
|
||||
new_player.play()
|
||||
|
||||
new_player.finished.connect(_on_audio_finished.bind(new_player, channel_name, path))
|
||||
|
||||
if channel_name:
|
||||
current_audio_channels[channel_name] = new_player
|
||||
|
||||
|
||||
## Returns `true` if any audio is playing on the given [param channel_name].
|
||||
func is_channel_playing(channel_name: String) -> bool:
|
||||
return (current_audio_channels.has(channel_name)
|
||||
and is_instance_valid(current_audio_channels[channel_name])
|
||||
and current_audio_channels[channel_name].is_playing())
|
||||
|
||||
|
||||
## Stops audio on all channels.
|
||||
func stop_all_channels(fade := 0.0) -> void:
|
||||
for channel_name in current_audio_channels.keys():
|
||||
update_audio(channel_name, '', {"fade_length":fade})
|
||||
|
||||
|
||||
### Stops all one-shot sounds.
|
||||
func stop_all_one_shot_sounds() -> void:
|
||||
for i in one_shot_audio_node.get_children():
|
||||
i.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: AudioStreamPlayer) -> 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_name].
|
||||
func is_channel_playing_file(file_path: String, channel_name: String) -> bool:
|
||||
return (is_channel_playing(channel_name)
|
||||
and current_audio_channels[channel_name].stream.resource_path == file_path)
|
||||
|
||||
|
||||
## Returns `true` if any channel is playing.
|
||||
func is_any_channel_playing() -> bool:
|
||||
for channel in current_audio_channels:
|
||||
if is_channel_playing(channel):
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
func _on_audio_finished(player: AudioStreamPlayer, channel_name: String, path: String) -> void:
|
||||
if current_audio_channels.has(channel_name) and current_audio_channels[channel_name] == player:
|
||||
current_audio_channels.erase(channel_name)
|
||||
player.queue_free()
|
||||
if dialogic.current_state_info.get('audio', {}).get(channel_name, {}).get('path', '') == path:
|
||||
dialogic.current_state_info['audio'].erase(channel_name)
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Pre Alpha 17 Conversion
|
||||
|
||||
func _convert_state_info() -> void:
|
||||
var info: Dictionary = dialogic.current_state_info.get("music", {})
|
||||
if info.is_empty():
|
||||
return
|
||||
|
||||
var new_info := {}
|
||||
if info.has("path"):
|
||||
# Pre Alpha 16 Save Data Conversion
|
||||
new_info['music'] = {
|
||||
"path":info.path,
|
||||
"settings_overrides": {
|
||||
"volume":info.volume,
|
||||
"audio_bus":info.audio_bus,
|
||||
"loop":info.loop}
|
||||
}
|
||||
|
||||
else:
|
||||
# Pre Alpha 17 Save Data Conversion
|
||||
for channel_id in info.keys():
|
||||
if info[channel_id].is_empty():
|
||||
continue
|
||||
|
||||
var channel_name = "music"
|
||||
if channel_id > 0:
|
||||
channel_name += str(channel_id + 1)
|
||||
new_info[channel_name] = {
|
||||
"path": info[channel_id].path,
|
||||
"settings_overrides":{
|
||||
'volume': info[channel_id].volume,
|
||||
'audio_bus': info[channel_id].audio_bus,
|
||||
'loop': info[channel_id].loop,
|
||||
}
|
||||
}
|
||||
|
||||
dialogic.current_state_info['audio'] = new_info
|
||||
dialogic.current_state_info.erase('music')
|
||||
|
||||
#endregion
|
||||
1
addons/dialogic/Modules/Audio/subsystem_audio.gd.uid
Normal file
1
addons/dialogic/Modules/Audio/subsystem_audio.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://do8vgqtp35d6w
|
||||
@@ -0,0 +1,31 @@
|
||||
extends DialogicBackground
|
||||
|
||||
## The default background scene.
|
||||
## Extend the DialogicBackground class to create your own background scene.
|
||||
|
||||
@onready var image_node: TextureRect = $Image
|
||||
@onready var color_node: ColorRect = $ColorRect
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
image_node.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
|
||||
image_node.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_COVERED
|
||||
|
||||
image_node.anchor_right = 1
|
||||
image_node.anchor_bottom = 1
|
||||
|
||||
|
||||
func _update_background(argument:String, _time:float) -> void:
|
||||
if argument.begins_with('res://'):
|
||||
image_node.texture = load(argument)
|
||||
color_node.color = Color.TRANSPARENT
|
||||
elif argument.begins_with('user://'):
|
||||
var ext_image = Image.load_from_file(argument)
|
||||
image_node.texture = ImageTexture.create_from_image(ext_image)
|
||||
color_node.color = Color.TRANSPARENT
|
||||
elif argument.is_valid_html_color():
|
||||
image_node.texture = null
|
||||
color_node.color = Color(argument, 1)
|
||||
else:
|
||||
image_node.texture = null
|
||||
color_node.color = Color.from_string(argument, Color.TRANSPARENT)
|
||||
@@ -0,0 +1 @@
|
||||
uid://ci7s5odxo7543
|
||||
@@ -0,0 +1,29 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://cl6g6ymkhjven"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://ci7s5odxo7543" path="res://addons/dialogic/Modules/Background/DefaultBackgroundScene/default_background.gd" id="1_nkdrp"]
|
||||
|
||||
[node name="DefaultBackground" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_nkdrp")
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="Image" type="TextureRect" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
mouse_filter = 0
|
||||
@@ -0,0 +1,7 @@
|
||||
extends "res://addons/dialogic/Modules/Background/Transitions/simple_push_transitions.gd"
|
||||
|
||||
func _fade() -> void:
|
||||
var shader := setup_push_shader()
|
||||
shader.set_shader_parameter('final_offset', Vector2.DOWN)
|
||||
tween_shader_progress().set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_IN_OUT)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
uid://blaaa6obvwknl
|
||||
@@ -0,0 +1,7 @@
|
||||
extends "res://addons/dialogic/Modules/Background/Transitions/simple_push_transitions.gd"
|
||||
|
||||
func _fade() -> void:
|
||||
var shader := setup_push_shader()
|
||||
shader.set_shader_parameter('final_offset', Vector2.LEFT)
|
||||
tween_shader_progress().set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_IN_OUT)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
uid://6f7qewx7aga
|
||||
@@ -0,0 +1,7 @@
|
||||
extends "res://addons/dialogic/Modules/Background/Transitions/simple_push_transitions.gd"
|
||||
|
||||
func _fade() -> void:
|
||||
var shader := setup_push_shader()
|
||||
shader.set_shader_parameter('final_offset', Vector2.RIGHT)
|
||||
tween_shader_progress().set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_IN_OUT)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
uid://m3anyujei6ro
|
||||
@@ -0,0 +1,7 @@
|
||||
extends "res://addons/dialogic/Modules/Background/Transitions/simple_push_transitions.gd"
|
||||
|
||||
func _fade() -> void:
|
||||
var shader := setup_push_shader()
|
||||
shader.set_shader_parameter('final_offset', Vector2.UP)
|
||||
tween_shader_progress().set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_IN_OUT)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
uid://dnuvmtb036bi3
|
||||
@@ -0,0 +1,13 @@
|
||||
extends DialogicBackgroundTransition
|
||||
|
||||
|
||||
func _fade() -> void:
|
||||
var shader := set_shader()
|
||||
shader.set_shader_parameter("wipe_texture", load(this_folder.path_join("simple_fade.tres")))
|
||||
|
||||
shader.set_shader_parameter("feather", 1)
|
||||
|
||||
shader.set_shader_parameter("previous_background", prev_texture)
|
||||
shader.set_shader_parameter("next_background", next_texture)
|
||||
|
||||
tween_shader_progress()
|
||||
@@ -0,0 +1 @@
|
||||
uid://bed16hbuh4atn
|
||||
@@ -0,0 +1,8 @@
|
||||
[gd_resource type="GradientTexture2D" load_steps=2 format=3 uid="uid://qak7mr560k0i"]
|
||||
|
||||
[sub_resource type="Gradient" id="Gradient_skd6w"]
|
||||
offsets = PackedFloat32Array(1)
|
||||
colors = PackedColorArray(0.423651, 0.423651, 0.423651, 1)
|
||||
|
||||
[resource]
|
||||
gradient = SubResource("Gradient_skd6w")
|
||||
@@ -0,0 +1,8 @@
|
||||
extends "res://addons/dialogic/Modules/Background/Transitions/simple_swipe_transitions.gd"
|
||||
|
||||
func _fade() -> void:
|
||||
var shader := setup_swipe_shader()
|
||||
var texture: GradientTexture2D = shader.get_shader_parameter('wipe_texture')
|
||||
texture.fill_from = Vector2.DOWN
|
||||
texture.fill_to = Vector2.RIGHT
|
||||
tween_shader_progress()
|
||||
@@ -0,0 +1 @@
|
||||
uid://ctoc2p12vahcc
|
||||
@@ -0,0 +1,10 @@
|
||||
extends "res://addons/dialogic/Modules/Background/Transitions/simple_swipe_transitions.gd"
|
||||
|
||||
func _fade() -> void:
|
||||
var shader := setup_swipe_shader()
|
||||
var texture: GradientTexture2D = shader.get_shader_parameter('wipe_texture')
|
||||
|
||||
texture.fill_from = Vector2.ZERO
|
||||
texture.fill_to = Vector2.RIGHT
|
||||
|
||||
tween_shader_progress()
|
||||
@@ -0,0 +1 @@
|
||||
uid://dknape5pbyevn
|
||||
@@ -0,0 +1,8 @@
|
||||
extends "res://addons/dialogic/Modules/Background/Transitions/simple_swipe_transitions.gd"
|
||||
|
||||
func _fade() -> void:
|
||||
var shader := setup_swipe_shader()
|
||||
var texture: GradientTexture2D = shader.get_shader_parameter('wipe_texture')
|
||||
texture.fill_from = Vector2.RIGHT
|
||||
texture.fill_to = Vector2.ZERO
|
||||
tween_shader_progress()
|
||||
@@ -0,0 +1 @@
|
||||
uid://dwhod30peco4c
|
||||
@@ -0,0 +1,57 @@
|
||||
class_name DialogicBackgroundTransition
|
||||
extends Node
|
||||
|
||||
## Helper
|
||||
var this_folder: String = get_script().resource_path.get_base_dir()
|
||||
|
||||
|
||||
## Set before _fade() is called, will be the root node of the previous bg scene.
|
||||
var prev_scene: Node
|
||||
## Set before _fade() is called, will be the viewport texture of the previous bg scene.
|
||||
var prev_texture: ViewportTexture
|
||||
|
||||
## Set before _fade() is called, will be the root node of the upcoming bg scene.
|
||||
var next_scene: Node
|
||||
## Set before _fade() is called, will be the viewport texture of the upcoming bg scene.
|
||||
var next_texture: ViewportTexture
|
||||
|
||||
## Set before _fade() is called, will be the requested time for the fade
|
||||
var time: float
|
||||
|
||||
## Set before _fade() is called, will be the background holder (TextureRect)
|
||||
var bg_holder: DialogicNode_BackgroundHolder
|
||||
|
||||
|
||||
@warning_ignore("unused_signal") # Used by scripts inheriting this class
|
||||
signal transition_finished
|
||||
|
||||
|
||||
## To be overridden by transitions
|
||||
func _fade() -> void:
|
||||
pass
|
||||
|
||||
|
||||
func set_shader(path_to_shader:String=DialogicUtil.get_module_path('Background').path_join("Transitions/default_transition_shader.gdshader")) -> ShaderMaterial:
|
||||
if bg_holder:
|
||||
if path_to_shader.is_empty():
|
||||
bg_holder.material = null
|
||||
bg_holder.color = Color.TRANSPARENT
|
||||
return null
|
||||
bg_holder.material = ShaderMaterial.new()
|
||||
bg_holder.material.shader = load(path_to_shader)
|
||||
return bg_holder.material
|
||||
return null
|
||||
|
||||
|
||||
func tween_shader_progress(_progress_parameter:="progress") -> PropertyTweener:
|
||||
if !bg_holder:
|
||||
return
|
||||
|
||||
if !bg_holder.material is ShaderMaterial:
|
||||
return
|
||||
|
||||
bg_holder.material.set_shader_parameter("progress", 0.0)
|
||||
var tween := create_tween()
|
||||
var tweener := tween.tween_property(bg_holder, "material:shader_parameter/progress", 1.0, time).from(0.0)
|
||||
tween.tween_callback(emit_signal.bind('transition_finished'))
|
||||
return tweener
|
||||
@@ -0,0 +1 @@
|
||||
uid://cf47aj5eivati
|
||||
@@ -0,0 +1,36 @@
|
||||
shader_type canvas_item;
|
||||
|
||||
// Indicates how far the transition is (0 start, 1 end).
|
||||
uniform float progress : hint_range(0.0, 1.0);
|
||||
// The previous background, transparent if there was none.
|
||||
uniform sampler2D previous_background : source_color, hint_default_transparent;
|
||||
// The next background, transparent if there is none.
|
||||
uniform sampler2D next_background : source_color, hint_default_transparent;
|
||||
|
||||
// The texture used to determine how far along the progress has to be for bending in the new background.
|
||||
uniform sampler2D wipe_texture : source_color;
|
||||
// The size of the trailing smear of the transition.
|
||||
uniform float feather : hint_range(0.0, 1.0, 0.0001) = 0.1;
|
||||
// Determines if the wipe texture should keep it's aspect ratio when scaled to the screen's size.
|
||||
uniform bool keep_aspect_ratio = false;
|
||||
|
||||
void fragment() {
|
||||
vec2 frag_coord = UV;
|
||||
if(keep_aspect_ratio) {
|
||||
vec2 ratio = (SCREEN_PIXEL_SIZE.x > SCREEN_PIXEL_SIZE.y) // determine how to scale
|
||||
? vec2(SCREEN_PIXEL_SIZE.y / SCREEN_PIXEL_SIZE.x, 1) // fit to width
|
||||
: vec2(1, SCREEN_PIXEL_SIZE.x / SCREEN_PIXEL_SIZE.y); // fit to height
|
||||
|
||||
frag_coord *= ratio;
|
||||
frag_coord += ((vec2(1,1) - ratio) / 2.0);
|
||||
}
|
||||
|
||||
// get the blend factor between the previous and next background.
|
||||
float alpha = (texture(wipe_texture, frag_coord).r) - progress;
|
||||
float blend_factor = 1. - smoothstep(0., feather, alpha + (feather * (1. -progress)));
|
||||
|
||||
vec4 old_frag = texture(previous_background, UV);
|
||||
vec4 new_frag = texture(next_background, UV);
|
||||
|
||||
COLOR = mix(old_frag, new_frag, blend_factor);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://clabj6a02r7iv
|
||||
@@ -0,0 +1,17 @@
|
||||
shader_type canvas_item;
|
||||
|
||||
uniform vec2 final_offset = vec2(0,-1);
|
||||
uniform float progress: hint_range(0.0, 1.0);
|
||||
uniform sampler2D previous_background: source_color, hint_default_transparent;
|
||||
uniform sampler2D next_background: source_color, hint_default_transparent;
|
||||
|
||||
|
||||
void fragment() {
|
||||
vec2 uv = UV + final_offset * progress*vec2(-1, -1);
|
||||
|
||||
if (uv.x < 1.0 && uv.x > 0.0 && uv.y < 1.0 && uv.y > 0.0){
|
||||
COLOR = texture(previous_background, uv, 1);
|
||||
} else {
|
||||
COLOR = texture(next_background, uv-final_offset*vec2(-1,-1));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://cuj1xsi7d7r5y
|
||||
@@ -0,0 +1,9 @@
|
||||
extends DialogicBackgroundTransition
|
||||
|
||||
func setup_push_shader() -> ShaderMaterial:
|
||||
var shader := set_shader(DialogicUtil.get_module_path('Background').path_join("Transitions/push_transition_shader.gdshader"))
|
||||
|
||||
shader.set_shader_parameter("previous_background", prev_texture)
|
||||
shader.set_shader_parameter("next_background", next_texture)
|
||||
|
||||
return shader
|
||||
@@ -0,0 +1 @@
|
||||
uid://bue1pfm6eu7ww
|
||||
@@ -0,0 +1,7 @@
|
||||
[gd_resource type="GradientTexture2D" load_steps=2 format=3 uid="uid://cweb3y3xc4uw0"]
|
||||
|
||||
[sub_resource type="Gradient" id="Gradient_skd6w"]
|
||||
colors = PackedColorArray(0, 0, 0, 1, 0.991164, 0.991164, 0.991164, 1)
|
||||
|
||||
[resource]
|
||||
gradient = SubResource("Gradient_skd6w")
|
||||
@@ -0,0 +1,14 @@
|
||||
extends DialogicBackgroundTransition
|
||||
|
||||
func setup_swipe_shader() -> ShaderMaterial:
|
||||
var shader := set_shader()
|
||||
shader.set_shader_parameter("wipe_texture", load(
|
||||
DialogicUtil.get_module_path('Background').path_join("Transitions/simple_swipe_gradient.tres")
|
||||
))
|
||||
|
||||
shader.set_shader_parameter("feather", 0.3)
|
||||
|
||||
shader.set_shader_parameter("previous_background", prev_texture)
|
||||
shader.set_shader_parameter("next_background", next_texture)
|
||||
|
||||
return shader
|
||||
@@ -0,0 +1 @@
|
||||
uid://bkj1kaqcq5208
|
||||
38
addons/dialogic/Modules/Background/dialogic_background.gd
Normal file
38
addons/dialogic/Modules/Background/dialogic_background.gd
Normal file
@@ -0,0 +1,38 @@
|
||||
extends Node
|
||||
class_name DialogicBackground
|
||||
|
||||
## This is the base class for dialogic backgrounds.
|
||||
## Extend it and override it's methods when you create a custom background.
|
||||
## You can take a look at the default background to get an idea of how it's working.
|
||||
|
||||
|
||||
## The subviewport container that holds this background. Set when instanced.
|
||||
var viewport_container: SubViewportContainer
|
||||
## The viewport that holds this background. Set when instanced.
|
||||
var viewport: SubViewport
|
||||
|
||||
|
||||
## Load the new background in here.
|
||||
## The time argument is given for when [_should_do_background_update] returns true
|
||||
## (then you have to do a transition in here)
|
||||
func _update_background(_argument:String, _time:float) -> void:
|
||||
pass
|
||||
|
||||
|
||||
## If a background event with this scene is encountered while this background is used,
|
||||
## this decides whether to create a new instance and call fade_out or just call [_update_background] # on this scene. Default is false
|
||||
func _should_do_background_update(_argument:String) -> bool:
|
||||
return false
|
||||
|
||||
|
||||
## Called by dialogic when first created.
|
||||
## If you return false (by default) it will attempt to animate the "modulate" property.
|
||||
func _custom_fade_in(_time:float) -> bool:
|
||||
return false
|
||||
|
||||
|
||||
## Called by dialogic before removing (done by dialogic).
|
||||
## If you return false (by default) it will attempt to animate the "modulate" property.
|
||||
func _custom_fade_out(_time:float) -> bool:
|
||||
return false
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
uid://blsjcvm6gvd78
|
||||
164
addons/dialogic/Modules/Background/event_background.gd
Normal file
164
addons/dialogic/Modules/Background/event_background.gd
Normal file
@@ -0,0 +1,164 @@
|
||||
@tool
|
||||
class_name DialogicBackgroundEvent
|
||||
extends DialogicEvent
|
||||
|
||||
## Event to show scenes in the background and switch between them.
|
||||
|
||||
### Settings
|
||||
|
||||
## The scene to use. If empty, this will default to the DefaultBackground.gd scene.
|
||||
## This scene supports images and fading.
|
||||
## If you set it to a scene path, then that scene will be instanced.
|
||||
## Learn more about custom backgrounds in the Subsystem_Background.gd docs.
|
||||
var scene := ""
|
||||
## The argument that is passed to the background scene.
|
||||
## For the default scene it's the path to the image to show.
|
||||
var argument := "":
|
||||
set(value):
|
||||
if argument != value:
|
||||
argument = value
|
||||
ui_update_needed.emit()
|
||||
## The time the fade animation will take. Leave at 0 for instant change.
|
||||
var fade: float = 0.0
|
||||
## Name of the transition to use.
|
||||
var transition := ""
|
||||
|
||||
## Helpers for visual editor
|
||||
enum ArgumentTypes {IMAGE, CUSTOM}
|
||||
var _arg_type := ArgumentTypes.IMAGE :
|
||||
get:
|
||||
if argument.begins_with("res://"):
|
||||
return ArgumentTypes.IMAGE
|
||||
else:
|
||||
return _arg_type
|
||||
set(value):
|
||||
if value == ArgumentTypes.CUSTOM:
|
||||
if argument.begins_with("res://"):
|
||||
argument = " "+argument
|
||||
_arg_type = value
|
||||
|
||||
enum SceneTypes {DEFAULT, CUSTOM}
|
||||
var _scene_type := SceneTypes.DEFAULT :
|
||||
get:
|
||||
if scene.is_empty():
|
||||
return _scene_type
|
||||
else:
|
||||
return SceneTypes.CUSTOM
|
||||
set(value):
|
||||
if value == SceneTypes.DEFAULT:
|
||||
scene = ""
|
||||
_scene_type = value
|
||||
|
||||
#region EXECUTION
|
||||
################################################################################
|
||||
|
||||
func _execute() -> void:
|
||||
var final_fade_duration := fade
|
||||
|
||||
if dialogic.Inputs.auto_skip.enabled:
|
||||
var time_per_event: float = dialogic.Inputs.auto_skip.time_per_event
|
||||
final_fade_duration = min(fade, time_per_event)
|
||||
|
||||
dialogic.Backgrounds.update_background(scene, argument, final_fade_duration, transition)
|
||||
|
||||
finish()
|
||||
|
||||
#endregion
|
||||
|
||||
#region INITIALIZE
|
||||
################################################################################
|
||||
|
||||
func _init() -> void:
|
||||
event_name = "Background"
|
||||
set_default_color('Color8')
|
||||
event_category = "Visuals"
|
||||
event_sorting_index = 0
|
||||
|
||||
#endregion
|
||||
|
||||
#region SAVE & LOAD
|
||||
################################################################################
|
||||
|
||||
func get_shortcode() -> String:
|
||||
return "background"
|
||||
|
||||
|
||||
func get_shortcode_parameters() -> Dictionary:
|
||||
return {
|
||||
#param_name : property_info
|
||||
"scene" : {"property": "scene", "default": "", "ext_file":true},
|
||||
"arg" : {"property": "argument", "default": "", "ext_file":true},
|
||||
"fade" : {"property": "fade", "default": 0},
|
||||
"transition" : {"property": "transition", "default": "",
|
||||
"suggestions": get_transition_suggestions},
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region EDITOR REPRESENTATION
|
||||
################################################################################
|
||||
|
||||
func build_event_editor() -> void:
|
||||
add_header_edit('_scene_type', ValueType.FIXED_OPTIONS, {
|
||||
'left_text' :'Show',
|
||||
'options': [
|
||||
{
|
||||
'label': 'Background',
|
||||
'value': SceneTypes.DEFAULT,
|
||||
'icon': ["GuiRadioUnchecked", "EditorIcons"]
|
||||
},
|
||||
{
|
||||
'label': 'Custom Scene',
|
||||
'value': SceneTypes.CUSTOM,
|
||||
'icon': ["PackedScene", "EditorIcons"]
|
||||
}
|
||||
]})
|
||||
add_header_label("with image", "_scene_type == SceneTypes.DEFAULT")
|
||||
add_header_edit("scene", ValueType.FILE,
|
||||
{'file_filter':'*.tscn, *.scn; Scene Files',
|
||||
'placeholder': "Custom scene",
|
||||
'editor_icon': ["PackedScene", "EditorIcons"],
|
||||
}, '_scene_type == SceneTypes.CUSTOM')
|
||||
add_header_edit('_arg_type', ValueType.FIXED_OPTIONS, {
|
||||
'left_text' : 'with',
|
||||
'options': [
|
||||
{
|
||||
'label': 'Image',
|
||||
'value': ArgumentTypes.IMAGE,
|
||||
'icon': ["Image", "EditorIcons"]
|
||||
},
|
||||
{
|
||||
'label': 'Custom Argument',
|
||||
'value': ArgumentTypes.CUSTOM,
|
||||
'icon': ["String", "EditorIcons"]
|
||||
}
|
||||
], "symbol_only": true}, "_scene_type == SceneTypes.CUSTOM")
|
||||
add_header_edit('argument', ValueType.FILE,
|
||||
{'file_filter':'*.jpg, *.jpeg, *.png, *.webp, *.tga, *svg, *.bmp, *.dds, *.exr, *.hdr; Supported Image Files',
|
||||
'placeholder': "No Image",
|
||||
'editor_icon': ["Image", "EditorIcons"],
|
||||
},
|
||||
'_arg_type == ArgumentTypes.IMAGE or _scene_type == SceneTypes.DEFAULT')
|
||||
add_header_edit('argument', ValueType.SINGLELINE_TEXT, {}, '_arg_type == ArgumentTypes.CUSTOM')
|
||||
|
||||
add_body_edit("argument", ValueType.IMAGE_PREVIEW, {'left_text':'Preview:'},
|
||||
'(_arg_type == ArgumentTypes.IMAGE or _scene_type == SceneTypes.DEFAULT) and !argument.is_empty()')
|
||||
add_body_line_break('(_arg_type == ArgumentTypes.IMAGE or _scene_type == SceneTypes.DEFAULT) and !argument.is_empty()')
|
||||
|
||||
add_body_edit("transition", ValueType.DYNAMIC_OPTIONS,
|
||||
{'left_text':'Transition:',
|
||||
'empty_text':'Simple Fade',
|
||||
'suggestions_func':get_transition_suggestions,
|
||||
'editor_icon':["PopupMenu", "EditorIcons"]})
|
||||
add_body_edit("fade", ValueType.NUMBER, {'left_text':'Fade time:'})
|
||||
|
||||
|
||||
func get_transition_suggestions(_filter:String="") -> Dictionary:
|
||||
var transitions := DialogicResourceUtil.list_special_resources("BackgroundTransition")
|
||||
var suggestions := {}
|
||||
for i in transitions:
|
||||
suggestions[DialogicUtil.pretty_name(i)] = {'value': DialogicUtil.pretty_name(i), 'editor_icon': ["PopupMenu", "EditorIcons"]}
|
||||
return suggestions
|
||||
|
||||
#endregion
|
||||
@@ -0,0 +1 @@
|
||||
uid://sioj2uwexnwx
|
||||
BIN
addons/dialogic/Modules/Background/icon.png
Normal file
BIN
addons/dialogic/Modules/Background/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 512 B |
40
addons/dialogic/Modules/Background/icon.png.import
Normal file
40
addons/dialogic/Modules/Background/icon.png.import
Normal file
@@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://517mp8gfj811"
|
||||
path="res://.godot/imported/icon.png-cab4c78f59b171335e340ba590cf5991.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/dialogic/Modules/Background/icon.png"
|
||||
dest_files=["res://.godot/imported/icon.png-cab4c78f59b171335e340ba590cf5991.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
|
||||
13
addons/dialogic/Modules/Background/index.gd
Normal file
13
addons/dialogic/Modules/Background/index.gd
Normal file
@@ -0,0 +1,13 @@
|
||||
@tool
|
||||
extends DialogicIndexer
|
||||
|
||||
|
||||
func _get_events() -> Array:
|
||||
return [this_folder.path_join('event_background.gd')]
|
||||
|
||||
func _get_subsystems() -> Array:
|
||||
return [{'name':'Backgrounds', 'script':this_folder.path_join('subsystem_backgrounds.gd')}]
|
||||
|
||||
|
||||
func _get_special_resources() -> Dictionary:
|
||||
return {&"BackgroundTransition":list_special_resources("Transitions/Defaults", ".gd")}
|
||||
1
addons/dialogic/Modules/Background/index.gd.uid
Normal file
1
addons/dialogic/Modules/Background/index.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bj085abnvwkyh
|
||||
@@ -0,0 +1,6 @@
|
||||
class_name DialogicNode_BackgroundHolder
|
||||
extends ColorRect
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
add_to_group('dialogic_background_holders')
|
||||
@@ -0,0 +1 @@
|
||||
uid://oxcjhq2817c7
|
||||
194
addons/dialogic/Modules/Background/subsystem_backgrounds.gd
Normal file
194
addons/dialogic/Modules/Background/subsystem_backgrounds.gd
Normal file
@@ -0,0 +1,194 @@
|
||||
extends DialogicSubsystem
|
||||
## Subsystem for managing backgrounds.
|
||||
##
|
||||
## This subsystem has many different helper methods for managing backgrounds.
|
||||
## For instance, you can listen to background changes via
|
||||
## [signal background_changed].
|
||||
|
||||
|
||||
## Whenever a new background is set, this signal is emitted and contains a
|
||||
## dictionary with the following keys: [br]
|
||||
## [br]
|
||||
## Key | Value Type | Value [br]
|
||||
## ----------- | ------------- | ----- [br]
|
||||
## `scene` | [type String] | The scene path of the new background. [br]
|
||||
## `argument` | [type String] | Information given to the background on its update routine. [br]
|
||||
## `fade_time` | [type float] | The time the background may take to transition in. [br]
|
||||
## `same_scene`| [type bool] | If the new background uses the same Godot scene. [br]
|
||||
signal background_changed(info: Dictionary)
|
||||
|
||||
## The default background scene Dialogic will use.
|
||||
var default_background_scene: PackedScene = load(get_script().resource_path.get_base_dir().path_join('DefaultBackgroundScene/default_background.tscn'))
|
||||
## The default transition Dialogic will use.
|
||||
var default_transition: String = get_script().resource_path.get_base_dir().path_join("Transitions/Defaults/simple_fade.gd")
|
||||
|
||||
|
||||
#region STATE
|
||||
####################################################################################################
|
||||
|
||||
## Empties the current background state.
|
||||
func clear_game_state(_clear_flag := DialogicGameHandler.ClearFlags.FULL_CLEAR) -> void:
|
||||
update_background()
|
||||
|
||||
## Loads the background state from the current state info.
|
||||
func load_game_state(_load_flag := LoadFlags.FULL_LOAD) -> void:
|
||||
update_background(dialogic.current_state_info.get('background_scene', ''), dialogic.current_state_info.get('background_argument', ''), 0.0, default_transition, true)
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region MAIN METHODS
|
||||
####################################################################################################
|
||||
|
||||
## Method that adds a given scene as child of the DialogicNode_BackgroundHolder.
|
||||
## It will call [_update_background()] on that scene with the given argument [argument].
|
||||
## It will call [_fade_in()] on that scene with the given fade time.
|
||||
## Will call fade_out on previous backgrounds scene.
|
||||
##
|
||||
## If the scene is the same as the last background you can bypass another instantiating
|
||||
## and use the same scene.
|
||||
## To do so implement [_should_do_background_update()] on the custom background scene.
|
||||
## Then [_update_background()] will be called directly on that previous scene.
|
||||
func update_background(scene := "", argument := "", fade_time := 0.0, transition_path:=default_transition, force := false) -> void:
|
||||
var background_holder: DialogicNode_BackgroundHolder
|
||||
if dialogic.has_subsystem('Styles'):
|
||||
background_holder = dialogic.Styles.get_first_node_in_layout('dialogic_background_holders')
|
||||
else:
|
||||
background_holder = get_tree().get_first_node_in_group('dialogic_background_holders')
|
||||
|
||||
var info := {'scene':scene, 'argument':argument, 'fade_time':fade_time, 'same_scene':false}
|
||||
if background_holder == null:
|
||||
background_changed.emit(info)
|
||||
return
|
||||
|
||||
|
||||
var bg_set := false
|
||||
|
||||
# First try just updating the existing scene.
|
||||
if scene == dialogic.current_state_info.get('background_scene', ''):
|
||||
|
||||
if not force and argument == dialogic.current_state_info.get('background_argument', ''):
|
||||
return
|
||||
|
||||
for old_bg in background_holder.get_children():
|
||||
if !old_bg.has_meta('node') or not old_bg.get_meta('node') is DialogicBackground:
|
||||
continue
|
||||
|
||||
var prev_bg_node: DialogicBackground = old_bg.get_meta('node')
|
||||
if prev_bg_node._should_do_background_update(argument):
|
||||
prev_bg_node._update_background(argument, fade_time)
|
||||
bg_set = true
|
||||
info['same_scene'] = true
|
||||
|
||||
dialogic.current_state_info['background_scene'] = scene
|
||||
dialogic.current_state_info['background_argument'] = argument
|
||||
|
||||
if bg_set:
|
||||
background_changed.emit(info)
|
||||
return
|
||||
|
||||
var old_viewport: SubViewportContainer = null
|
||||
if background_holder.has_meta('current_viewport'):
|
||||
old_viewport = background_holder.get_meta('current_viewport', null)
|
||||
|
||||
var new_viewport: SubViewportContainer
|
||||
if scene.ends_with('.tscn') and ResourceLoader.exists(scene):
|
||||
new_viewport = add_background_node(load(scene), background_holder)
|
||||
elif argument:
|
||||
new_viewport = add_background_node(default_background_scene, background_holder)
|
||||
else:
|
||||
new_viewport = null
|
||||
|
||||
# if there is still a transition going on, stop it now
|
||||
for node in get_children():
|
||||
if node is DialogicBackgroundTransition:
|
||||
node.queue_free()
|
||||
|
||||
|
||||
var trans_script: Script = load(DialogicResourceUtil.guess_special_resource("BackgroundTransition", transition_path, {"path":default_transition}).path)
|
||||
var trans_node := Node.new()
|
||||
trans_node.set_script(trans_script)
|
||||
trans_node = (trans_node as DialogicBackgroundTransition)
|
||||
trans_node.bg_holder = background_holder
|
||||
trans_node.time = fade_time
|
||||
|
||||
if old_viewport:
|
||||
old_viewport.name = "OldBackground"
|
||||
trans_node.prev_scene = old_viewport.get_meta('node', null)
|
||||
trans_node.prev_texture = old_viewport.get_child(0).get_texture()
|
||||
old_viewport.get_meta('node')._custom_fade_out(fade_time)
|
||||
old_viewport.hide()
|
||||
# TODO We have to call this again here because of https://github.com/godotengine/godot/issues/23729
|
||||
old_viewport.get_child(0).render_target_update_mode = SubViewport.UPDATE_ALWAYS
|
||||
trans_node.transition_finished.connect(old_viewport.queue_free)
|
||||
if new_viewport:
|
||||
new_viewport.name = "NewBackground"
|
||||
trans_node.next_scene = new_viewport.get_meta('node', null)
|
||||
trans_node.next_texture = new_viewport.get_child(0).get_texture()
|
||||
new_viewport.get_meta('node')._update_background(argument, fade_time)
|
||||
new_viewport.get_meta('node')._custom_fade_in(fade_time)
|
||||
else:
|
||||
background_holder.remove_meta('current_viewport')
|
||||
|
||||
add_child(trans_node)
|
||||
if fade_time == 0:
|
||||
trans_node.transition_finished.emit()
|
||||
_on_transition_finished(background_holder, trans_node)
|
||||
else:
|
||||
trans_node.transition_finished.connect(_on_transition_finished.bind(background_holder, trans_node))
|
||||
# We need to break this connection if the background_holder get's removed during the transition
|
||||
background_holder.tree_exited.connect(trans_node.disconnect.bind("transition_finished", _on_transition_finished))
|
||||
trans_node._fade()
|
||||
|
||||
background_changed.emit(info)
|
||||
|
||||
|
||||
func _on_transition_finished(background_node:DialogicNode_BackgroundHolder, transition_node:DialogicBackgroundTransition) -> void:
|
||||
if background_node.has_meta("current_viewport"):
|
||||
if background_node.get_meta("current_viewport").get_meta("node", null) == transition_node.next_scene:
|
||||
background_node.get_meta("current_viewport").show()
|
||||
background_node.material = null
|
||||
background_node.color = Color.TRANSPARENT
|
||||
transition_node.queue_free()
|
||||
|
||||
|
||||
## Adds sub-viewport with the given background scene as child to
|
||||
## Dialogic scene.
|
||||
func add_background_node(scene:PackedScene, parent:DialogicNode_BackgroundHolder) -> SubViewportContainer:
|
||||
var v_con := SubViewportContainer.new()
|
||||
var viewport := SubViewport.new()
|
||||
var b_scene := scene.instantiate()
|
||||
if not b_scene is DialogicBackground:
|
||||
printerr("[Dialogic] Given background scene was not of type DialogicBackground! Make sure the scene has a script that extends DialogicBackground.")
|
||||
v_con.queue_free()
|
||||
viewport.queue_free()
|
||||
b_scene.queue_free()
|
||||
return null
|
||||
|
||||
parent.add_child(v_con)
|
||||
v_con.hide()
|
||||
v_con.stretch = true
|
||||
v_con.size = parent.size
|
||||
v_con.set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||
|
||||
v_con.add_child(viewport)
|
||||
viewport.transparent_bg = true
|
||||
viewport.disable_3d = true
|
||||
viewport.render_target_update_mode = SubViewport.UPDATE_ALWAYS
|
||||
viewport.canvas_item_default_texture_filter = ProjectSettings.get_setting("rendering/textures/canvas_textures/default_texture_filter")
|
||||
|
||||
viewport.add_child(b_scene)
|
||||
b_scene.viewport = viewport
|
||||
b_scene.viewport_container = v_con
|
||||
|
||||
parent.set_meta('current_viewport', v_con)
|
||||
v_con.set_meta('node', b_scene)
|
||||
|
||||
return v_con
|
||||
|
||||
|
||||
## Whether a background is set.
|
||||
func has_background() -> bool:
|
||||
return !dialogic.current_state_info.get('background_scene', '').is_empty() or !dialogic.current_state_info.get('background_argument','').is_empty()
|
||||
|
||||
#endregion
|
||||
@@ -0,0 +1 @@
|
||||
uid://5uwbnllu1kfv
|
||||
235
addons/dialogic/Modules/Call/event_call.gd
Normal file
235
addons/dialogic/Modules/Call/event_call.gd
Normal file
@@ -0,0 +1,235 @@
|
||||
@tool
|
||||
class_name DialogicCallEvent
|
||||
extends DialogicEvent
|
||||
|
||||
## Event that allows calling a method in a node or autoload.
|
||||
|
||||
### Settings
|
||||
|
||||
## The name of the autoload to call the method on.
|
||||
var autoload_name := ""
|
||||
## The name of the method to call on the given autoload.
|
||||
var method := "":
|
||||
set(value):
|
||||
method = value
|
||||
if Engine.is_editor_hint():
|
||||
update_argument_info()
|
||||
check_arguments_and_update_warning()
|
||||
## A list of arguments to give to the call.
|
||||
var arguments := []:
|
||||
set(value):
|
||||
arguments = value
|
||||
if Engine.is_editor_hint():
|
||||
check_arguments_and_update_warning()
|
||||
|
||||
var _current_method_arg_hints := {'a':null, 'm':null, 'info':{}}
|
||||
|
||||
################################################################################
|
||||
## EXECUTION
|
||||
################################################################################
|
||||
|
||||
func _execute() -> void:
|
||||
var object: Object = null
|
||||
var obj_path := autoload_name
|
||||
var autoload: Node = dialogic.get_node('/root/'+obj_path.get_slice('.', 0))
|
||||
obj_path = obj_path.trim_prefix(obj_path.get_slice('.', 0)+'.')
|
||||
object = autoload
|
||||
if object:
|
||||
while obj_path:
|
||||
if obj_path.get_slice(".", 0) in object and object.get(obj_path.get_slice(".", 0)) is Object:
|
||||
object = object.get(obj_path.get_slice(".", 0))
|
||||
else:
|
||||
break
|
||||
obj_path = obj_path.trim_prefix(obj_path.get_slice('.', 0)+'.')
|
||||
|
||||
if object == null:
|
||||
printerr("[Dialogic] Call event failed: Unable to find autoload '",autoload_name,"'")
|
||||
finish()
|
||||
return
|
||||
|
||||
if object.has_method(method):
|
||||
var args := []
|
||||
for arg in arguments:
|
||||
if arg is String and arg.begins_with('@'):
|
||||
args.append(dialogic.Expressions.execute_string(arg.trim_prefix('@')))
|
||||
else:
|
||||
args.append(arg)
|
||||
dialogic.current_state = dialogic.States.WAITING
|
||||
await object.callv(method, args)
|
||||
dialogic.current_state = dialogic.States.IDLE
|
||||
else:
|
||||
printerr("[Dialogic] Call event failed: Autoload doesn't have the method '", method,"'.")
|
||||
|
||||
finish()
|
||||
|
||||
|
||||
################################################################################
|
||||
## INITIALIZE
|
||||
################################################################################
|
||||
|
||||
func _init() -> void:
|
||||
event_name = "Call"
|
||||
set_default_color('Color6')
|
||||
event_category = "Logic"
|
||||
event_sorting_index = 10
|
||||
|
||||
|
||||
################################################################################
|
||||
## SAVING/LOADING
|
||||
################################################################################
|
||||
|
||||
func to_text() -> String:
|
||||
var result := "do "
|
||||
if autoload_name:
|
||||
result += autoload_name
|
||||
if method:
|
||||
result += '.'+method
|
||||
if arguments.is_empty():
|
||||
result += '()'
|
||||
else:
|
||||
result += '('
|
||||
for i in arguments:
|
||||
if i is String and i.begins_with('@'):
|
||||
result += i.trim_prefix('@')
|
||||
else:
|
||||
result += var_to_str(i)
|
||||
result += ', '
|
||||
result = result.trim_suffix(', ')+')'
|
||||
return result
|
||||
|
||||
|
||||
func from_text(string:String) -> void:
|
||||
var result := RegEx.create_from_string(r"do (?<autoload>[^\(]*)\.((?<method>[^.(]*)(\((?<arguments>.*)\))?)?").search(string.strip_edges())
|
||||
if result:
|
||||
autoload_name = result.get_string('autoload')
|
||||
method = result.get_string('method')
|
||||
if result.get_string('arguments').is_empty():
|
||||
arguments = []
|
||||
else:
|
||||
var arr := []
|
||||
for i in result.get_string('arguments').split(','):
|
||||
i = i.strip_edges()
|
||||
if str_to_var(i) != null:
|
||||
arr.append(str_to_var(i))
|
||||
else:
|
||||
# Mark this as a complex expression
|
||||
arr.append("@"+i)
|
||||
arguments = arr
|
||||
|
||||
|
||||
func is_valid_event(string:String) -> bool:
|
||||
if string.strip_edges().begins_with("do"):
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
func get_shortcode_parameters() -> Dictionary:
|
||||
return {
|
||||
#param_name : property_info
|
||||
"autoload" : {"property": "autoload_name", "default": ""},
|
||||
"method" : {"property": "method", "default": ""},
|
||||
"args" : {"property": "arguments", "default": []},
|
||||
}
|
||||
|
||||
|
||||
################################################################################
|
||||
## EDITOR REPRESENTATION
|
||||
################################################################################
|
||||
|
||||
func build_event_editor() -> void:
|
||||
add_header_edit('autoload_name', ValueType.DYNAMIC_OPTIONS, {'left_text':'On autoload',
|
||||
'empty_text':'Autoload',
|
||||
'suggestions_func': DialogicUtil.get_autoload_suggestions,
|
||||
'editor_icon':["Node", "EditorIcons"]})
|
||||
add_header_edit('method', ValueType.DYNAMIC_OPTIONS, {'left_text':'call',
|
||||
'empty_text':'Method',
|
||||
'suggestions_func': get_method_suggestions,
|
||||
'editor_icon':["Callable", "EditorIcons"]}, 'autoload_name')
|
||||
add_body_edit('arguments', ValueType.ARRAY, {'left_text':'Arguments:'}, 'not autoload_name.is_empty() and not method.is_empty()')
|
||||
|
||||
|
||||
func get_method_suggestions(filter:="") -> Dictionary:
|
||||
return DialogicUtil.get_autoload_method_suggestions(filter, autoload_name)
|
||||
|
||||
|
||||
func update_argument_info() -> void:
|
||||
if autoload_name and method and not _current_method_arg_hints.is_empty() and (_current_method_arg_hints.a == autoload_name and _current_method_arg_hints.m == method):
|
||||
if !ResourceLoader.exists(ProjectSettings.get_setting('autoload/'+autoload_name, '').trim_prefix('*')):
|
||||
_current_method_arg_hints = {}
|
||||
return
|
||||
var script: Script = load(ProjectSettings.get_setting('autoload/'+autoload_name, '').trim_prefix('*'))
|
||||
for m in script.get_script_method_list():
|
||||
if m.name == method:
|
||||
_current_method_arg_hints = {'a':autoload_name, 'm':method, 'info':m}
|
||||
break
|
||||
|
||||
|
||||
func check_arguments_and_update_warning() -> void:
|
||||
if not _current_method_arg_hints.has("info") or _current_method_arg_hints.info.is_empty():
|
||||
ui_update_warning.emit()
|
||||
return
|
||||
|
||||
var idx := -1
|
||||
for arg in arguments:
|
||||
idx += 1
|
||||
if len(_current_method_arg_hints.info.args) <= idx:
|
||||
continue
|
||||
if _current_method_arg_hints.info.args[idx].type != 0:
|
||||
if _current_method_arg_hints.info.args[idx].type != typeof(arg):
|
||||
if arg is String and arg.begins_with('@'):
|
||||
continue
|
||||
var expected_type: String = ""
|
||||
match _current_method_arg_hints.info.args[idx].type:
|
||||
TYPE_BOOL: expected_type = "bool"
|
||||
TYPE_STRING: expected_type = "string"
|
||||
TYPE_FLOAT: expected_type = "float"
|
||||
TYPE_INT: expected_type = "int"
|
||||
_: expected_type = "something else"
|
||||
|
||||
ui_update_warning.emit('Argument '+ str(idx+1)+ ' ('+_current_method_arg_hints.info.args[idx].name+') has the wrong type (method expects '+expected_type+')!')
|
||||
return
|
||||
|
||||
if len(arguments) < len(_current_method_arg_hints.info.args)-len(_current_method_arg_hints.info.default_args):
|
||||
ui_update_warning.emit("The method is expecting at least "+str(len(_current_method_arg_hints.info.args)-len(_current_method_arg_hints.info.default_args))+ " arguments, but is given only "+str(len(arguments))+".")
|
||||
return
|
||||
elif len(arguments) > len(_current_method_arg_hints.info.args):
|
||||
ui_update_warning.emit("The method is expecting at most "+str(len(_current_method_arg_hints.info.args))+ " arguments, but is given "+str(len(arguments))+".")
|
||||
return
|
||||
ui_update_warning.emit()
|
||||
|
||||
####################### CODE COMPLETION ########################################
|
||||
################################################################################
|
||||
|
||||
func _get_code_completion(CodeCompletionHelper:Node, TextNode:TextEdit, line:String, _word:String, symbol:String) -> void:
|
||||
var autoloads := DialogicUtil.get_autoload_suggestions()
|
||||
var line_until_caret: String = CodeCompletionHelper.get_line_untill_caret(line)
|
||||
|
||||
if line.count(' ') == 1 and not '.' in line:
|
||||
for i in autoloads:
|
||||
TextNode.add_code_completion_option(CodeEdit.KIND_MEMBER, i, i+'.', event_color.lerp(TextNode.syntax_highlighter.normal_color, 0.3), TextNode.get_theme_icon("Node", "EditorIcons"))
|
||||
|
||||
elif (line_until_caret.ends_with(".") or symbol == "."):
|
||||
var some_autoload := line_until_caret.split(" ")[-1].split(".")[0]
|
||||
if some_autoload in autoloads:
|
||||
var methods := DialogicUtil.get_autoload_method_suggestions("", some_autoload)
|
||||
for i in methods.keys():
|
||||
TextNode.add_code_completion_option(CodeEdit.KIND_MEMBER, i, i+'(', event_color.lerp(TextNode.syntax_highlighter.normal_color, 0.3), TextNode.get_theme_icon("MemberMethod", "EditorIcons"))
|
||||
|
||||
|
||||
|
||||
func _get_start_code_completion(_CodeCompletionHelper:Node, TextNode:TextEdit) -> void:
|
||||
TextNode.add_code_completion_option(CodeEdit.KIND_PLAIN_TEXT, 'do', 'do ', event_color.lerp(TextNode.syntax_highlighter.normal_color, 0.3), _get_icon())
|
||||
|
||||
|
||||
#################### SYNTAX HIGHLIGHTING #######################################
|
||||
################################################################################
|
||||
|
||||
func _get_syntax_highlighting(Highlighter:SyntaxHighlighter, dict:Dictionary, line:String) -> Dictionary:
|
||||
dict[line.find('do')] = {"color":event_color.lerp(Highlighter.normal_color, 0.3)}
|
||||
dict[line.find('do')+2] = {"color":event_color.lerp(Highlighter.normal_color, 0.5)}
|
||||
|
||||
Highlighter.color_region(dict, Highlighter.normal_color, line, '(', ')')
|
||||
Highlighter.color_region(dict, Highlighter.string_color, line, '"', '"')
|
||||
Highlighter.color_word(dict, Highlighter.boolean_operator_color, line, 'true')
|
||||
Highlighter.color_word(dict, Highlighter.boolean_operator_color, line, 'false')
|
||||
return dict
|
||||
1
addons/dialogic/Modules/Call/event_call.gd.uid
Normal file
1
addons/dialogic/Modules/Call/event_call.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://uhicnbvlk57s
|
||||
BIN
addons/dialogic/Modules/Call/icon.png
Normal file
BIN
addons/dialogic/Modules/Call/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 554 B |
40
addons/dialogic/Modules/Call/icon.png.import
Normal file
40
addons/dialogic/Modules/Call/icon.png.import
Normal file
@@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://duvcdvtgy4h4b"
|
||||
path="res://.godot/imported/icon.png-12e444f0ed59397c7537943ea85b475c.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/dialogic/Modules/Call/icon.png"
|
||||
dest_files=["res://.godot/imported/icon.png-12e444f0ed59397c7537943ea85b475c.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
|
||||
6
addons/dialogic/Modules/Call/index.gd
Normal file
6
addons/dialogic/Modules/Call/index.gd
Normal file
@@ -0,0 +1,6 @@
|
||||
@tool
|
||||
extends DialogicIndexer
|
||||
|
||||
|
||||
func _get_events() -> Array:
|
||||
return [this_folder.path_join('event_call.gd')]
|
||||
1
addons/dialogic/Modules/Call/index.gd.uid
Normal file
1
addons/dialogic/Modules/Call/index.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bthb47untmgoo
|
||||
@@ -0,0 +1,16 @@
|
||||
extends DialogicAnimation
|
||||
|
||||
func animate() -> void:
|
||||
var tween := (node.create_tween() as Tween)
|
||||
tween.set_ease(Tween.EASE_OUT)
|
||||
tween.tween_property(node, 'position:y', base_position.y-node.get_viewport().size.y/10, time*0.4).set_trans(Tween.TRANS_EXPO)
|
||||
tween.parallel().tween_property(node, 'scale:y', base_scale.y*1.05, time*0.4).set_trans(Tween.TRANS_EXPO)
|
||||
tween.tween_property(node, 'position:y', base_position.y, time*0.6).set_trans(Tween.TRANS_BOUNCE)
|
||||
tween.parallel().tween_property(node, 'scale:y', base_scale.y, time*0.6).set_trans(Tween.TRANS_BOUNCE)
|
||||
tween.finished.connect(emit_signal.bind('finished_once'))
|
||||
|
||||
|
||||
func _get_named_variations() -> Dictionary:
|
||||
return {
|
||||
"bounce": {"type": AnimationType.ACTION},
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://qruxugkg6y8w
|
||||
@@ -0,0 +1,39 @@
|
||||
extends DialogicAnimation
|
||||
|
||||
|
||||
func animate() -> void:
|
||||
var tween := (node.create_tween() as Tween)
|
||||
|
||||
var end_scale: Vector2 = node.scale
|
||||
var end_modulate_alpha := 1.0
|
||||
var modulation_property := get_modulation_property()
|
||||
|
||||
if is_reversed:
|
||||
end_scale = Vector2(0, 0)
|
||||
end_modulate_alpha = 0.0
|
||||
|
||||
else:
|
||||
node.scale = Vector2(0, 0)
|
||||
var original_modulation: Color = node.get(modulation_property)
|
||||
original_modulation.a = 0.0
|
||||
node.set(modulation_property, original_modulation)
|
||||
|
||||
|
||||
tween.set_ease(Tween.EASE_IN_OUT)
|
||||
tween.set_trans(Tween.TRANS_SINE)
|
||||
tween.set_parallel()
|
||||
|
||||
(tween.tween_property(node, "scale", end_scale, time)
|
||||
.set_trans(Tween.TRANS_SPRING)
|
||||
.set_ease(Tween.EASE_OUT))
|
||||
tween.tween_property(node, modulation_property + ":a", end_modulate_alpha, time)
|
||||
|
||||
await tween.finished
|
||||
finished_once.emit()
|
||||
|
||||
|
||||
func _get_named_variations() -> Dictionary:
|
||||
return {
|
||||
"bounce in": {"reversed": false, "type": AnimationType.IN},
|
||||
"bounce out": {"reversed": true, "type": AnimationType.OUT},
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://rfgxn0xtuen3
|
||||
@@ -0,0 +1,44 @@
|
||||
extends DialogicAnimation
|
||||
|
||||
func animate() -> void:
|
||||
var tween := (node.create_tween() as Tween)
|
||||
|
||||
var start_height: float = base_position.y - node.get_viewport().size.y / 5
|
||||
var end_height := base_position.y
|
||||
|
||||
var start_modulation := 0.0
|
||||
var end_modulation := 1.0
|
||||
|
||||
if is_reversed:
|
||||
end_height = start_height
|
||||
start_height = base_position.y
|
||||
end_modulation = 0.0
|
||||
start_modulation = 1.0
|
||||
|
||||
node.position.y = start_height
|
||||
|
||||
tween.set_ease(Tween.EASE_OUT)
|
||||
tween.set_trans(Tween.TRANS_SINE)
|
||||
tween.set_parallel()
|
||||
|
||||
var end_postion := Vector2(base_position.x, end_height)
|
||||
tween.tween_property(node, "position", end_postion, time)
|
||||
|
||||
var property := get_modulation_property()
|
||||
|
||||
var original_modulation: Color = node.get(property)
|
||||
original_modulation.a = start_modulation
|
||||
node.set(property, original_modulation)
|
||||
var modulation_alpha := property + ":a"
|
||||
|
||||
tween.tween_property(node, modulation_alpha, end_modulation, time)
|
||||
|
||||
await tween.finished
|
||||
finished_once.emit()
|
||||
|
||||
|
||||
func _get_named_variations() -> Dictionary:
|
||||
return {
|
||||
"fade in down": {"reversed": false, "type": AnimationType.IN},
|
||||
"fade out up": {"reversed": true, "type": AnimationType.OUT},
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://bcs0jdci4mngb
|
||||
@@ -0,0 +1,34 @@
|
||||
extends DialogicAnimation
|
||||
|
||||
func animate() -> void:
|
||||
|
||||
var modulation_property := get_modulation_property()
|
||||
var end_modulation_alpha := 1.0
|
||||
|
||||
if is_reversed:
|
||||
end_modulation_alpha = 0.0
|
||||
|
||||
else:
|
||||
var original_modulation: Color = node.get(modulation_property)
|
||||
original_modulation.a = 0.0
|
||||
node.set(modulation_property, original_modulation)
|
||||
|
||||
var tween := (node.create_tween() as Tween)
|
||||
if is_reversed:
|
||||
tween.set_ease(Tween.EASE_IN)
|
||||
else:
|
||||
tween.set_ease(Tween.EASE_OUT)
|
||||
tween.set_trans(Tween.TRANS_SINE)
|
||||
tween.tween_property(node, modulation_property + ":a", end_modulation_alpha, time)
|
||||
|
||||
await tween.finished
|
||||
finished_once.emit()
|
||||
|
||||
|
||||
func _get_named_variations() -> Dictionary:
|
||||
return {
|
||||
"fade in": {"reversed": false, "type": AnimationType.IN},
|
||||
"fade out": {"reversed": true, "type": AnimationType.OUT},
|
||||
"fade cross": {"type": AnimationType.CROSSFADE},
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
uid://fekbbs23rj4m
|
||||
@@ -0,0 +1,44 @@
|
||||
extends DialogicAnimation
|
||||
|
||||
func animate() -> void:
|
||||
var tween := (node.create_tween() as Tween)
|
||||
|
||||
var start_height: float = base_position.y + node.get_viewport().size.y / 5
|
||||
var end_height := base_position.y
|
||||
|
||||
var start_modulation := 0.0
|
||||
var end_modulation := 1.0
|
||||
|
||||
if is_reversed:
|
||||
end_height = start_height
|
||||
start_height = base_position.y
|
||||
end_modulation = 0.0
|
||||
start_modulation = 1.0
|
||||
|
||||
node.position.y = start_height
|
||||
|
||||
tween.set_ease(Tween.EASE_OUT)
|
||||
tween.set_trans(Tween.TRANS_SINE)
|
||||
tween.set_parallel()
|
||||
|
||||
var end_postion := Vector2(base_position.x, end_height)
|
||||
tween.tween_property(node, "position", end_postion, time)
|
||||
|
||||
var property := get_modulation_property()
|
||||
|
||||
var original_modulation: Color = node.get(property)
|
||||
original_modulation.a = start_modulation
|
||||
node.set(property, original_modulation)
|
||||
var modulation_alpha := property + ":a"
|
||||
|
||||
tween.tween_property(node, modulation_alpha, end_modulation, time)
|
||||
|
||||
await tween.finished
|
||||
finished_once.emit()
|
||||
|
||||
|
||||
func _get_named_variations() -> Dictionary:
|
||||
return {
|
||||
"fade in up": {"reversed": false, "type": AnimationType.IN},
|
||||
"fade out down": {"reversed": true, "type": AnimationType.OUT},
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://dwnfbyjtc2anb
|
||||
@@ -0,0 +1,13 @@
|
||||
extends DialogicAnimation
|
||||
|
||||
func animate() -> void:
|
||||
var tween := (node.create_tween() as Tween)
|
||||
tween.tween_property(node, 'scale', Vector2(1,1)*1.2, time*0.5).set_trans(Tween.TRANS_ELASTIC).set_ease(Tween.EASE_OUT)
|
||||
tween.tween_property(node, 'scale', Vector2(1,1), time*0.5).set_trans(Tween.TRANS_BOUNCE).set_ease(Tween.EASE_OUT)
|
||||
tween.finished.connect(emit_signal.bind('finished_once'))
|
||||
|
||||
|
||||
func _get_named_variations() -> Dictionary:
|
||||
return {
|
||||
"heartbeat": {"type": AnimationType.ACTION},
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://8ro2ayitmjcp
|
||||
@@ -0,0 +1,12 @@
|
||||
extends DialogicAnimation
|
||||
|
||||
func animate() -> void:
|
||||
await node.get_tree().process_frame
|
||||
finished.emit()
|
||||
|
||||
|
||||
func _get_named_variations() -> Dictionary:
|
||||
return {
|
||||
"instant in": {"reversed": false, "type": AnimationType.IN},
|
||||
"instant out": {"reversed": true, "type": AnimationType.OUT},
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://cn4yveni7rdr7
|
||||
@@ -0,0 +1,20 @@
|
||||
extends DialogicAnimation
|
||||
|
||||
func animate() -> void:
|
||||
var tween := (node.create_tween() as Tween)
|
||||
tween.set_ease(Tween.EASE_IN_OUT).set_trans(Tween.TRANS_SINE)
|
||||
var strength: float = node.get_viewport().size.x/60
|
||||
var bound_multitween := DialogicUtil.multitween.bind(node, "position", "animation_shake_x")
|
||||
tween.tween_method(bound_multitween, Vector2(), Vector2(1, 0)*strength, time*0.2)
|
||||
tween.tween_method(bound_multitween, Vector2(), Vector2(-1,0)*strength, time*0.1)
|
||||
tween.tween_method(bound_multitween, Vector2(), Vector2(1, 0)*strength, time*0.1)
|
||||
tween.tween_method(bound_multitween, Vector2(), Vector2(-1,0)*strength, time*0.1)
|
||||
tween.tween_method(bound_multitween, Vector2(), Vector2(1, 0)*strength, time*0.1)
|
||||
tween.tween_method(bound_multitween, Vector2(), Vector2(-1,0)*strength, time*0.1)
|
||||
tween.tween_method(bound_multitween, Vector2(), Vector2(0, 0)*strength, time*0.2)
|
||||
tween.finished.connect(emit_signal.bind('finished_once'))
|
||||
|
||||
func _get_named_variations() -> Dictionary:
|
||||
return {
|
||||
"shake x": {"type": AnimationType.ACTION},
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://3tqien23j50t
|
||||
@@ -0,0 +1,23 @@
|
||||
extends DialogicAnimation
|
||||
|
||||
func animate() -> void:
|
||||
var tween := (node.create_tween() as Tween)
|
||||
tween.set_ease(Tween.EASE_IN_OUT).set_trans(Tween.TRANS_SINE)
|
||||
|
||||
var strength: float = node.get_viewport().size.y/40
|
||||
tween.tween_property(node, 'position:y', base_position.y + strength, time * 0.2)
|
||||
tween.tween_property(node, 'position:y', base_position.y - strength, time * 0.1)
|
||||
tween.tween_property(node, 'position:y', base_position.y + strength, time * 0.1)
|
||||
tween.tween_property(node, 'position:y', base_position.y - strength, time * 0.1)
|
||||
tween.tween_property(node, 'position:y', base_position.y + strength, time * 0.1)
|
||||
tween.tween_property(node, 'position:y', base_position.y - strength, time * 0.1)
|
||||
tween.tween_property(node, 'position:y', base_position.y + strength, time * 0.1)
|
||||
tween.tween_property(node, 'position:y', base_position.y, time * 0.2)
|
||||
|
||||
tween.finished.connect(emit_signal.bind('finished_once'))
|
||||
|
||||
|
||||
func _get_named_variations() -> Dictionary:
|
||||
return {
|
||||
"shake y": {"type": AnimationType.ACTION},
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://lur75holg34f
|
||||
@@ -0,0 +1,27 @@
|
||||
extends DialogicAnimation
|
||||
|
||||
func animate() -> void:
|
||||
var tween := (node.create_tween() as Tween)
|
||||
tween.set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_BACK)
|
||||
|
||||
var end_position_y: float = base_position.y + node.get_parent().global_position.y
|
||||
var start_position: float = -get_node_size().y + get_node_origin().y
|
||||
|
||||
if is_reversed:
|
||||
tween.set_ease(Tween.EASE_IN)
|
||||
end_position_y = -get_node_size().y + get_node_origin().y
|
||||
start_position = base_position.y
|
||||
|
||||
node.position.y = start_position
|
||||
|
||||
tween.tween_property(node, 'global_position:y', end_position_y, time)
|
||||
|
||||
await tween.finished
|
||||
finished_once.emit()
|
||||
|
||||
|
||||
func _get_named_variations() -> Dictionary:
|
||||
return {
|
||||
"slide in down": {"reversed": false, "type": AnimationType.IN},
|
||||
"slide out up": {"reversed": true, "type": AnimationType.OUT},
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://d0a5sgbr5imas
|
||||
@@ -0,0 +1,27 @@
|
||||
extends DialogicAnimation
|
||||
|
||||
|
||||
func animate() -> void:
|
||||
var tween := (node.create_tween() as Tween)
|
||||
tween.set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_BACK)
|
||||
|
||||
var end_position_x: float = base_position.x + node.get_parent().global_position.x
|
||||
|
||||
if is_reversed:
|
||||
end_position_x = - get_node_size().x + get_node_origin().x
|
||||
tween.set_ease(Tween.EASE_IN)
|
||||
|
||||
else:
|
||||
node.global_position.x = -get_node_size().x + get_node_origin().x
|
||||
|
||||
tween.tween_property(node, 'global_position:x', end_position_x, time)
|
||||
|
||||
await tween.finished
|
||||
finished_once.emit()
|
||||
|
||||
|
||||
func _get_named_variations() -> Dictionary:
|
||||
return {
|
||||
"slide from left": {"reversed": false, "type": AnimationType.IN},
|
||||
"slide to left": {"reversed": true, "type": AnimationType.OUT},
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://c8il877nw3xqw
|
||||
@@ -0,0 +1,24 @@
|
||||
extends DialogicAnimation
|
||||
|
||||
func animate() -> void:
|
||||
var tween := (node.create_tween() as Tween)
|
||||
tween.set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_BACK)
|
||||
|
||||
var viewport_x: float = get_viewport_size().x
|
||||
var end_position_x : float = base_position.x + node.get_parent().global_position.x
|
||||
|
||||
if is_reversed:
|
||||
end_position_x = viewport_x + get_node_origin().x
|
||||
tween.set_ease(Tween.EASE_IN)
|
||||
else:
|
||||
node.global_position.x = viewport_x + get_node_origin().x
|
||||
|
||||
tween.tween_property(node, 'global_position:x', end_position_x, time)
|
||||
tween.finished.connect(emit_signal.bind('finished_once'))
|
||||
|
||||
|
||||
func _get_named_variations() -> Dictionary:
|
||||
return {
|
||||
"slide from right": {"reversed": false, "type": AnimationType.IN},
|
||||
"slide to right": {"reversed": true, "type": AnimationType.OUT},
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://daj7cqft5hnxg
|
||||
@@ -0,0 +1,26 @@
|
||||
extends DialogicAnimation
|
||||
|
||||
func animate() -> void:
|
||||
var tween := (node.create_tween() as Tween)
|
||||
tween.set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_BACK)
|
||||
|
||||
var start_position_y: float = get_viewport_size().y + get_node_origin().y
|
||||
var end_position_y: float = base_position.y + node.get_parent().global_position.y
|
||||
|
||||
if is_reversed:
|
||||
tween.set_ease(Tween.EASE_IN)
|
||||
start_position_y = end_position_y
|
||||
end_position_y = get_viewport_size().y + get_node_origin().y
|
||||
|
||||
node.global_position.y = start_position_y
|
||||
tween.tween_property(node, 'global_position:y', end_position_y, time)
|
||||
|
||||
await tween.finished
|
||||
finished_once.emit()
|
||||
|
||||
|
||||
func _get_named_variations() -> Dictionary:
|
||||
return {
|
||||
"slide in up": {"reversed": false, "type": AnimationType.IN},
|
||||
"slide out down": {"reversed": true, "type": AnimationType.OUT},
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://bj5ak53i7s8ux
|
||||
25
addons/dialogic/Modules/Character/DefaultAnimations/tada.gd
Normal file
25
addons/dialogic/Modules/Character/DefaultAnimations/tada.gd
Normal file
@@ -0,0 +1,25 @@
|
||||
extends DialogicAnimation
|
||||
|
||||
func animate() -> void:
|
||||
var tween := (node.create_tween() as Tween)
|
||||
tween.set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_OUT)
|
||||
|
||||
var strength: float = 0.01
|
||||
|
||||
tween.set_parallel(true)
|
||||
tween.tween_property(node, 'scale', Vector2(1,1)*(1+strength), time*0.3)
|
||||
tween.tween_property(node, 'rotation', -strength, time*0.1).set_delay(time*0.2)
|
||||
tween.tween_property(node, 'rotation', strength, time*0.1).set_delay(time*0.3)
|
||||
tween.tween_property(node, 'rotation', -strength, time*0.1).set_delay(time*0.4)
|
||||
tween.tween_property(node, 'rotation', strength, time*0.1).set_delay(time*0.5)
|
||||
tween.tween_property(node, 'rotation', -strength, time*0.1).set_delay(time*0.6)
|
||||
tween.chain().tween_property(node, 'scale', Vector2(1,1), time*0.3)
|
||||
tween.parallel().tween_property(node, 'rotation', 0.0, time*0.3)
|
||||
|
||||
tween.finished.connect(emit_signal.bind('finished_once'))
|
||||
|
||||
|
||||
func _get_named_variations() -> Dictionary:
|
||||
return {
|
||||
"tada": {"type": AnimationType.ACTION},
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://crv1pn60clrvx
|
||||
@@ -0,0 +1,36 @@
|
||||
extends DialogicAnimation
|
||||
|
||||
func animate() -> void:
|
||||
var modulate_property := get_modulation_property()
|
||||
var modulate_alpha_property := modulate_property + ":a"
|
||||
|
||||
var end_scale: Vector2 = node.scale
|
||||
var end_modulation_alpha := 1.0
|
||||
|
||||
if is_reversed:
|
||||
end_modulation_alpha = 0.0
|
||||
|
||||
else:
|
||||
node.scale = Vector2(0, 0)
|
||||
node.position.y = base_position.y - node.get_viewport().size.y * 0.5
|
||||
|
||||
var original_modulation: Color = node.get(modulate_property)
|
||||
original_modulation.a = 0.0
|
||||
node.set(modulate_property, original_modulation)
|
||||
|
||||
var tween := (node.create_tween() as Tween)
|
||||
tween.set_ease(Tween.EASE_IN_OUT).set_trans(Tween.TRANS_EXPO)
|
||||
tween.set_parallel(true)
|
||||
tween.tween_property(node, "scale", end_scale, time)
|
||||
tween.tween_property(node, "position", base_position, time)
|
||||
tween.tween_property(node, modulate_alpha_property, end_modulation_alpha, time)
|
||||
|
||||
await tween.finished
|
||||
finished_once.emit()
|
||||
|
||||
|
||||
func _get_named_variations() -> Dictionary:
|
||||
return {
|
||||
"zoom center in": {"reversed": false, "type": AnimationType.IN},
|
||||
"zoom center out": {"reversed": true, "type": AnimationType.OUT},
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://cjwdb0jkjrcxe
|
||||
@@ -0,0 +1,35 @@
|
||||
extends DialogicAnimation
|
||||
|
||||
func animate() -> void:
|
||||
var modulate_property := get_modulation_property()
|
||||
var modulate_alpha_property := modulate_property + ":a"
|
||||
|
||||
var end_scale: Vector2 = node.scale
|
||||
var end_modulation_alpha := 1.0
|
||||
|
||||
if is_reversed:
|
||||
end_scale = Vector2(0, 0)
|
||||
end_modulation_alpha = 0.0
|
||||
|
||||
else:
|
||||
node.scale = Vector2(0,0)
|
||||
|
||||
var original_modulation: Color = node.get(modulate_property)
|
||||
original_modulation.a = 0.0
|
||||
node.set(modulate_property, original_modulation)
|
||||
|
||||
var tween := (node.create_tween() as Tween)
|
||||
tween.set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_EXPO)
|
||||
tween.set_parallel(true)
|
||||
tween.tween_property(node, "scale", end_scale, time)
|
||||
tween.tween_property(node, modulate_alpha_property, end_modulation_alpha, time)
|
||||
|
||||
await tween.finished
|
||||
finished_once.emit()
|
||||
|
||||
|
||||
func _get_named_variations() -> Dictionary:
|
||||
return {
|
||||
"zoom in": {"reversed": false, "type": AnimationType.IN},
|
||||
"zoom out": {"reversed": true, "type": AnimationType.OUT},
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://bl5sdpj631mtt
|
||||
@@ -0,0 +1,47 @@
|
||||
@tool
|
||||
class_name DialogicPortraitAnimationUtil
|
||||
|
||||
enum AnimationType {ALL=-1, IN=1, OUT=2, ACTION=3, CROSSFADE=4}
|
||||
|
||||
|
||||
static func guess_animation(string:String, type := AnimationType.ALL) -> String:
|
||||
var default := {}
|
||||
var filter := {}
|
||||
var ignores := []
|
||||
match type:
|
||||
AnimationType.ALL:
|
||||
pass
|
||||
AnimationType.IN:
|
||||
filter = {"type":AnimationType.IN}
|
||||
ignores = ["in"]
|
||||
AnimationType.OUT:
|
||||
filter = {"type":AnimationType.OUT}
|
||||
ignores = ["out"]
|
||||
AnimationType.ACTION:
|
||||
filter = {"type":AnimationType.ACTION}
|
||||
AnimationType.CROSSFADE:
|
||||
filter = {"type":AnimationType.CROSSFADE}
|
||||
ignores = ["cross"]
|
||||
return DialogicResourceUtil.guess_special_resource(&"PortraitAnimation", string, default, filter, ignores).get("path", "")
|
||||
|
||||
|
||||
static func get_portrait_animations_filtered(type := AnimationType.ALL) -> Dictionary:
|
||||
var filter := {"type":type}
|
||||
if type == AnimationType.ALL:
|
||||
filter["type"] = [AnimationType.IN, AnimationType.OUT, AnimationType.ACTION]
|
||||
return DialogicResourceUtil.list_special_resources("PortraitAnimation", filter)
|
||||
|
||||
|
||||
static func get_suggestions(_search_text := "", current_value:= "", empty_text := "Default", action := AnimationType.ALL) -> Dictionary:
|
||||
var suggestions := {}
|
||||
|
||||
if empty_text and current_value:
|
||||
suggestions[empty_text] = {'value':"", 'editor_icon':["GuiRadioUnchecked", "EditorIcons"]}
|
||||
|
||||
for anim_name in get_portrait_animations_filtered(action):
|
||||
suggestions[DialogicUtil.pretty_name(anim_name)] = {
|
||||
'value' : DialogicUtil.pretty_name(anim_name),
|
||||
'editor_icon' : ["Animation", "EditorIcons"]
|
||||
}
|
||||
|
||||
return suggestions
|
||||
@@ -0,0 +1 @@
|
||||
uid://j2k3uogf5715
|
||||
102
addons/dialogic/Modules/Character/class_dialogic_animation.gd
Normal file
102
addons/dialogic/Modules/Character/class_dialogic_animation.gd
Normal file
@@ -0,0 +1,102 @@
|
||||
class_name DialogicAnimation
|
||||
extends Node
|
||||
|
||||
## Class that can be used to animate portraits. Can be extended to create animations.
|
||||
|
||||
enum AnimationType {IN=1, OUT=2, ACTION=3, CROSSFADE=4}
|
||||
|
||||
signal finished_once
|
||||
signal finished
|
||||
|
||||
## Set at runtime, will be the node to animate.
|
||||
var node: Node
|
||||
|
||||
## Set at runtime, will be the length of the animation.
|
||||
var time: float
|
||||
|
||||
## Set at runtime, will be the base position of the node.
|
||||
## Depending on the animation, this might be the start, end or both.
|
||||
var base_position: Vector2
|
||||
## Set at runtime, will be the base scale of the node.
|
||||
var base_scale: Vector2
|
||||
|
||||
## Used to repeate the animation for a number of times.
|
||||
var repeats: int
|
||||
|
||||
## If `true`, the animation will be reversed.
|
||||
## This must be implemented by each animation or it will have no effect.
|
||||
var is_reversed: bool = false
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
finished_once.connect(finished_one_loop)
|
||||
|
||||
|
||||
## To be overridden. Do the actual animating/tweening in here.
|
||||
## Use the properties [member node], [member time], [member base_position], etc.
|
||||
func animate() -> void:
|
||||
pass
|
||||
|
||||
|
||||
## This method controls whether to repeat the animation or not.
|
||||
## Animations must call this once they finished an animation.
|
||||
func finished_one_loop() -> void:
|
||||
repeats -= 1
|
||||
|
||||
if repeats > 0:
|
||||
animate()
|
||||
|
||||
else:
|
||||
finished.emit()
|
||||
|
||||
|
||||
func pause() -> void:
|
||||
if node:
|
||||
node.process_mode = Node.PROCESS_MODE_DISABLED
|
||||
|
||||
|
||||
func resume() -> void:
|
||||
if node:
|
||||
node.process_mode = Node.PROCESS_MODE_INHERIT
|
||||
|
||||
|
||||
func _get_named_variations() -> Dictionary:
|
||||
return {}
|
||||
|
||||
|
||||
## If the animation wants to change the modulation, this method
|
||||
## will return the property to change.
|
||||
##
|
||||
## The [class CanvasGroup] can use `self_modulate` instead of `modulate`
|
||||
## to uniformly change the modulation of all children without additively
|
||||
## overlaying the modulations.
|
||||
func get_modulation_property() -> String:
|
||||
if node is CanvasGroup:
|
||||
return "self_modulate"
|
||||
else:
|
||||
return "modulate"
|
||||
|
||||
|
||||
## Tries to return the size of the node to be animated.
|
||||
## For portraits this uses the portrait containers size.
|
||||
## This is useful if your animation depends on the size of the node.
|
||||
func get_node_size() -> Vector2:
|
||||
if not node:
|
||||
return Vector2()
|
||||
if node.get_parent() is DialogicNode_PortraitContainer:
|
||||
return node.get_parent().size
|
||||
if "size" in node:
|
||||
return node.size * node.scale
|
||||
return node.get_viewport().size
|
||||
|
||||
|
||||
func get_node_origin() -> Vector2:
|
||||
if not node:
|
||||
return Vector2()
|
||||
if node.get_parent() is DialogicNode_PortraitContainer:
|
||||
return node.get_parent()._get_origin_position()
|
||||
return Vector2()
|
||||
|
||||
|
||||
func get_viewport_size() -> Vector2:
|
||||
return node.get_viewport().get_visible_rect().size
|
||||
@@ -0,0 +1 @@
|
||||
uid://0hsjlurlblou
|
||||
BIN
addons/dialogic/Modules/Character/custom_portrait_thumbnail.png
Normal file
BIN
addons/dialogic/Modules/Character/custom_portrait_thumbnail.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.8 KiB |
@@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://c5tu88x32sjkf"
|
||||
path="res://.godot/imported/custom_portrait_thumbnail.png-0513583853d87342a634d56bc0bec965.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/dialogic/Modules/Character/custom_portrait_thumbnail.png"
|
||||
dest_files=["res://.godot/imported/custom_portrait_thumbnail.png-0513583853d87342a634d56bc0bec965.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
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user