mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-02-21 21:13:14 +00:00
Changes to ManageLayouts dialog
This commit is contained in:
parent
21b4f3369f
commit
790cd8533a
2 changed files with 91 additions and 44 deletions
|
@ -1,11 +1,13 @@
|
||||||
extends AcceptDialog
|
extends AcceptDialog
|
||||||
|
|
||||||
var layout_selected := -1
|
var layout_selected := -1
|
||||||
|
var is_editing := false
|
||||||
|
|
||||||
onready var layout_list: ItemList = $VBoxContainer/SavedLayouts
|
onready var layout_list: ItemList = $VBoxContainer/SavedLayouts
|
||||||
onready var layout_name: LineEdit = $VBoxContainer/HBoxContainer/LayoutName
|
onready var edit_layout: Button = find_node("EditLayout")
|
||||||
onready var delete_layout: Button = $VBoxContainer/DeleteLayout
|
onready var delete_layout: Button = find_node("DeleteLayout")
|
||||||
onready var save_layout: Button = $VBoxContainer/HBoxContainer/SaveLayout
|
onready var layout_settings: ConfirmationDialog = $LayoutSettings
|
||||||
|
onready var layout_name: LineEdit = $LayoutSettings/LayoutName
|
||||||
|
|
||||||
|
|
||||||
func _on_ManageLayouts_about_to_show() -> void:
|
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:
|
func _on_SavedLayouts_item_selected(index: int) -> void:
|
||||||
layout_selected = index
|
layout_selected = index
|
||||||
|
edit_layout.disabled = index < 2
|
||||||
delete_layout.disabled = index < 2
|
delete_layout.disabled = index < 2
|
||||||
|
|
||||||
|
|
||||||
func _on_SavedLayouts_nothing_selected() -> void:
|
func _on_SavedLayouts_nothing_selected() -> void:
|
||||||
|
edit_layout.disabled = true
|
||||||
delete_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:
|
func _on_DeleteLayout_pressed() -> void:
|
||||||
var dir := Directory.new()
|
delete_layout_file(layout_list.get_item_text(layout_selected) + ".tres")
|
||||||
var file_name := layout_list.get_item_text(layout_selected) + ".tres"
|
|
||||||
dir.remove("user://layouts/".plus_file(file_name))
|
|
||||||
Global.top_menu_container.layouts.remove(layout_selected)
|
Global.top_menu_container.layouts.remove(layout_selected)
|
||||||
layout_list.remove_item(layout_selected)
|
layout_list.remove_item(layout_selected)
|
||||||
Global.top_menu_container.populate_layouts_submenu()
|
Global.top_menu_container.populate_layouts_submenu()
|
||||||
layout_selected = -1
|
layout_selected = -1
|
||||||
|
edit_layout.disabled = true
|
||||||
delete_layout.disabled = true
|
delete_layout.disabled = true
|
||||||
|
|
||||||
|
|
||||||
func _on_LayoutName_text_changed(new_text: String) -> void:
|
func _on_LayoutSettings_confirmed() -> void:
|
||||||
save_layout.disabled = new_text.empty()
|
|
||||||
|
|
||||||
|
|
||||||
func _on_SaveLayout_pressed() -> void:
|
|
||||||
var file_name := layout_name.text + ".tres"
|
var file_name := layout_name.text + ".tres"
|
||||||
var path := "user://layouts/".plus_file(file_name)
|
var path := "user://layouts/".plus_file(file_name)
|
||||||
var layout = Global.control.ui.get_layout()
|
var layout = Global.control.ui.get_layout()
|
||||||
|
@ -54,8 +67,24 @@ func _on_SaveLayout_pressed() -> void:
|
||||||
if err != OK:
|
if err != OK:
|
||||||
print(err)
|
print(err)
|
||||||
else:
|
else:
|
||||||
Global.top_menu_container.layouts.append([layout_name.text, layout])
|
if is_editing:
|
||||||
layout_list.add_item(layout_name.text)
|
var old_file_name: String = layout_list.get_item_text(layout_selected) + ".tres"
|
||||||
Global.top_menu_container.populate_layouts_submenu()
|
if old_file_name != file_name:
|
||||||
var n: int = Global.top_menu_container.layouts_submenu.get_item_count()
|
delete_layout_file(old_file_name)
|
||||||
Global.top_menu_container.layouts_submenu.set_item_checked(n - 2, true)
|
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))
|
||||||
|
|
|
@ -8,9 +8,6 @@ margin_bottom = 217.0
|
||||||
window_title = "Manage Layouts"
|
window_title = "Manage Layouts"
|
||||||
resizable = true
|
resizable = true
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
__meta__ = {
|
|
||||||
"_edit_use_anchors_": false
|
|
||||||
}
|
|
||||||
|
|
||||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
|
@ -24,7 +21,7 @@ __meta__ = {
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="Label" type="Label" parent="VBoxContainer"]
|
[node name="Label" type="Label" parent="VBoxContainer"]
|
||||||
margin_right = 175.0
|
margin_right = 200.0
|
||||||
margin_bottom = 14.0
|
margin_bottom = 14.0
|
||||||
text = "Layouts"
|
text = "Layouts"
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
|
@ -33,44 +30,65 @@ __meta__ = {
|
||||||
|
|
||||||
[node name="SavedLayouts" type="ItemList" parent="VBoxContainer"]
|
[node name="SavedLayouts" type="ItemList" parent="VBoxContainer"]
|
||||||
margin_top = 18.0
|
margin_top = 18.0
|
||||||
margin_right = 175.0
|
margin_right = 200.0
|
||||||
margin_bottom = 121.0
|
margin_bottom = 149.0
|
||||||
rect_min_size = Vector2( 0, 20 )
|
rect_min_size = Vector2( 0, 20 )
|
||||||
size_flags_vertical = 3
|
size_flags_vertical = 3
|
||||||
|
|
||||||
[node name="DeleteLayout" type="Button" parent="VBoxContainer"]
|
[node name="ButtonsContainer" type="HBoxContainer" parent="VBoxContainer"]
|
||||||
margin_top = 125.0
|
margin_top = 153.0
|
||||||
margin_right = 55.0
|
margin_right = 200.0
|
||||||
margin_bottom = 145.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
|
mouse_default_cursor_shape = 2
|
||||||
size_flags_horizontal = 0
|
size_flags_horizontal = 0
|
||||||
disabled = true
|
disabled = true
|
||||||
text = "Delete"
|
text = "Delete"
|
||||||
|
|
||||||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
|
[node name="LayoutSettings" type="ConfirmationDialog" parent="."]
|
||||||
margin_top = 149.0
|
margin_left = 8.0
|
||||||
margin_right = 175.0
|
margin_top = 8.0
|
||||||
margin_bottom = 173.0
|
margin_right = 208.0
|
||||||
|
margin_bottom = 181.0
|
||||||
|
resizable = true
|
||||||
|
|
||||||
[node name="LayoutName" type="LineEdit" parent="VBoxContainer/HBoxContainer"]
|
[node name="LayoutName" type="LineEdit" parent="LayoutSettings"]
|
||||||
margin_right = 130.0
|
anchor_top = 0.5
|
||||||
margin_bottom = 24.0
|
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
|
size_flags_horizontal = 3
|
||||||
placeholder_text = "Insert name"
|
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="about_to_show" from="." to="." method="_on_ManageLayouts_about_to_show"]
|
||||||
[connection signal="popup_hide" from="." to="." method="_on_ManageLayouts_popup_hide"]
|
[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_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="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="nothing_selected" from="VBoxContainer/SavedLayouts" to="." method="_on_SavedLayouts_nothing_selected"]
|
||||||
[connection signal="pressed" from="VBoxContainer/DeleteLayout" to="." method="_on_DeleteLayout_pressed"]
|
[connection signal="pressed" from="VBoxContainer/ButtonsContainer/AddLayout" to="." method="_on_AddLayout_pressed"]
|
||||||
[connection signal="text_changed" from="VBoxContainer/HBoxContainer/LayoutName" to="." method="_on_LayoutName_text_changed"]
|
[connection signal="pressed" from="VBoxContainer/ButtonsContainer/EditLayout" to="." method="_on_EditLayout_pressed"]
|
||||||
[connection signal="pressed" from="VBoxContainer/HBoxContainer/SaveLayout" to="." method="_on_SaveLayout_pressed"]
|
[connection signal="pressed" from="VBoxContainer/ButtonsContainer/DeleteLayout" to="." method="_on_DeleteLayout_pressed"]
|
||||||
|
[connection signal="confirmed" from="LayoutSettings" to="." method="_on_LayoutSettings_confirmed"]
|
||||||
|
|
Loading…
Add table
Reference in a new issue