From 3e967559e259475342da9c81a40c726d0447ebe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Sun, 5 Mar 2023 15:44:53 +0300 Subject: [PATCH] add group list item component --- UI/Components/GroupMenu.gd | 5 +-- UI/Components/InstallItem.gd | 60 ++++++++++++++++++++++++++++++++++ UI/Components/InstallItem.tscn | 48 +++++++++++++++++++++++++++ UI/Main/GroupsView.tscn | 1 + 4 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 UI/Components/InstallItem.gd create mode 100644 UI/Components/InstallItem.tscn diff --git a/UI/Components/GroupMenu.gd b/UI/Components/GroupMenu.gd index 06c3fbe..738cb7b 100644 --- a/UI/Components/GroupMenu.gd +++ b/UI/Components/GroupMenu.gd @@ -39,7 +39,7 @@ func _ready() -> void: func add(item: InstallItem) -> void: - pass + child_container.add_child(item) func free_item(at_idx: int) -> void: @@ -90,9 +90,10 @@ func setup_rename() -> void: l.size_flags_horizontal = header_text_label.size_flags_horizontal # edit_group_button.disabled = true + var label_index := header_text_label.get_index() header_container.add_child(l) - header_container.move_child(l, 2) + header_container.move_child(l, label_index) var reenable = func(): header_text_label.visible = true diff --git a/UI/Components/InstallItem.gd b/UI/Components/InstallItem.gd new file mode 100644 index 0000000..148bdb9 --- /dev/null +++ b/UI/Components/InstallItem.gd @@ -0,0 +1,60 @@ +extends HBoxContainer +class_name InstallItem + +@onready var item_icon: TextureRect = %ItemIcon +@onready var name_label: Label = %NameLabel +@onready var edit_item_button: Button = %EditItemButton +@onready var delete_item_button: Button = %DeleteItemButton +@onready var launch_item_button: Button = %LaunchItemButton + +signal edit_item_button_pressed +signal delete_item_button_pressed +signal launch_item_button_pressed + +signal name_changed(new_name: String) + + +func _ready() -> void: + edit_item_button.pressed.connect(func(): edit_item_button_pressed.emit()) + delete_item_button.pressed.connect(func(): delete_item_button_pressed.emit()) + + name_label.gui_input.connect(_on_name_label_gui_input) + + +func set_icon(icon: Texture2D) -> void: + item_icon.texture = icon + + +func set_icon_visible(p_visible: bool) -> void: + item_icon.visible = p_visible + + +func setup_rename() -> void: + name_label.visible = false + var l := RenameLineEdit.new(name_label.text) + l.size_flags_horizontal = name_label.size_flags_horizontal + + var label_index := name_label.get_index() + + add_child(l) + move_child(l, label_index) + + l.canceled.connect(name_label.set_visible.bind(true)) + + l.text_submitted.connect( + func(new_text: String): + name_label.text = new_text + name_changed.emit(new_text) + + name_label.visible = true + ) + + l.grab_focus() + + +func _on_name_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/InstallItem.tscn b/UI/Components/InstallItem.tscn new file mode 100644 index 0000000..d0f887f --- /dev/null +++ b/UI/Components/InstallItem.tscn @@ -0,0 +1,48 @@ +[gd_scene load_steps=3 format=3 uid="uid://duq208khfvm2t"] + +[ext_resource type="Script" path="res://UI/Components/InstallItem.gd" id="1_sh2ev"] +[ext_resource type="Texture2D" uid="uid://de57eeeobflp4" path="res://icon.svg" id="1_wwvlr"] + +[node name="InstallItem" type="HBoxContainer"] +anchors_preset = -1 +offset_right = 299.0 +offset_bottom = 32.0 +script = ExtResource("1_sh2ev") +metadata/_edit_use_anchors_ = true + +[node name="Indent" type="MarginContainer" parent="."] +layout_mode = 2 +theme_override_constants/margin_left = 6 + +[node name="ItemIcon" type="TextureRect" parent="."] +unique_name_in_owner = true +visible = false +layout_mode = 2 +texture = ExtResource("1_wwvlr") +expand_mode = 2 + +[node name="NameLabel" type="Label" parent="."] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 3 +mouse_filter = 1 +vertical_alignment = 1 + +[node name="EditItemButton" type="Button" parent="."] +unique_name_in_owner = true +layout_mode = 2 +text = "E" + +[node name="DeleteItemButton" type="Button" parent="."] +unique_name_in_owner = true +layout_mode = 2 +text = "X" + +[node name="LaunchItemButton" type="Button" parent="."] +unique_name_in_owner = true +layout_mode = 2 +text = ">" + +[node name="Indent2" type="MarginContainer" parent="."] +layout_mode = 2 +theme_override_constants/margin_left = 6 diff --git a/UI/Main/GroupsView.tscn b/UI/Main/GroupsView.tscn index 81174fa..1190007 100644 --- a/UI/Main/GroupsView.tscn +++ b/UI/Main/GroupsView.tscn @@ -6,6 +6,7 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 +metadata/_edit_use_anchors_ = true [node name="Label" type="Label" parent="."] layout_mode = 2