diff --git a/assets/textures/gui/pictograms.png b/assets/textures/gui/pictograms.png index 5f32d59..b4eca4f 100644 --- a/assets/textures/gui/pictograms.png +++ b/assets/textures/gui/pictograms.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f6ccb1e85a80a53607af1f7edf874acfc5e7fd697161b4e0e5fedfade6193af0 -size 88493 +oid sha256:8c4f6c866dc5dd30b8baed4c33bfb2fb14c53540a413f0e4a247a5ddb23ec62f +size 91253 diff --git a/scenes/structures/Anthill.tscn b/scenes/structures/Anthill.tscn index 0e1b682..88fe9bf 100644 --- a/scenes/structures/Anthill.tscn +++ b/scenes/structures/Anthill.tscn @@ -30,3 +30,6 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.15587, 0) transform = Transform3D(1.62268, 0, 0, 0, 1.62268, 0, 0, 0, 1.62268, 0, 0, 0) cast_shadow = 0 mesh = SubResource("QuadMesh_2gykr") + +[node name="NavigationObstacle3D" type="NavigationObstacle3D" parent="."] +radius = 0.57 diff --git a/scenes/ui/unit_info.tscn b/scenes/ui/unit_info.tscn index ad747fb..ccc3bf2 100644 --- a/scenes/ui/unit_info.tscn +++ b/scenes/ui/unit_info.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=12 format=3 uid="uid://dhtofjn8dnuw3"] +[gd_scene load_steps=13 format=3 uid="uid://dhtofjn8dnuw3"] [ext_resource type="Texture2D" uid="uid://cc40vkh4nc6pk" path="res://assets/textures/gui/think_bubble.png" id="1_hsifm"] [ext_resource type="Script" path="res://scripts/ui/unit_info.gd" id="2_b6c6l"] @@ -20,9 +20,13 @@ region = Rect2(476.79, 88.6228, 77.4275, 53.8488) atlas = ExtResource("6_vrqjx") region = Rect2(572.197, 83.8424, 60.0876, 64.636) -[sub_resource type="AtlasTexture" id="AtlasTexture_o8jta"] +[sub_resource type="AtlasTexture" id="AtlasTexture_0t4ki"] atlas = ExtResource("6_vrqjx") -region = Rect2(654.844, 86.7453, 91.2445, 50.4017) +region = Rect2(656.569, 88.7656, 91.2443, 48.374) + +[sub_resource type="AtlasTexture" id="AtlasTexture_mcquw"] +atlas = ExtResource("6_vrqjx") +region = Rect2(758.514, 84.6555, 89.4846, 61.9183) [sub_resource type="AtlasTexture" id="AtlasTexture_ndwb1"] atlas = ExtResource("6_vrqjx") @@ -98,13 +102,28 @@ anchor_left = 0.5 anchor_top = 0.5 anchor_right = 0.5 anchor_bottom = 0.5 -offset_left = -45.0 -offset_top = -38.0 -offset_right = 46.0 -offset_bottom = 12.0 +offset_left = -47.0 +offset_top = -37.0 +offset_right = 44.0 +offset_bottom = 11.0 grow_horizontal = 2 grow_vertical = 2 -texture = SubResource("AtlasTexture_o8jta") +texture = SubResource("AtlasTexture_0t4ki") + +[node name="AntAwaiting" type="TextureRect" parent="."] +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -44.0 +offset_top = -42.0 +offset_right = 45.0 +offset_bottom = 19.0 +grow_horizontal = 2 +grow_vertical = 2 +texture = SubResource("AtlasTexture_mcquw") [node name="AphidIdle" type="TextureRect" parent="."] layout_mode = 1 diff --git a/scripts/ui/unit_info.gd b/scripts/ui/unit_info.gd index 880db5b..f526ba4 100644 --- a/scripts/ui/unit_info.gd +++ b/scripts/ui/unit_info.gd @@ -7,6 +7,7 @@ enum InfoState { ANT_MOVING, ANT_PICKING_UP, ANT_DEPOSITING, + ANT_AWAITING, APHID_IDLE, APHID_PANIC, APHID_EAT, @@ -19,6 +20,7 @@ var state: InfoState = InfoState.NONE @onready var ant_moving: Control = $AntMoving @onready var ant_picking_up: Control = $AntPickingUp @onready var ant_depositing: Control = $AntDepositing +@onready var ant_awaiting: Control = $AntAwaiting @onready var aphid_idle: Control = $AphidIdle @onready var aphid_panic: Control = $AphidPanic @onready var aphid_eat: Control = $AphidEat @@ -29,6 +31,7 @@ func _ready() -> void: assert(ant_moving != null, "ant_moving missing!") assert(ant_picking_up != null, "ant_picking_up missing!") assert(ant_depositing != null, "ant_depositing missing!") + assert(ant_awaiting != null, "ant_awaiting missing!") assert(aphid_idle != null, "aphid_idle missing!") assert(aphid_panic != null, "aphid_panic missing!") assert(aphid_eat != null, "aphid_eat missing!") @@ -56,8 +59,8 @@ func close() -> void: super.close() -func _set_image()->void: - for child:Control in get_children(): +func _set_image() -> void: + for child: Control in get_children(): child.visible = false match state: @@ -69,6 +72,8 @@ func _set_image()->void: ant_picking_up.visible = true InfoState.ANT_DEPOSITING: ant_depositing.visible = true + InfoState.ANT_AWAITING: + ant_awaiting.visible = true InfoState.APHID_IDLE: aphid_idle.visible = true InfoState.APHID_PANIC: @@ -90,13 +95,7 @@ func _get_state() -> void: AntNitwit.AntNitwitState.MOVING: state = InfoState.ANT_MOVING AntNitwit.AntNitwitState.GATHERING: - match (unit as AntNitwit).gathering.state: - Gathering.GatherState.PICKING_UP: - state = InfoState.ANT_PICKING_UP - Gathering.GatherState.DEPOSITING: - state = InfoState.ANT_DEPOSITING - Gathering.GatherState.STOP: - state = InfoState.NONE + _get_gathering_state((unit as AntNitwit).gathering.state) if unit is AntGatherer: match (unit as AntGatherer).state: @@ -105,10 +104,16 @@ func _get_state() -> void: AntGatherer.AntGathererState.MOVING: state = InfoState.ANT_MOVING AntGatherer.AntGathererState.GATHERING: - match (unit as AntGatherer).gathering.state: - Gathering.GatherState.PICKING_UP: - state = InfoState.ANT_PICKING_UP - Gathering.GatherState.DEPOSITING: - state = InfoState.ANT_DEPOSITING - Gathering.GatherState.STOP: - state = InfoState.NONE + _get_gathering_state((unit as AntGatherer).gathering.state) + + +func _get_gathering_state(gather_state: Gathering.GatherState) -> void: + match gather_state: + Gathering.GatherState.PICKING_UP: + state = InfoState.ANT_PICKING_UP + Gathering.GatherState.DEPOSITING: + state = InfoState.ANT_DEPOSITING + Gathering.GatherState.AWAITING: + state = InfoState.ANT_AWAITING + Gathering.GatherState.STOP: + state = InfoState.NONE diff --git a/scripts/units/ant_gatherer.gd b/scripts/units/ant_gatherer.gd index cc9472e..95a8ae6 100644 --- a/scripts/units/ant_gatherer.gd +++ b/scripts/units/ant_gatherer.gd @@ -31,13 +31,12 @@ func _ready() -> void: for i in MAX_CARRY: item_bones.append(skeleton.find_bone(ITEM_BONE_NAME + str(i))) gathering.initialize(anthill, skeleton, item_bones, MAX_CARRY, 0.4, 1) - gathering.target_set.connect(_on_gathering_target_set) - gathering.stopped_gathering.connect(_on_stopped_gathering) + gathering.navigate_to.connect(_on_gathering_navigate_to) func _process(delta: float) -> void: super._process(delta) - if moving_to_target: + if is_relocating: state = AntGathererState.MOVING _handle_wandering(delta) @@ -58,7 +57,7 @@ func _handle_wandering(delta: float) -> void: func _handle_gathering() -> void: - gathering.handle_gathering(state != AntGathererState.GATHERING, showing_info) + gathering.handle_gathering(showing_info) func _on_moving_ended() -> void: @@ -71,12 +70,8 @@ func _on_moving_started() -> void: state = AntGathererState.MOVING -func _on_gathering_target_set(pos: Vector3) -> void: +func _on_gathering_navigate_to(pos: Vector3) -> void: if state != AntGathererState.GATHERING: return - nav_agent.set_target_position(pos) - - -func _on_stopped_gathering() -> void: - state = AntGathererState.WANDERING + navigate(pos) diff --git a/scripts/units/ant_nitwit.gd b/scripts/units/ant_nitwit.gd index e75a723..c4611d1 100644 --- a/scripts/units/ant_nitwit.gd +++ b/scripts/units/ant_nitwit.gd @@ -30,13 +30,12 @@ func _ready() -> void: for i in gathering.DEFAULT_MAX_CARRYING: item_bones.append(skeleton.find_bone(ITEM_BONE_NAME + str(i))) gathering.initialize(anthill, skeleton, item_bones) - gathering.target_set.connect(_on_gathering_target_set) - gathering.stopped_gathering.connect(_on_stopped_gathering) + gathering.navigate_to.connect(_on_gathering_navigate_to) func _process(delta: float) -> void: super._process(delta) - if moving_to_target: + if is_relocating: state = AntNitwitState.MOVING _handle_wandering(delta) @@ -57,7 +56,7 @@ func _handle_wandering(delta: float) -> void: func _handle_gathering() -> void: - gathering.handle_gathering(state != AntNitwitState.GATHERING, showing_info) + gathering.handle_gathering(showing_info) func _on_moving_ended() -> void: @@ -70,12 +69,10 @@ func _on_moving_started() -> void: state = AntNitwitState.MOVING -func _on_gathering_target_set(pos: Vector3) -> void: +func _on_gathering_navigate_to(pos: Vector3) -> void: + print('_on_gathering_navigate_to') if state != AntNitwitState.GATHERING: return + print('_on_gathering_navigate_to 2') - nav_agent.set_target_position(pos) - - -func _on_stopped_gathering() -> void: - state = AntNitwitState.WANDERING + navigate(pos) diff --git a/scripts/units/aphid.gd b/scripts/units/aphid.gd index a2f661e..d121bd8 100644 --- a/scripts/units/aphid.gd +++ b/scripts/units/aphid.gd @@ -65,7 +65,6 @@ func _handle_honeydew_spawn(delta: float) -> void: holder.add_child(new_honeydew) new_honeydew.global_position = global_position + new_pos _put_honeydew(new_honeydew) - audio_player.play_polyphonic(SoundManager.pop()) _set_spawn_timer() diff --git a/scripts/units/components/gathering.gd b/scripts/units/components/gathering.gd index fcf883c..708b1fe 100644 --- a/scripts/units/components/gathering.gd +++ b/scripts/units/components/gathering.gd @@ -1,8 +1,7 @@ extends Area3D class_name Gathering -signal target_set(pos: Vector3) -signal stopped_gathering +signal navigate_to(pos: Vector3) const DEFAULT_MAX_CARRYING = 3 const DEFAULT_DROP_INTERVAL = 0.25 @@ -11,6 +10,7 @@ const DROP_SPREAD: float = 0.1 const ANTHILL_DEPOSIT_RADIUS: float = 0.5 enum GatherState { + AWAITING, PICKING_UP, DEPOSITING, STOP, @@ -89,11 +89,9 @@ func initialize( item_bones = bones -func handle_gathering(stop: bool, showing_info: bool) -> void: +func handle_gathering(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) @@ -104,7 +102,8 @@ func handle_gathering(stop: bool, showing_info: bool) -> void: func start_gathering(item: Honeydew) -> void: gathering_center = item.global_position showing_after_set = true - _go_gather(item) + state = GatherState.AWAITING + _go_pick_up(item) func stop_gathering() -> void: @@ -123,7 +122,7 @@ func on_nav_agent_navigation_finished() -> void: _deposit() -func _go_gather(item: Honeydew) -> void: +func _go_pick_up(item: Honeydew) -> void: if anthill.space_left() <= 0: return if carrying_items.size() >= max_carrying: @@ -131,13 +130,13 @@ func _go_gather(item: Honeydew) -> void: return target = item state = GatherState.PICKING_UP - target_set.emit(item.global_position) + navigate_to.emit(item.global_position) func _go_deposit() -> void: state = GatherState.DEPOSITING var dir := anthill.global_position.direction_to(global_position) - target_set.emit( + navigate_to.emit( anthill.global_position + dir * ANTHILL_DEPOSIT_RADIUS @@ -152,7 +151,7 @@ func _pick_up() -> void: var nearest := _find_nearest(nearby_items.values()) if target == null or target.carried: if nearest != null: - _go_gather(nearest) + _go_pick_up(nearest) elif carrying_items.size() > 0: _go_deposit() return @@ -170,7 +169,7 @@ func _pick_up() -> void: _go_deposit() return - _go_gather(nearest) + _go_pick_up(nearest) func _deposit() -> void: @@ -180,10 +179,8 @@ func _deposit() -> void: return if anthill.space_left() <= 0: - print('DROP!') - _drop_everything() - stop_gathering() - stopped_gathering.emit() + state = GatherState.AWAITING + await _drop_everything() return var item := carrying_items.pop_back() as Honeydew @@ -198,11 +195,11 @@ func _deposit() -> void: var nearest := _find_nearest(nearby_items.values()) if nearest != null: - _go_gather(nearest) + _go_pick_up(nearest) return - stop_gathering() - stopped_gathering.emit() + state = GatherState.AWAITING + navigate_to.emit(gathering_center) func _drop_everything() -> void: @@ -248,6 +245,8 @@ func _on_body_entered(item: Node3D) -> void: return nearby_items[item_id] = item as Honeydew + if state == GatherState.AWAITING and anthill.space_left() > 0: + _go_pick_up(item as Honeydew) func _on_body_exited(item: Node3D) -> void: diff --git a/scripts/units/controlled_unit.gd b/scripts/units/controlled_unit.gd index db301f2..ecdeb3b 100644 --- a/scripts/units/controlled_unit.gd +++ b/scripts/units/controlled_unit.gd @@ -8,7 +8,7 @@ var anthill: Anthill var hovered_rect: bool = false var selected: bool = false -var moving_to_target: bool = false +var is_relocating: bool = false var ground_plane: Plane = Plane(Vector3.UP, 0) @onready var camera: Camera3D = get_viewport().get_camera_3d() @@ -40,8 +40,8 @@ func _process(delta: float) -> void: func _physics_process(delta: float) -> void: super._physics_process(delta) - if moving_to_target and nav_agent.is_navigation_finished(): - moving_to_target = false + if is_relocating and nav_agent.is_navigation_finished(): + is_relocating = false moving_ended.emit() @@ -59,7 +59,6 @@ func _input(event: InputEvent) -> void: if HoveringManager.hovered_node is Interactable: _interact(HoveringManager.hovered_node as Interactable) else: - moving_to_target = true moving_started.emit() _set_target_click(button_event.position) @@ -78,6 +77,11 @@ func set_selected(on: bool) -> void: selected = on +func navigate(to: Vector3, relocating: bool = false) -> void: + is_relocating = relocating + nav_agent.set_target_position(to) + + func _interact(with: Interactable) -> void: print(self, ' interacting with ', with) @@ -87,7 +91,7 @@ func _set_target_click(mouse_pos: Vector2) -> void: if click_pos == null: return - nav_agent.set_target_position(click_pos) + navigate(click_pos, true) func _click_raycast(mouse_pos: Vector2) -> Vector3: diff --git a/scripts/units/unit.gd b/scripts/units/unit.gd index 606d0a4..1b41988 100644 --- a/scripts/units/unit.gd +++ b/scripts/units/unit.gd @@ -70,8 +70,8 @@ func toggle_info(on: bool) -> void: func _click() -> void: - toggle_info(true) UiManager.unit_info.open(self) + toggle_info(true) func _navigate() -> void: