Merge branch 'ubruntu/hide-zero-armor-stats' into 'master'

Hide empty stats on item tooltips

See merge request veloren/veloren!3067
This commit is contained in:
Joshua Barretto 2021-12-20 15:07:38 +00:00
commit bd4796144a
3 changed files with 203 additions and 103 deletions

View File

@ -87,43 +87,18 @@ impl Sub<Stats> for Stats {
fn sub(self, other: Self) -> Self::Output { fn sub(self, other: Self) -> Self::Output {
Self { Self {
protection: if self.protection.is_none() && other.protection.is_none() { protection: self.protection.zip(other.protection).map(|(a, b)| a - b),
None poise_resilience: self
} else { .poise_resilience
Some( .zip(other.poise_resilience)
self.protection.unwrap_or(Protection::Normal(0.0)) .map(|(a, b)| a - b),
- other.protection.unwrap_or(Protection::Normal(0.0)), energy_max: self.energy_max.zip(other.energy_max).map(|(a, b)| a - b),
) energy_reward: self
}, .energy_reward
poise_resilience: if self.poise_resilience.is_none() && other.poise_resilience.is_none() .zip(other.energy_reward)
{ .map(|(a, b)| a - b),
None crit_power: self.crit_power.zip(other.crit_power).map(|(a, b)| a - b),
} else { stealth: self.stealth.zip(other.stealth).map(|(a, b)| a - b),
Some(
self.poise_resilience.unwrap_or(Protection::Normal(0.0))
- other.poise_resilience.unwrap_or(Protection::Normal(0.0)),
)
},
energy_max: if self.energy_max.is_none() && other.energy_max.is_none() {
None
} else {
Some(self.energy_max.unwrap_or(0.0) - other.energy_max.unwrap_or(0.0))
},
energy_reward: if self.energy_reward.is_none() && other.energy_reward.is_none() {
None
} else {
Some(self.energy_reward.unwrap_or(0.0) - other.energy_reward.unwrap_or(0.0))
},
crit_power: if self.crit_power.is_none() && other.crit_power.is_none() {
None
} else {
Some(self.crit_power.unwrap_or(0.0) - other.crit_power.unwrap_or(0.0))
},
stealth: if self.stealth.is_none() && other.stealth.is_none() {
None
} else {
Some(self.stealth.unwrap_or(0.0) - other.stealth.unwrap_or(0.0))
},
} }
} }
} }

View File

@ -111,7 +111,11 @@ pub fn stats_count(item: &dyn ItemDesc) -> usize {
if matches!(armor.kind, ArmorKind::Bag(_)) { if matches!(armor.kind, ArmorKind::Bag(_)) {
0 0
} else { } else {
5 armor.stats.energy_reward().is_some() as usize
+ armor.stats.energy_max().is_some() as usize
+ armor.stats.stealth().is_some() as usize
+ armor.stats.crit_power().is_some() as usize
+ armor.stats.poise_resilience().is_some() as usize
} }
}, },
ItemKind::Tool(_) => 4, ItemKind::Tool(_) => 4,

View File

