Add colors for buy/sell tooltips based on site prices.

This commit is contained in:
Avi Weinstock 2021-04-02 15:27:02 -04:00
parent d39d11d2fa
commit b7dbadc32f
8 changed files with 100 additions and 66 deletions

View File

@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Admin designated build areas - Admin designated build areas
- Indicator text to collectable terrain sprites - 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. - 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 ### Changed

View File

@ -304,19 +304,19 @@ impl<'a> InventoryScroller<'a> {
Quality::Artifact => self.imgs.inv_slot_orange, Quality::Artifact => self.imgs.inv_slot_orange,
_ => self.imgs.inv_slot_red, _ => self.imgs.inv_slot_red,
}; };
let i18n = &self.localized_strings;
let mut prices_info: Option<String> = None; let prices_info = self
if let Some((_, _, prices)) = self.client.pending_trade() { .client
prices_info = super::util::price_desc(prices, item.item_definition_id(), i18n); .pending_trade()
} .as_ref()
.and_then(|(_, _, prices)| prices.clone());
slot_widget slot_widget
.filled_slot(quality_col_img) .filled_slot(quality_col_img)
.with_item_tooltip( .with_item_tooltip(
self.item_tooltip_manager, self.item_tooltip_manager,
item, item,
prices_info, &prices_info,
self.item_tooltip, self.item_tooltip,
) )
.set(state.ids.inv_slots[i], ui); .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)) .with_icon(self.imgs.head_bg, Vec2::new(32.0, 40.0), Some(UI_MAIN))
.filled_slot(filled_slot); .filled_slot(filled_slot);
if let Some(item) = head_item { 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) .set(state.ids.head_slot, ui)
} else { } else {
slot.with_tooltip( 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)) .with_icon(self.imgs.necklace_bg, Vec2::new(40.0, 31.0), Some(UI_MAIN))
.filled_slot(filled_slot); .filled_slot(filled_slot);
if let Some(item) = neck_item { 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) .set(state.ids.neck_slot, ui)
} else { } else {
slot.with_tooltip( 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)) .with_icon(self.imgs.chest_bg, Vec2::new(64.0, 42.0), Some(UI_MAIN))
.filled_slot(filled_slot); .filled_slot(filled_slot);
if let Some(item) = chest_item { 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) .set(state.ids.chest_slot, ui)
} else { } else {
slot.with_tooltip( 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)) .with_icon(self.imgs.shoulders_bg, Vec2::new(60.0, 36.0), Some(UI_MAIN))
.filled_slot(filled_slot); .filled_slot(filled_slot);
if let Some(item) = shoulder_item { 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) .set(state.ids.shoulders_slot, ui)
} else { } else {
slot.with_tooltip( 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)) .with_icon(self.imgs.hands_bg, Vec2::new(55.0, 60.0), Some(UI_MAIN))
.filled_slot(filled_slot); .filled_slot(filled_slot);
if let Some(item) = hands_item { 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) .set(state.ids.hands_slot, ui)
} else { } else {
slot.with_tooltip( 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)) .with_icon(self.imgs.belt_bg, Vec2::new(40.0, 23.0), Some(UI_MAIN))
.filled_slot(filled_slot); .filled_slot(filled_slot);
if let Some(item) = belt_item { 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) .set(state.ids.belt_slot, ui)
} else { } else {
slot.with_tooltip( 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)) .with_icon(self.imgs.legs_bg, Vec2::new(48.0, 70.0), Some(UI_MAIN))
.filled_slot(filled_slot); .filled_slot(filled_slot);
if let Some(item) = legs_item { 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) .set(state.ids.legs_slot, ui)
} else { } else {
slot.with_tooltip( 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)) .with_icon(self.imgs.ring_bg, Vec2::new(36.0, 40.0), Some(UI_MAIN))
.filled_slot(filled_slot); .filled_slot(filled_slot);
if let Some(item) = ring1_item { 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) .set(state.ids.ring1_slot, ui)
} else { } else {
slot.with_tooltip( 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)) .with_icon(self.imgs.ring_bg, Vec2::new(36.0, 40.0), Some(UI_MAIN))
.filled_slot(filled_slot); .filled_slot(filled_slot);
if let Some(item) = ring2_item { 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) .set(state.ids.ring2_slot, ui)
} else { } else {
slot.with_tooltip( 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)) .with_icon(self.imgs.back_bg, Vec2::new(33.0, 40.0), Some(UI_MAIN))
.filled_slot(filled_slot); .filled_slot(filled_slot);
if let Some(item) = back_item { 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) .set(state.ids.back_slot, ui)
} else { } else {
slot.with_tooltip( 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)) .with_icon(self.imgs.feet_bg, Vec2::new(32.0, 40.0), Some(UI_MAIN))
.filled_slot(filled_slot); .filled_slot(filled_slot);
if let Some(item) = feet_item { 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) .set(state.ids.feet_slot, ui)
} else { } else {
slot.with_tooltip( 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)) .with_icon(self.imgs.lantern_bg, Vec2::new(24.0, 38.0), Some(UI_MAIN))
.filled_slot(filled_slot); .filled_slot(filled_slot);
if let Some(item) = lantern_item { 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) .set(state.ids.lantern_slot, ui)
} else { } else {
slot.with_tooltip( 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)) .with_icon(self.imgs.glider_bg, Vec2::new(38.0, 38.0), Some(UI_MAIN))
.filled_slot(filled_slot); .filled_slot(filled_slot);
if let Some(item) = glider_item { 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) .set(state.ids.glider_slot, ui)
} else { } else {
slot.with_tooltip( 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)) .with_icon(self.imgs.tabard_bg, Vec2::new(38.0, 38.0), Some(UI_MAIN))
.filled_slot(filled_slot); .filled_slot(filled_slot);
if let Some(item) = tabard_item { 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) .set(state.ids.tabard_slot, ui)
} else { } else {
slot.with_tooltip( 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)) .with_icon(self.imgs.mainhand_bg, Vec2::new(75.0, 75.0), Some(UI_MAIN))
.filled_slot(filled_slot); .filled_slot(filled_slot);
if let Some(item) = mainhand_item { 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) .set(state.ids.mainhand_slot, ui)
} else { } else {
slot.with_tooltip( 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)) .with_icon(self.imgs.offhand_bg, Vec2::new(75.0, 75.0), Some(UI_MAIN))
.filled_slot(filled_slot); .filled_slot(filled_slot);
if let Some(item) = offhand_item { 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) .set(state.ids.offhand_slot, ui)
} else { } else {
slot.with_tooltip( 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)) .with_icon(self.imgs.bag_bg, Vec2::new(28.0, 24.0), Some(UI_MAIN))
.filled_slot(filled_slot); .filled_slot(filled_slot);
if let Some(item) = bag1_item { 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) .set(state.ids.bag1_slot, ui)
} else { } else {
slot.with_tooltip( 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)) .with_icon(self.imgs.bag_bg, Vec2::new(28.0, 24.0), Some(UI_MAIN))
.filled_slot(filled_slot); .filled_slot(filled_slot);
if let Some(item) = bag2_item { 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) .set(state.ids.bag2_slot, ui)
} else { } else {
slot.with_tooltip( 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)) .with_icon(self.imgs.bag_bg, Vec2::new(28.0, 24.0), Some(UI_MAIN))
.filled_slot(filled_slot); .filled_slot(filled_slot);
if let Some(item) = bag3_item { 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) .set(state.ids.bag3_slot, ui)
} else { } else {
slot.with_tooltip( 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)) .with_icon(self.imgs.bag_bg, Vec2::new(28.0, 24.0), Some(UI_MAIN))
.filled_slot(filled_slot); .filled_slot(filled_slot);
if let Some(item) = bag4_item { 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) .set(state.ids.bag4_slot, ui)
} else { } else {
slot.with_tooltip( slot.with_tooltip(

View File

@ -326,7 +326,7 @@ impl<'a> Widget for Crafting<'a> {
.with_item_tooltip( .with_item_tooltip(
self.item_tooltip_manager, self.item_tooltip_manager,
&*recipe.output.0, &*recipe.output.0,
None, &None,
&item_tooltip, &item_tooltip,
) )
.set(state.ids.output_img, ui); .set(state.ids.output_img, ui);
@ -502,7 +502,7 @@ impl<'a> Widget for Crafting<'a> {
)) ))
.w_h(22.0, 22.0) .w_h(22.0, 22.0)
.middle_of(state.ids.ingredient_frame[i]) .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); .set(state.ids.ingredient_img[i], ui);
// Ingredients text and amount // Ingredients text and amount
// Don't show inventory amounts above 999 to avoid the widget clipping // Don't show inventory amounts above 999 to avoid the widget clipping

