This commit is contained in:
2024-11-04 17:25:09 +08:00
parent c87de7de5d
commit 471d425b23
30 changed files with 2319 additions and 584 deletions
@@ -152,6 +152,7 @@ func set_enhanced_gridmap(gridmap: EnhancedGridMap):
if enhanced_gridmap:
if enhanced_gridmap.grid_updated.is_connected(_on_grid_updated):
enhanced_gridmap.grid_updated.disconnect(_on_grid_updated)
enhanced_gridmap = gridmap
if enhanced_gridmap:
@@ -193,7 +194,7 @@ func _update_grid_ui():
var item_list = enhanced_gridmap.mesh_library.get_item_list()
var current_floor = floor_spin.value as int
for z in range(enhanced_gridmap.rows):
var row_container = HBoxContainer.new()
row_container.size_flags_horizontal = Control.SIZE_EXPAND_FILL
@@ -204,7 +205,7 @@ func _update_grid_ui():
var cell_container = VBoxContainer.new()
cell_container.size_flags_horizontal = Control.SIZE_EXPAND_FILL
cell_container.size_flags_vertical = Control.SIZE_EXPAND_FILL
var coord_label = Label.new()
coord_label.text = "(%d,%d,%d)" % [x, current_floor, z]
coord_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
@@ -216,9 +217,14 @@ func _update_grid_ui():
option.set_meta("grid_position", Vector3i(x, current_floor, z))
for i in range(item_list.size()):
option.add_item(enhanced_gridmap.mesh_library.get_item_name(item_list[i]), i)
# Ensure the selected item in the OptionButton corresponds to the current cell item
var cell_item = enhanced_gridmap.get_cell_item(Vector3i(x, current_floor, z))
if cell_item != -1: # Changed from INVALID_CELL_ITEM to -1
if cell_item != -1 and cell_item < option.get_item_count():
option.select(cell_item)
else:
option.select(0)# Select the first item if the cell is empty
option.item_selected.connect(_on_cell_item_selected.bind(option))
option.size_flags_horizontal = Control.SIZE_EXPAND_FILL
option.size_flags_vertical = Control.SIZE_EXPAND_FILL
@@ -239,10 +245,11 @@ func _update_grid_ui():
16: rotation_option.select(2)
22: rotation_option.select(3)
rotation_option.item_selected.connect(_on_cell_rotation_changed.bind(rotation_option))
cell_container.add_child(rotation_option)
row_container.add_child(cell_container)
cell_options.append(option)
enhanced_gridmap._update_cell_option_buttons()
func _update_astar_ui():
start_x_spin.max_value = enhanced_gridmap.columns - 1
@@ -273,6 +280,9 @@ func _on_floors_count_changed(value):
func _on_floor_changed(value):
if enhanced_gridmap:
_update_grid_ui()
_update_astar_ui()
_update_item_state_ui()
enhanced_gridmap.update_grid_data()
func _on_auto_generate_toggled(button_pressed):
if enhanced_gridmap:
@@ -321,7 +331,8 @@ func _on_fill_pressed():
func _on_cell_item_selected(index: int, option: OptionButton):
var position = option.get_meta("grid_position")
if enhanced_gridmap:
enhanced_gridmap.set_cell_item(position, index)
if index >= 0 and index < enhanced_gridmap.mesh_library.get_item_list().size():
enhanced_gridmap.set_cell_item(position, index)
func _on_find_path_pressed():
if enhanced_gridmap:
@@ -360,12 +371,14 @@ func _on_non_walkable_item_changed(value):
func _on_grid_updated():
update_ui()
enhanced_gridmap._update_cell_option_buttons()
func _on_cell_rotation_changed(index: int, option: OptionButton):
var position = option.get_meta("grid_position")
var rotation_value = option.get_item_id(index)
if enhanced_gridmap:
enhanced_gridmap.set_cell_rotation(position, rotation_value)
if index >= 0 and index < 4:
enhanced_gridmap.set_cell_rotation(position, rotation_value)
func _on_swap_items_pressed():
if enhanced_gridmap: