Skip to content

Commit

Permalink
Infinite subtitles in node
Browse files Browse the repository at this point in the history
  • Loading branch information
madjyc committed Oct 22, 2022
1 parent db0e2dc commit 3278d81
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 65 deletions.
File renamed without changes.
11 changes: 11 additions & 0 deletions Scenes/CommentGraphNode.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]
65 changes: 31 additions & 34 deletions Scenes/DisplayDialog.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -83,73 +80,73 @@ 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"
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
Expand All @@ -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 )

Expand Down
26 changes: 25 additions & 1 deletion Scenes/ImageGraphNode.tscn
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Expand Down
58 changes: 34 additions & 24 deletions Scripts/CommentGraphNode.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@ 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)
# offset is rect_position in graph space (rect_position is automatically derived from offset)
# rect_size is in graph space

func _ready():
assert(colorpicker)
assert(user_text)
old_offset = offset


Expand All @@ -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
}

Expand All @@ -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):
Expand All @@ -74,33 +74,41 @@ 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)


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
Expand All @@ -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)
Expand All @@ -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:
Expand Down
9 changes: 6 additions & 3 deletions Scripts/DisplayDialog.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand Down
Loading

0 comments on commit 3278d81

Please sign in to comment.