diff --git a/src/UI/Dialogs/ManageLayouts.gd b/src/UI/Dialogs/ManageLayouts.gd index b6a77e0ff..877137849 100644 --- a/src/UI/Dialogs/ManageLayouts.gd +++ b/src/UI/Dialogs/ManageLayouts.gd @@ -1,11 +1,13 @@ extends AcceptDialog var layout_selected := -1 +var is_editing := false onready var layout_list: ItemList = $VBoxContainer/SavedLayouts -onready var layout_name: LineEdit = $VBoxContainer/HBoxContainer/LayoutName -onready var delete_layout: Button = $VBoxContainer/DeleteLayout -onready var save_layout: Button = $VBoxContainer/HBoxContainer/SaveLayout +onready var edit_layout: Button = find_node("EditLayout") +onready var delete_layout: Button = find_node("DeleteLayout") +onready var layout_settings: ConfirmationDialog = $LayoutSettings +onready var layout_name: LineEdit = $LayoutSettings/LayoutName func _on_ManageLayouts_about_to_show() -> void: @@ -24,29 +26,40 @@ func _on_SavedLayouts_item_activated(index: int) -> void: func _on_SavedLayouts_item_selected(index: int) -> void: layout_selected = index + edit_layout.disabled = index < 2 delete_layout.disabled = index < 2 func _on_SavedLayouts_nothing_selected() -> void: + edit_layout.disabled = true delete_layout.disabled = true +func _on_AddLayout_pressed() -> void: + is_editing = false + layout_name.text = "New Layout" + layout_settings.window_title = "Add Layout" + layout_settings.popup_centered() + + +func _on_EditLayout_pressed() -> void: + is_editing = true + layout_name.text = layout_list.get_item_text(layout_selected) + layout_settings.window_title = "Edit Layout" + layout_settings.popup_centered() + + func _on_DeleteLayout_pressed() -> void: - var dir := Directory.new() - var file_name := layout_list.get_item_text(layout_selected) + ".tres" - dir.remove("user://layouts/".plus_file(file_name)) + delete_layout_file(layout_list.get_item_text(layout_selected) + ".tres") Global.top_menu_container.layouts.remove(layout_selected) layout_list.remove_item(layout_selected) Global.top_menu_container.populate_layouts_submenu() layout_selected = -1 + edit_layout.disabled = true delete_layout.disabled = true -func _on_LayoutName_text_changed(new_text: String) -> void: - save_layout.disabled = new_text.empty() - - -func _on_SaveLayout_pressed() -> void: +func _on_LayoutSettings_confirmed() -> void: var file_name := layout_name.text + ".tres" var path := "user://layouts/".plus_file(file_name) var layout = Global.control.ui.get_layout() @@ -54,8 +67,24 @@ func _on_SaveLayout_pressed() -> void: if err != OK: print(err) else: - Global.top_menu_container.layouts.append([layout_name.text, layout]) - layout_list.add_item(layout_name.text) - Global.top_menu_container.populate_layouts_submenu() - var n: int = Global.top_menu_container.layouts_submenu.get_item_count() - Global.top_menu_container.layouts_submenu.set_item_checked(n - 2, true) + if is_editing: + var old_file_name: String = layout_list.get_item_text(layout_selected) + ".tres" + if old_file_name != file_name: + delete_layout_file(old_file_name) + Global.top_menu_container.layouts[layout_selected][0] = layout_name.text + Global.top_menu_container.layouts[layout_selected][1] = layout + layout_list.set_item_text(layout_selected, layout_name.text) + Global.top_menu_container.layouts_submenu.set_item_text( + layout_selected + 2, layout_name.text + ) + else: + Global.top_menu_container.layouts.append([layout_name.text, layout]) + layout_list.add_item(layout_name.text) + Global.top_menu_container.populate_layouts_submenu() + var n: int = Global.top_menu_container.layouts_submenu.get_item_count() + Global.top_menu_container.layouts_submenu.set_item_checked(n - 2, true) + + +func delete_layout_file(file_name: String) -> void: + var dir := Directory.new() + dir.remove("user://layouts/".plus_file(file_name)) diff --git a/src/UI/Dialogs/ManageLayouts.tscn b/src/UI/Dialogs/ManageLayouts.tscn index dcc323bc1..46c8b9403 100644 --- a/src/UI/Dialogs/ManageLayouts.tscn +++ b/src/UI/Dialogs/ManageLayouts.tscn @@ -8,9 +8,6 @@ margin_bottom = 217.0 window_title = "Manage Layouts" resizable = true script = ExtResource( 1 ) -__meta__ = { -"_edit_use_anchors_": false -} [node name="VBoxContainer" type="VBoxContainer" parent="."] anchor_right = 1.0 @@ -24,7 +21,7 @@ __meta__ = { } [node name="Label" type="Label" parent="VBoxContainer"] -margin_right = 175.0 +margin_right = 200.0 margin_bottom = 14.0 text = "Layouts" __meta__ = { @@ -33,44 +30,65 @@ __meta__ = { [node name="SavedLayouts" type="ItemList" parent="VBoxContainer"] margin_top = 18.0 -margin_right = 175.0 -margin_bottom = 121.0 +margin_right = 200.0 +margin_bottom = 149.0 rect_min_size = Vector2( 0, 20 ) size_flags_vertical = 3 -[node name="DeleteLayout" type="Button" parent="VBoxContainer"] -margin_top = 125.0 -margin_right = 55.0 -margin_bottom = 145.0 +[node name="ButtonsContainer" type="HBoxContainer" parent="VBoxContainer"] +margin_top = 153.0 +margin_right = 200.0 +margin_bottom = 173.0 + +[node name="AddLayout" type="Button" parent="VBoxContainer/ButtonsContainer"] +margin_right = 37.0 +margin_bottom = 20.0 +mouse_default_cursor_shape = 2 +size_flags_horizontal = 0 +text = "Add" + +[node name="EditLayout" type="Button" parent="VBoxContainer/ButtonsContainer"] +margin_left = 41.0 +margin_right = 77.0 +margin_bottom = 20.0 +mouse_default_cursor_shape = 2 +size_flags_horizontal = 0 +disabled = true +text = "Edit" + +[node name="DeleteLayout" type="Button" parent="VBoxContainer/ButtonsContainer"] +margin_left = 81.0 +margin_right = 136.0 +margin_bottom = 20.0 mouse_default_cursor_shape = 2 size_flags_horizontal = 0 disabled = true text = "Delete" -[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"] -margin_top = 149.0 -margin_right = 175.0 -margin_bottom = 173.0 +[node name="LayoutSettings" type="ConfirmationDialog" parent="."] +margin_left = 8.0 +margin_top = 8.0 +margin_right = 208.0 +margin_bottom = 181.0 +resizable = true -[node name="LayoutName" type="LineEdit" parent="VBoxContainer/HBoxContainer"] -margin_right = 130.0 -margin_bottom = 24.0 +[node name="LayoutName" type="LineEdit" parent="LayoutSettings"] +anchor_top = 0.5 +anchor_right = 1.0 +anchor_bottom = 0.5 +margin_left = 8.0 +margin_top = -78.5 +margin_right = -8.0 +margin_bottom = 50.5 size_flags_horizontal = 3 placeholder_text = "Insert name" -[node name="SaveLayout" type="Button" parent="VBoxContainer/HBoxContainer"] -margin_left = 134.0 -margin_right = 175.0 -margin_bottom = 24.0 -mouse_default_cursor_shape = 2 -disabled = true -text = "Save" - [connection signal="about_to_show" from="." to="." method="_on_ManageLayouts_about_to_show"] [connection signal="popup_hide" from="." to="." method="_on_ManageLayouts_popup_hide"] [connection signal="item_activated" from="VBoxContainer/SavedLayouts" to="." method="_on_SavedLayouts_item_activated"] [connection signal="item_selected" from="VBoxContainer/SavedLayouts" to="." method="_on_SavedLayouts_item_selected"] [connection signal="nothing_selected" from="VBoxContainer/SavedLayouts" to="." method="_on_SavedLayouts_nothing_selected"] -[connection signal="pressed" from="VBoxContainer/DeleteLayout" to="." method="_on_DeleteLayout_pressed"] -[connection signal="text_changed" from="VBoxContainer/HBoxContainer/LayoutName" to="." method="_on_LayoutName_text_changed"] -[connection signal="pressed" from="VBoxContainer/HBoxContainer/SaveLayout" to="." method="_on_SaveLayout_pressed"] +[connection signal="pressed" from="VBoxContainer/ButtonsContainer/AddLayout" to="." method="_on_AddLayout_pressed"] +[connection signal="pressed" from="VBoxContainer/ButtonsContainer/EditLayout" to="." method="_on_EditLayout_pressed"] +[connection signal="pressed" from="VBoxContainer/ButtonsContainer/DeleteLayout" to="." method="_on_DeleteLayout_pressed"] +[connection signal="confirmed" from="LayoutSettings" to="." method="_on_LayoutSettings_confirmed"]