From b8ac90d0490e52960cad2f12a887eec9b553e051 Mon Sep 17 00:00:00 2001 From: Snowram Date: Wed, 24 Mar 2021 23:17:25 +0100 Subject: [PATCH] Changelog, cleanup, clippy --- CHANGELOG.md | 2 +- assets/voxygen/i18n/en/hud/trade.ron | 3 + assets/voxygen/i18n/fr_FR/hud/trade.ron | 3 + voxygen/src/hud/bag.rs | 335 +++++------------------- voxygen/src/hud/crafting.rs | 46 +--- voxygen/src/hud/mod.rs | 3 - voxygen/src/hud/skillbar.rs | 145 +++------- voxygen/src/hud/trade.rs | 44 +--- voxygen/src/hud/util.rs | 277 ++------------------ voxygen/src/ui/widgets/item_tooltip.rs | 216 ++++++++------- 10 files changed, 256 insertions(+), 818 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d4f0ce25f..de56e6a875 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,9 +24,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Separated character randomization buttons into appearance and name. - Reworked mindflayer to have unique attacks - Glowing remains are now `Armor` instead of `Ingredients`. - - Generated a net world map - Overhauled clouds for more verticality and performance +- New tooltip for items with stats comparison ### Removed diff --git a/assets/voxygen/i18n/en/hud/trade.ron b/assets/voxygen/i18n/en/hud/trade.ron index 7d4ecd2ad9..28614092fe 100644 --- a/assets/voxygen/i18n/en/hud/trade.ron +++ b/assets/voxygen/i18n/en/hud/trade.ron @@ -16,6 +16,9 @@ "hud.trade.result.completed": "Trade completed successfully.", "hud.trade.result.declined": "Trade declined.", "hud.trade.result.nospace": "Not enough space to complete the trade.", + "hud.trade.buy_price": "Buy price", + "hud.trade.sell_price": "Sell Price", + "hud.trade.coin": "coin(s)", }, diff --git a/assets/voxygen/i18n/fr_FR/hud/trade.ron b/assets/voxygen/i18n/fr_FR/hud/trade.ron index 8d88819a62..b53043ba8f 100644 --- a/assets/voxygen/i18n/fr_FR/hud/trade.ron +++ b/assets/voxygen/i18n/fr_FR/hud/trade.ron @@ -16,6 +16,9 @@ "hud.trade.result.completed": "Échange complété avec succès.", "hud.trade.result.declined": "Échange décliné.", "hud.trade.result.nospace": "Pas assez d'espace libre pour compléter l'échange.", + "hud.trade.buy_price": "Prix d'achat", + "hud.trade.sell_price": "Prix de vente", + "hud.trade.coin": "pièce(s)", }, diff --git a/voxygen/src/hud/bag.rs b/voxygen/src/hud/bag.rs index 35ba142fc3..703ec6b0b8 100644 --- a/voxygen/src/hud/bag.rs +++ b/voxygen/src/hud/bag.rs @@ -69,17 +69,14 @@ pub struct InventoryScroller<'a> { fonts: &'a Fonts, #[conrod(common_builder)] common: widget::CommonBuilder, - tooltip_manager: &'a mut TooltipManager, item_tooltip_manager: &'a mut ItemTooltipManager, slot_manager: &'a mut SlotManager, pulse: f32, localized_strings: &'a Localization, show_stats: bool, show_bag_inv: bool, - msm: &'a MaterialStatManifest, on_right: bool, - item_tooltip: &'a Tooltip<'a>, - item_tooltip2: &'a ItemTooltip<'a>, + item_tooltip: &'a ItemTooltip<'a>, playername: String, is_us: bool, inventory: &'a Inventory, @@ -93,17 +90,14 @@ impl<'a> InventoryScroller<'a> { imgs: &'a Imgs, item_imgs: &'a ItemImgs, fonts: &'a Fonts, - tooltip_manager: &'a mut TooltipManager, item_tooltip_manager: &'a mut ItemTooltipManager, slot_manager: &'a mut SlotManager, pulse: f32, localized_strings: &'a Localization, show_stats: bool, show_bag_inv: bool, - msm: &'a MaterialStatManifest, on_right: bool, - item_tooltip: &'a Tooltip<'a>, - item_tooltip2: &'a ItemTooltip<'a>, + item_tooltip: &'a ItemTooltip<'a>, playername: String, is_us: bool, inventory: &'a Inventory, @@ -115,17 +109,14 @@ impl<'a> InventoryScroller<'a> { item_imgs, fonts, common: widget::CommonBuilder::default(), - tooltip_manager, item_tooltip_manager, slot_manager, pulse, localized_strings, show_stats, show_bag_inv, - msm, on_right, item_tooltip, - item_tooltip2, playername, is_us, inventory, @@ -308,22 +299,20 @@ impl<'a> InventoryScroller<'a> { Quality::Artifact => self.imgs.inv_slot_orange, _ => self.imgs.inv_slot_red, }; - let mut desc = desc.to_string(); + let i18n = &self.localized_strings; + + let mut prices_info: Option = None; if let Some((_, _, prices)) = self.client.pending_trade() { - super::util::append_price_desc(&mut desc, prices, item.item_definition_id()); + 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, - self.client, - self.imgs, - self.item_imgs, - self.pulse, item, - self.msm, - self.item_tooltip2, + prices_info, + self.item_tooltip, ) .set(state.ids.inv_slots[i], ui); } else { @@ -569,7 +558,7 @@ impl<'a> Widget for Bag<'a> { }; // Tooltips - let item_tooltip = Tooltip::new({ + let tooltip = Tooltip::new({ // Edge images [t, b, r, l] // Corner images [tr, tl, br, bl] let edge = &self.rot_imgs.tt_side; @@ -587,8 +576,7 @@ impl<'a> Widget for Bag<'a> { .font_id(self.fonts.cyri.conrod_id) .desc_text_color(TEXT_COLOR); - // Tooltips - let item_tooltip2 = ItemTooltip::new( + let item_tooltip = ItemTooltip::new( { // Edge images [t, b, r, l] // Corner images [tr, tl, br, bl] @@ -619,17 +607,14 @@ impl<'a> Widget for Bag<'a> { self.imgs, self.item_imgs, self.fonts, - self.tooltip_manager, self.item_tooltip_manager, self.slot_manager, self.pulse, self.localized_strings, self.show.stats, self.show.bag_inv, - self.msm, true, &item_tooltip, - &item_tooltip2, self.stats.name.to_string(), true, &inventory, @@ -801,23 +786,14 @@ 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, - self.client, - self.imgs, - self.item_imgs, - self.pulse, - &item, - self.msm, - &item_tooltip2, - ) - .set(state.ids.head_slot, ui) + slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + .set(state.ids.head_slot, ui) } else { slot.with_tooltip( self.tooltip_manager, i18n.get("hud.bag.head"), "", - &item_tooltip, + &tooltip, color::WHITE, ) .set(state.ids.head_slot, ui) @@ -833,23 +809,14 @@ 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, - self.client, - self.imgs, - self.item_imgs, - self.pulse, - &item, - self.msm, - &item_tooltip2, - ) - .set(state.ids.neck_slot, ui) + slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + .set(state.ids.neck_slot, ui) } else { slot.with_tooltip( self.tooltip_manager, i18n.get("hud.bag.neck"), "", - &item_tooltip, + &tooltip, color::WHITE, ) .set(state.ids.neck_slot, ui) @@ -866,23 +833,14 @@ 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, - self.client, - self.imgs, - self.item_imgs, - self.pulse, - &item, - self.msm, - &item_tooltip2, - ) - .set(state.ids.chest_slot, ui) + slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + .set(state.ids.chest_slot, ui) } else { slot.with_tooltip( self.tooltip_manager, i18n.get("hud.bag.chest"), "", - &item_tooltip, + &tooltip, color::WHITE, ) .set(state.ids.chest_slot, ui) @@ -898,23 +856,14 @@ 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, - self.client, - self.imgs, - self.item_imgs, - self.pulse, - &item, - self.msm, - &item_tooltip2, - ) - .set(state.ids.shoulders_slot, ui) + slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + .set(state.ids.shoulders_slot, ui) } else { slot.with_tooltip( self.tooltip_manager, i18n.get("hud.bag.shoulders"), "", - &item_tooltip, + &tooltip, color::WHITE, ) .set(state.ids.shoulders_slot, ui) @@ -929,23 +878,14 @@ 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, - self.client, - self.imgs, - self.item_imgs, - self.pulse, - &item, - self.msm, - &item_tooltip2, - ) - .set(state.ids.hands_slot, ui) + slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + .set(state.ids.hands_slot, ui) } else { slot.with_tooltip( self.tooltip_manager, i18n.get("hud.bag.hands"), "", - &item_tooltip, + &tooltip, color::WHITE, ) .set(state.ids.hands_slot, ui) @@ -960,23 +900,14 @@ 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, - self.client, - self.imgs, - self.item_imgs, - self.pulse, - &item, - self.msm, - &item_tooltip2, - ) - .set(state.ids.belt_slot, ui) + slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + .set(state.ids.belt_slot, ui) } else { slot.with_tooltip( self.tooltip_manager, i18n.get("hud.bag.belt"), "", - &item_tooltip, + &tooltip, color::WHITE, ) .set(state.ids.belt_slot, ui) @@ -991,23 +922,14 @@ 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, - self.client, - self.imgs, - self.item_imgs, - self.pulse, - &item, - self.msm, - &item_tooltip2, - ) - .set(state.ids.legs_slot, ui) + slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + .set(state.ids.legs_slot, ui) } else { slot.with_tooltip( self.tooltip_manager, i18n.get("hud.bag.legs"), "", - &item_tooltip, + &tooltip, color::WHITE, ) .set(state.ids.legs_slot, ui) @@ -1022,23 +944,14 @@ 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, - self.client, - self.imgs, - self.item_imgs, - self.pulse, - &item, - self.msm, - &item_tooltip2, - ) - .set(state.ids.ring1_slot, ui) + slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + .set(state.ids.ring1_slot, ui) } else { slot.with_tooltip( self.tooltip_manager, i18n.get("hud.bag.ring"), "", - &item_tooltip, + &tooltip, color::WHITE, ) .set(state.ids.ring1_slot, ui) @@ -1053,23 +966,14 @@ 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, - self.client, - self.imgs, - self.item_imgs, - self.pulse, - &item, - self.msm, - &item_tooltip2, - ) - .set(state.ids.ring2_slot, ui) + slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + .set(state.ids.ring2_slot, ui) } else { slot.with_tooltip( self.tooltip_manager, i18n.get("hud.bag.ring"), "", - &item_tooltip, + &tooltip, color::WHITE, ) .set(state.ids.ring2_slot, ui) @@ -1084,23 +988,14 @@ 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, - self.client, - self.imgs, - self.item_imgs, - self.pulse, - &item, - self.msm, - &item_tooltip2, - ) - .set(state.ids.back_slot, ui) + slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + .set(state.ids.back_slot, ui) } else { slot.with_tooltip( self.tooltip_manager, i18n.get("hud.bag.back"), "", - &item_tooltip, + &tooltip, color::WHITE, ) .set(state.ids.back_slot, ui) @@ -1115,23 +1010,14 @@ 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, - self.client, - self.imgs, - self.item_imgs, - self.pulse, - &item, - self.msm, - &item_tooltip2, - ) - .set(state.ids.feet_slot, ui) + slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + .set(state.ids.feet_slot, ui) } else { slot.with_tooltip( self.tooltip_manager, i18n.get("hud.bag.feet"), "", - &item_tooltip, + &tooltip, color::WHITE, ) .set(state.ids.feet_slot, ui) @@ -1146,23 +1032,14 @@ 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, - self.client, - self.imgs, - self.item_imgs, - self.pulse, - &item, - self.msm, - &item_tooltip2, - ) - .set(state.ids.lantern_slot, ui) + slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + .set(state.ids.lantern_slot, ui) } else { slot.with_tooltip( self.tooltip_manager, i18n.get("hud.bag.lantern"), "", - &item_tooltip, + &tooltip, color::WHITE, ) .set(state.ids.lantern_slot, ui) @@ -1177,23 +1054,14 @@ 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, - self.client, - self.imgs, - self.item_imgs, - self.pulse, - &item, - self.msm, - &item_tooltip2, - ) - .set(state.ids.glider_slot, ui) + slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + .set(state.ids.glider_slot, ui) } else { slot.with_tooltip( self.tooltip_manager, i18n.get("hud.bag.glider"), "", - &item_tooltip, + &tooltip, color::WHITE, ) .set(state.ids.glider_slot, ui) @@ -1208,23 +1076,14 @@ 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, - self.client, - self.imgs, - self.item_imgs, - self.pulse, - &item, - self.msm, - &item_tooltip2, - ) - .set(state.ids.tabard_slot, ui) + slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + .set(state.ids.tabard_slot, ui) } else { slot.with_tooltip( self.tooltip_manager, i18n.get("hud.bag.tabard"), "", - &item_tooltip, + &tooltip, color::WHITE, ) .set(state.ids.tabard_slot, ui) @@ -1240,23 +1099,14 @@ 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, - self.client, - self.imgs, - self.item_imgs, - self.pulse, - &item, - self.msm, - &item_tooltip2, - ) - .set(state.ids.mainhand_slot, ui) + slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + .set(state.ids.mainhand_slot, ui) } else { slot.with_tooltip( self.tooltip_manager, i18n.get("hud.bag.mainhand"), "", - &item_tooltip, + &tooltip, color::WHITE, ) .set(state.ids.mainhand_slot, ui) @@ -1271,23 +1121,14 @@ 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, - self.client, - self.imgs, - self.item_imgs, - self.pulse, - &item, - self.msm, - &item_tooltip2, - ) - .set(state.ids.offhand_slot, ui) + slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + .set(state.ids.offhand_slot, ui) } else { slot.with_tooltip( self.tooltip_manager, i18n.get("hud.bag.offhand"), "", - &item_tooltip, + &tooltip, color::WHITE, ) .set(state.ids.offhand_slot, ui) @@ -1307,23 +1148,14 @@ 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, - self.client, - self.imgs, - self.item_imgs, - self.pulse, - &item, - self.msm, - &item_tooltip2, - ) - .set(state.ids.bag1_slot, ui) + slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + .set(state.ids.bag1_slot, ui) } else { slot.with_tooltip( self.tooltip_manager, i18n.get("hud.bag.bag"), "", - &item_tooltip, + &tooltip, color::WHITE, ) .set(state.ids.bag1_slot, ui) @@ -1338,23 +1170,14 @@ 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, - self.client, - self.imgs, - self.item_imgs, - self.pulse, - &item, - self.msm, - &item_tooltip2, - ) - .set(state.ids.bag2_slot, ui) + slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + .set(state.ids.bag2_slot, ui) } else { slot.with_tooltip( self.tooltip_manager, i18n.get("hud.bag.bag"), "", - &item_tooltip, + &tooltip, color::WHITE, ) .set(state.ids.bag2_slot, ui) @@ -1369,23 +1192,14 @@ 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, - self.client, - self.imgs, - self.item_imgs, - self.pulse, - &item, - self.msm, - &item_tooltip2, - ) - .set(state.ids.bag3_slot, ui) + slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + .set(state.ids.bag3_slot, ui) } else { slot.with_tooltip( self.tooltip_manager, i18n.get("hud.bag.bag"), "", - &item_tooltip, + &tooltip, color::WHITE, ) .set(state.ids.bag3_slot, ui) @@ -1400,23 +1214,14 @@ 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, - self.client, - self.imgs, - self.item_imgs, - self.pulse, - &item, - self.msm, - &item_tooltip2, - ) - .set(state.ids.bag4_slot, ui) + slot.with_item_tooltip(self.item_tooltip_manager, &item, None, &item_tooltip) + .set(state.ids.bag4_slot, ui) } else { slot.with_tooltip( self.tooltip_manager, i18n.get("hud.bag.bag"), "", - &item_tooltip, + &tooltip, color::WHITE, ) .set(state.ids.bag4_slot, ui) diff --git a/voxygen/src/hud/crafting.rs b/voxygen/src/hud/crafting.rs index 1fe0f5d1c1..12f620d6b5 100644 --- a/voxygen/src/hud/crafting.rs +++ b/voxygen/src/hud/crafting.rs @@ -5,10 +5,7 @@ use super::{ }; use crate::{ i18n::Localization, - ui::{ - fonts::Fonts, ImageFrame, ItemTooltip, ItemTooltipManager, ItemTooltipable, Tooltip, - TooltipManager, - }, + ui::{fonts::Fonts, ImageFrame, ItemTooltip, ItemTooltipManager, ItemTooltipable}, }; use client::{self, Client}; use common::{ @@ -67,7 +64,6 @@ pub struct Crafting<'a> { localized_strings: &'a Localization, pulse: f32, rot_imgs: &'a ImgsRot, - tooltip_manager: &'a mut TooltipManager, item_tooltip_manager: &'a mut ItemTooltipManager, item_imgs: &'a ItemImgs, inventory: &'a Inventory, @@ -84,7 +80,6 @@ impl<'a> Crafting<'a> { localized_strings: &'a Localization, pulse: f32, rot_imgs: &'a ImgsRot, - tooltip_manager: &'a mut TooltipManager, item_tooltip_manager: &'a mut ItemTooltipManager, item_imgs: &'a ItemImgs, inventory: &'a Inventory, @@ -97,7 +92,6 @@ impl<'a> Crafting<'a> { localized_strings, pulse, rot_imgs, - tooltip_manager, item_tooltip_manager, item_imgs, inventory, @@ -143,24 +137,7 @@ impl<'a> Widget for Crafting<'a> { let mut events = Vec::new(); // Tooltips - let item_tooltip = Tooltip::new({ - let edge = &self.rot_imgs.tt_side; - let corner = &self.rot_imgs.tt_corner; - ImageFrame::new( - [edge.cw180, edge.none, edge.cw270, edge.cw90], - [corner.none, corner.cw270, corner.cw90, corner.cw180], - Color::Rgba(0.08, 0.07, 0.04, 1.0), - 5.0, - ) - }) - .title_font_size(self.fonts.cyri.scale(15)) - .parent(ui.window) - .desc_font_size(self.fonts.cyri.scale(12)) - .font_id(self.fonts.cyri.conrod_id) - .desc_text_color(TEXT_COLOR); - - // Tooltips - let item_tooltip2 = ItemTooltip::new( + let item_tooltip = ItemTooltip::new( { // Edge images [t, b, r, l] // Corner images [tr, tl, br, bl] @@ -348,13 +325,9 @@ impl<'a> Widget for Crafting<'a> { .middle_of(state.ids.output_img_frame) .with_item_tooltip( self.item_tooltip_manager, - self.client, - self.imgs, - self.item_imgs, - self.pulse, &*recipe.output.0, - self.msm, - &item_tooltip2, + None, + &item_tooltip, ) .set(state.ids.output_img, ui); } @@ -529,16 +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, - self.client, - self.imgs, - self.item_imgs, - self.pulse, - &*item_def, - self.msm, - &item_tooltip2, - ) + .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/mod.rs b/voxygen/src/hud/mod.rs index 828cbaa136..bdf815d855 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -906,7 +906,6 @@ impl Hud { let mut events = std::mem::replace(&mut self.events, Vec::new()); let (ref mut ui_widgets, ref mut item_tooltip_manager, ref mut tooltip_manager) = &mut self.ui.set_widgets(); - //let (ref mut ui_item_widgets, ref mut item_tooltip_manager) = &mut // self.ui.set_item_widgets(); pulse time for pulsating elements self.pulse = self.pulse + dt.as_secs_f32(); // FPS @@ -2308,7 +2307,6 @@ impl Hud { &self.item_imgs, &self.fonts, &self.rot_imgs, - tooltip_manager, item_tooltip_manager, &mut self.slot_manager, i18n, @@ -2374,7 +2372,6 @@ impl Hud { i18n, self.pulse, &self.rot_imgs, - tooltip_manager, item_tooltip_manager, &self.item_imgs, &inventory, diff --git a/voxygen/src/hud/skillbar.rs b/voxygen/src/hud/skillbar.rs index 96144dc56d..f90dc830cd 100644 --- a/voxygen/src/hud/skillbar.rs +++ b/voxygen/src/hud/skillbar.rs @@ -473,7 +473,9 @@ impl<'a> Widget for Skillbar<'a> { slot_manager: Some(self.slot_manager), pulse: self.pulse, }; - let item_tooltip = Tooltip::new({ + + // Tooltips + let tooltip = Tooltip::new({ // Edge images [t, b, r, l] // Corner images [tr, tl, br, bl] let edge = &self.rot_imgs.tt_side; @@ -491,7 +493,7 @@ impl<'a> Widget for Skillbar<'a> { .font_id(self.fonts.cyri.conrod_id) .desc_text_color(TEXT_COLOR); - let item_tooltip2 = ItemTooltip::new( + let item_tooltip = ItemTooltip::new( { // Edge images [t, b, r, l] // Corner images [tr, tl, br, bl] @@ -522,7 +524,7 @@ impl<'a> Widget for Skillbar<'a> { .0 .get(slot) .and_then(|content| match content { - hotbar::SlotContents::Inventory(i) => content_source.1.get(i).map(|item| item), + hotbar::SlotContents::Inventory(i) => content_source.1.get(i), _ => None, }) }; @@ -589,19 +591,10 @@ 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, - self.client, - self.imgs, - self.item_imgs, - self.pulse, - item, - self.msm, - &item_tooltip2, - ) - .set(state.ids.slot1, ui); + 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, &item_tooltip, TEXT_COLOR) + slot.with_tooltip(self.tooltip_manager, title, desc, &tooltip, TEXT_COLOR) .set(state.ids.slot1, ui); } else { slot.set(state.ids.slot1, ui); @@ -612,19 +605,10 @@ 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, - self.client, - self.imgs, - self.item_imgs, - self.pulse, - item, - self.msm, - &item_tooltip2, - ) - .set(state.ids.slot2, ui); + 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, &item_tooltip, TEXT_COLOR) + slot.with_tooltip(self.tooltip_manager, title, desc, &tooltip, TEXT_COLOR) .set(state.ids.slot2, ui); } else { slot.set(state.ids.slot2, ui); @@ -635,19 +619,10 @@ 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, - self.client, - self.imgs, - self.item_imgs, - self.pulse, - item, - self.msm, - &item_tooltip2, - ) - .set(state.ids.slot3, ui); + 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, &item_tooltip, TEXT_COLOR) + slot.with_tooltip(self.tooltip_manager, title, desc, &tooltip, TEXT_COLOR) .set(state.ids.slot3, ui); } else { slot.set(state.ids.slot3, ui); @@ -658,19 +633,10 @@ 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, - self.client, - self.imgs, - self.item_imgs, - self.pulse, - item, - self.msm, - &item_tooltip2, - ) - .set(state.ids.slot4, ui); + 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, &item_tooltip, TEXT_COLOR) + slot.with_tooltip(self.tooltip_manager, title, desc, &tooltip, TEXT_COLOR) .set(state.ids.slot4, ui); } else { slot.set(state.ids.slot4, ui); @@ -681,19 +647,10 @@ 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, - self.client, - self.imgs, - self.item_imgs, - self.pulse, - item, - self.msm, - &item_tooltip2, - ) - .set(state.ids.slot5, ui); + 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, &item_tooltip, TEXT_COLOR) + slot.with_tooltip(self.tooltip_manager, title, desc, &tooltip, TEXT_COLOR) .set(state.ids.slot5, ui); } else { slot.set(state.ids.slot5, ui); @@ -797,19 +754,10 @@ 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, - self.client, - self.imgs, - self.item_imgs, - self.pulse, - item, - self.msm, - &item_tooltip2, - ) - .set(state.ids.slot6, ui); + 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, &item_tooltip, TEXT_COLOR) + slot.with_tooltip(self.tooltip_manager, title, desc, &tooltip, TEXT_COLOR) .set(state.ids.slot6, ui); } else { slot.set(state.ids.slot6, ui); @@ -820,19 +768,10 @@ 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, - self.client, - self.imgs, - self.item_imgs, - self.pulse, - item, - self.msm, - &item_tooltip2, - ) - .set(state.ids.slot7, ui); + 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, &item_tooltip, TEXT_COLOR) + slot.with_tooltip(self.tooltip_manager, title, desc, &tooltip, TEXT_COLOR) .set(state.ids.slot7, ui); } else { slot.set(state.ids.slot7, ui); @@ -843,19 +782,10 @@ 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, - self.client, - self.imgs, - self.item_imgs, - self.pulse, - item, - self.msm, - &item_tooltip2, - ) - .set(state.ids.slot8, ui); + 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, &item_tooltip, TEXT_COLOR) + slot.with_tooltip(self.tooltip_manager, title, desc, &tooltip, TEXT_COLOR) .set(state.ids.slot8, ui); } else { slot.set(state.ids.slot8, ui); @@ -866,19 +796,10 @@ 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, - self.client, - self.imgs, - self.item_imgs, - self.pulse, - item, - self.msm, - &item_tooltip2, - ) - .set(state.ids.slot9, ui); + 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, &item_tooltip, TEXT_COLOR) + slot.with_tooltip(self.tooltip_manager, title, desc, &tooltip, TEXT_COLOR) .set(state.ids.slot9, ui); } else { slot.set(state.ids.slot9, ui); @@ -891,7 +812,7 @@ impl<'a> Widget for Skillbar<'a> { .filled_slot(self.imgs.skillbar_slot) .right_from(state.ids.slot9, slot_offset); if let Some((title, desc)) = tooltip_text(hotbar::Slot::Ten) { - slot.with_tooltip(self.tooltip_manager, title, desc, &item_tooltip, TEXT_COLOR) + slot.with_tooltip(self.tooltip_manager, title, desc, &tooltip, TEXT_COLOR) .set(state.ids.slot10, ui); } else { slot.set(state.ids.slot10, ui); diff --git a/voxygen/src/hud/trade.rs b/voxygen/src/hud/trade.rs index 17de53c7b6..04af1189bc 100644 --- a/voxygen/src/hud/trade.rs +++ b/voxygen/src/hud/trade.rs @@ -10,7 +10,7 @@ use crate::{ ui::{ fonts::Fonts, slot::{ContentSize, SlotMaker}, - ImageFrame, ItemTooltip, ItemTooltipManager, ItemTooltipable, Tooltip, TooltipManager, + ImageFrame, ItemTooltip, ItemTooltipManager, ItemTooltipable, }, }; use client::Client; @@ -62,7 +62,6 @@ pub struct Trade<'a> { item_imgs: &'a ItemImgs, fonts: &'a Fonts, rot_imgs: &'a ImgsRot, - tooltip_manager: &'a mut TooltipManager, item_tooltip_manager: &'a mut ItemTooltipManager, #[conrod(common_builder)] common: widget::CommonBuilder, @@ -79,7 +78,6 @@ impl<'a> Trade<'a> { item_imgs: &'a ItemImgs, fonts: &'a Fonts, rot_imgs: &'a ImgsRot, - tooltip_manager: &'a mut TooltipManager, item_tooltip_manager: &'a mut ItemTooltipManager, slot_manager: &'a mut SlotManager, localized_strings: &'a Localization, @@ -92,7 +90,6 @@ impl<'a> Trade<'a> { item_imgs, fonts, rot_imgs, - tooltip_manager, item_tooltip_manager, common: widget::CommonBuilder::default(), slot_manager, @@ -266,26 +263,8 @@ impl<'a> Trade<'a> { prices: &'a Option, tradeslots: &[TradeSlot], ) { - let item_tooltip = Tooltip::new({ - // Edge images [t, b, r, l] - // Corner images [tr, tl, br, bl] - let edge = &self.rot_imgs.tt_side; - let corner = &self.rot_imgs.tt_corner; - ImageFrame::new( - [edge.cw180, edge.none, edge.cw270, edge.cw90], - [corner.none, corner.cw270, corner.cw90, corner.cw180], - Color::Rgba(0.08, 0.07, 0.04, 1.0), - 5.0, - ) - }) - .title_font_size(self.fonts.cyri.scale(15)) - .parent(ui.window) - .desc_font_size(self.fonts.cyri.scale(12)) - .font_id(self.fonts.cyri.conrod_id) - .desc_text_color(TEXT_COLOR); - // Tooltips - let item_tooltip2 = ItemTooltip::new( + let item_tooltip = ItemTooltip::new( { // Edge images [t, b, r, l] // Corner images [tr, tl, br, bl] @@ -317,17 +296,14 @@ impl<'a> Trade<'a> { self.imgs, self.item_imgs, self.fonts, - self.tooltip_manager, self.item_tooltip_manager, self.slot_manager, self.pulse, self.localized_strings, false, true, - self.msm, false, &item_tooltip, - &item_tooltip2, name, false, &inventory, @@ -395,20 +371,12 @@ impl<'a> Trade<'a> { Quality::Artifact => self.imgs.inv_slot_orange, _ => self.imgs.inv_slot_red, }; - let mut desc = desc.to_string(); - super::util::append_price_desc(&mut desc, prices, item.item_definition_id()); + 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, - self.client, - self.imgs, - self.item_imgs, - self.pulse, - item, - self.msm, - &item_tooltip2, - ) + .with_item_tooltip(self.item_tooltip_manager, item, prices_info, &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 401ab9923b..a928c52cb3 100644 --- a/voxygen/src/hud/util.rs +++ b/voxygen/src/hud/util.rs @@ -4,104 +4,41 @@ use common::{ item::{ armor::{Armor, ArmorKind, Protection}, tool::{Hands, StatKind, Stats, Tool, ToolKind}, - Item, ItemDesc, ItemKind, MaterialStatManifest, ModularComponent, + Item, ItemKind, MaterialStatManifest, ModularComponent, }, BuffKind, }, effect::Effect, trade::{Good, SitePrices}, }; -use std::{borrow::Cow, fmt::Write}; +use std::fmt::Write; use crate::i18n::Localization; -pub fn loadout_slot_text<'a>( - item: Option<&'a impl ItemDesc>, - mut empty: impl FnMut() -> (&'a str, &'a str), - msm: &'a MaterialStatManifest, - i18n: &'a Localization, -) -> (&'a str, Cow<'a, str>) { - item.map_or_else( - || { - let (title, desc) = empty(); - (title, Cow::Borrowed(desc)) - }, - |item| item_text(item, msm, i18n), - ) -} - -pub fn item_text<'a>( - item: &'a dyn ItemDesc, - msm: &'a MaterialStatManifest, - i18n: &'a Localization, -) -> (&'a str, Cow<'a, str>) { - let desc: Cow = match item.kind() { - ItemKind::Armor(armor) => Cow::Owned(armor_desc( - armor, - item.description(), - item.num_slots(), - i18n, - )), - ItemKind::Tool(tool) => Cow::Owned(tool_desc( - &tool, - item.components(), - &msm, - item.description(), - i18n, - )), - ItemKind::ModularComponent(mc) => Cow::Owned(modular_component_desc( - mc, - item.components(), - &msm, - item.description(), - )), - ItemKind::Glider(_glider) => Cow::Owned(generic_desc(item, i18n)), - ItemKind::Consumable { effect, .. } => Cow::Owned(consumable_desc(effect, i18n)), - ItemKind::Throwable { .. } => Cow::Owned(generic_desc(item, i18n)), - ItemKind::Utility { .. } => Cow::Owned(generic_desc(item, i18n)), - ItemKind::Ingredient { .. } => Cow::Owned(ingredient_desc( - item.description(), - item.item_definition_id(), - msm, - )), - ItemKind::Lantern { .. } => Cow::Owned(generic_desc(item, i18n)), - ItemKind::TagExamples { .. } => Cow::Borrowed(item.description()), - //_ => Cow::Borrowed(item.description()), - }; - - (item.name(), desc) -} - -pub fn append_price_desc(desc: &mut String, prices: &Option, item_definition_id: &str) { +pub fn price_desc( + prices: &Option, + item_definition_id: &str, + i18n: &Localization, +) -> Option { 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(); - *desc += &format!( - "\n\nBuy price: {:0.1} coins\nSell price: {:0.1} coins", + Some(format!( + "{} : {:0.1} {}\n{} : {:0.1} {}", + i18n.get("hud.trade.buy_price").to_string(), buyprice / coinprice, - sellprice / coinprice - ); + i18n.get("hud.trade.coin").to_string(), + i18n.get("hud.trade.sell_price").to_string(), + sellprice / coinprice, + i18n.get("hud.trade.coin").to_string(), + )) + } else { + None } } -fn use_text(kind: &ItemKind) -> String { - let text = match kind { - ItemKind::Armor(_) - | ItemKind::Tool(_) - | ItemKind::ModularComponent(_) - | ItemKind::Glider(_) - | ItemKind::Consumable { .. } - | ItemKind::Utility { .. } - | ItemKind::Ingredient { .. } - | ItemKind::Lantern { .. } => "", - ItemKind::Throwable { .. } => "", - ItemKind::TagExamples { .. } => "", - }; - text.to_string() -} - pub fn kind_text(kind: &ItemKind, i18n: &Localization) -> String { match kind { ItemKind::Armor(armor) => armor_kind(&armor, &i18n), @@ -119,17 +56,8 @@ pub fn kind_text(kind: &ItemKind, i18n: &Localization) -> String { } } -fn generic_desc(desc: &dyn ItemDesc, i18n: &Localization) -> String { - format!( - "{}\n\n{}\n\n{}", - kind_text(desc.kind(), i18n), - desc.description(), - use_text(desc.kind()) - ) -} - // TODO: localization -fn modular_component_desc( +pub fn modular_component_desc( mc: &ModularComponent, components: &[Item], msm: &MaterialStatManifest, @@ -206,15 +134,6 @@ pub fn consumable_desc(effects: &[Effect], i18n: &Localization) -> String { description } -fn ingredient_desc(desc: &str, item_id: &str, msm: &MaterialStatManifest) -> String { - let mut result = format!("Crafting Ingredient\n\n{}", desc); - if let Some(stats) = msm.0.get(item_id) { - result += "\n\nStat multipliers:\n"; - result += &statblock_desc(stats); - } - result -} - // Armor fn armor_kind(armor: &Armor, i18n: &Localization) -> String { let kind = match armor.kind { @@ -234,42 +153,9 @@ fn armor_kind(armor: &Armor, i18n: &Localization) -> String { kind.to_string() } -fn armor_protection(armor: &Armor) -> String { - match armor.get_protection() { - Protection::Normal(a) => format!("Protection: {}", a.to_string()), - Protection::Invincible => "Protection: Inf".to_string(), - } -} - -pub fn armor_desc(armor: &Armor, desc: &str, slots: u16, i18n: &Localization) -> String { - // TODO: localization - let kind = armor_kind(armor, i18n); - let armor_protection = armor_protection(armor); - //let armor_poise_resilience = match armor.get_poise_resilience() { - // Protection::Normal(a) => a.to_string(), - // Protection::Invincible => "Inf".to_string(), - //}; - - let mut desctext: String = "".to_string(); - if !desc.is_empty() { - desctext = desc.to_string(); - } - - let mut slottext: String = "".to_string(); - if slots > 0 { - slottext = format!("Slots: {}", slots) - } - - let usetext = use_text(&ItemKind::Armor(armor.clone())); - format!( - "{} {}\n\n{}\n{}\n{}", - kind, armor_protection, slottext, desctext, usetext - ) -} - //Tool -pub fn tool_kind(tool: &Tool, i18n: &Localization) -> String { +fn tool_kind(tool: &Tool, i18n: &Localization) -> String { let kind = match tool.kind { ToolKind::Sword => i18n.get("common.weapons.sword"), ToolKind::Axe => i18n.get("common.weapons.axe"), @@ -294,11 +180,6 @@ pub fn tool_kind(tool: &Tool, i18n: &Localization) -> String { kind.to_string() } -pub fn tool_stats(tool: &Tool, components: &[Item], msm: &MaterialStatManifest) -> String { - let stats = tool.stats.resolve_stats(msm, components).clamp_speed(); - statblock_desc(&stats) -} - pub fn tool_hands(tool: &Tool, i18n: &Localization) -> String { let hands = match tool.hands { Hands::One => i18n.get("common.hands.one"), @@ -307,41 +188,6 @@ pub fn tool_hands(tool: &Tool, i18n: &Localization) -> String { hands.to_string() } -fn components_list(components: &[Item]) -> String { - let mut text: String = "Made from:\n".to_string(); - for component in components { - text += component.name(); - text += "\n" - } - text -} - -pub fn tool_desc( - tool: &Tool, - components: &[Item], - msm: &MaterialStatManifest, - desc: &str, - i18n: &Localization, -) -> String { - let kind = tool_kind(tool, i18n); - //let poise_strength = tool.base_poise_strength(); - let hands = tool_hands(tool, i18n); - let stats = tool_stats(tool, components, msm); - let usetext = use_text(&ItemKind::Tool(tool.clone())); - let mut componentstext: String = "".to_string(); - if !components.is_empty() { - componentstext = components_list(components); - } - let mut desctext: String = "".to_string(); - if !desc.is_empty() { - desctext = desc.to_string(); - } - format!( - "{} {}\n\n{}\n{}\n{}\n{}", - hands, kind, stats, componentstext, desctext, usetext - ) -} - fn statblock_desc(stats: &Stats) -> String { format!( "Power: {:0.1}\n\nPoise Strength: {:0.1}\n\nSpeed: {:0.1}\n\n", @@ -372,88 +218,3 @@ pub fn protec2string(stat: Protection) -> String { Protection::Invincible => "Inf".to_string(), } } - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_glider_desc() { - let item_description = "mushrooms"; - - assert_eq!( - "Glider\n\nmushrooms\n\n", - glider_desc(item_description) - ); - } - - #[test] - fn test_consumable_desc() { - let item_description = "mushrooms"; - - assert_eq!( - "Consumable\n\nmushrooms\n\n", - consumable_desc(&[], item_description) - ); - } - - #[test] - fn test_throwable_desc() { - let item_description = "mushrooms"; - - assert_eq!( - "Can be thrown\n\nmushrooms\n\n", - throwable_desc(item_description) - ); - } - - #[test] - fn test_utility_desc() { - let item_description = "mushrooms"; - - assert_eq!( - "mushrooms\n\n", - utility_desc(item_description) - ); - } - - #[test] - fn test_ingredient_desc() { - let mut testmsm = MaterialStatManifest(hashbrown::HashMap::new()); - testmsm.0.insert( - "common.items.crafting_ing.bronze_ingot".to_string(), - Stats { - equip_time_secs: 0.0, - power: 3.0, - poise_strength: 5.0, - speed: 7.0, - crit_chance: 0.5, - crit_mult: 2.0, - }, - ); - - assert_eq!( - "Crafting Ingredient\n\nmushrooms", - ingredient_desc("mushrooms", "common.items.food.mushroom", &testmsm) - ); - assert_eq!( - "Crafting Ingredient\n\nA bronze ingot.\n\nStat multipliers:\nPower: 30.0\n\nPoise \ - Strength: 50.0\n\nSpeed: 7.0\n\nCrit chance: 50.0%\n\nCrit damage: x2.0\n\n", - ingredient_desc( - "A bronze ingot.", - "common.items.crafting_ing.bronze_ingot", - &testmsm - ) - ); - } - - #[test] - fn test_lantern_desc() { - let item_description = "mushrooms"; - - assert_eq!( - "Lantern\n\nmushrooms\n\n", - lantern_desc(item_description) - ); - } -} diff --git a/voxygen/src/ui/widgets/item_tooltip.rs b/voxygen/src/ui/widgets/item_tooltip.rs index fc8b3774e8..efdecdc753 100644 --- a/voxygen/src/ui/widgets/item_tooltip.rs +++ b/voxygen/src/ui/widgets/item_tooltip.rs @@ -14,8 +14,8 @@ use common::comp::item::{ }; use conrod_core::{ builder_method, builder_methods, image, input::global::Global, position::Dimension, text, - widget, widget_ids, Color, Colorable, FontSize, Positionable, Sizeable, Ui, UiCell, Widget, - WidgetCommon, WidgetStyle, + widget, widget_ids, Color, Colorable, FontSize, Positionable, Scalar, Sizeable, Ui, UiCell, + Widget, WidgetCommon, WidgetStyle, }; use lazy_static::lazy_static; use std::time::{Duration, Instant}; @@ -109,6 +109,7 @@ impl ItemTooltipManager { &mut self, tooltip: &ItemTooltip, item: &dyn ItemDesc, + extra: Option, img_id: Option, image_dims: Option<(f64, f64)>, src_id: widget::Id, @@ -123,6 +124,7 @@ impl ItemTooltipManager { let tooltip = tooltip .clone() .item(item) + .extra(extra) .image(img_id) .image_dims(image_dims); @@ -170,12 +172,9 @@ impl ItemTooltipManager { pub struct ItemTooltipped<'a, W> { inner: W, tooltip_manager: &'a mut ItemTooltipManager, - client: &'a Client, - imgs: &'a Imgs, - item_imgs: &'a ItemImgs, - pulse: f32, + item: &'a dyn ItemDesc, - msm: &'a MaterialStatManifest, + extra: Option, img_id: Option, image_dims: Option<(f64, f64)>, tooltip: &'a ItemTooltip<'a>, @@ -196,6 +195,7 @@ impl<'a, W: Widget> ItemTooltipped<'a, W> { self.tooltip_manager.set_tooltip( self.tooltip, self.item, + self.extra, self.img_id, self.image_dims, id, @@ -210,12 +210,11 @@ pub trait ItemTooltipable { fn with_item_tooltip<'a>( self, tooltip_manager: &'a mut ItemTooltipManager, - client: &'a Client, - imgs: &'a Imgs, - item_imgs: &'a ItemImgs, - pulse: f32, + item: &'a dyn ItemDesc, - msm: &'a MaterialStatManifest, + + extra: Option, + tooltip: &'a ItemTooltip<'a>, ) -> ItemTooltipped<'a, Self> where @@ -225,23 +224,15 @@ impl ItemTooltipable for W { fn with_item_tooltip<'a>( self, tooltip_manager: &'a mut ItemTooltipManager, - client: &'a Client, - imgs: &'a Imgs, - item_imgs: &'a ItemImgs, - pulse: f32, item: &'a dyn ItemDesc, - msm: &'a MaterialStatManifest, + extra: Option, tooltip: &'a ItemTooltip<'a>, ) -> ItemTooltipped<'a, W> { ItemTooltipped { inner: self, tooltip_manager, - client, - imgs, - item_imgs, - pulse, item, - msm, + extra, img_id: None, image_dims: None, tooltip, @@ -257,10 +248,6 @@ const H_PAD: f64 = 10.0; const V_PAD_STATS: f64 = 6.0; /// Default portion of inner width that goes to an image const IMAGE_W_FRAC: f64 = 0.3; -/// Default width multiplied by the description font size -const DEFAULT_CHAR_W: f64 = 20.0; -/// Text vertical spacing factor to account for overhanging text -const TEXT_SPACE_FACTOR: f64 = 0.35; // Item icon size const ICON_SIZE: [f64; 2] = [64.0, 64.0]; @@ -271,6 +258,7 @@ pub struct ItemTooltip<'a> { common: widget::CommonBuilder, item: &'a dyn ItemDesc, msm: &'a MaterialStatManifest, + extra: Option, image: Option, image_dims: Option<(f64, f64)>, style: Style, @@ -297,6 +285,7 @@ widget_ids! { title, subtitle, desc, + extra, main_stat, main_stat_text, stats[], @@ -325,8 +314,11 @@ impl<'a> ItemTooltip<'a> { pub desc_font_size { style.desc.font_size = Some(FontSize) } pub title_justify { style.title.justify = Some(text::Justify) } pub desc_justify { style.desc.justify = Some(text::Justify) } + pub title_line_spacing { style.title.line_spacing = Some(Scalar) } + pub desc_line_spacing { style.desc.line_spacing = Some(Scalar) } image { image = Option } item { item = &'a dyn ItemDesc } + extra { extra = Option } msm { msm = &'a MaterialStatManifest } image_dims { image_dims = Option<(f64, f64)> } transparency { transparency = f32 } @@ -346,6 +338,7 @@ impl<'a> ItemTooltip<'a> { style: Style::default(), item: &*EMPTY_ITEM, msm, + extra: None, transparency: 1.0, image_frame, image: None, @@ -422,7 +415,6 @@ impl<'a> Widget for ItemTooltip<'a> { id, state, rect, - style, ui, .. } = args; @@ -463,9 +455,6 @@ impl<'a> Widget for ItemTooltip<'a> { // Widths let (text_w, image_w) = self.text_image_width(rect.w()); - // Apply transparency - let color = style.color(ui.theme()).alpha(self.transparency); - // Color quality let quality_col_img = match &item.quality() { Quality::Low => self.imgs.inv_slot_grey, @@ -478,9 +467,7 @@ impl<'a> Widget for ItemTooltip<'a> { _ => self.imgs.inv_slot_red, }; - // Spacing for overhanging text - let title_space = self.style.title.font_size(&ui.theme) as f64 * TEXT_SPACE_FACTOR; - + // Update windget array size state.update(|s| { s.ids .stats @@ -573,7 +560,7 @@ impl<'a> Widget for ItemTooltip<'a> { .color(text_color) .font_size(34) .align_middle_y_of(state.ids.item_frame) - .right_from(state.ids.item_frame, V_PAD) + .right_from(state.ids.item_frame, H_PAD) .set(state.ids.main_stat, ui); widget::Text::new(i18n.get("common.stats.dps")) @@ -582,12 +569,12 @@ impl<'a> Widget for ItemTooltip<'a> { .with_style(self.style.desc) .color(text_color) .align_bottom_of(state.ids.main_stat) - .right_from(state.ids.main_stat, V_PAD) + .right_from(state.ids.main_stat, H_PAD) .set(state.ids.main_stat_text, ui); // Power widget::Text::new(&format!( - "- {} : {:.1}", + "{} : {:.1}", i18n.get("common.stats.power"), power )) @@ -601,7 +588,7 @@ impl<'a> Widget for ItemTooltip<'a> { // Speed widget::Text::new(&format!( - "- {} : {:.1}", + "{} : {:.1}", i18n.get("common.stats.speed"), speed )) @@ -614,7 +601,7 @@ impl<'a> Widget for ItemTooltip<'a> { // Poise widget::Text::new(&format!( - "- {} : {:.1}", + "{} : {:.1}", i18n.get("common.stats.poise"), poise_str )) @@ -627,7 +614,7 @@ impl<'a> Widget for ItemTooltip<'a> { // Crit chance widget::Text::new(&format!( - "- {} : {:.1}%", + "{} : {:.1}%", i18n.get("common.stats.crit_chance"), crit_chance )) @@ -640,7 +627,7 @@ impl<'a> Widget for ItemTooltip<'a> { // Crit mult widget::Text::new(&format!( - "- {} : x{:.1}", + "{} : x{:.1}", i18n.get("common.stats.crit_mult"), crit_mult )) @@ -681,7 +668,7 @@ impl<'a> Widget for ItemTooltip<'a> { if equipped_dps - dps != 0.0 { widget::Text::new(&diff_main_stat.0) - .right_from(state.ids.main_stat_text, 5.0) + .right_from(state.ids.main_stat_text, H_PAD) .graphics_for(id) .parent(id) .with_style(self.style.desc) @@ -696,7 +683,7 @@ impl<'a> Widget for ItemTooltip<'a> { &diff.power * 10.0 )) .align_middle_y_of(state.ids.stats[0]) - .right_from(state.ids.stats[0], 10.0) + .right_from(state.ids.stats[0], H_PAD) .graphics_for(id) .parent(id) .with_style(self.style.desc) @@ -706,7 +693,7 @@ impl<'a> Widget for ItemTooltip<'a> { if diff.speed != 0.0 { widget::Text::new(&format!("{} {:.1}", &speed_diff.0, &diff.speed)) .align_middle_y_of(state.ids.stats[1]) - .right_from(state.ids.stats[1], 10.0) + .right_from(state.ids.stats[1], H_PAD) .graphics_for(id) .parent(id) .with_style(self.style.desc) @@ -720,7 +707,7 @@ impl<'a> Widget for ItemTooltip<'a> { &diff.poise_strength * 10.0 )) .align_middle_y_of(state.ids.stats[2]) - .right_from(state.ids.stats[2], 10.0) + .right_from(state.ids.stats[2], H_PAD) .graphics_for(id) .parent(id) .with_style(self.style.desc) @@ -734,7 +721,7 @@ impl<'a> Widget for ItemTooltip<'a> { &diff.crit_chance * 100.0 )) .align_middle_y_of(state.ids.stats[3]) - .right_from(state.ids.stats[3], 10.0) + .right_from(state.ids.stats[3], H_PAD) .graphics_for(id) .parent(id) .with_style(self.style.desc) @@ -747,7 +734,7 @@ impl<'a> Widget for ItemTooltip<'a> { &crit_mult_diff.0, &diff.crit_mult )) .align_middle_y_of(state.ids.stats[4]) - .right_from(state.ids.stats[4], 10.0) + .right_from(state.ids.stats[4], H_PAD) .graphics_for(id) .parent(id) .with_style(self.style.desc) @@ -761,16 +748,6 @@ impl<'a> Widget for ItemTooltip<'a> { let protection = armor.get_protection(); let poise_res = armor.get_poise_resilience(); - /*// Armour - widget::Text::new(&format!("- Armour : {}", util::protec2string(protection))) - .x_align_to(state.ids.item_frame, conrod_core::position::Align::Start) - .graphics_for(id) - .parent(id) - .with_style(self.style.desc) - .color(text_color) - .down_from(state.ids.item_frame, V_PAD) - .set(state.ids.stat1, ui);*/ - // Armour widget::Text::new(&util::protec2string(protection)) .graphics_for(id) @@ -779,7 +756,7 @@ impl<'a> Widget for ItemTooltip<'a> { .color(text_color) .font_size(34) .align_middle_y_of(state.ids.item_frame) - .right_from(state.ids.item_frame, V_PAD) + .right_from(state.ids.item_frame, H_PAD) .set(state.ids.main_stat, ui); widget::Text::new(i18n.get("common.stats.armor")) @@ -788,12 +765,12 @@ impl<'a> Widget for ItemTooltip<'a> { .with_style(self.style.desc) .color(text_color) .align_bottom_of(state.ids.main_stat) - .right_from(state.ids.main_stat, V_PAD) + .right_from(state.ids.main_stat, H_PAD) .set(state.ids.main_stat_text, ui); // Poise res widget::Text::new(&format!( - "- {} : {}", + "{} : {}", i18n.get("common.stats.poise_res"), util::protec2string(poise_res) )) @@ -808,7 +785,7 @@ impl<'a> Widget for ItemTooltip<'a> { // Slots if item.num_slots() > 0 { widget::Text::new(&format!( - "- {} : {}", + "{} : {}", i18n.get("common.stats.slots"), item.num_slots() )) @@ -835,7 +812,7 @@ impl<'a> Widget for ItemTooltip<'a> { if diff.get_protection() != Protection::Normal(0.0) { widget::Text::new(&protection_diff.0) - .right_from(state.ids.main_stat_text, 5.0) + .right_from(state.ids.main_stat_text, H_PAD) .graphics_for(id) .parent(id) .with_style(self.style.desc) @@ -843,21 +820,6 @@ impl<'a> Widget for ItemTooltip<'a> { .set(state.ids.diff_main_stat, ui); } - /*if diff.protection != Protection::Normal(0.0) { - widget::Text::new(&format!( - "{} {}", - &diff1.0, - util::protec2string(diff.protection) - )) - .align_middle_y_of(state.ids.stat1) - .right_from(state.ids.stat1, 10.0) - .graphics_for(id) - .parent(id) - .with_style(self.style.desc) - .color(diff1.1) - .set(state.ids.diff1, ui); - }*/ - if diff.get_poise_resilience() != Protection::Normal(0.0) { widget::Text::new(&format!( "{} {}", @@ -865,7 +827,7 @@ impl<'a> Widget for ItemTooltip<'a> { util::protec2string(diff.get_poise_resilience()) )) .align_middle_y_of(state.ids.stats[0]) - .right_from(state.ids.stats[0], 10.0) + .right_from(state.ids.stats[0], H_PAD) .graphics_for(id) .parent(id) .with_style(self.style.desc) @@ -885,11 +847,27 @@ impl<'a> Widget for ItemTooltip<'a> { .down_from(state.ids.item_frame, V_PAD) .set(state.ids.stats[0], ui); }, + ItemKind::ModularComponent(mc) => { + widget::Text::new(&util::modular_component_desc( + mc, + item.components(), + &self.msm, + item.description(), + )) + .x_align_to(state.ids.item_frame, conrod_core::position::Align::Start) + .graphics_for(id) + .parent(id) + .with_style(self.style.desc) + .color(text_color) + .down_from(state.ids.item_frame, V_PAD) + .set(state.ids.stats[0], ui); + }, _ => (), } + // Description if !desc.is_empty() { - widget::Text::new(&desc) + widget::Text::new(&format!("\"{}\"", &desc)) .x_align_to(state.ids.item_frame, conrod_core::position::Align::Start) .graphics_for(id) .parent(id) @@ -906,6 +884,27 @@ impl<'a> Widget for ItemTooltip<'a> { .w(text_w) .set(state.ids.desc, ui); } + + // Extra text + if let Some(extra) = self.extra { + widget::Text::new(&extra) + .x_align_to(state.ids.item_frame, conrod_core::position::Align::Start) + .graphics_for(id) + .parent(id) + .with_style(self.style.desc) + .down_from( + if !desc.is_empty() { + state.ids.desc + } else if stats_count(item) > 0 { + state.ids.stats[state.ids.stats.len() - 1] + } else { + state.ids.item_frame + }, + V_PAD, + ) + .w(text_w) + .set(state.ids.extra, ui); + } } /// Default width is based on the description font size unless the text is @@ -914,57 +913,74 @@ impl<'a> Widget for ItemTooltip<'a> { fn default_y_dimension(&self, ui: &Ui) -> Dimension { fn stats_count(item: &dyn ItemDesc) -> usize { - let mut count: usize = match item.kind() { + let mut count = match item.kind() { ItemKind::Armor(_) => 1, ItemKind::Tool(_) => 5, ItemKind::Consumable { .. } => 1, + ItemKind::ModularComponent { .. } => 1, _ => 0, }; if item.num_slots() != 0 { count += 1 } - count + count as usize } let item = &self.item; let (title, desc) = (item.name().to_string(), item.description().to_string()); - let (text_w, _image_w) = self.text_image_width(280.0); + let (text_w, _image_w) = self.text_image_width(260.0); + // Title let title_h = widget::Text::new(&title) .w(text_w) .with_style(self.style.title) .get_h(ui) - .unwrap_or(0.0); + .unwrap_or(0.0) + + V_PAD; // Item frame - let frame_h = ICON_SIZE[1]; + let frame_h = ICON_SIZE[1] + V_PAD; - // Stat - let stat_h = widget::Text::new(&"placeholder".to_string()) - .with_style(self.style.desc) - .get_h(ui) - .unwrap_or(0.0); - - // Description - let desc_h: f64 = if !desc.is_empty() { - widget::Text::new(&desc) + // Stats + let stat_h = if stats_count(self.item) > 0 { + widget::Text::new(&"placeholder".to_string()) .with_style(self.style.desc) - .color(conrod_core::color::GREY) - .w(text_w) .get_h(ui) .unwrap_or(0.0) + * stats_count(self.item) as f64 + + (stats_count(self.item) - 1) as f64 * V_PAD_STATS + + V_PAD } else { 0.0 }; - let height = title_h - + frame_h - + stat_h * stats_count(self.item) as f64 - + desc_h - + V_PAD * 5.0 - + V_PAD_STATS * stats_count(self.item) as f64; + // Description + let desc_h: f64 = if !desc.is_empty() { + widget::Text::new(&format!("\"{}\"", &desc)) + .with_style(self.style.desc) + .w(text_w) + .get_h(ui) + .unwrap_or(0.0) + + V_PAD + } else { + 0.0 + }; + + // Price + let price_h: f64 = if let Some(extra) = &self.extra { + widget::Text::new(&extra) + .with_style(self.style.desc) + .w(text_w) + .get_h(ui) + .unwrap_or(0.0) + + V_PAD + } else { + 0.0 + }; + + let height = title_h + frame_h + stat_h + desc_h + price_h + V_PAD + 5.0; // extra padding to fit frame top padding Dimension::Absolute(height) } }