From f40ef6f329b2dd7fe3800e812c36c44b0e6f1c89 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas Date: Tue, 5 Dec 2023 01:11:51 +0200 Subject: [PATCH] Some more LayerButton.gd code improvements --- src/UI/Timeline/LayerButton.gd | 20 ++++++++++---------- src/UI/Timeline/LayerButton.tscn | 11 ++++++++--- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/UI/Timeline/LayerButton.gd b/src/UI/Timeline/LayerButton.gd index 66230c0b0..6a85bc1ac 100644 --- a/src/UI/Timeline/LayerButton.gd +++ b/src/UI/Timeline/LayerButton.gd @@ -6,11 +6,11 @@ const HIERARCHY_DEPTH_PIXEL_SHIFT := 8 var layer_index := 0 @onready var expand_button := %ExpandButton as BaseButton -@onready var visibility_button: BaseButton = find_child("VisibilityButton") -@onready var lock_button: BaseButton = find_child("LockButton") -@onready var label: Label = find_child("Label") -@onready var line_edit: LineEdit = find_child("LineEdit") -@onready var hierarchy_spacer: Control = find_child("HierarchySpacer") +@onready var visibility_button := %VisibilityButton as BaseButton +@onready var lock_button := %LockButton as BaseButton +@onready var label := %LayerNameLabel as Label +@onready var line_edit := %LayerNameLineEdit as LineEdit +@onready var hierarchy_spacer := %HierarchySpacer as Control @onready var linked_button := %LinkButton as BaseButton @@ -25,7 +25,7 @@ func _ready() -> void: label.text = layer.name line_edit.text = layer.name - var layer_buttons = find_child("LayerButtons") + var layer_buttons := find_child("LayerButtons") for child in layer_buttons.get_children(): var texture = child.get_child(0) texture.modulate = Global.modulate_icon_color @@ -97,7 +97,7 @@ func _draw() -> void: func _input(event: InputEvent) -> void: if ( - (event.is_action_released("ui_accept") or event.is_action_released("ui_cancel")) + (event.is_action_released(&"ui_accept") or event.is_action_released(&"ui_cancel")) and line_edit.visible and event.keycode != KEY_SPACE ): @@ -110,7 +110,7 @@ func _on_LayerContainer_gui_input(event: InputEvent) -> void: if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT: Global.canvas.selection.transform_content_confirm() var prev_curr_layer := project.current_layer - if Input.is_action_pressed("shift"): + if Input.is_action_pressed(&"shift"): var layer_diff_sign := signi(layer_index - prev_curr_layer) if layer_diff_sign == 0: layer_diff_sign = 1 @@ -120,7 +120,7 @@ func _on_LayerContainer_gui_input(event: InputEvent) -> void: if !project.selected_cels.has(frame_layer): project.selected_cels.append(frame_layer) project.change_cel(-1, layer_index) - elif Input.is_action_pressed("ctrl"): + elif Input.is_action_pressed(&"ctrl"): for i in range(0, project.frames.size()): var frame_layer := [i, layer_index] if !project.selected_cels.has(frame_layer): @@ -228,7 +228,7 @@ func _can_drop_data(_pos: Vector2, data) -> bool: var region: Rect2 var depth := curr_layer.get_hierarchy_depth() - if Input.is_action_pressed("ctrl"): # Swap layers + if Input.is_action_pressed(&"ctrl"): # Swap layers if drag_layer.is_ancestor_of(curr_layer) or curr_layer.is_ancestor_of(drag_layer): Global.animation_timeline.drag_highlight.visible = false return false diff --git a/src/UI/Timeline/LayerButton.tscn b/src/UI/Timeline/LayerButton.tscn index 6dcbde3ad..d3c720175 100644 --- a/src/UI/Timeline/LayerButton.tscn +++ b/src/UI/Timeline/LayerButton.tscn @@ -58,6 +58,7 @@ size_flags_vertical = 0 texture = ExtResource("2_enrtd") [node name="VisibilityButton" type="Button" parent="HBoxContainer/LayerButtons" groups=["UIButtons"]] +unique_name_in_owner = true custom_minimum_size = Vector2(22, 22) layout_mode = 2 size_flags_horizontal = 0 @@ -81,6 +82,7 @@ size_flags_vertical = 0 texture = ExtResource("2_ef6fb") [node name="LockButton" type="Button" parent="HBoxContainer/LayerButtons" groups=["UIButtons"]] +unique_name_in_owner = true custom_minimum_size = Vector2(22, 22) layout_mode = 2 size_flags_horizontal = 0 @@ -136,16 +138,19 @@ mouse_default_cursor_shape = 2 alignment = 1 [node name="HierarchySpacer" type="Control" parent="HBoxContainer/LayerName"] +unique_name_in_owner = true layout_mode = 2 mouse_filter = 2 -[node name="Label" type="Label" parent="HBoxContainer/LayerName"] +[node name="LayerNameLabel" type="Label" parent="HBoxContainer/LayerName"] +unique_name_in_owner = true layout_mode = 2 size_flags_horizontal = 3 text = "Layer 0" clip_text = true -[node name="LineEdit" type="LineEdit" parent="HBoxContainer/LayerName"] +[node name="LayerNameLineEdit" type="LineEdit" parent="HBoxContainer/LayerName"] +unique_name_in_owner = true visible = false layout_mode = 2 size_flags_horizontal = 3 @@ -164,4 +169,4 @@ mouse_filter = 2 [connection signal="pressed" from="HBoxContainer/LayerButtons/VisibilityButton" to="." method="_on_VisibilityButton_pressed"] [connection signal="pressed" from="HBoxContainer/LayerButtons/LockButton" to="." method="_on_LockButton_pressed"] [connection signal="pressed" from="HBoxContainer/LayerButtons/LinkButton" to="." method="_on_LinkButton_pressed"] -[connection signal="focus_exited" from="HBoxContainer/LayerName/LineEdit" to="." method="_on_LineEdit_focus_exited"] +[connection signal="focus_exited" from="HBoxContainer/LayerName/LayerNameLineEdit" to="." method="_on_LineEdit_focus_exited"]