2020-05-01 19:17:05 +00:00
|
|
|
class_name LayerButton
|
2020-02-10 22:06:24 +00:00
|
|
|
extends Button
|
2019-08-18 09:28:38 +00:00
|
|
|
|
2020-12-18 15:22:45 +00:00
|
|
|
|
2020-01-18 19:06:47 +00:00
|
|
|
var i := 0
|
2020-03-08 19:57:22 +00:00
|
|
|
var visibility_button : BaseButton
|
2020-03-09 01:26:13 +00:00
|
|
|
var lock_button : BaseButton
|
2020-03-14 19:40:10 +00:00
|
|
|
var linked_button : BaseButton
|
2020-03-08 19:57:22 +00:00
|
|
|
var label : Label
|
|
|
|
var line_edit : LineEdit
|
2019-12-05 23:48:29 +00:00
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
|
2019-08-18 09:28:38 +00:00
|
|
|
func _ready() -> void:
|
2021-01-30 21:57:33 +00:00
|
|
|
rect_min_size.y = Global.animation_timeline.cel_size
|
2020-12-18 15:22:45 +00:00
|
|
|
visibility_button = find_node("VisibilityButton")
|
|
|
|
lock_button = find_node("LockButton")
|
|
|
|
linked_button = find_node("LinkButton")
|
|
|
|
label = find_node("Label")
|
|
|
|
line_edit = find_node("LineEdit")
|
|
|
|
|
|
|
|
var layer_buttons = find_node("LayerButtons")
|
|
|
|
for child in layer_buttons.get_children():
|
|
|
|
var texture = child.get_child(0)
|
|
|
|
var last_backslash = texture.texture.resource_path.get_base_dir().find_last("/")
|
|
|
|
var button_category = texture.texture.resource_path.get_base_dir().right(last_backslash + 1)
|
|
|
|
var normal_file_name = texture.texture.resource_path.get_file()
|
|
|
|
|
2021-06-03 19:42:08 +00:00
|
|
|
texture.texture = load("res://assets/graphics/%s/%s" % [button_category, normal_file_name])
|
2021-06-04 18:44:05 +00:00
|
|
|
texture.modulate = Global.modulate_icon_color
|
2020-03-08 19:57:22 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
if Global.current_project.layers[i].visible:
|
2020-05-06 12:19:53 +00:00
|
|
|
Global.change_button_texturerect(visibility_button.get_child(0), "layer_visible.png")
|
2019-12-27 18:24:44 +00:00
|
|
|
else:
|
2020-05-06 12:19:53 +00:00
|
|
|
Global.change_button_texturerect(visibility_button.get_child(0), "layer_invisible.png")
|
2019-08-18 09:28:38 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
if Global.current_project.layers[i].locked:
|
2020-05-06 12:19:53 +00:00
|
|
|
Global.change_button_texturerect(lock_button.get_child(0), "lock.png")
|
2020-03-09 01:26:13 +00:00
|
|
|
else:
|
2020-05-06 12:19:53 +00:00
|
|
|
Global.change_button_texturerect(lock_button.get_child(0), "unlock.png")
|
2020-03-09 01:26:13 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
if Global.current_project.layers[i].new_cels_linked: # If new layers will be linked
|
2020-05-06 12:19:53 +00:00
|
|
|
Global.change_button_texturerect(linked_button.get_child(0), "linked_layer.png")
|
2020-03-14 19:40:10 +00:00
|
|
|
else:
|
2020-05-06 12:19:53 +00:00
|
|
|
Global.change_button_texturerect(linked_button.get_child(0), "unlinked_layer.png")
|
2020-03-14 19:40:10 +00:00
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
|
2019-12-27 18:24:44 +00:00
|
|
|
func _input(event : InputEvent) -> void:
|
2020-03-09 15:17:20 +00:00
|
|
|
if (event.is_action_released("ui_accept") or event.is_action_released("ui_cancel")) and line_edit.visible and event.scancode != KEY_SPACE:
|
|
|
|
save_layer_name(line_edit.text)
|
2019-12-05 23:48:29 +00:00
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
|
2019-11-06 16:39:23 +00:00
|
|
|
func _on_LayerContainer_pressed() -> void:
|
2020-03-04 23:13:59 +00:00
|
|
|
pressed = !pressed
|
2020-03-09 15:17:20 +00:00
|
|
|
label.visible = false
|
|
|
|
line_edit.visible = true
|
|
|
|
line_edit.editable = true
|
|
|
|
line_edit.grab_focus()
|
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
|
2020-03-09 15:17:20 +00:00
|
|
|
func _on_LineEdit_focus_exited() -> void:
|
|
|
|
save_layer_name(line_edit.text)
|
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
|
2020-03-09 15:17:20 +00:00
|
|
|
func save_layer_name(new_name : String) -> void:
|
|
|
|
label.visible = true
|
|
|
|
line_edit.visible = false
|
|
|
|
line_edit.editable = false
|
|
|
|
label.text = new_name
|
2020-04-06 15:35:54 +00:00
|
|
|
Global.layers_changed_skip = true
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.layers[i].name = new_name
|
2019-08-18 09:28:38 +00:00
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
|
2019-08-18 09:28:38 +00:00
|
|
|
func _on_VisibilityButton_pressed() -> void:
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.layers[i].visible = !Global.current_project.layers[i].visible
|
2019-12-27 18:24:44 +00:00
|
|
|
Global.canvas.update()
|
2020-03-09 01:26:13 +00:00
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
|
2020-03-09 01:26:13 +00:00
|
|
|
func _on_LockButton_pressed() -> void:
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.layers[i].locked = !Global.current_project.layers[i].locked
|
2020-03-14 19:40:10 +00:00
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
|
2020-03-14 19:40:10 +00:00
|
|
|
func _on_LinkButton_pressed() -> void:
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.layers[i].new_cels_linked = !Global.current_project.layers[i].new_cels_linked
|
|
|
|
if Global.current_project.layers[i].new_cels_linked && !Global.current_project.layers[i].linked_cels:
|
2020-06-02 23:14:24 +00:00
|
|
|
# If button is pressed and there are no linked cels in the layer
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.layers[i].linked_cels.append(Global.current_project.frames[Global.current_project.current_frame])
|
|
|
|
Global.current_project.layers[i].frame_container.get_child(Global.current_project.current_frame)._ready()
|