update
This commit is contained in:
@@ -5,9 +5,11 @@ var enhanced_gridmap: EnhancedGridMap
|
||||
|
||||
@onready var columns_spin = $VBoxContainer/Columns/SpinBox
|
||||
@onready var rows_spin = $VBoxContainer/Rows/SpinBox
|
||||
@onready var floor_spin = $VBoxContainer/FloorContainer/FloorSpinBox
|
||||
@onready var floors_count_spin = $VBoxContainer/FloorsCount/SpinBox
|
||||
@onready var auto_generate_check = $VBoxContainer/AutoGenerate
|
||||
@onready var generate_button = $VBoxContainer/GenerateButton
|
||||
@onready var clear_button = $VBoxContainer/ClearButton
|
||||
@onready var generate_button = $VBoxContainer/GridOperations/GenerateButton
|
||||
@onready var clear_button = $VBoxContainer/GridOperations/ClearButton
|
||||
@onready var randomize_button = $VBoxContainer/RandomizeButton
|
||||
@onready var fill_options = $VBoxContainer/FillOptions
|
||||
@onready var fill_button = $VBoxContainer/FillButton
|
||||
@@ -28,10 +30,14 @@ var enhanced_gridmap: EnhancedGridMap
|
||||
@onready var start_item_spin = $VBoxContainer/ItemStates/StartItem/SpinBox
|
||||
@onready var end_item_spin = $VBoxContainer/ItemStates/EndItem/SpinBox
|
||||
@onready var non_walkable_item_spin = $VBoxContainer/ItemStates/NonWalkableItem/SpinBox
|
||||
# Custom item states UI elements
|
||||
@onready var item_states_container = $VBoxContainer/ItemStates/ItemStatesContainer
|
||||
@onready var add_item_state_button = $VBoxContainer/ItemStates/AddItemStateButton
|
||||
|
||||
# Item Management UI elements
|
||||
@onready var old_item_spin = $VBoxContainer/ItemManagement/SwapItems/OldItem
|
||||
@onready var new_item_spin = $VBoxContainer/ItemManagement/SwapItems/NewItem
|
||||
@onready var swap_button = $VBoxContainer/ItemManagement/SwapItems/SwapButton
|
||||
|
||||
var row_containers: Array = []
|
||||
var cell_options: Array = []
|
||||
var custom_item_states: Dictionary = {}
|
||||
@@ -44,6 +50,8 @@ func _ready():
|
||||
func connect_signals():
|
||||
columns_spin.value_changed.connect(_on_columns_changed)
|
||||
rows_spin.value_changed.connect(_on_rows_changed)
|
||||
floor_spin.value_changed.connect(_on_floor_changed)
|
||||
floors_count_spin.value_changed.connect(_on_floors_count_changed)
|
||||
auto_generate_check.toggled.connect(_on_auto_generate_toggled)
|
||||
generate_button.pressed.connect(_on_generate_pressed)
|
||||
clear_button.pressed.connect(_on_clear_pressed)
|
||||
@@ -57,13 +65,11 @@ func connect_signals():
|
||||
start_item_spin.value_changed.connect(_on_start_item_changed)
|
||||
end_item_spin.value_changed.connect(_on_end_item_changed)
|
||||
non_walkable_item_spin.value_changed.connect(_on_non_walkable_item_changed)
|
||||
swap_button.pressed.connect(_on_swap_items_pressed)
|
||||
|
||||
func initialize_custom_item_states():
|
||||
# Add default item states
|
||||
add_custom_item_state("Normal", 0)
|
||||
#add_custom_item_state("Hover", 1)
|
||||
#add_custom_item_state("Start", 2)
|
||||
#add_custom_item_state("End", 3)
|
||||
add_custom_item_state("Non-Walkable", 4)
|
||||
|
||||
func add_custom_item_state(name: String, id: int):
|
||||
@@ -89,7 +95,7 @@ func add_item_state_ui(item_state: CustomItemState):
|
||||
id_spin.value_changed.connect(_on_item_state_id_changed.bind(item_state))
|
||||
|
||||
randomize_check.text = "🎲"
|
||||
randomize_check.button_pressed = item_state.include_in_randomize # Changed from 'pressed' to 'button_pressed'
|
||||
randomize_check.button_pressed = item_state.include_in_randomize
|
||||
randomize_check.toggled.connect(_on_item_state_randomize_toggled.bind(item_state))
|
||||
|
||||
percentage_spin.min_value = 0
|
||||
@@ -142,11 +148,19 @@ class CustomItemState:
|
||||
id = _id
|
||||
|
||||
func set_enhanced_gridmap(gridmap: EnhancedGridMap):
|
||||
# Disconnect from previous gridmap if it exists
|
||||
if enhanced_gridmap:
|
||||
if enhanced_gridmap.grid_updated.is_connected(_on_grid_updated):
|
||||
enhanced_gridmap.grid_updated.disconnect(_on_grid_updated)
|
||||
|
||||
enhanced_gridmap = gridmap
|
||||
enhanced_gridmap.grid_updated.connect(_on_grid_updated)
|
||||
update_ui()
|
||||
diagonal_movement_check.button_pressed = enhanced_gridmap.diagonal_movement
|
||||
print("EnhancedGridMap set: ", enhanced_gridmap)
|
||||
if enhanced_gridmap:
|
||||
enhanced_gridmap.grid_updated.connect(_on_grid_updated)
|
||||
floor_spin.max_value = enhanced_gridmap.floors - 1
|
||||
floors_count_spin.value = enhanced_gridmap.floors
|
||||
update_ui()
|
||||
diagonal_movement_check.button_pressed = enhanced_gridmap.diagonal_movement
|
||||
print("EnhancedGridMap set: ", enhanced_gridmap)
|
||||
|
||||
func update_ui():
|
||||
if enhanced_gridmap:
|
||||
@@ -157,7 +171,6 @@ func update_ui():
|
||||
_update_grid_ui()
|
||||
_update_astar_ui()
|
||||
_update_item_state_ui()
|
||||
print("UI updated. Columns: ", enhanced_gridmap.columns, " Rows: ", enhanced_gridmap.rows)
|
||||
|
||||
func _update_fill_options():
|
||||
fill_options.clear()
|
||||
@@ -166,6 +179,8 @@ func _update_fill_options():
|
||||
for i in range(item_list.size()):
|
||||
fill_options.add_item(enhanced_gridmap.mesh_library.get_item_name(item_list[i]), i)
|
||||
|
||||
# In enhanced_gridmap_dock.gd, update the _update_grid_ui function:
|
||||
|
||||
func _update_grid_ui():
|
||||
for child in grid_container.get_children():
|
||||
child.queue_free()
|
||||
@@ -177,9 +192,8 @@ func _update_grid_ui():
|
||||
return
|
||||
|
||||
var item_list = enhanced_gridmap.mesh_library.get_item_list()
|
||||
var current_floor = floor_spin.value as int
|
||||
|
||||
print("Updating grid UI. Columns: ", enhanced_gridmap.columns, " Rows: ", enhanced_gridmap.rows)
|
||||
|
||||
for z in range(enhanced_gridmap.rows):
|
||||
var row_container = HBoxContainer.new()
|
||||
row_container.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
@@ -192,24 +206,24 @@ func _update_grid_ui():
|
||||
cell_container.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||||
|
||||
var coord_label = Label.new()
|
||||
coord_label.text = "(%d,%d)" % [x, z]
|
||||
coord_label.text = "(%d,%d,%d)" % [x, current_floor, z]
|
||||
coord_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
coord_label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||
coord_label.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||
cell_container.add_child(coord_label)
|
||||
|
||||
var option = OptionButton.new()
|
||||
option.set_meta("grid_position", Vector2i(x, z))
|
||||
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)
|
||||
var cell_item = enhanced_gridmap.get_cell_item(Vector3i(x, 0, z))
|
||||
option.select(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
|
||||
option.select(cell_item)
|
||||
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
|
||||
cell_container.add_child(option)
|
||||
|
||||
# Add rotation Option for each cell
|
||||
var rotation_option = OptionButton.new()
|
||||
rotation_option.add_item("0°", 0)
|
||||
rotation_option.add_item("90°", 10)
|
||||
@@ -217,9 +231,8 @@ func _update_grid_ui():
|
||||
rotation_option.add_item("270°", 22)
|
||||
rotation_option.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
rotation_option.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||
rotation_option.set_meta("grid_position", Vector2i(x, z))
|
||||
# Set the current item based on the cell's rotation
|
||||
var current_rotation = enhanced_gridmap.get_cell_rotation(Vector3i(x, 0, z))
|
||||
rotation_option.set_meta("grid_position", Vector3i(x, current_floor, z))
|
||||
var current_rotation = enhanced_gridmap.get_cell_rotation(Vector3i(x, current_floor, z))
|
||||
match current_rotation:
|
||||
0: rotation_option.select(0)
|
||||
10: rotation_option.select(1)
|
||||
@@ -228,12 +241,9 @@ func _update_grid_ui():
|
||||
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)
|
||||
|
||||
print("Grid UI updated. Total cells: ", cell_options.size())
|
||||
|
||||
func _update_astar_ui():
|
||||
start_x_spin.max_value = enhanced_gridmap.columns - 1
|
||||
start_z_spin.max_value = enhanced_gridmap.rows - 1
|
||||
@@ -241,21 +251,28 @@ func _update_astar_ui():
|
||||
end_z_spin.max_value = enhanced_gridmap.rows - 1
|
||||
|
||||
func _update_item_state_ui():
|
||||
normal_item_spin.value = enhanced_gridmap.normal_item
|
||||
normal_item_spin.value = enhanced_gridmap.normal_items[0]
|
||||
hover_item_spin.value = enhanced_gridmap.hover_item
|
||||
start_item_spin.value = enhanced_gridmap.start_item
|
||||
end_item_spin.value = enhanced_gridmap.end_item
|
||||
non_walkable_item_spin.value = enhanced_gridmap.non_walkable_item
|
||||
non_walkable_item_spin.value = enhanced_gridmap.non_walkable_items[0]
|
||||
|
||||
func _on_columns_changed(value):
|
||||
if enhanced_gridmap:
|
||||
enhanced_gridmap.columns = value
|
||||
print("Columns changed to: ", value)
|
||||
|
||||
func _on_rows_changed(value):
|
||||
if enhanced_gridmap:
|
||||
enhanced_gridmap.rows = value
|
||||
print("Rows changed to: ", value)
|
||||
|
||||
func _on_floors_count_changed(value):
|
||||
if enhanced_gridmap:
|
||||
enhanced_gridmap.floors = value as int
|
||||
floor_spin.max_value = value - 1
|
||||
|
||||
func _on_floor_changed(value):
|
||||
if enhanced_gridmap:
|
||||
_update_grid_ui()
|
||||
|
||||
func _on_auto_generate_toggled(button_pressed):
|
||||
if enhanced_gridmap:
|
||||
@@ -263,80 +280,83 @@ func _on_auto_generate_toggled(button_pressed):
|
||||
|
||||
func _on_generate_pressed():
|
||||
if enhanced_gridmap:
|
||||
enhanced_gridmap.generate_grid()
|
||||
print("Generate grid pressed")
|
||||
var current_floor = floor_spin.value as int
|
||||
enhanced_gridmap.generate_grid(current_floor)
|
||||
|
||||
func _on_clear_pressed():
|
||||
if enhanced_gridmap:
|
||||
enhanced_gridmap.clear_grid()
|
||||
print("Clear grid pressed")
|
||||
var current_floor = floor_spin.value as int
|
||||
enhanced_gridmap.clear_grid(current_floor)
|
||||
|
||||
func _on_randomize_pressed():
|
||||
if enhanced_gridmap:
|
||||
var current_floor = floor_spin.value as int
|
||||
var randomize_states = []
|
||||
var total_percentage = 0
|
||||
|
||||
# Collect only enabled randomize states
|
||||
for state in custom_item_states.values():
|
||||
if state.include_in_randomize:
|
||||
randomize_states.append(state)
|
||||
total_percentage += state.randomize_percentage
|
||||
|
||||
if randomize_states.is_empty():
|
||||
print("No states selected for randomization")
|
||||
return
|
||||
|
||||
if total_percentage != 100:
|
||||
print("Warning: Total randomize percentage is not 100%")
|
||||
|
||||
enhanced_gridmap.randomize_grid_custom(randomize_states)
|
||||
enhanced_gridmap.randomize_grid_custom(randomize_states, current_floor)
|
||||
|
||||
func _on_fill_pressed():
|
||||
if enhanced_gridmap:
|
||||
var current_floor = floor_spin.value as int
|
||||
var selected_index = fill_options.get_selected_id()
|
||||
enhanced_gridmap.fill_grid(selected_index)
|
||||
print("Fill grid pressed with item index: ", selected_index)
|
||||
if selected_index >= 0:
|
||||
enhanced_gridmap.fill_grid(selected_index, current_floor)
|
||||
else:
|
||||
print("No item selected for filling")
|
||||
|
||||
func _on_cell_item_selected(index: int, option: OptionButton):
|
||||
var position = option.get_meta("grid_position")
|
||||
if enhanced_gridmap:
|
||||
enhanced_gridmap.set_cell_from_data(position.x, position.y, index)
|
||||
print("Cell item selected: ", index, " at position: ", position)
|
||||
enhanced_gridmap.set_cell_item(position, index)
|
||||
|
||||
func _on_find_path_pressed():
|
||||
if enhanced_gridmap:
|
||||
var current_floor = floor_spin.value as int
|
||||
var start = Vector2(start_x_spin.value, start_z_spin.value)
|
||||
var end = Vector2(end_x_spin.value, end_z_spin.value)
|
||||
var path = enhanced_gridmap.find_path(start, end)
|
||||
var path = enhanced_gridmap.find_path(start, end, current_floor)
|
||||
if path.is_empty():
|
||||
path_result_label.text = "No path found"
|
||||
else:
|
||||
path_result_label.text = "Path found: " + str(path)
|
||||
print("Find path pressed. Start: ", start, " End: ", end)
|
||||
|
||||
func _on_diagonal_movement_toggled(button_pressed):
|
||||
if enhanced_gridmap:
|
||||
enhanced_gridmap.set_diagonal_movement(button_pressed)
|
||||
print("Diagonal movement toggled: ", button_pressed)
|
||||
|
||||
func _on_normal_item_changed(value):
|
||||
if enhanced_gridmap:
|
||||
enhanced_gridmap.normal_item = value
|
||||
print("Normal item changed to: ", value)
|
||||
enhanced_gridmap.normal_items[0] = value
|
||||
|
||||
func _on_hover_item_changed(value):
|
||||
if enhanced_gridmap:
|
||||
enhanced_gridmap.hover_item = value
|
||||
print("Hover item changed to: ", value)
|
||||
|
||||
func _on_start_item_changed(value):
|
||||
if enhanced_gridmap:
|
||||
enhanced_gridmap.start_item = value
|
||||
print("Start item changed to: ", value)
|
||||
|
||||
func _on_end_item_changed(value):
|
||||
if enhanced_gridmap:
|
||||
enhanced_gridmap.end_item = value
|
||||
print("End item changed to: ", value)
|
||||
|
||||
func _on_non_walkable_item_changed(value):
|
||||
if enhanced_gridmap:
|
||||
enhanced_gridmap.non_walkable_item = value
|
||||
print("Non-walkable item changed to: ", value)
|
||||
enhanced_gridmap.non_walkable_items[0] = value
|
||||
|
||||
func _on_grid_updated():
|
||||
update_ui()
|
||||
@@ -345,5 +365,10 @@ 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(Vector3i(position.x, 0, position.y), rotation_value)
|
||||
print("Cell rotation changed: ", rotation_value, " at position: ", position)
|
||||
enhanced_gridmap.set_cell_rotation(position, rotation_value)
|
||||
|
||||
func _on_swap_items_pressed():
|
||||
if enhanced_gridmap:
|
||||
var old_item = old_item_spin.value as int
|
||||
var new_item = new_item_spin.value as int
|
||||
enhanced_gridmap.swap_items(old_item, new_item, floor_spin.value as int)
|
||||
|
||||
Reference in New Issue
Block a user