diff --git a/CHANGELOG.md b/CHANGELOG.md index a1ac007634..c4fef7c43b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Admin designated build areas - Indicator text to collectable terrain sprites - You can now autorequest exact change by ctrl-clicking in a trade, and can quick-add individual items with shift-click. +- Buy and sell prices in tooltips when trading with a merchant now have colors. ### Changed diff --git a/voxygen/src/hud/bag.rs b/voxygen/src/hud/bag.rs index fd7bd1834c..7d031ef6f4 100644 --- a/voxygen/src/hud/bag.rs +++ b/voxygen/src/hud/bag.rs @@ -304,19 +304,19 @@ impl<'a> InventoryScroller<'a> { Quality::Artifact => self.imgs.inv_slot_orange, _ => self.imgs.inv_slot_red, }; - let i18n = &self.localized_strings; - let mut prices_info: Option = None; - if let Some((_, _, prices)) = self.client.pending_trade() { - prices_info = super::util::price_desc(prices, item.item_definition_id(), i18n); - } + let prices_info = self + .client + .pending_trade() + .as_ref() + .and_then(|(_, _, prices)| prices.clone()); slot_widget .filled_slot(quality_col_img) .with_item_tooltip( self.item_tooltip_manager, item, - prices_info, + &prices_info, self.item_tooltip, ) .set(state.ids.inv_slots[i], ui); @@ -792,7 +792,7 @@ impl<'a> Widget for Bag<'a> { .with_icon(self.imgs.head_bg, Vec2::new(32.0, 40.0), Some(UI_MAIN)) .filled_slot(filled_slot); if let Some(item) = head_item { - slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + slot.with_item_tooltip(self.item_tooltip_manager, &item, &None, &item_tooltip) .set(state.ids.head_slot, ui) } else { slot.with_tooltip( @@ -815,7 +815,7 @@ impl<'a> Widget for Bag<'a> { .with_icon(self.imgs.necklace_bg, Vec2::new(40.0, 31.0), Some(UI_MAIN)) .filled_slot(filled_slot); if let Some(item) = neck_item { - slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + slot.with_item_tooltip(self.item_tooltip_manager, &item, &None, &item_tooltip) .set(state.ids.neck_slot, ui) } else { slot.with_tooltip( @@ -839,7 +839,7 @@ impl<'a> Widget for Bag<'a> { .with_icon(self.imgs.chest_bg, Vec2::new(64.0, 42.0), Some(UI_MAIN)) .filled_slot(filled_slot); if let Some(item) = chest_item { - slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + slot.with_item_tooltip(self.item_tooltip_manager, &item, &None, &item_tooltip) .set(state.ids.chest_slot, ui) } else { slot.with_tooltip( @@ -862,7 +862,7 @@ impl<'a> Widget for Bag<'a> { .with_icon(self.imgs.shoulders_bg, Vec2::new(60.0, 36.0), Some(UI_MAIN)) .filled_slot(filled_slot); if let Some(item) = shoulder_item { - slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + slot.with_item_tooltip(self.item_tooltip_manager, &item, &None, &item_tooltip) .set(state.ids.shoulders_slot, ui) } else { slot.with_tooltip( @@ -884,7 +884,7 @@ impl<'a> Widget for Bag<'a> { .with_icon(self.imgs.hands_bg, Vec2::new(55.0, 60.0), Some(UI_MAIN)) .filled_slot(filled_slot); if let Some(item) = hands_item { - slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + slot.with_item_tooltip(self.item_tooltip_manager, &item, &None, &item_tooltip) .set(state.ids.hands_slot, ui) } else { slot.with_tooltip( @@ -906,7 +906,7 @@ impl<'a> Widget for Bag<'a> { .with_icon(self.imgs.belt_bg, Vec2::new(40.0, 23.0), Some(UI_MAIN)) .filled_slot(filled_slot); if let Some(item) = belt_item { - slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + slot.with_item_tooltip(self.item_tooltip_manager, &item, &None, &item_tooltip) .set(state.ids.belt_slot, ui) } else { slot.with_tooltip( @@ -928,7 +928,7 @@ impl<'a> Widget for Bag<'a> { .with_icon(self.imgs.legs_bg, Vec2::new(48.0, 70.0), Some(UI_MAIN)) .filled_slot(filled_slot); if let Some(item) = legs_item { - slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + slot.with_item_tooltip(self.item_tooltip_manager, &item, &None, &item_tooltip) .set(state.ids.legs_slot, ui) } else { slot.with_tooltip( @@ -950,7 +950,7 @@ impl<'a> Widget for Bag<'a> { .with_icon(self.imgs.ring_bg, Vec2::new(36.0, 40.0), Some(UI_MAIN)) .filled_slot(filled_slot); if let Some(item) = ring1_item { - slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + slot.with_item_tooltip(self.item_tooltip_manager, &item, &None, &item_tooltip) .set(state.ids.ring1_slot, ui) } else { slot.with_tooltip( @@ -972,7 +972,7 @@ impl<'a> Widget for Bag<'a> { .with_icon(self.imgs.ring_bg, Vec2::new(36.0, 40.0), Some(UI_MAIN)) .filled_slot(filled_slot); if let Some(item) = ring2_item { - slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + slot.with_item_tooltip(self.item_tooltip_manager, &item, &None, &item_tooltip) .set(state.ids.ring2_slot, ui) } else { slot.with_tooltip( @@ -994,7 +994,7 @@ impl<'a> Widget for Bag<'a> { .with_icon(self.imgs.back_bg, Vec2::new(33.0, 40.0), Some(UI_MAIN)) .filled_slot(filled_slot); if let Some(item) = back_item { - slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + slot.with_item_tooltip(self.item_tooltip_manager, &item, &None, &item_tooltip) .set(state.ids.back_slot, ui) } else { slot.with_tooltip( @@ -1016,7 +1016,7 @@ impl<'a> Widget for Bag<'a> { .with_icon(self.imgs.feet_bg, Vec2::new(32.0, 40.0), Some(UI_MAIN)) .filled_slot(filled_slot); if let Some(item) = feet_item { - slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + slot.with_item_tooltip(self.item_tooltip_manager, &item, &None, &item_tooltip) .set(state.ids.feet_slot, ui) } else { slot.with_tooltip( @@ -1038,7 +1038,7 @@ impl<'a> Widget for Bag<'a> { .with_icon(self.imgs.lantern_bg, Vec2::new(24.0, 38.0), Some(UI_MAIN)) .filled_slot(filled_slot); if let Some(item) = lantern_item { - slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + slot.with_item_tooltip(self.item_tooltip_manager, &item, &None, &item_tooltip) .set(state.ids.lantern_slot, ui) } else { slot.with_tooltip( @@ -1060,7 +1060,7 @@ impl<'a> Widget for Bag<'a> { .with_icon(self.imgs.glider_bg, Vec2::new(38.0, 38.0), Some(UI_MAIN)) .filled_slot(filled_slot); if let Some(item) = glider_item { - slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + slot.with_item_tooltip(self.item_tooltip_manager, &item, &None, &item_tooltip) .set(state.ids.glider_slot, ui) } else { slot.with_tooltip( @@ -1082,7 +1082,7 @@ impl<'a> Widget for Bag<'a> { .with_icon(self.imgs.tabard_bg, Vec2::new(38.0, 38.0), Some(UI_MAIN)) .filled_slot(filled_slot); if let Some(item) = tabard_item { - slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + slot.with_item_tooltip(self.item_tooltip_manager, &item, &None, &item_tooltip) .set(state.ids.tabard_slot, ui) } else { slot.with_tooltip( @@ -1105,7 +1105,7 @@ impl<'a> Widget for Bag<'a> { .with_icon(self.imgs.mainhand_bg, Vec2::new(75.0, 75.0), Some(UI_MAIN)) .filled_slot(filled_slot); if let Some(item) = mainhand_item { - slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + slot.with_item_tooltip(self.item_tooltip_manager, &item, &None, &item_tooltip) .set(state.ids.mainhand_slot, ui) } else { slot.with_tooltip( @@ -1127,7 +1127,7 @@ impl<'a> Widget for Bag<'a> { .with_icon(self.imgs.offhand_bg, Vec2::new(75.0, 75.0), Some(UI_MAIN)) .filled_slot(filled_slot); if let Some(item) = offhand_item { - slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + slot.with_item_tooltip(self.item_tooltip_manager, &item, &None, &item_tooltip) .set(state.ids.offhand_slot, ui) } else { slot.with_tooltip( @@ -1154,7 +1154,7 @@ impl<'a> Widget for Bag<'a> { .with_icon(self.imgs.bag_bg, Vec2::new(28.0, 24.0), Some(UI_MAIN)) .filled_slot(filled_slot); if let Some(item) = bag1_item { - slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + slot.with_item_tooltip(self.item_tooltip_manager, &item, &None, &item_tooltip) .set(state.ids.bag1_slot, ui) } else { slot.with_tooltip( @@ -1176,7 +1176,7 @@ impl<'a> Widget for Bag<'a> { .with_icon(self.imgs.bag_bg, Vec2::new(28.0, 24.0), Some(UI_MAIN)) .filled_slot(filled_slot); if let Some(item) = bag2_item { - slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + slot.with_item_tooltip(self.item_tooltip_manager, &item, &None, &item_tooltip) .set(state.ids.bag2_slot, ui) } else { slot.with_tooltip( @@ -1198,7 +1198,7 @@ impl<'a> Widget for Bag<'a> { .with_icon(self.imgs.bag_bg, Vec2::new(28.0, 24.0), Some(UI_MAIN)) .filled_slot(filled_slot); if let Some(item) = bag3_item { - slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + slot.with_item_tooltip(self.item_tooltip_manager, &item, &None, &item_tooltip) .set(state.ids.bag3_slot, ui) } else { slot.with_tooltip( @@ -1220,7 +1220,7 @@ impl<'a> Widget for Bag<'a> { .with_icon(self.imgs.bag_bg, Vec2::new(28.0, 24.0), Some(UI_MAIN)) .filled_slot(filled_slot); if let Some(item) = bag4_item { - slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + slot.with_item_tooltip(self.item_tooltip_manager, &item, &None, &item_tooltip) .set(state.ids.bag4_slot, ui) } else { slot.with_tooltip( diff --git a/voxygen/src/hud/crafting.rs b/voxygen/src/hud/crafting.rs index 12f620d6b5..28089484ec 100644 --- a/voxygen/src/hud/crafting.rs +++ b/voxygen/src/hud/crafting.rs @@ -326,7 +326,7 @@ impl<'a> Widget for Crafting<'a> { .with_item_tooltip( self.item_tooltip_manager, &*recipe.output.0, - None, + &None, &item_tooltip, ) .set(state.ids.output_img, ui); @@ -502,7 +502,7 @@ impl<'a> Widget for Crafting<'a> { )) .w_h(22.0, 22.0) .middle_of(state.ids.ingredient_frame[i]) - .with_item_tooltip(self.item_tooltip_manager, &*item_def, None, &item_tooltip) + .with_item_tooltip(self.item_tooltip_manager, &*item_def, &None, &item_tooltip) .set(state.ids.ingredient_img[i], ui); // Ingredients text and amount // Don't show inventory amounts above 999 to avoid the widget clipping diff --git a/voxygen/src/hud/map.rs b/voxygen/src/hud/map.rs index 6975634ab2..5cda0b59c1 100644 --- a/voxygen/src/hud/map.rs +++ b/voxygen/src/hud/map.rs @@ -135,11 +135,11 @@ fn get_site_economy(site_rich: &SiteInfoRich) -> String { let mut result = format!("\n\nPopulation {:?}", economy.population); result += "\nStock"; for i in [Food, Potions, Ingredients, Coin, Tools, Armor].iter() { - result += &format!(" {:?}={:.1}", *i, *economy.stock.get(i).unwrap_or(&0.0)); + result += &format!("\n {:?}={:.3}", *i, *economy.stock.get(i).unwrap_or(&0.0)); } result += "\nPrice"; for i in [Food, Potions, Ingredients, Coin, Tools, Armor].iter() { - result += &format!(" {:?}={:.1}", *i, *economy.values.get(i).unwrap_or(&0.0)); + result += &format!("\n {:?}={:.3}", *i, *economy.values.get(i).unwrap_or(&0.0)); } let mut trade_sorted: Vec<(&Good, &f32)> = economy.last_exports.iter().collect(); @@ -149,7 +149,7 @@ fn get_site_economy(site_rich: &SiteInfoRich) -> String { for i in trade_sorted.iter().filter(|x| *x.1 != 0.0) { result += &format!("{:?} ", i.0); } - result += &format!("{:.1}", *(trade_sorted.last().unwrap().1)); + result += &format!("{:.3}", *(trade_sorted.last().unwrap().1)); } result } else { diff --git a/voxygen/src/hud/skillbar.rs b/voxygen/src/hud/skillbar.rs index f90dc830cd..c32b4949ac 100644 --- a/voxygen/src/hud/skillbar.rs +++ b/voxygen/src/hud/skillbar.rs @@ -591,7 +591,7 @@ impl<'a> Widget for Skillbar<'a> { .filled_slot(self.imgs.skillbar_slot) .bottom_left_with_margins_on(state.ids.frame, 0.0, 0.0); if let Some(item) = slot_content(hotbar::Slot::One) { - slot.with_item_tooltip(self.item_tooltip_manager, item, None, &item_tooltip) + slot.with_item_tooltip(self.item_tooltip_manager, item, &None, &item_tooltip) .set(state.ids.slot1, ui); } else if let Some((title, desc)) = tooltip_text(hotbar::Slot::One) { slot.with_tooltip(self.tooltip_manager, title, desc, &tooltip, TEXT_COLOR) @@ -605,7 +605,7 @@ impl<'a> Widget for Skillbar<'a> { .filled_slot(self.imgs.skillbar_slot) .right_from(state.ids.slot1, slot_offset); if let Some(item) = slot_content(hotbar::Slot::Two) { - slot.with_item_tooltip(self.item_tooltip_manager, item, None, &item_tooltip) + slot.with_item_tooltip(self.item_tooltip_manager, item, &None, &item_tooltip) .set(state.ids.slot2, ui); } else if let Some((title, desc)) = tooltip_text(hotbar::Slot::Two) { slot.with_tooltip(self.tooltip_manager, title, desc, &tooltip, TEXT_COLOR) @@ -619,7 +619,7 @@ impl<'a> Widget for Skillbar<'a> { .filled_slot(self.imgs.skillbar_slot) .right_from(state.ids.slot2, slot_offset); if let Some(item) = slot_content(hotbar::Slot::Three) { - slot.with_item_tooltip(self.item_tooltip_manager, item, None, &item_tooltip) + slot.with_item_tooltip(self.item_tooltip_manager, item, &None, &item_tooltip) .set(state.ids.slot3, ui); } else if let Some((title, desc)) = tooltip_text(hotbar::Slot::Three) { slot.with_tooltip(self.tooltip_manager, title, desc, &tooltip, TEXT_COLOR) @@ -633,7 +633,7 @@ impl<'a> Widget for Skillbar<'a> { .filled_slot(self.imgs.skillbar_slot) .right_from(state.ids.slot3, slot_offset); if let Some(item) = slot_content(hotbar::Slot::Four) { - slot.with_item_tooltip(self.item_tooltip_manager, item, None, &item_tooltip) + slot.with_item_tooltip(self.item_tooltip_manager, item, &None, &item_tooltip) .set(state.ids.slot4, ui); } else if let Some((title, desc)) = tooltip_text(hotbar::Slot::Four) { slot.with_tooltip(self.tooltip_manager, title, desc, &tooltip, TEXT_COLOR) @@ -647,7 +647,7 @@ impl<'a> Widget for Skillbar<'a> { .filled_slot(self.imgs.skillbar_slot) .right_from(state.ids.slot4, slot_offset); if let Some(item) = slot_content(hotbar::Slot::Five) { - slot.with_item_tooltip(self.item_tooltip_manager, item, None, &item_tooltip) + slot.with_item_tooltip(self.item_tooltip_manager, item, &None, &item_tooltip) .set(state.ids.slot5, ui); } else if let Some((title, desc)) = tooltip_text(hotbar::Slot::Five) { slot.with_tooltip(self.tooltip_manager, title, desc, &tooltip, TEXT_COLOR) @@ -754,7 +754,7 @@ impl<'a> Widget for Skillbar<'a> { .filled_slot(self.imgs.skillbar_slot) .right_from(state.ids.m2_slot_bg, slot_offset); if let Some(item) = slot_content(hotbar::Slot::Six) { - slot.with_item_tooltip(self.item_tooltip_manager, item, None, &item_tooltip) + slot.with_item_tooltip(self.item_tooltip_manager, item, &None, &item_tooltip) .set(state.ids.slot6, ui); } else if let Some((title, desc)) = tooltip_text(hotbar::Slot::Six) { slot.with_tooltip(self.tooltip_manager, title, desc, &tooltip, TEXT_COLOR) @@ -768,7 +768,7 @@ impl<'a> Widget for Skillbar<'a> { .filled_slot(self.imgs.skillbar_slot) .right_from(state.ids.slot6, slot_offset); if let Some(item) = slot_content(hotbar::Slot::Seven) { - slot.with_item_tooltip(self.item_tooltip_manager, item, None, &item_tooltip) + slot.with_item_tooltip(self.item_tooltip_manager, item, &None, &item_tooltip) .set(state.ids.slot7, ui); } else if let Some((title, desc)) = tooltip_text(hotbar::Slot::Seven) { slot.with_tooltip(self.tooltip_manager, title, desc, &tooltip, TEXT_COLOR) @@ -782,7 +782,7 @@ impl<'a> Widget for Skillbar<'a> { .filled_slot(self.imgs.skillbar_slot) .right_from(state.ids.slot7, slot_offset); if let Some(item) = slot_content(hotbar::Slot::Eight) { - slot.with_item_tooltip(self.item_tooltip_manager, item, None, &item_tooltip) + slot.with_item_tooltip(self.item_tooltip_manager, item, &None, &item_tooltip) .set(state.ids.slot8, ui); } else if let Some((title, desc)) = tooltip_text(hotbar::Slot::Eight) { slot.with_tooltip(self.tooltip_manager, title, desc, &tooltip, TEXT_COLOR) @@ -796,7 +796,7 @@ impl<'a> Widget for Skillbar<'a> { .filled_slot(self.imgs.skillbar_slot) .right_from(state.ids.slot8, slot_offset); if let Some(item) = slot_content(hotbar::Slot::Nine) { - slot.with_item_tooltip(self.item_tooltip_manager, item, None, &item_tooltip) + slot.with_item_tooltip(self.item_tooltip_manager, item, &None, &item_tooltip) .set(state.ids.slot9, ui); } else if let Some((title, desc)) = tooltip_text(hotbar::Slot::Nine) { slot.with_tooltip(self.tooltip_manager, title, desc, &tooltip, TEXT_COLOR) diff --git a/voxygen/src/hud/trade.rs b/voxygen/src/hud/trade.rs index 3a506f5911..adf6392dee 100644 --- a/voxygen/src/hud/trade.rs +++ b/voxygen/src/hud/trade.rs @@ -372,12 +372,10 @@ impl<'a> Trade<'a> { Quality::Artifact => self.imgs.inv_slot_orange, _ => self.imgs.inv_slot_red, }; - let i18n = &self.localized_strings; - let prices_info = super::util::price_desc(prices, item.item_definition_id(), i18n); slot_widget .filled_slot(quality_col_img) - .with_item_tooltip(self.item_tooltip_manager, item, prices_info, &item_tooltip) + .with_item_tooltip(self.item_tooltip_manager, item, prices, &item_tooltip) .set(slot_id, ui); } else { slot_widget.set(slot_id, ui); diff --git a/voxygen/src/hud/util.rs b/voxygen/src/hud/util.rs index 60f08fa105..9edda17811 100644 --- a/voxygen/src/hud/util.rs +++ b/voxygen/src/hud/util.rs @@ -19,21 +19,36 @@ pub fn price_desc( prices: &Option, item_definition_id: &str, i18n: &Localization, -) -> Option { +) -> Option<(String, String, f32)> { if let Some(prices) = prices { let (material, factor) = TradePricing::get_material(item_definition_id); let coinprice = prices.values.get(&Good::Coin).cloned().unwrap_or(1.0); let buyprice = prices.values.get(&material).cloned().unwrap_or_default() * factor; let sellprice = buyprice * material.trade_margin(); - Some(format!( - "{} : {:0.1} {}\n{} : {:0.1} {}", + + let deal_goodness = prices.values.get(&material).cloned().unwrap_or(0.0) + / prices.values.get(&Good::Coin).cloned().unwrap_or(1.0); + let deal_goodness = deal_goodness.log(2.0); + let buy_string = format!( + "{} : {:0.1} {}", i18n.get("hud.trade.buy_price"), buyprice / coinprice, i18n.get("hud.trade.coin"), + ); + let sell_string = format!( + "{} : {:0.1} {}", i18n.get("hud.trade.sell_price"), sellprice / coinprice, i18n.get("hud.trade.coin"), - )) + ); + let deal_goodness = match deal_goodness { + x if x < -2.5 => 0.0, + x if x < -1.05 => 0.25, + x if x < -0.95 => 0.5, + x if x < 0.0 => 0.75, + _ => 1.0, + }; + Some((buy_string, sell_string, deal_goodness)) } else { None } diff --git a/voxygen/src/ui/widgets/item_tooltip.rs b/voxygen/src/ui/widgets/item_tooltip.rs index efdecdc753..fdd51c6043 100644 --- a/voxygen/src/ui/widgets/item_tooltip.rs +++ b/voxygen/src/ui/widgets/item_tooltip.rs @@ -9,8 +9,9 @@ use crate::{ i18n::Localization, }; use client::Client; -use common::comp::item::{ - armor::Protection, Item, ItemDesc, ItemKind, MaterialStatManifest, Quality, +use common::{ + comp::item::{armor::Protection, Item, ItemDesc, ItemKind, MaterialStatManifest, Quality}, + trade::SitePrices, }; use conrod_core::{ builder_method, builder_methods, image, input::global::Global, position::Dimension, text, @@ -43,6 +44,7 @@ pub struct ItemTooltipManager { // Current scaling of the ui logical_scale_factor: f64, } + impl ItemTooltipManager { pub fn new( mut generator: widget::id::Generator, @@ -109,7 +111,7 @@ impl ItemTooltipManager { &mut self, tooltip: &ItemTooltip, item: &dyn ItemDesc, - extra: Option, + prices: &Option, img_id: Option, image_dims: Option<(f64, f64)>, src_id: widget::Id, @@ -124,7 +126,7 @@ impl ItemTooltipManager { let tooltip = tooltip .clone() .item(item) - .extra(extra) + .prices(prices) .image(img_id) .image_dims(image_dims); @@ -174,7 +176,7 @@ pub struct ItemTooltipped<'a, W> { tooltip_manager: &'a mut ItemTooltipManager, item: &'a dyn ItemDesc, - extra: Option, + prices: &'a Option, img_id: Option, image_dims: Option<(f64, f64)>, tooltip: &'a ItemTooltip<'a>, @@ -195,7 +197,7 @@ impl<'a, W: Widget> ItemTooltipped<'a, W> { self.tooltip_manager.set_tooltip( self.tooltip, self.item, - self.extra, + self.prices, self.img_id, self.image_dims, id, @@ -213,7 +215,7 @@ pub trait ItemTooltipable { item: &'a dyn ItemDesc, - extra: Option, + prices: &'a Option, tooltip: &'a ItemTooltip<'a>, ) -> ItemTooltipped<'a, Self> @@ -225,14 +227,14 @@ impl ItemTooltipable for W { self, tooltip_manager: &'a mut ItemTooltipManager, item: &'a dyn ItemDesc, - extra: Option, + prices: &'a Option, tooltip: &'a ItemTooltip<'a>, ) -> ItemTooltipped<'a, W> { ItemTooltipped { inner: self, tooltip_manager, item, - extra, + prices, img_id: None, image_dims: None, tooltip, @@ -258,7 +260,7 @@ pub struct ItemTooltip<'a> { common: widget::CommonBuilder, item: &'a dyn ItemDesc, msm: &'a MaterialStatManifest, - extra: Option, + prices: &'a Option, image: Option, image_dims: Option<(f64, f64)>, style: Style, @@ -285,7 +287,8 @@ widget_ids! { title, subtitle, desc, - extra, + prices_buy, + prices_sell, main_stat, main_stat_text, stats[], @@ -318,7 +321,7 @@ impl<'a> ItemTooltip<'a> { pub desc_line_spacing { style.desc.line_spacing = Some(Scalar) } image { image = Option } item { item = &'a dyn ItemDesc } - extra { extra = Option } + prices { prices = &'a Option } msm { msm = &'a MaterialStatManifest } image_dims { image_dims = Option<(f64, f64)> } transparency { transparency = f32 } @@ -338,7 +341,7 @@ impl<'a> ItemTooltip<'a> { style: Style::default(), item: &*EMPTY_ITEM, msm, - extra: None, + prices: &None, transparency: 1.0, image_frame, image: None, @@ -885,13 +888,16 @@ impl<'a> Widget for ItemTooltip<'a> { .set(state.ids.desc, ui); } - // Extra text - if let Some(extra) = self.extra { - widget::Text::new(&extra) + // Price display + if let Some((buy, sell, factor)) = + util::price_desc(self.prices, item.item_definition_id(), i18n) + { + widget::Text::new(&buy) .x_align_to(state.ids.item_frame, conrod_core::position::Align::Start) .graphics_for(id) .parent(id) .with_style(self.style.desc) + .color(Color::Rgba(factor, 1.0 - factor, 0.00, 1.0)) .down_from( if !desc.is_empty() { state.ids.desc @@ -903,7 +909,17 @@ impl<'a> Widget for ItemTooltip<'a> { V_PAD, ) .w(text_w) - .set(state.ids.extra, ui); + .set(state.ids.prices_buy, ui); + + widget::Text::new(&sell) + .x_align_to(state.ids.item_frame, conrod_core::position::Align::Start) + .graphics_for(id) + .parent(id) + .with_style(self.style.desc) + .color(Color::Rgba(1.0 - factor, factor, 0.00, 1.0)) + .down_from(state.ids.prices_buy, V_PAD_STATS) + .w(text_w) + .set(state.ids.prices_sell, ui); } } @@ -969,8 +985,12 @@ impl<'a> Widget for ItemTooltip<'a> { }; // Price - let price_h: f64 = if let Some(extra) = &self.extra { - widget::Text::new(&extra) + let price_h: f64 = if let Some((buy, sell, _)) = util::price_desc( + self.prices, + item.item_definition_id(), + &self.localized_strings, + ) { + widget::Text::new(&format!("{}\n{}", buy, sell)) .with_style(self.style.desc) .w(text_w) .get_h(ui)