From bc692c0101bdf78b549b5270f6c64d206d5686dd Mon Sep 17 00:00:00 2001 From: S Handley Date: Wed, 11 Mar 2020 10:30:59 +0000 Subject: [PATCH] Add audio and chat message feedback when the player attempts to collect something while thier inventory is full. --- CHANGELOG.md | 1 + assets/voxygen/audio/sfx.ron | 6 ++++ .../audio/sfx/inventory/add_failed.wav | 3 ++ .../voxygen/audio/sfx/inventory/add_item.wav | 4 +-- client/src/lib.rs | 18 ++++++++++-- common/src/comp/inventory/mod.rs | 1 + server/src/events/inventory_manip.rs | 29 ++++++++++++------- 7 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 assets/voxygen/audio/sfx/inventory/add_failed.wav diff --git a/CHANGELOG.md b/CHANGELOG.md index 74023e63c9..f0f8bc8c16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Game pauses when in singleplayer and pause menu - Added authentication system (to play on the official server register on https://account.veloren.net) - Added gamepad/controller support +- Added player feedback when attempting to pickup an item with a full inventory ### Changed diff --git a/assets/voxygen/audio/sfx.ron b/assets/voxygen/audio/sfx.ron index 2a8d79e5e2..9add266bf9 100644 --- a/assets/voxygen/audio/sfx.ron +++ b/assets/voxygen/audio/sfx.ron @@ -88,6 +88,12 @@ "voxygen.audio.sfx.inventory.consumable.food", ], threshold: 0.3, + ), + Inventory(CollectFailed): ( + files: [ + "voxygen.audio.sfx.inventory.add_failed", + ], + threshold: 0.3, ) } ) \ No newline at end of file diff --git a/assets/voxygen/audio/sfx/inventory/add_failed.wav b/assets/voxygen/audio/sfx/inventory/add_failed.wav new file mode 100644 index 0000000000..6e5d3abe97 --- /dev/null +++ b/assets/voxygen/audio/sfx/inventory/add_failed.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b7cf98460ef3c627df1603e34b9b2b4443f54dc9bfafccaccaba6719f4214085 +size 51216 diff --git a/assets/voxygen/audio/sfx/inventory/add_item.wav b/assets/voxygen/audio/sfx/inventory/add_item.wav index b6fa2c3665..380dc30d4d 100644 --- a/assets/voxygen/audio/sfx/inventory/add_item.wav +++ b/assets/voxygen/audio/sfx/inventory/add_item.wav @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5320d020c82cab3f1ed294c06bdd50df007ed354bca2103b42e3fb4fc3f3ee7a -size 71196 +oid sha256:f811babdffe01795b1ff75827ab8e968b61baff8243ea031390dc49152885950 +size 40140 diff --git a/client/src/lib.rs b/client/src/lib.rs index 8895ce60d4..6d7b6f7405 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -14,7 +14,9 @@ pub use specs::{ use byteorder::{ByteOrder, LittleEndian}; use common::{ - comp::{self, ControlEvent, Controller, ControllerInputs, InventoryManip}, + comp::{ + self, ControlEvent, Controller, ControllerInputs, InventoryManip, InventoryUpdateEvent, + }, event::{EventBus, SfxEvent, SfxEventItem}, msg::{ validate_chat_msg, ChatMsgValidationError, ClientMsg, ClientState, PlayerListUpdate, @@ -689,7 +691,19 @@ impl Client { } }, ServerMsg::InventoryUpdate(inventory, event) => { - self.state.write_component(self.entity, inventory); + match event { + InventoryUpdateEvent::CollectFailed => { + frontend_events.push(Event::Chat { + message: String::from( + "Failed to collect item. Your inventory may be full!", + ), + chat_type: ChatType::Meta, + }) + }, + _ => { + self.state.write_component(self.entity, inventory); + }, + } self.state .ecs() diff --git a/common/src/comp/inventory/mod.rs b/common/src/comp/inventory/mod.rs index 1b79359eb8..6861e59d01 100644 --- a/common/src/comp/inventory/mod.rs +++ b/common/src/comp/inventory/mod.rs @@ -150,6 +150,7 @@ pub enum InventoryUpdateEvent { Swapped, Dropped, Collected, + CollectFailed, Possession, Debug, } diff --git a/server/src/events/inventory_manip.rs b/server/src/events/inventory_manip.rs index 62aed2d676..1973410290 100644 --- a/server/src/events/inventory_manip.rs +++ b/server/src/events/inventory_manip.rs @@ -61,17 +61,24 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv let block = state.terrain().get(pos).ok().copied(); if let Some(block) = block { - if block.is_collectible() - && state - .ecs() - .read_storage::() - .get(entity) - .map(|inv| !inv.is_full()) - .unwrap_or(false) - && state.try_set_block(pos, Block::empty()).is_some() - { - comp::Item::try_reclaim_from_block(block) - .map(|item| state.give_item(entity, item)); + let has_inv_space = state + .ecs() + .read_storage::() + .get(entity) + .map(|inv| !inv.is_full()) + .unwrap_or(false); + + if !has_inv_space { + state.write_component( + entity, + comp::InventoryUpdate::new(comp::InventoryUpdateEvent::CollectFailed), + ); + } else { + if block.is_collectible() && state.try_set_block(pos, Block::empty()).is_some() + { + comp::Item::try_reclaim_from_block(block) + .map(|item| state.give_item(entity, item)); + } } } },