1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 17:19:50 +00:00

Only have one CelButton scene instead of using inheritance

This commit is contained in:
Emmanouil Papadeas 2023-12-05 00:40:16 +02:00
parent 41fdba266a
commit a627cff107
10 changed files with 31 additions and 75 deletions

View file

@ -427,12 +427,8 @@ var base_layer_button_node: PackedScene = load("res://src/UI/Timeline/BaseLayerB
var pixel_layer_button_node: PackedScene = load("res://src/UI/Timeline/PixelLayerButton.tscn")
## The preload of button used by the [GroupLayer].
var group_layer_button_node: PackedScene = load("res://src/UI/Timeline/GroupLayerButton.tscn")
## The preload of button used by the [PixelCel].
var pixel_cel_button_node: PackedScene = load("res://src/UI/Timeline/PixelCelButton.tscn")
## The preload of button used by the [GroupCel].
var group_cel_button_node: PackedScene = load("res://src/UI/Timeline/GroupCelButton.tscn")
## The preload of button used by the [Cel3D].
var cel_3d_button_node: PackedScene = load("res://src/UI/Timeline/Cel3DButton.tscn")
## The [PackedScene] of the button used by cels in the timeline.
var cel_button_scene: PackedScene = load("res://src/UI/Timeline/CelButton.tscn")
@onready var main_window := get_window() ## The main Pixelorama [Window].
## The control node (aka Main node). It has the [param Main.gd] script attached.

View file

@ -85,7 +85,7 @@ func on_remove() -> void:
## Returns an instance of the cel button that will be added to the timeline.
func instantiate_cel_button() -> Node:
return null
return Global.cel_button_scene.instantiate()
## Returns to get the type of the cel class.

View file

@ -290,9 +290,5 @@ func on_remove() -> void:
viewport.queue_free()
func instantiate_cel_button() -> Node:
return Global.cel_3d_button_node.instantiate()
func get_class_name() -> String:
return "Cel3D"

View file

@ -16,9 +16,5 @@ func get_image() -> Image:
return image
func instantiate_cel_button() -> Node:
return Global.group_cel_button_node.instantiate()
func get_class_name() -> String:
return "GroupCel"

View file

@ -57,9 +57,5 @@ func update_texture() -> void:
super.update_texture()
func instantiate_cel_button() -> Node:
return Global.pixel_cel_button_node.instantiate()
func get_class_name() -> String:
return "PixelCel"

View file

@ -1,14 +0,0 @@
[gd_scene load_steps=3 format=3 uid="uid://cqpi2e7amvsau"]
[ext_resource type="PackedScene" uid="uid://byhnvhs6av108" path="res://src/UI/Timeline/BaseCelButton.tscn" id="1"]
[ext_resource type="Script" path="res://src/UI/Timeline/CelButton.gd" id="2"]
[node name="PixelCelButton" instance=ExtResource("1")]
pivot_offset = Vector2(-18, 6)
script = ExtResource("2")
[node name="LinkedIndicator" type="Polygon2D" parent="." index="1"]
color = Color(0, 1, 0, 1)
invert_enabled = true
invert_border = 1.0
polygon = PackedVector2Array(0, 0, 36, 0, 36, 36, 0, 36)

View file

@ -17,6 +17,8 @@ func _ready() -> void:
button_setup()
_dim_checker()
cel.texture_changed.connect(_dim_checker)
if cel is GroupCel:
transparent_checker.visible = false
func button_setup() -> void:
@ -84,7 +86,7 @@ func _on_CelButton_pressed() -> void:
release_focus()
elif Input.is_action_just_released("right_mouse"):
if is_instance_valid(popup_menu):
if cel is PixelCel:
popup_menu.popup(Rect2(get_global_mouse_position(), Vector2.ONE))
button_pressed = !button_pressed
elif Input.is_action_just_released("middle_mouse"):

View file

@ -1,10 +1,11 @@
[gd_scene load_steps=4 format=3 uid="uid://byhnvhs6av108"]
[gd_scene load_steps=5 format=3 uid="uid://dw7ci3uixjuev"]
[ext_resource type="Shader" path="res://src/Shaders/TransparentChecker.gdshader" id="1"]
[ext_resource type="PackedScene" uid="uid://3pmb60gpst7b" path="res://src/UI/Nodes/TransparentChecker.tscn" id="2"]
[ext_resource type="Script" path="res://src/UI/Timeline/CelButton.gd" id="1_iewgo"]
[ext_resource type="PackedScene" uid="uid://3pmb60gpst7b" path="res://src/UI/Nodes/TransparentChecker.tscn" id="2_mi8wp"]
[ext_resource type="Shader" path="res://src/Shaders/TransparentChecker.gdshader" id="3_qv21g"]
[sub_resource type="ShaderMaterial" id="1"]
shader = ExtResource("1")
shader = ExtResource("3_qv21g")
shader_parameter/size = 10.0
shader_parameter/alpha = 1.0
shader_parameter/color1 = Color(0.7, 0.7, 0.7, 1)
@ -15,17 +16,19 @@ shader_parameter/rect_size = Vector2(0, 0)
shader_parameter/follow_movement = false
shader_parameter/follow_scale = false
[node name="BaseCelButton" type="Button"]
[node name="CelButton" type="Button"]
custom_minimum_size = Vector2(36, 36)
offset_top = 18.0
offset_right = 36.0
offset_bottom = 54.0
pivot_offset = Vector2(-18, 6)
size_flags_horizontal = 0
size_flags_vertical = 0
focus_mode = 0
mouse_default_cursor_shape = 2
toggle_mode = true
button_mask = 7
script = ExtResource("1_iewgo")
[node name="CelTexture" type="TextureRect" parent="."]
custom_minimum_size = Vector2(32, 32)
@ -39,7 +42,7 @@ size_flags_vertical = 0
expand_mode = 1
stretch_mode = 6
[node name="TransparentChecker" parent="CelTexture" instance=ExtResource("2")]
[node name="TransparentChecker" parent="CelTexture" instance=ExtResource("2_mi8wp")]
show_behind_parent = true
material = SubResource("1")
layout_mode = 1
@ -49,5 +52,21 @@ anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="PopupMenu" type="PopupMenu" parent="."]
item_count = 3
item_0/text = "Delete"
item_0/id = -1
item_1/text = "Link Cels to"
item_1/id = -1
item_2/text = "Unlink Cels"
item_2/id = 2
[node name="LinkedIndicator" type="Polygon2D" parent="."]
color = Color(0, 1, 0, 1)
invert_enabled = true
invert_border = 1.0
polygon = PackedVector2Array(0, 0, 36, 0, 36, 36, 0, 36)
[connection signal="pressed" from="." to="." method="_on_CelButton_pressed"]
[connection signal="resized" from="." to="." method="_on_CelButton_resized"]
[connection signal="id_pressed" from="PopupMenu" to="." method="_on_PopupMenu_id_pressed"]

