fix offscreen units deselection
This commit is contained in:
parent
285aacd6e4
commit
d9f3216793
@ -1,6 +1,8 @@
|
|||||||
extends Node
|
extends Node
|
||||||
## Handles selection of units.
|
## Handles selection of units.
|
||||||
|
|
||||||
|
signal deselect
|
||||||
|
|
||||||
const MIN_DRAG_DISTANCE: float = 15
|
const MIN_DRAG_DISTANCE: float = 15
|
||||||
const UNIT_SELECT_OFFSET: float = 0.25
|
const UNIT_SELECT_OFFSET: float = 0.25
|
||||||
|
|
||||||
@ -50,6 +52,7 @@ func _input(event: InputEvent) -> void:
|
|||||||
_selection_rect.size = Vector2.ZERO
|
_selection_rect.size = Vector2.ZERO
|
||||||
elif selecting:
|
elif selecting:
|
||||||
_set_selection_state(false)
|
_set_selection_state(false)
|
||||||
|
deselect.emit()
|
||||||
|
|
||||||
if event is InputEventMouseMotion:
|
if event is InputEventMouseMotion:
|
||||||
if _mouse_pressed:
|
if _mouse_pressed:
|
||||||
@ -73,6 +76,11 @@ func remove_unit_from_visible(unit: Unit) -> void:
|
|||||||
_visible_units.erase(unit_id)
|
_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:
|
func _handle_advance_anim_step() -> void:
|
||||||
var remapped_unclamped := remap(
|
var remapped_unclamped := remap(
|
||||||
_visible_units.size(),
|
_visible_units.size(),
|
||||||
|
|||||||
@ -28,6 +28,7 @@ func _init() -> void:
|
|||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
assert(selection_indicator != null, "selection_indicator missing!")
|
assert(selection_indicator != null, "selection_indicator missing!")
|
||||||
nav_agent.navigation_finished.connect(_on_nav_agent_navigation_finished)
|
nav_agent.navigation_finished.connect(_on_nav_agent_navigation_finished)
|
||||||
|
SelectionManager.deselect.connect(_on_selection_manager_deselect)
|
||||||
super._ready()
|
super._ready()
|
||||||
|
|
||||||
|
|
||||||
@ -98,3 +99,8 @@ func _click_raycast(mouse_pos: Vector2) -> Vector3:
|
|||||||
|
|
||||||
func _on_nav_agent_navigation_finished() -> void:
|
func _on_nav_agent_navigation_finished() -> void:
|
||||||
_wandering_center = nav_agent.get_final_position()
|
_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)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user