Fixes #1452 - Prevents empty trades

This commit is contained in:
ShouvikGhosh2048 2022-02-16 21:41:26 +00:00 committed by Marcel
parent 6c7c0eefae
commit d72f43190b
3 changed files with 21 additions and 4 deletions

View File

@ -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] {

View File

@ -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,

View File

@ -473,10 +473,25 @@ impl<'a> Trade<'a> {
trade: &'a PendingTrade,
) -> <Self as Widget>::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))