From b8eb90cbf778e02a5e4751effa045e54ba66069f Mon Sep 17 00:00:00 2001 From: Bram Dingelstad Date: Tue, 7 Dec 2021 12:12:33 +0100 Subject: [PATCH] feat: Added a pane for previewing dialogue --- ExampleDialogue/Sally.yarn | 63 +++++++++++------------ addons/Wol/Wol.gd | 8 +++ addons/Wol/core/compiler/Compiler.gd | 6 +-- addons/Wol/editor/Editor.gd | 19 ++++--- addons/Wol/editor/Preview.gd | 76 ++++++++++++++++++++++++++++ addons/Wol/editor/WolEditor.gd | 11 ++-- addons/Wol/editor/WolEditor.tscn | 4 +- 7 files changed, 138 insertions(+), 49 deletions(-) create mode 100644 addons/Wol/editor/Preview.gd diff --git a/ExampleDialogue/Sally.yarn b/ExampleDialogue/Sally.yarn index 0101a35..5147c7d 100644 --- a/ExampleDialogue/Sally.yarn +++ b/ExampleDialogue/Sally.yarn @@ -1,7 +1,35 @@ +title: Sally.Watch +tags: +colorID: +position: 500, 400 +--- +Sally: Not really. #line:8c3f98 +Sally: Same old nebula, doing the same old thing. #line:24c418 +Sally: Oh, Ship wanted to see you. Go say hi to it. #line:df4eaf +<> +<> + Player: Already done! #line:1fea6c + Sally: Go say hi again. #line:5df323 +<> +=== +title: Sally.Exit +tags: +colorID: +position: 100, 400 +--- +Sally: Bye. #line:60c282 +=== +title: Sally.Sorry +tags: +colorID: +position: 900, 400 +--- +Sally: Yeah. Don't do it again. #line:d7df49 +=== title: Sally tags: -colorID: 0 -position: 524,111 +colorID: +position: 500, 100 --- <> Player: Hey, Sally. #line:794945 @@ -22,34 +50,3 @@ position: 524,111 <> [[See you later.|Sally.Exit]] #line:0facf7 === - -title: Sally.Watch -tags: -colorID: 0 -position: 512,430 ---- -Sally: Not really. #line:8c3f98 -Sally: Same old nebula, doing the same old thing. #line:24c418 -Sally: Oh, Ship wanted to see you. Go say hi to it. #line:df4eaf -<> -<> - Player: Already done! #line:1fea6c - Sally: Go say hi again. #line:5df323 -<> -=== - -title: Sally.Exit -tags: -colorID: 6 -position: 211,417 ---- -Sally: Bye. #line:60c282 -=== - -title: Sally.Sorry -tags: -colorID: 0 -position: 827,439 ---- -Sally: Yeah. Don't do it again. #line:d7df49 -=== diff --git a/addons/Wol/Wol.gd b/addons/Wol/Wol.gd index 8b20d44..2405459 100644 --- a/addons/Wol/Wol.gd +++ b/addons/Wol/Wol.gd @@ -55,6 +55,9 @@ func set_path(_path): var compiler = Compiler.new(path) virtual_machine.program = compiler.compile() +func set_program(program): + virtual_machine.program = program + func _on_line(line): if auto_substitute: var index = 0 @@ -106,5 +109,10 @@ func start(node = starting_node): virtual_machine.set_node(node) virtual_machine.start() +func stop(): + if running: + virtual_machine.call_deferred('stop') + running = false + func resume(): virtual_machine.call_deferred('resume') diff --git a/addons/Wol/core/compiler/Compiler.gd b/addons/Wol/core/compiler/Compiler.gd index 82996ff..3040453 100644 --- a/addons/Wol/core/compiler/Compiler.gd +++ b/addons/Wol/core/compiler/Compiler.gd @@ -1,5 +1,4 @@ extends Object - signal error(message, line_number, column) const Constants = preload('res://addons/Wol/core/Constants.gd') @@ -25,11 +24,12 @@ func _init(_filename, _source = null, _soft_assert = false): soft_assert = _soft_assert if not _filename and _source: - self.source = _source + filename = 'inline_source' + source = _source else: var file = File.new() file.open(_filename, File.READ) - self.source = file.get_as_text() + source = file.get_as_text() file.close() var source_lines = source.split('\n') diff --git a/addons/Wol/editor/Editor.gd b/addons/Wol/editor/Editor.gd index 3cc120b..47aac83 100644 --- a/addons/Wol/editor/Editor.gd +++ b/addons/Wol/editor/Editor.gd @@ -1,19 +1,21 @@ tool extends Panel -var current_node var current_graph_node +onready var preview = get_node('../Preview') + func _ready(): hide() connect('visibility_changed', self, '_on_visibility_changed') - $Close.connect('pressed', self, 'close') + $Tools/Left/Play.connect('pressed', self, '_on_play') + $Tools/Right/Close.connect('pressed', self, 'close') func close(): hide() + preview.close() -func open_node(graph_node, node): - current_node = node +func open_node(graph_node): current_graph_node = graph_node var text_edit = graph_node.get_node('TextEdit') @@ -21,9 +23,9 @@ func open_node(graph_node, node): $Content.add_child(text_edit) toggle_text_edit(text_edit) - $HBoxContainer/TextEdit.disconnect('text_changed', self, '_on_title_changed') - $HBoxContainer/TextEdit.text = node.title - $HBoxContainer/TextEdit.connect('text_changed', self, '_on_title_changed') + $Tools/Left/Title.disconnect('text_changed', self, '_on_title_changed') + $Tools/Left/Title.text = graph_node.node.title + $Tools/Left/Title.connect('text_changed', self, '_on_title_changed') show() @@ -50,6 +52,9 @@ func toggle_text_edit(text_edit): ]: text_edit.set(property, not text_edit.get(property)) +func _on_play(): + preview.open_node(current_graph_node) + func _on_title_changed(): current_graph_node.node.title = $HBoxContainer/TextEdit.text current_graph_node.compile() diff --git a/addons/Wol/editor/Preview.gd b/addons/Wol/editor/Preview.gd new file mode 100644 index 0000000..39f0991 --- /dev/null +++ b/addons/Wol/editor/Preview.gd @@ -0,0 +1,76 @@ +extends Panel + +var current_graph_node + +onready var line_template = $Content/List/LineTemplate +onready var button_template = $Options/List/ButtonTemplate + +onready var wol_editor = find_parent('WolEditor') + +func _ready(): + hide() + $Wol.connect('line', self, '_on_line') + $Wol.connect('options', self, '_on_options') + $Tools/Right/Close.connect('pressed', self, 'close') + +func open_node(graph_node): + current_graph_node = graph_node + + $Wol.stop() + + for child in $Content/List.get_children(): + if child != line_template and not 'Padding' in child.name: + $Content/List.remove_child(child) + child.queue_free() + + for child in $Options/List.get_children(): + if child != button_template: + $Options/List.remove_child(child) + child.queue_free() + + $Wol.variable_storage = {} + $Wol.set_program(wol_editor.get_program()) + $Wol.start(current_graph_node.node.title) + show() + +func close(): + hide() + current_graph_node = null + $Wol.stop() + +func next(): + $Wol.resume() + +func _on_line(line): + var line_node = line_template.duplicate() + $Content/List.add_child(line_node) + $Content/List/PaddingBottom.raise() + line_node.get_node('RichTextLabel').bbcode_text = line.text + line_node.show() + yield(get_tree(), 'idle_frame') + $Content.scroll_vertical = $Content/List.rect_size.y + +func _on_options(options): + for option in options: + var button = button_template.duplicate() + $Options/List.add_child(button) + + button.text = option.line.text + button.connect('pressed', self, '_on_option_pressed', [option]) + button.show() + +func _on_option_pressed(option): + $Wol.select_option(option.id) + + for child in $Options/List.get_children(): + if child != button_template: + $Options/List.remove_child(child) + child.queue_free() + +func _input(event): + if visible \ + and ( \ + (event is InputEventMouseButton and event.doubleclick) \ + or (event is InputEventKey and not event.pressed and event.scancode in [KEY_SPACE, KEY_ENTER]) \ + ): + next() diff --git a/addons/Wol/editor/WolEditor.gd b/addons/Wol/editor/WolEditor.gd index 7128090..5b4c891 100644 --- a/addons/Wol/editor/WolEditor.gd +++ b/addons/Wol/editor/WolEditor.gd @@ -37,7 +37,7 @@ func create_node(position = Vector2.ZERO): } graph_node.connect('recompiled', self, '_on_graph_node_recompiled', [graph_node]) - graph_node.connect('gui_input', self, '_on_graph_node_input', [graph_node, node]) + graph_node.connect('gui_input', self, '_on_graph_node_input', [graph_node]) graph_node.node = node graph_node.show() @@ -52,11 +52,14 @@ func build_nodes(): $GraphEdit.add_child(graph_node) graph_node.connect('recompiled', self, '_on_graph_node_recompiled', [graph_node]) - graph_node.connect('gui_input', self, '_on_graph_node_input', [graph_node, node]) + graph_node.connect('gui_input', self, '_on_graph_node_input', [graph_node]) graph_node.node = node graph_node.show() +func get_program(): + return Compiler.new(null, serialize_to_file(), true).compile() + func serialize_to_file(): var buffer = [] for graph_node in $GraphEdit.get_children(): @@ -153,10 +156,10 @@ func _on_graph_node_recompiled(_graph_node): yield(get_tree().create_timer(.3), 'timeout') refreshed = false -func _on_graph_node_input(event, graph_node, node): +func _on_graph_node_input(event, graph_node): if event is InputEventMouseButton \ and event.doubleclick and event.button_index == BUTTON_LEFT: - $HBoxContainer/Editor.open_node(graph_node, node) + $HBoxContainer/Editor.open_node(graph_node) accept_event() func _on_node_selected(node, selected): diff --git a/addons/Wol/editor/WolEditor.tscn b/addons/Wol/editor/WolEditor.tscn index 88db627..29f694f 100644 --- a/addons/Wol/editor/WolEditor.tscn +++ b/addons/Wol/editor/WolEditor.tscn @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c726947550552cda030c91eb876dbbb8d2840d9faeba9b90a6f428a43db140f4 -size 605185 +oid sha256:ef446d59a4c2bd4cf042b55abf92d9c816c2af021f81e6c8f6fd83a07ba75a55 +size 610584