Skip to content

Feature: Play from here #2535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions addons/dialogic/Core/DialogicGameHandler.gd
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ func _ready() -> void:
## Method to start a timeline AND ensure that a layout scene is present.
## For argument info, checkout [method start_timeline].
## -> returns the layout node
func start(timeline:Variant, label:Variant="") -> Node:
func start(timeline:Variant, label_or_idx:Variant="") -> Node:
# If we don't have a style subsystem, default to just start_timeline()
if not has_subsystem('Styles'):
printerr("[Dialogic] You called Dialogic.start() but the Styles subsystem is missing!")
clear(ClearFlags.KEEP_VARIABLES)
start_timeline(timeline, label)
start_timeline(timeline, label_or_idx)
return null

# Otherwise make sure there is a style active.
Expand All @@ -183,9 +183,9 @@ func start(timeline:Variant, label:Variant="") -> Node:

if not scene.is_node_ready():
scene.ready.connect(clear.bind(ClearFlags.KEEP_VARIABLES))
scene.ready.connect(start_timeline.bind(timeline, label))
scene.ready.connect(start_timeline.bind(timeline, label_or_idx))
else:
start_timeline(timeline, label)
start_timeline(timeline, label_or_idx)

return scene

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ var current_event: Node = null

func _ready() -> void:
clear()
add_icon_item(get_theme_icon("Duplicate", "EditorIcons"), "Duplicate")
add_icon_item(get_theme_icon("Duplicate", "EditorIcons"), "Duplicate", 0)
add_separator()
add_icon_item(get_theme_icon("Help", "EditorIcons"), "Documentation")
add_icon_item(get_theme_icon("CodeHighlighter", "EditorIcons"), "Open Code")
add_icon_item(get_theme_icon("PlayStart", "EditorIcons"), "Play from here", 1)
add_separator()
add_icon_item(get_theme_icon("ArrowUp", "EditorIcons"), "Move up")
add_icon_item(get_theme_icon("ArrowDown", "EditorIcons"), "Move down")
add_icon_item(get_theme_icon("Help", "EditorIcons"), "Documentation", 2)
add_icon_item(get_theme_icon("CodeHighlighter", "EditorIcons"), "Open Code", 3)
add_separator()
add_icon_item(get_theme_icon("Remove", "EditorIcons"), "Delete")
add_icon_item(get_theme_icon("ArrowUp", "EditorIcons"), "Move up", 4)
add_icon_item(get_theme_icon("ArrowDown", "EditorIcons"), "Move down", 5)
add_separator()
add_icon_item(get_theme_icon("Remove", "EditorIcons"), "Delete", 6)

var menu_background := StyleBoxFlat.new()
menu_background.bg_color = get_parent().get_theme_color("base_color", "Editor")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ func _ready() -> void:
syntax_highlighter = code_completion_helper.syntax_highlighter
timeline_editor.editors_manager.sidebar.content_item_activated.connect(_on_content_item_clicked)

get_menu().add_icon_item(get_theme_icon("PlayStart", "EditorIcons"), "Play from here", 42)
get_menu().id_pressed.connect(_on_context_menu_id_pressed)


func _on_text_editor_text_changed() -> void:
timeline_editor.current_resource_state = DialogicEditor.ResourceStates.UNSAVED
Expand Down Expand Up @@ -73,6 +76,15 @@ func text_timeline_to_array(text:String) -> Array:
## HELPFUL EDITOR FUNCTIONALITY
################################################################################

func _on_context_menu_id_pressed(id:int) -> void:
if id == 42:
play_from_here()


func play_from_here() -> void:
timeline_editor.play_timeline(timeline_editor.current_resource.get_index_from_text_line(text, get_caret_line()))


func _gui_input(event):
if not event is InputEventKey: return
if not event.is_pressed(): return
Expand All @@ -90,6 +102,11 @@ func _gui_input(event):

"Ctrl+Shift+D", "Ctrl+D":
duplicate_lines()

