Skip to content
Open
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
21 changes: 19 additions & 2 deletions src/UI/Timeline/TagProperties.gd
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
extends ConfirmationDialog

var current_tag_id := 0
var old_duration: float = 0
@onready var delete_tag_button := add_button("Delete", true, "delete_tag")
@onready var name_line_edit := $GridContainer/NameLineEdit as LineEdit
@onready var color_picker_button := $GridContainer/ColorPickerButton as ColorPickerButton
@onready var from_spinbox := $GridContainer/FromSpinBox as SpinBox
@onready var to_spinbox := $GridContainer/ToSpinBox as SpinBox
@onready var duration_slider := $GridContainer/DurationSlider as ValueSlider
@onready var from_spinbox := $GridContainer/FromSlider as ValueSlider
@onready var to_spinbox := $GridContainer/ToSlider as ValueSlider
@onready var user_data_text_edit := $GridContainer/UserDataTextEdit as TextEdit


Expand All @@ -17,10 +19,19 @@ func show_dialog(
popup_rect: Rect2i, tag_id: int, is_editing: bool, selected_frames := PackedInt32Array()
) -> void:
current_tag_id = tag_id
$GridContainer/DurationLabel.visible = is_editing
duration_slider.visible = is_editing
old_duration = 0
duration_slider.value = 0
if is_editing:
var animation_tag := Global.current_project.animation_tags[tag_id]
name_line_edit.text = animation_tag.name
color_picker_button.color = animation_tag.color
for i in range(animation_tag.from - 1, animation_tag.to):
var frame: Frame = Global.current_project.frames[i]
old_duration += frame.get_duration_in_seconds(Global.current_project.fps)
duration_slider.value = old_duration

from_spinbox.value = animation_tag.from
to_spinbox.value = animation_tag.to
user_data_text_edit.text = animation_tag.user_data
Expand All @@ -43,6 +54,12 @@ func _on_confirmed() -> void:
var tag_color := color_picker_button.color
var tag_to := clampi(to_spinbox.value, 0, Global.current_project.frames.size())
var tag_from := clampi(from_spinbox.value, 0, tag_to)
if not is_equal_approx(old_duration, duration_slider.value):
# Spread the new duration weighted by their individual duration
var ratio = duration_slider.value / old_duration
for i in range(tag_from - 1, tag_to):
var frame: Frame = Global.current_project.frames[i]
frame.duration *= snappedf(ratio * frame.duration, 0.01)
var user_data := user_data_text_edit.text
var new_animation_tags: Array[AnimationTag] = []
# Loop through the tags to create new classes for them, so that they won't be the same
Expand Down
28 changes: 19 additions & 9 deletions src/UI/Timeline/TagProperties.tscn
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
[gd_scene load_steps=2 format=3 uid="uid://c6fyrnyt3663o"]
[gd_scene load_steps=3 format=3 uid="uid://c6fyrnyt3663o"]

[ext_resource type="Script" uid="uid://da66yrocd1l3g" path="res://src/UI/Timeline/TagProperties.gd" id="1_wbmaq"]
[ext_resource type="PackedScene" uid="uid://yjhp0ssng2mp" path="res://src/UI/Nodes/Sliders/ValueSlider.tscn" id="2_jh8b3"]

[node name="TagProperties" type="ConfirmationDialog"]
title = "Tag properties"
size = Vector2i(303, 240)
size = Vector2i(303, 311)
script = ExtResource("1_wbmaq")

[node name="GridContainer" type="GridContainer" parent="."]
offset_left = 8.0
offset_top = 8.0
offset_right = 295.0
offset_bottom = 191.0
offset_bottom = 262.0
theme_override_constants/h_separation = 8
theme_override_constants/v_separation = 8
columns = 2
Expand All @@ -38,15 +39,24 @@ size_flags_horizontal = 3
mouse_default_cursor_shape = 2
color = Color(1, 0, 0, 1)

[node name="DurationLabel" type="Label" parent="GridContainer"]
layout_mode = 2
text = "Duration:"

[node name="DurationSlider" parent="GridContainer" instance=ExtResource("2_jh8b3")]
layout_mode = 2
step = 0.01
suffix = "sec"

[node name="FromLabel" type="Label" parent="GridContainer"]
layout_mode = 2
size_flags_horizontal = 3
text = "From:"

[node name="FromSpinBox" type="SpinBox" parent="GridContainer"]
[node name="FromSlider" parent="GridContainer" instance=ExtResource("2_jh8b3")]
custom_minimum_size = Vector2(0, 0)
layout_mode = 2
size_flags_horizontal = 3
mouse_default_cursor_shape = 2
theme_type_variation = &""
min_value = 1.0
value = 1.0
allow_greater = true
Expand All @@ -56,10 +66,10 @@ layout_mode = 2
size_flags_horizontal = 3
text = "To:"

[node name="ToSpinBox" type="SpinBox" parent="GridContainer"]
[node name="ToSlider" parent="GridContainer" instance=ExtResource("2_jh8b3")]
custom_minimum_size = Vector2(0, 0)
layout_mode = 2
size_flags_horizontal = 3
mouse_default_cursor_shape = 2
theme_type_variation = &""
min_value = 1.0
value = 1.0
allow_greater = true
Expand Down