Skip to content

Commit

Permalink
add columnset buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
rainlizard committed Jun 3, 2024
1 parent 9baf9d2 commit d55cc37
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 110 deletions.
20 changes: 12 additions & 8 deletions Scenes/ClmControls.gd
Original file line number Diff line number Diff line change
Expand Up @@ -282,18 +282,22 @@ func _on_ColumnPasteButton_pressed():
oMessage.quick("Pasted column from clipboard")
nodeVoxelView.refresh_entire_view()

func revert_columns(column_ids):
for column_id in column_ids:
nodeClm.height[column_id] = nodeClm.default_data["height"][column_id]
nodeClm.solidMask[column_id] = nodeClm.default_data["solidMask"][column_id]
nodeClm.permanent[column_id] = nodeClm.default_data["permanent"][column_id]
nodeClm.orientation[column_id] = nodeClm.default_data["orientation"][column_id]
nodeClm.lintel[column_id] = nodeClm.default_data["lintel"][column_id]
nodeClm.floorTexture[column_id] = nodeClm.default_data["floorTexture"][column_id]
nodeClm.utilized[column_id] = nodeClm.default_data["utilized"][column_id]
nodeClm.cubes[column_id] = nodeClm.default_data["cubes"][column_id].duplicate(true)

func _on_ColumnRevertButton_pressed():
if nodeClm == oDataClm:
oEditor.mapHasBeenEdited = true
var clmIndex = int(oColumnIndexSpinBox.value)
nodeClm.height[clmIndex] = nodeClm.default_data["height"][clmIndex]
nodeClm.solidMask[clmIndex] = nodeClm.default_data["solidMask"][clmIndex]
nodeClm.permanent[clmIndex] = nodeClm.default_data["permanent"][clmIndex]
nodeClm.orientation[clmIndex] = nodeClm.default_data["orientation"][clmIndex]
nodeClm.lintel[clmIndex] = nodeClm.default_data["lintel"][clmIndex]
nodeClm.floorTexture[clmIndex] = nodeClm.default_data["floorTexture"][clmIndex]
nodeClm.utilized[clmIndex] = nodeClm.default_data["utilized"][clmIndex]
nodeClm.cubes[clmIndex] = nodeClm.default_data["cubes"][clmIndex].duplicate(true)
revert_columns([clmIndex])

_on_ColumnIndexSpinBox_value_changed(clmIndex) # Refresh UI
oMessage.quick("Reverted column to default")
Expand Down
54 changes: 42 additions & 12 deletions Scenes/Main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -3107,6 +3107,19 @@ dialog_text = "<adjusted in code>"
dialog_autowrap = true
script = ExtResource( 61 )

