From f893e68d592168f02aaa945912a56ec4080ddb99 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas Date: Tue, 5 Dec 2023 02:04:34 +0200 Subject: [PATCH] Move even more code away from Global and Project to AnimationTimeline This time related to layer buttons --- src/Autoload/Global.gd | 8 ------ src/Classes/Project.gd | 28 ------------------- src/UI/Timeline/AnimationTimeline.gd | 38 ++++++++++++++++++++++++-- src/UI/Timeline/AnimationTimeline.tscn | 4 +++ 4 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/Autoload/Global.gd b/src/Autoload/Global.gd index 4d2070e23..66a267cb5 100644 --- a/src/Autoload/Global.gd +++ b/src/Autoload/Global.gd @@ -489,14 +489,6 @@ var cel_button_scene: PackedScene = load("res://src/UI/Timeline/CelButton.tscn") @onready var cel_vbox: VBoxContainer = animation_timeline.find_child("CelVBox") ## The container of animation tags. @onready var tag_container: Control = animation_timeline.find_child("TagContainer") -## Remove layer button. -@onready var remove_layer_button: BaseButton = animation_timeline.find_child("RemoveLayer") -## Move layer up button. -@onready var move_up_layer_button: BaseButton = animation_timeline.find_child("MoveUpLayer") -## Move layer down button. -@onready var move_down_layer_button: BaseButton = animation_timeline.find_child("MoveDownLayer") -## Merge with layer below button. -@onready var merge_down_layer_button: BaseButton = animation_timeline.find_child("MergeDownLayer") ## The brushes popup dialog used to display brushes. ## It has the [param BrushesPopup.gd] script attached. diff --git a/src/Classes/Project.gd b/src/Classes/Project.gd index 01544990e..2d5d10065 100644 --- a/src/Classes/Project.gd +++ b/src/Classes/Project.gd @@ -178,7 +178,6 @@ func change_project() -> void: Global.animation_timeline.project_changed() Global.current_frame_mark_label.text = "%s/%s" % [str(current_frame + 1), frames.size()] - toggle_layer_buttons() animation_tags = animation_tags # Change the guides @@ -516,7 +515,6 @@ func change_cel(new_frame: int, new_layer := -1) -> void: if new_layer != current_layer: # If the layer has changed current_layer = new_layer - toggle_layer_buttons() Global.transparent_checker.update_rect() Global.cel_changed.emit() @@ -527,31 +525,6 @@ func change_cel(new_frame: int, new_layer := -1) -> void: Global.canvas.queue_redraw() -func toggle_layer_buttons() -> void: - if layers.is_empty() or current_layer >= layers.size(): - return - var child_count: int = layers[current_layer].get_child_count(true) - - Global.disable_button( - Global.remove_layer_button, - layers[current_layer].is_locked_in_hierarchy() or layers.size() == child_count + 1 - ) - Global.disable_button(Global.move_up_layer_button, current_layer == layers.size() - 1) - Global.disable_button( - Global.move_down_layer_button, - current_layer == child_count and not is_instance_valid(layers[current_layer].parent) - ) - Global.disable_button( - Global.merge_down_layer_button, - ( - current_layer == child_count - or layers[current_layer] is GroupLayer - or layers[current_layer - 1] is GroupLayer - or layers[current_layer - 1] is Layer3D - ) - ) - - func _animation_tags_changed(value: Array[AnimationTag]) -> void: animation_tags = value for child in Global.tag_container.get_children(): @@ -866,4 +839,3 @@ func _update_layer_ui() -> void: for f in frames.size(): cel_hbox.get_child(f).layer = l cel_hbox.get_child(f).button_setup() - toggle_layer_buttons() diff --git a/src/UI/Timeline/AnimationTimeline.gd b/src/UI/Timeline/AnimationTimeline.gd index 87d3d4f3e..2b10e897b 100644 --- a/src/UI/Timeline/AnimationTimeline.gd +++ b/src/UI/Timeline/AnimationTimeline.gd @@ -20,15 +20,19 @@ var future_above_canvas := true @onready var layer_settings_container := %LayerSettingsContainer as VBoxContainer @onready var layer_container := %LayerContainer as VBoxContainer @onready var add_layer_list := %AddLayerList as MenuButton +@onready var remove_layer := %RemoveLayer as Button +@onready var move_up_layer := %MoveUpLayer as Button +@onready var move_down_layer := %MoveDownLayer as Button +@onready var merge_down_layer := %MergeDownLayer as Button @onready var blend_modes_button := %BlendModes as OptionButton @onready var opacity_slider: ValueSlider = %OpacitySlider @onready var frame_scroll_container := %FrameScrollContainer as Control @onready var frame_scroll_bar := %FrameScrollBar as HScrollBar @onready var tag_scroll_container := %TagScroll as ScrollContainer @onready var layer_frame_h_split := %LayerFrameHSplit as HSplitContainer -@onready var delete_frame: Button = %DeleteFrame -@onready var move_frame_left: Button = %MoveFrameLeft -@onready var move_frame_right: Button = %MoveFrameRight +@onready var delete_frame := %DeleteFrame as Button +@onready var move_frame_left := %MoveFrameLeft as Button +@onready var move_frame_right := %MoveFrameRight as Button @onready var play_backwards := %PlayBackwards as Button @onready var play_forward := %PlayForward as Button @onready var fps_spinbox := %FPSValue as ValueSlider @@ -993,6 +997,7 @@ func _on_onion_skinning_settings_visibility_changed() -> void: func _cel_changed() -> void: _toggle_frame_buttons() + _toggle_layer_buttons() var project := Global.current_project var cel_opacity := project.get_current_cel().opacity opacity_slider.value = cel_opacity * 100 @@ -1009,9 +1014,36 @@ func _toggle_frame_buttons() -> void: Global.disable_button(move_frame_right, project.current_frame == project.frames.size() - 1) +func _toggle_layer_buttons() -> void: + var project := Global.current_project + if project.layers.is_empty() or project.current_layer >= project.layers.size(): + return + var layer := project.layers[project.current_layer] + var child_count := layer.get_child_count(true) + + Global.disable_button( + remove_layer, layer.is_locked_in_hierarchy() or project.layers.size() == child_count + 1 + ) + Global.disable_button(move_up_layer, project.current_layer == project.layers.size() - 1) + Global.disable_button( + move_down_layer, + project.current_layer == child_count and not is_instance_valid(layer.parent) + ) + Global.disable_button( + merge_down_layer, + ( + project.current_layer == child_count + or layer is GroupLayer + or project.layers[project.current_layer - 1] is GroupLayer + or project.layers[project.current_layer - 1] is Layer3D + ) + ) + + func project_changed() -> void: var project := Global.current_project _toggle_frame_buttons() + _toggle_layer_buttons() # These must be removed from tree immediately to not mess up the indices of # the new buttons, so use either free or queue_free + parent.remove_child for layer_button in Global.layer_vbox.get_children(): diff --git a/src/UI/Timeline/AnimationTimeline.tscn b/src/UI/Timeline/AnimationTimeline.tscn index dad49fd41..d865b5aee 100644 --- a/src/UI/Timeline/AnimationTimeline.tscn +++ b/src/UI/Timeline/AnimationTimeline.tscn @@ -254,6 +254,7 @@ offset_bottom = 6.0 texture = ExtResource("10") [node name="RemoveLayer" type="Button" parent="TimelineContainer/TimelineButtons/LayerTools/LayerSettingsContainer/LayerButtons" groups=["UIButtons"]] +unique_name_in_owner = true custom_minimum_size = Vector2(24, 24) layout_mode = 2 size_flags_horizontal = 3 @@ -279,6 +280,7 @@ size_flags_vertical = 0 texture = ExtResource("6") [node name="MoveUpLayer" type="Button" parent="TimelineContainer/TimelineButtons/LayerTools/LayerSettingsContainer/LayerButtons" groups=["UIButtons"]] +unique_name_in_owner = true custom_minimum_size = Vector2(24, 24) layout_mode = 2 size_flags_horizontal = 3 @@ -304,6 +306,7 @@ size_flags_vertical = 0 texture = ExtResource("4") [node name="MoveDownLayer" type="Button" parent="TimelineContainer/TimelineButtons/LayerTools/LayerSettingsContainer/LayerButtons" groups=["UIButtons"]] +unique_name_in_owner = true custom_minimum_size = Vector2(24, 24) layout_mode = 2 size_flags_horizontal = 3 @@ -353,6 +356,7 @@ size_flags_vertical = 0 texture = ExtResource("7") [node name="MergeDownLayer" type="Button" parent="TimelineContainer/TimelineButtons/LayerTools/LayerSettingsContainer/LayerButtons" groups=["UIButtons"]] +unique_name_in_owner = true custom_minimum_size = Vector2(24, 24) layout_mode = 2 size_flags_horizontal = 3