]> Untitled Git - wolf-seeking-sheep.git/blob - addons/dialogic/Modules/Jump/event_label.gd
Squashed commit of the following:
[wolf-seeking-sheep.git] / addons / dialogic / Modules / Jump / event_label.gd
1 @tool
2 class_name DialogicLabelEvent
3 extends DialogicEvent
4
5 ## Event that is used as an anchor. You can use the DialogicJumpEvent to jump to this point.
6
7
8 ### Settings
9
10 ## Used to identify the label. Duplicate names in a timeline will mean it always chooses the first.
11 var name := ""
12 var display_name := ""
13
14
15
16 ################################################################################
17 ##                                              EXECUTE
18 ################################################################################
19
20 func _execute() -> void:
21         # This event is mainly implemented in the Jump subsystem.
22         dialogic.Jump.passed_label.emit(
23                 {
24                         "identifier": name,
25                         "display_name": get_property_translated("display_name"),
26                         "display_name_orig": display_name,
27                         "timeline": DialogicResourceUtil.get_unique_identifier(dialogic.current_timeline.resource_path)
28                 })
29         finish()
30
31
32 ################################################################################
33 ##                                              INITIALIZE
34 ################################################################################
35
36 func _init() -> void:
37         event_name = "Label"
38         set_default_color('Color4')
39         event_category = "Flow"
40         event_sorting_index = 3
41
42
43 func _get_icon() -> Resource:
44         return load(self.get_script().get_path().get_base_dir().path_join('icon_label.png'))
45
46
47 ################################################################################
48 ##                                              SAVING/LOADING
49 ################################################################################
50 func to_text() -> String:
51         if display_name.is_empty():
52                 return "label "+name
53         else:
54                 return "label "+name+ " ("+display_name+")"
55
56
57
58 func from_text(string:String) -> void:
59         var regex := RegEx.create_from_string(r'label +(?<name>[^(]+)(\((?<display_name>.+)\))?')
60         var result := regex.search(string.strip_edges())
61         if result:
62                 name = result.get_string('name').strip_edges()
63                 display_name = result.get_string('display_name').strip_edges()
64
65
66 func is_valid_event(string:String) -> bool:
67         if string.strip_edges().begins_with("label"):
68                 return true
69         return false
70
71
72 # this is only here to provide a list of default values
73 # this way the module manager can add custom default overrides to this event.
74 func get_shortcode_parameters() -> Dictionary:
75         return {
76                 #param_name     : property_info
77                 "name"                  : {"property": "name", "default": ""},
78                 "display"               : {"property": "display_name", "default": ""},
79         }
80
81
82 func _get_translatable_properties() -> Array:
83         return ["display_name"]
84
85
86 func _get_property_original_translation(property_name:String) -> String:
87         match property_name:
88                 'display_name':
89                         return display_name
90         return ''
91
92 ################################################################################
93 ##                                              EDITOR REPRESENTATION
94 ################################################################################
95
96 func build_event_editor() -> void:
97         add_header_edit('name', ValueType.SINGLELINE_TEXT, {'left_text':'Label', 'autofocus':true})
98         add_body_edit('display_name', ValueType.SINGLELINE_TEXT, {'left_text':'Display Name:'})
99
100
101 ####################### CODE COMPLETION ########################################
102 ################################################################################
103
104 func _get_start_code_completion(_CodeCompletionHelper:Node, TextNode:TextEdit) -> void:
105         TextNode.add_code_completion_option(CodeEdit.KIND_PLAIN_TEXT, 'label', 'label ', event_color.lerp(TextNode.syntax_highlighter.normal_color, 0.3))
106
107
108 #################### SYNTAX HIGHLIGHTING #######################################
109 ################################################################################
110
111 func _get_syntax_highlighting(Highlighter:SyntaxHighlighter, dict:Dictionary, line:String) -> Dictionary:
112         dict[line.find('label')] = {"color":event_color.lerp(Highlighter.normal_color, 0.3)}
113         dict[line.find('label')+5] = {"color":event_color.lerp(Highlighter.normal_color, 0.5)}
114         return dict