Overall code re-organizing & layer renaming changes

- When renaming a layer, the line edit grabs the focus. If enter is pressed, it gets invisible. Also fixed positioning and size
- Re-organized the variables in Global, now they are less messy and randomly placed
- Layer, frame & brush textures stretch mode has been changed to Keep Aspect Centered
This commit is contained in:
OverloadedOrama 2019-12-06 01:48:29 +02:00
parent da61234b13
commit 5613c3d7ef
14 changed files with 158 additions and 116 deletions

View file

@ -5,31 +5,42 @@ var i
# warning-ignore:unused_class_variable
var currently_selected := false
onready var visibility_button := $HBoxContainer/VisibilityButton
onready var label := $HBoxContainer/Label
onready var line_edit := $HBoxContainer/LineEdit
func _ready() -> void:
changed_selection()
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
func _on_LayerContainer_pressed() -> void:
var initially_pressed := pressed
var label_initially_visible : bool = $HBoxContainer/Label.visible
var label_initially_visible : bool = label.visible
Global.canvas.current_layer_index = i
changed_selection()
if !initially_pressed:
if label_initially_visible:
$HBoxContainer/Label.visible = false
$HBoxContainer/LineEdit.visible = true
$HBoxContainer/LineEdit.editable = true
label.visible = false
line_edit.visible = true
line_edit.editable = true
line_edit.grab_focus()
else:
$HBoxContainer/Label.visible = true
$HBoxContainer/LineEdit.visible = false
$HBoxContainer/LineEdit.editable = false
label.visible = true
line_edit.visible = false
line_edit.editable = false
func changed_selection() -> void:
var parent = get_parent()
var parent := get_parent()
for child in parent.get_children():
if child is Button:
child.get_node("HBoxContainer/Label").visible = true
child.get_node("HBoxContainer/LineEdit").visible = false
child.get_node("HBoxContainer/LineEdit").editable = false
child.label.visible = true
child.line_edit.visible = false
child.line_edit.editable = false
if Global.canvas.current_layer_index == child.i:
child.currently_selected = true
child.pressed = true
@ -58,11 +69,11 @@ func changed_selection() -> void:
func _on_VisibilityButton_pressed() -> void:
if Global.canvas.layers[i][3]:
Global.canvas.layers[i][3] = false
get_child(0).get_child(0).texture_normal = preload("res://Assets/Graphics/Layers/layer_invisible.png")
visibility_button.texture_normal = preload("res://Assets/Graphics/Layers/layer_invisible.png")
else:
Global.canvas.layers[i][3] = true
get_child(0).get_child(0).texture_normal = preload("res://Assets/Graphics/Layers/layer_visible.png")
visibility_button.texture_normal = preload("res://Assets/Graphics/Layers/layer_visible.png")
func _on_LineEdit_text_changed(new_text : String) -> void:
Global.canvas.layers[i][2] = new_text
$HBoxContainer/Label.text = new_text
label.text = new_text