From 4669b4ab5299dcc5a9ad517bf90e9ab078c945de Mon Sep 17 00:00:00 2001 From: Avi Weinstock Date: Fri, 28 Jul 2023 11:47:05 -0400 Subject: [PATCH] Show item amounts in item tooltips. --- common/src/comp/inventory/item/mod.rs | 7 +++++++ voxygen/src/ui/widgets/item_tooltip.rs | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/common/src/comp/inventory/item/mod.rs b/common/src/comp/inventory/item/mod.rs index b42363e645..ca65c93b54 100644 --- a/common/src/comp/inventory/item/mod.rs +++ b/common/src/comp/inventory/item/mod.rs @@ -1397,6 +1397,7 @@ pub trait ItemDesc { fn description(&self) -> &str; fn name(&self) -> Cow; fn kind(&self) -> Cow; + fn amount(&self) -> NonZeroU32; fn quality(&self) -> Quality; fn num_slots(&self) -> u16; fn item_definition_id(&self) -> ItemDefinitionId<'_>; @@ -1423,6 +1424,8 @@ impl ItemDesc for Item { fn kind(&self) -> Cow { self.kind() } + fn amount(&self) -> NonZeroU32 { self.amount } + fn quality(&self) -> Quality { self.quality() } fn num_slots(&self) -> u16 { self.num_slots() } @@ -1451,6 +1454,8 @@ impl ItemDesc for ItemDef { fn kind(&self) -> Cow { Cow::Borrowed(&self.kind) } + fn amount(&self) -> NonZeroU32 { NonZeroU32::new(1).unwrap() } + fn quality(&self) -> Quality { self.quality } fn num_slots(&self) -> u16 { self.slots } @@ -1495,6 +1500,8 @@ impl<'a, T: ItemDesc + ?Sized> ItemDesc for &'a T { fn kind(&self) -> Cow { (*self).kind() } + fn amount(&self) -> NonZeroU32 { (*self).amount() } + fn quality(&self) -> Quality { (*self).quality() } fn num_slots(&self) -> u16 { (*self).num_slots() } diff --git a/voxygen/src/ui/widgets/item_tooltip.rs b/voxygen/src/ui/widgets/item_tooltip.rs index 8c6f60cbe4..91ca2e5431 100644 --- a/voxygen/src/ui/widgets/item_tooltip.rs +++ b/voxygen/src/ui/widgets/item_tooltip.rs @@ -310,6 +310,7 @@ pub struct Style { widget_ids! { struct Ids { title, + quantity, subtitle, desc, prices_buy, @@ -570,6 +571,20 @@ impl<'a> Widget for ItemTooltip<'a> { .color(quality) .set(state.ids.title, ui); + // Amount + let mut subtitle_relative_id = state.ids.title; + if self.item.amount().get() > 1 { + subtitle_relative_id = state.ids.quantity; + widget::Text::new(&format!("Amount: {}", self.item.amount().get())) + .w(title_w) + .graphics_for(id) + .parent(id) + .with_style(self.style.desc) + .color(conrod_core::color::GREY) + .down_from(state.ids.title, V_PAD) + .set(state.ids.quantity, ui); + } + // Subtitle widget::Text::new(&subtitle) .w(title_w) @@ -577,7 +592,7 @@ impl<'a> Widget for ItemTooltip<'a> { .parent(id) .with_style(self.style.desc) .color(conrod_core::color::GREY) - .down_from(state.ids.title, V_PAD) + .down_from(subtitle_relative_id, V_PAD) .set(state.ids.subtitle, ui); // Stats