diff options
author | jacopograndi <jacopo.grandi@outlook.it> | 2022-01-15 16:29:02 +0100 |
---|---|---|
committer | jacopograndi <jacopo.grandi@outlook.it> | 2022-01-15 16:29:02 +0100 |
commit | c9c5b5d7c2a238310ce7bde336f76d2d1b6f9f29 (patch) | |
tree | c6e935fea995752a0b307e56892e8422fb734c0e /addons/voxel-core/engine/voxel_set_editor | |
parent | 98f356e68b759bf84300290315d4ada09c41f79b (diff) |
moved shapes to loading area & fixed asset paths
Diffstat (limited to 'addons/voxel-core/engine/voxel_set_editor')
-rw-r--r-- | addons/voxel-core/engine/voxel_set_editor/voxel_set_editor.gd | 210 | ||||
-rw-r--r-- | addons/voxel-core/engine/voxel_set_editor/voxel_set_editor.tscn | 257 |
2 files changed, 467 insertions, 0 deletions
diff --git a/addons/voxel-core/engine/voxel_set_editor/voxel_set_editor.gd b/addons/voxel-core/engine/voxel_set_editor/voxel_set_editor.gd new file mode 100644 index 0000000..53acba2 --- /dev/null +++ b/addons/voxel-core/engine/voxel_set_editor/voxel_set_editor.gd @@ -0,0 +1,210 @@ +tool +extends ScrollContainer + + + +## Signals +# Emited when editor needs closing +signal close + + + +## Exported Variables +export(Resource) var voxel_set = null setget set_voxel_set + + + +## Public Variables +var undo_redo : UndoRedo + + + +## Private Variables +var import_file_path := "" + + + +## OnReady Variables +onready var ImportMenu := get_node("HBoxContainer/VBoxContainer/HBoxContainer/HBoxContainer/Import/ImportFile") + +onready var ImportHow := get_node("HBoxContainer/VBoxContainer/HBoxContainer/HBoxContainer/Import/ImportHow") + +onready var VoxelSetInfo := get_node("HBoxContainer/VBoxContainer/VoxelSetInfo") + +onready var VoxelInfo := get_node("HBoxContainer/VBoxContainer/VoxelInfo") + +onready var VoxelID := get_node("HBoxContainer/VBoxContainer/VoxelInfo/HBoxContainer/VoxelID") + +onready var VoxelName := get_node("HBoxContainer/VBoxContainer/VoxelInfo/HBoxContainer/VoxelName") + +onready var VoxelData := get_node("HBoxContainer/VBoxContainer/VoxelInfo/VoxelData") + +onready var VoxelSetViewer := get_node("HBoxContainer/VBoxContainer2/VoxelSetViewer") + +onready var VoxelInspector := get_node("HBoxContainer/VoxelInspector") + +onready var VoxelViewer := get_node("HBoxContainer/VoxelInspector/VoxelViewer") + + + +## Built-In Virtual Methods +func _ready(): + set_voxel_set(voxel_set) + + if not is_instance_valid(undo_redo): + undo_redo = UndoRedo.new() + VoxelSetViewer.undo_redo = undo_redo + VoxelViewer.undo_redo = undo_redo + + + +## Public Methods +func set_voxel_set(value : Resource, update := true) -> void: + if not typeof(voxel_set) == TYPE_NIL and not voxel_set is VoxelSet: + printerr("VoxelSetEditor : Invalid Resource given expected VoxelSet") + return + + if is_instance_valid(voxel_set): + if voxel_set.is_connected("requested_refresh", self, "update_view"): + voxel_set.disconnect("requested_refresh", self, "update_view") + + voxel_set = value + if is_instance_valid(voxel_set): + if not voxel_set.is_connected("requested_refresh", self, "update_view"): + voxel_set.connect("requested_refresh", self, "update_view") + if is_instance_valid(VoxelSetViewer): + VoxelSetViewer.voxel_set = voxel_set + + if update: + update_view() + + +func update_view() -> void: + if is_instance_valid(voxel_set): + if is_instance_valid(VoxelSetInfo): + VoxelSetInfo.text = "Voxels:\t\t" + str(voxel_set.size()) + VoxelSetInfo.text += "\nUV Ready:\t" + str(voxel_set.uv_ready()) + + if is_instance_valid(VoxelSetViewer): + var editing_single : bool = VoxelSetViewer.get_selected_size() == 1 + VoxelSetInfo.size_flags_vertical = Container.SIZE_FILL if editing_single else Container.SIZE_EXPAND_FILL + VoxelInfo.visible = editing_single + VoxelInspector.visible = editing_single + + if editing_single: + var id = VoxelSetViewer.get_selected(0) + + VoxelID.text = str(id) + VoxelName.text = voxel_set.id_to_name(id) + VoxelData.text = var2str(voxel_set.get_voxel(id)) + + VoxelViewer.setup(voxel_set, id) + else: + if not is_instance_valid(VoxelSetInfo): + return + VoxelSetInfo.text = "" + + +# Show import menu centered +func show_import_menu() -> void: + ImportMenu.popup_centered() + + +# Hide import menu +func hide_import_menu() -> void: + ImportMenu.hide() + + +# Show import how centered +func show_import_how(): + ImportHow.popup_centered() + + +# Hide import how +func hide_import_how(): + ImportHow.hide() + + + +## Private Methods +func _on_Refresh_pressed(): + voxel_set.request_refresh() + + +func _on_Import_file_selected(path): + import_file_path = path + show_import_how() + + +func _on_Import_Append_pressed(): + var result = voxel_set.load_file(import_file_path, true) + if result == OK: + voxel_set.request_refresh() + else: + printerr(result) + hide_import_how() + + +func _on_Import_Replace_pressed(): + var result = voxel_set.load_file(import_file_path, false) + if result == OK: + voxel_set.request_refresh() + else: + printerr(result) + hide_import_how() + + +func _on_Close_pressed(): + emit_signal("close") + + +func _on_VoxelID_text_entered(new_id): + if not new_id.is_valid_integer(): + return + new_id = new_id.to_int() + if new_id == VoxelSetViewer.get_selected(0): + return + elif new_id <= -1 or new_id >= voxel_set.size(): + return + + var id = VoxelSetViewer.get_selected(0) + var voxel = voxel_set.get_voxel(id) + undo_redo.create_action("VoxelSetEditor : Set voxel id") + undo_redo.add_do_method(voxel_set, "erase_voxel", id) + undo_redo.add_undo_method(voxel_set, "insert_voxel", id, voxel) + undo_redo.add_do_method(voxel_set, "insert_voxel", new_id, voxel) + undo_redo.add_undo_method(voxel_set, "erase_voxel", new_id) + undo_redo.add_do_method(voxel_set, "request_refresh") + undo_redo.add_undo_method(voxel_set, "request_refresh") + undo_redo.commit_action() + VoxelSetViewer.unselect_all() + VoxelSetViewer.select(new_id) + + +func _on_VoxelName_text_entered(new_name : String): + var voxel_id = VoxelSetViewer.get_selected(0) + var voxel = voxel_set.get_voxel(voxel_id) + if new_name == Voxel.get_name(voxel): + return + + var _voxel = voxel.duplicate(true) + if new_name.empty(): + undo_redo.create_action("VoxelSetEditor : Remove voxel name") + Voxel.remove_name(_voxel) + else: + undo_redo.create_action("VoxelSetEditor : Set voxel name") + Voxel.set_name(_voxel, new_name) + Voxel.clean(_voxel) + undo_redo.add_do_method(voxel_set, "set_voxel", voxel_id, _voxel) + undo_redo.add_undo_method(voxel_set, "set_voxel", voxel_id, voxel) + undo_redo.add_do_method(voxel_set, "request_refresh") + undo_redo.add_undo_method(voxel_set, "request_refresh") + undo_redo.commit_action() + + +func _on_VoxelSetViewer_selected(voxel_id : int): + update_view() + + +func _on_VoxelSetViewer_unselected(voxel_id : int): + update_view() diff --git a/addons/voxel-core/engine/voxel_set_editor/voxel_set_editor.tscn b/addons/voxel-core/engine/voxel_set_editor/voxel_set_editor.tscn new file mode 100644 index 0000000..fe468a6 --- /dev/null +++ b/addons/voxel-core/engine/voxel_set_editor/voxel_set_editor.tscn @@ -0,0 +1,257 @@ +[gd_scene load_steps=5 format=2] + +[ext_resource path="res://addons/voxel-core/controls/voxel_viewer/voxel_viewer.tscn" type="PackedScene" id=1] +[ext_resource path="res://addons/voxel-core/engine/voxel_set_editor/voxel_set_editor.gd" type="Script" id=2] +[ext_resource path="res://addons/voxel-core/assets/classes/voxel_set.png" type="Texture" id=3] +[ext_resource path="res://addons/voxel-core/controls/voxel_set_viewer/voxel_set_viewer.tscn" type="PackedScene" id=4] + +[node name="VoxelSetEditor" type="ScrollContainer"] +anchor_right = 1.0 +margin_bottom = 200.0 +rect_min_size = Vector2( 0, 200 ) +follow_focus = true +scroll_vertical_enabled = false +script = ExtResource( 2 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="HBoxContainer" type="HBoxContainer" parent="."] +margin_right = 1024.0 +margin_bottom = 200.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 + +[node name="VBoxContainer" type="VBoxContainer" parent="HBoxContainer"] +margin_right = 300.0 +margin_bottom = 200.0 +rect_min_size = Vector2( 300, 0 ) +size_flags_vertical = 3 + +[node name="HBoxContainer" type="HBoxContainer" parent="HBoxContainer/VBoxContainer"] +margin_right = 300.0 +margin_bottom = 20.0 + +[node name="TextureRect" type="TextureRect" parent="HBoxContainer/VBoxContainer/HBoxContainer"] +margin_right = 16.0 +margin_bottom = 20.0 +size_flags_vertical = 3 +texture = ExtResource( 3 ) +stretch_mode = 4 + +[node name="Label" type="Label" parent="HBoxContainer/VBoxContainer/HBoxContainer"] +margin_left = 20.0 +margin_top = 3.0 +margin_right = 75.0 +margin_bottom = 17.0 +text = "VoxelSet" + +[node name="HBoxContainer" type="HBoxContainer" parent="HBoxContainer/VBoxContainer/HBoxContainer"] +margin_left = 79.0 +margin_right = 300.0 +margin_bottom = 20.0 +size_flags_horizontal = 3 +alignment = 2 + +[node name="Import" type="Button" parent="HBoxContainer/VBoxContainer/HBoxContainer/HBoxContainer"] +margin_left = 50.0 +margin_right = 106.0 +margin_bottom = 20.0 +hint_tooltip = "Import voxels from file" +text = "Import" + +[node name="ImportFile" type="FileDialog" parent="HBoxContainer/VBoxContainer/HBoxContainer/HBoxContainer/Import"] +margin_right = 315.0 +margin_bottom = 130.0 +rect_min_size = Vector2( 400, 300 ) +window_title = "Open a File" +resizable = true +mode = 0 +filters = PoolStringArray( "*.vox ; VOX Files", "*.png, *.bmp, *.dds, *.exr, *.hdr, *.jpg, *.jpeg, *.tga, *.svg, *.svgz, *.webp; Image Files", "*.gpl; GIMP Palette" ) + +[node name="ImportHow" type="PopupDialog" parent="HBoxContainer/VBoxContainer/HBoxContainer/HBoxContainer/Import"] +margin_right = 40.0 +margin_bottom = 40.0 +rect_min_size = Vector2( 325, 100 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="VBoxContainer" type="VBoxContainer" parent="HBoxContainer/VBoxContainer/HBoxContainer/HBoxContainer/Import/ImportHow"] +anchor_right = 1.0 +anchor_bottom = 1.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 + +[node name="Label" type="Label" parent="HBoxContainer/VBoxContainer/HBoxContainer/HBoxContainer/Import/ImportHow/VBoxContainer"] +margin_top = 17.0 +margin_right = 325.0 +margin_bottom = 31.0 +size_flags_horizontal = 3 +size_flags_vertical = 6 +text = "How to import voxels to VoxelSet?" +align = 1 +valign = 1 + +[node name="HBoxContainer" type="HBoxContainer" parent="HBoxContainer/VBoxContainer/HBoxContainer/HBoxContainer/Import/ImportHow/VBoxContainer"] +margin_top = 52.0 +margin_right = 325.0 +margin_bottom = 100.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 +alignment = 1 + +[node name="Append" type="Button" parent="HBoxContainer/VBoxContainer/HBoxContainer/HBoxContainer/Import/ImportHow/VBoxContainer/HBoxContainer"] +margin_left = 70.0 +margin_top = 14.0 +margin_right = 131.0 +margin_bottom = 34.0 +size_flags_horizontal = 4 +size_flags_vertical = 4 +text = "Append" + +[node name="Replace" type="Button" parent="HBoxContainer/VBoxContainer/HBoxContainer/HBoxContainer/Import/ImportHow/VBoxContainer/HBoxContainer"] +margin_left = 135.0 +margin_top = 14.0 +margin_right = 197.0 +margin_bottom = 34.0 +size_flags_horizontal = 4 +size_flags_vertical = 4 +text = "Replace" + +[node name="Cancel" type="Button" parent="HBoxContainer/VBoxContainer/HBoxContainer/HBoxContainer/Import/ImportHow/VBoxContainer/HBoxContainer"] +margin_left = 201.0 +margin_top = 14.0 +margin_right = 255.0 +margin_bottom = 34.0 +size_flags_horizontal = 4 +size_flags_vertical = 4 +text = "Cancel" + +[node name="Refresh" type="Button" parent="HBoxContainer/VBoxContainer/HBoxContainer/HBoxContainer"] +margin_left = 110.0 +margin_right = 170.0 +margin_bottom = 20.0 +hint_tooltip = "Request refresh from all connected objects" +text = "Refresh" + +[node name="Close" type="Button" parent="HBoxContainer/VBoxContainer/HBoxContainer/HBoxContainer"] +margin_left = 174.0 +margin_right = 221.0 +margin_bottom = 20.0 +hint_tooltip = "Close the VoxelSetEditor" +text = "Close" + +[node name="VoxelSetInfo" type="RichTextLabel" parent="HBoxContainer/VBoxContainer"] +margin_top = 24.0 +margin_right = 300.0 +margin_bottom = 200.0 +rect_min_size = Vector2( 0, 50 ) +size_flags_vertical = 3 + +[node name="VoxelInfo" type="VBoxContainer" parent="HBoxContainer/VBoxContainer"] +visible = false +margin_top = 114.0 +margin_right = 300.0 +margin_bottom = 200.0 +size_flags_vertical = 3 + +[node name="HBoxContainer" type="HBoxContainer" parent="HBoxContainer/VBoxContainer/VoxelInfo"] +margin_right = 300.0 +margin_bottom = 24.0 + +[node name="Label" type="Label" parent="HBoxContainer/VBoxContainer/VoxelInfo/HBoxContainer"] +margin_top = 5.0 +margin_right = 19.0 +margin_bottom = 19.0 +text = "ID:" + +[node name="VoxelID" type="LineEdit" parent="HBoxContainer/VBoxContainer/VoxelInfo/HBoxContainer"] +margin_left = 23.0 +margin_right = 81.0 +margin_bottom = 24.0 +hint_tooltip = "Enter to change id" + +[node name="Label2" type="Label" parent="HBoxContainer/VBoxContainer/VoxelInfo/HBoxContainer"] +margin_left = 85.0 +margin_top = 5.0 +margin_right = 127.0 +margin_bottom = 19.0 +text = "Name:" + +[node name="VoxelName" type="LineEdit" parent="HBoxContainer/VBoxContainer/VoxelInfo/HBoxContainer"] +margin_left = 131.0 +margin_right = 300.0 +margin_bottom = 24.0 +hint_tooltip = "Enter to change name" +size_flags_horizontal = 3 +placeholder_text = "Enter name..." + +[node name="VoxelData" type="RichTextLabel" parent="HBoxContainer/VBoxContainer/VoxelInfo"] +margin_top = 28.0 +margin_right = 300.0 +margin_bottom = 86.0 +size_flags_vertical = 3 + +[node name="HSplitContainer" type="VSeparator" parent="HBoxContainer"] +margin_left = 304.0 +margin_right = 308.0 +margin_bottom = 200.0 + +[node name="VBoxContainer2" type="VBoxContainer" parent="HBoxContainer"] +margin_left = 312.0 +margin_right = 1024.0 +margin_bottom = 200.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 + +[node name="VoxelSetViewer" parent="HBoxContainer/VBoxContainer2" instance=ExtResource( 4 )] +anchor_right = 0.0 +anchor_bottom = 0.0 +margin_right = 712.0 +margin_bottom = 200.0 +size_flags_horizontal = 7 +size_flags_vertical = 3 +search = "" +allow_edit = true +selection_max = -1 +show_hints = true +voxel_set = null + +[node name="VoxelInspector" type="HBoxContainer" parent="HBoxContainer"] +visible = false +margin_left = 684.0 +margin_right = 1024.0 +margin_bottom = 200.0 + +[node name="HSplitContainer2" type="VSeparator" parent="HBoxContainer/VoxelInspector"] +margin_right = 4.0 +margin_bottom = 200.0 + +[node name="VoxelViewer" parent="HBoxContainer/VoxelInspector" instance=ExtResource( 1 )] +anchor_right = 0.0 +anchor_bottom = 0.0 +margin_left = 8.0 +margin_right = 340.0 +margin_bottom = 200.0 +rect_min_size = Vector2( 332, 200 ) +size_flags_horizontal = 0 +size_flags_vertical = 4 +selection_max = 6 +allow_edit = true +view_mode = 1 +camera_sensitivity = 8 +voxel_id = 0 +voxel_set = null + +[connection signal="pressed" from="HBoxContainer/VBoxContainer/HBoxContainer/HBoxContainer/Import" to="." method="show_import_menu"] +[connection signal="file_selected" from="HBoxContainer/VBoxContainer/HBoxContainer/HBoxContainer/Import/ImportFile" to="." method="_on_Import_file_selected"] +[connection signal="pressed" from="HBoxContainer/VBoxContainer/HBoxContainer/HBoxContainer/Import/ImportHow/VBoxContainer/HBoxContainer/Append" to="." method="_on_Import_Append_pressed"] +[connection signal="pressed" from="HBoxContainer/VBoxContainer/HBoxContainer/HBoxContainer/Import/ImportHow/VBoxContainer/HBoxContainer/Replace" to="." method="_on_Import_Replace_pressed"] +[connection signal="pressed" from="HBoxContainer/VBoxContainer/HBoxContainer/HBoxContainer/Import/ImportHow/VBoxContainer/HBoxContainer/Cancel" to="." method="hide_import_how"] +[connection signal="pressed" from="HBoxContainer/VBoxContainer/HBoxContainer/HBoxContainer/Refresh" to="." method="_on_Refresh_pressed"] +[connection signal="pressed" from="HBoxContainer/VBoxContainer/HBoxContainer/HBoxContainer/Close" to="." method="_on_Close_pressed"] +[connection signal="text_entered" from="HBoxContainer/VBoxContainer/VoxelInfo/HBoxContainer/VoxelID" to="." method="_on_VoxelID_text_entered"] +[connection signal="text_entered" from="HBoxContainer/VBoxContainer/VoxelInfo/HBoxContainer/VoxelName" to="." method="_on_VoxelName_text_entered"] +[connection signal="selected_voxel" from="HBoxContainer/VBoxContainer2/VoxelSetViewer" to="." method="_on_VoxelSetViewer_selected"] +[connection signal="unselected_voxel" from="HBoxContainer/VBoxContainer2/VoxelSetViewer" to="." method="_on_VoxelSetViewer_unselected"] |