From 1ecf9dba097047fb68fd09109c0b793cd42316cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Sun, 5 Mar 2023 15:08:54 +0300 Subject: [PATCH] change edit button in GroupMenu to be a signal change rename to be handled by double click on label --- UI/Components/GroupMenu.gd | 34 +++++++++++++++++++++++++++++----- UI/Components/GroupMenu.tscn | 13 +++++++++---- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/UI/Components/GroupMenu.gd b/UI/Components/GroupMenu.gd index b1ecdc1..06c3fbe 100644 --- a/UI/Components/GroupMenu.gd +++ b/UI/Components/GroupMenu.gd @@ -1,4 +1,5 @@ extends VBoxContainer +class_name GroupMenu @onready var collapse_button: Button = %CollapseButton @onready var header_icon: TextureRect = %HeaderIcon @@ -7,14 +8,16 @@ extends VBoxContainer @onready var child_container: VBoxContainer = %ChildContainer @onready var add_install_button_container: CenterContainer = %AddInstallButtonContainer @onready var add_install_button: Button = %AddInstallButton +@onready var description_label: Label = %DescriptionLabel -@onready var edit_text_button: Button = %EditTextButton +@onready var edit_group_button: Button = %EditGroupButton @onready var delete_group_button: Button = %DeleteGroupButton @onready var header_container: HBoxContainer = %HeaderContainer signal add_install_button_pressed +signal edit_group_button_pressed signal delete_button_pressed signal header_text_changed(new_text: String) @@ -28,11 +31,14 @@ func _ready() -> void: add_install_button.pressed.connect(func(): add_install_button_pressed.emit()) - edit_text_button.pressed.connect(setup_rename) +# edit_group_button.pressed.connect(setup_rename) + edit_group_button.pressed.connect(func(): edit_group_button_pressed.emit()) delete_group_button.pressed.connect(func(): delete_button_pressed.emit()) + header_text_label.gui_input.connect(_on_header_text_label_gui_input) -func add(item) -> void: + +func add(item: InstallItem) -> void: pass @@ -51,6 +57,15 @@ func set_text(text: String) -> void: header_text_label.text = text +func set_description(text: String) -> void: + if text == "": + description_label.visible = false + return + + description_label.visible = true + description_label.text = text + + func set_icon(icon: Texture2D) -> void: header_icon.texture = icon @@ -74,14 +89,14 @@ func setup_rename() -> void: var l := RenameLineEdit.new(header_text_label.text) l.size_flags_horizontal = header_text_label.size_flags_horizontal - edit_text_button.disabled = true +# edit_group_button.disabled = true header_container.add_child(l) header_container.move_child(l, 2) var reenable = func(): header_text_label.visible = true - edit_text_button.disabled = false +# edit_group_button.disabled = false l.canceled.connect(reenable) @@ -94,3 +109,12 @@ func setup_rename() -> void: ) l.grab_focus() + + +func _on_header_text_label_gui_input(event: InputEvent) -> void: + if event is InputEventMouseButton && \ + (event as InputEventMouseButton).double_click && \ + (event as InputEventMouseButton).button_index == MOUSE_BUTTON_LEFT: + get_viewport().set_input_as_handled() + setup_rename() + diff --git a/UI/Components/GroupMenu.tscn b/UI/Components/GroupMenu.tscn index e2d9e91..14098e6 100644 --- a/UI/Components/GroupMenu.tscn +++ b/UI/Components/GroupMenu.tscn @@ -4,8 +4,8 @@ [ext_resource type="Texture2D" uid="uid://de57eeeobflp4" path="res://icon.svg" id="2_crg6a"] [node name="GroupMenu" type="VBoxContainer"] -offset_right = 169.0 -offset_bottom = 71.0 +offset_right = 299.0 +offset_bottom = 87.0 script = ExtResource("1_h3o1w") [node name="HSeparator" type="HSeparator" parent="."] @@ -36,14 +36,14 @@ unique_name_in_owner = true layout_mode = 2 size_flags_horizontal = 3 size_flags_vertical = 1 -text = "header text" +mouse_filter = 1 vertical_alignment = 1 [node name="HeaderCustomControlContainer" type="HBoxContainer" parent="HeaderContainer"] unique_name_in_owner = true layout_mode = 2 -[node name="EditTextButton" type="Button" parent="HeaderContainer/HeaderCustomControlContainer"] +[node name="EditGroupButton" type="Button" parent="HeaderContainer/HeaderCustomControlContainer"] unique_name_in_owner = true layout_mode = 2 text = "E" @@ -53,6 +53,11 @@ unique_name_in_owner = true layout_mode = 2 text = "X" +[node name="DescriptionLabel" type="Label" parent="."] +unique_name_in_owner = true +visible = false +layout_mode = 2 + [node name="ChildContainer" type="VBoxContainer" parent="."] unique_name_in_owner = true layout_mode = 2