mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Initial work to show decayed health in healthbars
This commit is contained in:
parent
1edf79d109
commit
c0c6ff3063
@ -51,6 +51,7 @@ widget_ids! {
|
||||
member_panels_txt_bg[],
|
||||
member_panels_txt[],
|
||||
member_health[],
|
||||
member_health_decayed[],
|
||||
member_stam[],
|
||||
buffs[],
|
||||
buff_timers[],
|
||||
@ -284,7 +285,10 @@ impl<'a> Widget for Group<'a> {
|
||||
state.update(|s| {
|
||||
s.ids
|
||||
.member_health
|
||||
.resize(group_size, &mut ui.widget_id_generator())
|
||||
.resize(group_size, &mut ui.widget_id_generator());
|
||||
s.ids
|
||||
.member_health_decayed
|
||||
.resize(group_size, &mut ui.widget_id_generator());
|
||||
})
|
||||
};
|
||||
if state.ids.member_stam.len() < group_size {
|
||||
@ -364,7 +368,9 @@ impl<'a> Widget for Group<'a> {
|
||||
let combat_rating =
|
||||
combat::combat_rating(inventory, health, stats, *body, &self.msm);
|
||||
let char_name = stats.name.to_string();
|
||||
let health_perc = health.current() as f64 / health.maximum() as f64;
|
||||
|
||||
let max_hp = health.base_max().max(health.maximum());
|
||||
let health_perc = health.current() as f64 / max_hp as f64;
|
||||
// change panel positions when debug info is shown
|
||||
let x = if debug_on { i / 8 } else { i / 12 };
|
||||
let y = if debug_on { i % 8 } else { i % 12 };
|
||||
@ -395,6 +401,21 @@ impl<'a> Widget for Group<'a> {
|
||||
.color(Some(health_col))
|
||||
.top_left_with_margins_on(state.ids.member_panels_bg[i], 2.0, 2.0)
|
||||
.set(state.ids.member_health[i], ui);
|
||||
let decayed_health = 1.0 - health.maximum() as f64 / health.base_max() as f64;
|
||||
if decayed_health > 0.0 {
|
||||
Image::new(self.imgs.bar_content)
|
||||
.w_h(
|
||||
inline_tweak::tweak!(148.0) * decayed_health,
|
||||
inline_tweak::tweak!(22.0),
|
||||
)
|
||||
.color(Some(BLACK))
|
||||
.top_right_with_margins_on(
|
||||
state.ids.member_panels_bg[i],
|
||||
inline_tweak::tweak!(2.0),
|
||||
inline_tweak::tweak!(2.0),
|
||||
)
|
||||
.set(state.ids.member_health_decayed[i], ui);
|
||||
}
|
||||
if health.is_dead {
|
||||
// Death Text
|
||||
Text::new(&self.localized_strings.get("hud.group.dead"))
|
||||
|
@ -64,7 +64,9 @@ pub struct Info<'a> {
|
||||
}
|
||||
|
||||
/// Determines whether to show the healthbar
|
||||
pub fn should_show_healthbar(health: &Health) -> bool { health.current() != health.maximum() }
|
||||
pub fn should_show_healthbar(health: &Health) -> bool {
|
||||
health.current() != health.maximum() || health.current() < health.base_max()
|
||||
}
|
||||
|
||||
/// ui widget containing everything that goes over a character's head
|
||||
/// (Speech bubble, Name, Level, HP/energy bars, etc.)
|
||||
|
@ -67,6 +67,7 @@ widget_ids! {
|
||||
// HP-Bar
|
||||
hp_alignment,
|
||||
hp_filling,
|
||||
hp_decayed,
|
||||
hp_txt_alignment,
|
||||
hp_txt_bg,
|
||||
hp_txt,
|
||||
@ -217,7 +218,9 @@ impl<'a> Widget for Skillbar<'a> {
|
||||
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
|
||||
let widget::UpdateArgs { state, ui, .. } = args;
|
||||
|
||||
let mut hp_percentage = self.health.current() as f64 / self.health.maximum() as f64 * 100.0;
|
||||
let max_hp = self.health.base_max().max(self.health.maximum());
|
||||
|
||||
let mut hp_percentage = self.health.current() as f64 / max_hp as f64 * 100.0;
|
||||
let mut energy_percentage =
|
||||
self.energy.current() as f64 / self.energy.maximum() as f64 * 100.0;
|
||||
if self.health.is_dead {
|
||||
@ -306,6 +309,14 @@ impl<'a> Widget for Skillbar<'a> {
|
||||
.color(Some(health_col))
|
||||
.top_left_with_margins_on(state.ids.hp_alignment, 0.0, 0.0)
|
||||
.set(state.ids.hp_filling, ui);
|
||||
let decayed_health = 1.0 - self.health.maximum() as f64 / self.health.base_max() as f64;
|
||||
if decayed_health > 0.0 {
|
||||
Image::new(self.imgs.bar_content)
|
||||
.w_h(480.0 * decayed_health, 18.0)
|
||||
.color(Some(BLACK))
|
||||
.top_right_with_margins_on(state.ids.hp_alignment, 0.0, 0.0)
|
||||
.set(state.ids.hp_decayed, ui);
|
||||
}
|
||||
Image::new(self.imgs.health_frame)
|
||||
.w_h(484.0, 24.0)
|
||||
.color(Some(UI_HIGHLIGHT_0))
|
||||
|
Loading…
Reference in New Issue
Block a user