"Ctrl+F6" when OS.get_name() != "macOS": # Play from here
play_from_here()
"Ctrl+Shift+B" when OS.get_name() == "macOS": # Play from here
play_from_here()
_:
return
get_viewport().set_input_as_handled()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -938,25 +938,30 @@ func indent_events() -> void:
#region SPECIAL BLOCK OPERATIONS
################################################################################

func _on_event_popup_menu_index_pressed(index:int) -> void:
func _on_event_popup_menu_id_pressed(id:int) -> void:
var item: Control = %EventPopupMenu.current_event
if index == 0:
if id == 0:
if not item in selected_items:
selected_items = [item]
duplicate_selected()
elif index == 2:

elif id == 1:
play_from_here(%EventPopupMenu.current_event.get_index())

elif id == 2:
if not item.resource.help_page_path.is_empty():
OS.shell_open(item.resource.help_page_path)
elif index == 3:

elif id == 3:
find_parent('EditorView').plugin_reference.get_editor_interface().set_main_screen_editor('Script')
find_parent('EditorView').plugin_reference.get_editor_interface().edit_script(item.resource.get_script(), 1, 1)
elif index == 5 or index == 6:
if index == 5:
elif id == 4 or id == 5:
if id == 4:
offset_blocks_by_index(selected_items, -1)
else:
offset_blocks_by_index(selected_items, +1)

elif index == 8:
elif id == 6:
var events_indexed : Dictionary
if item in selected_items:
events_indexed = get_events_indexed(selected_items)
Expand All @@ -969,6 +974,12 @@ func _on_event_popup_menu_index_pressed(index:int) -> void:
indent_events()


func play_from_here(index:=-1) -> void:
if index == -1:
if not selected_items.is_empty():
index = selected_items[0].get_index()
timeline_editor.play_timeline(index)

func _on_right_sidebar_resized() -> void:
var _scale := DialogicUtil.get_editor_scale()

Expand Down Expand Up @@ -1078,6 +1089,11 @@ func _input(event:InputEvent) -> void:
_add_event_button_pressed(DialogicLabelEvent.new(), true)
get_viewport().set_input_as_handled()

"Ctrl+F6" when OS.get_name() != "macOS": # Play from here
play_from_here()
"Ctrl+Shift+B" when OS.get_name() == "macOS": # Play from here
play_from_here()

## Some shortcuts should be disabled when writing text.
var focus_owner: Control = get_viewport().gui_get_focus_owner()
if focus_owner is TextEdit or focus_owner is LineEdit or (focus_owner is Button and focus_owner.get_parent_control().name == "Spin"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

[ext_resource type="Script" path="res://addons/dialogic/Editor/TimelineEditor/VisualEditor/timeline_editor_visual.gd" id="1_8smxc"]
[ext_resource type="Theme" uid="uid://cqst728xxipcw" path="res://addons/dialogic/Editor/Theme/MainTheme.tres" id="2_x0fhp"]
[ext_resource type="Script" uid="uid://bigjdicunph7y" path="res://addons/dialogic/Editor/TimelineEditor/VisualEditor/TimelineArea.gd" id="3_sap1x"]
[ext_resource type="Script" path="res://addons/dialogic/Editor/TimelineEditor/VisualEditor/TimelineArea.gd" id="3_sap1x"]
[ext_resource type="Script" path="res://addons/dialogic/Editor/Events/EventBlock/event_right_click_menu.gd" id="4_ugiq6"]

[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_phyjj"]
content_margin_top = 10.0

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_qtla0"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_6gqu8"]
bg_color = Color(0, 0, 0, 1)

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_3omuv"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_jujwh"]
content_margin_left = 4.0
content_margin_top = 4.0
content_margin_right = 4.0
Expand All @@ -24,7 +24,7 @@ border_width_right = 2
border_width_bottom = 2
corner_detail = 1

