Added additional confirmation when trading for nothing.

This commit is contained in:
Avi Weinstock 2023-06-26 10:39:30 -04:00
parent 2a4187e769
commit ced6880168
4 changed files with 30 additions and 5 deletions

View File

@ -52,6 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Adlet caves - Adlet caves
- Durability free areas (`/area_add <area_name> no_durability ...`) - Durability free areas (`/area_add <area_name> no_durability ...`)
- Added Brazilian Portuguese translation. - Added Brazilian Portuguese translation.
- Added additional confirmation when trading for nothing.
### Changed ### Changed

View File

@ -29,3 +29,4 @@ hud-trade-tooltip_hint_2 = <Ctrl-Click to Auto-Balance with this.>
hud-trade-your_offer = Your offer hud-trade-your_offer = Your offer
hud-trade-their_offer = Their offer hud-trade-their_offer = Their offer
hud-trade-amount_input = Select an item hud-trade-amount_input = Select an item
hud-confirm-trade-for-nothing = Really give away these items in exchange for nothing?

View File

@ -3183,12 +3183,16 @@ impl Hud {
} else { } else {
self.force_ungrab = true self.force_ungrab = true
}; };
self.show.prompt_dialog = None;
} }
events.push(Event::TradeAction(action)); events.push(Event::TradeAction(action));
}, },
trade::TradeEvent::SetDetailsMode(mode) => { trade::TradeEvent::SetDetailsMode(mode) => {
self.show.trade_details = mode; self.show.trade_details = mode;
}, },
trade::TradeEvent::ShowPrompt(prompt) => {
self.show.prompt_dialog = Some(prompt);
},
} }
} }
} }

View File

@ -19,7 +19,10 @@ use common_net::sync::WorldSyncExt;
use i18n::Localization; use i18n::Localization;
use crate::{ use crate::{
hud::bag::{BackgroundIds, InventoryScroller}, hud::{
bag::{BackgroundIds, InventoryScroller},
Event as HudEvent, PromptDialogSettings,
},
ui::{ ui::{
fonts::Fonts, fonts::Fonts,
slot::{ContentSize, SlotMaker}, slot::{ContentSize, SlotMaker},
@ -36,11 +39,11 @@ use super::{
}; };
use std::borrow::Cow; use std::borrow::Cow;
#[derive(Debug)]
pub enum TradeEvent { pub enum TradeEvent {
TradeAction(TradeAction), TradeAction(TradeAction),
SetDetailsMode(bool), SetDetailsMode(bool),
HudUpdate(HudUpdate), HudUpdate(HudUpdate),
ShowPrompt(PromptDialogSettings),
} }
#[derive(Debug)] #[derive(Debug)]
@ -98,6 +101,7 @@ pub struct Trade<'a> {
msm: &'a MaterialStatManifest, msm: &'a MaterialStatManifest,
pulse: f32, pulse: f32,
show: &'a mut Show, show: &'a mut Show,
needs_thirdconfirm: bool,
} }
impl<'a> Trade<'a> { impl<'a> Trade<'a> {
@ -131,6 +135,7 @@ impl<'a> Trade<'a> {
msm, msm,
pulse, pulse,
show, show,
needs_thirdconfirm: false,
} }
} }
} }
@ -552,6 +557,10 @@ impl<'a> Trade<'a> {
1.0, 1.0,
)) ))
.set(state.ids.inv_textslots[who * MAX_TRADE_SLOTS], ui); .set(state.ids.inv_textslots[who * MAX_TRADE_SLOTS], ui);
if !ours {
self.needs_thirdconfirm = true;
}
} }
} }
@ -590,7 +599,17 @@ impl<'a> Trade<'a> {
.set(state.ids.accept_button, ui) .set(state.ids.accept_button, ui)
.was_clicked() .was_clicked()
{ {
event = Some(TradeAction::Accept(trade.phase())); if matches!(trade.phase, TradePhase::Review) && self.needs_thirdconfirm {
event = Some(TradeEvent::ShowPrompt(PromptDialogSettings::new(
self.localized_strings
.get_msg("hud-confirm-trade-for-nothing")
.to_string(),
HudEvent::TradeAction(TradeAction::Accept(trade.phase())),
None,
)));
} else {
event = Some(TradeEvent::TradeAction(TradeAction::Accept(trade.phase())));
}
} }
if Button::image(self.imgs.button) if Button::image(self.imgs.button)
@ -606,9 +625,9 @@ impl<'a> Trade<'a> {
.set(state.ids.decline_button, ui) .set(state.ids.decline_button, ui)
.was_clicked() .was_clicked()
{ {
event = Some(TradeAction::Decline); event = Some(TradeEvent::TradeAction(TradeAction::Decline));
} }
event.map(TradeEvent::TradeAction) event
} }
fn input_item_amount( fn input_item_amount(