Skip to content

Commit

Permalink
wip custom slab system
Browse files Browse the repository at this point in the history
  • Loading branch information
rainlizard committed Nov 25, 2023
1 parent ed14f20 commit 9bfc5a5
Show file tree
Hide file tree
Showing 11 changed files with 285 additions and 271 deletions.
193 changes: 90 additions & 103 deletions Autoload/Slabs.gd

Large diffs are not rendered by default.

68 changes: 32 additions & 36 deletions Scenes/AddCustomSlabWindow.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ onready var oDataClmPos = Nodelist.list["oDataClmPos"]
onready var oColumnEditor = Nodelist.list["oColumnEditor"]
onready var oFakeSlabCheckBox = Nodelist.list["oFakeSlabCheckBox"]
onready var oFakeCustomColumnsPanelContainer = Nodelist.list["oFakeCustomColumnsPanelContainer"]
onready var oSlabBitmaskOptionButton = Nodelist.list["oSlabBitmaskOptionButton"]
onready var oSlabIsSolidOptionButton = Nodelist.list["oSlabIsSolidOptionButton"]
onready var oSlabOwnableOptionButton = Nodelist.list["oSlabOwnableOptionButton"]


var scnColumnSetter = preload('res://Scenes/ColumnSetter.tscn')
var customSlabArrayOfSpinbox = []
Expand Down Expand Up @@ -61,53 +65,35 @@ func _on_CustomSlabID_value_changed(value):


func _on_AddCustomSlabButton_pressed():
if oFakeSlabCheckBox.pressed == true:
add_fake_slab()
else:
add_slabset_slab()


func add_slabset_slab():
var newID = oCustomSlabID.value # We'll say fake slabs are ID 1000 and up
#if oCustomSlabSystem.data.has(newID) == true:

var slabName = oNewSlabName.text
var recognizedAs = oCustomSlabID.value
var liquidType = oSlabLiquidOptionButton.get_selected_id()
var wibbleType = oSlabWibbleOptionButton.get_selected_id() #Slabs.WIBBLE_ON
var wibbleType = oSlabWibbleOptionButton.get_selected_id()
var wibbleEdges = oWibbleEdgesCheckBox.pressed

oCustomSlabSystem.add_custom_slab(newID, slabName, recognizedAs, liquidType, wibbleType, wibbleEdges, [], [])

oPickSlabWindow.add_slabs()
oSlabTabs.current_tab = Slabs.TAB_CUSTOM
oPickSlabWindow.set_selection(newID)


func add_fake_slab():
var newID = 1000 # We'll say fake slabs are ID 1000 and up
while true: # Find an unused ID within the fake data dictionary
if oCustomSlabSystem.data.has(newID) == false:
break
else:
var is_fake = oFakeSlabCheckBox.pressed
var newID
if is_fake:
newID = 1000 # We'll say fake slabs are ID 1000 and up
# Find an unused ID within the fake data dictionary
while oCustomSlabSystem.data.has(newID):
newID += 1

var slabName = oNewSlabName.text
var recognizedAs = oCustomSlabID.value
var liquidType = oSlabLiquidOptionButton.get_selected_id()
var wibbleType = oSlabWibbleOptionButton.get_selected_id() #Slabs.WIBBLE_ON
var wibbleEdges = oWibbleEdgesCheckBox.pressed
else:
newID = recognizedAs # For slabset, use the value from the UI
if oCustomSlabSystem.data.has(newID):
oMessage.big("Error", "For Slabset slabs you must use a unique ID. You may need to first delete the existing one.")
return

var slabCubeData = []
var slabFloorData = []
for id in oGridContainerCustomColumns3x3.get_children():
var spinbox = id.get_node("CustomSpinBox")
var clmIndex = spinbox.value
slabCubeData.append(oDataClm.cubes[clmIndex])
slabFloorData.append(oDataClm.floorTexture[clmIndex])
if is_fake: # For fake slabs, gather cube and floor data from the UI elements
for id in oGridContainerCustomColumns3x3.get_children():
var spinbox = id.get_node("CustomSpinBox")
var clmIndex = spinbox.value
slabCubeData.append(oDataClm.cubes[clmIndex])
slabFloorData.append(oDataClm.floorTexture[clmIndex])

oCustomSlabSystem.add_custom_slab(newID, slabName, recognizedAs, liquidType, wibbleType, wibbleEdges, slabCubeData, slabFloorData)

