add displaying gathering radius when showing unit info

This commit is contained in:
2024-10-07 23:37:21 +10:00
parent 0fba1ee78d
commit 81b68f592c
5 changed files with 45 additions and 12 deletions

View File

@@ -44,11 +44,18 @@ func _process(delta: float) -> void:
func open(who: Unit) -> void:
if unit != null:
close()
visible = true
unit = who
set_target(unit.ui_origin)
func close() -> void:
unit.toggle_info(false)
super.close()
func _set_image()->void:
for child:Control in get_children():
child.visible = false

View File

@@ -58,7 +58,7 @@ func _handle_wandering(delta: float) -> void:
func _handle_gathering() -> void:
gathering.handle_gathering(state != AntGathererState.GATHERING)
gathering.handle_gathering(state != AntGathererState.GATHERING, showing_info)
func _on_moving_ended() -> void:

View File

@@ -57,7 +57,7 @@ func _handle_wandering(delta: float) -> void:
func _handle_gathering() -> void:
gathering.handle_gathering(state != AntNitwitState.GATHERING)
gathering.handle_gathering(state != AntNitwitState.GATHERING, showing_info)
func _on_moving_ended() -> void:

View File

@@ -29,6 +29,7 @@ var skeleton: Skeleton3D
var drop_interval: float = DEFAULT_DROP_INTERVAL
var pickup_interval: float = DEFAULT_PICKUP_INTERVAL
var item_bones: Array[int] = []
var showing_after_set: bool = false
@onready var gathering_center: Vector3 = global_position
@onready var collision_shape: CollisionShape3D = $NearbyItemsSearch
@@ -53,6 +54,21 @@ func _process(_delta: float) -> void:
DebugDraw.circle(target.global_position)
func _input(event: InputEvent) -> void:
if not visible:
return
if event is InputEventMouseButton and showing_after_set:
var button_event := event as InputEventMouseButton
if not button_event.pressed:
return
if (
button_event.button_index == MOUSE_BUTTON_LEFT
or button_event.button_index == MOUSE_BUTTON_RIGHT
):
showing_after_set = false
func initialize(
from: Anthill,
skeleton_3d: Skeleton3D,
@@ -69,8 +85,21 @@ func initialize(
item_bones = bones
func handle_gathering(stop: bool, showing_info: bool) -> void:
collision_shape.global_position = gathering_center
collision_shape.global_rotation = Vector3.ZERO
if stop:
state = GatherState.STOP
radius_indicator.visible = (
(state != GatherState.STOP and showing_info)
or showing_after_set
)
func start_gathering(item: Honeydew) -> void:
gathering_center = item.global_position
showing_after_set = true
_go_gather(item)
@@ -79,13 +108,6 @@ func stop_gathering() -> void:
target = null
func handle_gathering(stop: bool) -> void:
collision_shape.global_position = gathering_center
collision_shape.global_rotation = Vector3.ZERO
if stop:
state = GatherState.STOP
func on_nav_agent_navigation_finished() -> void:
if state == GatherState.PICKING_UP and target != null:
_pick_up()
@@ -205,7 +227,6 @@ func _erase_honeydew(item: Honeydew) -> void:
func _on_body_entered(item: Node3D) -> void:
print(item, ' entered')
if item is not Honeydew:
return
@@ -217,7 +238,6 @@ func _on_body_entered(item: Node3D) -> void:
func _on_body_exited(item: Node3D) -> void:
print(item, ' exited')
if item is not Honeydew:
return

View File

@@ -14,6 +14,7 @@ var wandering_center: Vector3 = Vector3.ZERO
var spawn_pos: Vector3
var locomotion_value: float = 0
var showing_info: bool = false
@onready var nav_agent: NavigationAgent3D = $NavigationAgent3D
@onready var ui_origin: Node3D = $UiOrigin
@@ -54,7 +55,12 @@ func _physics_process(_delta: float) -> void:
_navigate()
func toggle_info(on: bool) -> void:
showing_info = on
func _click() ->void:
toggle_info(true)
UiManager.unit_info.open(self)