Set the item tooltip for every bag slots

This commit is contained in:
Snowram 2021-03-22 20:34:35 +01:00 committed by Robin Gilh
parent b7dd2d6685
commit 2c09180189
4 changed files with 939 additions and 818 deletions

View File

@ -7,8 +7,8 @@ ItemDef(
hands: Two,
stats: Direct((
equip_time_secs: 0.0,
power: 1000.0,
poise_strength: 1000.0,
power: 999.9,
poise_strength: 999.9,
speed: 1.0,
crit_chance: 0.5,
crit_mult: 2.0,

View File

@ -28,8 +28,8 @@ impl Armor {
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
pub struct Stats<Protection> {
pub protection: Protection,
pub poise_resilience: Protection,
protection: Protection,
poise_resilience: Protection,
}
impl Stats<Protection> {
@ -41,6 +41,10 @@ impl Stats<Protection> {
poise_resilience,
}
}
pub fn get_protection(&self) -> Protection { self.protection }
pub fn get_poise_resilience(&self) -> Protection { self.poise_resilience }
}
impl Sub<Stats<Protection>> for Stats<Protection> {

View File

@ -3,8 +3,7 @@ use super::{
img_ids::{Imgs, ImgsRot},
item_imgs::ItemImgs,
slots::{ArmorSlot, EquipSlot, InventorySlot, SlotManager},
util::loadout_slot_text,
Show, CRITICAL_HP_COLOR, LOW_HP_COLOR, QUALITY_COMMON, TEXT_COLOR, UI_HIGHLIGHT_0, UI_MAIN,
Show, CRITICAL_HP_COLOR, LOW_HP_COLOR, TEXT_COLOR, UI_HIGHLIGHT_0, UI_MAIN,
};
use crate::{
hud::get_quality_col,
@ -796,11 +795,6 @@ impl<'a> Widget for Bag<'a> {
}
// Loadout Slots
// Head
let (title, desc) = loadout_slot_text(
inventory.equipped(EquipSlot::Armor(ArmorSlot::Head)),
|| (i18n.get("hud.bag.head"), ""),
&self.msm,
);
let head_item = inventory
.equipped(EquipSlot::Armor(ArmorSlot::Head))
.map(|item| item.to_owned());
@ -811,21 +805,21 @@ impl<'a> Widget for Bag<'a> {
.with_icon(self.imgs.head_bg, Vec2::new(32.0, 40.0), Some(UI_MAIN))
.filled_slot(filled_slot);
if let Some(item) = head_item {
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.head_slot, ui)
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.head_slot, ui)
} else {
slot.with_tooltip(
self.tooltip_manager,
i18n.get("hud.bag.neck"),
i18n.get("hud.bag.head"),
"",
&item_tooltip,
color::WHITE,
@ -834,35 +828,38 @@ impl<'a> Widget for Bag<'a> {
}
// Necklace
let (title, desc) = loadout_slot_text(
inventory.equipped(EquipSlot::Armor(ArmorSlot::Neck)),
|| (i18n.get("hud.bag.neck"), ""),
&self.msm,
);
let neck_q_col = inventory
let neck_item = inventory
.equipped(EquipSlot::Armor(ArmorSlot::Neck))
.map(|item| get_quality_col(item))
.unwrap_or(QUALITY_COMMON);
slot_maker
.map(|item| item.to_owned());
let slot = slot_maker
.fabricate(EquipSlot::Armor(ArmorSlot::Neck), [45.0; 2])
.mid_bottom_with_margin_on(state.ids.head_slot, -55.0)
.with_icon(self.imgs.necklace_bg, Vec2::new(40.0, 31.0), Some(UI_MAIN))
.filled_slot(filled_slot)
.with_tooltip(
self.tooltip_manager,
title,
&*desc,
&item_tooltip,
neck_q_col,
.filled_slot(filled_slot);
if let Some(item) = neck_item {
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.neck_slot, ui);
.set(state.ids.neck_slot, ui)
} else {
slot.with_tooltip(
self.tooltip_manager,
i18n.get("hud.bag.neck"),
"",
&item_tooltip,
color::WHITE,
)
.set(state.ids.neck_slot, ui)
}
// Chest
//Image::new(self.imgs.armor_slot) // different graphics for empty/non empty
let (title, desc) = loadout_slot_text(
inventory.equipped(EquipSlot::Armor(ArmorSlot::Chest)),
|| (i18n.get("hud.bag.chest"), ""),
&self.msm,
);
let chest_item = inventory
.equipped(EquipSlot::Armor(ArmorSlot::Chest))
.map(|item| item.to_owned());
@ -873,17 +870,17 @@ impl<'a> Widget for Bag<'a> {
.with_icon(self.imgs.chest_bg, Vec2::new(64.0, 42.0), Some(UI_MAIN))
.filled_slot(filled_slot);
if let Some(item) = chest_item {
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.chest_slot, ui)
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.chest_slot, ui)
} else {
slot.with_tooltip(
self.tooltip_manager,
@ -895,332 +892,416 @@ impl<'a> Widget for Bag<'a> {
.set(state.ids.chest_slot, ui)
}
// Shoulders
let (title, desc) = loadout_slot_text(
inventory.equipped(EquipSlot::Armor(ArmorSlot::Shoulders)),
|| (i18n.get("hud.bag.shoulders"), ""),
&self.msm,
);
let shoulder_q_col = inventory
let shoulder_item = inventory
.equipped(EquipSlot::Armor(ArmorSlot::Shoulders))
.map(|item| get_quality_col(item))
.unwrap_or(QUALITY_COMMON);
slot_maker
.map(|item| item.to_owned());
let slot = slot_maker
.fabricate(EquipSlot::Armor(ArmorSlot::Shoulders), [70.0; 2])
.bottom_left_with_margins_on(state.ids.chest_slot, 0.0, -80.0)
.with_icon(self.imgs.shoulders_bg, Vec2::new(60.0, 36.0), Some(UI_MAIN))
.filled_slot(filled_slot)
.with_tooltip(
self.tooltip_manager,
title,
&*desc,
&item_tooltip,
shoulder_q_col,
.filled_slot(filled_slot);
if let Some(item) = shoulder_item {
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.shoulders_slot, ui);
.set(state.ids.shoulders_slot, ui)
} else {
slot.with_tooltip(
self.tooltip_manager,
i18n.get("hud.bag.shoulders"),
"",
&item_tooltip,
color::WHITE,
)
.set(state.ids.shoulders_slot, ui)
}
// Hands
let (title, desc) = loadout_slot_text(
inventory.equipped(EquipSlot::Armor(ArmorSlot::Hands)),
|| (i18n.get("hud.bag.hands"), ""),
&self.msm,
);
let chest_q_col = inventory
let hands_item = inventory
.equipped(EquipSlot::Armor(ArmorSlot::Hands))
.map(|item| get_quality_col(item))
.unwrap_or(QUALITY_COMMON);
slot_maker
.map(|item| item.to_owned());
let slot = slot_maker
.fabricate(EquipSlot::Armor(ArmorSlot::Hands), [70.0; 2])
.bottom_right_with_margins_on(state.ids.chest_slot, 0.0, -80.0)
.with_icon(self.imgs.hands_bg, Vec2::new(55.0, 60.0), Some(UI_MAIN))
.filled_slot(filled_slot)
.with_tooltip(
self.tooltip_manager,
title,
&*desc,
&item_tooltip,
chest_q_col,
.filled_slot(filled_slot);
if let Some(item) = hands_item {
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.hands_slot, ui);
.set(state.ids.hands_slot, ui)
} else {
slot.with_tooltip(
self.tooltip_manager,
i18n.get("hud.bag.hands"),
"",
&item_tooltip,
color::WHITE,
)
.set(state.ids.hands_slot, ui)
}
// Belt
let (title, desc) = loadout_slot_text(
inventory.equipped(EquipSlot::Armor(ArmorSlot::Belt)),
|| (i18n.get("hud.bag.belt"), ""),
&self.msm,
);
let belt_q_col = inventory
let belt_item = inventory
.equipped(EquipSlot::Armor(ArmorSlot::Belt))
.map(|item| get_quality_col(item))
.unwrap_or(QUALITY_COMMON);
slot_maker
.map(|item| item.to_owned());
let slot = slot_maker
.fabricate(EquipSlot::Armor(ArmorSlot::Belt), [45.0; 2])
.mid_bottom_with_margin_on(state.ids.chest_slot, -55.0)
.with_icon(self.imgs.belt_bg, Vec2::new(40.0, 23.0), Some(UI_MAIN))
.filled_slot(filled_slot)
.with_tooltip(
self.tooltip_manager,
title,
&*desc,
&item_tooltip,
belt_q_col,
.filled_slot(filled_slot);
if let Some(item) = belt_item {
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.belt_slot, ui);
.set(state.ids.belt_slot, ui)
} else {
slot.with_tooltip(
self.tooltip_manager,
i18n.get("hud.bag.belt"),
"",
&item_tooltip,
color::WHITE,
)
.set(state.ids.belt_slot, ui)
}
// Legs
let (title, desc) = loadout_slot_text(
inventory.equipped(EquipSlot::Armor(ArmorSlot::Legs)),
|| (i18n.get("hud.bag.legs"), ""),
&self.msm,
);
let legs_q_col = inventory
let legs_item = inventory
.equipped(EquipSlot::Armor(ArmorSlot::Legs))
.map(|item| get_quality_col(item))
.unwrap_or(QUALITY_COMMON);
slot_maker
.map(|item| item.to_owned());
let slot = slot_maker
.fabricate(EquipSlot::Armor(ArmorSlot::Legs), [85.0; 2])
.mid_bottom_with_margin_on(state.ids.belt_slot, -95.0)
.with_icon(self.imgs.legs_bg, Vec2::new(48.0, 70.0), Some(UI_MAIN))
.filled_slot(filled_slot)
.with_tooltip(
self.tooltip_manager,
title,
&*desc,
&item_tooltip,
legs_q_col,
.filled_slot(filled_slot);
if let Some(item) = legs_item {
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.legs_slot, ui);
.set(state.ids.legs_slot, ui)
} else {
slot.with_tooltip(
self.tooltip_manager,
i18n.get("hud.bag.legs"),
"",
&item_tooltip,
color::WHITE,
)
.set(state.ids.legs_slot, ui)
}
// Ring
let (title, desc) = loadout_slot_text(
inventory.equipped(EquipSlot::Armor(ArmorSlot::Ring1)),
|| (i18n.get("hud.bag.ring"), ""),
&self.msm,
);
let ring_q_col = inventory
let ring1_item = inventory
.equipped(EquipSlot::Armor(ArmorSlot::Ring1))
.map(|item| get_quality_col(item))
.unwrap_or(QUALITY_COMMON);
slot_maker
.map(|item| item.to_owned());
let slot = slot_maker
.fabricate(EquipSlot::Armor(ArmorSlot::Ring1), [45.0; 2])
.bottom_left_with_margins_on(state.ids.hands_slot, -55.0, 0.0)
.with_icon(self.imgs.ring_bg, Vec2::new(36.0, 40.0), Some(UI_MAIN))
.filled_slot(filled_slot)
.with_tooltip(
self.tooltip_manager,
title,
&*desc,
&item_tooltip,
ring_q_col,
.filled_slot(filled_slot);
if let Some(item) = ring1_item {
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.ring1_slot, ui);
.set(state.ids.ring1_slot, ui)
} else {
slot.with_tooltip(
self.tooltip_manager,
i18n.get("hud.bag.ring"),
"",
&item_tooltip,
color::WHITE,
)
.set(state.ids.ring1_slot, ui)
}
// Ring 2
let (title, desc) = loadout_slot_text(
inventory.equipped(EquipSlot::Armor(ArmorSlot::Ring2)),
|| (i18n.get("hud.bag.ring"), ""),
&self.msm,
);
let ring2_q_col = inventory
let ring2_item = inventory
.equipped(EquipSlot::Armor(ArmorSlot::Ring2))
.map(|item| get_quality_col(item))
.unwrap_or(QUALITY_COMMON);
slot_maker
.map(|item| item.to_owned());
let slot = slot_maker
.fabricate(EquipSlot::Armor(ArmorSlot::Ring2), [45.0; 2])
.bottom_right_with_margins_on(state.ids.shoulders_slot, -55.0, 0.0)
.with_icon(self.imgs.ring_bg, Vec2::new(36.0, 40.0), Some(UI_MAIN))
.filled_slot(filled_slot)
.with_tooltip(
self.tooltip_manager,
title,
&*desc,
&item_tooltip,
ring2_q_col,
.filled_slot(filled_slot);
if let Some(item) = ring2_item {
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.ring2_slot, ui);
.set(state.ids.ring2_slot, ui)
} else {
slot.with_tooltip(
self.tooltip_manager,
i18n.get("hud.bag.ring"),
"",
&item_tooltip,
color::WHITE,
)
.set(state.ids.ring2_slot, ui)
}
// Back
let (title, desc) = loadout_slot_text(
inventory.equipped(EquipSlot::Armor(ArmorSlot::Back)),
|| (i18n.get("hud.bag.back"), ""),
&self.msm,
);
let back_q_col = inventory
let back_item = inventory
.equipped(EquipSlot::Armor(ArmorSlot::Back))
.map(|item| get_quality_col(item))
.unwrap_or(QUALITY_COMMON);
slot_maker
.map(|item| item.to_owned());
let slot = slot_maker
.fabricate(EquipSlot::Armor(ArmorSlot::Back), [45.0; 2])
.down_from(state.ids.ring2_slot, 10.0)
.with_icon(self.imgs.back_bg, Vec2::new(33.0, 40.0), Some(UI_MAIN))
.filled_slot(filled_slot)
.with_tooltip(
self.tooltip_manager,
title,
&*desc,
&item_tooltip,
back_q_col,
.filled_slot(filled_slot);
if let Some(item) = back_item {
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.back_slot, ui);
.set(state.ids.back_slot, ui)
} else {
slot.with_tooltip(
self.tooltip_manager,
i18n.get("hud.bag.back"),
"",
&item_tooltip,
color::WHITE,
)
.set(state.ids.back_slot, ui)
}
// Foot
let (title, desc) = loadout_slot_text(
inventory.equipped(EquipSlot::Armor(ArmorSlot::Feet)),
|| (i18n.get("hud.bag.feet"), ""),
&self.msm,
);
let foot_q_col = inventory
let feet_item = inventory
.equipped(EquipSlot::Armor(ArmorSlot::Feet))
.map(|item| get_quality_col(item))
.unwrap_or(QUALITY_COMMON);
slot_maker
.map(|item| item.to_owned());
let slot = slot_maker
.fabricate(EquipSlot::Armor(ArmorSlot::Feet), [45.0; 2])
.down_from(state.ids.ring1_slot, 10.0)
.with_icon(self.imgs.feet_bg, Vec2::new(32.0, 40.0), Some(UI_MAIN))
.filled_slot(filled_slot)
.with_tooltip(
self.tooltip_manager,
title,
&*desc,
&item_tooltip,
foot_q_col,
.filled_slot(filled_slot);
if let Some(item) = feet_item {
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.feet_slot, ui);
.set(state.ids.feet_slot, ui)
} else {
slot.with_tooltip(
self.tooltip_manager,
i18n.get("hud.bag.feet"),
"",
&item_tooltip,
color::WHITE,
)
.set(state.ids.feet_slot, ui)
}
// Lantern
let (title, desc) = loadout_slot_text(
inventory.equipped(EquipSlot::Lantern),
|| (i18n.get("hud.bag.lantern"), ""),
&self.msm,
);
let lantern_q_col = inventory
let lantern_item = inventory
.equipped(EquipSlot::Lantern)
.map(|item| get_quality_col(item))
.unwrap_or(QUALITY_COMMON);
slot_maker
.map(|item| item.to_owned());
let slot = slot_maker
.fabricate(EquipSlot::Lantern, [45.0; 2])
.top_right_with_margins_on(state.bg_ids.bg_frame, 60.0, 5.0)
.with_icon(self.imgs.lantern_bg, Vec2::new(24.0, 38.0), Some(UI_MAIN))
.filled_slot(filled_slot)
.with_tooltip(
self.tooltip_manager,
title,
&*desc,
&item_tooltip,
lantern_q_col,
.filled_slot(filled_slot);
if let Some(item) = lantern_item {
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.lantern_slot, ui);
.set(state.ids.lantern_slot, ui)
} else {
slot.with_tooltip(
self.tooltip_manager,
i18n.get("hud.bag.lantern"),
"",
&item_tooltip,
color::WHITE,
)
.set(state.ids.lantern_slot, ui)
}
// Glider
let (title, desc) = loadout_slot_text(
inventory.equipped(EquipSlot::Glider),
|| (i18n.get("hud.bag.glider"), ""),
&self.msm,
);
let glider_q_col = inventory
let glider_item = inventory
.equipped(EquipSlot::Glider)
.map(|item| get_quality_col(item))
.unwrap_or(QUALITY_COMMON);
slot_maker
.map(|item| item.to_owned());
let slot = slot_maker
.fabricate(EquipSlot::Glider, [45.0; 2])
.down_from(state.ids.lantern_slot, 5.0)
.with_icon(self.imgs.glider_bg, Vec2::new(38.0, 38.0), Some(UI_MAIN))
.filled_slot(filled_slot)
.with_tooltip(
self.tooltip_manager,
title,
&*desc,
&item_tooltip,
glider_q_col,
.filled_slot(filled_slot);
if let Some(item) = glider_item {
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.glider_slot, ui);
.set(state.ids.glider_slot, ui)
} else {
slot.with_tooltip(
self.tooltip_manager,
i18n.get("hud.bag.glider"),
"",
&item_tooltip,
color::WHITE,
)
.set(state.ids.glider_slot, ui)
}
// Tabard
let (title, desc) = loadout_slot_text(
inventory.equipped(EquipSlot::Armor(ArmorSlot::Tabard)),
|| (i18n.get("hud.bag.tabard"), ""),
&self.msm,
);
let tabard_q_col = inventory
let tabard_item = inventory
.equipped(EquipSlot::Armor(ArmorSlot::Tabard))
.map(|item| get_quality_col(item))
.unwrap_or(QUALITY_COMMON);
slot_maker
.map(|item| item.to_owned());
let slot = slot_maker
.fabricate(EquipSlot::Armor(ArmorSlot::Tabard), [45.0; 2])
.down_from(state.ids.glider_slot, 5.0)
.with_icon(self.imgs.tabard_bg, Vec2::new(38.0, 38.0), Some(UI_MAIN))
.filled_slot(filled_slot)
.with_tooltip(
self.tooltip_manager,
title,
&*desc,
&item_tooltip,
tabard_q_col,
.filled_slot(filled_slot);
if let Some(item) = tabard_item {
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.tabard_slot, ui);
.set(state.ids.tabard_slot, ui)
} else {
slot.with_tooltip(
self.tooltip_manager,
i18n.get("hud.bag.tabard"),
"",
&item_tooltip,
color::WHITE,
)
.set(state.ids.tabard_slot, ui)
}
// Mainhand/Left-Slot
let (title, desc) = loadout_slot_text(
inventory.equipped(EquipSlot::Mainhand),
|| (i18n.get("hud.bag.mainhand"), ""),
&self.msm,
);
let mainhand_item = inventory
.equipped(EquipSlot::Mainhand)
.map(|item| item.to_owned());
let slot = slot_maker
.fabricate(EquipSlot::Mainhand, [85.0; 2])
.bottom_right_with_margins_on(state.ids.back_slot, -95.0, 0.0)
.with_icon(self.imgs.mainhand_bg, Vec2::new(75.0, 75.0), Some(UI_MAIN))
.filled_slot(filled_slot);
if let Some(item) = mainhand_item {
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.mainhand_slot, ui)
} else {
slot.with_tooltip(
self.tooltip_manager,
i18n.get("hud.bag.mainhand"),
"",
&item_tooltip,
color::WHITE,
)
.set(state.ids.mainhand_slot, ui)
}
.equipped(EquipSlot::Mainhand)
.map(|item| item.to_owned());
let slot = slot_maker
.fabricate(EquipSlot::Mainhand, [85.0; 2])
.bottom_right_with_margins_on(state.ids.back_slot, -95.0, 0.0)
.with_icon(self.imgs.mainhand_bg, Vec2::new(75.0, 75.0), Some(UI_MAIN))
.filled_slot(filled_slot);
if let Some(item) = mainhand_item {
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.mainhand_slot, ui)
} else {
slot.with_tooltip(
self.tooltip_manager,
i18n.get("hud.bag.mainhand"),
"",
&item_tooltip,
color::WHITE,
)
.set(state.ids.mainhand_slot, ui)
}
// Offhand/Right-Slot
let (title, desc) = loadout_slot_text(
inventory.equipped(EquipSlot::Offhand),
|| (i18n.get("hud.bag.offhand"), ""),
&self.msm,
);
let offhand_q_col = inventory
let offhand_item = inventory
.equipped(EquipSlot::Offhand)
.map(|item| get_quality_col(item))
.unwrap_or(QUALITY_COMMON);
slot_maker
.map(|item| item.to_owned());
let slot = slot_maker
.fabricate(EquipSlot::Offhand, [85.0; 2])
.bottom_left_with_margins_on(state.ids.feet_slot, -95.0, 0.0)
.with_icon(self.imgs.offhand_bg, Vec2::new(75.0, 75.0), Some(UI_MAIN))
.filled_slot(filled_slot)
.with_tooltip(
self.tooltip_manager,
title,
&*desc,
&item_tooltip,
offhand_q_col,
.filled_slot(filled_slot);
if let Some(item) = offhand_item {
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.offhand_slot, ui);
.set(state.ids.offhand_slot, ui)
} else {
slot.with_tooltip(
self.tooltip_manager,
i18n.get("hud.bag.offhand"),
"",
&item_tooltip,
color::WHITE,
)
.set(state.ids.offhand_slot, ui)
}
}
// Bag 1
let (title, desc) = loadout_slot_text(
inventory.equipped(EquipSlot::Armor(ArmorSlot::Bag1)),
|| (i18n.get("hud.bag.bag"), ""),
&self.msm,
);
let bag1_q_col = inventory
let bag1_item = inventory
.equipped(EquipSlot::Armor(ArmorSlot::Bag1))
.map(|item| get_quality_col(item))
.unwrap_or(QUALITY_COMMON);
slot_maker
.map(|item| item.to_owned());
let slot = slot_maker
.fabricate(EquipSlot::Armor(ArmorSlot::Bag1), [35.0; 2])
.bottom_left_with_margins_on(
state.bg_ids.bg_frame,
@ -1228,84 +1309,122 @@ impl<'a> Widget for Bag<'a> {
3.0,
)
.with_icon(self.imgs.bag_bg, Vec2::new(28.0, 24.0), Some(UI_MAIN))
.filled_slot(filled_slot)
.with_tooltip(
self.tooltip_manager,
title,
&*desc,
&item_tooltip,
bag1_q_col,
.filled_slot(filled_slot);
if let Some(item) = bag1_item {
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.bag1_slot, ui);
.set(state.ids.bag1_slot, ui)
} else {
slot.with_tooltip(
self.tooltip_manager,
i18n.get("hud.bag.bag"),
"",
&item_tooltip,
color::WHITE,
)
.set(state.ids.bag1_slot, ui)
}
// Bag 2
let (title, desc) = loadout_slot_text(
inventory.equipped(EquipSlot::Armor(ArmorSlot::Bag2)),
|| (i18n.get("hud.bag.bag"), ""),
&self.msm,
);
let bag2_q_col = inventory
let bag2_item = inventory
.equipped(EquipSlot::Armor(ArmorSlot::Bag2))
.map(|item| get_quality_col(item))
.unwrap_or(QUALITY_COMMON);
slot_maker
.map(|item| item.to_owned());
let slot = slot_maker
.fabricate(EquipSlot::Armor(ArmorSlot::Bag2), [35.0; 2])
.down_from(state.ids.bag1_slot, 2.0)
.with_icon(self.imgs.bag_bg, Vec2::new(28.0, 24.0), Some(UI_MAIN))
.filled_slot(filled_slot)
.with_tooltip(
self.tooltip_manager,
title,
&*desc,
&item_tooltip,
bag2_q_col,
.filled_slot(filled_slot);
if let Some(item) = bag2_item {
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.bag2_slot, ui);
.set(state.ids.bag2_slot, ui)
} else {
slot.with_tooltip(
self.tooltip_manager,
i18n.get("hud.bag.bag"),
"",
&item_tooltip,
color::WHITE,
)
.set(state.ids.bag2_slot, ui)
}
// Bag 3
let (title, desc) = loadout_slot_text(
inventory.equipped(EquipSlot::Armor(ArmorSlot::Bag3)),
|| (i18n.get("hud.bag.bag"), ""),
&self.msm,
);
let bag3_q_col = inventory
let bag3_item = inventory
.equipped(EquipSlot::Armor(ArmorSlot::Bag3))
.map(|item| get_quality_col(item))
.unwrap_or(QUALITY_COMMON);
slot_maker
.map(|item| item.to_owned());
let slot = slot_maker
.fabricate(EquipSlot::Armor(ArmorSlot::Bag3), [35.0; 2])
.down_from(state.ids.bag2_slot, 2.0)
.with_icon(self.imgs.bag_bg, Vec2::new(28.0, 24.0), Some(UI_MAIN))
.filled_slot(filled_slot)
.with_tooltip(
self.tooltip_manager,
title,
&*desc,
&item_tooltip,
bag3_q_col,
.filled_slot(filled_slot);
if let Some(item) = bag3_item {
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.bag3_slot, ui);
.set(state.ids.bag3_slot, ui)
} else {
slot.with_tooltip(
self.tooltip_manager,
i18n.get("hud.bag.bag"),
"",
&item_tooltip,
color::WHITE,
)
.set(state.ids.bag3_slot, ui)
}
// Bag 4
let (title, desc) = loadout_slot_text(
inventory.equipped(EquipSlot::Armor(ArmorSlot::Bag4)),
|| (i18n.get("hud.bag.bag"), ""),
&self.msm,
);
let bag4_q_col = inventory
let bag4_item = inventory
.equipped(EquipSlot::Armor(ArmorSlot::Bag4))
.map(|item| get_quality_col(item))
.unwrap_or(QUALITY_COMMON);
slot_maker
.map(|item| item.to_owned());
let slot = slot_maker
.fabricate(EquipSlot::Armor(ArmorSlot::Bag4), [35.0; 2])
.down_from(state.ids.bag3_slot, 2.0)
.with_icon(self.imgs.bag_bg, Vec2::new(28.0, 24.0), Some(UI_MAIN))
.filled_slot(filled_slot)
.with_tooltip(
self.tooltip_manager,
title,
&*desc,
&item_tooltip,
bag4_q_col,
.filled_slot(filled_slot);
if let Some(item) = bag4_item {
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.bag4_slot, ui);
.set(state.ids.bag4_slot, ui)
} else {
slot.with_tooltip(
self.tooltip_manager,
i18n.get("hud.bag.bag"),
"",
&item_tooltip,
color::WHITE,
)
.set(state.ids.bag4_slot, ui)
}
// Close button
if Button::image(self.imgs.close_btn)

View File

@ -28,7 +28,6 @@ enum HoverState {
// Spacing between the tooltip and mouse
const MOUSE_PAD_Y: f64 = 15.0;
const TEXT_COLOR: Color = Color::Rgba(1.0, 1.0, 1.0, 1.0); // Default text color
pub struct ItemTooltipManager {
tooltip_id: widget::Id,
@ -430,453 +429,450 @@ impl<'a> Widget for ItemTooltip<'a> {
count as usize
}
let inventories = self.client.inventories();
let inventory = match inventories.get(self.client.entity()) {
Some(l) => l,
None => return,
};
let inventories = self.client.inventories();
let inventory = match inventories.get(self.client.entity()) {
Some(l) => l,
None => return,
};
let item = self.item.clone();
let item = &self.item;
let quality = get_quality_col(&item);
let quality = get_quality_col(item);
let equip_slot = inventory.equipped_items_of_kind(item.kind().clone());
let equip_slot = inventory.equipped_items_of_kind(item.kind().clone());
let (title, desc) = (item.name().to_string(), item.description().to_string());
let (title, desc) = (item.name().to_string(), item.description().to_string());
let subtitle = util::kind_text(item.kind());
let subtitle = util::kind_text(item.kind());
let text_color = conrod_core::color::WHITE;
let text_color = conrod_core::color::WHITE;
// Widths
let (text_w, image_w) = self.text_image_width(rect.w());
// Widths
let (text_w, image_w) = self.text_image_width(rect.w());
// Apply transparency
let color = style.color(ui.theme()).alpha(self.transparency);
// Apply transparency
let color = style.color(ui.theme()).alpha(self.transparency);
// Color quality
let quality_col_img = match &item.quality() {
Quality::Low => self.imgs.inv_slot_grey,
Quality::Common => self.imgs.inv_slot,
Quality::Moderate => self.imgs.inv_slot_green,
Quality::High => self.imgs.inv_slot_blue,
Quality::Epic => self.imgs.inv_slot_purple,
Quality::Legendary => self.imgs.inv_slot_gold,
Quality::Artifact => self.imgs.inv_slot_orange,
_ => self.imgs.inv_slot_red,
};
// Color quality
let quality_col_img = match &item.quality() {
Quality::Low => self.imgs.inv_slot_grey,
Quality::Common => self.imgs.inv_slot,
Quality::Moderate => self.imgs.inv_slot_green,
Quality::High => self.imgs.inv_slot_blue,
Quality::Epic => self.imgs.inv_slot_purple,
Quality::Legendary => self.imgs.inv_slot_gold,
Quality::Artifact => self.imgs.inv_slot_orange,
_ => self.imgs.inv_slot_red,
};
// Spacing for overhanging text
let title_space = self.style.title.font_size(&ui.theme) as f64 * TEXT_SPACE_FACTOR;
// Spacing for overhanging text
let title_space = self.style.title.font_size(&ui.theme) as f64 * TEXT_SPACE_FACTOR;
state.update(|s| {
s.ids
.stats
.resize(stats_count(&item), &mut ui.widget_id_generator())
});
state.update(|s| {
s.ids
.stats
.resize(stats_count(&item), &mut ui.widget_id_generator())
});
state.update(|s| {
s.ids
.diffs
.resize(stats_count(&item), &mut ui.widget_id_generator())
});
state.update(|s| {
s.ids
.diffs
.resize(stats_count(&item), &mut ui.widget_id_generator())
});
// Background image frame
self.image_frame
.wh(rect.dim())
.xy(rect.xy())
// Background image frame
self.image_frame
.wh(rect.dim())
.xy(rect.xy())
.graphics_for(id)
.parent(id)
.color(quality)
.set(state.ids.image_frame, ui);
// Image
if let Some(img_id) = self.image {
widget::Image::new(img_id)
.w_h(image_w, self.image_dims.map_or(image_w, |(_, h)| h))
.graphics_for(id)
.parent(id)
.color(quality)
.set(state.ids.image_frame, ui);
.color(Some(quality))
.top_left_with_margins_on(state.ids.image_frame, V_PAD, H_PAD)
.set(state.ids.image, ui);
}
// Image
if let Some(img_id) = self.image {
widget::Image::new(img_id)
.w_h(image_w, self.image_dims.map_or(image_w, |(_, h)| h))
// Title
widget::Text::new(&title)
.w(text_w)
.graphics_for(id)
.parent(id)
.with_style(self.style.title)
.top_left_with_margins_on(state.ids.image_frame, V_PAD, H_PAD)
.center_justify()
.color(quality)
.set(state.ids.title, ui);
// Item frame
widget::Image::new(quality_col_img)
.wh(ICON_SIZE)
.graphics_for(id)
.parent(id)
.top_left_with_margins_on(state.ids.image_frame, V_PAD, H_PAD)
.down_from(state.ids.title, V_PAD)
.set(state.ids.item_frame, ui);
// Item render
widget::Image::new(animate_by_pulse(
&self.item_imgs.img_ids_or_not_found_img(ItemKey::from(item)),
self.pulse,
))
.color(Some(conrod_core::color::WHITE))
.w_h(ICON_SIZE[0] * 0.8, ICON_SIZE[1] * 0.8)
.middle_of(state.ids.item_frame)
.set(state.ids.item_render, ui);
// Subtitle
widget::Text::new(&subtitle)
.w(text_w)
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(conrod_core::color::GREY)
.right_from(state.ids.item_frame, H_PAD)
.set(state.ids.subtitle, ui);
// Stats
match item.kind() {
ItemKind::Tool(tool) => {
let power = tool.base_power(self.msm, item.components()) * 10.0;
let speed = tool.base_speed(self.msm, item.components());
let poise_str = tool.base_poise_strength(self.msm, item.components()) * 10.0;
let crit_chance = tool.base_crit_chance(self.msm, item.components()) * 100.0;
let crit_mult = tool.base_crit_mult(self.msm, item.components());
let dps = power * speed;
// DPS
widget::Text::new(&format!("{:.1}", dps))
.graphics_for(id)
.parent(id)
.color(Some(quality))
.top_left_with_margins_on(state.ids.image_frame, V_PAD, H_PAD)
.set(state.ids.image, ui);
}
.with_style(self.style.desc)
.color(text_color)
.font_size(34)
.align_middle_y_of(state.ids.item_frame)
.right_from(state.ids.item_frame, V_PAD)
.set(state.ids.main_stat, ui);
// Title
widget::Text::new(&title)
.w(text_w)
.graphics_for(id)
.parent(id)
.with_style(self.style.title)
.top_left_with_margins_on(state.ids.image_frame, V_PAD, H_PAD)
.center_justify()
.color(quality)
.set(state.ids.title, ui);
widget::Text::new(&"DPS".to_string())
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.align_bottom_of(state.ids.main_stat)
.right_from(state.ids.main_stat, V_PAD)
.set(state.ids.main_stat_text, ui);
// Item frame
widget::Image::new(quality_col_img)
.wh(ICON_SIZE)
.graphics_for(id)
.parent(id)
.top_left_with_margins_on(state.ids.image_frame, V_PAD, H_PAD)
.down_from(state.ids.title, V_PAD)
.set(state.ids.item_frame, ui);
// Item render
widget::Image::new(animate_by_pulse(
&self.item_imgs.img_ids_or_not_found_img(ItemKey::from(&item)),
self.pulse,
))
.color(Some(conrod_core::color::WHITE))
.w_h(ICON_SIZE[0] * 0.8, ICON_SIZE[1] * 0.8)
.middle_of(state.ids.item_frame)
.set(state.ids.item_render, ui);
// Subtitle
widget::Text::new(&subtitle)
.w(text_w)
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(conrod_core::color::GREY)
.right_from(state.ids.item_frame, H_PAD)
.set(state.ids.subtitle, ui);
// Stats
match item.kind() {
ItemKind::Tool(tool) => {
let power = tool.base_power(self.msm, item.components()) * 10.0;
let speed = tool.base_speed(self.msm, item.components());
let poise_str = tool.base_poise_strength(self.msm, item.components()) * 10.0;
let crit_chance = tool.base_crit_chance(self.msm, item.components()) * 100.0;
let crit_mult = tool.base_crit_mult(self.msm, item.components());
let dps = power * speed;
// DPS
widget::Text::new(&format!("{:.1}", dps))
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.font_size(35)
.align_middle_y_of(state.ids.item_frame)
.right_from(state.ids.item_frame, V_PAD)
.set(state.ids.main_stat, ui);
widget::Text::new(&"DPS".to_string())
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.align_bottom_of(state.ids.main_stat)
.right_from(state.ids.main_stat, V_PAD)
.set(state.ids.main_stat_text, ui);
// Power
widget::Text::new(&format!("- Power : {:.1}", power))
.x_align_to(state.ids.item_frame, conrod_core::position::Align::Start)
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.down_from(state.ids.item_frame, V_PAD_STATS )
.set(state.ids.stats[0], ui);
// Speed
widget::Text::new(&format!("- Speed : {:.1}", speed))
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.down_from(state.ids.stats[0], V_PAD_STATS )
.set(state.ids.stats[1], ui);
// Poise
widget::Text::new(&format!("- Poise : {:.1}", poise_str))
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.down_from(state.ids.stats[1], V_PAD_STATS )
.set(state.ids.stats[2], ui);
// Crit chance
widget::Text::new(&format!("- Crit Chance : {:.1}%", crit_chance))
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.down_from(state.ids.stats[2], V_PAD_STATS )
.set(state.ids.stats[3], ui);
// Crit mult
widget::Text::new(&format!("- Crit Mult : x{:.1}", crit_mult))
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.down_from(state.ids.stats[3], V_PAD_STATS )
.set(state.ids.stats[4], ui);
if let Some(equipped_item) = equip_slot.cloned().next() {
if let ItemKind::Tool(equipped_tool) = equipped_item.kind() {
let tool_stats = tool
.stats
.resolve_stats(self.msm, item.components())
.clamp_speed();
let equipped_tool_stats = equipped_tool
.stats
.resolve_stats(self.msm, equipped_item.components())
.clamp_speed();
let diff = tool_stats - equipped_tool_stats;
let power_diff =
util::comparison(tool_stats.power, equipped_tool_stats.power);
let speed_diff =
util::comparison(tool_stats.speed, equipped_tool_stats.speed);
let poise_strength_diff = util::comparison(
tool_stats.poise_strength,
equipped_tool_stats.poise_strength,
);
let crit_chance_diff = util::comparison(
tool_stats.crit_chance,
equipped_tool_stats.crit_chance,
);
let crit_mult_diff = 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){
widget::Text::new(&diff_main_stat.0)
.right_from(state.ids.main_stat_text, 5.0)
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(diff_main_stat.1)
.set(state.ids.diff_main_stat, ui);
}
if diff.power != 0.0 {
widget::Text::new(&format!(
"{} {:.1}",
&power_diff.0,
&diff.power * 10.0
))
.align_middle_y_of(state.ids.stats[0])
.right_from(state.ids.stats[0], 10.0)
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(power_diff.1)
.set(state.ids.diffs[0], ui);
}
if diff.speed != 0.0 {
widget::Text::new(&format!("{} {:.1}", &speed_diff.0, &diff.speed))
.align_middle_y_of(state.ids.stats[1])
.right_from(state.ids.stats[1], 10.0)
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(speed_diff.1)
.set(state.ids.diffs[1], ui);
}
if diff.poise_strength != 0.0 {
widget::Text::new(&format!(
"{} {:.1}",
&poise_strength_diff.0,
&diff.poise_strength * 10.0
))
.align_middle_y_of(state.ids.stats[2])
.right_from(state.ids.stats[2], 10.0)
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(poise_strength_diff.1)
.set(state.ids.diffs[2], ui);
}
if diff.crit_chance != 0.0 {
widget::Text::new(&format!(
"{} {:.1}%",
&crit_chance_diff.0,
&diff.crit_chance * 100.0
))
.align_middle_y_of(state.ids.stats[3])
.right_from(state.ids.stats[3], 10.0)
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(crit_chance_diff.1)
.set(state.ids.diffs[3], ui);
}
if diff.crit_mult != 0.0 {
widget::Text::new(&format!(
"{} {:.1}",
&crit_mult_diff.0, &diff.crit_mult
))
.align_middle_y_of(state.ids.stats[4])
.right_from(state.ids.stats[4], 10.0)
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(crit_mult_diff.1)
.set(state.ids.diffs[4], ui);
}
}
}
},
ItemKind::Armor(armor) => {
let protection = armor.get_protection();
let poise_res = armor.get_poise_resilience();
/*// Armour
widget::Text::new(&format!("- Armour : {}", util::protec2string(protection)))
.x_align_to(state.ids.item_frame, conrod_core::position::Align::Start)
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.down_from(state.ids.item_frame, V_PAD)
.set(state.ids.stat1, ui);*/
// Armour
widget::Text::new(&util::protec2string(protection))
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.font_size(35)
.align_middle_y_of(state.ids.item_frame)
.right_from(state.ids.item_frame, V_PAD)
.set(state.ids.main_stat, ui);
widget::Text::new(&"Armor".to_string())
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.align_bottom_of(state.ids.main_stat)
.right_from(state.ids.main_stat, V_PAD)
.set(state.ids.main_stat_text, ui);
// Poise res
widget::Text::new(&format!("- Poise res : {}", util::protec2string(poise_res)))
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.x_align_to(state.ids.item_frame, conrod_core::position::Align::Start)
.set(state.ids.stats[0], ui);
// Slots
if item.num_slots() > 0 {
widget::Text::new(&format!("- Slots : {}", item.num_slots()))
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.x_align_to(state.ids.item_frame, conrod_core::position::Align::Start)
.down_from(state.ids.stats[0], V_PAD_STATS )
.set(state.ids.stats[1], ui);
}
if let Some(equipped_item) = equip_slot.cloned().next() {
if let ItemKind::Armor(equipped_armor) = equipped_item.kind() {
let diff = armor.stats - equipped_armor.stats;
let protection_diff = util::comparison(
&armor.stats.protection,
&equipped_armor.stats.protection,
);
let poise_res_diff = util::comparison(
&armor.stats.poise_resilience,
&equipped_armor.stats.poise_resilience,
);
if diff.protection != Protection::Normal(0.0) {
widget::Text::new(&protection_diff.0)
.right_from(state.ids.main_stat_text, 5.0)
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(protection_diff.1)
.set(state.ids.diff_main_stat, ui);
}
/*if diff.protection != Protection::Normal(0.0) {
widget::Text::new(&format!(
"{} {}",
&diff1.0,
util::protec2string(diff.protection)
))
.align_middle_y_of(state.ids.stat1)
.right_from(state.ids.stat1, 10.0)
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(diff1.1)
.set(state.ids.diff1, ui);
}*/
if diff.poise_resilience != Protection::Normal(0.0) {
widget::Text::new(&format!(
"{} {}",
&poise_res_diff.0,
util::protec2string(diff.poise_resilience)
))
.align_middle_y_of(state.ids.stats[0])
.right_from(state.ids.stats[0], 10.0)
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(poise_res_diff.1)
.set(state.ids.diffs[0], ui);
}
}
}
},
ItemKind::Consumable { effect, .. } => {
widget::Text::new(&util::consumable_desc(effect))
.x_align_to(state.ids.item_frame, conrod_core::position::Align::Start)
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.down_from(state.ids.item_frame, V_PAD)
.set(state.ids.stats[0], ui);
},
_ => (),
}
if !desc.is_empty() {
widget::Text::new(&desc)
// Power
widget::Text::new(&format!("- Power : {:.1}", power))
.x_align_to(state.ids.item_frame, conrod_core::position::Align::Start)
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(conrod_core::color::GREY)
.down_from(
if stats_count(&item) > 0 {
state.ids.stats[state.ids.stats.len() - 1]
} else {
(state.ids.item_frame)
},
V_PAD,
)
.w(text_w)
.set(state.ids.desc, ui);
}
.color(text_color)
.down_from(state.ids.item_frame, V_PAD_STATS)
.set(state.ids.stats[0], ui);
// Speed
widget::Text::new(&format!("- Speed : {:.1}", speed))
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.down_from(state.ids.stats[0], V_PAD_STATS)
.set(state.ids.stats[1], ui);
// Poise
widget::Text::new(&format!("- Poise : {:.1}", poise_str))
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.down_from(state.ids.stats[1], V_PAD_STATS)
.set(state.ids.stats[2], ui);
// Crit chance
widget::Text::new(&format!("- Crit Chance : {:.1}%", crit_chance))
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.down_from(state.ids.stats[2], V_PAD_STATS)
.set(state.ids.stats[3], ui);
// Crit mult
widget::Text::new(&format!("- Crit Mult : x{:.1}", crit_mult))
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.down_from(state.ids.stats[3], V_PAD_STATS)
.set(state.ids.stats[4], ui);
if let Some(equipped_item) = equip_slot.cloned().next() {
if let ItemKind::Tool(equipped_tool) = equipped_item.kind() {
let tool_stats = tool
.stats
.resolve_stats(self.msm, item.components())
.clamp_speed();
let equipped_tool_stats = equipped_tool
.stats
.resolve_stats(self.msm, equipped_item.components())
.clamp_speed();
let diff = tool_stats - equipped_tool_stats;
let power_diff =
util::comparison(tool_stats.power, equipped_tool_stats.power);
let speed_diff =
util::comparison(tool_stats.speed, equipped_tool_stats.speed);
let poise_strength_diff = util::comparison(
tool_stats.poise_strength,
equipped_tool_stats.poise_strength,
);
let crit_chance_diff = util::comparison(
tool_stats.crit_chance,
equipped_tool_stats.crit_chance,
);
let crit_mult_diff =
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 {
widget::Text::new(&diff_main_stat.0)
.right_from(state.ids.main_stat_text, 5.0)
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(diff_main_stat.1)
.set(state.ids.diff_main_stat, ui);
}
if diff.power != 0.0 {
widget::Text::new(&format!(
"{} {:.1}",
&power_diff.0,
&diff.power * 10.0
))
.align_middle_y_of(state.ids.stats[0])
.right_from(state.ids.stats[0], 10.0)
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(power_diff.1)
.set(state.ids.diffs[0], ui);
}
if diff.speed != 0.0 {
widget::Text::new(&format!("{} {:.1}", &speed_diff.0, &diff.speed))
.align_middle_y_of(state.ids.stats[1])
.right_from(state.ids.stats[1], 10.0)
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(speed_diff.1)
.set(state.ids.diffs[1], ui);
}
if diff.poise_strength != 0.0 {
widget::Text::new(&format!(
"{} {:.1}",
&poise_strength_diff.0,
&diff.poise_strength * 10.0
))
.align_middle_y_of(state.ids.stats[2])
.right_from(state.ids.stats[2], 10.0)
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(poise_strength_diff.1)
.set(state.ids.diffs[2], ui);
}
if diff.crit_chance != 0.0 {
widget::Text::new(&format!(
"{} {:.1}%",
&crit_chance_diff.0,
&diff.crit_chance * 100.0
))
.align_middle_y_of(state.ids.stats[3])
.right_from(state.ids.stats[3], 10.0)
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(crit_chance_diff.1)
.set(state.ids.diffs[3], ui);
}
if diff.crit_mult != 0.0 {
widget::Text::new(&format!(
"{} {:.1}",
&crit_mult_diff.0, &diff.crit_mult
))
.align_middle_y_of(state.ids.stats[4])
.right_from(state.ids.stats[4], 10.0)
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(crit_mult_diff.1)
.set(state.ids.diffs[4], ui);
}
}
}
},
ItemKind::Armor(armor) => {
let protection = armor.get_protection();
let poise_res = armor.get_poise_resilience();
/*// Armour
widget::Text::new(&format!("- Armour : {}", util::protec2string(protection)))
.x_align_to(state.ids.item_frame, conrod_core::position::Align::Start)
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.down_from(state.ids.item_frame, V_PAD)
.set(state.ids.stat1, ui);*/
// Armour
widget::Text::new(&util::protec2string(protection))
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.font_size(34)
.align_middle_y_of(state.ids.item_frame)
.right_from(state.ids.item_frame, V_PAD)
.set(state.ids.main_stat, ui);
widget::Text::new(&"Armor".to_string())
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.align_bottom_of(state.ids.main_stat)
.right_from(state.ids.main_stat, V_PAD)
.set(state.ids.main_stat_text, ui);
// Poise res
widget::Text::new(&format!("- Poise res : {}", util::protec2string(poise_res)))
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.x_align_to(state.ids.item_frame, conrod_core::position::Align::Start)
.set(state.ids.stats[0], ui);
// Slots
if item.num_slots() > 0 {
widget::Text::new(&format!("- Slots : {}", item.num_slots()))
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.x_align_to(state.ids.item_frame, conrod_core::position::Align::Start)
.down_from(state.ids.stats[0], V_PAD_STATS)
.set(state.ids.stats[1], ui);
}
if let Some(equipped_item) = equip_slot.cloned().next() {
if let ItemKind::Armor(equipped_armor) = equipped_item.kind() {
let diff = armor.stats - equipped_armor.stats;
let protection_diff = util::comparison(
&armor.get_protection(),
&equipped_armor.get_protection(),
);
let poise_res_diff = util::comparison(
&armor.get_poise_resilience(),
&equipped_armor.get_poise_resilience(),
);
if diff.get_protection() != Protection::Normal(0.0) {
widget::Text::new(&protection_diff.0)
.right_from(state.ids.main_stat_text, 5.0)
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(protection_diff.1)
.set(state.ids.diff_main_stat, ui);
}
/*if diff.protection != Protection::Normal(0.0) {
widget::Text::new(&format!(
"{} {}",
&diff1.0,
util::protec2string(diff.protection)
))
.align_middle_y_of(state.ids.stat1)
.right_from(state.ids.stat1, 10.0)
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(diff1.1)
.set(state.ids.diff1, ui);
}*/
if diff.get_poise_resilience() != Protection::Normal(0.0) {
widget::Text::new(&format!(
"{} {}",
&poise_res_diff.0,
util::protec2string(diff.get_poise_resilience())
))
.align_middle_y_of(state.ids.stats[0])
.right_from(state.ids.stats[0], 10.0)
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(poise_res_diff.1)
.set(state.ids.diffs[0], ui);
}
}
}
},
ItemKind::Consumable { effect, .. } => {
widget::Text::new(&util::consumable_desc(effect))
.x_align_to(state.ids.item_frame, conrod_core::position::Align::Start)
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(text_color)
.down_from(state.ids.item_frame, V_PAD)
.set(state.ids.stats[0], ui);
},
_ => (),
}
if !desc.is_empty() {
widget::Text::new(&desc)
.x_align_to(state.ids.item_frame, conrod_core::position::Align::Start)
.graphics_for(id)
.parent(id)
.with_style(self.style.desc)
.color(conrod_core::color::GREY)
.down_from(
if stats_count(&item) > 0 {
state.ids.stats[state.ids.stats.len() - 1]
} else {
state.ids.item_frame
},
V_PAD,
)
.w(text_w)
.set(state.ids.desc, ui);
}
}
/// 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(280.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: &Item) -> usize {
let mut count = match item.kind() {
let mut count: usize = match item.kind() {
ItemKind::Armor(_) => 2,
ItemKind::Tool(_) => 5,
ItemKind::Consumable { .. } => 1,
@ -885,52 +881,54 @@ impl<'a> Widget for ItemTooltip<'a> {
if item.num_slots() != 0 {
count += 1
}
count as usize
count
}
let (title, desc) = (self.item.name().to_string(), self.item.description().to_string());
let item = &self.item;
let (text_w, image_w) = self.text_image_width(280.0);
// Title
let title_h = widget::Text::new(&title)
.w(text_w)
.with_style(self.style.title)
.get_h(ui)
.unwrap_or(0.0);
let (title, desc) = (item.name().to_string(), item.description().to_string());
// Item frame
let frame_h = ICON_SIZE[1];
let (text_w, image_w) = self.text_image_width(280.0);
// Title
let title_h = widget::Text::new(&title)
.w(text_w)
.with_style(self.style.title)
.get_h(ui)
.unwrap_or(0.0);
// Stat
let stat_h = widget::Text::new(&"placeholder".to_string())
// Item frame
let frame_h = ICON_SIZE[1];
// Stat
let stat_h = widget::Text::new(&"placeholder".to_string())
.with_style(self.style.desc)
.get_h(ui)
.unwrap_or(0.0);
// Description
let desc_h: f64 = if !desc.is_empty() {
widget::Text::new(&desc)
.with_style(self.style.desc)
.color(conrod_core::color::GREY)
.w(text_w)
.get_h(ui)
.unwrap_or(0.0);
// Description
let desc_h: f64 = if !desc.is_empty() {
widget::Text::new(&desc)
.with_style(self.style.desc)
.color(conrod_core::color::GREY)
.w(text_w)
.get_h(ui)
.unwrap_or(0.0)
} else {
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
+ desc_h
+ V_PAD * 5.0 + V_PAD_STATS * stats_count(&self.item) as f64;
Dimension::Absolute(height)
.unwrap_or(0.0)
} else {
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
+ desc_h
+ V_PAD * 5.0
+ V_PAD_STATS * stats_count(&self.item) as f64;
Dimension::Absolute(height)
}
}