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
- Durability free areas (`/area_add <area_name> no_durability ...`)
- Added Brazilian Portuguese translation.
- Added additional confirmation when trading for nothing.
### 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-their_offer = Their offer
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 {
self.force_ungrab = true
};
self.show.prompt_dialog = None;
}
events.push(Event::TradeAction(action));
},
trade::TradeEvent::SetDetailsMode(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 crate::{
hud::bag::{BackgroundIds, InventoryScroller},
hud::{
bag::{BackgroundIds, InventoryScroller},
Event as HudEvent, PromptDialogSettings,
},
ui::{
fonts::Fonts,
slot::{ContentSize, SlotMaker},
@ -36,11 +39,11 @@ use super::{
};
use std::borrow::Cow;
#[derive(Debug)]
pub enum TradeEvent {
TradeAction(TradeAction),
SetDetailsMode(bool),
HudUpdate(HudUpdate),
ShowPrompt(PromptDialogSettings),
}
#[derive(Debug)]
@ -98,6 +101,7 @@ pub struct Trade<'a> {
msm: &'a MaterialStatManifest,
pulse: f32,
show: &'a mut Show,
needs_thirdconfirm: bool,
}
impl<'a> Trade<'a> {
@ -131,6 +135,7 @@ impl<'a> Trade<'a> {
msm,
pulse,
show,
needs_thirdconfirm: false,
}
}
}
@ -552,6 +557,10 @@ impl<'a> Trade<'a> {
1.0,
))
.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)
.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)
@ -606,9 +625,9 @@ impl<'a> Trade<'a> {
.set(state.ids.decline_button, ui)
.was_clicked()
{
event = Some(TradeAction::Decline);
event = Some(TradeEvent::TradeAction(TradeAction::Decline));
}
event.map(TradeEvent::TradeAction)
event
}
fn input_item_amount(