2 class_name DialogicJumpEvent
5 ## Event that allows starting another timeline. Also can jump to a label in that or the current timeline.
10 ## The timeline to jump to, if null then it's the current one. This setting should be a dialogic timeline resource.
11 var timeline: DialogicTimeline
12 ## If not empty, the event will try to find a Label event with this set as name. Empty by default..
18 ## Used to set the timeline resource from the unique name identifier and vice versa
19 var timeline_identifier := "":
22 var identifier := DialogicResourceUtil.get_unique_identifier(timeline.resource_path)
23 if not identifier.is_empty():
25 return timeline_identifier
27 timeline_identifier = value
28 timeline = DialogicResourceUtil.get_timeline_resource(value)
29 if (not timeline_identifier in DialogicResourceUtil.get_label_cache().keys()
30 or not label_name in DialogicResourceUtil.get_label_cache()[timeline_identifier]):
32 ui_update_needed.emit()
35 ################################################################################
37 ################################################################################
39 func _execute() -> void:
40 dialogic.Jump.push_to_jump_stack()
41 if timeline and timeline != dialogic.current_timeline:
42 dialogic.Jump.switched_timeline.emit({'previous_timeline':dialogic.current_timeline, 'timeline':timeline, 'label':label_name})
43 dialogic.start_timeline(timeline, label_name)
46 dialogic.Jump.jump_to_label(label_name)
49 dialogic.start_timeline(dialogic.current_timeline)
52 ################################################################################
54 ################################################################################
58 set_default_color('Color4')
59 event_category = "Flow"
60 event_sorting_index = 4
63 func _get_icon() -> Resource:
64 return load(self.get_script().get_path().get_base_dir().path_join('icon_jump.png'))
67 ################################################################################
69 ################################################################################
70 func to_text() -> String:
72 if timeline_identifier:
73 result += timeline_identifier+'/'
81 func from_text(string:String) -> void:
82 var result := RegEx.create_from_string(r"jump (?<timeline>.*\/)?(?<label>.*)?").search(string.strip_edges())
84 timeline_identifier = result.get_string('timeline').trim_suffix('/')
85 label_name = result.get_string('label')
88 func is_valid_event(string:String) -> bool:
89 if string.strip_edges().begins_with("jump"):
94 func get_shortcode_parameters() -> Dictionary:
96 #param_name : property_info
97 "timeline" : {"property": "timeline_identifier", "default": null,
98 "suggestions": get_timeline_suggestions},
99 "label" : {"property": "label_name", "default": ""},
103 ################################################################################
104 ## EDITOR REPRESENTATION
105 ################################################################################
107 func build_event_editor() -> void:
108 add_header_edit('timeline_identifier', ValueType.DYNAMIC_OPTIONS, {'left_text':'Jump to',
109 'file_extension': '.dtl',
111 'suggestions_func': get_timeline_suggestions,
112 'editor_icon' : ["TripleBar", "EditorIcons"],
113 'empty_text' : '(this timeline)',
116 add_header_edit("label_name", ValueType.DYNAMIC_OPTIONS, {'left_text':"at",
117 'empty_text':'the beginning',
118 'suggestions_func':get_label_suggestions,
119 'editor_icon':["ArrowRight", "EditorIcons"]})
122 func get_timeline_suggestions(_filter:String= "") -> Dictionary:
123 var suggestions := {}
125 suggestions['(this timeline)'] = {'value':'', 'editor_icon':['GuiRadioUnchecked', 'EditorIcons']}
126 for resource in DialogicResourceUtil.get_timeline_directory().keys():
127 suggestions[resource] = {'value': resource, 'tooltip':DialogicResourceUtil.get_timeline_directory()[resource], 'editor_icon': ["TripleBar", "EditorIcons"]}
131 func get_label_suggestions(_filter:String="") -> Dictionary:
132 var suggestions := {}
133 suggestions['at the beginning'] = {'value':'', 'editor_icon':['GuiRadioUnchecked', 'EditorIcons']}
134 if timeline_identifier in DialogicResourceUtil.get_label_cache().keys():
135 for label in DialogicResourceUtil.get_label_cache()[timeline_identifier]:
136 suggestions[label] = {'value': label, 'tooltip':label, 'editor_icon': ["ArrowRight", "EditorIcons"]}
140 ####################### CODE COMPLETION ########################################
141 ################################################################################
143 func _get_code_completion(CodeCompletionHelper:Node, TextNode:TextEdit, line:String, _word:String, symbol:String) -> void:
144 if symbol == ' ' and line.count(' ') == 1:
145 CodeCompletionHelper.suggest_labels(TextNode, '', '\n', event_color.lerp(TextNode.syntax_highlighter.normal_color, 0.6))
146 CodeCompletionHelper.suggest_timelines(TextNode, CodeEdit.KIND_MEMBER, event_color.lerp(TextNode.syntax_highlighter.normal_color, 0.6))
148 CodeCompletionHelper.suggest_labels(TextNode, line.strip_edges().trim_prefix('jump ').trim_suffix('/'+String.chr(0xFFFF)).strip_edges(), '\n', event_color.lerp(TextNode.syntax_highlighter.normal_color, 0.6))
151 func _get_start_code_completion(_CodeCompletionHelper:Node, TextNode:TextEdit) -> void:
152 TextNode.add_code_completion_option(CodeEdit.KIND_PLAIN_TEXT, 'jump', 'jump ', event_color.lerp(TextNode.syntax_highlighter.normal_color, 0.3))
155 #################### SYNTAX HIGHLIGHTING #######################################
156 ################################################################################
158 func _get_syntax_highlighting(Highlighter:SyntaxHighlighter, dict:Dictionary, line:String) -> Dictionary:
159 dict[line.find('jump')] = {"color":event_color.lerp(Highlighter.normal_color, 0.3)}
160 dict[line.find('jump')+4] = {"color":event_color.lerp(Highlighter.normal_color, 0.5)}