2 class_name DialogicBackgroundEvent
5 ## Event to show scenes in the background and switch between them.
9 ## The scene to use. If empty, this will default to the DefaultBackground.gd scene.
10 ## This scene supports images and fading.
11 ## If you set it to a scene path, then that scene will be instanced.
12 ## Learn more about custom backgrounds in the Subsystem_Background.gd docs.
14 ## The argument that is passed to the background scene.
15 ## For the default scene it's the path to the image to show.
17 ## The time the fade animation will take. Leave at 0 for instant change.
19 ## Name of the transition to use.
22 ## Helpers for visual editor
23 enum ArgumentTypes {IMAGE, CUSTOM}
24 var _arg_type := ArgumentTypes.IMAGE :
26 if argument.begins_with("res://"):
27 return ArgumentTypes.IMAGE
31 if value == ArgumentTypes.CUSTOM:
32 if argument.begins_with("res://"):
33 argument = " "+argument
36 enum SceneTypes {DEFAULT, CUSTOM}
37 var _scene_type := SceneTypes.DEFAULT :
42 return SceneTypes.CUSTOM
44 if value == SceneTypes.DEFAULT:
49 ################################################################################
51 func _execute() -> void:
52 var final_fade_duration := fade
54 if dialogic.Inputs.auto_skip.enabled:
55 var time_per_event: float = dialogic.Inputs.auto_skip.time_per_event
56 final_fade_duration = min(fade, time_per_event)
58 dialogic.Backgrounds.update_background(scene, argument, final_fade_duration, transition)
65 ################################################################################
68 event_name = "Background"
69 set_default_color('Color8')
70 event_category = "Visuals"
71 event_sorting_index = 0
76 ################################################################################
78 func get_shortcode() -> String:
82 func get_shortcode_parameters() -> Dictionary:
84 #param_name : property_info
85 "scene" : {"property": "scene", "default": ""},
86 "arg" : {"property": "argument", "default": ""},
87 "fade" : {"property": "fade", "default": 0},
88 "transition" : {"property": "transition", "default": "",
89 "suggestions": get_transition_suggestions},
95 #region EDITOR REPRESENTATION
96 ################################################################################
98 func build_event_editor() -> void:
99 add_header_edit('_scene_type', ValueType.FIXED_OPTIONS, {
103 'label': 'Background',
104 'value': SceneTypes.DEFAULT,
105 'icon': ["GuiRadioUnchecked", "EditorIcons"]
108 'label': 'Custom Scene',
109 'value': SceneTypes.CUSTOM,
110 'icon': ["PackedScene", "EditorIcons"]
113 add_header_label("with image", "_scene_type == SceneTypes.DEFAULT")
114 add_header_edit("scene", ValueType.FILE,
115 {'file_filter':'*.tscn, *.scn; Scene Files',
116 'placeholder': "Custom scene",
117 'editor_icon': ["PackedScene", "EditorIcons"],
118 }, '_scene_type == SceneTypes.CUSTOM')
119 add_header_edit('_arg_type', ValueType.FIXED_OPTIONS, {
120 'left_text' : 'with',
124 'value': ArgumentTypes.IMAGE,
125 'icon': ["Image", "EditorIcons"]
128 'label': 'Custom Argument',
129 'value': ArgumentTypes.CUSTOM,
130 'icon': ["String", "EditorIcons"]
132 ], "symbol_only": true}, "_scene_type == SceneTypes.CUSTOM")
133 add_header_edit('argument', ValueType.FILE,
134 {'file_filter':'*.jpg, *.jpeg, *.png, *.webp, *.tga, *svg, *.bmp, *.dds, *.exr, *.hdr; Supported Image Files',
135 'placeholder': "No Image",
136 'editor_icon': ["Image", "EditorIcons"],
138 '_arg_type == ArgumentTypes.IMAGE or _scene_type == SceneTypes.DEFAULT')
139 add_header_edit('argument', ValueType.SINGLELINE_TEXT, {}, '_arg_type == ArgumentTypes.CUSTOM')
141 add_body_edit("transition", ValueType.DYNAMIC_OPTIONS,
142 {'left_text':'Transition:',
143 'empty_text':'Simple Fade',
144 'suggestions_func':get_transition_suggestions,
145 'editor_icon':["PopupMenu", "EditorIcons"]})
146 add_body_edit("fade", ValueType.NUMBER, {'left_text':'Fade time:'})
149 func get_transition_suggestions(_filter:String="") -> Dictionary:
150 var transitions := DialogicResourceUtil.list_special_resources("BackgroundTransition")
151 var suggestions := {}
152 for i in transitions:
153 suggestions[DialogicUtil.pretty_name(i)] = {'value': DialogicUtil.pretty_name(i), 'editor_icon': ["PopupMenu", "EditorIcons"]}