Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhaul custom library creation window #759

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions material_maker/panels/library/create_lib_dialog.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ extends Window


var file_path = ""
var file_name = ""


signal return_info(status)


func _ready():
$VBoxContainer/GridContainer/FilePickerButton.set_mode(FileDialog.FILE_MODE_SAVE_FILE)
$VBoxContainer/GridContainer/FilePickerButton.add_filter("*.json;Material Maker library")
$VBoxContainer/GridContainer/HBoxContainerPath/FilePickerButton.set_mode(FileDialog.FILE_MODE_OPEN_DIR)
popup_centered()

func set_value(v) -> void:
Expand All @@ -22,12 +22,30 @@ func popup_centered_(window_size : Vector2i = Vector2i(0, 0)) -> void:
func _on_LineEdit_text_entered(_new_text) -> void:
pass

func _on_line_edit_text_changed(new_text: String) -> void:
file_name = $VBoxContainer/GridContainer/LineEdit.text
$VBoxContainer/HBoxContainer/OK.disabled = ((file_path == "") || (file_name == ""))

func _on_line_edit_2_text_changed(new_text: String) -> void:
file_path = new_text
$VBoxContainer/HBoxContainer/OK.disabled = ((file_path == "") || (file_name == ""))

func _on_FilePickerButton_file_selected(f):
file_path = f
$VBoxContainer/HBoxContainer/OK.disabled = (file_path == "")
if file_name == "":
$VBoxContainer/GridContainer/HBoxContainerPath/LineEdit2.text = f + "/"
else:
$VBoxContainer/GridContainer/HBoxContainerPath/LineEdit2.text = f + "/" + file_name.validate_filename() + ".json"
file_path = $VBoxContainer/GridContainer/HBoxContainerPath/LineEdit2.text
$VBoxContainer/HBoxContainer/OK.disabled = ((file_path == "") || (file_name == ""))


func _on_OK_pressed() -> void:
emit_signal("return_info", { ok=true, name=$VBoxContainer/GridContainer/LineEdit.text, path=file_path })
var fp
if file_path.ends_with(".json"):
fp = file_path
else:
fp = file_path + "/" + file_name.validate_filename() + ".json"
emit_signal("return_info", { ok=true, name=$VBoxContainer/GridContainer/LineEdit.text, path=fp })

func _on_Cancel_pressed():
emit_signal("return_info", { ok=false })
Expand Down
88 changes: 39 additions & 49 deletions material_maker/panels/library/create_lib_dialog.tscn
Original file line number Diff line number Diff line change
@@ -1,91 +1,81 @@
[gd_scene load_steps=3 format=3 uid="uid://c0ir88hj07hh5"]
[gd_scene load_steps=4 format=3 uid="uid://c0ir88hj07hh5"]

[ext_resource type="Script" path="res://material_maker/panels/library/create_lib_dialog.gd" id="1"]
[ext_resource type="Script" uid="uid://4b20sg0x1nvu" path="res://material_maker/panels/library/create_lib_dialog.gd" id="1"]
[ext_resource type="PackedScene" uid="uid://cfyio0a1b27t0" path="res://material_maker/widgets/file_picker_button/file_picker_button.tscn" id="2"]

[sub_resource type="ImageTexture" id="ImageTexture_8pecb"]

[node name="CreateLibDialog" type="Window"]
offset_right = 321.0
offset_bottom = 76.0
size = Vector2i(600, 100)
exclusive = true
window_title = "New library"
script = ExtResource("1")
__meta__ = {
"_edit_use_anchors_": false
}

[node name="VBoxContainer" type="VBoxContainer" parent="."]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 2.0
offset_top = 2.0
offset_right = -2.0
offset_bottom = -2.0
offset_left = 5.0
offset_top = 5.0
offset_right = -9.0
offset_bottom = 8.0
grow_horizontal = 2
grow_vertical = 2
theme_override_constants/separation = 5
__meta__ = {
"_edit_use_anchors_": false
}

[node name="GridContainer" type="GridContainer" parent="VBoxContainer"]
offset_right = 317.0
offset_bottom = 48.0
layout_mode = 2
columns = 2

[node name="Label1" type="Label" parent="VBoxContainer/GridContainer"]
offset_top = 5.0
offset_right = 87.0
offset_bottom = 19.0
layout_mode = 2
text = "Library name:"