View file

@ -1,10 +0,0 @@
[gd_scene load_steps=3 format=3 uid="uid://b5qw4utq8u88h"]
[ext_resource type="PackedScene" uid="uid://byhnvhs6av108" path="res://src/UI/Timeline/BaseCelButton.tscn" id="1"]
[ext_resource type="Script" path="res://src/UI/Timeline/CelButton.gd" id="2"]
[node name="GroupCelButton" instance=ExtResource("1")]
script = ExtResource("2")
[node name="TransparentChecker" parent="CelTexture" index="0"]
visible = false

View file

@ -1,25 +0,0 @@
[gd_scene load_steps=3 format=3 uid="uid://dw7ci3uixjuev"]
[ext_resource type="PackedScene" uid="uid://byhnvhs6av108" path="res://src/UI/Timeline/BaseCelButton.tscn" id="1"]
[ext_resource type="Script" path="res://src/UI/Timeline/CelButton.gd" id="2"]
[node name="PixelCelButton" instance=ExtResource("1")]
pivot_offset = Vector2(-18, 6)
script = ExtResource("2")
[node name="PopupMenu" type="PopupMenu" parent="." index="1"]
item_count = 3
item_0/text = "Delete"
item_0/id = -1
item_1/text = "Link Cels to"
item_1/id = -1
item_2/text = "Unlink Cels"
item_2/id = 2
[node name="LinkedIndicator" type="Polygon2D" parent="." index="2"]
color = Color(0, 1, 0, 1)
invert_enabled = true
invert_border = 1.0
polygon = PackedVector2Array(0, 0, 36, 0, 36, 36, 0, 36)
[connection signal="id_pressed" from="PopupMenu" to="." method="_on_PopupMenu_id_pressed"]