From 15b56ef048c4f6e01dbb6018ce9118abffca8177 Mon Sep 17 00:00:00 2001 From: LunarAkai Date: Wed, 2 Jul 2025 00:29:21 +0200 Subject: [PATCH] feat: rename container name (remaining issue: renames every instance of the container_selection_button) --- src/Singletons/signal_bus.gd | 6 +- src/UI/buttons/container_selection_button.gd | 25 +++++- .../buttons/container_selection_button.tscn | 5 +- src/UI/done_box.gd | 6 +- src/UI/done_box.tscn | 2 +- src/UI/main.gd | 3 +- src/UI/main.tscn | 4 - src/UI/windows/edit_collection_name_window.gd | 35 +++++++++ .../edit_collection_name_window.gd.uid | 1 + .../windows/edit_collection_name_window.tscn | 78 +++++++++++++++++++ src/UI/{ => windows}/editmenu.gd | 7 +- src/UI/{ => windows}/editmenu.gd.uid | 0 src/UI/{ => windows}/editmenu.tscn | 12 +-- 13 files changed, 164 insertions(+), 20 deletions(-) create mode 100644 src/UI/windows/edit_collection_name_window.gd create mode 100644 src/UI/windows/edit_collection_name_window.gd.uid create mode 100644 src/UI/windows/edit_collection_name_window.tscn rename src/UI/{ => windows}/editmenu.gd (83%) rename src/UI/{ => windows}/editmenu.gd.uid (100%) rename src/UI/{ => windows}/editmenu.tscn (92%) diff --git a/src/Singletons/signal_bus.gd b/src/Singletons/signal_bus.gd index c7d08ba..b566acd 100644 --- a/src/Singletons/signal_bus.gd +++ b/src/Singletons/signal_bus.gd @@ -1,9 +1,11 @@ extends Node +signal on_window_closed(window: Window) + signal settings_window_closed signal edit_window_closed -signal edit_window_requested(text: String) -signal edit_window_text_saved(text: String) +signal edit_window_requested(window: Window, text: String) +signal edit_window_text_saved(window: Window, text: String) signal main_panel_color_changed(color: Color) signal main_window_color_changed(color: Color) diff --git a/src/UI/buttons/container_selection_button.gd b/src/UI/buttons/container_selection_button.gd index 345b5af..e42a354 100644 --- a/src/UI/buttons/container_selection_button.gd +++ b/src/UI/buttons/container_selection_button.gd @@ -3,12 +3,15 @@ class_name ContainerSelectionButton extends MarginContainer @export var button: Button @export var container_box: ContainerBox @export var popup_menu: PopupMenu +@export var edit_collection_name_window: PackedScene var button_index: int +var instantiated_menu # Called when the node enters the scene tree for the first time. func _ready() -> void: - pass + SignalBus.edit_window_text_saved.connect(_on_edit_window_text_saved) + SignalBus.on_window_closed.connect(_on_window_closed) func _enter_tree() -> void: @@ -32,3 +35,23 @@ func _input(event: InputEvent) -> void: button.get_global_rect().size.x, button.get_global_rect().size.y) ) + + +func _on_popup_menu_index_pressed(index: int) -> void: + if instantiated_menu != null: + return + if index == 0: + instantiated_menu = edit_collection_name_window.instantiate() + add_child(instantiated_menu) + SignalBus.edit_window_requested.emit(instantiated_menu, button.text) + +func _on_edit_window_text_saved(window: Window, text: String) -> void: + if not is_instance_of(window, EditCollectionNameWindow): + return + button.text = text + +func _on_window_closed(window: Window) -> void: + if not is_instance_of(window, EditCollectionNameWindow): + return + if instantiated_menu != null: + instantiated_menu.queue_free() diff --git a/src/UI/buttons/container_selection_button.tscn b/src/UI/buttons/container_selection_button.tscn index c65de86..317650a 100644 --- a/src/UI/buttons/container_selection_button.tscn +++ b/src/UI/buttons/container_selection_button.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=8 format=3 uid="uid://csre4kogd8afg"] +[gd_scene load_steps=9 format=3 uid="uid://csre4kogd8afg"] [ext_resource type="Script" uid="uid://osei0aimuya2" path="res://src/UI/buttons/container_selection_button.gd" id="1_g121j"] [ext_resource type="Theme" uid="uid://bal6yp0a25hf2" path="res://src/theme/main_theme.tres" id="1_ru1ls"] +[ext_resource type="PackedScene" uid="uid://bgqshc2r7sdmx" path="res://src/UI/windows/edit_collection_name_window.tscn" id="2_4ff2x"] [ext_resource type="Texture2D" uid="uid://ne4o3drvj5vw" path="res://src/assets/icons/color-picker.svg" id="3_wvlx0"] [ext_resource type="Texture2D" uid="uid://s3vf3vhl8y3e" path="res://src/assets/icons/trash.svg" id="4_4ff2x"] @@ -23,6 +24,7 @@ theme_override_constants/margin_bottom = 5 script = ExtResource("1_g121j") button = NodePath("Button") popup_menu = NodePath("PopupMenu") +edit_collection_name_window = ExtResource("2_4ff2x") [node name="Button" type="Button" parent="."] layout_mode = 2 @@ -43,3 +45,4 @@ item_1/icon = ExtResource("4_4ff2x") item_1/id = 1 [connection signal="pressed" from="Button" to="." method="_on_button_pressed"] +[connection signal="index_pressed" from="PopupMenu" to="." method="_on_popup_menu_index_pressed"] diff --git a/src/UI/done_box.gd b/src/UI/done_box.gd index ff1764b..54744c3 100644 --- a/src/UI/done_box.gd +++ b/src/UI/done_box.gd @@ -27,12 +27,14 @@ func _on_index_pressed(index:int) -> void: if index == 0: instantiated_menu = edit_menu.instantiate() add_child(instantiated_menu) - SignalBus.edit_window_requested.emit(entry_text_box.text) + SignalBus.edit_window_requested.emit(instantiated_menu, entry_text_box.text) if index == 1: queue_free() -func on_edit_window_text_save(text: String) -> void: +func on_edit_window_text_save(window: Window, text: String) -> void: + if not is_instance_of(window, Editmenu): + return entry_text_box.text = text func on_edit_window_closed() -> void: diff --git a/src/UI/done_box.tscn b/src/UI/done_box.tscn index f94716f..f375800 100644 --- a/src/UI/done_box.tscn +++ b/src/UI/done_box.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=6 format=3 uid="uid://d1b10b44uwo8y"] [ext_resource type="Script" uid="uid://buvowannsky2u" path="res://src/UI/done_box.gd" id="1_kikfe"] -[ext_resource type="PackedScene" uid="uid://dcifyvgobrvp5" path="res://src/UI/editmenu.tscn" id="2_qm8q0"] +[ext_resource type="PackedScene" uid="uid://dcifyvgobrvp5" path="res://src/UI/windows/editmenu.tscn" id="2_qm8q0"] [ext_resource type="Texture2D" uid="uid://c1ccasyx80msg" path="res://src/assets/icons/dots-vertical.svg" id="3_leupd"] [ext_resource type="Texture2D" uid="uid://ne4o3drvj5vw" path="res://src/assets/icons/color-picker.svg" id="4_qqlum"] [ext_resource type="Texture2D" uid="uid://s3vf3vhl8y3e" path="res://src/assets/icons/trash.svg" id="5_k527k"] diff --git a/src/UI/main.gd b/src/UI/main.gd index 66d9de5..d65f85a 100644 --- a/src/UI/main.gd +++ b/src/UI/main.gd @@ -1,10 +1,11 @@ extends Control + # Called when the node enters the scene tree for the first time. func _ready() -> void: pass - # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta: float) -> void: pass + \ No newline at end of file diff --git a/src/UI/main.tscn b/src/UI/main.tscn index 63037ee..f79753e 100644 --- a/src/UI/main.tscn +++ b/src/UI/main.tscn @@ -170,10 +170,6 @@ size_flags_horizontal = 3 size_flags_vertical = 3 script = ExtResource("5_cqoei") -[node name="ContainerSelectionButton" parent="Panel/VBoxContainer/UIManager/Panel/MarginContainer/ScrollContainer/ContainerBox" node_paths=PackedStringArray("container_box") instance=ExtResource("5_14o3q")] -layout_mode = 2 -container_box = NodePath("..") - [node name="ContainerAddButton" type="Button" parent="Panel/VBoxContainer/UIManager/Panel/MarginContainer/ScrollContainer/ContainerBox" node_paths=PackedStringArray("container_box")] layout_mode = 2 tooltip_text = "Add a new collection" diff --git a/src/UI/windows/edit_collection_name_window.gd b/src/UI/windows/edit_collection_name_window.gd new file mode 100644 index 0000000..e9b96e4 --- /dev/null +++ b/src/UI/windows/edit_collection_name_window.gd @@ -0,0 +1,35 @@ +class_name EditCollectionNameWindow extends Window + +@export var text_edit: LineEdit + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + SignalBus.edit_window_requested.connect(on_edit_window_requested) + + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + pass + + +func cancel() -> void: + SignalBus.edit_window_closed.emit() + + +func save() -> void: + SignalBus.edit_window_text_saved.emit(self, text_edit.text) + SignalBus.on_window_closed.emit(self) + + +func on_edit_window_requested(window: Window, text: String) -> void: + if not is_instance_of(window, EditCollectionNameWindow): + return + text_edit.text = text + + +func _on_cancel_button_pressed() -> void: + cancel() + +func _on_save_button_pressed() -> void: + save() diff --git a/src/UI/windows/edit_collection_name_window.gd.uid b/src/UI/windows/edit_collection_name_window.gd.uid new file mode 100644 index 0000000..1495d97 --- /dev/null +++ b/src/UI/windows/edit_collection_name_window.gd.uid @@ -0,0 +1 @@ +uid://cs8uqq3avmeon diff --git a/src/UI/windows/edit_collection_name_window.tscn b/src/UI/windows/edit_collection_name_window.tscn new file mode 100644 index 0000000..730bbdc --- /dev/null +++ b/src/UI/windows/edit_collection_name_window.tscn @@ -0,0 +1,78 @@ +[gd_scene load_steps=8 format=3 uid="uid://bgqshc2r7sdmx"] + +[ext_resource type="Texture2D" uid="uid://bpvgbghct7ayv" path="res://src/assets/icons/x.svg" id="1_4qw31"] +[ext_resource type="Script" uid="uid://cs8uqq3avmeon" path="res://src/UI/windows/edit_collection_name_window.gd" id="1_xruei"] +[ext_resource type="Texture2D" uid="uid://cbj48abbpldb" path="res://src/assets/icons/device-floppy.svg" id="2_xruei"] + +[sub_resource type="InputEventKey" id="InputEventKey_i6crh"] +device = -1 +keycode = 4194305 + +[sub_resource type="Shortcut" id="Shortcut_06rc3"] +events = [SubResource("InputEventKey_i6crh")] + +[sub_resource type="InputEventKey" id="InputEventKey_lut1q"] +device = -1 +ctrl_pressed = true +keycode = 83 +unicode = 115 + +[sub_resource type="Shortcut" id="Shortcut_esnbn"] +events = [SubResource("InputEventKey_lut1q")] + +[node name="EditCollectionNameWindow" type="Window" node_paths=PackedStringArray("text_edit")] +title = "Edit Collection Name" +initial_position = 4 +size = Vector2i(300, 100) +script = ExtResource("1_xruei") +text_edit = NodePath("Panel/MarginContainer/VBoxContainer/LineEdit") + +[node name="Panel" type="Panel" parent="."] +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="MarginContainer" type="MarginContainer" parent="Panel"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_constants/margin_left = 40 +theme_override_constants/margin_top = 40 +theme_override_constants/margin_right = 40 +theme_override_constants/margin_bottom = 40 + +[node name="VBoxContainer" type="VBoxContainer" parent="Panel/MarginContainer"] +layout_mode = 2 +size_flags_vertical = 4 + +[node name="RichTextLabel" type="RichTextLabel" parent="Panel/MarginContainer/VBoxContainer"] +layout_mode = 2 +fit_content = true + +[node name="LineEdit" type="LineEdit" parent="Panel/MarginContainer/VBoxContainer"] +layout_mode = 2 +size_flags_vertical = 4 + +[node name="HBoxContainer" type="HBoxContainer" parent="Panel/MarginContainer/VBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 4 + +[node name="CancelButton" type="Button" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer"] +layout_mode = 2 +shortcut = SubResource("Shortcut_06rc3") +text = "Cancel" +icon = ExtResource("1_4qw31") + +[node name="SaveButton" type="Button" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer"] +layout_mode = 2 +shortcut = SubResource("Shortcut_esnbn") +text = "Save" +icon = ExtResource("2_xruei") + +[connection signal="pressed" from="Panel/MarginContainer/VBoxContainer/HBoxContainer/CancelButton" to="." method="_on_cancel_button_pressed"] +[connection signal="pressed" from="Panel/MarginContainer/VBoxContainer/HBoxContainer/SaveButton" to="." method="_on_save_button_pressed"] diff --git a/src/UI/editmenu.gd b/src/UI/windows/editmenu.gd similarity index 83% rename from src/UI/editmenu.gd rename to src/UI/windows/editmenu.gd index ef3207c..3715441 100644 --- a/src/UI/editmenu.gd +++ b/src/UI/windows/editmenu.gd @@ -1,4 +1,4 @@ -extends Window +class_name Editmenu extends Window @export var text_edit: TextEdit @@ -16,7 +16,9 @@ func _process(delta: float) -> void: func _on_close_requested() -> void: cancel() -func on_edit_window_requested(text: String) -> void: +func on_edit_window_requested(window: Window, text: String) -> void: + if not is_instance_of(window, Editmenu): + return text_edit.text = text func _on_cancel_button_button_down() -> void: @@ -38,6 +40,7 @@ func cancel() -> void: func save() -> void: SignalBus.edit_window_text_saved.emit(text_edit.text) SignalBus.edit_window_closed.emit() + func _on_cancel_button_pressed() -> void: cancel() diff --git a/src/UI/editmenu.gd.uid b/src/UI/windows/editmenu.gd.uid similarity index 100% rename from src/UI/editmenu.gd.uid rename to src/UI/windows/editmenu.gd.uid diff --git a/src/UI/editmenu.tscn b/src/UI/windows/editmenu.tscn similarity index 92% rename from src/UI/editmenu.tscn rename to src/UI/windows/editmenu.tscn index 92124a3..2752d58 100644 --- a/src/UI/editmenu.tscn +++ b/src/UI/windows/editmenu.tscn @@ -1,8 +1,8 @@ [gd_scene load_steps=8 format=3 uid="uid://dcifyvgobrvp5"] -[ext_resource type="Script" uid="uid://cdkqu7he8lkb6" path="res://src/UI/editmenu.gd" id="1_qmobg"] -[ext_resource type="Texture2D" uid="uid://bpvgbghct7ayv" path="res://src/assets/icons/x.svg" id="2_lut1q"] -[ext_resource type="Texture2D" uid="uid://cbj48abbpldb" path="res://src/assets/icons/device-floppy.svg" id="3_i6crh"] +[ext_resource type="Script" uid="uid://cdkqu7he8lkb6" path="res://src/UI/windows/editmenu.gd" id="1_v1pdc"] +[ext_resource type="Texture2D" uid="uid://bpvgbghct7ayv" path="res://src/assets/icons/x.svg" id="2_a7lul"] +[ext_resource type="Texture2D" uid="uid://cbj48abbpldb" path="res://src/assets/icons/device-floppy.svg" id="3_pi283"] [sub_resource type="InputEventKey" id="InputEventKey_i6crh"] device = -1 @@ -25,7 +25,7 @@ title = "Edit Entry" initial_position = 1 size = Vector2i(600, 300) exclusive = true -script = ExtResource("1_qmobg") +script = ExtResource("1_v1pdc") text_edit = NodePath("Panel/MarginContainer/VBoxContainer/TextEdit") [node name="Panel" type="Panel" parent="."] @@ -63,13 +63,13 @@ size_flags_horizontal = 4 layout_mode = 2 shortcut = SubResource("Shortcut_hou23") text = "Cancel" -icon = ExtResource("2_lut1q") +icon = ExtResource("2_a7lul") [node name="SaveButton" type="Button" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer"] layout_mode = 2 shortcut = SubResource("Shortcut_i6crh") text = "Save" -icon = ExtResource("3_i6crh") +icon = ExtResource("3_pi283") [connection signal="close_requested" from="." to="." method="_on_close_requested"] [connection signal="button_down" from="Panel/MarginContainer/VBoxContainer/HBoxContainer/CancelButton" to="." method="_on_cancel_button_button_down"]