add selection hove indicator and make selection on mouse release
This commit is contained in:
BIN
assets/textures/selection_unit_hover_decal.png
LFS
Normal file
BIN
assets/textures/selection_unit_hover_decal.png
LFS
Normal file
Binary file not shown.
35
assets/textures/selection_unit_hover_decal.png.import
Normal file
35
assets/textures/selection_unit_hover_decal.png.import
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://duf132faskeid"
|
||||||
|
path.s3tc="res://.godot/imported/selection_unit_hover_decal.png-3405fd7bd28aecc3a58787620fa15847.s3tc.ctex"
|
||||||
|
metadata={
|
||||||
|
"imported_formats": ["s3tc_bptc"],
|
||||||
|
"vram_texture": true
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/textures/selection_unit_hover_decal.png"
|
||||||
|
dest_files=["res://.godot/imported/selection_unit_hover_decal.png-3405fd7bd28aecc3a58787620fa15847.s3tc.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=2
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=true
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=0
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
[gd_scene load_steps=5 format=3 uid="uid://cfixshlmwhpmi"]
|
[gd_scene load_steps=6 format=3 uid="uid://cfixshlmwhpmi"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://scripts/units/test_unit.gd" id="1_e76lg"]
|
[ext_resource type="Script" path="res://scripts/units/test_unit.gd" id="1_e76lg"]
|
||||||
[ext_resource type="PackedScene" uid="uid://bi231xk2sp410" path="res://assets/models/ant.glb" id="1_ff64u"]
|
[ext_resource type="PackedScene" uid="uid://bi231xk2sp410" path="res://assets/models/ant.glb" id="1_ff64u"]
|
||||||
[ext_resource type="Texture2D" uid="uid://dehqm00kiljut" path="res://assets/textures/selection_unit_decal.png" id="2_5725f"]
|
[ext_resource type="Texture2D" uid="uid://dehqm00kiljut" path="res://assets/textures/selection_unit_decal.png" id="2_5725f"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://duf132faskeid" path="res://assets/textures/selection_unit_hover_decal.png" id="4_umx1w"]
|
||||||
|
|
||||||
[sub_resource type="SphereShape3D" id="SphereShape3D_e8dcp"]
|
[sub_resource type="SphereShape3D" id="SphereShape3D_e8dcp"]
|
||||||
radius = 0.25
|
radius = 0.25
|
||||||
@@ -23,7 +24,13 @@ pixel_size = 0.0055
|
|||||||
axis = 1
|
axis = 1
|
||||||
texture = ExtResource("2_5725f")
|
texture = ExtResource("2_5725f")
|
||||||
|
|
||||||
[node name="NavigationAgent3D" type="NavigationAgent3D" parent="." index="4"]
|
[node name="HoverSprite" type="Sprite3D" parent="." index="4"]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0021804, 0.00953716, -0.00236732)
|
||||||
|
pixel_size = 0.0085
|
||||||
|
axis = 1
|
||||||
|
texture = ExtResource("4_umx1w")
|
||||||
|
|
||||||
|
[node name="NavigationAgent3D" type="NavigationAgent3D" parent="." index="5"]
|
||||||
path_desired_distance = 0.5
|
path_desired_distance = 0.5
|
||||||
target_desired_distance = 0.5
|
target_desired_distance = 0.5
|
||||||
path_height_offset = 0.5
|
path_height_offset = 0.5
|
||||||
|
|||||||
@@ -50,9 +50,11 @@ func _input(event: InputEvent) -> void:
|
|||||||
var button_event := event as InputEventMouseButton
|
var button_event := event as InputEventMouseButton
|
||||||
if button_event.button_index == MOUSE_BUTTON_LEFT:
|
if button_event.button_index == MOUSE_BUTTON_LEFT:
|
||||||
mouse_pressed = button_event.pressed
|
mouse_pressed = button_event.pressed
|
||||||
if button_event.pressed:
|
if mouse_pressed:
|
||||||
selection_rect.position = button_event.position
|
selection_rect.position = button_event.position
|
||||||
selection_rect.size = Vector2.ZERO
|
selection_rect.size = Vector2.ZERO
|
||||||
|
else:
|
||||||
|
_set_selection_state(false)
|
||||||
|
|
||||||
if event is InputEventMouseMotion and mouse_pressed:
|
if event is InputEventMouseMotion and mouse_pressed:
|
||||||
var motion_event := event as InputEventMouseMotion
|
var motion_event := event as InputEventMouseMotion
|
||||||
@@ -93,6 +95,10 @@ func _handle_unit_selection() -> void:
|
|||||||
if not selecting:
|
if not selecting:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
_set_selection_state(true)
|
||||||
|
|
||||||
|
|
||||||
|
func _set_selection_state(hover: bool) -> void:
|
||||||
var rect_abs := selection_rect.abs()
|
var rect_abs := selection_rect.abs()
|
||||||
|
|
||||||
for unit: Node3D in visible_units.values():
|
for unit: Node3D in visible_units.values():
|
||||||
@@ -101,7 +107,11 @@ func _handle_unit_selection() -> void:
|
|||||||
+ (Vector3.UP * UNIT_SELECT_OFFSET)
|
+ (Vector3.UP * UNIT_SELECT_OFFSET)
|
||||||
)
|
)
|
||||||
if unit is TestUnit:
|
if unit is TestUnit:
|
||||||
(unit as TestUnit).set_selected(rect_abs.has_point(point))
|
if hover:
|
||||||
|
(unit as TestUnit).set_hovered(rect_abs.has_point(point))
|
||||||
|
else:
|
||||||
|
(unit as TestUnit).set_selected(rect_abs.has_point(point))
|
||||||
|
(unit as TestUnit).set_hovered(false)
|
||||||
|
|
||||||
|
|
||||||
func _on_frustrum_area_unit_entered(unit: Node3D) -> void:
|
func _on_frustrum_area_unit_entered(unit: Node3D) -> void:
|
||||||
|
|||||||
@@ -5,10 +5,12 @@ const MOVE_SPEED: float = 3
|
|||||||
const TURN_SPEED: float = 10
|
const TURN_SPEED: float = 10
|
||||||
|
|
||||||
var selected: bool = false
|
var selected: bool = false
|
||||||
|
var hovered: bool = false
|
||||||
var ground_plane: Plane = Plane(Vector3.UP, 0)
|
var ground_plane: Plane = Plane(Vector3.UP, 0)
|
||||||
|
|
||||||
@onready var camera: Camera3D = get_viewport().get_camera_3d()
|
@onready var camera: Camera3D = get_viewport().get_camera_3d()
|
||||||
@onready var selection_sprite: Sprite3D = $SelectionSprite
|
@onready var selection_sprite: Sprite3D = $SelectionSprite
|
||||||
|
@onready var hover_sprite: Sprite3D = $HoverSprite
|
||||||
@onready var nav_agent: NavigationAgent3D = $NavigationAgent3D
|
@onready var nav_agent: NavigationAgent3D = $NavigationAgent3D
|
||||||
@onready var animation_player: AnimationPlayer = $AnimationPlayer
|
@onready var animation_player: AnimationPlayer = $AnimationPlayer
|
||||||
|
|
||||||
@@ -40,7 +42,10 @@ func _input(event: InputEvent) -> void:
|
|||||||
|
|
||||||
func set_selected(on: bool) -> void:
|
func set_selected(on: bool) -> void:
|
||||||
selected = on
|
selected = on
|
||||||
selection_sprite.visible = selected
|
|
||||||
|
|
||||||
|
func set_hovered(on: bool) -> void:
|
||||||
|
hovered = on
|
||||||
|
|
||||||
|
|
||||||
func _set_target_click(mouse_pos: Vector2) -> void:
|
func _set_target_click(mouse_pos: Vector2) -> void:
|
||||||
@@ -74,14 +79,17 @@ func _animate(delta: float) -> void:
|
|||||||
var velocity_normalized := velocity.normalized()
|
var velocity_normalized := velocity.normalized()
|
||||||
var angle := atan2(-velocity_normalized.x, -velocity_normalized.z) + PI
|
var angle := atan2(-velocity_normalized.x, -velocity_normalized.z) + PI
|
||||||
global_rotation.y = rotate_toward(
|
global_rotation.y = rotate_toward(
|
||||||
global_rotation.y,
|
global_rotation.y,
|
||||||
angle,
|
angle,
|
||||||
TURN_SPEED * delta,
|
TURN_SPEED * delta,
|
||||||
)
|
)
|
||||||
# look_at(global_position + velocity, Vector3.UP, true)
|
# look_at(global_position + velocity, Vector3.UP, true)
|
||||||
animation_player.play('walk')
|
animation_player.play('walk')
|
||||||
else:
|
else:
|
||||||
animation_player.play('idle')
|
animation_player.play('idle')
|
||||||
|
|
||||||
|
selection_sprite.visible = selected
|
||||||
|
hover_sprite.visible = hovered
|
||||||
|
|
||||||
|
|
||||||
func _on_nav_agent_velocity_computed(safe_velocity: Vector3) -> void:
|
func _on_nav_agent_velocity_computed(safe_velocity: Vector3) -> void:
|
||||||
|
|||||||
Reference in New Issue
Block a user