]> Untitled Git - wolf-seeking-sheep.git/blob - addons/dialogic/Modules/Condition/ui_condition_end.gd
Initial Godot project with Dialogic 2.0-Alpha-17
[wolf-seeking-sheep.git] / addons / dialogic / Modules / Condition / ui_condition_end.gd
1 @tool
2 extends HBoxContainer
3
4 var parent_resource: DialogicEvent = null
5
6
7 func _ready() -> void:
8         $AddElif.button_up.connect(add_elif)
9         $AddElse.button_up.connect(add_else)
10
11
12 func refresh() -> void:
13         if parent_resource is DialogicConditionEvent:
14                 # hide add elif and add else button on ELSE event
15                 $AddElif.visible = parent_resource.condition_type != DialogicConditionEvent.ConditionTypes.ELSE
16                 $AddElse.visible = parent_resource.condition_type != DialogicConditionEvent.ConditionTypes.ELSE
17                 $Label.text = "End of "+["IF", "ELIF", "ELSE"][parent_resource.condition_type]+" ("+parent_resource.condition+")"
18
19                 # hide add add else button if followed by ELIF or ELSE event
20                 var timeline_editor := find_parent('VisualEditor')
21                 if timeline_editor:
22                         var next_event: DialogicEvent = null
23                         if timeline_editor.get_block_below(get_parent()):
24                                 next_event = timeline_editor.get_block_below(get_parent()).resource
25                                 if next_event is DialogicConditionEvent:
26                                         if next_event.condition_type != DialogicConditionEvent.ConditionTypes.IF:
27                                                 $AddElse.hide()
28                 if parent_resource.condition_type == DialogicConditionEvent.ConditionTypes.ELSE:
29                         $Label.text = "End of ELSE"
30         else:
31                 hide()
32
33
34 func add_elif() -> void:
35         var timeline := find_parent('VisualEditor')
36         if timeline:
37                 var resource := DialogicConditionEvent.new()
38                 resource.condition_type = DialogicConditionEvent.ConditionTypes.ELIF
39                 timeline.add_event_undoable(resource, get_parent().get_index()+1)
40                 timeline.indent_events()
41                 timeline.something_changed()
42
43
44 func add_else() -> void:
45         var timeline := find_parent('VisualEditor')
46         if timeline:
47                 var resource := DialogicConditionEvent.new()
48                 resource.condition_type = DialogicConditionEvent.ConditionTypes.ELSE
49                 timeline.add_event_undoable(resource, get_parent().get_index()+1)
50                 timeline.indent_events()
51                 timeline.something_changed()