[node name="LineEdit" type="LineEdit" parent="VBoxContainer/GridContainer"]
offset_left = 91.0
offset_right = 317.0
offset_bottom = 24.0
custom_minimum_size = Vector2(200, 0)
layout_mode = 2
size_flags_horizontal = 3
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Label2" type="Label" parent="VBoxContainer/GridContainer"]
offset_top = 31.0
offset_right = 87.0
offset_bottom = 45.0
text = "Library file:"
layout_mode = 2
text = "Library path:"

[node name="HBoxContainerPath" type="HBoxContainer" parent="VBoxContainer/GridContainer"]
layout_mode = 2
size_flags_vertical = 0

[node name="LineEdit2" type="LineEdit" parent="VBoxContainer/GridContainer/HBoxContainerPath"]
layout_mode = 2
size_flags_horizontal = 3
emoji_menu_enabled = false

[node name="FilePickerButton" parent="VBoxContainer/GridContainer" instance=ExtResource("2")]
anchor_right = 0.0
anchor_bottom = 0.0
offset_left = 91.0
offset_top = 28.0
offset_right = 317.0
offset_bottom = 48.0
text = "Click to enter a path"
[node name="FilePickerButton" parent="VBoxContainer/GridContainer/HBoxContainerPath" instance=ExtResource("2")]
custom_minimum_size = Vector2(25, 25)
layout_mode = 2
size_flags_horizontal = 8
size_flags_vertical = 4
text = ""
icon = SubResource("ImageTexture_8pecb")

[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
offset_left = 96.0
offset_top = 53.0
offset_right = 220.0
offset_bottom = 73.0
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 0

[node name="OK" type="Button" parent="VBoxContainer/HBoxContainer"]
offset_right = 60.0
offset_bottom = 20.0
custom_minimum_size = Vector2(60, 0)
layout_mode = 2
disabled = true
text = "OK"

[node name="Cancel" type="Button" parent="VBoxContainer/HBoxContainer"]
offset_left = 64.0
offset_right = 124.0
offset_bottom = 20.0
custom_minimum_size = Vector2(60, 0)
layout_mode = 2
text = "Cancel"

[connection signal="popup_hide" from="." to="." method="_on_Cancel_pressed"]
[connection signal="minimum_size_changed" from="VBoxContainer" to="." method="_on_VBoxContainer_minimum_size_changed"]
[connection signal="text_changed" from="VBoxContainer/GridContainer/LineEdit" to="." method="_on_line_edit_text_changed"]
[connection signal="text_submitted" from="VBoxContainer/GridContainer/LineEdit" to="." method="_on_LineEdit_text_entered"]
[connection signal="file_selected" from="VBoxContainer/GridContainer/FilePickerButton" to="." method="_on_FilePickerButton_file_selected"]
[connection signal="text_changed" from="VBoxContainer/GridContainer/HBoxContainerPath/LineEdit2" to="." method="_on_line_edit_2_text_changed"]
[connection signal="file_selected" from="VBoxContainer/GridContainer/HBoxContainerPath/FilePickerButton" to="." method="_on_FilePickerButton_file_selected"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer/OK" to="." method="_on_OK_pressed"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer/Cancel" to="." method="_on_Cancel_pressed"]
4 changes: 3 additions & 1 deletion material_maker/tools/library_manager/library_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ func get_items(filter : String, sorted := false) -> Array:
func save_library_list() -> void:
var library_list = []
for i in range(2, get_child_count()):
library_list.push_back(get_child(i).library_path)
var lib_path: String = get_child(i).library_path
library_list.push_back(lib_path)
mm_globals.config.set_value(config_section, "libraries", library_list)

func has_library(path : String) -> bool:
Expand All @@ -145,6 +146,7 @@ func create_library(path : String, library_name : String) -> void:
var library = LIBRARY.new()
library.create_library(path, library_name)
add_child(library)
library.save_library()
save_library_list()

func load_library(path : String, data : String = "") -> void:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ func set_mode(m):

func set_path(p : String) -> void:
path = p
text = path.get_file()

func add_filter(f : String) -> void:
filters.append(f)
Expand All @@ -25,7 +24,7 @@ func _on_Control_pressed() -> void:
var dialog = preload("res://material_maker/windows/file_dialog/file_dialog.tscn").instantiate()
dialog.min_size = Vector2i(500, 500)
dialog.access = FileDialog.ACCESS_FILESYSTEM
dialog.mode = mode
dialog.file_mode = mode
dialog.current_dir = path.get_base_dir()
for f in filters:
dialog.add_filter(f)
Expand Down