[node name="ConfirmDeleteColumnsetFile" 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 Columnset and delete file"
dialog_text = "<adjusted in code>"
dialog_autowrap = true
script = ExtResource( 61 )

[node name="ControlsWindow" type="WindowDialog" parent="Ui/UiSystem"]
visible = true
margin_left = -2754.0
Expand Down Expand Up @@ -5465,6 +5478,7 @@ size_flags_horizontal = 3
size_flags_vertical = 3

[node name="TabSlabset" type="VBoxContainer" parent="Ui/UiSystem/SlabsetWindow/SlabsetTabs"]
visible = false
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 12.0
Expand Down Expand Up @@ -5523,7 +5537,7 @@ size_flags_vertical = 3
scroll_horizontal_enabled = false

[node name="VBoxContainer" type="VBoxContainer" parent="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabSlabset/HBoxContainer/VBoxContainer/ScrollContainer"]
margin_right = 236.0
margin_right = 18.0
margin_bottom = 839.0
size_flags_vertical = 3

Expand Down Expand Up @@ -5986,7 +6000,6 @@ size_flags_horizontal = 3
size_flags_vertical = 3

[node name="TabColumnset" type="VBoxContainer" parent="Ui/UiSystem/SlabsetWindow/SlabsetTabs"]
visible = false
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 12.0
Expand Down Expand Up @@ -6027,23 +6040,37 @@ align = 1
[node name="ColumnsetControls" parent="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabColumnset/HBoxContainer/VBoxContainer" instance=ExtResource( 137 )]
margin_top = 43.0
margin_right = 226.0
margin_bottom = 839.0
margin_bottom = 808.0
size_flags_horizontal = 1

[node name="PanelContainer2" type="PanelContainer" parent="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabColumnset/HBoxContainer/VBoxContainer"]
margin_top = 843.0
margin_top = 812.0
margin_right = 226.0
margin_bottom = 893.0

[node name="HBoxContainer" type="HBoxContainer" parent="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabColumnset/HBoxContainer/VBoxContainer/PanelContainer2"]
[node name="GridContainer" type="GridContainer" parent="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabColumnset/HBoxContainer/VBoxContainer/PanelContainer2"]
margin_left = 9.0
margin_top = 9.0
margin_right = 217.0
margin_bottom = 41.0
margin_bottom = 72.0
columns = 2

[node name="ColumnsetHelpButton" type="TextureButton" parent="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabColumnset/HBoxContainer/VBoxContainer/PanelContainer2/HBoxContainer"]
[node name="Spacing" type="Control" parent="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabColumnset/HBoxContainer/VBoxContainer/PanelContainer2/GridContainer"]
margin_right = 51.0
margin_bottom = 32.0
margin_bottom = 27.0

[node name="ColumnsetDeleteButton" type="Button" parent="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabColumnset/HBoxContainer/VBoxContainer/PanelContainer2/GridContainer"]
margin_left = 55.0
margin_right = 208.0
margin_bottom = 27.0
size_flags_horizontal = 3
size_flags_vertical = 0
text = "Delete & revert"

[node name="ColumnsetHelpButton" type="TextureButton" parent="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabColumnset/HBoxContainer/VBoxContainer/PanelContainer2/GridContainer"]
margin_top = 31.0
margin_right = 51.0
margin_bottom = 63.0
rect_min_size = Vector2( 32, 32 )
size_flags_horizontal = 3
size_flags_vertical = 4
Expand All @@ -6053,10 +6080,11 @@ texture_hover = ExtResource( 128 )
expand = true
stretch_mode = 4

[node name="ExportColumnsToml" type="Button" parent="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabColumnset/HBoxContainer/VBoxContainer/PanelContainer2/HBoxContainer"]
[node name="ExportColumnsToml" type="Button" parent="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabColumnset/HBoxContainer/VBoxContainer/PanelContainer2/GridContainer"]
margin_left = 55.0
margin_top = 31.0
margin_right = 208.0
margin_bottom = 27.0
margin_bottom = 58.0
size_flags_horizontal = 3
size_flags_vertical = 0
text = "Save columnset"
Expand Down Expand Up @@ -7516,6 +7544,7 @@ script = SubResource( 20 )
[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="confirmed" from="Ui/UiSystem/ConfirmDeleteColumnsetFile" to="Ui/UiSystem/SlabsetWindow" method="_on_ConfirmDeleteColumnsetFile_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"]
Expand Down Expand Up @@ -7602,8 +7631,9 @@ script = SubResource( 20 )
[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"]
[connection signal="pressed" from="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabColumnset/HBoxContainer/VBoxContainer/PanelContainer2/GridContainer/ColumnsetDeleteButton" to="Ui/UiSystem/SlabsetWindow" method="_on_ColumnsetDeleteButton_pressed"]
[connection signal="pressed" from="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabColumnset/HBoxContainer/VBoxContainer/PanelContainer2/GridContainer/ColumnsetHelpButton" to="Ui/UiSystem/SlabsetWindow" method="_on_ColumnsetHelpButton_pressed"]
[connection signal="pressed" from="Ui/UiSystem/SlabsetWindow/SlabsetTabs/TabColumnset/HBoxContainer/VBoxContainer/PanelContainer2/GridContainer/ExportColumnsToml" to="Ui/UiSystem/SlabsetWindow" method="_on_ExportColumnsToml_pressed"]
[connection signal="visibility_changed" from="Ui/UiSystem/NewMapWindow" to="Ui/UiSystem/NewMapWindow" method="_on_NewMapWindow_visibility_changed"]
[connection signal="item_selected" from="Ui/UiSystem/NewMapWindow/MarginContainer/HBoxContainer/VBoxContainer/HBoxContainer3/SetNewFormat" to="Ui/UiSystem/NewMapWindow" method="_on_NewMapFormat_item_selected"]
[connection signal="focus_exited" from="Ui/UiSystem/NewMapWindow/MarginContainer/HBoxContainer/VBoxContainer/HBoxContainer2/HBoxContainer/XSizeLine" to="Ui/UiSystem/NewMapWindow" method="_on_XSizeLine_focus_exited"]
Expand Down
135 changes: 45 additions & 90 deletions Scenes/SlabsetWindow.gd
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ onready var oSlabRevertButton = Nodelist.list["oSlabRevertButton"]
onready var oVarRevertButton = Nodelist.list["oVarRevertButton"]
onready var oSlabsetDeleteButton = Nodelist.list["oSlabsetDeleteButton"]
onready var oConfirmDeleteSlabsetFile = Nodelist.list["oConfirmDeleteSlabsetFile"]
onready var oConfirmDeleteColumnsetFile = Nodelist.list["oConfirmDeleteColumnsetFile"]
onready var oCfgLoader = Nodelist.list["oCfgLoader"]

enum {
Expand All @@ -67,20 +68,13 @@ onready var object_field_nodes = [

var scnColumnSetter = preload('res://Scenes/ColumnSetter.tscn')

# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var columnSettersArray = []

# Called when the node enters the scene tree for the first time.
func _ready():
oSlabsetTabs.set_tab_title(0, "Slabset") #slabs.dat
oSlabsetTabs.set_tab_title(1, "Columnset") #slabs.clm

# for i in 2:
# yield(get_tree(),'idle_frame')
# Utils.popup_centered(self)

for number in 9:
var id = scnColumnSetter.instance()
var spinbox = id.get_node("CustomSpinBox")
Expand All @@ -93,11 +87,6 @@ func _ready():
columnSettersArray.append(id)

oDkSlabsetVoxelView.initialize()

#yield(get_tree(),'idle_frame')
#_on_SlabsetIDSpinBox_value_changed(0)

#variation_changed(0)

func _notification(what):
match what:
Expand Down Expand Up @@ -179,19 +168,6 @@ func variation_changed(localVariation):
oVariationInfoLabel.text = constructString
update_objects_ui()

#enum dir {
# s = 0
# w = 1
# n = 2
# e = 3
# sw = 4
# nw = 5
# ne = 6
# se = 7
# all = 8
# center = 27
#}

func _on_SlabsetIDSpinBox_value_changed(value):
var slabName = "Unknown"
value = int(value)
Expand Down Expand Up @@ -279,18 +255,6 @@ func _on_SlabsetCopyValues_pressed():
oPickSlabWindow._on_pressed_add_new_custom_slab()


#func _on_ExportSlabsDat_pressed():
# Utils.popup_centered(oExportSlabsetDatDialog)
# oExportSlabsetDatDialog.current_dir = oGame.GAME_DIRECTORY.plus_file("")
# oExportSlabsetDatDialog.current_path = oGame.GAME_DIRECTORY.plus_file("")
# oExportSlabsetDatDialog.current_file = "slabs.dat"
#func _on_ExportSlabsClm_pressed():
# Utils.popup_centered(oExportSlabsetClmDialog)
# oExportSlabsetClmDialog.current_dir = oGame.GAME_DIRECTORY.plus_file("")
# oExportSlabsetClmDialog.current_path = oGame.GAME_DIRECTORY.plus_file("")
# oExportSlabsetClmDialog.current_file = "slabs.clm"


func _on_ExportSlabsToml_pressed():
Utils.popup_centered(oExportSlabsetTomlDialog)
oExportSlabsetTomlDialog.current_dir = oCurrentMap.path.get_base_dir().plus_file("")
Expand Down Expand Up @@ -327,18 +291,6 @@ func _on_ExportColumnsetTomlDialog_file_selected(filePath):
Columnset.export_toml_columnset(filePath)


#func _on_ImportSlabsetTomlDialog_file_selected(filePath):
# var fullImport = false
# Slabset.import_toml_slabset(filePath, fullImport, true)
# update_column_spinboxes()
# update_objects_ui()
#
#func _on_ImportColumnsetTomlDialog_file_selected(filePath):
# var fullImport = false
# Columnset.import_toml_columnset(filePath, fullImport, true)
# # Update columnset visuals here
# oColumnsetVoxelView.refresh_entire_view()

func _on_ExportSlabsetDatDialog_file_selected(filePath):
var buffer = StreamPeerBuffer.new()

Expand All @@ -357,35 +309,6 @@ func _on_ExportSlabsetDatDialog_file_selected(filePath):
oMessage.big("Error", "Couldn't save file, maybe try saving to another directory.")


#func _on_ExportSlabsetClmDialog_file_selected(filePath):
# var buffer = StreamPeerBuffer.new()
#
# var numberOfClmEntries = 2048
# buffer.put_16(numberOfClmEntries)
# buffer.put_16(0)
## buffer.put_16(numberOfClmEntries)
## buffer.put_data([0,0])
## buffer.put_16(0)
## buffer.put_data([0,0])
#
# for entry in numberOfClmEntries:
# buffer.put_16(Columnset.utilized[entry]) # 0-1
# buffer.put_8((Columnset.permanent[entry] & 1) + ((Columnset.lintel[entry] & 7) << 1) + ((Columnset.height[entry] & 15) << 4))
# buffer.put_16(Columnset.solidMask[entry]) # 3-4
# buffer.put_16(Columnset.floorTexture[entry]) # 5-6
# buffer.put_8(Columnset.orientation[entry]) # 7
#
# for cubeNumber in 8:
# buffer.put_16(Columnset.cubes[entry][cubeNumber]) # 8-23
#
# var file = File.new()
# if file.open(filePath,File.WRITE) == OK:
# file.store_buffer(buffer.data_array)
# file.close()
# oMessage.quick("Saved: " + filePath)
# else:
# oMessage.big("Error", "Couldn't save file, maybe try saving to another directory.")

func get_current_variation():
return (int(oSlabsetIDSpinBox.value) * 28) + int(oVariationNumberSpinBox.value)

Expand Down Expand Up @@ -740,14 +663,6 @@ func paste(howMany):
update_objects_ui()
oDkSlabsetVoxelView._on_SlabsetIDSpinBox_value_changed(oSlabsetIDSpinBox.value)



const ROTATION_POSITIONS = [ # New positions for subtiles after rotation
6, 3, 0,
7, 4, 1,
8, 5, 2,
]

const ROTATION_MAP = {
0: 6, 1: 3, 2: 0,
3: 7, 4: 4, 5: 1,
Expand Down Expand Up @@ -836,10 +751,9 @@ func _on_SlabsetHelpButton_pressed():

func _on_ColumnsetHelpButton_pressed():
var helptxt = ""
helptxt += "Be wary not to confuse the Columnset with the Map Columns. \n"
helptxt += "Map Columns are read from the map's local file such as map00001.clm \n"
helptxt += "Whereas Columnset is a global file loaded from /fxdata/columnset.toml \n"
helptxt += "However you can export a columnset.toml file to use for your own mappack/campaign."
helptxt += "Be wary not to confuse the Columnset with the Map Columns. Map Columns (.clm) are the appearance of any columns that have already been placed on the map, while the Columnset (.toml) is the appearance of any new columns that are placed in the future. \n"
helptxt += "\n"
helptxt += "columnset.toml is a global file in /fxdata/ that is used by all maps in the game, but it can also be saved as a local file to a map or campaign. When you run the game, the files are merged together."
oMessage.big("Help",helptxt)


Expand All @@ -861,6 +775,15 @@ func _on_SlabsetDeleteButton_pressed():
Utils.popup_centered(oConfirmDeleteSlabsetFile)


func _on_ColumnsetDeleteButton_pressed():
oConfirmDeleteColumnsetFile.dialog_text = "Revert all columns to default and delete this file?\n"
var mapName = oCurrentMap.path.get_file().get_basename()
var columnsetFilePath = oCurrentMap.path.get_base_dir().plus_file(mapName + ".columnset.toml")
oConfirmDeleteColumnsetFile.dialog_text += columnsetFilePath
oConfirmDeleteColumnsetFile.rect_min_size.x = 800
Utils.popup_centered(oConfirmDeleteColumnsetFile)


func _on_ConfirmDeleteSlabsetFile_confirmed():
var mapName = oCurrentMap.path.get_file().get_basename()
var slabsetFilePath = oCurrentMap.path.get_base_dir().plus_file(mapName + ".slabset.toml")
Expand Down Expand Up @@ -892,3 +815,35 @@ func _on_ConfirmDeleteSlabsetFile_confirmed():
oMessage.big("Error", "Failed to delete the file.")
else:
oMessage.big("Error", "The slabset file doesn't exist.")

func _on_ConfirmDeleteColumnsetFile_confirmed():
var mapName = oCurrentMap.path.get_file().get_basename()
var columnsetFilePath = oCurrentMap.path.get_base_dir().plus_file(mapName + ".columnset.toml")

var dir = Directory.new()
if dir.file_exists(columnsetFilePath):
var err = dir.remove(columnsetFilePath)
if err == OK:
oMessage.quick("Deleted: " + columnsetFilePath)
oMessage.quick("Reverted all columns")

# Revert every column to its default state
var column_ids = []
for column_id in Columnset.default_data["cubes"].size():
column_ids.append(column_id)
oColumnsetControls.revert_columns(column_ids)

# Remove from the little box thing of currently loaded files
oCfgLoader.paths_loaded[oCfgLoader.LOAD_CFG_CURRENT_MAP].erase(columnsetFilePath)
oColumnsetPathsLabel.start()

# Update the UI
update_column_spinboxes()
oColumnsetControls._on_ColumnIndexSpinBox_value_changed(oColumnsetControls.oColumnIndexSpinBox.value)
oColumnsetControls.adjust_ui_color_if_different()
oColumnsetVoxelView.refresh_entire_view()
oColumnsetVoxelView.update_column_view()
else:
oMessage.big("Error", "Failed to delete the file.")
else:
oMessage.big("Error", "The columnset file doesn't exist.")

0 comments on commit d55cc37

Please sign in to comment.