Skip to content

Commit

Permalink
columnset button availability
Browse files Browse the repository at this point in the history
  • Loading branch information
rainlizard committed Jun 3, 2024
1 parent d55cc37 commit ceaefea
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 19 deletions.
5 changes: 5 additions & 0 deletions Scenes/ClmControls.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ onready var oDataClm = Nodelist.list["oDataClm"]
onready var oCustomTooltip = Nodelist.list["oCustomTooltip"]
onready var oColumnEditorVoxelView = Nodelist.list["oColumnEditorVoxelView"]
onready var oColumnsetVoxelView = Nodelist.list["oColumnsetVoxelView"]
onready var oSlabsetWindow = Nodelist.list["oSlabsetWindow"]

onready var oColumnIndexSpinBox = $"%ColumnIndexSpinBox"
onready var oGridAdvancedValues = $"%GridAdvancedValues"
Expand Down Expand Up @@ -233,6 +234,10 @@ func adjust_ui_color_if_different():
var cube_spinbox = cubeSpinBoxArray[i]
var cube_is_different = nodeClm["cubes"][column_index][i] != nodeClm.default_data["cubes"][column_index][i]
adjust_spinbox_color(cube_spinbox, cube_is_different)

if nodeClm == Columnset:
oSlabsetWindow.update_save_columnset_button_availability() # Add this line


# Function to check if a property is different from its default value
func is_property_different(property_name, column_index):
Expand Down
55 changes: 36 additions & 19 deletions Scenes/SlabsetWindow.gd
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ onready var oSlabsetPathsLabel = Nodelist.list["oSlabsetPathsLabel"]
onready var oColumnsetPathsLabel = Nodelist.list["oColumnsetPathsLabel"]
onready var oSlabsetTextSIDLabel = Nodelist.list["oSlabsetTextSIDLabel"]
onready var oExportSlabsToml = Nodelist.list["oExportSlabsToml"]
onready var oExportColumnsToml = Nodelist.list["oExportColumnsToml"]
onready var oSlabRevertButton = Nodelist.list["oSlabRevertButton"]
onready var oVarRevertButton = Nodelist.list["oVarRevertButton"]
onready var oSlabsetDeleteButton = Nodelist.list["oSlabsetDeleteButton"]
onready var oColumnsetDeleteButton = Nodelist.list["oColumnsetDeleteButton"]
onready var oConfirmDeleteSlabsetFile = Nodelist.list["oConfirmDeleteSlabsetFile"]
onready var oConfirmDeleteColumnsetFile = Nodelist.list["oConfirmDeleteColumnsetFile"]
onready var oCfgLoader = Nodelist.list["oCfgLoader"]
Expand Down Expand Up @@ -92,6 +94,7 @@ func _notification(what):
match what:
NOTIFICATION_WM_FOCUS_IN:
update_slabset_delete_button_state()
update_columnset_delete_button_state()

func shortcut_pressed(id):
var spinbox = id.get_node("CustomSpinBox")
Expand All @@ -110,6 +113,7 @@ func _on_SlabsetWindow_visibility_changed():
oColumnsetPathsLabel.start()

update_slabset_delete_button_state()
update_columnset_delete_button_state()

yield(get_tree(),'idle_frame')
oDkSlabsetVoxelView.oAllVoxelObjects.visible = true
Expand Down Expand Up @@ -176,6 +180,18 @@ func _on_SlabsetIDSpinBox_value_changed(value):
oSlabsetSlabNameLabel.text = slabName
update_column_spinboxes()


func update_columnset_delete_button_state():
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):
oColumnsetDeleteButton.disabled = false
else:
oColumnsetDeleteButton.disabled = true


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")
Expand Down Expand Up @@ -210,6 +226,13 @@ func update_save_slabset_button_availability():
else:
oExportSlabsToml.disabled = false

func update_save_columnset_button_availability():
var list_of_modified_columns = Columnset.find_all_different_columns()
if list_of_modified_columns.empty():
oExportColumnsToml.disabled = true
else:
oExportColumnsToml.disabled = false

func _on_VariationNumberSpinBox_value_changed(value):

update_column_spinboxes()
Expand Down Expand Up @@ -289,24 +312,16 @@ func _on_ExportSlabsetTomlDialog_file_selected(filePath):

func _on_ExportColumnsetTomlDialog_file_selected(filePath):
Columnset.export_toml_columnset(filePath)


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

buffer.put_u16(1304)
for slab in 1304:
for subtile in 9:
var value = 65536 - Slabset.dat[slab][subtile]
buffer.put_u16(value)
for i in 50:
yield(get_tree(),'idle_frame')

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.")
var dir = Directory.new()
if dir.file_exists(filePath):
update_columnset_delete_button_state()

if oCfgLoader.paths_loaded[oCfgLoader.LOAD_CFG_CURRENT_MAP].has(filePath) == false:
oCfgLoader.paths_loaded[oCfgLoader.LOAD_CFG_CURRENT_MAP].append(filePath)
oColumnsetPathsLabel.start()


func get_current_variation():
Expand Down Expand Up @@ -753,7 +768,7 @@ func _on_ColumnsetHelpButton_pressed():
var helptxt = ""
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."
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 both columnset.toml files will be loaded, but with the local file overwriting any same fields of the file in /fxdata/."
oMessage.big("Help",helptxt)


Expand Down Expand Up @@ -816,6 +831,7 @@ func _on_ConfirmDeleteSlabsetFile_confirmed():
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")
Expand All @@ -842,7 +858,8 @@ func _on_ConfirmDeleteColumnsetFile_confirmed():
oColumnsetControls._on_ColumnIndexSpinBox_value_changed(oColumnsetControls.oColumnIndexSpinBox.value)
oColumnsetControls.adjust_ui_color_if_different()
oColumnsetVoxelView.refresh_entire_view()
oColumnsetVoxelView.update_column_view()

update_columnset_delete_button_state()
else:
oMessage.big("Error", "Failed to delete the file.")
else:
Expand Down

0 comments on commit ceaefea

Please sign in to comment.