Skillbar uses item tooltip

This commit is contained in:
Snowram 2021-03-24 22:02:01 +01:00 committed by Robin Gilh
parent 508e35ca17
commit 5b99b7ca18
6 changed files with 165 additions and 31 deletions

View File

@ -6,7 +6,6 @@ use super::{
Show, CRITICAL_HP_COLOR, LOW_HP_COLOR, TEXT_COLOR, UI_HIGHLIGHT_0, UI_MAIN,
};
use crate::{
hud::get_quality_col,
i18n::Localization,
ui::{
fonts::Fonts,
@ -299,9 +298,6 @@ impl<'a> InventoryScroller<'a> {
}
if let Some(item) = item {
let (title, desc) =
super::util::item_text(item, &self.msm, &self.localized_strings);
let quality_col = get_quality_col(item);
let quality_col_img = match item.quality() {
Quality::Low => self.imgs.inv_slot_grey,
Quality::Common => self.imgs.inv_slot,

View File

@ -4,11 +4,10 @@ use super::{
TEXT_COLOR, TEXT_DULL_RED_COLOR, TEXT_GRAY_COLOR, UI_HIGHLIGHT_0, UI_MAIN,
};
use crate::{
hud::get_quality_col,
i18n::Localization,
ui::{
fonts::Fonts, ImageFrame, ItemTooltip, ItemTooltipManager, ItemTooltipable, Tooltip,
TooltipManager, Tooltipable,
TooltipManager,
},
};
use client::{self, Client};
@ -333,7 +332,6 @@ impl<'a> Widget for Crafting<'a> {
{
let output_text = format!("x{}", &recipe.output.1.to_string());
// Output Image
let quality_col = get_quality_col(&*recipe.output.0);
Button::image(animate_by_pulse(
&self
.item_imgs
@ -507,7 +505,6 @@ impl<'a> Widget for Crafting<'a> {
} else {
0.0
};
let quality_col = get_quality_col(&*item_def);
let quality_col_img = match &item_def.quality {
Quality::Low => self.imgs.inv_slot_grey,
Quality::Common => self.imgs.inv_slot,

View File

@ -2233,6 +2233,7 @@ impl Hud {
controllers.get(entity).map(|c| &c.inputs),
) {
Skillbar::new(
client,
global_state,
&self.imgs,
&self.item_imgs,

View File

@ -17,6 +17,8 @@ use crate::{
window::GameInput,
GlobalState,
};
use client::{self, Client};
use common::comp::{
self,
inventory::slot::EquipSlot,
@ -131,6 +133,7 @@ widget_ids! {
#[derive(WidgetCommon)]
pub struct Skillbar<'a> {
client: &'a Client,
global_state: &'a GlobalState,
imgs: &'a Imgs,
item_imgs: &'a ItemImgs,
@ -157,6 +160,7 @@ pub struct Skillbar<'a> {
impl<'a> Skillbar<'a> {
#[allow(clippy::too_many_arguments)] // TODO: Pending review in #587
pub fn new(
client: &'a Client,
global_state: &'a GlobalState,
imgs: &'a Imgs,
item_imgs: &'a ItemImgs,
@ -178,6 +182,7 @@ impl<'a> Skillbar<'a> {
combo: Option<ComboFloater>,
) -> Self {
Self {
client,
global_state,
imgs,
item_imgs,
@ -486,6 +491,42 @@ impl<'a> Widget for Skillbar<'a> {
.font_id(self.fonts.cyri.conrod_id)
.desc_text_color(TEXT_COLOR);
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,
self.localized_strings,
)
.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);
let slot_content = |slot| {
content_source
.0
.get(slot)
.and_then(|content| match content {
hotbar::SlotContents::Inventory(i) => content_source.1.get(i).map(|item| item),
_ => None,
})
};
// Helper
let tooltip_text = |slot| {
content_source
@ -547,7 +588,19 @@ impl<'a> Widget for Skillbar<'a> {
.fabricate(hotbar::Slot::One, [40.0; 2])
.filled_slot(self.imgs.skillbar_slot)
.bottom_left_with_margins_on(state.ids.frame, 0.0, 0.0);
if let Some((title, desc)) = tooltip_text(hotbar::Slot::One) {
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);
} else if let Some((title, desc)) = tooltip_text(hotbar::Slot::One) {
slot.with_tooltip(self.tooltip_manager, title, desc, &item_tooltip, TEXT_COLOR)
.set(state.ids.slot1, ui);
} else {
@ -558,7 +611,19 @@ impl<'a> Widget for Skillbar<'a> {
.fabricate(hotbar::Slot::Two, [40.0; 2])
.filled_slot(self.imgs.skillbar_slot)
.right_from(state.ids.slot1, slot_offset);
if let Some((title, desc)) = tooltip_text(hotbar::Slot::Two) {
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);
} else if let Some((title, desc)) = tooltip_text(hotbar::Slot::Two) {
slot.with_tooltip(self.tooltip_manager, title, desc, &item_tooltip, TEXT_COLOR)
.set(state.ids.slot2, ui);
} else {
@ -569,7 +634,19 @@ impl<'a> Widget for Skillbar<'a> {
.fabricate(hotbar::Slot::Three, [40.0; 2])
.filled_slot(self.imgs.skillbar_slot)
.right_from(state.ids.slot2, slot_offset);
if let Some((title, desc)) = tooltip_text(hotbar::Slot::Three) {
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);
} else if let Some((title, desc)) = tooltip_text(hotbar::Slot::Three) {
slot.with_tooltip(self.tooltip_manager, title, desc, &item_tooltip, TEXT_COLOR)
.set(state.ids.slot3, ui);
} else {
@ -580,7 +657,19 @@ impl<'a> Widget for Skillbar<'a> {
.fabricate(hotbar::Slot::Four, [40.0; 2])
.filled_slot(self.imgs.skillbar_slot)
.right_from(state.ids.slot3, slot_offset);
if let Some((title, desc)) = tooltip_text(hotbar::Slot::Four) {
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);
} else if let Some((title, desc)) = tooltip_text(hotbar::Slot::Four) {
slot.with_tooltip(self.tooltip_manager, title, desc, &item_tooltip, TEXT_COLOR)
.set(state.ids.slot4, ui);
} else {
@ -591,7 +680,19 @@ impl<'a> Widget for Skillbar<'a> {
.fabricate(hotbar::Slot::Five, [40.0; 2])
.filled_slot(self.imgs.skillbar_slot)
.right_from(state.ids.slot4, slot_offset);
if let Some((title, desc)) = tooltip_text(hotbar::Slot::Five) {
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);
} else if let Some((title, desc)) = tooltip_text(hotbar::Slot::Five) {
slot.with_tooltip(self.tooltip_manager, title, desc, &item_tooltip, TEXT_COLOR)
.set(state.ids.slot5, ui);
} else {
@ -695,7 +796,19 @@ impl<'a> Widget for Skillbar<'a> {
.fabricate(hotbar::Slot::Six, [40.0; 2])
.filled_slot(self.imgs.skillbar_slot)
.right_from(state.ids.m2_slot_bg, slot_offset);
if let Some((title, desc)) = tooltip_text(hotbar::Slot::Six) {
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);
} else if let Some((title, desc)) = tooltip_text(hotbar::Slot::Six) {
slot.with_tooltip(self.tooltip_manager, title, desc, &item_tooltip, TEXT_COLOR)
.set(state.ids.slot6, ui);
} else {
@ -706,7 +819,19 @@ impl<'a> Widget for Skillbar<'a> {
.fabricate(hotbar::Slot::Seven, [40.0; 2])
.filled_slot(self.imgs.skillbar_slot)
.right_from(state.ids.slot6, slot_offset);
if let Some((title, desc)) = tooltip_text(hotbar::Slot::Seven) {
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);
} else if let Some((title, desc)) = tooltip_text(hotbar::Slot::Seven) {
slot.with_tooltip(self.tooltip_manager, title, desc, &item_tooltip, TEXT_COLOR)
.set(state.ids.slot7, ui);
} else {
@ -717,7 +842,19 @@ impl<'a> Widget for Skillbar<'a> {
.fabricate(hotbar::Slot::Eight, [40.0; 2])
.filled_slot(self.imgs.skillbar_slot)
.right_from(state.ids.slot7, slot_offset);
if let Some((title, desc)) = tooltip_text(hotbar::Slot::Eight) {
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);
} else if let Some((title, desc)) = tooltip_text(hotbar::Slot::Eight) {
slot.with_tooltip(self.tooltip_manager, title, desc, &item_tooltip, TEXT_COLOR)
.set(state.ids.slot8, ui);
} else {
@ -728,7 +865,19 @@ impl<'a> Widget for Skillbar<'a> {
.fabricate(hotbar::Slot::Nine, [40.0; 2])
.filled_slot(self.imgs.skillbar_slot)
.right_from(state.ids.slot8, slot_offset);
if let Some((title, desc)) = tooltip_text(hotbar::Slot::Nine) {
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);
} else if let Some((title, desc)) = tooltip_text(hotbar::Slot::Nine) {
slot.with_tooltip(self.tooltip_manager, title, desc, &item_tooltip, TEXT_COLOR)
.set(state.ids.slot9, ui);
} else {

View File

@ -1,5 +1,4 @@
use super::{
get_quality_col,
img_ids::{Imgs, ImgsRot},
item_imgs::ItemImgs,
slots::{SlotManager, TradeSlot},
@ -12,7 +11,6 @@ use crate::{
fonts::Fonts,
slot::{ContentSize, SlotMaker},
ImageFrame, ItemTooltip, ItemTooltipManager, ItemTooltipable, Tooltip, TooltipManager,
Tooltipable,
},
};
use client::Client;
@ -387,7 +385,6 @@ impl<'a> Trade<'a> {
);
let slot_id = state.ids.inv_slots[i + who * MAX_TRADE_SLOTS];
if let Some(Some(item)) = slot.invslot.and_then(|slotid| inventory.slot(slotid)) {
let quality_col = get_quality_col(item);
let quality_col_img = match item.quality() {
Quality::Low => self.imgs.inv_slot_grey,
Quality::Common => self.imgs.inv_slot,

View File

@ -596,7 +596,7 @@ impl<'a> Widget for ItemTooltip<'a> {
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.down_from(state.ids.item_frame, V_PAD_STATS)
.down_from(state.ids.item_frame, V_PAD)
.set(state.ids.stats[0], ui);
// Speed
@ -677,8 +677,6 @@ impl<'a> Widget for ItemTooltip<'a> {
util::comparison(tool_stats.crit_mult, equipped_tool_stats.crit_mult);
let equipped_dps =
equipped_tool_stats.power * equipped_tool_stats.speed * 10.0;
dbg!(dps);
dbg!(equipped_dps);
let diff_main_stat = util::comparison(dps, equipped_dps);
if equipped_dps - dps != 0.0 {
@ -804,6 +802,7 @@ impl<'a> Widget for ItemTooltip<'a> {
.with_style(self.style.desc)
.color(text_color)
.x_align_to(state.ids.item_frame, conrod_core::position::Align::Start)
.down_from(state.ids.item_frame, V_PAD)
.set(state.ids.stats[0], ui);
// Slots
@ -911,12 +910,12 @@ impl<'a> Widget for ItemTooltip<'a> {
/// Default width is based on the description font size unless the text is
/// small enough to fit on a single line
fn default_x_dimension(&self, ui: &Ui) -> Dimension { Dimension::Absolute(260.0) }
fn default_x_dimension(&self, _ui: &Ui) -> Dimension { Dimension::Absolute(260.0) }
fn default_y_dimension(&self, ui: &Ui) -> Dimension {
fn stats_count(item: &dyn ItemDesc) -> usize {
let mut count: usize = match item.kind() {
ItemKind::Armor(_) => 2,
ItemKind::Armor(_) => 1,
ItemKind::Tool(_) => 5,
ItemKind::Consumable { .. } => 1,
_ => 0,
@ -931,7 +930,7 @@ impl<'a> Widget for ItemTooltip<'a> {
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(280.0);
// Title
let title_h = widget::Text::new(&title)
.w(text_w)
@ -949,7 +948,6 @@ impl<'a> Widget for ItemTooltip<'a> {
.unwrap_or(0.0);
// Description
let desc_h: f64 = if !desc.is_empty() {
widget::Text::new(&desc)
.with_style(self.style.desc)
@ -961,10 +959,6 @@ impl<'a> Widget for ItemTooltip<'a> {
0.0
};
dbg!(title_h);
dbg!(frame_h);
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