From 3278d8187ed241fbc764d042e6ef5f14064586dd Mon Sep 17 00:00:00 2001 From: Jean-Yves Chasle Date: Sat, 22 Oct 2022 21:11:45 +0200 Subject: [PATCH] Infinite subtitles in node --- Assets/{ => Fonts}/Roboto-Bold.ttf | Bin Scenes/CommentGraphNode.tscn | 11 +++++ Scenes/DisplayDialog.tscn | 65 ++++++++++++++--------------- Scenes/ImageGraphNode.tscn | 26 +++++++++++- Scripts/CommentGraphNode.gd | 58 ++++++++++++++----------- Scripts/DisplayDialog.gd | 9 ++-- Scripts/ImageGraphNode.gd | 20 +++++++-- 7 files changed, 124 insertions(+), 65 deletions(-) rename Assets/{ => Fonts}/Roboto-Bold.ttf (100%) diff --git a/Assets/Roboto-Bold.ttf b/Assets/Fonts/Roboto-Bold.ttf similarity index 100% rename from Assets/Roboto-Bold.ttf rename to Assets/Fonts/Roboto-Bold.ttf diff --git a/Scenes/CommentGraphNode.tscn b/Scenes/CommentGraphNode.tscn index ba00d3a..e82c9e8 100644 --- a/Scenes/CommentGraphNode.tscn +++ b/Scenes/CommentGraphNode.tscn @@ -29,6 +29,7 @@ custom_styles/commentfocus = ExtResource( 17 ) custom_styles/comment = ExtResource( 17 ) title = "Title" show_close = true +resizable = true comment = true slot/0/left_enabled = false slot/0/left_type = 0 @@ -120,8 +121,18 @@ margin_bottom = 24.0 rect_min_size = Vector2( 28, 24 ) hint_tooltip = "Frame background color" +[node name="UserText" type="TextEdit" parent="VBoxContainer"] +margin_top = 28.0 +margin_right = 224.0 +margin_bottom = 48.0 +rect_min_size = Vector2( 0, 20 ) +size_flags_horizontal = 3 +size_flags_vertical = 3 +wrap_enabled = true + [connection signal="close_request" from="." to="." method="_on_CommentNode_close_request"] [connection signal="dragged" from="." to="." method="_on_CommentNode_dragged"] +[connection signal="resize_request" from="." to="." method="_on_CommentNode_resize_request"] [connection signal="pressed" from="VBoxContainer/HBoxContainer/HBoxContainer2/AddButton" to="." method="_on_AddButton_pressed"] [connection signal="pressed" from="VBoxContainer/HBoxContainer/HBoxContainer2/SubButton" to="." method="_on_SubButton_pressed"] [connection signal="color_changed" from="VBoxContainer/HBoxContainer/HBoxContainer2/ColorPicker" to="." method="_on_ColorPicker_color_changed"] diff --git a/Scenes/DisplayDialog.tscn b/Scenes/DisplayDialog.tscn index f8e93ba..f65cab9 100644 --- a/Scenes/DisplayDialog.tscn +++ b/Scenes/DisplayDialog.tscn @@ -14,7 +14,7 @@ [ext_resource path="res://Assets/Icons/SoundFile.svg" type="Texture" id=12] [sub_resource type="DynamicFontData" id=1] -font_path = "res://Assets/Roboto-Bold.ttf" +font_path = "res://Assets/Fonts/Roboto-Bold.ttf" [sub_resource type="DynamicFont" id=2] size = 30 @@ -61,20 +61,17 @@ stretch_mode = 6 anchor_top = 1.0 anchor_right = 1.0 anchor_bottom = 1.0 -margin_left = 128.0 -margin_top = -132.0 -margin_right = -128.0 +margin_top = -671.0 +margin_bottom = -9.0 custom_colors/font_color = Color( 1, 0.976471, 0.87451, 1 ) custom_colors/font_outline_modulate = Color( 0, 0, 0, 1 ) custom_colors/font_color_shadow = Color( 0, 0, 0, 1 ) custom_constants/shadow_as_outline = 1 custom_fonts/font = SubResource( 2 ) -text = "pdvjpnj\\\\npn -njpn pkn kn pkn " align = 1 -valign = 1 +valign = 2 +autowrap = true clip_text = true -max_lines_visible = 2 [node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"] margin_top = 675.0 @@ -83,7 +80,7 @@ margin_bottom = 715.0 alignment = 1 [node name="SubtitleEdit" type="TextEdit" parent="VBoxContainer/HBoxContainer"] -margin_right = 679.0 +margin_right = 647.0 margin_bottom = 40.0 rect_min_size = Vector2( 0, 22 ) hint_tooltip = "Subtitles" @@ -91,65 +88,65 @@ size_flags_horizontal = 3 wrap_enabled = true [node name="FirstButton" type="Button" parent="VBoxContainer/HBoxContainer"] -margin_left = 683.0 -margin_right = 707.0 +margin_left = 651.0 +margin_right = 675.0 margin_bottom = 40.0 hint_tooltip = "First frame" icon = ExtResource( 8 ) [node name="PrevButton" type="Button" parent="VBoxContainer/HBoxContainer"] -margin_left = 711.0 -margin_right = 735.0 +margin_left = 679.0 +margin_right = 703.0 margin_bottom = 40.0 hint_tooltip = " Previous frame" icon = ExtResource( 3 ) [node name="PlayButton" type="Button" parent="VBoxContainer/HBoxContainer"] -margin_left = 739.0 -margin_right = 767.0 +margin_left = 707.0 +margin_right = 735.0 margin_bottom = 40.0 hint_tooltip = "Play/pause" icon = ExtResource( 7 ) [node name="StopButton" type="Button" parent="VBoxContainer/HBoxContainer"] -margin_left = 771.0 -margin_right = 799.0 +margin_left = 739.0 +margin_right = 767.0 margin_bottom = 40.0 hint_tooltip = "Stop playback" icon = ExtResource( 6 ) [node name="NextButton" type="Button" parent="VBoxContainer/HBoxContainer"] -margin_left = 803.0 -margin_right = 827.0 +margin_left = 771.0 +margin_right = 795.0 margin_bottom = 40.0 hint_tooltip = " Next frame" icon = ExtResource( 5 ) [node name="LastButton" type="Button" parent="VBoxContainer/HBoxContainer"] -margin_left = 831.0 -margin_right = 855.0 +margin_left = 799.0 +margin_right = 823.0 margin_bottom = 40.0 hint_tooltip = "Last frame" icon = ExtResource( 4 ) [node name="LoopButton" type="CheckButton" parent="VBoxContainer/HBoxContainer"] -margin_left = 859.0 -margin_right = 951.0 +margin_left = 827.0 +margin_right = 919.0 margin_bottom = 40.0 hint_tooltip = "Loop" icon = ExtResource( 9 ) [node name="Label" type="Label" parent="VBoxContainer/HBoxContainer"] -margin_left = 955.0 +margin_left = 923.0 margin_top = 13.0 -margin_right = 1018.0 +margin_right = 986.0 margin_bottom = 27.0 text = "Duration: " valign = 1 [node name="SpinBox" type="SpinBox" parent="VBoxContainer/HBoxContainer"] -margin_left = 1022.0 -margin_right = 1096.0 +margin_left = 990.0 +margin_right = 1064.0 margin_bottom = 40.0 hint_tooltip = "Frame duration (in seconds)" min_value = 0.1 @@ -161,23 +158,23 @@ align = 3 suffix = "s" [node name="LoadButton" type="Button" parent="VBoxContainer/HBoxContainer"] -margin_left = 1100.0 -margin_right = 1128.0 +margin_left = 1068.0 +margin_right = 1096.0 margin_bottom = 40.0 hint_tooltip = "Load image from file" icon = ExtResource( 11 ) [node name="SoundButton" type="Button" parent="VBoxContainer/HBoxContainer"] -margin_left = 1132.0 -margin_right = 1160.0 +margin_left = 1100.0 +margin_right = 1128.0 margin_bottom = 40.0 hint_tooltip = "Load sound from file" icon = ExtResource( 12 ) [node name="DelSoundButton" type="Button" parent="VBoxContainer/HBoxContainer"] -margin_left = 209.0 -margin_right = 237.0 -margin_bottom = 24.0 +margin_left = 1132.0 +margin_right = 1160.0 +margin_bottom = 40.0 hint_tooltip = "Remove sound" icon = ExtResource( 2 ) diff --git a/Scenes/ImageGraphNode.tscn b/Scenes/ImageGraphNode.tscn index 3d4053b..3df1988 100644 --- a/Scenes/ImageGraphNode.tscn +++ b/Scenes/ImageGraphNode.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=9 format=2] +[gd_scene load_steps=11 format=2] [ext_resource path="res://Resources/SelectedFrame.tres" type="StyleBox" id=1] [ext_resource path="res://Resources/NormalFrame.tres" type="StyleBox" id=2] @@ -9,6 +9,16 @@ [ext_resource path="res://Assets/Icons/SoundFile.svg" type="Texture" id=7] [ext_resource path="res://Assets/Icons/Remove.svg" type="Texture" id=8] +[sub_resource type="DynamicFontData" id=1] +font_path = "res://Assets/Fonts/Roboto-Bold.ttf" + +[sub_resource type="DynamicFont" id=2] +size = 8 +outline_size = 1 +outline_color = Color( 0, 0, 0, 1 ) +use_filter = true +font_data = SubResource( 1 ) + [node name="GraphNode" type="GraphNode"] margin_right = 232.0 margin_bottom = 197.0 @@ -60,6 +70,19 @@ size_flags_vertical = 3 expand = true stretch_mode = 6 +[node name="Subtitle" type="Label" parent="VBoxContainer/Control"] +anchor_right = 1.0 +anchor_bottom = 1.0 +custom_colors/font_color = Color( 1, 0.976471, 0.87451, 1 ) +custom_colors/font_outline_modulate = Color( 0, 0, 0, 1 ) +custom_colors/font_color_shadow = Color( 0, 0, 0, 1 ) +custom_constants/shadow_as_outline = 1 +custom_fonts/font = SubResource( 2 ) +align = 1 +valign = 2 +autowrap = true +clip_text = true + [node name="SubtitleEdit" type="TextEdit" parent="VBoxContainer"] margin_top = 117.0 margin_right = 269.0 @@ -132,6 +155,7 @@ icon_align = 1 [connection signal="resize_request" from="." to="." method="_on_GraphNode_resize_request"] [connection signal="focus_entered" from="VBoxContainer/Control/Thumbnail" to="." method="_on_TextureRect_focus_entered"] [connection signal="gui_input" from="VBoxContainer/Control/Thumbnail" to="." method="_on_TextureRect_gui_input"] +[connection signal="text_changed" from="VBoxContainer/SubtitleEdit" to="." method="_on_SubtitleEdit_text_changed"] [connection signal="pressed" from="VBoxContainer/HBoxContainer/LoadButton" to="." method="_on_LoadButton_pressed"] [connection signal="pressed" from="VBoxContainer/HBoxContainer/SoundButton" to="." method="_on_SoundButton_pressed"] [connection signal="pressed" from="VBoxContainer/HBoxContainer/DelSoundButton" to="." method="_on_DelSoundButton_pressed"] diff --git a/Scripts/CommentGraphNode.gd b/Scripts/CommentGraphNode.gd index d60399b..05d984b 100644 --- a/Scripts/CommentGraphNode.gd +++ b/Scripts/CommentGraphNode.gd @@ -2,17 +2,16 @@ extends GraphNode class_name CommentGraphNode const DEFAULT_SIZE: = Vector2(230.0, 80.0) # graph space -const LEFT_MARGIN: = 24.0 # graph space -const TOP_MARGIN: = 64.0 # graph space -const RIGHT_MARGIN: = 24.0 # graph space -const BOTTOM_MARGIN: = 24.0 # graph space +const LEFT_MARGIN: = 16.0 # graph space +const TOP_MARGIN: = 80.0 # graph space +const RIGHT_MARGIN: = 16.0 # graph space +const BOTTOM_MARGIN: = 16.0 # graph space -var node_color: = Color.gray var img_nodes: = [] # array of ImageGraphNode var old_offset: Vector2 onready var colorpicker: = $VBoxContainer/HBoxContainer/HBoxContainer2/ColorPicker - +onready var user_text: = $VBoxContainer/UserText # Important to know: # rect_position is in viewport space, can't be set directly in code (use offset) @@ -20,6 +19,8 @@ onready var colorpicker: = $VBoxContainer/HBoxContainer/HBoxContainer2/ColorPick # rect_size is in graph space func _ready(): + assert(colorpicker) + assert(user_text) old_offset = offset @@ -31,7 +32,7 @@ func _exit_tree(): func get_extra_data() -> Dictionary: var extra_data = { "title": get_title(), - "color": node_color, + "color": colorpicker.color, "img_node_names": [] # filled hereafter } @@ -52,11 +53,10 @@ func set_extra_data(extra_data: Dictionary): func set_color(color: Color): - node_color = color colorpicker.color = color var custom_styles: StyleBox = get("custom_styles/comment") - custom_styles.bg_color = color - custom_styles.border_color = color + custom_styles.bg_color = colorpicker.color + custom_styles.border_color = colorpicker.color func _on_ColorPicker_color_changed(color): @@ -74,19 +74,16 @@ func has_img_node(node: ImageGraphNode): func add_img_node(node: ImageGraphNode, auto_update: bool): if not img_nodes.has(node): img_nodes.push_back(node) + update_size_options() if auto_update: update_size() print("img_nodes: ", img_nodes) - #var old_position = node.global_position -# get_parent().remove_child(node) -# add_child(node) - #node.set_owner(self) - #node.global_position = old_position func remove_img_node(node: ImageGraphNode, auto_update: bool): if img_nodes.has(node): img_nodes.erase(node) + update_size_options() if auto_update: update_size() print("img_nodes: ", img_nodes) @@ -94,13 +91,24 @@ func remove_img_node(node: ImageGraphNode, auto_update: bool): func purge_img_nodes(auto_update: bool): img_nodes.clear() + update_size_options() if auto_update: update_size() +func update_size_options(): + if img_nodes.empty(): + resizable = true + user_text.size_flags_vertical = SIZE_EXPAND_FILL + else: + resizable = false + user_text.size_flags_vertical = SIZE_FILL + + func update_size(): if img_nodes.empty(): set_size(DEFAULT_SIZE) # graph space + else: var rect: Rect2 var initialized: = false @@ -116,6 +124,17 @@ func update_size(): set_size(rect.size + Vector2(LEFT_MARGIN + RIGHT_MARGIN, TOP_MARGIN + BOTTOM_MARGIN)) # graph space +func _on_CommentNode_resize_request(new_size): + if not img_nodes.empty(): + return + var graph = get_parent() + assert(graph is GraphEdit) + if graph.is_using_snap(): + rect_size = graph.snap_position(new_size) + else: + rect_size = new_size + + func _on_CommentNode_close_request(): var graph = get_parent() assert(graph is GraphEdit) @@ -137,15 +156,6 @@ func _on_SubButton_pressed(): graph.remove_selected_img_nodes_from_comment_node(self) -func _on_CommentNode_resize_request(new_size): - var graph = get_parent() - assert(graph is GraphEdit) - if graph.is_using_snap(): - rect_size = graph.snap_position(new_size) - else: - rect_size = new_size - - func _on_CommentNode_offset_changed(): var diff = offset - old_offset for img_node in img_nodes: diff --git a/Scripts/DisplayDialog.gd b/Scripts/DisplayDialog.gd index 5b8077b..3427fa5 100644 --- a/Scripts/DisplayDialog.gd +++ b/Scripts/DisplayDialog.gd @@ -205,8 +205,11 @@ func display_node(index: int, play_sound: bool): node_chain_index = index var node: ImageGraphNode = node_chain[index] - var tex = load_image_from_file(node.img_path) - display_rect.texture = tex if tex else node.get_thumbnail_texture() + if node.img_path == "": + display_rect.texture = null + else: + var tex = load_image_from_file(node.img_path) + display_rect.texture = tex if tex else node.get_thumbnail_texture() if audio_player.is_playing(): audio_player.stop() @@ -243,7 +246,7 @@ func _on_SubtitleEdit_text_changed(): var node: ImageGraphNode = node_chain[node_chain_index] assert(node) subtitle.text = subedit.text - node.subedit.text = subedit.text + node.set_subtitle(subedit.text) func _on_SpinBox_value_changed(value): diff --git a/Scripts/ImageGraphNode.gd b/Scripts/ImageGraphNode.gd index f13f679..2b3b839 100644 --- a/Scripts/ImageGraphNode.gd +++ b/Scripts/ImageGraphNode.gd @@ -15,6 +15,7 @@ var ctrl_key_was_down: bool # Dragging onready var background: = $VBoxContainer/Control/Background onready var thumbnail: = $VBoxContainer/Control/Thumbnail +onready var subtitle: = $VBoxContainer/Control/Subtitle onready var subedit: = $VBoxContainer/SubtitleEdit onready var spinbox: = $VBoxContainer/HBoxContainer/SpinBox @@ -48,7 +49,7 @@ func set_extra_data(extra_data: Dictionary): set_title(extra_data["title"]) img_path =extra_data["img_path"] snd_path = extra_data["snd_path"] - subedit.text = extra_data["subtitle"] + set_subtitle(extra_data["subtitle"]) spinbox.set_value(extra_data["duration"]) if not img_path.empty(): load_thumbnail_from_file(img_path) @@ -64,6 +65,15 @@ func get_thumbnail_texture(): return thumbnail.texture +func set_subtitle(text: String): + subedit.text = text + update_subtitle() + + +func update_subtitle(): + subtitle.text = subedit.text + + func get_subtitle(): return subedit.text @@ -193,11 +203,11 @@ func remove_sound(): func open_image_file(): - get_parent().open_load_image_dialog(self) + get_parent().display_open_image_file_dialog(self) func open_sound_file(): - get_parent().open_load_sound_dialog(self) + get_parent().display_open_sound_dialog(self) func reload_image_file(): @@ -214,3 +224,7 @@ func _on_GraphNode_offset_changed(): return assert(graph is GraphEdit) graph.img_node_offset_changed(self) + + +func _on_SubtitleEdit_text_changed(): + update_subtitle()