From 345ef1ca2280227d4316c0b955150907c7eff209 Mon Sep 17 00:00:00 2001 From: Monty Date: Sat, 27 Mar 2021 23:02:20 +0100 Subject: [PATCH] decay display for groups and overhead bars --- .../voxygen/element/skillbar/decayed_bg.png | 4 +- voxygen/src/hud/group.rs | 21 +++++++- voxygen/src/hud/overhead.rs | 54 +++++++++++++++---- 3 files changed, 65 insertions(+), 14 deletions(-) diff --git a/assets/voxygen/element/skillbar/decayed_bg.png b/assets/voxygen/element/skillbar/decayed_bg.png index 1af7c7b9eb..ea5ffc7085 100644 --- a/assets/voxygen/element/skillbar/decayed_bg.png +++ b/assets/voxygen/element/skillbar/decayed_bg.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6f30c8f37d45cbc7cce792fe2f15593b51498a056ce04ff1a8e3d9763d118e06 -size 4317 +oid sha256:bfdb2cf3daf1c7576b52064644b1b684a4097a093c49cea72d314ff1fbc7300e +size 306 diff --git a/voxygen/src/hud/group.rs b/voxygen/src/hud/group.rs index d1891b2e5d..f731600eb6 100644 --- a/voxygen/src/hud/group.rs +++ b/voxygen/src/hud/group.rs @@ -2,7 +2,8 @@ use super::{ cr_color, img_ids::{Imgs, ImgsRot}, Show, BLACK, BUFF_COLOR, DEBUFF_COLOR, ERROR_COLOR, GROUP_COLOR, HP_COLOR, KILL_COLOR, - LOW_HP_COLOR, STAMINA_COLOR, TEXT_COLOR, TEXT_COLOR_GREY, UI_HIGHLIGHT_0, UI_MAIN, + LOW_HP_COLOR, QUALITY_EPIC, STAMINA_COLOR, TEXT_COLOR, TEXT_COLOR_GREY, UI_HIGHLIGHT_0, + UI_MAIN, }; use crate::{ @@ -51,6 +52,7 @@ widget_ids! { member_panels_txt_bg[], member_panels_txt[], member_health[], + member_health_decay[], member_stam[], buffs[], buff_timers[], @@ -287,6 +289,13 @@ impl<'a> Widget for Group<'a> { .resize(group_size, &mut ui.widget_id_generator()); }) }; + if state.ids.member_health_decay.len() < group_size { + state.update(|s| { + s.ids + .member_health_decay + .resize(group_size, &mut ui.widget_id_generator()); + }) + }; if state.ids.member_stam.len() < group_size { state.update(|s| { s.ids @@ -395,6 +404,16 @@ 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); + // Health Decay + let decayed_health = 1.0 - health.maximum() as f64 / health.base_max() as f64; + if decayed_health > 0.0 { + let decay_bar_len = 148.0 * decayed_health * 0.5; + Image::new(self.imgs.bar_content) + .w_h(decay_bar_len, 22.0) + .color(Some(QUALITY_EPIC)) + .top_right_with_margins_on(state.ids.member_panels_bg[i], 2.0, 2.0) + .set(state.ids.member_health_decay[i], ui); + } if health.is_dead { // Death Text Text::new(&self.localized_strings.get("hud.group.dead")) diff --git a/voxygen/src/hud/overhead.rs b/voxygen/src/hud/overhead.rs index cfeced24ee..4c2a2bd5e6 100644 --- a/voxygen/src/hud/overhead.rs +++ b/voxygen/src/hud/overhead.rs @@ -1,7 +1,7 @@ use super::{ cr_color, img_ids::Imgs, DEFAULT_NPC, ENEMY_HP_COLOR, FACTION_COLOR, GROUP_COLOR, GROUP_MEMBER, - HP_COLOR, LOW_HP_COLOR, REGION_COLOR, SAY_COLOR, STAMINA_COLOR, TELL_COLOR, TEXT_BG, - TEXT_COLOR, + HP_COLOR, LOW_HP_COLOR, QUALITY_EPIC, REGION_COLOR, SAY_COLOR, STAMINA_COLOR, TELL_COLOR, + TEXT_BG, TEXT_COLOR, }; use crate::{ hud::{get_buff_image, get_buff_info}, @@ -16,6 +16,7 @@ use conrod_core::{ widget::{self, Image, Rectangle, Text}, widget_ids, Color, Colorable, Positionable, Sizeable, Widget, WidgetCommon, }; +use inline_tweak::*; const MAX_BUBBLE_WIDTH: f64 = 250.0; widget_ids! { struct Ids { @@ -42,6 +43,7 @@ widget_ids! { level, level_skull, health_bar, + decay_bar, health_bar_bg, health_txt, mana_bar, @@ -67,7 +69,10 @@ pub struct Info<'a> { pub fn should_show_healthbar(health: &Health) -> bool { health.current() != health.maximum() || health.current() < health.base_max() } - +/// Determines if there is decayed health being applied +pub fn decayed_health_displayed(health: &Health) -> bool { + (1.0 - health.maximum() as f64 / health.base_max() as f64) > 0.0 +} /// ui widget containing everything that goes over a character's head /// (Speech bubble, Name, Level, HP/energy bars, etc.) #[derive(WidgetCommon)] @@ -147,6 +152,11 @@ impl<'a> Ingameable for Overhead<'a> { } else { 0 } + + if info.health.map_or(false, |h| decayed_health_displayed(h)) { + 1 + } else { + 0 + } }) + if self.bubble.is_some() { 13 } else { 0 } } } @@ -300,18 +310,20 @@ impl<'a> Widget for Overhead<'a> { .set(state.ids.name, ui); match health { - Some(health) if should_show_healthbar(health) => { + Some(health) + if should_show_healthbar(health) || decayed_health_displayed(health) => + { // Show HP Bar let hp_ani = (self.pulse * 4.0/* speed factor */).cos() * 0.5 + 1.0; //Animation timer let crit_hp_color: Color = Color::Rgba(0.93, 0.59, 0.03, hp_ani); - + let decayed_health = 1.0 - health.maximum() as f64 / health.base_max() as f64; // Background Image::new(if self.in_group {self.imgs.health_bar_group_bg} else {self.imgs.enemy_health_bg}) - .w_h(84.0 * BARSIZE, 10.0 * BARSIZE) - .x_y(0.0, MANA_BAR_Y + 6.5) //-25.5) - .color(Some(Color::Rgba(0.1, 0.1, 0.1, 0.8))) - .parent(id) - .set(state.ids.health_bar_bg, ui); + .w_h(84.0 * BARSIZE, 10.0 * BARSIZE) + .x_y(0.0, MANA_BAR_Y + 6.5) //-25.5) + .color(Some(Color::Rgba(0.1, 0.1, 0.1, 0.8))) + .parent(id) + .set(state.ids.health_bar_bg, ui); // % HP Filling let size_factor = (hp_percentage / 100.0) * BARSIZE; @@ -341,6 +353,26 @@ impl<'a> Widget for Overhead<'a> { }) .parent(id) .set(state.ids.health_bar, ui); + + if decayed_health > 0.0 { + let x_decayed = if self.in_group { + (tweak!(0.0) + (decayed_health / 100.0 * tweak!(41.0) - tweak!(41.0))) + * BARSIZE + } else { + (tweak!(-4.5) + + (decayed_health / 100.0 * tweak!(36.45) - tweak!(36.45))) + * BARSIZE + }; + + let decay_bar_len = + decayed_health * 0.5 * if self.in_group { 82.0 } else { 73.0 }; + Image::new(self.imgs.enemy_bar) + .w_h(decay_bar_len, h) + .x_y(x_decayed * tweak!(-1.0), MANA_BAR_Y + 8.0) + .color(Some(QUALITY_EPIC)) + .parent(id) + .set(state.ids.decay_bar, ui); + } let mut txt = format!("{}/{}", health_cur_txt, health_max_txt); if health.is_dead { txt = self.i18n.get("hud.group.dead").to_string() @@ -411,7 +443,7 @@ impl<'a> Widget for Overhead<'a> { .parent(id) .set(state.ids.level, ui); } - }, + } _ => {}, } }