Initial sort menu implementation.

This commit is contained in:
Relintai 2022-12-10 13:20:14 +01:00
parent 0e02e5588d
commit b2376afa1c
5 changed files with 294 additions and 5 deletions

View File

@ -3,6 +3,7 @@ extends Control
var _menu : Control
var _settings : Control
var _sort : Control
var _folder_setup_error_popup : AcceptDialog
func hide_all() -> void:
_menu.hide()
@ -10,6 +11,10 @@ func hide_all() -> void:
_sort.hide()
func _on_Sort_pressed() -> void:
if !_sort.validate_folders():
_folder_setup_error_popup.popup_centered()
return
hide_all()
_sort.show()
@ -22,7 +27,7 @@ func _notification(what: int) -> void:
_menu = get_node("Menu")
_settings = get_node("Settings")
_sort = get_node("Sort")
_folder_setup_error_popup = get_node("Control/FolderSetupError")
func _on_Settings_back() -> void:
hide_all()

View File

@ -51,6 +51,20 @@ margin_top = 7.0
margin_right = 1017.0
margin_bottom = 593.0
[node name="Control" type="Control" parent="."]
margin_left = 7.0
margin_top = 7.0
margin_right = 1017.0
margin_bottom = 593.0
mouse_filter = 2
[node name="FolderSetupError" type="AcceptDialog" parent="Control"]
margin_left = 384.0
margin_top = 172.0
margin_right = 597.0
margin_bottom = 230.0
dialog_text = "Folders are not setup properly!"
[connection signal="pressed" from="Menu/VBoxContainer/Sort" to="." method="_on_Sort_pressed"]
[connection signal="pressed" from="Menu/VBoxContainer/Settings" to="." method="_on_Settings_pressed"]
[connection signal="back" from="Settings" to="." method="_on_Settings_back"]

View File

@ -18,9 +18,8 @@ config/target_folder=""
[display]
window/size/width=600
window/handheld/orientation="sensor"
window/stretch/mode="2d"
window/stretch/aspect="expand"
[physics]

154
game/sort/Sort.gd Normal file
View File

@ -0,0 +1,154 @@
extends VBoxContainer
var sort_folder : String
var target_folder : String
var _texture_rect : TextureRect
var _categories_ob : OptionButton
var _sub_categories_ob : OptionButton
var _categories_popup : ConfirmationDialog
var _categories_popup_line_edit : LineEdit
var _sub_categories_popup : ConfirmationDialog
var _sub_categories_popup_line_edit : LineEdit
func refresh_categories() -> void:
_categories_ob.clear()
var tf : Directory = Directory.new()
if tf.open(target_folder) != OK:
return
var folders : PoolStringArray = PoolStringArray()
tf.list_dir_begin(true)
var f : String = tf.get_next()
while !f.empty():
if !tf.current_is_dir():
f = tf.get_next()
continue
folders.push_back(f)
f = tf.get_next()
tf.list_dir_end()
folders.sort()
for i in range(folders.size()):
_categories_ob.add_item(folders[i])
func refresh_sub_categories() -> void:
_sub_categories_ob.clear()
var tf : Directory = Directory.new()
if tf.open(target_folder.append_path(_categories_ob.get_item_text(_categories_ob.selected))) != OK:
return
var folders : PoolStringArray = PoolStringArray()
tf.list_dir_begin(true)
var f : String = tf.get_next()
while !f.empty():
if !tf.current_is_dir():
f = tf.get_next()
continue
folders.push_back(f)
f = tf.get_next()
tf.list_dir_end()
folders.sort()
for i in range(folders.size()):
_sub_categories_ob.add_item(folders[i])
func validate_folders() -> bool:
sort_folder = ProjectSettings.get("application/config/sort_folder")
target_folder = ProjectSettings.get("application/config/target_folder")
if sort_folder.empty() || target_folder.empty():
return false
var d1 : Directory = Directory.new()
if d1.open(sort_folder) != OK:
return false
var d2 : Directory = Directory.new()
if d2.open(target_folder) != OK:
return false
return true
func _on_Apply_pressed() -> void:
pass # Replace with function body.
func _on_Skip_pressed() -> void:
pass # Replace with function body.
func _on_Categories_item_selected(index: int) -> void:
refresh_sub_categories()
func _on_SubCategoies_item_selected(index: int) -> void:
pass # Replace with function body.
func _on_Categories_Add_pressed() -> void:
_categories_popup_line_edit.text = ""
_categories_popup.popup_centered()
func _on_SubCategoies_Add_pressed() -> void:
_sub_categories_popup_line_edit.text = ""
_sub_categories_popup.popup_centered()
func _on_NewCategoryPopup_confirmed() -> void:
if _categories_popup_line_edit.text.empty():
return
var folder : String = target_folder.append_path(_categories_popup_line_edit.text)
print(folder)
var d : Directory = Directory.new()
d.make_dir_recursive(folder)
refresh_categories()
func _on_NewSubCategoryPopup_confirmed() -> void:
if _categories_ob.selected == -1:
return
if _sub_categories_popup_line_edit.text.empty():
return
var folder : String = target_folder.append_path(_categories_ob.get_item_text(_categories_ob.selected))
folder = folder.append_path(_sub_categories_popup_line_edit.text)
print(folder)
var d : Directory = Directory.new()
d.make_dir_recursive(folder)
refresh_sub_categories()
func _notification(what: int) -> void:
if what == NOTIFICATION_READY:
_texture_rect = get_node("ScrollContainer/TextureRect") as TextureRect
_categories_ob = get_node("Categories/Categories") as OptionButton
_sub_categories_ob = get_node("SubCategoies/SubCategoies") as OptionButton
_categories_popup = get_node("Control/NewCategoryPopup") as ConfirmationDialog
_categories_popup_line_edit = get_node("Control/NewCategoryPopup/VBoxContainer/LineEdit") as LineEdit
_sub_categories_popup = get_node("Control/NewSubCategoryPopup") as ConfirmationDialog
_sub_categories_popup_line_edit = get_node("Control/NewSubCategoryPopup/VBoxContainer/LineEdit") as LineEdit
elif what == NOTIFICATION_VISIBILITY_CHANGED:
if is_visible_in_tree():
sort_folder = ProjectSettings.get("application/config/sort_folder")
target_folder = ProjectSettings.get("application/config/target_folder")
refresh_categories()
refresh_sub_categories()

