From 2614ac5b3a90acf64e51d0642e74ab3fd75fcda3 Mon Sep 17 00:00:00 2001 From: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com> Date: Mon, 9 Mar 2020 17:17:20 +0200 Subject: [PATCH] Changes to layer re-naming Layer's LineEdit saves the changes when it loses focus, or when the user presses ESC (or Enter) --- Prefabs/LayerContainer.tscn | 2 ++ Scripts/LayerContainer.gd | 32 +++++++++++++++----------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Prefabs/LayerContainer.tscn b/Prefabs/LayerContainer.tscn index e08241d71..9a7ea3ebc 100644 --- a/Prefabs/LayerContainer.tscn +++ b/Prefabs/LayerContainer.tscn @@ -12,6 +12,7 @@ margin_bottom = 36.0 rect_min_size = Vector2( 212, 36 ) size_flags_horizontal = 0 toggle_mode = true +action_mode = 0 script = ExtResource( 1 ) __meta__ = { "_edit_horizontal_guides_": [ ], @@ -93,3 +94,4 @@ caret_blink_speed = 0.5 [connection signal="pressed" from="." to="." method="_on_LayerContainer_pressed"] [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="focus_exited" from="HBoxContainer/LayerName/LineEdit" to="." method="_on_LineEdit_focus_exited"] diff --git a/Scripts/LayerContainer.gd b/Scripts/LayerContainer.gd index ec2b8fd47..5c4f7e802 100644 --- a/Scripts/LayerContainer.gd +++ b/Scripts/LayerContainer.gd @@ -28,27 +28,25 @@ func _ready() -> void: lock_button.texture_hover = load("res://Assets/Graphics/%s Themes/Layers/Unlock_Hover.png" % Global.theme_type) func _input(event : InputEvent) -> void: - if event.is_action_released("ui_accept") && line_edit.visible && event.scancode != KEY_SPACE: - label.visible = true - line_edit.visible = false - line_edit.editable = false - var new_text : String = line_edit.text - label.text = new_text - Global.layers[i][0] = new_text + 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) func _on_LayerContainer_pressed() -> void: pressed = !pressed - var label_initially_visible : bool = label.visible + label.visible = false + line_edit.visible = true + line_edit.editable = true + line_edit.grab_focus() - if label_initially_visible: - label.visible = false - line_edit.visible = true - line_edit.editable = true - line_edit.grab_focus() - else: - label.visible = true - line_edit.visible = false - line_edit.editable = false +func _on_LineEdit_focus_exited() -> void: + save_layer_name(line_edit.text) + +func save_layer_name(new_name : String) -> void: + label.visible = true + line_edit.visible = false + line_edit.editable = false + label.text = new_name + Global.layers[i][0] = new_name func _on_VisibilityButton_pressed() -> void: if Global.layers[i][1]: