From 7a178639884d3e5f02ee03d6703d2c87f5b4007e Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 5 Oct 2021 22:08:03 -0400 Subject: [PATCH] Salvage works by double clicking from inventory while salvage tab in crafting is open. --- client/src/lib.rs | 22 +++++++++++++++++++++- voxygen/src/hud/mod.rs | 19 ++++++++++++++----- voxygen/src/session/mod.rs | 3 +++ 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index 7ddc91b0a6..0cf679117c 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -27,7 +27,7 @@ use common::{ group, invite::{InviteKind, InviteResponse}, skills::Skill, - slot::Slot, + slot::{InvSlotId, Slot}, CharacterState, ChatMode, ControlAction, ControlEvent, Controller, ControllerInputs, GroupManip, InputKind, InventoryAction, InventoryEvent, InventoryUpdateEvent, UtteranceKind, @@ -1015,6 +1015,26 @@ impl Client { } } + pub fn can_salvage_item(&self, slot: InvSlotId) -> bool { + self.inventories() + .get(self.entity()) + .and_then(|inv| inv.get(slot)) + .map_or(false, |item| item.is_salvageable()) + } + + pub fn salvage_item(&mut self, slot: InvSlotId) -> bool { + let is_salvageable = self.can_salvage_item(slot); + if is_salvageable { + self.send_msg(ClientGeneral::ControlEvent(ControlEvent::InventoryEvent( + InventoryEvent::CraftRecipe { + craft_event: CraftEvent::Salvage(slot), + craft_sprite: None, + }, + ))); + } + is_salvageable + } + fn update_available_recipes(&mut self) { self.available_recipes = self .recipe_book diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 2281261fa5..fbe61773be 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -75,7 +75,7 @@ use common::{ combat, comp::{ self, fluid_dynamics, - inventory::trade_pricing::TradePricing, + inventory::{slot::InvSlotId, trade_pricing::TradePricing}, item::{tool::ToolKind, ItemDesc, MaterialStatManifest, Quality}, skills::{Skill, SkillGroupKind}, BuffData, BuffKind, Item, @@ -521,6 +521,7 @@ pub enum Event { recipe: String, craft_sprite: Option<(Vec3, SpriteKind)>, }, + SalvageItem(InvSlotId), InviteMember(Uid), AcceptInvite, DeclineInvite, @@ -3329,10 +3330,18 @@ impl Hud { slot::Event::Used(from) => { // Item used (selected and then clicked again) if let Some(from) = to_slot(from) { - events.push(Event::UseSlot { - slot: from, - bypass_dialog: false, - }); + if self.show.crafting + && matches!(self.show.crafting_tab, CraftingTab::Dismantle) + { + if let Slot::Inventory(slot) = from { + events.push(Event::SalvageItem(slot)) + } + } else { + events.push(Event::UseSlot { + slot: from, + bypass_dialog: false, + }); + } } else if let Hotbar(h) = from { // Used from hotbar self.hotbar.get(h).map(|s| { diff --git a/voxygen/src/session/mod.rs b/voxygen/src/session/mod.rs index 58ff24ac25..4cdae8a24f 100644 --- a/voxygen/src/session/mod.rs +++ b/voxygen/src/session/mod.rs @@ -1397,6 +1397,9 @@ impl PlayState for SessionState { } => { self.client.borrow_mut().craft_recipe(&recipe, craft_sprite); }, + HudEvent::SalvageItem(slot) => { + self.client.borrow_mut().salvage_item(slot); + }, HudEvent::InviteMember(uid) => { self.client.borrow_mut().send_invite(uid, InviteKind::Group); },