fix offscreen units deselection

This commit is contained in:
Teatov 2024-10-21 22:57:34 +10:00
parent 285aacd6e4
commit d9f3216793
2 changed files with 14 additions and 0 deletions

View File

@ -1,6 +1,8 @@
extends Node
## Handles selection of units.
signal deselect
const MIN_DRAG_DISTANCE: float = 15
const UNIT_SELECT_OFFSET: float = 0.25
@ -50,6 +52,7 @@ func _input(event: InputEvent) -> void:
_selection_rect.size = Vector2.ZERO
elif selecting:
_set_selection_state(false)
deselect.emit()
if event is InputEventMouseMotion:
if _mouse_pressed:
@ -73,6 +76,11 @@ func remove_unit_from_visible(unit: Unit) -> void:
_visible_units.erase(unit_id)
func is_unit_visible(unit: Unit) -> bool:
var unit_id := unit.get_instance_id()
return _visible_units.keys().has(unit_id)
func _handle_advance_anim_step() -> void:
var remapped_unclamped := remap(
_visible_units.size(),

View File

@ -28,6 +28,7 @@ func _init() -> void:
func _ready() -> void:
assert(selection_indicator != null, "selection_indicator missing!")
nav_agent.navigation_finished.connect(_on_nav_agent_navigation_finished)
SelectionManager.deselect.connect(_on_selection_manager_deselect)
super._ready()
@ -98,3 +99,8 @@ func _click_raycast(mouse_pos: Vector2) -> Vector3:
func _on_nav_agent_navigation_finished() -> void:
_wandering_center = nav_agent.get_final_position()
func _on_selection_manager_deselect() -> void:
if _selected and not SelectionManager.is_unit_visible(self):
set_selected(false)