-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split 'SelectionHandler' into 'Areal' and 'DoubleClick' selection han…
…dlers
- Loading branch information
Showing
7 changed files
with
67 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[gd_scene load_steps=2 format=3 uid="uid://bocb7hjilvri5"] | ||
|
||
[ext_resource type="Script" path="res://source/match/handlers/ArealUnitSelectionHandler.gd" id="1_xmfnv"] | ||
|
||
[node name="ArealUnitSelectionHandler" type="Node3D"] | ||
script = ExtResource("1_xmfnv") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
extends Node3D | ||
|
||
const DOUBLE_CLICK_LB_MS = 50 | ||
const DOUBLE_CLICK_UB_MS = 600 | ||
|
||
var _last_unit_selected = null | ||
var _last_unit_selected_timestamp = 0 | ||
|
||
|
||
func _ready(): | ||
MatchSignals.unit_selected.connect(_on_unit_selected) | ||
|
||
|
||
func _handle_double_click(unit_type): | ||
var units_to_select = Utils.Set.new() | ||
var camera = get_viewport().get_camera_3d() | ||
for unit in get_tree().get_nodes_in_group("controlled_units"): | ||
if not unit.visible or not camera.is_position_in_frustum(unit.global_position): | ||
continue | ||
if unit.type == unit_type: | ||
units_to_select.add(unit) | ||
Utils.Match.select_units(units_to_select) | ||
|
||
|
||
func _on_unit_selected(unit): | ||
if not unit.is_in_group("controlled_units"): | ||
return | ||
if Time.get_ticks_msec() < _last_unit_selected_timestamp + DOUBLE_CLICK_LB_MS: | ||
return | ||
if ( | ||
unit == _last_unit_selected | ||
and Time.get_ticks_msec() <= _last_unit_selected_timestamp + DOUBLE_CLICK_UB_MS | ||
): | ||
_last_unit_selected = null | ||
_last_unit_selected_timestamp = 0 | ||
_handle_double_click(unit.type) | ||
else: | ||
_last_unit_selected = unit | ||
_last_unit_selected_timestamp = Time.get_ticks_msec() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[gd_scene load_steps=2 format=3 uid="uid://pi813oou7xim"] | ||
|
||
[ext_resource type="Script" path="res://source/match/handlers/DoubleClickUnitSelectionHandler.gd" id="1_myskc"] | ||
|
||
[node name="DoubleClickUnitSelectionHandler" type="Node3D"] | ||
script = ExtResource("1_myskc") |
This file was deleted.
Oops, something went wrong.