Merge branch 'itemtooltip-quantity' into 'master'

Show item amounts in item tooltips.

See merge request veloren/veloren!4047
This commit is contained in:
Avi Weinstock 2023-07-28 23:00:51 +00:00
commit 15e75ebfbf
2 changed files with 25 additions and 1 deletions

View File

@ -1397,6 +1397,7 @@ pub trait ItemDesc {
fn description(&self) -> &str;
fn name(&self) -> Cow<str>;
fn kind(&self) -> Cow<ItemKind>;
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<ItemKind> { 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<ItemKind> { 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<ItemKind> { (*self).kind() }
fn amount(&self) -> NonZeroU32 { (*self).amount() }
fn quality(&self) -> Quality { (*self).quality() }
fn num_slots(&self) -> u16 { (*self).num_slots() }

View File

@ -310,6 +310,7 @@ pub struct Style {
widget_ids! {
struct Ids {
title,
quantity,
subtitle,
desc,
prices_buy,
@ -570,6 +571,22 @@ impl<'a> Widget for ItemTooltip<'a> {
.color(quality)
.set(state.ids.title, ui);
// Amount
let (subtitle_relative_id, spacing) = if self.item.amount().get() > 1 {
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, 2.0)
.set(state.ids.quantity, ui);
(state.ids.quantity, 2.0)
} else {
(state.ids.title, V_PAD)
};
// Subtitle
widget::Text::new(&subtitle)
.w(title_w)
@ -577,7 +594,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, spacing)
.set(state.ids.subtitle, ui);
// Stats