Improved menu system
This commit is contained in:
parent
da78e7f287
commit
c95b8186ab
12 changed files with 181 additions and 111 deletions
|
|
@ -140,8 +140,6 @@ func get_neighbours(coords: Vector4i, ground_layer: bool = false) -> Array[Vecto
|
|||
Vector4i(coords.x, coords.y + 1, coords.z - 1, layer)
|
||||
]
|
||||
|
||||
var current_tile: Node3D
|
||||
|
||||
const HEX_OUTLINE = preload("res://hex_outline.tscn")
|
||||
|
||||
func get_placeable_positions(button: InsectButton) -> Array[Vector4i]:
|
||||
|
|
@ -237,6 +235,10 @@ func can_reach(start: Vector4i, target: Vector4i, exclude: Array[Vector4i] = [])
|
|||
|
||||
func _on_insect_selected(button: InsectButton, is_black: bool) -> void:
|
||||
var positions = get_placeable_positions(button)
|
||||
|
||||
for child in placement_visualizer.get_children():
|
||||
child.queue_free()
|
||||
|
||||
for p in positions:
|
||||
var outline = HEX_OUTLINE.instantiate()
|
||||
var hex_pos = cube_to_world_pos(p)
|
||||
|
|
@ -247,84 +249,8 @@ func _on_insect_selected(button: InsectButton, is_black: bool) -> void:
|
|||
outline.coordinates = p
|
||||
outline.map_reference = self
|
||||
placement_visualizer.add_child(outline)
|
||||
#placements[p] = outline
|
||||
|
||||
# create a hexagon with insect resource data
|
||||
#var tile = INSECT_TILE.instantiate()
|
||||
#tile.resource = insect_resource
|
||||
#tile.is_black = is_black
|
||||
#current_tile = tile
|
||||
#add_child(tile)
|
||||
#var insect_resource: TileResource = button.insect_resource
|
||||
#
|
||||
## spawn possible placement locations :)
|
||||
#if used_cells.size() == 0: # we have no cells placed, display a placement outline at 0, 0
|
||||
#var outline = HEX_OUTLINE.instantiate()
|
||||
#var cubepos = Vector4i.new(0, 0, 0)
|
||||
#var hex_pos = cube_to_world_pos(cubepos)
|
||||
#outline.position = Vector3(hex_pos.x, 0.0, hex_pos.y)
|
||||
#outline.visible = true
|
||||
#outline.insect_resource = insect_resource
|
||||
#outline.is_black = is_black
|
||||
#outline.coordinates = cubepos
|
||||
#outline.map_reference = self
|
||||
#placement_visualizer.add_child(outline)
|
||||
#placements[hex_pos] = outline
|
||||
#elif used_cells.size() == 1: # we have ONE cell placed, this is a special case in which
|
||||
## the opposing player is allowed to place a tile that touches the enemy color
|
||||
## We display outline placement around all spaces of this single cell
|
||||
#var single_cell = used_cells.keys().front()
|
||||
#var neighbours = get_neighbours(Vector4i.new(single_cell.x, single_cell.y, single_cell.z))
|
||||
#for neighbour in neighbours:
|
||||
#var outline = HEX_OUTLINE.instantiate()
|
||||
#var hex_pos = cube_to_world_pos(neighbour)
|
||||
#outline.position = Vector3(hex_pos.x, 0.0, hex_pos.y)
|
||||
#outline.visible = true
|
||||
#outline.insect_resource = insect_resource
|
||||
#outline.is_black = is_black
|
||||
#outline.coordinates = neighbour
|
||||
#outline.map_reference = self
|
||||
#placement_visualizer.add_child(outline)
|
||||
#placements[hex_pos] = outline
|
||||
#else:
|
||||
## iterate over all used_cells, get all empty cells surrounding those cells
|
||||
## iterate over all those empty cells, check if they only neighbour the same color
|
||||
#var possible_placements: Dictionary = {}
|
||||
#
|
||||
#for hex in used_cells.keys():
|
||||
##var eligible: bool = true
|
||||
#for neighbour in get_empty_neighbours(Vector4i.new(hex.x, hex.y, hex.z)):
|
||||
#if not used_cells.has(Vector4(neighbour.q, neighbour.r, neighbour.s, 0)):
|
||||
#possible_placements[Vector4i(neighbour.q, neighbour.r, neighbour.s, 0)] = true
|
||||
#
|
||||
#for p in possible_placements:
|
||||
#var eligible: bool = true
|
||||
#
|
||||
#for neighbour in get_neighbours(Vector4i.new(p.x, p.y, p.z)):
|
||||
#if not used_cells.has(Vector4i(neighbour.q, neighbour.r, neighbour.s, 0)):
|
||||
#continue
|
||||
#
|
||||
#if used_cells[Vector4i(neighbour.q, neighbour.r, neighbour.s, 0)].is_black != is_black:
|
||||
#eligible = false
|
||||
#break
|
||||
#
|
||||
#if eligible:
|
||||
#var outline = HEX_OUTLINE.instantiate()
|
||||
#var hex_pos = cube_to_world_pos(Vector4i.new(p.x, p.y, p.z))
|
||||
#outline.position = Vector3(hex_pos.x, 0.0, hex_pos.y)
|
||||
#outline.visible = true
|
||||
#outline.insect_resource = insect_resource
|
||||
#outline.is_black = is_black
|
||||
#outline.coordinates = Vector4i.new(p.x, p.y, p.z)
|
||||
#outline.map_reference = self
|
||||
#placement_visualizer.add_child(outline)
|
||||
#placements[p] = outline
|
||||
|
||||
func _on_insect_placement_cancelled() -> void:
|
||||
if current_tile:
|
||||
current_tile.queue_free()
|
||||
current_tile = null
|
||||
|
||||
for child in placement_visualizer.get_children():
|
||||
child.queue_free()
|
||||
|
||||
|
|
@ -366,6 +292,9 @@ func can_move(tile: InsectTile) -> bool:
|
|||
return can_hive_exist_without_tile(tile)
|
||||
|
||||
func _on_insect_tile_selected(tile: InsectTile) -> void:
|
||||
for child in placement_visualizer.get_children():
|
||||
child.queue_free()
|
||||
|
||||
if not can_hive_exist_without_tile(tile):
|
||||
print("Would break hive")
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue