mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Changed tooltips to take iterator. Tooltips also show original item as well as salvage output.
This commit is contained in:
parent
154dec2b4f
commit
430c34b462
@ -21,7 +21,7 @@ use common::{
|
||||
combat::{combat_rating, Damage},
|
||||
comp::{
|
||||
inventory::InventorySortOrder,
|
||||
item::{Item, ItemDef, ItemDesc, MaterialStatManifest, Quality},
|
||||
item::{ItemDef, ItemDesc, MaterialStatManifest, Quality},
|
||||
Body, Energy, Health, Inventory, Poise, SkillSet, Stats,
|
||||
},
|
||||
};
|
||||
@ -34,7 +34,7 @@ use i18n::Localization;
|
||||
|
||||
use crate::hud::slots::SlotKind;
|
||||
use specs::Entity as EcsEntity;
|
||||
use std::sync::Arc;
|
||||
use std::{borrow::Borrow, sync::Arc};
|
||||
use vek::Vec2;
|
||||
|
||||
widget_ids! {
|
||||
@ -383,29 +383,40 @@ impl<'a> InventoryScroller<'a> {
|
||||
.as_ref()
|
||||
.and_then(|(_, _, prices)| prices.clone());
|
||||
|
||||
let salvage_result: Vec<Item> = item
|
||||
.salvage_output()
|
||||
.map(|asset| Item::new_from_asset_expect(asset))
|
||||
.collect();
|
||||
if self.show_salvage && item.is_salvageable() {
|
||||
let salvage_result: Vec<_> = item
|
||||
.salvage_output()
|
||||
.map(|asset| Arc::<ItemDef>::load_expect_cloned(asset))
|
||||
.map(|item| item as Arc<dyn ItemDesc>)
|
||||
.collect();
|
||||
|
||||
let item: Vec<&dyn ItemDesc> = if self.show_salvage {
|
||||
salvage_result
|
||||
// let items = core::iter::once(item as &dyn ItemDesc)
|
||||
// .chain(salvage_result.iter().map(|item| item.borrow()));
|
||||
let items = salvage_result
|
||||
.iter()
|
||||
.map(|item| item as &dyn ItemDesc)
|
||||
.collect()
|
||||
} else {
|
||||
vec![item]
|
||||
};
|
||||
.map(|item| item.borrow())
|
||||
.chain(core::iter::once(item as &dyn ItemDesc));
|
||||
|
||||
slot_widget
|
||||
.filled_slot(quality_col_img)
|
||||
.with_item_tooltip(
|
||||
self.item_tooltip_manager,
|
||||
item,
|
||||
&prices_info,
|
||||
self.item_tooltip,
|
||||
)
|
||||
.set(state.ids.inv_slots[i], ui);
|
||||
slot_widget
|
||||
.filled_slot(quality_col_img)
|
||||
.with_item_tooltip(
|
||||
self.item_tooltip_manager,
|
||||
items,
|
||||
&prices_info,
|
||||
self.item_tooltip,
|
||||
)
|
||||
.set(state.ids.inv_slots[i], ui);
|
||||
} else {
|
||||
slot_widget
|
||||
.filled_slot(quality_col_img)
|
||||
.with_item_tooltip(
|
||||
self.item_tooltip_manager,
|
||||
core::iter::once(item as &dyn ItemDesc),
|
||||
&prices_info,
|
||||
self.item_tooltip,
|
||||
)
|
||||
.set(state.ids.inv_slots[i], ui);
|
||||
}
|
||||
} else {
|
||||
slot_widget.set(state.ids.inv_slots[i], ui);
|
||||
}
|
||||
@ -865,7 +876,12 @@ impl<'a> Widget for Bag<'a> {
|
||||
if let Some(item) = inventory.equipped($slot) {
|
||||
let manager = &mut *self.item_tooltip_manager;
|
||||
$slot_maker
|
||||
.with_item_tooltip(manager, vec![item], &None, &item_tooltip)
|
||||
.with_item_tooltip(
|
||||
manager,
|
||||
core::iter::once(item as &dyn ItemDesc),
|
||||
&None,
|
||||
&item_tooltip,
|
||||
)
|
||||
.set($slot_id, ui)
|
||||
} else {
|
||||
let manager = &mut *self.tooltip_manager;
|
||||
|
@ -724,7 +724,7 @@ impl<'a> Widget for Crafting<'a> {
|
||||
.middle_of(state.ids.output_img_frame)
|
||||
.with_item_tooltip(
|
||||
self.item_tooltip_manager,
|
||||
vec![&*recipe.output.0],
|
||||
core::iter::once(&*recipe.output.0 as &dyn ItemDesc),
|
||||
&None,
|
||||
&item_tooltip,
|
||||
)
|
||||
@ -970,7 +970,7 @@ impl<'a> Widget for Crafting<'a> {
|
||||
.graphics_for(state.ids.ingredient_btn[i])
|
||||
.with_item_tooltip(
|
||||
self.item_tooltip_manager,
|
||||
vec![&*item_def],
|
||||
core::iter::once(&*item_def as &dyn ItemDesc),
|
||||
&None,
|
||||
&item_tooltip,
|
||||
)
|
||||
|
@ -6,7 +6,7 @@ use super::{
|
||||
};
|
||||
use crate::ui::{fonts::Fonts, ImageFrame, ItemTooltip, ItemTooltipManager, ItemTooltipable};
|
||||
use client::Client;
|
||||
use common::comp::inventory::item::{ItemDef, MaterialStatManifest, Quality};
|
||||
use common::comp::inventory::item::{ItemDef, ItemDesc, MaterialStatManifest, Quality};
|
||||
use conrod_core::{
|
||||
color,
|
||||
position::Dimension,
|
||||
@ -335,7 +335,7 @@ impl<'a> Widget for LootScroller<'a> {
|
||||
.middle_of(state.ids.message_icon_bgs[i])
|
||||
.with_item_tooltip(
|
||||
self.item_tooltip_manager,
|
||||
vec![&**item],
|
||||
core::iter::once(&**item as &dyn ItemDesc),
|
||||
&None,
|
||||
&item_tooltip,
|
||||
)
|
||||
|
@ -728,7 +728,8 @@ impl Show {
|
||||
self.selected_crafting_tab(tab);
|
||||
self.crafting(true);
|
||||
self.craft_sprite = self.craft_sprite.or(craft_sprite);
|
||||
self.salvage = matches!(craft_sprite, Some((_, SpriteKind::SalvagingBench)));
|
||||
self.salvage = matches!(self.craft_sprite, Some((_, SpriteKind::SalvagingBench)))
|
||||
&& matches!(tab, CraftingTab::Dismantle);
|
||||
}
|
||||
|
||||
fn diary(&mut self, open: bool) {
|
||||
|
@ -24,7 +24,7 @@ use common::comp::{
|
||||
inventory::slot::EquipSlot,
|
||||
item::{
|
||||
tool::{Tool, ToolKind},
|
||||
Hands, Item, ItemKind, MaterialStatManifest,
|
||||
Hands, Item, ItemDesc, ItemKind, MaterialStatManifest,
|
||||
},
|
||||
Energy, Health, Inventory, SkillSet,
|
||||
};
|
||||
@ -645,8 +645,13 @@ impl<'a> Skillbar<'a> {
|
||||
.position(entry.position);
|
||||
// if there is an item attached, show item tooltip
|
||||
if let Some(item) = slot_content(entry.slot) {
|
||||
slot.with_item_tooltip(self.item_tooltip_manager, vec![item], &None, &item_tooltip)
|
||||
.set(entry.widget_id, ui);
|
||||
slot.with_item_tooltip(
|
||||
self.item_tooltip_manager,
|
||||
core::iter::once(item as &dyn ItemDesc),
|
||||
&None,
|
||||
&item_tooltip,
|
||||
)
|
||||
.set(entry.widget_id, ui);
|
||||
// if we can gather some text to display, show it
|
||||
} else if let Some((title, desc)) = tooltip_text(entry.slot) {
|
||||
slot.with_tooltip(self.tooltip_manager, title, desc, &tooltip, TEXT_COLOR)
|
||||
|
@ -10,7 +10,7 @@ use vek::*;
|
||||
use client::Client;
|
||||
use common::{
|
||||
comp::{
|
||||
inventory::item::{MaterialStatManifest, Quality},
|
||||
inventory::item::{ItemDesc, MaterialStatManifest, Quality},
|
||||
Inventory, Stats,
|
||||
},
|
||||
trade::{PendingTrade, SitePrices, TradeAction, TradePhase},
|
||||
@ -393,7 +393,12 @@ impl<'a> Trade<'a> {
|
||||
|
||||
slot_widget
|
||||
.filled_slot(quality_col_img)
|
||||
.with_item_tooltip(self.item_tooltip_manager, vec![item], prices, &item_tooltip)
|
||||
.with_item_tooltip(
|
||||
self.item_tooltip_manager,
|
||||
core::iter::once(item as &dyn ItemDesc),
|
||||
prices,
|
||||
&item_tooltip,
|
||||
)
|
||||
.set(slot_id, ui);
|
||||
} else {
|
||||
slot_widget.set(slot_id, ui);
|
||||
|
@ -24,7 +24,10 @@ use conrod_core::{
|
||||
};
|
||||
use i18n::Localization;
|
||||
use lazy_static::lazy_static;
|
||||
use std::time::{Duration, Instant};
|
||||
use std::{
|
||||
borrow::Borrow,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
struct Hover(widget::Id, [f64; 2]);
|
||||
@ -105,16 +108,18 @@ impl ItemTooltipManager {
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)] // TODO: Pending review in #587
|
||||
fn set_tooltip(
|
||||
fn set_tooltip<'a, I>(
|
||||
&mut self,
|
||||
tooltip: &ItemTooltip,
|
||||
items: Vec<&dyn ItemDesc>,
|
||||
prices: &Option<SitePrices>,
|
||||
tooltip: &'a ItemTooltip,
|
||||
items: impl Iterator<Item = I>,
|
||||
prices: &'a Option<SitePrices>,
|
||||
img_id: Option<image::Id>,
|
||||
image_dims: Option<(f64, f64)>,
|
||||
src_id: widget::Id,
|
||||
ui: &mut UiCell,
|
||||
) {
|
||||
) where
|
||||
I: Borrow<dyn ItemDesc>,
|
||||
{
|
||||
let mut y_offset = 0.0;
|
||||
let mp_h = MOUSE_PAD_Y / self.logical_scale_factor;
|
||||
for item in items {
|
||||
@ -125,7 +130,7 @@ impl ItemTooltipManager {
|
||||
// spacing
|
||||
let tooltip = tooltip
|
||||
.clone()
|
||||
.item(item)
|
||||
.item(item.borrow())
|
||||
.prices(prices)
|
||||
.image(img_id)
|
||||
.image_dims(image_dims);
|
||||
@ -178,17 +183,18 @@ impl ItemTooltipManager {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ItemTooltipped<'a, W> {
|
||||
pub struct ItemTooltipped<'a, W, I> {
|
||||
inner: W,
|
||||
tooltip_manager: &'a mut ItemTooltipManager,
|
||||
|
||||
items: Vec<&'a dyn ItemDesc>,
|
||||
items: I,
|
||||
prices: &'a Option<SitePrices>,
|
||||
img_id: Option<image::Id>,
|
||||
image_dims: Option<(f64, f64)>,
|
||||
tooltip: &'a ItemTooltip<'a>,
|
||||
}
|
||||
impl<'a, W: Widget> ItemTooltipped<'a, W> {
|
||||
|
||||
impl<'a, W: Widget, I: Iterator> ItemTooltipped<'a, W, I> {
|
||||
pub fn tooltip_image(mut self, img_id: image::Id) -> Self {
|
||||
self.img_id = Some(img_id);
|
||||
self
|
||||
@ -199,7 +205,10 @@ impl<'a, W: Widget> ItemTooltipped<'a, W> {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set(self, id: widget::Id, ui: &mut UiCell) -> W::Event {
|
||||
pub fn set(self, id: widget::Id, ui: &mut UiCell) -> W::Event
|
||||
where
|
||||
<I as Iterator>::Item: Borrow<dyn ItemDesc>,
|
||||
{
|
||||
let event = self.inner.set(id, ui);
|
||||
self.tooltip_manager.set_tooltip(
|
||||
self.tooltip,
|
||||
@ -216,27 +225,27 @@ impl<'a, W: Widget> ItemTooltipped<'a, W> {
|
||||
|
||||
pub trait ItemTooltipable {
|
||||
// If `Tooltip` is expensive to construct accept a closure here instead.
|
||||
fn with_item_tooltip<'a>(
|
||||
fn with_item_tooltip<'a, I>(
|
||||
self,
|
||||
tooltip_manager: &'a mut ItemTooltipManager,
|
||||
|
||||
items: Vec<&'a dyn ItemDesc>,
|
||||
items: I,
|
||||
|
||||
prices: &'a Option<SitePrices>,
|
||||
|
||||
tooltip: &'a ItemTooltip<'a>,
|
||||
) -> ItemTooltipped<'a, Self>
|
||||
) -> ItemTooltipped<'a, Self, I>
|
||||
where
|
||||
Self: std::marker::Sized;
|
||||
}
|
||||
impl<W: Widget> ItemTooltipable for W {
|
||||
fn with_item_tooltip<'a>(
|
||||
fn with_item_tooltip<'a, I>(
|
||||
self,
|
||||
tooltip_manager: &'a mut ItemTooltipManager,
|
||||
items: Vec<&'a dyn ItemDesc>,
|
||||
items: I,
|
||||
prices: &'a Option<SitePrices>,
|
||||
tooltip: &'a ItemTooltip<'a>,
|
||||
) -> ItemTooltipped<'a, W> {
|
||||
) -> ItemTooltipped<'a, W, I> {
|
||||
ItemTooltipped {
|
||||
inner: self,
|
||||
tooltip_manager,
|
||||
|
Loading…
Reference in New Issue
Block a user