From d72f43190b62ea5e789b5db4216c8eed0ff4f5b9 Mon Sep 17 00:00:00 2001 From: ShouvikGhosh2048 Date: Wed, 16 Feb 2022 21:41:26 +0000 Subject: [PATCH] Fixes #1452 - Prevents empty trades --- common/src/trade.rs | 4 +++- server/src/sys/agent.rs | 2 +- voxygen/src/hud/trade.rs | 19 +++++++++++++++++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/common/src/trade.rs b/common/src/trade.rs index 4d8bd721a6..f37ac12ef7 100644 --- a/common/src/trade.rs +++ b/common/src/trade.rs @@ -116,6 +116,8 @@ impl PendingTrade { .map(|(i, _)| i) } + pub fn is_empty_trade(&self) -> bool { self.offers[0].is_empty() && self.offers[1].is_empty() } + /// Invariants: /// - A party is never shown as offering more of an item than they own /// - Offers with a quantity of zero get removed from the trade @@ -165,7 +167,7 @@ impl PendingTrade { } }, Accept(phase) => { - if self.phase == phase { + if self.phase == phase && !self.is_empty_trade() { self.accept_flags[who] = true; } if self.accept_flags[0] && self.accept_flags[1] { diff --git a/server/src/sys/agent.rs b/server/src/sys/agent.rs index ba3b3431d7..d21cd5ca58 100644 --- a/server/src/sys/agent.rs +++ b/server/src/sys/agent.rs @@ -1226,7 +1226,7 @@ impl<'a> AgentData<'a> { // results in lagging and moving to the review phase of an unfavorable trade // (although since the phase is included in the message, this shouldn't // result in fully accepting an unfavourable trade)) - if !pending.accept_flags[who] { + if !pending.accept_flags[who] && !pending.is_empty_trade() { event_emitter.emit(ServerEvent::ProcessTradeAction( *self.entity, tradeid, diff --git a/voxygen/src/hud/trade.rs b/voxygen/src/hud/trade.rs index d1cfd454f1..36f428d4e7 100644 --- a/voxygen/src/hud/trade.rs +++ b/voxygen/src/hud/trade.rs @@ -473,10 +473,25 @@ impl<'a> Trade<'a> { trade: &'a PendingTrade, ) -> ::Event { let mut event = None; + let (hover_img, press_img, accept_button_luminance) = if trade.is_empty_trade() { + //Darken the accept button if the trade is empty. + ( + self.imgs.button, + self.imgs.button, + Color::Rgba(0.6, 0.6, 0.6, 1.0), + ) + } else { + ( + self.imgs.button_hover, + self.imgs.button_press, + Color::Rgba(1.0, 1.0, 1.0, 1.0), + ) + }; if Button::image(self.imgs.button) .w_h(31.0 * 5.0, 12.0 * 2.0) - .hover_image(self.imgs.button_hover) - .press_image(self.imgs.button_press) + .hover_image(hover_img) + .press_image(press_img) + .image_color(accept_button_luminance) .bottom_left_with_margins_on(state.ids.bg, 90.0, 47.0) .label(self.localized_strings.get("hud.trade.accept")) .label_font_size(self.fonts.cyri.scale(14))