diff --git a/addons/enhanced_gridmap/enhanced_gridmap_dock.gd b/addons/enhanced_gridmap/enhanced_gridmap_dock.gd index 731c69f..e00e8e9 100644 --- a/addons/enhanced_gridmap/enhanced_gridmap_dock.gd +++ b/addons/enhanced_gridmap/enhanced_gridmap_dock.gd @@ -69,52 +69,124 @@ func connect_signals(): func initialize_custom_item_states(): # Add default item states - add_custom_item_state("Normal", 0) - add_custom_item_state("Non-Walkable", 4) + #add_custom_item_state("Normal", 0) + #add_custom_item_state("Non-Walkable", 4) + pass func add_custom_item_state(name: String, id: int): + # Check if an item state with this ID already exists + if custom_item_states.has(id): + print("Item state with ID ", id, " already exists") + return + var new_state = CustomItemState.new(name, id) custom_item_states[id] = new_state add_item_state_ui(new_state) +#func add_item_state_ui(item_state: CustomItemState): + #var container = HBoxContainer.new() + #var name_edit = LineEdit.new() + #var id_spin = SpinBox.new() + #var randomize_check = CheckBox.new() + #var percentage_spin = SpinBox.new() + #var remove_button = Button.new() +# + #name_edit.text = item_state.name + #name_edit.size_flags_horizontal = Control.SIZE_EXPAND_FILL + #name_edit.text_changed.connect(_on_item_state_name_changed.bind(item_state)) +# + #id_spin.value = item_state.id + #id_spin.min_value = 0 + #id_spin.max_value = 9999 + #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 + #randomize_check.toggled.connect(_on_item_state_randomize_toggled.bind(item_state)) +# + #percentage_spin.min_value = 0 + #percentage_spin.max_value = 100 + #percentage_spin.value = item_state.randomize_percentage + #percentage_spin.suffix = "%" + #percentage_spin.value_changed.connect(_on_item_state_percentage_changed.bind(item_state)) +# + #remove_button.text = "Del" + #remove_button.pressed.connect(_on_remove_item_state_pressed.bind(item_state, container)) +# + #container.add_child(name_edit) + #container.add_child(id_spin) + #container.add_child(randomize_check) + #container.add_child(percentage_spin) + #container.add_child(remove_button) +# + #item_states_container.add_child(container) + func add_item_state_ui(item_state: CustomItemState): var container = HBoxContainer.new() - var name_edit = LineEdit.new() - var id_spin = SpinBox.new() + + # Create a new OptionButton instead of separate name_edit and id_spin + var item_selector = OptionButton.new() + item_selector.size_flags_horizontal = Control.SIZE_EXPAND_FILL + + # Populate the selector with items from mesh_library + if enhanced_gridmap and enhanced_gridmap.mesh_library: + var item_list = enhanced_gridmap.mesh_library.get_item_list() + # Add an "Empty" option as item -1 + item_selector.add_item("Empty", -1) + + # Add all items from the mesh library + for item_id in item_list: + var item_name = enhanced_gridmap.mesh_library.get_item_name(item_id) + item_selector.add_item(item_name, item_id) + # Select the current item if it matches + if item_id == item_state.id: + item_selector.select(item_selector.get_item_count() - 1) + + # Connect the item selection signal + item_selector.item_selected.connect( + func(index): + var selected_id = item_selector.get_item_id(index) + var selected_name = item_selector.get_item_text(index) + _on_item_state_selection_changed(selected_id, selected_name, item_state) + ) + var randomize_check = CheckBox.new() var percentage_spin = SpinBox.new() var remove_button = Button.new() - - name_edit.text = item_state.name - name_edit.size_flags_horizontal = Control.SIZE_EXPAND_FILL - name_edit.text_changed.connect(_on_item_state_name_changed.bind(item_state)) - - id_spin.value = item_state.id - id_spin.min_value = 0 - id_spin.max_value = 9999 - 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 randomize_check.toggled.connect(_on_item_state_randomize_toggled.bind(item_state)) - + percentage_spin.min_value = 0 percentage_spin.max_value = 100 percentage_spin.value = item_state.randomize_percentage percentage_spin.suffix = "%" percentage_spin.value_changed.connect(_on_item_state_percentage_changed.bind(item_state)) - + remove_button.text = "Del" remove_button.pressed.connect(_on_remove_item_state_pressed.bind(item_state, container)) - - container.add_child(name_edit) - container.add_child(id_spin) + + # Add all components to the container + container.add_child(item_selector) container.add_child(randomize_check) container.add_child(percentage_spin) container.add_child(remove_button) - + item_states_container.add_child(container) +# Add a new function to handle item selection changes +func _on_item_state_selection_changed(new_id: int, new_name: String, item_state: CustomItemState): + # Remove the item state from the dictionary with the old ID + custom_item_states.erase(item_state.id) + + # Update the item state + item_state.id = new_id + item_state.name = new_name + + # Add the item state back to the dictionary with the new ID + custom_item_states[new_id] = item_state + func _on_add_item_state_pressed(): var new_id = custom_item_states.size() add_custom_item_state("New State {0}".format([new_id]), new_id) @@ -142,7 +214,7 @@ class CustomItemState: var id: int var include_in_randomize: bool = false var randomize_percentage: float = 0 - + func _init(_name: String, _id: int): name = _name id = _id @@ -152,14 +224,14 @@ 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: 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() + _update_fill_options() # Update the fill options when setting a new gridmap diagonal_movement_check.button_pressed = enhanced_gridmap.diagonal_movement print("EnhancedGridMap set: ", enhanced_gridmap) @@ -215,6 +287,9 @@ func _update_grid_ui(): var option = OptionButton.new() option.set_meta("grid_position", Vector3i(x, current_floor, z)) + # Add empty option at index 0 + option.add_item("Empty", -1) + # Add items from the mesh library for i in range(item_list.size()): option.add_item(enhanced_gridmap.mesh_library.get_item_name(item_list[i]), i) @@ -223,7 +298,7 @@ func _update_grid_ui(): 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.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 @@ -328,11 +403,21 @@ func _on_fill_pressed(): 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: +# if index >= 0 and index < enhanced_gridmap.mesh_library.get_item_list().size(): +# enhanced_gridmap.set_cell_item(position, index) + func _on_cell_item_selected(index: int, option: OptionButton): var position = option.get_meta("grid_position") if enhanced_gridmap: - if index >= 0 and index < enhanced_gridmap.mesh_library.get_item_list().size(): - enhanced_gridmap.set_cell_item(position, index) + var item_id = option.get_item_id(index) + if item_id == -1: + # Handle empty selection + enhanced_gridmap.set_cell_item(position, -1) + elif index > 0: # Skip the first item (Empty) + enhanced_gridmap.set_cell_item(position, item_id) func _on_find_path_pressed(): if enhanced_gridmap: diff --git a/addons/enhanced_gridmap/enhanced_gridmap_dock.tscn b/addons/enhanced_gridmap/enhanced_gridmap_dock.tscn index 99c0891..f2189e3 100644 --- a/addons/enhanced_gridmap/enhanced_gridmap_dock.tscn +++ b/addons/enhanced_gridmap/enhanced_gridmap_dock.tscn @@ -6,6 +6,7 @@ anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 +offset_bottom = 137.0 grow_horizontal = 2 grow_vertical = 2 script = ExtResource("1_abcde") diff --git a/assets/models/meshes/block.res b/assets/models/meshes/block.res index 0935365..ab6f591 100644 Binary files a/assets/models/meshes/block.res and b/assets/models/meshes/block.res differ diff --git a/assets/obstacle_example.png.import b/assets/obstacle_example.png.import new file mode 100644 index 0000000..6917e76 --- /dev/null +++ b/assets/obstacle_example.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://bh8jg8k21ubsh" +path="res://.godot/imported/obstacle_example.png-3c341da752bc068c99b3358aacbd41dd.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/obstacle_example.png" +dest_files=["res://.godot/imported/obstacle_example.png-3c341da752bc068c99b3358aacbd41dd.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/scenes/main.tscn b/scenes/main.tscn index 5837fd0..bf860c5 100644 --- a/scenes/main.tscn +++ b/scenes/main.tscn @@ -38,16 +38,16 @@ enable_bots = false mesh_library = ExtResource("1_110wo") cell_size = Vector3(1, 1, 1) data = { -"cells": PackedInt32Array(0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0, 5, 0, 0, 6, 0, 0, 7, 0, 0, 8, 0, 0, 9, 0, 0, 10, 0, 0, 11, 0, 1, 0, 0, 1, 1, 0, 1, 2, 0, 1, 3, 0, 1, 4, 0, 1, 5, 0, 1, 6, 0, 1, 7, 0, 1, 8, 0, 1, 9, 0, 1, 10, 0, 1, 11, 0, 2, 0, 0, 2, 1, 0, 2, 2, 0, 2, 3, 0, 2, 4, 0, 2, 5, 0, 2, 6, 0, 2, 7, 0, 2, 8, 0, 2, 9, 0, 2, 10, 0, 2, 11, 0, 3, 0, 0, 3, 1, 0, 3, 2, 0, 3, 3, 0, 3, 4, 0, 3, 5, 0, 3, 6, 0, 3, 7, 0, 3, 8, 0, 3, 9, 0, 3, 10, 0, 3, 11, 0, 4, 0, 0, 4, 1, 0, 4, 2, 0, 4, 3, 0, 4, 4, 0, 4, 5, 0, 4, 6, 0, 4, 7, 0, 4, 8, 0, 4, 9, 0, 4, 10, 0, 4, 11, 0, 5, 0, 0, 5, 1, 0, 5, 2, 0, 5, 3, 0, 5, 4, 0, 5, 5, 0, 5, 6, 0, 5, 7, 0, 5, 8, 0, 5, 9, 0, 5, 10, 0, 5, 11, 0, 6, 0, 0, 6, 1, 0, 6, 2, 0, 6, 3, 0, 6, 4, 0, 6, 5, 0, 6, 6, 0, 6, 7, 0, 6, 8, 0, 6, 9, 0, 6, 10, 0, 6, 11, 0, 7, 0, 0, 7, 1, 0, 7, 2, 0, 7, 3, 0, 7, 4, 0, 7, 5, 0, 7, 6, 0, 7, 7, 0, 7, 8, 0, 7, 9, 0, 7, 10, 0, 7, 11, 0, 8, 0, 0, 8, 1, 0, 8, 2, 0, 8, 3, 0, 8, 4, 0, 8, 5, 0, 8, 6, 0, 8, 7, 0, 8, 8, 0, 8, 9, 0, 8, 10, 0, 8, 11, 0, 9, 0, 0, 9, 1, 0, 9, 2, 0, 9, 3, 0, 9, 4, 0, 9, 5, 0, 9, 6, 0, 9, 7, 0, 9, 8, 0, 9, 9, 0, 9, 10, 0, 9, 11, 0, 10, 0, 0, 10, 1, 0, 10, 2, 0, 10, 3, 0, 10, 4, 0, 10, 5, 0, 10, 6, 0, 10, 7, 0, 10, 8, 0, 10, 9, 0, 10, 10, 0, 10, 11, 0, 11, 0, 0, 11, 1, 0, 11, 2, 0, 11, 3, 0, 11, 4, 0, 11, 5, 0, 11, 6, 0, 11, 7, 0, 11, 8, 0, 11, 9, 0, 11, 10, 0, 11, 11, 0, 12, 0, 0, 12, 1, 0, 12, 2, 0, 12, 3, 0, 12, 4, 0, 12, 5, 0, 12, 6, 0, 12, 7, 0, 12, 8, 0, 12, 9, 0, 12, 10, 0, 12, 11, 0, 13, 0, 0, 13, 1, 0, 13, 2, 0, 13, 3, 0, 13, 4, 0, 13, 5, 0, 13, 6, 0, 13, 7, 0, 13, 8, 0, 13, 9, 0, 13, 10, 0, 13, 11, 0, 65537, 1, 9, 65537, 2, 9, 65537, 3, 10, 65537, 4, 7, 65537, 5, 10, 65537, 6, 7, 65537, 7, 7, 65537, 8, 8, 65537, 9, 7, 65537, 10, 10, 65537, 11, 8, 65538, 1, 8, 65538, 2, 8, 65538, 3, 10, 65538, 4, 8, 65538, 5, 10, 65538, 6, 8, 65538, 7, 9, 65538, 8, 9, 65538, 9, 7, 65538, 10, 7, 65538, 11, 9, 65539, 0, 8, 65539, 1, 9, 65539, 2, 7, 65539, 3, 10, 65539, 4, 9, 65539, 5, 7, 65539, 6, 8, 65539, 8, 7, 65539, 9, 7, 65539, 10, 7, 65539, 11, 9, 65540, 0, 9, 65540, 1, 9, 65540, 2, 10, 65540, 3, 8, 65540, 4, 9, 65540, 5, 10, 65540, 6, 7, 65540, 7, 10, 65540, 8, 9, 65540, 9, 10, 65540, 10, 9, 65540, 11, 10, 65541, 0, 8, 65541, 1, 8, 65541, 2, 8, 65541, 3, 10, 65541, 4, 7, 65541, 5, 9, 65541, 6, 8, 65541, 7, 10, 65541, 8, 9, 65541, 9, 8, 65541, 10, 10, 65541, 11, 9, 65542, 0, 7, 65542, 1, 8, 65542, 2, 9, 65542, 3, 10, 65542, 4, 9, 65542, 5, 10, 65542, 6, 10, 65542, 7, 7, 65542, 8, 7, 65542, 9, 10, 65542, 10, 7, 65542, 11, 7, 65543, 0, 9, 65543, 1, 8, 65543, 2, 10, 65543, 3, 7, 65543, 4, 7, 65543, 5, 10, 65543, 6, 9, 65543, 7, 8, 65543, 8, 9, 65543, 9, 7, 65543, 10, 7, 65543, 11, 9, 65544, 0, 7, 65544, 1, 7, 65544, 2, 10, 65544, 3, 10, 65544, 4, 7, 65544, 5, 7, 65544, 6, 9, 65544, 7, 10, 65544, 8, 7, 65544, 9, 7, 65544, 10, 8, 65544, 11, 9, 65545, 0, 9, 65545, 1, 10, 65545, 2, 9, 65545, 3, 9, 65545, 4, 9, 65545, 5, 9, 65545, 6, 9, 65545, 7, 9, 65545, 8, 10, 65545, 9, 7, 65545, 10, 7, 65545, 11, 9, 65546, 0, 8, 65546, 1, 8, 65546, 2, 7, 65546, 3, 10, 65546, 4, 7, 65546, 5, 9, 65546, 6, 9, 65546, 7, 9, 65546, 8, 7, 65546, 9, 9, 65546, 10, 10, 65546, 11, 10, 65547, 0, 10, 65547, 1, 8, 65547, 2, 7, 65547, 3, 8, 65547, 4, 10, 65547, 5, 7, 65547, 6, 10, 65547, 7, 7, 65547, 8, 10, 65547, 9, 8, 65547, 10, 7, 65547, 11, 8, 65548, 0, 7, 65548, 1, 9, 65548, 2, 10, 65548, 3, 9, 65548, 4, 7, 65548, 5, 9, 65548, 6, 8, 65548, 7, 10, 65548, 8, 10, 65548, 9, 8, 65548, 10, 9, 65548, 11, 9, 65538, 0, 10, 65537, 0, 7, 65539, 7, 9) +"cells": PackedInt32Array(0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0, 5, 0, 1, 0, 0, 1, 1, 0, 1, 2, 0, 1, 3, 0, 1, 4, 0, 1, 5, 0, 2, 0, 0, 2, 1, 0, 2, 2, 0, 2, 3, 0, 2, 4, 0, 2, 5, 0, 3, 0, 0, 3, 1, 0, 3, 2, 0, 3, 3, 0, 3, 4, 0, 3, 5, 0, 4, 0, 0, 4, 1, 0, 4, 2, 0, 4, 3, 0, 4, 4, 0, 4, 5, 0, 5, 0, 0, 5, 1, 0, 5, 2, 0, 5, 3, 0, 5, 4, 0, 5, 5, 0, 6, 0, 0, 6, 1, 0, 6, 2, 0, 6, 3, 0, 6, 4, 0, 6, 5, 0, 7, 0, 0, 7, 1, 0, 7, 2, 0, 7, 3, 0, 7, 4, 0, 7, 5, 0, 8, 0, 0, 8, 1, 0, 8, 2, 0, 8, 3, 0, 8, 4, 0, 8, 5, 0, 9, 0, 0, 9, 1, 0, 9, 2, 0, 9, 3, 0, 9, 4, 0, 9, 5, 0, 10, 0, 0, 10, 1, 0, 10, 2, 0, 10, 3, 0, 10, 4, 0, 10, 5, 0, 11, 0, 0, 11, 1, 0, 11, 2, 0, 11, 3, 0, 11, 4, 0, 11, 5, 0, 12, 0, 0, 12, 1, 0, 12, 2, 0, 12, 3, 0, 12, 4, 0, 12, 5, 0, 13, 0, 0, 13, 1, 0, 13, 2, 0, 13, 3, 0, 13, 4, 0, 13, 5, 0, 65536, 0, 8, 65536, 1, 10, 65536, 2, 7, 65536, 3, 10, 65536, 4, 8, 65536, 5, 7, 65537, 0, 9, 65537, 1, 10, 65537, 2, 9, 65537, 3, 8, 65537, 4, 10, 65537, 5, 9, 65538, 0, 7, 65538, 1, 8, 65538, 2, 7, 65538, 3, 8, 65538, 4, 7, 65538, 5, 9, 65539, 0, 8, 65539, 1, 10, 65539, 2, 10, 65539, 3, 8, 65539, 4, 10, 65539, 5, 8, 65540, 0, 7, 65540, 1, 8, 65540, 2, 10, 65540, 3, 7, 65540, 4, 8, 65540, 5, 9, 65541, 0, 7, 65541, 1, 8, 65541, 2, 7, 65541, 3, 9, 65541, 4, 8, 65541, 5, 10, 65542, 0, 8, 65542, 1, 7, 65542, 2, 9, 65542, 3, 10, 65542, 4, 8, 65542, 5, 9, 65543, 0, 10, 65543, 1, 8, 65543, 2, 7, 65543, 3, 10, 65543, 4, 8, 65543, 5, 10, 65544, 0, 7, 65544, 1, 10, 65544, 2, 7, 65544, 3, 9, 65544, 4, 8, 65544, 5, 7, 65545, 0, 7, 65545, 1, 8, 65545, 2, 7, 65545, 3, 7, 65545, 4, 7, 65545, 5, 9, 65546, 0, 7, 65546, 1, 7, 65546, 2, 8, 65546, 3, 8, 65546, 4, 10, 65546, 5, 8, 65547, 0, 7, 65547, 1, 10, 65547, 2, 7, 65547, 3, 9, 65547, 4, 10, 65547, 5, 10, 65548, 0, 8, 65548, 1, 9, 65548, 2, 10, 65548, 3, 7, 65548, 4, 8, 65548, 5, 7, 65549, 0, 8, 65549, 1, 10, 65549, 2, 10, 65549, 3, 9, 65549, 4, 8, 65549, 5, 10, 131072, 0, 2031616, 131072, 1, 2031616, 131072, 2, 2031616, 131072, 3, 2031616, 131072, 4, 2031616, 131072, 5, 2031616, 131073, 0, 2031616, 131073, 1, 2031616, 131073, 2, 2031616, 131073, 3, 2031616, 131073, 4, 2031616, 131073, 5, 2031616, 131074, 0, 2031616, 131074, 1, 2031616, 131074, 2, 2031616, 131074, 3, 2031616, 131074, 4, 2031616, 131074, 5, 2031616, 131075, 0, 2031616, 131075, 1, 2031616, 131075, 2, 2031616, 131075, 3, 2031616, 131075, 4, 2031616, 131075, 5, 2031616, 131076, 0, 2031616, 131076, 1, 2031616, 131076, 2, 2031616, 131076, 3, 2031616, 131076, 4, 2031616, 131076, 5, 2031616, 131077, 0, 2031616, 131077, 1, 2031616, 131077, 2, 2031616, 131077, 3, 2031616, 131077, 4, 2031616, 131077, 5, 2031616, 131078, 0, 2031616, 131078, 1, 2031616, 131078, 2, 2031616, 131078, 3, 2031616, 131078, 4, 2031616, 131078, 5, 2031616, 131079, 0, 2031616, 131079, 1, 2031616, 131079, 2, 2031616, 131079, 3, 2031616, 131079, 4, 2031616, 131079, 5, 2031616, 131080, 0, 2031616, 131080, 1, 2031616, 131080, 2, 2031616, 131080, 3, 2031616, 131080, 4, 2031616, 131080, 5, 2031616, 131081, 0, 2031616, 131081, 1, 2031616, 131081, 2, 2031616, 131081, 3, 2031616, 131081, 4, 2031616, 131081, 5, 2031616, 131082, 0, 2031616, 131082, 1, 2031616, 131082, 2, 2031616, 131082, 3, 2031616, 131082, 4, 2031616, 131082, 5, 2031616, 131083, 0, 2031616, 131083, 1, 2031616, 131083, 2, 2031616, 131083, 3, 2031616, 131083, 4, 2031616, 131083, 5, 2031616, 131084, 0, 2031616, 131084, 1, 2031616, 131084, 2, 2031616, 131084, 3, 2031616, 131084, 4, 2031616, 131084, 5, 2031616, 131085, 0, 2031616, 131085, 1, 2031616, 131085, 2, 2031616, 131085, 3, 2031616, 131085, 4, 2031616, 131085, 5, 2031616) } script = ExtResource("2_hbe1v") columns = 14 -rows = 12 +rows = 6 obstacle_items = Array[int]([12]) -metadata/_editor_floor_ = Vector3(0, -2, 0) +metadata/_editor_floor_ = Vector3(0, 1, 0) [node name="Camera3D" type="Camera3D" parent="."] -transform = Transform3D(1, 0, 0, 0, 0.422618, 0.906308, 0, -0.906308, 0.422618, 7, 26, 17) +transform = Transform3D(1, 0, 0, 0, 0.422618, 0.906308, 0, -0.906308, 0.422618, 7, 19, 11.2354) environment = ExtResource("4_ky38j") fov = 35.5