mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added durability to item tooltips
This commit is contained in:
parent
c586db8feb
commit
a555e08d0b
@ -103,6 +103,7 @@ common-stats-energy_reward = Energy Reward
|
|||||||
common-stats-crit_power = Crit Power
|
common-stats-crit_power = Crit Power
|
||||||
common-stats-stealth = Stealth
|
common-stats-stealth = Stealth
|
||||||
common-stats-slots = Slots
|
common-stats-slots = Slots
|
||||||
|
common-stats-durability = Durability
|
||||||
common-material-metal = Metal
|
common-material-metal = Metal
|
||||||
common-material-wood = Wood
|
common-material-wood = Wood
|
||||||
common-material-stone = Stone
|
common-material-stone = Stone
|
||||||
|
@ -772,6 +772,8 @@ impl assets::Asset for RawItemDef {
|
|||||||
pub struct OperationFailure;
|
pub struct OperationFailure;
|
||||||
|
|
||||||
impl Item {
|
impl Item {
|
||||||
|
pub const MAX_DURABILITY: u32 = 8;
|
||||||
|
|
||||||
// TODO: consider alternatives such as default abilities that can be added to a
|
// TODO: consider alternatives such as default abilities that can be added to a
|
||||||
// loadout when no weapon is present
|
// loadout when no weapon is present
|
||||||
pub fn empty() -> Self { Item::new_from_asset_expect("common.items.weapons.empty.empty") }
|
pub fn empty() -> Self { Item::new_from_asset_expect("common.items.weapons.empty.empty") }
|
||||||
@ -1196,14 +1198,17 @@ impl Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn durability(&self) -> Option<u32> { self.durability.map(|x| x.min(Self::MAX_DURABILITY)) }
|
||||||
|
|
||||||
pub fn stats_durability_multiplier(&self) -> DurabilityMultiplier {
|
pub fn stats_durability_multiplier(&self) -> DurabilityMultiplier {
|
||||||
const MAX_DURABILITY: u32 = 8;
|
let durability = self
|
||||||
let durability = self.durability.map_or(0, |x| x.clamp(0, MAX_DURABILITY));
|
.durability
|
||||||
|
.map_or(0, |x| x.clamp(0, Self::MAX_DURABILITY));
|
||||||
const DURABILITY_THRESHOLD: u32 = 4;
|
const DURABILITY_THRESHOLD: u32 = 4;
|
||||||
const MIN_FRAC: f32 = 0.2;
|
const MIN_FRAC: f32 = 0.2;
|
||||||
let mult = (1.0
|
let mult = (1.0
|
||||||
- durability.saturating_sub(DURABILITY_THRESHOLD) as f32
|
- durability.saturating_sub(DURABILITY_THRESHOLD) as f32
|
||||||
/ (MAX_DURABILITY - DURABILITY_THRESHOLD) as f32)
|
/ (Self::MAX_DURABILITY - DURABILITY_THRESHOLD) as f32)
|
||||||
* (1.0 - MIN_FRAC)
|
* (1.0 - MIN_FRAC)
|
||||||
+ MIN_FRAC;
|
+ MIN_FRAC;
|
||||||
DurabilityMultiplier(mult)
|
DurabilityMultiplier(mult)
|
||||||
@ -1264,6 +1269,8 @@ pub trait ItemDesc {
|
|||||||
fn tags(&self) -> Vec<ItemTag>;
|
fn tags(&self) -> Vec<ItemTag>;
|
||||||
fn is_modular(&self) -> bool;
|
fn is_modular(&self) -> bool;
|
||||||
fn components(&self) -> &[Item];
|
fn components(&self) -> &[Item];
|
||||||
|
fn has_durability(&self) -> bool;
|
||||||
|
fn durability(&self) -> Option<u32>;
|
||||||
fn stats_durability_multiplier(&self) -> DurabilityMultiplier;
|
fn stats_durability_multiplier(&self) -> DurabilityMultiplier;
|
||||||
|
|
||||||
fn tool_info(&self) -> Option<ToolKind> {
|
fn tool_info(&self) -> Option<ToolKind> {
|
||||||
@ -1294,6 +1301,10 @@ impl ItemDesc for Item {
|
|||||||
|
|
||||||
fn components(&self) -> &[Item] { self.components() }
|
fn components(&self) -> &[Item] { self.components() }
|
||||||
|
|
||||||
|
fn has_durability(&self) -> bool { self.has_durability() }
|
||||||
|
|
||||||
|
fn durability(&self) -> Option<u32> { self.durability() }
|
||||||
|
|
||||||
fn stats_durability_multiplier(&self) -> DurabilityMultiplier {
|
fn stats_durability_multiplier(&self) -> DurabilityMultiplier {
|
||||||
self.stats_durability_multiplier()
|
self.stats_durability_multiplier()
|
||||||
}
|
}
|
||||||
@ -1320,6 +1331,10 @@ impl ItemDesc for ItemDef {
|
|||||||
|
|
||||||
fn components(&self) -> &[Item] { &[] }
|
fn components(&self) -> &[Item] { &[] }
|
||||||
|
|
||||||
|
fn has_durability(&self) -> bool { false }
|
||||||
|
|
||||||
|
fn durability(&self) -> Option<u32> { None }
|
||||||
|
|
||||||
fn stats_durability_multiplier(&self) -> DurabilityMultiplier { DurabilityMultiplier(1.0) }
|
fn stats_durability_multiplier(&self) -> DurabilityMultiplier { DurabilityMultiplier(1.0) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1356,6 +1371,10 @@ impl<'a, T: ItemDesc + ?Sized> ItemDesc for &'a T {
|
|||||||
|
|
||||||
fn components(&self) -> &[Item] { (*self).components() }
|
fn components(&self) -> &[Item] { (*self).components() }
|
||||||
|
|
||||||
|
fn has_durability(&self) -> bool { (*self).has_durability() }
|
||||||
|
|
||||||
|
fn durability(&self) -> Option<u32> { (*self).durability() }
|
||||||
|
|
||||||
fn stats_durability_multiplier(&self) -> DurabilityMultiplier {
|
fn stats_durability_multiplier(&self) -> DurabilityMultiplier {
|
||||||
(*self).stats_durability_multiplier()
|
(*self).stats_durability_multiplier()
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ pub fn material_kind_text<'a>(kind: &MaterialKind, i18n: &'a Localization) -> Co
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn stats_count(item: &dyn ItemDesc, msm: &MaterialStatManifest) -> usize {
|
pub fn stats_count(item: &dyn ItemDesc, msm: &MaterialStatManifest) -> usize {
|
||||||
match &*item.kind() {
|
let mut count = match &*item.kind() {
|
||||||
ItemKind::Armor(armor) => {
|
ItemKind::Armor(armor) => {
|
||||||
let armor_stats = armor.stats(msm, item.stats_durability_multiplier());
|
let armor_stats = armor.stats(msm, item.stats_durability_multiplier());
|
||||||
armor_stats.energy_reward.is_some() as usize
|
armor_stats.energy_reward.is_some() as usize
|
||||||
@ -118,7 +118,11 @@ pub fn stats_count(item: &dyn ItemDesc, msm: &MaterialStatManifest) -> usize {
|
|||||||
},
|
},
|
||||||
ItemKind::ModularComponent { .. } => 7,
|
ItemKind::ModularComponent { .. } => 7,
|
||||||
_ => 0,
|
_ => 0,
|
||||||
|
};
|
||||||
|
if item.has_durability() {
|
||||||
|
count += 1;
|
||||||
}
|
}
|
||||||
|
count
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn line_count(item: &dyn ItemDesc, msm: &MaterialStatManifest, i18n: &Localization) -> usize {
|
pub fn line_count(item: &dyn ItemDesc, msm: &MaterialStatManifest, i18n: &Localization) -> usize {
|
||||||
|
@ -669,6 +669,24 @@ impl<'a> Widget for ItemTooltip<'a> {
|
|||||||
6,
|
6,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Durability
|
||||||
|
if let Some(durability) = item.durability() {
|
||||||
|
const MAX_DURABILITY: u32 = 8;
|
||||||
|
let durability = MAX_DURABILITY - durability.min(MAX_DURABILITY);
|
||||||
|
widget::Text::new(&format!(
|
||||||
|
"{} : {}/{}",
|
||||||
|
i18n.get("common.stats.durability"),
|
||||||
|
durability,
|
||||||
|
MAX_DURABILITY
|
||||||
|
))
|
||||||
|
.graphics_for(id)
|
||||||
|
.parent(id)
|
||||||
|
.with_style(self.style.desc)
|
||||||
|
.color(text_color)
|
||||||
|
.down_from(state.ids.stats[6], V_PAD_STATS)
|
||||||
|
.set(state.ids.stats[7], ui);
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(equipped_item) = equipped_item {
|
if let Some(equipped_item) = equipped_item {
|
||||||
if let ItemKind::Tool(equipped_tool) = &*equipped_item.kind() {
|
if let ItemKind::Tool(equipped_tool) = &*equipped_item.kind() {
|
||||||
let tool_stats = tool.stats(item.stats_durability_multiplier());
|
let tool_stats = tool.stats(item.stats_durability_multiplier());
|
||||||
@ -874,6 +892,20 @@ impl<'a> Widget for ItemTooltip<'a> {
|
|||||||
),
|
),
|
||||||
index,
|
index,
|
||||||
);
|
);
|
||||||
|
index += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if item.has_durability() {
|
||||||
|
let durability = Item::MAX_DURABILITY - item.durability().unwrap_or(0);
|
||||||
|
stat_text(
|
||||||
|
format!(
|
||||||
|
"{} : {}/{}",
|
||||||
|
i18n.get("common.stats.durability"),
|
||||||
|
durability,
|
||||||
|
Item::MAX_DURABILITY
|
||||||
|
),
|
||||||
|
index,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(equipped_item) = equipped_item {
|
if let Some(equipped_item) = equipped_item {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user