Skip to content

Commit

Permalink
2.0 Jump + Label, Event Button Sorting (#934)
Browse files Browse the repository at this point in the history
* Add Goto and Label event

This reimplements the goto and label functionality. GoTo only allows to jump inside the timeline, while change timeline now has a label settings as well, that allows to start the given timeline at a specific point.

Alternatively you can also specify a label when starting a timeline in code by doing DialogicGameHandler.start_timeline(resource, label). The label is optional though.

The event icons are a bit to big. Emilio should fix that.

* Implement event button sorting and class names  

Added class names to the events that were missing one. 

Implemented button sorting again.

* Make sure events don't save empty/null properties

* Unify Change Timeline and GoTo into Jump event

The new jump event is basically a Change timeline event with a label selector. If no timeline is selected (or the current one), it will just jump to a label with the name inside the current timeline.

* Make ResourcePicker allow empty values
  • Loading branch information
Jowan-Spooner authored Jun 20, 2022
1 parent f34a89d commit 7f05e22
Show file tree
Hide file tree
Showing 17 changed files with 110 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ func _on_Search_text_entered(new_text = ""):
if $Search/Suggestions.get_item_count() and not $Search.text.empty():
suggestion_selected(0)
else:
set_value(current_value)
emit_signal("value_changed", property_name, null)
# set_value(null)

func _on_Search_text_changed(new_text):
$Search/Suggestions.clear()
Expand Down

This file was deleted.

34 changes: 17 additions & 17 deletions addons/dialogic/Editor/TimelineEditor/TimelineEditor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,23 @@ func _ready():
var buttonScene = load("res://addons/dialogic/Editor/TimelineEditor/SmallEventButton.tscn")
var file_list = DialogicUtil.listdir("res://addons/dialogic/Events/", false)
for file in file_list:
var event_script = load("res://addons/dialogic/Events/" + file + "/event.gd")
var event_resource = event_script.new()
if event_resource.disable_editor_button == true: continue
var button = buttonScene.instance()
button.resource = event_resource
button.visible_name = ' ' + event_resource.event_name
button.set_icon(event_resource.get_icon())
button.event_color = event_resource.event_color
button.event_category = event_resource.event_category
button.event_sorting_index = event_resource.event_sorting_index


button.connect('pressed', self, "_add_event_button_pressed", [event_script])

get_node("View/ScrollContainer/EventContainer/FlexContainer" + str(button.event_category)).add_child(button)


var event_script = load("res://addons/dialogic/Events/" + file + "/event.gd")
var event_resource = event_script.new()
if event_resource.disable_editor_button == true: continue
var button = buttonScene.instance()
button.resource = event_resource
button.visible_name = ' ' + event_resource.event_name
button.set_icon(event_resource.get_icon())
button.event_color = event_resource.event_color
button.event_category = event_resource.event_category
button.event_sorting_index = event_resource.event_sorting_index


button.connect('pressed', self, "_add_event_button_pressed", [event_script])

get_node("View/ScrollContainer/EventContainer/FlexContainer" + str(button.event_category)).add_child(button)
while event_resource.event_sorting_index < get_node("View/ScrollContainer/EventContainer/FlexContainer" + str(button.event_category)).get_child(max(0, button.get_index()-1)).resource.event_sorting_index:
get_node("View/ScrollContainer/EventContainer/FlexContainer" + str(button.event_category)).move_child(button, button.get_index()-1)


# handles dragging/moving of events
Expand Down
1 change: 0 additions & 1 deletion addons/dialogic/Events/Condition/event.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
tool
extends DialogicEvent

class_name DialogicConditionEvent

enum ConditionTypes {IF, ELIF, ELSE}
Expand Down
1 change: 0 additions & 1 deletion addons/dialogic/Events/End Branch/event.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
tool
extends DialogicEvent

class_name DialogicEndBranchEvent

var this_is_an_end_event
Expand Down
4 changes: 2 additions & 2 deletions addons/dialogic/Events/End/event.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
tool
extends DialogicEvent

class_name DialogicEndTimelineEvent

# DEFINE ALL PROPERTIES OF THE EVENT

Expand All @@ -20,7 +20,7 @@ func _init() -> void:
event_name = "End Timeline"
event_color = Color("#f04438")
event_category = Category.TIMELINE
event_sorting_index = 3
event_sorting_index = 10



Expand Down
52 changes: 52 additions & 0 deletions addons/dialogic/Events/Jump/event.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
tool
extends DialogicEvent
class_name DialogicChangeTimelineEvent

# DEFINE ALL PROPERTIES OF THE EVENT
var Timeline :DialogicTimeline = null
var Label : String = ""

func _execute() -> void:
if Timeline and Timeline != dialogic_game_handler.current_timeline:
print("---------------switching timelines----------------")
dialogic_game_handler.start_timeline(Timeline, Label)
elif Label:
dialogic_game_handler.jump_to_label(Label)
finish()


################################################################################
## INITIALIZE
################################################################################

# SET ALL VALUES THAT SHOULD NEVER CHANGE HERE
func _init() -> void:
event_name = "Jump"
event_color = Color("#12b76a")
event_category = Category.TIMELINE
event_sorting_index = 0



################################################################################
## SAVING/LOADING
################################################################################
func get_shortcode() -> String:
return "jump"

func get_shortcode_parameters() -> Dictionary:
return {
#param_name : property_name
"timeline" : "Timeline",
"label" : "Label",
}


################################################################################
## EDITOR REPRESENTATION
################################################################################

func build_event_editor():
add_header_edit('Timeline', ValueType.Timeline, 'Timeline:')
add_header_edit('Label', ValueType.SinglelineText, 'Label:')

File renamed without changes
Original file line number Diff line number Diff line change
@@ -1,41 +1,36 @@
tool
extends DialogicEvent

class_name DialogicLabelEvent

# DEFINE ALL PROPERTIES OF THE EVENT
var Timeline :DialogicTimeline = null
var Anchor : String = ""
var Name :String = ""

func _execute() -> void:
if Timeline:
dialogic_game_handler.start_timeline(Timeline)
else:
finish()

finish()

################################################################################
## INITIALIZE
################################################################################

# SET ALL VALUES THAT SHOULD NEVER CHANGE HERE
func _init() -> void:
event_name = "Change Timeline"
event_name = "Label"
event_color = Color("#12b76a")
event_category = Category.TIMELINE
event_sorting_index = 0

event_sorting_index = 1
continue_at_end = true


################################################################################
## SAVING/LOADING
################################################################################
func get_shortcode() -> String:
return "change_timeline"
return "label"

func get_shortcode_parameters() -> Dictionary:
return {
#param_name : property_name
"path" : "Timeline",
"name" : "Name",
}


Expand All @@ -44,5 +39,4 @@ func get_shortcode_parameters() -> Dictionary:
################################################################################

func build_event_editor():
add_header_edit('Timeline', ValueType.Timeline, 'Timeline:')

add_header_edit('Name', ValueType.SinglelineText, '')
File renamed without changes
2 changes: 1 addition & 1 deletion addons/dialogic/Events/Signal/event.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
tool
extends DialogicEvent

class_name DialogicSignalEvent

# DEFINE ALL PROPERTIES OF THE EVENT
var Argument: String = ""
Expand Down
4 changes: 0 additions & 4 deletions addons/dialogic/Events/Text/event.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ func _init() -> void:
event_sorting_index = 0
help_page_path = "https://dialogic.coppolaemilio.com/documentation/Events/000/"
continue_at_end = false
# maybe using setters is better for this scenario?
# like doing:
#set_name("Pepito Event")
#set_color(Color.black)


func _execute() -> void:
Expand Down
2 changes: 1 addition & 1 deletion addons/dialogic/Events/Visual Background/event.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
tool
extends DialogicEvent

class_name DialogicBackgroundEvent

# DEFINE ALL PROPERTIES OF THE EVENT
var ImagePath: String = ""
Expand Down
4 changes: 2 additions & 2 deletions addons/dialogic/Events/Wait/event.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
tool
extends DialogicEvent

class_name DialogicWaitEvent

# DEFINE ALL PROPERTIES OF THE EVENT
var SecondsTime :float = 1.0
Expand All @@ -20,7 +20,7 @@ func _init() -> void:
event_name = "Wait"
event_color = Color("#657084")
event_category = Category.TIMELINE
event_sorting_index = 0
event_sorting_index = 5


################################################################################
Expand Down
18 changes: 17 additions & 1 deletion addons/dialogic/Other/DialogicGameHandler.gd
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func _input(event:InputEvent) -> void:
################################################################################
## TIMELINE+EVENT HANDLING
################################################################################
func start_timeline(timeline_resource) -> void:
func start_timeline(timeline_resource, label = "") -> void:
# load the resource if only the path is given
if typeof(timeline_resource) == TYPE_STRING:
timeline_resource = load(timeline_resource)
Expand All @@ -42,6 +42,9 @@ func start_timeline(timeline_resource) -> void:
current_timeline_events = current_timeline.get_events()
current_event_idx = -1

if label:
jump_to_label(label)

handle_next_event()


Expand Down Expand Up @@ -72,6 +75,19 @@ func handle_event(event_index:int) -> void:
event.connect("event_finished", self, 'handle_next_event')
event.execute(self)


func jump_to_label(label:String) -> void:
var idx = -1
while true:
idx += 1
var event = current_timeline.get_event(idx)
if not event:
idx = current_event_idx
break
if event is DialogicLabelEvent and event.Name == label:
break
current_event_idx = idx

################################################################################
## DISPLAY NODES
################################################################################
Expand Down
3 changes: 2 additions & 1 deletion addons/dialogic/Other/DialogicUtil.gd
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ static func get_event_by_string(string:String) -> Resource:
for event in [ # the text event should always be last.
# Every event that isn't identified as something else, will end up as text
# We should get this list from a folder or something, but then we'll have to sort it somehow
"res://addons/dialogic/Events/Label/event.gd",
"res://addons/dialogic/Events/End/event.gd",
"res://addons/dialogic/Events/Change Timeline/event.gd",
"res://addons/dialogic/Events/Jump/event.gd",
"res://addons/dialogic/Events/Visual Background/event.gd",
"res://addons/dialogic/Events/Signal/event.gd",
"res://addons/dialogic/Events/Wait/event.gd",
Expand Down
9 changes: 5 additions & 4 deletions addons/dialogic/Resources/event.gd
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,11 @@ func get_as_string_to_store() -> String:
var result_string = "["+self.get_shortcode()
var params = get_shortcode_parameters()
for parameter in params.keys():
if typeof(get(params[parameter])) == TYPE_OBJECT:
result_string += " "+parameter+'="'+str(get(params[parameter]).resource_path)+'"'
else:
result_string += " "+parameter+'="'+str(get(params[parameter]))+'"'
if get(params[parameter]):
if typeof(get(params[parameter])) == TYPE_OBJECT:
result_string += " "+parameter+'="'+str(get(params[parameter]).resource_path)+'"'
else:
result_string += " "+parameter+'="'+str(get(params[parameter]))+'"'
result_string += "]"
return result_string

Expand Down

0 comments on commit 7f05e22

Please sign in to comment.