update some plugins, fitting the 4.4.1 gridmap feature
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user