[sub_resource type="Image" id="Image_6gdod"]
[sub_resource type="Image" id="Image_h7ek6"]
data = {
"data": PackedByteArray(255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 231, 255, 94, 94, 54, 255, 94, 94, 57, 255, 93, 93, 233, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 231, 255, 94, 94, 54, 255, 94, 94, 57, 255, 93, 93, 233, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 93, 93, 233, 255, 93, 93, 232, 255, 93, 93, 41, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 93, 93, 233, 255, 93, 93, 232, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 44, 255, 255, 255, 0, 255, 97, 97, 42, 255, 97, 97, 42, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 44, 255, 255, 255, 0, 255, 97, 97, 42, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 235, 255, 94, 94, 234, 255, 95, 95, 43, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 235, 255, 94, 94, 234, 255, 95, 95, 43, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 235, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 233, 255, 95, 95, 59, 255, 96, 96, 61, 255, 93, 93, 235, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 233, 255, 95, 95, 59, 255, 96, 96, 61, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0),
"format": "RGBA8",
Expand All @@ -33,8 +33,8 @@ data = {
"width": 16
}

[sub_resource type="ImageTexture" id="ImageTexture_brv5s"]
image = SubResource("Image_6gdod")
[sub_resource type="ImageTexture" id="ImageTexture_xe7d2"]
image = SubResource("Image_h7ek6")

[node name="TimelineVisualEditor" type="MarginContainer"]
anchors_preset = 15
Expand Down Expand Up @@ -70,31 +70,31 @@ size_flags_vertical = 3
[node name="EventPopupMenu" type="PopupMenu" parent="View/TimelineArea"]
unique_name_in_owner = true
size = Vector2i(165, 124)
theme_override_styles/panel = SubResource("StyleBoxFlat_qtla0")
theme_override_styles/hover = SubResource("StyleBoxFlat_3omuv")
theme_override_styles/panel = SubResource("StyleBoxFlat_6gqu8")
theme_override_styles/hover = SubResource("StyleBoxFlat_jujwh")
item_count = 9
item_0/text = "Duplicate"
item_0/icon = SubResource("ImageTexture_brv5s")
item_0/icon = SubResource("ImageTexture_xe7d2")
item_1/id = -1
item_1/separator = true
item_2/text = "Documentation"
item_2/icon = SubResource("ImageTexture_brv5s")
item_2/icon = SubResource("ImageTexture_xe7d2")
item_2/id = 2
item_3/text = "Open Code"
item_3/icon = SubResource("ImageTexture_brv5s")
item_3/icon = SubResource("ImageTexture_xe7d2")
item_3/id = 3
item_4/id = -1
item_4/separator = true
item_5/text = "Move up"
item_5/icon = SubResource("ImageTexture_brv5s")
item_5/icon = SubResource("ImageTexture_xe7d2")
item_5/id = 5
item_6/text = "Move down"
item_6/icon = SubResource("ImageTexture_brv5s")
item_6/icon = SubResource("ImageTexture_xe7d2")
item_6/id = 6
item_7/id = -1
item_7/separator = true
item_8/text = "Delete"
item_8/icon = SubResource("ImageTexture_brv5s")
item_8/icon = SubResource("ImageTexture_xe7d2")
item_8/id = 8
script = ExtResource("4_ugiq6")

Expand All @@ -112,5 +112,5 @@ size_flags_vertical = 3
size_flags_stretch_ratio = 0.2

[connection signal="drag_completed" from="View/TimelineArea" to="." method="_on_timeline_area_drag_completed"]
[connection signal="index_pressed" from="View/TimelineArea/EventPopupMenu" to="." method="_on_event_popup_menu_index_pressed"]
[connection signal="id_pressed" from="View/TimelineArea/EventPopupMenu" to="." method="_on_event_popup_menu_id_pressed"]
[connection signal="resized" from="View/RightSidebar" to="." method="_on_right_sidebar_resized"]
22 changes: 17 additions & 5 deletions addons/dialogic/Editor/TimelineEditor/shortcut_popup.gd
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ var shortcuts := [
{"shortcut":"Alt/Opt+Down", "text":"Move selected events/lines down"},
{},
{"shortcut":"Ctrl+F", "text":"Search"},
{},
{"shortcut":"Ctrl+F5", "text":"Play timeline", "platform":"-macOS"},
{"shortcut":"Ctrl+B", "text":"Play timeline", "platform":"macOS"},
{"shortcut":"Ctrl+F6", "text":"Play timeline from here", "platform":"-macOS"},
{"shortcut":"Ctrl+Shift+B", "text":"Play timeline from here", "platform":"macOS"},

{},
{"shortcut":"Ctrl+C", "text":"Copy"},
Expand All @@ -42,20 +47,26 @@ func _ready() -> void:
%CloseShortcutPanel.icon = get_theme_icon("Close", "EditorIcons")
get_theme_stylebox("panel").bg_color = get_theme_color("dark_color_3", "Editor")


func reload_shortcuts() -> void:
for i in %ShortcutList.get_children():
i.queue_free()


var is_text_editor: bool = %TextEditor.visible
for i in shortcuts:
if i.is_empty():
%ShortcutList.add_child(HSeparator.new())
%ShortcutList.add_child(HSeparator.new())
continue

if "editor" in i and not get_node("%"+i.editor).visible:
continue

if "platform" in i:
var platform := OS.get_name()
if not (platform == i.platform.trim_prefix("-") != i.platform.begins_with("-")):
continue

var hbox := HBoxContainer.new()
hbox.add_theme_constant_override("separation", 0)
for key_text in i.shortcut.split("+"):
Expand All @@ -64,17 +75,17 @@ func reload_shortcuts() -> void:
plus_l.text = "+"
hbox.add_child(plus_l)



var key := Button.new()
if key_text == "Up":
key.icon = get_theme_icon("ArrowUp", "EditorIcons")
elif key_text == "Down":
key.icon = get_theme_icon("ArrowDown", "EditorIcons")
else:
key_text = key_text.replace("Alt/Opt", "Opt" if OS.get_name() == "macOS" else "Alt")
key.text = key_text
key.disabled = true
key.theme_type_variation = "ShortcutKeyLabel"
key.add_theme_font_override("font", get_theme_font("source", "EditorFonts"))
hbox.add_child(key)

%ShortcutList.add_child(hbox)
Expand All @@ -89,12 +100,13 @@ func open():
if visible:
close()
return

reload_shortcuts()

show()
size = get_parent().size - Vector2(200, 200)*DialogicUtil.get_editor_scale()
await get_tree().process_frame
size = get_parent().size - Vector2(100, 100)*DialogicUtil.get_editor_scale()
size.x = %ShortcutList.get_minimum_size().x + 100
size.y = min(size.y, %ShortcutList.get_minimum_size().y+100)
global_position = get_parent().global_position+get_parent().size/2-size/2


Expand Down
4 changes: 2 additions & 2 deletions addons/dialogic/Editor/TimelineEditor/test_timeline_scene.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ func _ready() -> void:

randomize()
var current_timeline: String = DialogicUtil.get_editor_setting("current_timeline_path", "")
var start_from_index: int = DialogicUtil.get_editor_setting("play_from_index", -1)
if not current_timeline:
get_tree().quit()
DialogicUtil.autoload().start(current_timeline)
DialogicUtil.autoload().start(current_timeline, start_from_index)
DialogicUtil.autoload().timeline_ended.connect(get_tree().quit)
DialogicUtil.autoload().signal_event.connect(receive_event_signal)
DialogicUtil.autoload().text_signal.connect(receive_text_signal)
Expand All @@ -41,4 +42,3 @@ func _input(event:InputEvent) -> void:

auto_skip.disable_on_unread_text = false
auto_skip.enabled = not is_auto_skip_enabled

4 changes: 2 additions & 2 deletions addons/dialogic/Editor/TimelineEditor/timeline_editor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ func _input(event: InputEvent) -> void:


## Method to play the current timeline. Connected to the button in the sidebar.
func play_timeline() -> void:
func play_timeline(index := -1) -> void:
_save()

var dialogic_plugin := DialogicUtil.get_dialogic_plugin()

# Save the current opened timeline
DialogicUtil.set_editor_setting('current_timeline_path', current_resource.resource_path)

DialogicUtil.set_editor_setting('play_from_index', index)
DialogicUtil.get_dialogic_plugin().get_editor_interface().play_custom_scene("res://addons/dialogic/Editor/TimelineEditor/test_timeline_scene.tscn")


Expand Down
Loading