2019-11-06 16:39:23 +00:00
|
|
|
extends Button
|
|
|
|
class_name LayerContainer
|
2019-08-18 09:28:38 +00:00
|
|
|
|
|
|
|
var i
|
2019-09-03 19:51:14 +00:00
|
|
|
# warning-ignore:unused_class_variable
|
2019-08-18 09:28:38 +00:00
|
|
|
var currently_selected := false
|
|
|
|
|
2019-12-05 23:48:29 +00:00
|
|
|
onready var visibility_button := $HBoxContainer/VisibilityButton
|
|
|
|
onready var label := $HBoxContainer/Label
|
|
|
|
onready var line_edit := $HBoxContainer/LineEdit
|
|
|
|
|
2019-08-18 09:28:38 +00:00
|
|
|
func _ready() -> void:
|
|
|
|
changed_selection()
|
|
|
|
|
2019-12-05 23:48:29 +00:00
|
|
|
func _input(event : InputEvent):
|
|
|
|
if event.is_action_released("ui_accept") && line_edit.visible:
|
|
|
|
label.visible = true
|
|
|
|
line_edit.visible = false
|
|
|
|
line_edit.editable = false
|
|
|
|
|
2019-11-06 16:39:23 +00:00
|
|
|
func _on_LayerContainer_pressed() -> void:
|
|
|
|
var initially_pressed := pressed
|
2019-12-05 23:48:29 +00:00
|
|
|
var label_initially_visible : bool = label.visible
|
2019-11-06 16:39:23 +00:00
|
|
|
Global.canvas.current_layer_index = i
|
|
|
|
changed_selection()
|
|
|
|
if !initially_pressed:
|
|
|
|
if label_initially_visible:
|
2019-12-05 23:48:29 +00:00
|
|
|
label.visible = false
|
|
|
|
line_edit.visible = true
|
|
|
|
line_edit.editable = true
|
|
|
|
line_edit.grab_focus()
|
2019-11-06 16:39:23 +00:00
|
|
|
else:
|
2019-12-05 23:48:29 +00:00
|
|
|
label.visible = true
|
|
|
|
line_edit.visible = false
|
|
|
|
line_edit.editable = false
|
2019-08-18 09:28:38 +00:00
|
|
|
|
|
|
|
func changed_selection() -> void:
|
2019-12-05 23:48:29 +00:00
|
|
|
var parent := get_parent()
|
2019-08-18 09:28:38 +00:00
|
|
|
for child in parent.get_children():
|
2019-11-06 16:39:23 +00:00
|
|
|
if child is Button:
|
2019-12-05 23:48:29 +00:00
|
|
|
child.label.visible = true
|
|
|
|
child.line_edit.visible = false
|
|
|
|
child.line_edit.editable = false
|
2019-08-18 09:28:38 +00:00
|
|
|
if Global.canvas.current_layer_index == child.i:
|
|
|
|
child.currently_selected = true
|
2019-11-06 16:39:23 +00:00
|
|
|
child.pressed = true
|
2019-10-25 14:38:38 +00:00
|
|
|
|
2019-08-18 09:28:38 +00:00
|
|
|
if Global.canvas.current_layer_index < Global.canvas.layers.size() - 1:
|
|
|
|
Global.move_up_layer_button.disabled = false
|
2019-09-04 17:50:05 +00:00
|
|
|
Global.move_up_layer_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
2019-08-18 09:28:38 +00:00
|
|
|
else:
|
|
|
|
Global.move_up_layer_button.disabled = true
|
2019-09-04 17:50:05 +00:00
|
|
|
Global.move_up_layer_button.mouse_default_cursor_shape = Control.CURSOR_FORBIDDEN
|
2019-10-25 14:38:38 +00:00
|
|
|
|
2019-08-18 09:28:38 +00:00
|
|
|
if Global.canvas.current_layer_index > 0:
|
|
|
|
Global.move_down_layer_button.disabled = false
|
2019-09-04 17:50:05 +00:00
|
|
|
Global.move_down_layer_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
2019-08-18 09:28:38 +00:00
|
|
|
Global.merge_down_layer_button.disabled = false
|
2019-09-04 17:50:05 +00:00
|
|
|
Global.merge_down_layer_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
2019-08-18 09:28:38 +00:00
|
|
|
else:
|
|
|
|
Global.move_down_layer_button.disabled = true
|
2019-09-04 17:50:05 +00:00
|
|
|
Global.move_down_layer_button.mouse_default_cursor_shape = Control.CURSOR_FORBIDDEN
|
2019-08-18 09:28:38 +00:00
|
|
|
Global.merge_down_layer_button.disabled = true
|
2019-09-04 17:50:05 +00:00
|
|
|
Global.merge_down_layer_button.mouse_default_cursor_shape = Control.CURSOR_FORBIDDEN
|
2019-08-18 09:28:38 +00:00
|
|
|
else:
|
|
|
|
child.currently_selected = false
|
2019-11-06 16:39:23 +00:00
|
|
|
child.pressed = false
|
2019-08-18 09:28:38 +00:00
|
|
|
|
|
|
|
func _on_VisibilityButton_pressed() -> void:
|
|
|
|
if Global.canvas.layers[i][3]:
|
|
|
|
Global.canvas.layers[i][3] = false
|
2019-12-05 23:48:29 +00:00
|
|
|
visibility_button.texture_normal = preload("res://Assets/Graphics/Layers/layer_invisible.png")
|
2019-08-18 09:28:38 +00:00
|
|
|
else:
|
|
|
|
Global.canvas.layers[i][3] = true
|
2019-12-05 23:48:29 +00:00
|
|
|
visibility_button.texture_normal = preload("res://Assets/Graphics/Layers/layer_visible.png")
|
2019-08-18 09:28:38 +00:00
|
|
|
|
2019-11-06 16:39:23 +00:00
|
|
|
func _on_LineEdit_text_changed(new_text : String) -> void:
|
|
|
|
Global.canvas.layers[i][2] = new_text
|
2019-12-05 23:48:29 +00:00
|
|
|
label.text = new_text
|