oPickSlabWindow.add_slabs()
oSlabTabs.current_tab = Slabs.TAB_CUSTOM
oPickSlabWindow.set_selection(newID)
Expand Down Expand Up @@ -174,3 +160,13 @@ func _on_HelpCustomSlabsButton_pressed():
var helptext = ""
helptext += "After adding a custom slab, right click on its portrait within the slab selection window to remove it from the editor."
oMessage.big("Help",helptext)


func _on_SlabIsSolidOptionButton_item_selected(index):
pass # Replace with function body.

func _on_SlabOwnableOptionButton_item_selected(index):
pass # Replace with function body.

func _on_SlabBitmaskOptionButton_item_selected(index):
pass # Replace with function body.
104 changes: 46 additions & 58 deletions Scenes/CustomSlabSystem.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,8 @@ onready var oDataClm = Nodelist.list["oDataClm"]
onready var oPickSlabWindow = Nodelist.list["oPickSlabWindow"]
onready var oMessage = Nodelist.list["oMessage"]

var data = {}
var cfg = ConfigFile.new()

enum {
RECOGNIZED_AS
WIBBLE_EDGES
CUBE_DATA
FLOOR_DATA
}

func _ready():
load_file()

Expand All @@ -32,75 +24,71 @@ func load_file():
return

for section in cfg.get_sections():
var newID = int(section.trim_prefix("slab"))
var slabName = cfg.get_value(section, "name")
var recognizedAs = cfg.get_value(section, "recognized_as")
var liquidType = cfg.get_value(section, "liquid_type")
var wibbleType = cfg.get_value(section, "wibble_type")
var wibbleEdges = cfg.get_value(section, "wibble_edges")

var slabCubeData = []
var slabFloorData = []
for i in 9:
slabCubeData.append( cfg.get_value(section, "cubes"+str(i), []))
slabFloorData.append( cfg.get_value(section, "floor"+str(i), []))

add_custom_slab(newID, slabName, recognizedAs, liquidType, wibbleType, wibbleEdges, slabCubeData, slabFloorData)
var slab_dict = {
"header_id": int(section.trim_prefix("slab")),
"name": cfg.get_value(section, "name", "Unknown"),
"recognized_as": cfg.get_value(section, "recognized_as", Slabs.ROCK),
"liquid_type": cfg.get_value(section, "liquid_type", Slabs.REMEMBER_PATH),
"wibble_type": cfg.get_value(section, "wibble_type", Slabs.WIBBLE_ON),
"wibble_edges": cfg.get_value(section, "wibble_edges", false),
"cube_data": slabCubeData,
"floor_data": slabFloorData,
"bitmask": cfg.get_value(section, "bitmask", Slabs.BITMASK_FLOOR),
"is_solid": cfg.get_value(section, "is_solid", Slabs.FLOOR_SLAB),
"ownable": cfg.get_value(section, "ownable", Slabs.OWNABLE)
}

add_custom_slab(slab_dict)


func add_custom_slab(newID, slabName, recognizedAs, liquidType, wibbleType, wibbleEdges, slabCubeData, slabFloorData):