View File

@ -1,5 +1,122 @@
[gd_scene format=2]
[gd_scene load_steps=2 format=2]
[node name="Sort" type="MarginContainer"]
[ext_resource path="res://sort/Sort.gd" type="Script" id=1]
[node name="Sort" type="VBoxContainer"]
margin_right = 1024.0
margin_bottom = 600.0
script = ExtResource( 1 )
[node name="ScrollContainer" type="ScrollContainer" parent="."]
margin_right = 1024.0
margin_bottom = 500.0
size_flags_horizontal = 3
size_flags_vertical = 3
[node name="TextureRect" type="TextureRect" parent="ScrollContainer"]
[node name="Categories" type="HBoxContainer" parent="."]
margin_top = 504.0
margin_right = 1024.0
margin_bottom = 524.0
size_flags_horizontal = 3
[node name="Categories" type="OptionButton" parent="Categories"]
margin_right = 1000.0
margin_bottom = 20.0
size_flags_horizontal = 3
[node name="Add" type="Button" parent="Categories"]
margin_left = 1004.0
margin_right = 1024.0
margin_bottom = 20.0
text = "+"
[node name="SubCategoies" type="HBoxContainer" parent="."]
margin_top = 528.0
margin_right = 1024.0
margin_bottom = 548.0
size_flags_horizontal = 3
[node name="SubCategoies" type="OptionButton" parent="SubCategoies"]
margin_right = 1000.0
margin_bottom = 20.0
size_flags_horizontal = 3
[node name="Add" type="Button" parent="SubCategoies"]
margin_left = 1004.0
margin_right = 1024.0
margin_bottom = 20.0
text = "+"
[node name="Apply" type="Button" parent="."]
margin_top = 552.0
margin_right = 1024.0
margin_bottom = 572.0
text = "Apply"
[node name="Skip" type="Button" parent="."]
margin_top = 576.0
margin_right = 1024.0
margin_bottom = 596.0
text = "Skip"
[node name="Control" type="Control" parent="."]
margin_top = 600.0
margin_right = 1024.0
margin_bottom = 600.0
[node name="NewCategoryPopup" type="ConfirmationDialog" parent="Control"]
margin_left = 291.0
margin_top = -404.0
margin_right = 491.0
margin_bottom = -318.0
window_title = "Add New Category"
[node name="VBoxContainer" type="VBoxContainer" parent="Control/NewCategoryPopup"]
margin_left = 8.0
margin_top = 8.0
margin_right = 192.0
margin_bottom = 50.0
[node name="Label" type="Label" parent="Control/NewCategoryPopup/VBoxContainer"]
margin_right = 184.0
margin_bottom = 14.0
text = "Name"
[node name="LineEdit" type="LineEdit" parent="Control/NewCategoryPopup/VBoxContainer"]
margin_top = 18.0
margin_right = 184.0
margin_bottom = 42.0
[node name="NewSubCategoryPopup" type="ConfirmationDialog" parent="Control"]
margin_left = 291.0
margin_top = -404.0
margin_right = 491.0
margin_bottom = -318.0
window_title = "Add Sub New Category"
[node name="VBoxContainer" type="VBoxContainer" parent="Control/NewSubCategoryPopup"]
margin_left = 8.0
margin_top = 8.0
margin_right = 192.0
margin_bottom = 50.0
[node name="Label" type="Label" parent="Control/NewSubCategoryPopup/VBoxContainer"]
margin_right = 184.0
margin_bottom = 14.0
text = "Name"
[node name="LineEdit" type="LineEdit" parent="Control/NewSubCategoryPopup/VBoxContainer"]
margin_top = 18.0
margin_right = 184.0
margin_bottom = 42.0
[connection signal="item_selected" from="Categories/Categories" to="." method="_on_Categories_item_selected"]
[connection signal="pressed" from="Categories/Add" to="." method="_on_Categories_Add_pressed"]
[connection signal="item_selected" from="SubCategoies/SubCategoies" to="." method="_on_SubCategoies_item_selected"]
[connection signal="pressed" from="SubCategoies/Add" to="." method="_on_SubCategoies_Add_pressed"]
[connection signal="pressed" from="Apply" to="." method="_on_Apply_pressed"]
[connection signal="pressed" from="Skip" to="." method="_on_Skip_pressed"]
[connection signal="confirmed" from="Control/NewCategoryPopup" to="." method="_on_NewCategoryPopup_confirmed"]
[connection signal="confirmed" from="Control/NewSubCategoryPopup" to="." method="_on_NewSubCategoryPopup_confirmed"]