View File

@ -135,11 +135,11 @@ fn get_site_economy(site_rich: &SiteInfoRich) -> String {
let mut result = format!("\n\nPopulation {:?}", economy.population); let mut result = format!("\n\nPopulation {:?}", economy.population);
result += "\nStock"; result += "\nStock";
for i in [Food, Potions, Ingredients, Coin, Tools, Armor].iter() { 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"; result += "\nPrice";
for i in [Food, Potions, Ingredients, Coin, Tools, Armor].iter() { 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(); 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) { for i in trade_sorted.iter().filter(|x| *x.1 != 0.0) {
result += &format!("{:?} ", i.0); result += &format!("{:?} ", i.0);
} }
result += &format!("{:.1}", *(trade_sorted.last().unwrap().1)); result += &format!("{:.3}", *(trade_sorted.last().unwrap().1));
} }
result result
} else { } else {

View File

@ -591,7 +591,7 @@ impl<'a> Widget for Skillbar<'a> {
.filled_slot(self.imgs.skillbar_slot) .filled_slot(self.imgs.skillbar_slot)
.bottom_left_with_margins_on(state.ids.frame, 0.0, 0.0); .bottom_left_with_margins_on(state.ids.frame, 0.0, 0.0);
if let Some(item) = slot_content(hotbar::Slot::One) { 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); .set(state.ids.slot1, ui);
} else if let Some((title, desc)) = tooltip_text(hotbar::Slot::One) { } else if let Some((title, desc)) = tooltip_text(hotbar::Slot::One) {
slot.with_tooltip(self.tooltip_manager, title, desc, &tooltip, TEXT_COLOR) 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) .filled_slot(self.imgs.skillbar_slot)
.right_from(state.ids.slot1, slot_offset); .right_from(state.ids.slot1, slot_offset);
if let Some(item) = slot_content(hotbar::Slot::Two) { 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); .set(state.ids.slot2, ui);
} else if let Some((title, desc)) = tooltip_text(hotbar::Slot::Two) { } else if let Some((title, desc)) = tooltip_text(hotbar::Slot::Two) {
slot.with_tooltip(self.tooltip_manager, title, desc, &tooltip, TEXT_COLOR) 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) .filled_slot(self.imgs.skillbar_slot)
.right_from(state.ids.slot2, slot_offset); .right_from(state.ids.slot2, slot_offset);
if let Some(item) = slot_content(hotbar::Slot::Three) { 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); .set(state.ids.slot3, ui);
} else if let Some((title, desc)) = tooltip_text(hotbar::Slot::Three) { } else if let Some((title, desc)) = tooltip_text(hotbar::Slot::Three) {
slot.with_tooltip(self.tooltip_manager, title, desc, &tooltip, TEXT_COLOR) 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) .filled_slot(self.imgs.skillbar_slot)
.right_from(state.ids.slot3, slot_offset); .right_from(state.ids.slot3, slot_offset);
if let Some(item) = slot_content(hotbar::Slot::Four) { 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); .set(state.ids.slot4, ui);
} else if let Some((title, desc)) = tooltip_text(hotbar::Slot::Four) { } else if let Some((title, desc)) = tooltip_text(hotbar::Slot::Four) {
slot.with_tooltip(self.tooltip_manager, title, desc, &tooltip, TEXT_COLOR) 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) .filled_slot(self.imgs.skillbar_slot)
.right_from(state.ids.slot4, slot_offset); .right_from(state.ids.slot4, slot_offset);
if let Some(item) = slot_content(hotbar::Slot::Five) { 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); .set(state.ids.slot5, ui);
} else if let Some((title, desc)) = tooltip_text(hotbar::Slot::Five) { } else if let Some((title, desc)) = tooltip_text(hotbar::Slot::Five) {
slot.with_tooltip(self.tooltip_manager, title, desc, &tooltip, TEXT_COLOR) 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) .filled_slot(self.imgs.skillbar_slot)
.right_from(state.ids.m2_slot_bg, slot_offset); .right_from(state.ids.m2_slot_bg, slot_offset);
if let Some(item) = slot_content(hotbar::Slot::Six) { 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); .set(state.ids.slot6, ui);
} else if let Some((title, desc)) = tooltip_text(hotbar::Slot::Six) { } else if let Some((title, desc)) = tooltip_text(hotbar::Slot::Six) {
slot.with_tooltip(self.tooltip_manager, title, desc, &tooltip, TEXT_COLOR) 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) .filled_slot(self.imgs.skillbar_slot)
.right_from(state.ids.slot6, slot_offset); .right_from(state.ids.slot6, slot_offset);
if let Some(item) = slot_content(hotbar::Slot::Seven) { 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); .set(state.ids.slot7, ui);
} else if let Some((title, desc)) = tooltip_text(hotbar::Slot::Seven) { } else if let Some((title, desc)) = tooltip_text(hotbar::Slot::Seven) {
slot.with_tooltip(self.tooltip_manager, title, desc, &tooltip, TEXT_COLOR) 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) .filled_slot(self.imgs.skillbar_slot)
.right_from(state.ids.slot7, slot_offset); .right_from(state.ids.slot7, slot_offset);
if let Some(item) = slot_content(hotbar::Slot::Eight) { 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); .set(state.ids.slot8, ui);
} else if let Some((title, desc)) = tooltip_text(hotbar::Slot::Eight) { } else if let Some((title, desc)) = tooltip_text(hotbar::Slot::Eight) {
slot.with_tooltip(self.tooltip_manager, title, desc, &tooltip, TEXT_COLOR) 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) .filled_slot(self.imgs.skillbar_slot)
.right_from(state.ids.slot8, slot_offset); .right_from(state.ids.slot8, slot_offset);
if let Some(item) = slot_content(hotbar::Slot::Nine) { 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); .set(state.ids.slot9, ui);
} else if let Some((title, desc)) = tooltip_text(hotbar::Slot::Nine) { } else if let Some((title, desc)) = tooltip_text(hotbar::Slot::Nine) {
slot.with_tooltip(self.tooltip_manager, title, desc, &tooltip, TEXT_COLOR) slot.with_tooltip(self.tooltip_manager, title, desc, &tooltip, TEXT_COLOR)

View File

@ -372,12 +372,10 @@ impl<'a> Trade<'a> {
Quality::Artifact => self.imgs.inv_slot_orange, Quality::Artifact => self.imgs.inv_slot_orange,
_ => self.imgs.inv_slot_red, _ => 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 slot_widget
.filled_slot(quality_col_img) .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); .set(slot_id, ui);
} else { } else {
slot_widget.set(slot_id, ui); slot_widget.set(slot_id, ui);

View File

@ -19,21 +19,36 @@ pub fn price_desc(
prices: &Option<SitePrices>, prices: &Option<SitePrices>,
item_definition_id: &str, item_definition_id: &str,
i18n: &Localization, i18n: &Localization,
) -> Option<String> { ) -> Option<(String, String, f32)> {
if let Some(prices) = prices { if let Some(prices) = prices {
let (material, factor) = TradePricing::get_material(item_definition_id); let (material, factor) = TradePricing::get_material(item_definition_id);
let coinprice = prices.values.get(&Good::Coin).cloned().unwrap_or(1.0); let coinprice = prices.values.get(&Good::Coin).cloned().unwrap_or(1.0);
let buyprice = prices.values.get(&material).cloned().unwrap_or_default() * factor; let buyprice = prices.values.get(&material).cloned().unwrap_or_default() * factor;
let sellprice = buyprice * material.trade_margin(); 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"), i18n.get("hud.trade.buy_price"),
buyprice / coinprice, buyprice / coinprice,
i18n.get("hud.trade.coin"), i18n.get("hud.trade.coin"),
);
let sell_string = format!(
"{} : {:0.1} {}",
i18n.get("hud.trade.sell_price"), i18n.get("hud.trade.sell_price"),
sellprice / coinprice, sellprice / coinprice,
i18n.get("hud.trade.coin"), 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 { } else {
None None
} }

View File

@ -9,8 +9,9 @@ use crate::{
i18n::Localization, i18n::Localization,
}; };
use client::Client; use client::Client;
use common::comp::item::{ use common::{
armor::Protection, Item, ItemDesc, ItemKind, MaterialStatManifest, Quality, comp::item::{armor::Protection, Item, ItemDesc, ItemKind, MaterialStatManifest, Quality},
trade::SitePrices,
}; };
use conrod_core::{ use conrod_core::{
builder_method, builder_methods, image, input::global::Global, position::Dimension, text, builder_method, builder_methods, image, input::global::Global, position::Dimension, text,
@ -43,6 +44,7 @@ pub struct ItemTooltipManager {
// Current scaling of the ui // Current scaling of the ui
logical_scale_factor: f64, logical_scale_factor: f64,
} }
impl ItemTooltipManager { impl ItemTooltipManager {
pub fn new( pub fn new(
mut generator: widget::id::Generator, mut generator: widget::id::Generator,
@ -109,7 +111,7 @@ impl ItemTooltipManager {
&mut self, &mut self,
tooltip: &ItemTooltip, tooltip: &ItemTooltip,
item: &dyn ItemDesc, item: &dyn ItemDesc,
extra: Option<String>, prices: &Option<SitePrices>,
img_id: Option<image::Id>, img_id: Option<image::Id>,
image_dims: Option<(f64, f64)>, image_dims: Option<(f64, f64)>,
src_id: widget::Id, src_id: widget::Id,
@ -124,7 +126,7 @@ impl ItemTooltipManager {
let tooltip = tooltip let tooltip = tooltip
.clone() .clone()
.item(item) .item(item)
.extra(extra) .prices(prices)
.image(img_id) .image(img_id)
.image_dims(image_dims); .image_dims(image_dims);
@ -174,7 +176,7 @@ pub struct ItemTooltipped<'a, W> {
tooltip_manager: &'a mut ItemTooltipManager, tooltip_manager: &'a mut ItemTooltipManager,
item: &'a dyn ItemDesc, item: &'a dyn ItemDesc,
extra: Option<String>, prices: &'a Option<SitePrices>,
img_id: Option<image::Id>, img_id: Option<image::Id>,
image_dims: Option<(f64, f64)>, image_dims: Option<(f64, f64)>,
tooltip: &'a ItemTooltip<'a>, tooltip: &'a ItemTooltip<'a>,
@ -195,7 +197,7 @@ impl<'a, W: Widget> ItemTooltipped<'a, W> {
self.tooltip_manager.set_tooltip( self.tooltip_manager.set_tooltip(
self.tooltip, self.tooltip,
self.item, self.item,
self.extra, self.prices,
self.img_id, self.img_id,
self.image_dims, self.image_dims,
id, id,
@ -213,7 +215,7 @@ pub trait ItemTooltipable {
item: &'a dyn ItemDesc, item: &'a dyn ItemDesc,
extra: Option<String>, prices: &'a Option<SitePrices>,
tooltip: &'a ItemTooltip<'a>, tooltip: &'a ItemTooltip<'a>,
) -> ItemTooltipped<'a, Self> ) -> ItemTooltipped<'a, Self>
@ -225,14 +227,14 @@ impl<W: Widget> ItemTooltipable for W {
self, self,
tooltip_manager: &'a mut ItemTooltipManager, tooltip_manager: &'a mut ItemTooltipManager,
item: &'a dyn ItemDesc, item: &'a dyn ItemDesc,
extra: Option<String>, prices: &'a Option<SitePrices>,
tooltip: &'a ItemTooltip<'a>, tooltip: &'a ItemTooltip<'a>,
) -> ItemTooltipped<'a, W> { ) -> ItemTooltipped<'a, W> {
ItemTooltipped { ItemTooltipped {
inner: self, inner: self,
tooltip_manager, tooltip_manager,
item, item,
extra, prices,
img_id: None, img_id: None,
image_dims: None, image_dims: None,
tooltip, tooltip,
@ -258,7 +260,7 @@ pub struct ItemTooltip<'a> {
common: widget::CommonBuilder, common: widget::CommonBuilder,
item: &'a dyn ItemDesc, item: &'a dyn ItemDesc,
msm: &'a MaterialStatManifest, msm: &'a MaterialStatManifest,
extra: Option<String>, prices: &'a Option<SitePrices>,
image: Option<image::Id>, image: Option<image::Id>,
image_dims: Option<(f64, f64)>, image_dims: Option<(f64, f64)>,
style: Style, style: Style,
@ -285,7 +287,8 @@ widget_ids! {
title, title,
subtitle, subtitle,
desc, desc,
extra, prices_buy,
prices_sell,
main_stat, main_stat,
main_stat_text, main_stat_text,
stats[], stats[],
@ -318,7 +321,7 @@ impl<'a> ItemTooltip<'a> {
pub desc_line_spacing { style.desc.line_spacing = Some(Scalar) } pub desc_line_spacing { style.desc.line_spacing = Some(Scalar) }
image { image = Option<image::Id> } image { image = Option<image::Id> }
item { item = &'a dyn ItemDesc } item { item = &'a dyn ItemDesc }
extra { extra = Option<String> } prices { prices = &'a Option<SitePrices> }
msm { msm = &'a MaterialStatManifest } msm { msm = &'a MaterialStatManifest }
image_dims { image_dims = Option<(f64, f64)> } image_dims { image_dims = Option<(f64, f64)> }
transparency { transparency = f32 } transparency { transparency = f32 }
@ -338,7 +341,7 @@ impl<'a> ItemTooltip<'a> {
style: Style::default(), style: Style::default(),
item: &*EMPTY_ITEM, item: &*EMPTY_ITEM,
msm, msm,
extra: None, prices: &None,
transparency: 1.0, transparency: 1.0,
image_frame, image_frame,
image: None, image: None,
@ -885,13 +888,16 @@ impl<'a> Widget for ItemTooltip<'a> {
.set(state.ids.desc, ui); .set(state.ids.desc, ui);
} }
// Extra text // Price display
if let Some(extra) = self.extra { if let Some((buy, sell, factor)) =
widget::Text::new(&extra) 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) .x_align_to(state.ids.item_frame, conrod_core::position::Align::Start)
.graphics_for(id) .graphics_for(id)
.parent(id) .parent(id)
.with_style(self.style.desc) .with_style(self.style.desc)
.color(Color::Rgba(factor, 1.0 - factor, 0.00, 1.0))
.down_from( .down_from(
if !desc.is_empty() { if !desc.is_empty() {
state.ids.desc state.ids.desc
@ -903,7 +909,17 @@ impl<'a> Widget for ItemTooltip<'a> {
V_PAD, V_PAD,
) )
.w(text_w) .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 // Price
let price_h: f64 = if let Some(extra) = &self.extra { let price_h: f64 = if let Some((buy, sell, _)) = util::price_desc(
widget::Text::new(&extra) self.prices,
item.item_definition_id(),
&self.localized_strings,
) {
widget::Text::new(&format!("{}\n{}", buy, sell))
.with_style(self.style.desc) .with_style(self.style.desc)
.w(text_w) .w(text_w)
.get_h(ui) .get_h(ui)