From 81b68f592ca3b753d69b35b4ed46423bcbce8442 Mon Sep 17 00:00:00 2001 From: teatov Date: Mon, 7 Oct 2024 23:37:21 +1000 Subject: [PATCH] add displaying gathering radius when showing unit info --- scripts/ui/unit_info.gd | 9 ++++++- scripts/units/ant_gatherer.gd | 2 +- scripts/units/ant_nitwit.gd | 2 +- scripts/units/components/gathering.gd | 38 ++++++++++++++++++++------- scripts/units/unit.gd | 6 +++++ 5 files changed, 45 insertions(+), 12 deletions(-) diff --git a/scripts/ui/unit_info.gd b/scripts/ui/unit_info.gd index 0d33bc8..880db5b 100644 --- a/scripts/ui/unit_info.gd +++ b/scripts/ui/unit_info.gd @@ -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 @@ -104,4 +111,4 @@ func _get_state() -> void: Gathering.GatherState.DEPOSITING: state = InfoState.ANT_DEPOSITING Gathering.GatherState.STOP: - state = InfoState.NONE \ No newline at end of file + state = InfoState.NONE diff --git a/scripts/units/ant_gatherer.gd b/scripts/units/ant_gatherer.gd index 3ab34fe..cc9472e 100644 --- a/scripts/units/ant_gatherer.gd +++ b/scripts/units/ant_gatherer.gd @@ -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: diff --git a/scripts/units/ant_nitwit.gd b/scripts/units/ant_nitwit.gd index 27d8947..e75a723 100644 --- a/scripts/units/ant_nitwit.gd +++ b/scripts/units/ant_nitwit.gd @@ -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: diff --git a/scripts/units/components/gathering.gd b/scripts/units/components/gathering.gd index 92c7176..51a9644 100644 --- a/scripts/units/components/gathering.gd +++ b/scripts/units/components/gathering.gd @@ -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 diff --git a/scripts/units/unit.gd b/scripts/units/unit.gd index 901e1d2..7f3f5bf 100644 --- a/scripts/units/unit.gd +++ b/scripts/units/unit.gd @@ -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)