]> Untitled Git - wolf-seeking-sheep.git/blob - addons/dialogic/Modules/Background/event_background.gd
Initial Godot project with Dialogic 2.0-Alpha-17
[wolf-seeking-sheep.git] / addons / dialogic / Modules / Background / event_background.gd
1 @tool
2 class_name DialogicBackgroundEvent
3 extends DialogicEvent
4
5 ## Event to show scenes in the background and switch between them.
6
7 ### Settings
8
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.
13 var scene := ""
14 ## The argument that is passed to the background scene.
15 ## For the default scene it's the path to the image to show.
16 var argument := ""
17 ## The time the fade animation will take. Leave at 0 for instant change.
18 var fade: float = 0.0
19 ## Name of the transition to use.
20 var transition := ""
21
22 ## Helpers for visual editor
23 enum ArgumentTypes {IMAGE, CUSTOM}
24 var _arg_type := ArgumentTypes.IMAGE :
25         get:
26                 if argument.begins_with("res://"):
27                         return ArgumentTypes.IMAGE
28                 else:
29                         return _arg_type
30         set(value):
31                 if value == ArgumentTypes.CUSTOM:
32                         if argument.begins_with("res://"):
33                                 argument = " "+argument
34                 _arg_type = value
35
36 enum SceneTypes {DEFAULT, CUSTOM}
37 var _scene_type := SceneTypes.DEFAULT :
38         get:
39                 if scene.is_empty():
40                         return _scene_type
41                 else:
42                         return SceneTypes.CUSTOM
43         set(value):
44                 if value == SceneTypes.DEFAULT:
45                         scene = ""
46                 _scene_type = value
47
48 #region EXECUTION
49 ################################################################################
50
51 func _execute() -> void:
52         var final_fade_duration := fade
53
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)
57
58         dialogic.Backgrounds.update_background(scene, argument, final_fade_duration, transition)
59
60         finish()
61
62 #endregion
63
64 #region INITIALIZE
65 ################################################################################
66
67 func _init() -> void:
68         event_name = "Background"
69         set_default_color('Color8')
70         event_category = "Visuals"
71         event_sorting_index = 0
72
73 #endregion
74
75 #region SAVE & LOAD
76 ################################################################################
77
78 func get_shortcode() -> String:
79         return "background"
80
81
82 func get_shortcode_parameters() -> Dictionary:
83         return {
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},
90         }
91
92
93 #endregion
94
95 #region EDITOR REPRESENTATION
96 ################################################################################
97
98 func build_event_editor() -> void:
99         add_header_edit('_scene_type', ValueType.FIXED_OPTIONS, {
100                 'left_text' :'Show',
101                 'options': [
102                         {
103                                 'label': 'Background',
104                                 'value': SceneTypes.DEFAULT,
105                                 'icon': ["GuiRadioUnchecked", "EditorIcons"]
106                         },
107                         {
108                                 'label': 'Custom Scene',
109                                 'value': SceneTypes.CUSTOM,
110                                 'icon': ["PackedScene", "EditorIcons"]
111                         }
112                 ]})
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',
121                 'options': [
122                         {
123                                 'label': 'Image',
124                                 'value': ArgumentTypes.IMAGE,
125                                 'icon': ["Image", "EditorIcons"]
126                         },
127                         {
128                                 'label': 'Custom Argument',
129                                 'value': ArgumentTypes.CUSTOM,
130                                 'icon': ["String", "EditorIcons"]
131                         }
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"],
137                         },
138                         '_arg_type == ArgumentTypes.IMAGE or _scene_type == SceneTypes.DEFAULT')
139         add_header_edit('argument', ValueType.SINGLELINE_TEXT, {}, '_arg_type == ArgumentTypes.CUSTOM')
140
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:'})
147
148
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"]}
154         return suggestions
155
156 #endregion