mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Tooltip now use ItemDesc instead of Item
This commit is contained in:
parent
2c09180189
commit
d1e734b9b1
@ -728,3 +728,21 @@ pub struct ItemDrop(pub Item);
|
||||
impl Component for ItemDrop {
|
||||
type Storage = IdvStorage<Self>;
|
||||
}
|
||||
|
||||
impl<'a, T: ItemDesc + ?Sized> ItemDesc for &'a T {
|
||||
fn description(&self) -> &str { (*self).description() }
|
||||
|
||||
fn name(&self) -> &str { (*self).name() }
|
||||
|
||||
fn kind(&self) -> &ItemKind { (*self).kind() }
|
||||
|
||||
fn quality(&self) -> &Quality { (*self).quality() }
|
||||
|
||||
fn num_slots(&self) -> u16 { (*self).num_slots() }
|
||||
|
||||
fn item_definition_id(&self) -> &str { (*self).item_definition_id() }
|
||||
|
||||
fn components(&self) -> &[Item] { (*self).components() }
|
||||
|
||||
fn tags(&self) -> &[ItemTag] { (*self).tags() }
|
||||
}
|
||||
|
@ -324,7 +324,7 @@ impl<'a> InventoryScroller<'a> {
|
||||
self.imgs,
|
||||
self.item_imgs,
|
||||
self.pulse,
|
||||
&item.clone(),
|
||||
item,
|
||||
self.msm,
|
||||
self.item_tooltip2,
|
||||
)
|
||||
|
@ -6,7 +6,10 @@ use super::{
|
||||
use crate::{
|
||||
hud::get_quality_col,
|
||||
i18n::Localization,
|
||||
ui::{fonts::Fonts, ImageFrame, Tooltip, TooltipManager, Tooltipable},
|
||||
ui::{
|
||||
fonts::Fonts, ImageFrame, ItemTooltip, ItemTooltipManager, ItemTooltipable, Tooltip,
|
||||
TooltipManager, Tooltipable,
|
||||
},
|
||||
};
|
||||
use client::{self, Client};
|
||||
use common::{
|
||||
@ -66,6 +69,7 @@ pub struct Crafting<'a> {
|
||||
pulse: f32,
|
||||
rot_imgs: &'a ImgsRot,
|
||||
tooltip_manager: &'a mut TooltipManager,
|
||||
item_tooltip_manager: &'a mut ItemTooltipManager,
|
||||
item_imgs: &'a ItemImgs,
|
||||
inventory: &'a Inventory,
|
||||
msm: &'a MaterialStatManifest,
|
||||
@ -82,6 +86,7 @@ impl<'a> Crafting<'a> {
|
||||
pulse: f32,
|
||||
rot_imgs: &'a ImgsRot,
|
||||
tooltip_manager: &'a mut TooltipManager,
|
||||
item_tooltip_manager: &'a mut ItemTooltipManager,
|
||||
item_imgs: &'a ItemImgs,
|
||||
inventory: &'a Inventory,
|
||||
msm: &'a MaterialStatManifest,
|
||||
@ -94,6 +99,7 @@ impl<'a> Crafting<'a> {
|
||||
pulse,
|
||||
rot_imgs,
|
||||
tooltip_manager,
|
||||
item_tooltip_manager,
|
||||
item_imgs,
|
||||
inventory,
|
||||
msm,
|
||||
@ -154,6 +160,32 @@ impl<'a> Widget for Crafting<'a> {
|
||||
.font_id(self.fonts.cyri.conrod_id)
|
||||
.desc_text_color(TEXT_COLOR);
|
||||
|
||||
// Tooltips
|
||||
let item_tooltip2 = ItemTooltip::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,
|
||||
)
|
||||
},
|
||||
self.client,
|
||||
self.imgs,
|
||||
self.item_imgs,
|
||||
self.pulse,
|
||||
self.msm,
|
||||
)
|
||||
.title_font_size(self.fonts.cyri.scale(20))
|
||||
.parent(ui.window)
|
||||
.desc_font_size(self.fonts.cyri.scale(12))
|
||||
.font_id(self.fonts.cyri.conrod_id)
|
||||
.desc_text_color(TEXT_COLOR);
|
||||
|
||||
Image::new(self.imgs.crafting_window)
|
||||
.bottom_right_with_margins_on(ui.window, 308.0, 450.0)
|
||||
.color(Some(UI_MAIN))
|
||||
@ -316,12 +348,15 @@ impl<'a> Widget for Crafting<'a> {
|
||||
.label_y(conrod_core::position::Relative::Scalar(-24.0))
|
||||
.label_x(conrod_core::position::Relative::Scalar(24.0))
|
||||
.middle_of(state.ids.output_img_frame)
|
||||
.with_tooltip(
|
||||
self.tooltip_manager,
|
||||
title,
|
||||
&*desc,
|
||||
&item_tooltip,
|
||||
quality_col,
|
||||
.with_item_tooltip(
|
||||
self.item_tooltip_manager,
|
||||
self.client,
|
||||
self.imgs,
|
||||
self.item_imgs,
|
||||
self.pulse,
|
||||
&*recipe.output.0,
|
||||
self.msm,
|
||||
&item_tooltip2,
|
||||
)
|
||||
.set(state.ids.output_img, ui);
|
||||
}
|
||||
@ -498,12 +533,15 @@ impl<'a> Widget for Crafting<'a> {
|
||||
))
|
||||
.w_h(22.0, 22.0)
|
||||
.middle_of(state.ids.ingredient_frame[i])
|
||||
.with_tooltip(
|
||||
self.tooltip_manager,
|
||||
title,
|
||||
&*desc,
|
||||
&item_tooltip,
|
||||
quality_col,
|
||||
.with_item_tooltip(
|
||||
self.item_tooltip_manager,
|
||||
self.client,
|
||||
self.imgs,
|
||||
self.item_imgs,
|
||||
self.pulse,
|
||||
&*item_def,
|
||||
self.msm,
|
||||
&item_tooltip2,
|
||||
)
|
||||
.set(state.ids.ingredient_img[i], ui);
|
||||
// Ingredients text and amount
|
||||
|
@ -2374,6 +2374,7 @@ impl Hud {
|
||||
self.pulse,
|
||||
&self.rot_imgs,
|
||||
tooltip_manager,
|
||||
item_tooltip_manager,
|
||||
&self.item_imgs,
|
||||
&inventory,
|
||||
&msm,
|
||||
@ -3333,7 +3334,7 @@ impl Hud {
|
||||
}
|
||||
}
|
||||
// Get item qualities of equipped items and assign a tooltip title/frame color
|
||||
pub fn get_quality_col<I: ItemDesc>(item: &I) -> Color {
|
||||
pub fn get_quality_col<I: ItemDesc + ?Sized>(item: &I) -> Color {
|
||||
match item.quality() {
|
||||
Quality::Low => QUALITY_LOW,
|
||||
Quality::Common => QUALITY_COMMON,
|
||||
|
@ -11,7 +11,8 @@ use crate::{
|
||||
ui::{
|
||||
fonts::Fonts,
|
||||
slot::{ContentSize, SlotMaker},
|
||||
ImageFrame, ItemTooltip, ItemTooltipManager, Tooltip, TooltipManager, Tooltipable,
|
||||
ImageFrame, ItemTooltip, ItemTooltipManager, ItemTooltipable, Tooltip, TooltipManager,
|
||||
Tooltipable,
|
||||
},
|
||||
};
|
||||
use client::Client;
|
||||
@ -305,7 +306,7 @@ impl<'a> Trade<'a> {
|
||||
self.pulse,
|
||||
self.msm,
|
||||
)
|
||||
.title_font_size(self.fonts.cyri.scale(15))
|
||||
.title_font_size(self.fonts.cyri.scale(20))
|
||||
.parent(ui.window)
|
||||
.desc_font_size(self.fonts.cyri.scale(12))
|
||||
.font_id(self.fonts.cyri.conrod_id)
|
||||
@ -401,12 +402,15 @@ impl<'a> Trade<'a> {
|
||||
super::util::append_price_desc(&mut desc, prices, item.item_definition_id());
|
||||
slot_widget
|
||||
.filled_slot(quality_col_img)
|
||||
.with_tooltip(
|
||||
self.tooltip_manager,
|
||||
title,
|
||||
&*desc,
|
||||
&item_tooltip,
|
||||
quality_col,
|
||||
.with_item_tooltip(
|
||||
self.item_tooltip_manager,
|
||||
self.client,
|
||||
self.imgs,
|
||||
self.item_imgs,
|
||||
self.pulse,
|
||||
item,
|
||||
self.msm,
|
||||
&item_tooltip2,
|
||||
)
|
||||
.set(slot_id, ui);
|
||||
} else {
|
||||
|
@ -14,6 +14,7 @@ use conrod_core::{
|
||||
widget, widget_ids, Color, Colorable, FontSize, Positionable, Sizeable, Ui, UiCell, Widget,
|
||||
WidgetCommon, WidgetStyle,
|
||||
};
|
||||
use lazy_static::lazy_static;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
@ -104,7 +105,7 @@ impl ItemTooltipManager {
|
||||
fn set_tooltip(
|
||||
&mut self,
|
||||
tooltip: &ItemTooltip,
|
||||
item: &Item,
|
||||
item: &dyn ItemDesc,
|
||||
img_id: Option<image::Id>,
|
||||
image_dims: Option<(f64, f64)>,
|
||||
src_id: widget::Id,
|
||||
@ -118,7 +119,7 @@ impl ItemTooltipManager {
|
||||
// spacing
|
||||
let tooltip = tooltip
|
||||
.clone()
|
||||
.item(item.clone())
|
||||
.item(item)
|
||||
.image(img_id)
|
||||
.image_dims(image_dims);
|
||||
|
||||
@ -170,7 +171,7 @@ pub struct ItemTooltipped<'a, W> {
|
||||
imgs: &'a Imgs,
|
||||
item_imgs: &'a ItemImgs,
|
||||
pulse: f32,
|
||||
item: &'a Item,
|
||||
item: &'a dyn ItemDesc,
|
||||
msm: &'a MaterialStatManifest,
|
||||
img_id: Option<image::Id>,
|
||||
image_dims: Option<(f64, f64)>,
|
||||
@ -191,7 +192,7 @@ impl<'a, W: Widget> ItemTooltipped<'a, W> {
|
||||
let event = self.inner.set(id, ui);
|
||||
self.tooltip_manager.set_tooltip(
|
||||
self.tooltip,
|
||||
&self.item,
|
||||
self.item,
|
||||
self.img_id,
|
||||
self.image_dims,
|
||||
id,
|
||||
@ -210,7 +211,7 @@ pub trait ItemTooltipable {
|
||||
imgs: &'a Imgs,
|
||||
item_imgs: &'a ItemImgs,
|
||||
pulse: f32,
|
||||
item: &'a Item,
|
||||
item: &'a dyn ItemDesc,
|
||||
msm: &'a MaterialStatManifest,
|
||||
tooltip: &'a ItemTooltip<'a>,
|
||||
) -> ItemTooltipped<'a, Self>
|
||||
@ -225,7 +226,7 @@ impl<W: Widget> ItemTooltipable for W {
|
||||
imgs: &'a Imgs,
|
||||
item_imgs: &'a ItemImgs,
|
||||
pulse: f32,
|
||||
item: &'a Item,
|
||||
item: &'a dyn ItemDesc,
|
||||
msm: &'a MaterialStatManifest,
|
||||
tooltip: &'a ItemTooltip<'a>,
|
||||
) -> ItemTooltipped<'a, W> {
|
||||
@ -265,7 +266,7 @@ const ICON_SIZE: [f64; 2] = [64.0, 64.0];
|
||||
pub struct ItemTooltip<'a> {
|
||||
#[conrod(common_builder)]
|
||||
common: widget::CommonBuilder,
|
||||
item: Item,
|
||||
item: &'a dyn ItemDesc,
|
||||
msm: &'a MaterialStatManifest,
|
||||
image: Option<image::Id>,
|
||||
image_dims: Option<(f64, f64)>,
|
||||
@ -309,6 +310,10 @@ pub struct State {
|
||||
ids: Ids,
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref EMPTY_ITEM: Item = Item::new_from_asset_expect("common.items.weapons.empty.empty");
|
||||
}
|
||||
|
||||
impl<'a> ItemTooltip<'a> {
|
||||
builder_methods! {
|
||||
pub desc_text_color { style.desc.color = Some(Color) }
|
||||
@ -317,7 +322,7 @@ impl<'a> ItemTooltip<'a> {
|
||||
pub title_justify { style.title.justify = Some(text::Justify) }
|
||||
pub desc_justify { style.desc.justify = Some(text::Justify) }
|
||||
image { image = Option<image::Id> }
|
||||
item { item = Item }
|
||||
item { item = &'a dyn ItemDesc }
|
||||
msm { msm = &'a MaterialStatManifest }
|
||||
image_dims { image_dims = Option<(f64, f64)> }
|
||||
transparency { transparency = f32 }
|
||||
@ -334,7 +339,7 @@ impl<'a> ItemTooltip<'a> {
|
||||
ItemTooltip {
|
||||
common: widget::CommonBuilder::default(),
|
||||
style: Style::default(),
|
||||
item: Item::new_from_asset_expect("common.items.weapons.empty.empty"),
|
||||
item: &*EMPTY_ITEM,
|
||||
msm,
|
||||
transparency: 1.0,
|
||||
image_frame,
|
||||
@ -416,7 +421,7 @@ impl<'a> Widget for ItemTooltip<'a> {
|
||||
..
|
||||
} = args;
|
||||
|
||||
fn stats_count(item: &Item) -> usize {
|
||||
fn stats_count(item: &dyn ItemDesc) -> usize {
|
||||
let mut count = match item.kind() {
|
||||
ItemKind::Armor(_) => 1,
|
||||
ItemKind::Tool(_) => 5,
|
||||
@ -435,7 +440,7 @@ impl<'a> Widget for ItemTooltip<'a> {
|
||||
None => return,
|
||||
};
|
||||
|
||||
let item = &self.item;
|
||||
let item = self.item;
|
||||
|
||||
let quality = get_quality_col(item);
|
||||
|
||||
@ -471,13 +476,13 @@ impl<'a> Widget for ItemTooltip<'a> {
|
||||
state.update(|s| {
|
||||
s.ids
|
||||
.stats
|
||||
.resize(stats_count(&item), &mut ui.widget_id_generator())
|
||||
.resize(stats_count(item), &mut ui.widget_id_generator())
|
||||
});
|
||||
|
||||
state.update(|s| {
|
||||
s.ids
|
||||
.diffs
|
||||
.resize(stats_count(&item), &mut ui.widget_id_generator())
|
||||
.resize(stats_count(item), &mut ui.widget_id_generator())
|
||||
});
|
||||
|
||||
// Background image frame
|
||||
@ -522,7 +527,9 @@ impl<'a> Widget for ItemTooltip<'a> {
|
||||
|
||||
// Item render
|
||||
widget::Image::new(animate_by_pulse(
|
||||
&self.item_imgs.img_ids_or_not_found_img(ItemKey::from(item)),
|
||||
&self
|
||||
.item_imgs
|
||||
.img_ids_or_not_found_img(ItemKey::from(&item)),
|
||||
self.pulse,
|
||||
))
|
||||
.color(Some(conrod_core::color::WHITE))
|
||||
@ -854,7 +861,7 @@ impl<'a> Widget for ItemTooltip<'a> {
|
||||
.with_style(self.style.desc)
|
||||
.color(conrod_core::color::GREY)
|
||||
.down_from(
|
||||
if stats_count(&item) > 0 {
|
||||
if stats_count(item) > 0 {
|
||||
state.ids.stats[state.ids.stats.len() - 1]
|
||||
} else {
|
||||
state.ids.item_frame
|
||||
@ -871,7 +878,7 @@ impl<'a> Widget for ItemTooltip<'a> {
|
||||
fn default_x_dimension(&self, ui: &Ui) -> Dimension { Dimension::Absolute(260.0) }
|
||||
|
||||
fn default_y_dimension(&self, ui: &Ui) -> Dimension {
|
||||
fn stats_count(item: &Item) -> usize {
|
||||
fn stats_count(item: &dyn ItemDesc) -> usize {
|
||||
let mut count: usize = match item.kind() {
|
||||
ItemKind::Armor(_) => 2,
|
||||
ItemKind::Tool(_) => 5,
|
||||
@ -920,14 +927,14 @@ impl<'a> Widget for ItemTooltip<'a> {
|
||||
|
||||
dbg!(title_h);
|
||||
dbg!(frame_h);
|
||||
dbg!(stat_h * stats_count(&self.item) as f64);
|
||||
dbg!(stat_h * stats_count(self.item) as f64);
|
||||
dbg!(desc_h);
|
||||
let height = title_h
|
||||
+ frame_h
|
||||
+ stat_h * stats_count(&self.item) as f64
|
||||
+ stat_h * stats_count(self.item) as f64
|
||||
+ desc_h
|
||||
+ V_PAD * 5.0
|
||||
+ V_PAD_STATS * stats_count(&self.item) as f64;
|
||||
+ V_PAD_STATS * stats_count(self.item) as f64;
|
||||
Dimension::Absolute(height)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user