Slabs.data[newID] = [
slabName,
Slabs.BLOCK_SLAB,
Slabs.BITMASK_TALL,
func add_custom_slab(slab_dict):
#var newID = slab_dict.id
#var section = 'slab'+str(newID)
Slabs.data[slab_dict.header_id] = [
slab_dict.name,
slab_dict.is_solid,
slab_dict.bitmask,
Slabs.PANEL_TOP_VIEW,
0,
0, # SIDE_VIEW_Z_OFFSET
Slabs.TAB_CUSTOM,
wibbleType,
liquidType,
Slabs.NOT_OWNABLE
slab_dict.wibble_type,
slab_dict.liquid_type,
slab_dict.ownable
]

data[newID] = [recognizedAs, wibbleEdges, slabCubeData, slabFloorData]
var section = 'slab'+str(newID)
cfg.set_value(section,"name", slabName)
cfg.set_value(section,"recognized_as",int(recognizedAs))
cfg.set_value(section,"liquid_type", liquidType)
cfg.set_value(section,"wibble_type", wibbleType)
cfg.set_value(section,"wibble_edges", wibbleEdges)
var section = 'slab'+str(slab_dict.header_id)
cfg.set_value(section,"name", slab_dict.name)
cfg.set_value(section,"recognized_as", slab_dict.recognized_as)
cfg.set_value(section,"liquid_type", slab_dict.liquid_type)
cfg.set_value(section,"wibble_type", slab_dict.wibble_type)
cfg.set_value(section,"wibble_edges", slab_dict.wibble_edges)
cfg.set_value(section,"bitmask", slab_dict.bitmask)
cfg.set_value(section,"is_solid", slab_dict.is_solid)
cfg.set_value(section,"ownable", slab_dict.ownable)

for i in 9:
if slabCubeData.size() > 0:
cfg.set_value(section,"cubes"+str(i),slabCubeData[i])
if slabFloorData.size() > 0:
cfg.set_value(section,"floor"+str(i),slabFloorData[i])
if slab_dict.cube_data.size() > 0:
cfg.set_value(section,"cubes"+str(i),slab_dict.cube_data[i])
if slab_dict.floor_data.size() > 0:
cfg.set_value(section,"floor"+str(i),slab_dict.floor_data[i])

cfg.save(Settings.unearthdata.plus_file("custom_slabs.cfg"))


# The purpose of this function is so I don't have to index the columns into clm for simply displaying within the slab window. Only index when PLACING the Fake Slab.
func get_top_cube_face(indexIn3x3, slabID):
var cubesArray = data[slabID][CUBE_DATA][indexIn3x3]
var get_height = oDataClm.get_real_height(cubesArray)
if get_height == 0:
return data[slabID][FLOOR_DATA][indexIn3x3]
else:
var cubeID = cubesArray[get_height-1]
if cubeID > Cube.CUBES_COUNT:
return 1
return Cube.tex[cubeID][Cube.SIDE_TOP]

func remove_custom_slab(slabID):
if slabID < 1000: return # means it's not a Fake Slab

print('Attempting to remove Custom Slab:' + str(slabID))
func remove_custom_slab(header_id):
oPickSlabWindow.set_selection(null)

if data.has(slabID):
data.erase(slabID)
var statusOfRemoval = Slabs.data.erase(header_id)
if statusOfRemoval == true:
oMessage.quick("Removed custom slab")
else:
oMessage.quick("Tried to remove a custom slab that wasn't present in the data")

var section = 'slab'+str(slabID)
var section = 'slab'+str(header_id)
if cfg.has_section(section):
cfg.erase_section(section)

Expand Down
1 change: 0 additions & 1 deletion Scenes/Instances.gd
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,6 @@ func on_slab_delete_stray_door_thing_and_key(id, slabID):
if id.is_in_group("Door") or id.is_in_group("Key"):
if Slabs.doors.has(slabID) == false:
id.queue_free()


func on_slab_set_gold_owner_to_slab_owner(id, slabID, ownership):
if slabID == Slabs.TREASURE_ROOM and id.thingType == Things.TYPE.OBJECT and id.subtype in [52,53,54,55,56,3,6,43,136]:
Expand Down
88 changes: 74 additions & 14 deletions Scenes/Main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -5130,19 +5130,19 @@ stretch_mode = 4
[node name="PanelContainer" type="PanelContainer" parent="Ui/UiSystem/AddCustomSlabWindow/MarginContainer/HBoxContainer/VBoxContainer2"]
margin_top = 90.0
margin_right = 347.0
margin_bottom = 261.0
margin_bottom = 354.0
size_flags_horizontal = 3

[node name="VBoxContainer" type="VBoxContainer" parent="Ui/UiSystem/AddCustomSlabWindow/MarginContainer/HBoxContainer/VBoxContainer2/PanelContainer"]
margin_left = 9.0
margin_top = 9.0
margin_right = 338.0
margin_bottom = 162.0
margin_bottom = 255.0
size_flags_horizontal = 3

[node name="GridContainer" type="GridContainer" parent="Ui/UiSystem/AddCustomSlabWindow/MarginContainer/HBoxContainer/VBoxContainer2/PanelContainer/VBoxContainer"]
margin_right = 329.0
margin_bottom = 153.0
margin_bottom = 246.0
size_flags_horizontal = 3
columns = 2
__meta__ = {
Expand Down Expand Up @@ -5226,8 +5226,8 @@ margin_bottom = 122.0
rect_min_size = Vector2( 150, 0 )
hint_tooltip = "If a bridge is placed on this slab, this indicates what's underneath the bridge."
size_flags_horizontal = 10
text = "0 : No"
items = [ "0 : No", null, false, 0, null, "1 : Lava", null, false, 1, null, "2 : Water", null, false, 2, null ]
text = "No"
items = [ "No", null, false, 0, null, "Lava", null, false, 1, null, "Water", null, false, 2, null ]
selected = 0

[node name="Label" type="Label" parent="Ui/UiSystem/AddCustomSlabWindow/MarginContainer/HBoxContainer/VBoxContainer2/PanelContainer/VBoxContainer/GridContainer"]
Expand All @@ -5248,15 +5248,36 @@ margin_bottom = 153.0
rect_min_size = Vector2( 150, 0 )
hint_tooltip = "Sets whether the slab will have a clean appearance, a deformed appearance, or a wavy appearance."
size_flags_horizontal = 10
text = "1 : On"
items = [ "0 : Off", null, false, 0, null, "1 : On", null, false, 1, null, "2 : Animated", null, false, 2, null ]
text = "On"
items = [ "Off", null, false, 0, null, "On", null, false, 1, null, "Animated", null, false, 2, null ]
selected = 1

[node name="Label5" type="Label" parent="Ui/UiSystem/AddCustomSlabWindow/MarginContainer/HBoxContainer/VBoxContainer2/PanelContainer/VBoxContainer/GridContainer"]
margin_top = 160.0
margin_right = 175.0
margin_bottom = 181.0
text = "Bitmask"
__meta__ = {
"_edit_use_anchors_": false
}

[node name="SlabBitmaskOptionButton" type="OptionButton" parent="Ui/UiSystem/AddCustomSlabWindow/MarginContainer/HBoxContainer/VBoxContainer2/PanelContainer/VBoxContainer/GridContainer"]
margin_left = 179.0
margin_top = 157.0
margin_right = 329.0
margin_bottom = 184.0
rect_min_size = Vector2( 150, 0 )
hint_tooltip = "Editor placement rules"
size_flags_horizontal = 10
text = "Floor"
items = [ "Floor", null, false, 0, null, "Reinforced", null, false, 1, null, "Block", null, false, 2, null, "Other", null, false, 3, null, "Claimed", null, false, 4, null ]
selected = 0

[node name="WibbleEdgesSpacing" type="Control" parent="Ui/UiSystem/AddCustomSlabWindow/MarginContainer/HBoxContainer/VBoxContainer2/PanelContainer/VBoxContainer/GridContainer"]
visible = false
margin_top = 157.0
margin_right = 128.0
margin_bottom = 186.0
margin_top = 188.0
margin_right = 175.0
margin_bottom = 209.0
__meta__ = {
"_edit_use_anchors_": false
}
Expand All @@ -5272,10 +5293,46 @@ __meta__ = {
"_edit_use_anchors_": false
}

[node name="Label6" type="Label" parent="Ui/UiSystem/AddCustomSlabWindow/MarginContainer/HBoxContainer/VBoxContainer2/PanelContainer/VBoxContainer/GridContainer"]
margin_top = 191.0
margin_right = 175.0
margin_bottom = 212.0
text = "Type"

[node name="SlabIsSolidOptionButton" type="OptionButton" parent="Ui/UiSystem/AddCustomSlabWindow/MarginContainer/HBoxContainer/VBoxContainer2/PanelContainer/VBoxContainer/GridContainer"]
margin_left = 179.0
margin_top = 188.0
margin_right = 329.0
margin_bottom = 215.0
rect_min_size = Vector2( 150, 0 )
hint_tooltip = "Editor placement rules"
size_flags_horizontal = 10
text = "Block"
items = [ "Floor", null, false, 0, null, "Block", null, false, 1, null ]
selected = 1

[node name="Label7" type="Label" parent="Ui/UiSystem/AddCustomSlabWindow/MarginContainer/HBoxContainer/VBoxContainer2/PanelContainer/VBoxContainer/GridContainer"]
margin_top = 222.0
margin_right = 175.0
margin_bottom = 243.0
text = "Ownable"

[node name="SlabOwnableOptionButton" type="OptionButton" parent="Ui/UiSystem/AddCustomSlabWindow/MarginContainer/HBoxContainer/VBoxContainer2/PanelContainer/VBoxContainer/GridContainer"]
margin_left = 179.0
margin_top = 219.0
margin_right = 329.0
margin_bottom = 246.0
rect_min_size = Vector2( 150, 0 )
hint_tooltip = "Editor placement rules"
size_flags_horizontal = 10
text = "Yes"
items = [ "Yes", null, false, 0, null, "No", null, false, 1, null ]
selected = 0

[node name="FakeCustomColumnsPanelContainer" type="PanelContainer" parent="Ui/UiSystem/AddCustomSlabWindow/MarginContainer/HBoxContainer/VBoxContainer2"]
margin_top = 265.0
margin_top = 358.0
margin_right = 347.0
margin_bottom = 308.0
margin_bottom = 401.0

[node name="VBoxContainer" type="VBoxContainer" parent="Ui/UiSystem/AddCustomSlabWindow/MarginContainer/HBoxContainer/VBoxContainer2/FakeCustomColumnsPanelContainer"]
margin_left = 9.0
Expand All @@ -5301,9 +5358,9 @@ size_flags_vertical = 4
columns = 3

[node name="PanelContainer3" type="PanelContainer" parent="Ui/UiSystem/AddCustomSlabWindow/MarginContainer/HBoxContainer/VBoxContainer2"]
margin_top = 312.0
margin_top = 405.0
margin_right = 347.0
margin_bottom = 362.0
margin_bottom = 455.0

[node name="AddCustomSlabButton" type="Button" parent="Ui/UiSystem/AddCustomSlabWindow/MarginContainer/HBoxContainer/VBoxContainer2/PanelContainer3"]
margin_left = 150.0
Expand Down Expand Up @@ -7041,6 +7098,9 @@ script = SubResource( 20 )
[connection signal="pressed" from="Ui/UiSystem/AddCustomSlabWindow/MarginContainer/HBoxContainer/VBoxContainer2/PanelContainer2/GridContainer/FakeSlabHelpButton" to="Ui/UiSystem/AddCustomSlabWindow" method="_on_FakeSlabHelpButton_pressed"]
[connection signal="value_changed" from="Ui/UiSystem/AddCustomSlabWindow/MarginContainer/HBoxContainer/VBoxContainer2/PanelContainer/VBoxContainer/GridContainer/CustomSlabID" to="Ui/UiSystem/AddCustomSlabWindow" method="_on_CustomSlabID_value_changed"]
[connection signal="item_selected" from="Ui/UiSystem/AddCustomSlabWindow/MarginContainer/HBoxContainer/VBoxContainer2/PanelContainer/VBoxContainer/GridContainer/SlabWibbleOptionButton" to="Ui/UiSystem/AddCustomSlabWindow" method="_on_SlabWibbleOptionButton_item_selected"]
[connection signal="item_selected" from="Ui/UiSystem/AddCustomSlabWindow/MarginContainer/HBoxContainer/VBoxContainer2/PanelContainer/VBoxContainer/GridContainer/SlabBitmaskOptionButton" to="Ui/UiSystem/AddCustomSlabWindow" method="_on_SlabBitmaskOptionButton_item_selected"]
[connection signal="item_selected" from="Ui/UiSystem/AddCustomSlabWindow/MarginContainer/HBoxContainer/VBoxContainer2/PanelContainer/VBoxContainer/GridContainer/SlabIsSolidOptionButton" to="Ui/UiSystem/AddCustomSlabWindow" method="_on_SlabIsSolidOptionButton_item_selected"]
[connection signal="item_selected" from="Ui/UiSystem/AddCustomSlabWindow/MarginContainer/HBoxContainer/VBoxContainer2/PanelContainer/VBoxContainer/GridContainer/SlabOwnableOptionButton" to="Ui/UiSystem/AddCustomSlabWindow" method="_on_SlabOwnableOptionButton_item_selected"]
[connection signal="pressed" from="Ui/UiSystem/AddCustomSlabWindow/MarginContainer/HBoxContainer/VBoxContainer2/PanelContainer3/AddCustomSlabButton" to="Ui/UiSystem/AddCustomSlabWindow" method="_on_AddCustomSlabButton_pressed"]
[connection signal="pressed" from="Ui/UiSystem/AddCustomSlabWindow/MarginContainer/HBoxContainer/VBoxContainer2/PanelContainer3/HelpCustomSlabsButton" to="Ui/UiSystem/AddCustomSlabWindow" method="_on_HelpCustomSlabsButton_pressed"]
[connection signal="visibility_changed" from="Ui/UiSystem/SlabsetWindow" to="Ui/UiSystem/SlabsetWindow" method="_on_SlabsetWindow_visibility_changed"]
Expand Down
Loading

0 comments on commit 9bfc5a5

Please sign in to comment.