From c6e9b1621d64ffe2204a200440014d0110f712ed Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Mon, 6 May 2024 20:29:37 +0300 Subject: [PATCH] Implement the ability to edit a tag by clicking on it from the timeline Editing tags now is faster! Just click on it from the timeline to bring out the edit dialog. --- src/Main.tscn | 5 ++++- src/UI/Timeline/AnimationTagUI.gd | 10 ++++++++-- src/UI/Timeline/AnimationTagUI.tscn | 6 +++++- src/UI/Timeline/FrameTagDialog.gd | 19 ++++++++++++++----- src/UI/Timeline/FrameTagDialog.tscn | 6 +----- .../{TagOptions.gd => TagProperties.gd} | 5 ++++- .../{TagOptions.tscn => TagProperties.tscn} | 5 +++-- 7 files changed, 39 insertions(+), 17 deletions(-) rename src/UI/Timeline/{TagOptions.gd => TagProperties.gd} (98%) rename src/UI/Timeline/{TagOptions.tscn => TagProperties.tscn} (92%) diff --git a/src/Main.tscn b/src/Main.tscn index 4c81b55e4..8cffca839 100644 --- a/src/Main.tscn +++ b/src/Main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=16 format=3 uid="uid://dbylw5k04ulp8"] +[gd_scene load_steps=17 format=3 uid="uid://dbylw5k04ulp8"] [ext_resource type="Theme" uid="uid://cngbvfpwjoimv" path="res://assets/themes/dark/theme.tres" id="1"] [ext_resource type="Script" path="res://src/Main.gd" id="2"] @@ -12,6 +12,7 @@ [ext_resource type="PackedScene" uid="uid://b3aeqj2k58wdk" path="res://src/UI/Dialogs/OpenSprite.tscn" id="12"] [ext_resource type="PackedScene" uid="uid://d3dt1gdlf7hox" path="res://src/UI/Timeline/LayerProperties.tscn" id="13_4dhva"] [ext_resource type="PackedScene" uid="uid://c0nuukjakmai2" path="res://src/UI/Dialogs/TileModeOffsetsDialog.tscn" id="14"] +[ext_resource type="PackedScene" uid="uid://c6fyrnyt3663o" path="res://src/UI/Timeline/TagProperties.tscn" id="14_fw6cf"] [ext_resource type="Script" path="res://src/HandleExtensions.gd" id="15_v0k2h"] [ext_resource type="PackedScene" uid="uid://clbjfkdupw52l" path="res://src/UI/Timeline/CelProperties.tscn" id="17_ucs64"] [ext_resource type="PackedScene" uid="uid://clgu8wb5o6oup" path="res://src/UI/Dialogs/ExportDialog.tscn" id="39"] @@ -87,6 +88,8 @@ dialog_autowrap = true [node name="LayerProperties" parent="Dialogs" instance=ExtResource("13_4dhva")] +[node name="TagProperties" parent="Dialogs" instance=ExtResource("14_fw6cf")] + [node name="TileModeOffsetsDialog" parent="Dialogs" instance=ExtResource("14")] [node name="Extensions" type="Control" parent="."] diff --git a/src/UI/Timeline/AnimationTagUI.gd b/src/UI/Timeline/AnimationTagUI.gd index 1253559ea..f821f6070 100644 --- a/src/UI/Timeline/AnimationTagUI.gd +++ b/src/UI/Timeline/AnimationTagUI.gd @@ -1,14 +1,15 @@ extends VBoxContainer var tag: AnimationTag +@onready var options_dialog := Global.control.find_child("TagProperties") as ConfirmationDialog func _ready() -> void: if not is_instance_valid(tag): return - $Label.text = tag.name + $Button.text = tag.name + $Button.modulate = tag.color $Line2D.default_color = tag.color - $Label.modulate = tag.color update_position_and_size() @@ -18,3 +19,8 @@ func update_position_and_size() -> void: size.x = custom_minimum_size.x $Line2D.points[2] = Vector2(custom_minimum_size.x, 0) $Line2D.points[3] = Vector2(custom_minimum_size.x, 32) + + +func _on_button_pressed() -> void: + var tag_id = Global.current_project.animation_tags.find(tag) + options_dialog.show_dialog(Rect2i(), tag_id, true) diff --git a/src/UI/Timeline/AnimationTagUI.tscn b/src/UI/Timeline/AnimationTagUI.tscn index 441ff4265..e6d477036 100644 --- a/src/UI/Timeline/AnimationTagUI.tscn +++ b/src/UI/Timeline/AnimationTagUI.tscn @@ -15,8 +15,12 @@ joint_mode = 2 begin_cap_mode = 2 end_cap_mode = 2 -[node name="Label" type="Label" parent="."] +[node name="Button" type="Button" parent="."] layout_mode = 2 size_flags_horizontal = 4 size_flags_vertical = 3 +mouse_default_cursor_shape = 2 text = "Idle" +flat = true + +[connection signal="pressed" from="Button" to="." method="_on_button_pressed"] diff --git a/src/UI/Timeline/FrameTagDialog.gd b/src/UI/Timeline/FrameTagDialog.gd index 49371a1df..33c03532b 100644 --- a/src/UI/Timeline/FrameTagDialog.gd +++ b/src/UI/Timeline/FrameTagDialog.gd @@ -1,10 +1,21 @@ extends AcceptDialog var tag_vboxes := [] +var called_tag_properties := false ## True when tag properties has been shown by this dialog @onready var main_vbox_cont: VBoxContainer = $VBoxContainer/ScrollContainer/VBoxTagContainer @onready var add_tag_button: Button = $VBoxContainer/ScrollContainer/VBoxTagContainer/AddTag -@onready var options_dialog := $TagOptions as ConfirmationDialog +@onready var options_dialog := Global.control.find_child("TagProperties") as ConfirmationDialog + + +func _ready() -> void: + options_dialog.visibility_changed.connect(_on_tag_options_visibility_changed) + + +func _on_tag_options_visibility_changed() -> void: + if called_tag_properties: + called_tag_properties = false + popup_centered.call_deferred() func _on_FrameTagDialog_about_to_show() -> void: @@ -65,6 +76,7 @@ func _on_AddTag_pressed() -> void: frames.append(cel[0]) frames.sort() options_dialog.show_dialog(dialog_position, current_tag_id, false, frames) + called_tag_properties = true func _on_EditButton_pressed(_tag_id: int, edit_button: Button) -> void: @@ -72,10 +84,7 @@ func _on_EditButton_pressed(_tag_id: int, edit_button: Button) -> void: var y_pos := edit_button.global_position.y + 2 * edit_button.size.y var dialog_position := Rect2i(position + Vector2i(x_pos, y_pos), options_dialog.size) options_dialog.show_dialog(dialog_position, _tag_id, true) - - -func _on_tag_options_visibility_changed() -> void: - _on_FrameTagDialog_about_to_show.call_deferred() + called_tag_properties = true func _on_PlayOnlyTags_toggled(button_pressed: bool) -> void: diff --git a/src/UI/Timeline/FrameTagDialog.tscn b/src/UI/Timeline/FrameTagDialog.tscn index 0207c51d7..e34d87fa7 100644 --- a/src/UI/Timeline/FrameTagDialog.tscn +++ b/src/UI/Timeline/FrameTagDialog.tscn @@ -1,8 +1,7 @@ -[gd_scene load_steps=4 format=3 uid="uid://c6je8lgr850wf"] +[gd_scene load_steps=3 format=3 uid="uid://c6je8lgr850wf"] [ext_resource type="Script" path="res://src/UI/Timeline/FrameTagDialog.gd" id="1"] [ext_resource type="Texture2D" uid="uid://d1urikaf1lxwl" path="res://assets/graphics/timeline/new_frame.png" id="2"] -[ext_resource type="PackedScene" uid="uid://c6fyrnyt3663o" path="res://src/UI/Timeline/TagOptions.tscn" id="3_hw52m"] [node name="FrameTagDialog" type="AcceptDialog"] title = "Frame Tag Properties" @@ -63,10 +62,7 @@ mouse_default_cursor_shape = 2 button_pressed = true text = "Animation plays only on frames of the same tag" -[node name="TagOptions" parent="." instance=ExtResource("3_hw52m")] - [connection signal="about_to_popup" from="." to="." method="_on_FrameTagDialog_about_to_show"] [connection signal="visibility_changed" from="." to="." method="_on_FrameTagDialog_visibility_changed"] [connection signal="pressed" from="VBoxContainer/ScrollContainer/VBoxTagContainer/AddTag" to="." method="_on_AddTag_pressed"] [connection signal="toggled" from="VBoxContainer/PlayOnlyTags" to="." method="_on_PlayOnlyTags_toggled"] -[connection signal="visibility_changed" from="TagOptions" to="." method="_on_tag_options_visibility_changed"] diff --git a/src/UI/Timeline/TagOptions.gd b/src/UI/Timeline/TagProperties.gd similarity index 98% rename from src/UI/Timeline/TagOptions.gd rename to src/UI/Timeline/TagProperties.gd index 21aa3b923..3ed419785 100644 --- a/src/UI/Timeline/TagOptions.gd +++ b/src/UI/Timeline/TagProperties.gd @@ -31,7 +31,10 @@ func show_dialog( color_picker_button.color = Color(randf(), randf(), randf()) user_data_text_edit.text = "" delete_tag_button.visible = false - popup(popup_rect) + if popup_rect == Rect2i(): + popup_centered() + else: + popup(popup_rect) func _on_confirmed() -> void: diff --git a/src/UI/Timeline/TagOptions.tscn b/src/UI/Timeline/TagProperties.tscn similarity index 92% rename from src/UI/Timeline/TagOptions.tscn rename to src/UI/Timeline/TagProperties.tscn index afb6b4162..1668f6430 100644 --- a/src/UI/Timeline/TagOptions.tscn +++ b/src/UI/Timeline/TagProperties.tscn @@ -1,8 +1,9 @@ [gd_scene load_steps=2 format=3 uid="uid://c6fyrnyt3663o"] -[ext_resource type="Script" path="res://src/UI/Timeline/TagOptions.gd" id="1_wbmaq"] +[ext_resource type="Script" path="res://src/UI/Timeline/TagProperties.gd" id="1_wbmaq"] -[node name="TagOptions" type="ConfirmationDialog"] +[node name="TagProperties" type="ConfirmationDialog"] +title = "Tag properties" size = Vector2i(303, 240) exclusive = false popup_window = true