diff --git a/source/match/Match.tscn b/source/match/Match.tscn index c67b7cf..c5665ea 100644 --- a/source/match/Match.tscn +++ b/source/match/Match.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=43 format=3 uid="uid://camns8fqod8d4"] +[gd_scene load_steps=44 format=3 uid="uid://camns8fqod8d4"] [ext_resource type="Script" path="res://source/match/Match.gd" id="1_1555u"] [ext_resource type="Script" path="res://source/match/IsometricCamera3D.gd" id="1_qb2ry"] @@ -20,11 +20,12 @@ [ext_resource type="Script" path="res://source/match/hud/Minimap.gd" id="17_0bfte"] [ext_resource type="Script" path="res://source/match/TerrainNavigation.gd" id="17_6fprk"] [ext_resource type="Shader" path="res://source/shaders/2d/white_transparent.gdshader" id="19_m1b2v"] -[ext_resource type="PackedScene" uid="uid://bocb7hjilvri5" path="res://source/match/handlers/SelectionHandler.tscn" id="20_tw1wp"] [ext_resource type="PackedScene" uid="uid://c0uxy26e4qs4w" path="res://source/match/handlers/MouseClickAnimationsHandler.tscn" id="22_438pb"] [ext_resource type="PackedScene" uid="uid://1rby73ckmk7b" path="res://source/match/Menu.tscn" id="22_ofmlu"] [ext_resource type="PackedScene" uid="uid://b83l4dny3gly0" path="res://source/match/debug/FrameIncrementer.tscn" id="23_exhtd"] [ext_resource type="PackedScene" uid="uid://c3xjdp2yrr1fu" path="res://source/match/debug/DiagnosticHud.tscn" id="23_pocq6"] +[ext_resource type="PackedScene" uid="uid://bocb7hjilvri5" path="res://source/match/handlers/ArealUnitSelectionHandler.tscn" id="24_aug7m"] +[ext_resource type="PackedScene" uid="uid://pi813oou7xim" path="res://source/match/handlers/DoubleClickUnitSelectionHandler.tscn" id="25_ldkhw"] [ext_resource type="PackedScene" uid="uid://yn470qvc3eak" path="res://source/match/handlers/MatchEndHandler.tscn" id="26_4d7im"] [ext_resource type="PackedScene" uid="uid://b8p6lcwubx1tp" path="res://source/match/handlers/UnitVisibilityHandler.tscn" id="32_fci1c"] @@ -410,9 +411,11 @@ visible = false [node name="Handlers" type="Node3D" parent="."] -[node name="UnitSelectionHandler" parent="Handlers" instance=ExtResource("20_tw1wp")] +[node name="ArealUnitSelectionHandler" parent="Handlers" instance=ExtResource("24_aug7m")] rectangular_selection_3d = NodePath("../../RectangularSelection3D") +[node name="DoubleClickUnitSelectionHandler" parent="Handlers" instance=ExtResource("25_ldkhw")] + [node name="MouseClickAnimationsHandler" parent="Handlers" instance=ExtResource("22_438pb")] [node name="MatchEndHandler" parent="Handlers" instance=ExtResource("26_4d7im")] diff --git a/source/match/MatchUtils.gd b/source/match/MatchUtils.gd index 1925447..3bc9481 100644 --- a/source/match/MatchUtils.gd +++ b/source/match/MatchUtils.gd @@ -23,3 +23,12 @@ static func traverse_node_tree_and_replace_materials_matching_albedo( ) ): child.set("surface_material_override/{0}".format([surface_id]), material_to_set) + + +static func select_units(units_to_select): + if not units_to_select.empty() and not Input.is_action_pressed("shift_selecting"): + MatchSignals.deselect_all_units.emit() + for unit in units_to_select.iterate(): + var selection = unit.find_child("Selection") + if selection != null: + selection.select() diff --git a/source/match/handlers/SelectionHandler.gd b/source/match/handlers/ArealUnitSelectionHandler.gd similarity index 74% rename from source/match/handlers/SelectionHandler.gd rename to source/match/handlers/ArealUnitSelectionHandler.gd index 47d91e1..19c088e 100644 --- a/source/match/handlers/SelectionHandler.gd +++ b/source/match/handlers/ArealUnitSelectionHandler.gd @@ -5,9 +5,6 @@ extends Node3D var _rectangular_selection_3d = null var _highlighted_units = Utils.Set.new() -var _double_click_last_unit = null -var _double_click_timer = 0 - func _ready(): _rectangular_selection_3d = get_node_or_null(rectangular_selection_3d) @@ -16,7 +13,6 @@ func _ready(): _rectangular_selection_3d.started.connect(_on_selection_started) _rectangular_selection_3d.interrupted.connect(_on_selection_interrupted) _rectangular_selection_3d.finished.connect(_on_selection_finished) - MatchSignals.unit_selected.connect(_on_unit_selected) func _force_highlight(units_to_highlight): @@ -50,15 +46,6 @@ func _get_controlled_units_from_navigation_domain_within_topdown_polygon_2d( return units_within_polygon -func _select_units(units_to_select): - if not units_to_select.empty() && not Input.is_action_pressed("shift_selecting"): - MatchSignals.deselect_all_units.emit() - for unit in units_to_select.iterate(): - var selection = unit.find_child("Selection") - if selection != null: - selection.select() - - func _rebase_topdown_polygon_2d_to_different_plane(topdown_polygon_2d, plane): var rebased_topdown_polygon_2d = [] var camera = get_viewport().get_camera_3d() @@ -116,29 +103,4 @@ func _on_selection_finished(topdown_polygon_2d): ) ) ) - _select_units(units_to_select) - - -func _on_unit_selected(unit): - if Time.get_ticks_msec() <= _double_click_timer + 50: - return - if not unit.is_in_group("controlled_units"): - return - if unit == _double_click_last_unit and Time.get_ticks_msec() <= _double_click_timer + 600: - _double_click_last_unit = unit - _double_click_timer = Time.get_ticks_msec() - _double_click(unit) - else: - _double_click_last_unit = unit - _double_click_timer = Time.get_ticks_msec() - - -func _double_click(unit): - var units_to_select = Utils.Set.new() - var camera = get_viewport().get_camera_3d() - for u in get_tree().get_nodes_in_group("controlled_units"): - if not u.visible or not camera.is_position_in_frustum(u.global_position): - continue - if u.type == unit.type: - units_to_select.add(u) - _select_units(units_to_select) + Utils.Match.select_units(units_to_select) diff --git a/source/match/handlers/ArealUnitSelectionHandler.tscn b/source/match/handlers/ArealUnitSelectionHandler.tscn new file mode 100644 index 0000000..7068f3a --- /dev/null +++ b/source/match/handlers/ArealUnitSelectionHandler.tscn @@ -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") diff --git a/source/match/handlers/DoubleClickUnitSelectionHandler.gd b/source/match/handlers/DoubleClickUnitSelectionHandler.gd new file mode 100644 index 0000000..3dd2206 --- /dev/null +++ b/source/match/handlers/DoubleClickUnitSelectionHandler.gd @@ -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() diff --git a/source/match/handlers/DoubleClickUnitSelectionHandler.tscn b/source/match/handlers/DoubleClickUnitSelectionHandler.tscn new file mode 100644 index 0000000..eb64d77 --- /dev/null +++ b/source/match/handlers/DoubleClickUnitSelectionHandler.tscn @@ -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") diff --git a/source/match/handlers/SelectionHandler.tscn b/source/match/handlers/SelectionHandler.tscn deleted file mode 100644 index de961ec..0000000 --- a/source/match/handlers/SelectionHandler.tscn +++ /dev/null @@ -1,6 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://bocb7hjilvri5"] - -[ext_resource type="Script" path="res://source/match/handlers/SelectionHandler.gd" id="1_6obd3"] - -[node name="UnitSelectionHandler" type="Node3D"] -script = ExtResource("1_6obd3")