@ -500,7 +500,7 @@ impl<'a> Widget for ItemTooltip<'a> {
_ => self.imgs.inv_slot_red, _ => self.imgs.inv_slot_red,
}; };
// Update windget array size // Update widget array size
state.update(|s| { state.update(|s| {
s.ids s.ids
.stats .stats
@ -782,70 +782,147 @@ impl<'a> Widget for ItemTooltip<'a> {
.set(state.ids.main_stat_text, ui); .set(state.ids.main_stat_text, ui);
// Poise res // Poise res
widget::Text::new(&format!( if armor.stats.poise_resilience().is_some() {
"{} : {}", widget::Text::new(&format!(
i18n.get("common.stats.poise_res"), "{} : {}",
util::protec2string(poise_res) i18n.get("common.stats.poise_res"),
)) util::protec2string(poise_res)
.graphics_for(id) ))
.parent(id) .graphics_for(id)
.with_style(self.style.desc) .parent(id)
.color(text_color) .with_style(self.style.desc)
.x_align_to(state.ids.item_frame, conrod_core::position::Align::Start) .color(text_color)
.down_from(state.ids.item_frame, V_PAD) .x_align_to(state.ids.item_frame, conrod_core::position::Align::Start)
.set(state.ids.stats[0], ui); .down_from(state.ids.item_frame, V_PAD)
.set(state.ids.stats[0], ui);
}
// Max Energy // Max Energy
widget::Text::new(&format!( if armor.stats.energy_max().is_some() {
"{} : {:.1}", widget::Text::new(&format!(
i18n.get("common.stats.energy_max"), "{} : {:.1}",
energy_max i18n.get("common.stats.energy_max"),
)) energy_max
.graphics_for(id) ))
.parent(id) .graphics_for(id)
.with_style(self.style.desc) .parent(id)
.color(text_color) .with_style(self.style.desc)
.down_from(state.ids.stats[0], V_PAD_STATS) .color(text_color)
.set(state.ids.stats[1], ui); .and(|t| {
if armor.stats.poise_resilience().is_some() {
t.down_from(state.ids.stats[0], V_PAD_STATS)
} else {
t.x_align_to(
state.ids.item_frame,
conrod_core::position::Align::Start,
)
.down_from(state.ids.item_frame, V_PAD)
}
})
.set(
state.ids.stats[armor.stats.poise_resilience().is_some() as usize],
ui,
);
}
// Energy Recovery // Energy Recovery
widget::Text::new(&format!( if armor.stats.energy_reward().is_some() {
"{} : {:.1}%", widget::Text::new(&format!(
i18n.get("common.stats.energy_reward"), "{} : {:.1}%",
energy_reward i18n.get("common.stats.energy_reward"),
)) energy_reward
.graphics_for(id) ))
.parent(id) .graphics_for(id)
.with_style(self.style.desc) .parent(id)
.color(text_color) .with_style(self.style.desc)
.down_from(state.ids.stats[1], V_PAD_STATS) .color(text_color)
.set(state.ids.stats[2], ui); .and(|t| {
match armor.stats.poise_resilience().is_some() as usize
+ armor.stats.energy_max().is_some() as usize
{
0 => t
.x_align_to(
state.ids.item_frame,
conrod_core::position::Align::Start,
)
.down_from(state.ids.item_frame, V_PAD),
x => t.down_from(state.ids.stats[x - 1], V_PAD_STATS),
}
})
.set(
state.ids.stats[armor.stats.poise_resilience().is_some() as usize
+ armor.stats.energy_max().is_some() as usize],
ui,
);
}
// Crit Power // Crit Power
widget::Text::new(&format!( if armor.stats.crit_power().is_some() {
"{} : {}", widget::Text::new(&format!(
i18n.get("common.stats.crit_power"), "{} : {:.3}",
crit_power i18n.get("common.stats.crit_power"),
)) crit_power
.graphics_for(id) ))
.parent(id) .graphics_for(id)
.with_style(self.style.desc) .parent(id)
.color(text_color) .with_style(self.style.desc)
.down_from(state.ids.stats[2], V_PAD_STATS) .color(text_color)
.set(state.ids.stats[3], ui); .and(|t| {
match armor.stats.poise_resilience().is_some() as usize
+ armor.stats.energy_max().is_some() as usize
+ armor.stats.energy_reward().is_some() as usize
{
0 => t
.x_align_to(
state.ids.item_frame,
conrod_core::position::Align::Start,
)
.down_from(state.ids.item_frame, V_PAD),
x => t.down_from(state.ids.stats[x - 1], V_PAD_STATS),
}
})
.set(
state.ids.stats[armor.stats.poise_resilience().is_some() as usize
+ armor.stats.energy_max().is_some() as usize
+ armor.stats.energy_reward().is_some() as usize],
ui,
);
}
// Stealth // Stealth
widget::Text::new(&format!( if armor.stats.stealth().is_some() {
"{} : {}", widget::Text::new(&format!(
i18n.get("common.stats.stealth"), "{} : {:.3}",
stealth i18n.get("common.stats.stealth"),
)) stealth
.graphics_for(id) ))
.parent(id) .graphics_for(id)
.with_style(self.style.desc) .parent(id)
.color(text_color) .with_style(self.style.desc)
.down_from(state.ids.stats[3], V_PAD_STATS) .color(text_color)
.set(state.ids.stats[4], ui); .and(|t| {
match armor.stats.poise_resilience().is_some() as usize
+ armor.stats.energy_max().is_some() as usize
+ armor.stats.energy_reward().is_some() as usize
+ armor.stats.crit_power().is_some() as usize
{
0 => t
.x_align_to(
state.ids.item_frame,
conrod_core::position::Align::Start,
)
.down_from(state.ids.item_frame, V_PAD),
x => t.down_from(state.ids.stats[x - 1], V_PAD_STATS),
}
})
.set(
state.ids.stats[armor.stats.poise_resilience().is_some() as usize
+ armor.stats.energy_max().is_some() as usize
+ armor.stats.energy_reward().is_some() as usize
+ armor.stats.crit_power().is_some() as usize],
ui,
);
}
// Slots // Slots
if item.num_slots() > 0 { if item.num_slots() > 0 {
@ -858,8 +935,30 @@ impl<'a> Widget for ItemTooltip<'a> {
.parent(id) .parent(id)
.with_style(self.style.desc) .with_style(self.style.desc)
.color(text_color) .color(text_color)
.down_from(state.ids.stats[4], V_PAD_STATS) .and(|t| {
.set(state.ids.stats[5], ui); match armor.stats.poise_resilience().is_some() as usize
+ armor.stats.energy_max().is_some() as usize
+ armor.stats.energy_reward().is_some() as usize
+ armor.stats.crit_power().is_some() as usize
+ armor.stats.stealth().is_some() as usize
{
0 => t
.x_align_to(
state.ids.item_frame,
conrod_core::position::Align::Start,
)
.down_from(state.ids.item_frame, V_PAD),
x => t.down_from(state.ids.stats[x - 1], V_PAD_STATS),
}
})
.set(
state.ids.stats[armor.stats.poise_resilience().is_some() as usize
+ armor.stats.energy_max().is_some() as usize
+ armor.stats.energy_reward().is_some() as usize
+ armor.stats.crit_power().is_some() as usize
+ armor.stats.stealth().is_some() as usize],
ui,
);
} }
}, },
} }
@ -927,7 +1026,11 @@ impl<'a> Widget for ItemTooltip<'a> {
if let Some(e_m_diff) = diff.energy_max() { if let Some(e_m_diff) = diff.energy_max() {
if e_m_diff > Energy::ENERGY_EPSILON { if e_m_diff > Energy::ENERGY_EPSILON {
let text = format!("{} {:.1}", &energy_max_diff.0, e_m_diff); let text = format!("{} {:.1}", &energy_max_diff.0, e_m_diff);
diff_text(text, energy_max_diff.1, 1) diff_text(
text,
energy_max_diff.1,
armor.stats.poise_resilience().is_some() as usize,
)
} }
} }
@ -935,21 +1038,39 @@ impl<'a> Widget for ItemTooltip<'a> {
if e_r_diff > Energy::ENERGY_EPSILON { if e_r_diff > Energy::ENERGY_EPSILON {
let text = let text =
format!("{} {:.1}", &energy_reward_diff.0, e_r_diff * 100.0); format!("{} {:.1}", &energy_reward_diff.0, e_r_diff * 100.0);
diff_text(text, energy_reward_diff.1, 2) diff_text(
text,
energy_reward_diff.1,
armor.stats.poise_resilience().is_some() as usize
+ armor.stats.energy_max().is_some() as usize,
)
} }
} }
if let Some(c_p_diff) = diff.crit_power() { if let Some(c_p_diff) = diff.crit_power() {
if c_p_diff != 0.0_f32 { if c_p_diff != 0.0_f32 {
let text = format!("{} {}", &crit_power_diff.0, c_p_diff); let text = format!("{} {:.3}", &crit_power_diff.0, c_p_diff);
diff_text(text, crit_power_diff.1, 3) diff_text(
text,
crit_power_diff.1,
armor.stats.poise_resilience().is_some() as usize
+ armor.stats.energy_max().is_some() as usize
+ armor.stats.energy_reward().is_some() as usize,
)
} }
} }
if let Some(s_diff) = diff.stealth() { if let Some(s_diff) = diff.stealth() {
if s_diff != 0.0_f32 { if s_diff != 0.0_f32 {
let text = format!("{} {}", &stealth_diff.0, s_diff); let text = format!("{} {:.3}", &stealth_diff.0, s_diff);
diff_text(text, stealth_diff.1, 4) diff_text(
text,
stealth_diff.1,
armor.stats.poise_resilience().is_some() as usize
+ armor.stats.energy_max().is_some() as usize
+ armor.stats.energy_reward().is_some() as usize
+ armor.stats.crit_power().is_some() as usize,
)
} }
} }
} }