diff --git a/Scenes/Main.tscn b/Scenes/Main.tscn index 63896be9..b4ee6d9e 100644 --- a/Scenes/Main.tscn +++ b/Scenes/Main.tscn @@ -3094,6 +3094,19 @@ dialog_text = "Delete all columns which have no presence on the map? (a utilized dialog_autowrap = true script = ExtResource( 61 ) +[node name="ConfirmDeleteSlabsetFile" type="ConfirmationDialog" parent="Ui/UiSystem"] +visible = true +margin_left = -456.0 +margin_top = 304.0 +margin_right = -16.0 +margin_bottom = 409.0 +rect_min_size = Vector2( 300, 105 ) +popup_exclusive = true +window_title = "Revert Slabset and delete file" +dialog_text = "Revert all slabs to default and delete map00001.slabset.toml file?" +dialog_autowrap = true +script = ExtResource( 61 ) + [node name="ControlsWindow" type="WindowDialog" parent="Ui/UiSystem"] visible = true margin_left = -2754.0 @@ -5468,7 +5481,7 @@ size_flags_horizontal = 3 size_flags_vertical = 3 [node name="DkSlabsetVoxelView" parent="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabSlabset/HBoxContainer" instance=ExtResource( 19 )] -margin_right = 996.0 +margin_right = 905.0 margin_bottom = 915.0 displayingType = 2 @@ -5483,7 +5496,7 @@ anchor_right = 1.0 anchor_bottom = 1.0 [node name="SlabsetSlabNameLabel" type="Label" parent="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabSlabset/HBoxContainer/DkSlabsetVoxelView/Control/VBoxContainer"] -margin_right = 996.0 +margin_right = 905.0 margin_bottom = 21.0 size_flags_vertical = 1 text = "Impenetrable Rock" @@ -5491,20 +5504,20 @@ align = 2 [node name="VariationInfoLabel" type="Label" parent="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabSlabset/HBoxContainer/DkSlabsetVoxelView/Control/VBoxContainer"] margin_top = 25.0 -margin_right = 996.0 +margin_right = 905.0 margin_bottom = 46.0 size_flags_vertical = 1 text = "Variation info" align = 2 [node name="VBoxContainer" type="VBoxContainer" parent="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabSlabset/HBoxContainer"] -margin_left = 1000.0 +margin_left = 909.0 margin_right = 1236.0 margin_bottom = 915.0 size_flags_vertical = 3 [node name="ScrollContainer" type="ScrollContainer" parent="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabSlabset/HBoxContainer/VBoxContainer"] -margin_right = 236.0 +margin_right = 327.0 margin_bottom = 839.0 size_flags_vertical = 3 scroll_horizontal_enabled = false @@ -5916,20 +5929,19 @@ text = "Export slabs.dat" [node name="PanelContainer" type="PanelContainer" parent="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabSlabset/HBoxContainer/VBoxContainer"] margin_top = 843.0 -margin_right = 236.0 +margin_right = 327.0 margin_bottom = 893.0 [node name="HBoxContainer" type="HBoxContainer" parent="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabSlabset/HBoxContainer/VBoxContainer/PanelContainer"] margin_left = 9.0 margin_top = 9.0 -margin_right = 227.0 +margin_right = 318.0 margin_bottom = 41.0 [node name="SlabsetHelpButton" type="TextureButton" parent="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabSlabset/HBoxContainer/VBoxContainer/PanelContainer/HBoxContainer"] margin_right = 32.0 margin_bottom = 32.0 rect_min_size = Vector2( 32, 32 ) -size_flags_horizontal = 2 size_flags_vertical = 4 texture_normal = ExtResource( 156 ) texture_pressed = ExtResource( 66 ) @@ -5937,9 +5949,17 @@ texture_hover = ExtResource( 128 ) expand = true stretch_mode = 4 +[node name="SlabsetDeleteButton" type="Button" parent="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabSlabset/HBoxContainer/VBoxContainer/PanelContainer/HBoxContainer"] +margin_left = 36.0 +margin_right = 182.0 +margin_bottom = 27.0 +size_flags_horizontal = 3 +size_flags_vertical = 0 +text = "Delete & revert" + [node name="ExportSlabsToml" type="Button" parent="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabSlabset/HBoxContainer/VBoxContainer/PanelContainer/HBoxContainer"] -margin_left = 95.0 -margin_right = 218.0 +margin_left = 186.0 +margin_right = 309.0 margin_bottom = 27.0 size_flags_horizontal = 3 size_flags_vertical = 0 @@ -5947,21 +5967,21 @@ text = "Save slabset" [node name="SlabsetPathsLabel" type="PanelContainer" parent="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabSlabset/HBoxContainer/VBoxContainer"] margin_top = 897.0 -margin_right = 236.0 +margin_right = 327.0 margin_bottom = 915.0 script = ExtResource( 91 ) [node name="ScrollContainer" type="ScrollContainer" parent="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabSlabset/HBoxContainer/VBoxContainer/SlabsetPathsLabel"] margin_left = 9.0 margin_top = 9.0 -margin_right = 227.0 +margin_right = 318.0 margin_bottom = 9.0 size_flags_horizontal = 3 size_flags_vertical = 3 scroll_vertical_enabled = false [node name="VBoxContainer" type="VBoxContainer" parent="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabSlabset/HBoxContainer/VBoxContainer/SlabsetPathsLabel/ScrollContainer"] -margin_right = 218.0 +margin_right = 309.0 size_flags_horizontal = 3 size_flags_vertical = 3 @@ -7495,6 +7515,7 @@ script = SubResource( 20 ) [connection signal="confirmed" from="Ui/UiSystem/ConfirmAutoGen" to="SlabPlacement" method="_on_ConfirmAutoGen_confirmed"] [connection signal="confirmed" from="Ui/UiSystem/ConfirmGenerateScript" to="Ui/UiSystem/MapSettingsWindow/MapSettingsTabs/ScriptGenerator" method="_on_ConfirmGenerateScript_confirmed"] [connection signal="confirmed" from="Ui/UiSystem/ConfirmClmClearUnused" to="Ui/UiSystem/ColumnEditor" method="_on_ConfirmClmClearUnused_confirmed"] +[connection signal="confirmed" from="Ui/UiSystem/ConfirmDeleteSlabsetFile" to="Ui/UiSystem/SlabsetWindow" method="_on_ConfirmDeleteSlabsetFile_confirmed"] [connection signal="about_to_show" from="Ui/UiSystem/AboutWindow" to="Ui/UiSystem/AboutWindow" method="_on_AboutWindow_about_to_show"] [connection signal="visibility_changed" from="Ui/UiSystem/ImageAsMapDialog" to="Ui/UiSystem/ImageAsMapDialog" method="_on_ImageAsMapDialog_visibility_changed"] [connection signal="pressed" from="Ui/UiSystem/ImageAsMapDialog/HBoxContainer/VBoxContainer/HBoxContainer/ImgMapButtonNewMap" to="Ui/UiSystem/ImageAsMapDialog" method="_on_ImgMapButtonNewMap_pressed"] @@ -7579,6 +7600,7 @@ script = SubResource( 20 ) [connection signal="toggled" from="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabSlabset/HBoxContainer/VBoxContainer/ScrollContainer/VBoxContainer/PanelContainer3/VBoxContainer/SlabsetObjectSection/VBoxContainer/GridContainer/ObjIsLightCheckBox" to="Ui/UiSystem/SlabsetWindow" method="_on_ObjIsLightCheckBox_toggled"] [connection signal="pressed" from="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabSlabset/HBoxContainer/VBoxContainer/ScrollContainer/VBoxContainer/SlabsetCopyValues" to="Ui/UiSystem/SlabsetWindow" method="_on_SlabsetCopyValues_pressed"] [connection signal="pressed" from="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabSlabset/HBoxContainer/VBoxContainer/PanelContainer/HBoxContainer/SlabsetHelpButton" to="Ui/UiSystem/SlabsetWindow" method="_on_SlabsetHelpButton_pressed"] +[connection signal="pressed" from="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabSlabset/HBoxContainer/VBoxContainer/PanelContainer/HBoxContainer/SlabsetDeleteButton" to="Ui/UiSystem/SlabsetWindow" method="_on_SlabsetDeleteButton_pressed"] [connection signal="pressed" from="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabSlabset/HBoxContainer/VBoxContainer/PanelContainer/HBoxContainer/ExportSlabsToml" to="Ui/UiSystem/SlabsetWindow" method="_on_ExportSlabsToml_pressed"] [connection signal="pressed" from="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabColumnset/HBoxContainer/VBoxContainer/PanelContainer2/HBoxContainer/ColumnsetHelpButton" to="Ui/UiSystem/SlabsetWindow" method="_on_ColumnsetHelpButton_pressed"] [connection signal="pressed" from="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabColumnset/HBoxContainer/VBoxContainer/PanelContainer2/HBoxContainer/ExportColumnsToml" to="Ui/UiSystem/SlabsetWindow" method="_on_ExportColumnsToml_pressed"] diff --git a/Scenes/SlabsetWindow.gd b/Scenes/SlabsetWindow.gd index 1f72f0a9..8c03efe5 100644 --- a/Scenes/SlabsetWindow.gd +++ b/Scenes/SlabsetWindow.gd @@ -39,6 +39,7 @@ onready var oSlabsetTextSIDLabel = Nodelist.list["oSlabsetTextSIDLabel"] onready var oExportSlabsToml = Nodelist.list["oExportSlabsToml"] onready var oSlabRevertButton = Nodelist.list["oSlabRevertButton"] onready var oVarRevertButton = Nodelist.list["oVarRevertButton"] +onready var oSlabsetDeleteButton = Nodelist.list["oSlabsetDeleteButton"] enum { ONE_VARIATION, @@ -96,6 +97,11 @@ func _ready(): #variation_changed(0) +func _notification(what): + match what: + NOTIFICATION_WM_FOCUS_IN: + update_slabset_delete_button_state() + func shortcut_pressed(id): var spinbox = id.get_node("CustomSpinBox") var clmIndex = spinbox.value @@ -112,9 +118,10 @@ func _on_SlabsetWindow_visibility_changed(): oSlabsetPathsLabel.start() oColumnsetPathsLabel.start() + update_slabset_delete_button_state() + yield(get_tree(),'idle_frame') oDkSlabsetVoxelView.oAllVoxelObjects.visible = true - elif visible == false: if is_instance_valid(oPickSlabWindow): oPickSlabWindow.add_slabs() @@ -191,6 +198,16 @@ func _on_SlabsetIDSpinBox_value_changed(value): oSlabsetSlabNameLabel.text = slabName update_column_spinboxes() +func update_slabset_delete_button_state(): + var mapName = oCurrentMap.path.get_file().get_basename() + var slabsetFilePath = oCurrentMap.path.get_base_dir().plus_file(mapName + ".slabset.toml") + + var dir = Directory.new() + if dir.file_exists(slabsetFilePath): + oSlabsetDeleteButton.disabled = false + else: + oSlabsetDeleteButton.disabled = true + func update_modified_label_for_slab_id(): if Slabset.is_slab_edited(int(oSlabsetIDSpinBox.value)): oSlabsetIDSpinBox.modulate = Color(1.4,1.4,1.7) @@ -292,6 +309,9 @@ func _on_ExportColumnsToml_pressed(): func _on_ExportSlabsetTomlDialog_file_selected(filePath): Slabset.export_toml_slabset(filePath) + for i in 100: + yield(get_tree(),'idle_frame') + update_slabset_delete_button_state() func _on_ExportColumnsetTomlDialog_file_selected(filePath): Columnset.export_toml_columnset(filePath) @@ -734,13 +754,22 @@ func _on_VarRotateButton_pressed(): new_dat.append(Slabset.dat[variation][ROTATION_MAP[i]]) Slabset.dat[variation] = new_dat - # Rotate the object positions within the slab + # Rotate the object subtiles and relative positions within the slab for obj in Slabset.tng[variation]: - var new_x = obj[Slabset.obj.RELATIVE_Y] - var new_y = -obj[Slabset.obj.RELATIVE_X] - obj[Slabset.obj.RELATIVE_X] = new_x - obj[Slabset.obj.RELATIVE_Y] = new_y - obj[Slabset.obj.SUBTILE] = ROTATION_MAP[obj[Slabset.obj.SUBTILE]] + var old_subtile = obj[Slabset.obj.SUBTILE] + var new_subtile = ROTATION_MAP[old_subtile] + obj[Slabset.obj.SUBTILE] = new_subtile + + var old_relative_x = obj[Slabset.obj.RELATIVE_X] + var old_relative_y = obj[Slabset.obj.RELATIVE_Y] + var new_relative_x = 0 + var new_relative_y = 0 + + new_relative_x = old_relative_y + new_relative_y = 256 - old_relative_x + + obj[Slabset.obj.RELATIVE_X] = new_relative_x + obj[Slabset.obj.RELATIVE_Y] = new_relative_y # Update the UI update_column_spinboxes() @@ -748,28 +777,23 @@ func _on_VarRotateButton_pressed(): oMessage.quick("Rotated variation") - - func _on_SlabRevertButton_pressed(): - revert(ALL_VARIATION) + var slabID = int(oSlabsetIDSpinBox.value) + var variations_to_revert = [] + for i in 28: + variations_to_revert.append((slabID * 28) + i) + revert(variations_to_revert) + oMessage.quick("Reverted all 28 variations of current slab ID") -func _on_VarRevertButton_pressed(): - revert(ONE_VARIATION) -func revert(howMany): - var variationsToRevert = [] - if howMany == ALL_VARIATION: - oMessage.quick("Reverted all 28 variations of current slab ID") - var slabBaseId = int(oSlabsetIDSpinBox.value) * 28 - variationsToRevert.resize(28) - for i in 28: - variationsToRevert[i] = slabBaseId + i - else: - oMessage.quick("Reverted current variation") - var current_variation = get_current_variation() - variationsToRevert = [current_variation] +func _on_VarRevertButton_pressed(): + var variations_to_revert = [] + variations_to_revert.append((int(oSlabsetIDSpinBox.value) * 28) + int(oVariationNumberSpinBox.value)) + revert(variations_to_revert) + oMessage.quick("Reverted current variation") - for variation in variationsToRevert: +func revert(variations_to_revert): + for variation in variations_to_revert: # Revert the 'dat' array for the variation if default data is available if variation < Slabset.default_data["dat"].size(): Slabset.dat[variation] = Slabset.default_data["dat"][variation].duplicate() @@ -783,53 +807,21 @@ func revert(howMany): else: if variation < Slabset.tng.size(): Slabset.tng.remove(variation) - update_column_spinboxes() # Update UI for columns - update_objects_ui() # Update UI for objects + + # Update UI for columns and objects + update_column_spinboxes() + update_objects_ui() yield(get_tree(),'idle_frame') oDkSlabsetVoxelView.refresh_entire_view() -#func _on_VarDuplicateButton_pressed(): -# # Find the next free variation space -# var current_variation = get_current_variation() -# var next_free_variation = find_next_free_variation(current_variation) -# -# if next_free_variation == -1: -# oMessage.quick("No free variation spaces available.") -# return -# -# # Duplicate the 'dat' for the current variation -# ensure_dat_array_has_space(next_free_variation) -# Slabset.dat[next_free_variation] = Slabset.dat[current_variation].duplicate() -# -# # Duplicate the 'tng' for the current variation -# ensure_tng_array_has_space(next_free_variation) -# Slabset.tng[next_free_variation] = Slabset.tng[current_variation].duplicate(true) # true for deep copy if needed -# -# # Update UI to reflect the new duplicated variation -# update_column_spinboxes() # Assuming this updates the UI with new column data -# update_objects_ui() # Assuming this updates the UI with new things/objects -# oMessage.quick("Variation duplicated into SlabID: " + str(next_free_variation/28) + ", Variation: " + str(next_free_variation % 28)) -# -# oSlabsetIDSpinBox.value = next_free_variation/28 -# oVariationNumberSpinBox.value = next_free_variation % 28 -# oDkSlabsetVoxelView._on_SlabsetIDSpinBox_value_changed(oSlabsetIDSpinBox.value) -# -#func find_next_free_variation(current_variation): -# for i in range(current_variation+1, 255*28): -# if (i >= Slabset.dat.size() or Slabset.dat[i].empty() or Slabset.dat[i] == [0,0,0, 0,0,0, 0,0,0]) and (i >= Slabset.tng.size() or Slabset.tng[i].empty()): -# return i -## if Slabset.dat[i] == [0,0,0, 0,0,0, 0,0,0] and Slabset.tng[i].empty(): -## return i -# return -1 # Return -1 if no free space is found - func _on_SlabsetHelpButton_pressed(): var helptxt = "" - helptxt += "slabset.toml and columnset.toml affect the appearance of slabs when they're placed. \n" - helptxt += "While these files are automatically loaded when you open your map, they're not automatically saved, so you will need to press this 'Save slabset' button whenever you make any changes.\n" - helptxt += "Also, new entries in terrain.cfg are required for adding new slabs.\n" + helptxt += "slabset.toml and columnset.toml affect the appearance of slabs when they're placed. When placing in Unearth AND when placing in-game. \n" + helptxt += "However keep in mind these files are not automatically saved by Unearth, so you will need to press this 'Save slabset' button whenever you make any changes.\n" + helptxt += "New entries in terrain.cfg are also required in order to add new Slab IDs to the Slabset.\n" oMessage.big("Help",helptxt) func _on_ColumnsetHelpButton_pressed(): @@ -847,3 +839,36 @@ func _on_VarButtonsApplyToAllCheckBox_toggled(button_pressed): else: oMessage.quick("Copy and paste buttons will affect 1 variation") + +onready var oConfirmDeleteSlabsetFile = Nodelist.list["oConfirmDeleteSlabsetFile"] + +func _on_SlabsetDeleteButton_pressed(): + Utils.popup_centered(oConfirmDeleteSlabsetFile) + +func _on_ConfirmDeleteSlabsetFile_confirmed(): + var mapName = oCurrentMap.path.get_file().get_basename() + var slabsetFilePath = oCurrentMap.path.get_base_dir().plus_file(mapName + ".slabset.toml") + + var dir = Directory.new() + if dir.file_exists(slabsetFilePath): + var err = dir.remove(slabsetFilePath) + if err == OK: + oMessage.quick("Deleted: " + slabsetFilePath) + oMessage.quick("Reverted all slabs") + # Revert every slab ID to its default state + var totalSlabs = max(Slabset.dat.size(), Slabset.tng.size()) / 28 + var variations_to_revert = [] + for slabID in totalSlabs: + for i in 28: + variations_to_revert.append((slabID * 28) + i) + revert(variations_to_revert) + + # Update the UI + update_column_spinboxes() + update_objects_ui() + oDkSlabsetVoxelView._on_SlabsetIDSpinBox_value_changed(oSlabsetIDSpinBox.value) + update_slabset_delete_button_state() + else: + oMessage.big("Error", "Failed to delete the file.") + else: + oMessage.big("Error", "The slabset file doesn't exist.")