From 0f3d6b3e3eb97edc6a3edd6ba7e8fcc038c67d42 Mon Sep 17 00:00:00 2001 From: kitswas <90329875+kitswas@users.noreply.github.com> Date: Thu, 1 Sep 2022 15:09:08 +0530 Subject: [PATCH] Poisebar for the player --- voxygen/src/hud/img_ids.rs | 2 + voxygen/src/hud/mod.rs | 12 ++++- voxygen/src/hud/skillbar.rs | 87 +++++++++++++++++++++++++++++++------ 3 files changed, 87 insertions(+), 14 deletions(-) diff --git a/voxygen/src/hud/img_ids.rs b/voxygen/src/hud/img_ids.rs index 7d55e98875..3dcb8f6622 100644 --- a/voxygen/src/hud/img_ids.rs +++ b/voxygen/src/hud/img_ids.rs @@ -339,6 +339,8 @@ image_ids! { decayed_bg: "voxygen.element.ui.skillbar.decayed_bg", energy_bg: "voxygen.element.ui.skillbar.energy_bg", energy_frame: "voxygen.element.ui.skillbar.energy_frame", + poise_bg: "voxygen.element.ui.skillbar.energy_bg", + poise_frame: "voxygen.element.ui.skillbar.energy_frame", m1_ico: "voxygen.element.ui.generic.icons.m1", m2_ico: "voxygen.element.ui.generic.icons.m2", m_scroll_ico: "voxygen.element.ui.generic.icons.m_scroll", diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index de90b4a5bb..f96c2bbe0c 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -145,6 +145,7 @@ const CRITICAL_HP_COLOR: Color = Color::Rgba(0.79, 0.19, 0.17, 1.0); const STAMINA_COLOR: Color = Color::Rgba(0.29, 0.62, 0.75, 0.9); const ENEMY_HP_COLOR: Color = Color::Rgba(0.93, 0.1, 0.29, 1.0); const XP_COLOR: Color = Color::Rgba(0.59, 0.41, 0.67, 1.0); +const POISE_COLOR: Color = Color::Rgba(0.70, 0.0, 0.50, 1.0); //const TRANSPARENT: Color = Color::Rgba(0.0, 0.0, 0.0, 0.0); //const FOCUS_COLOR: Color = Color::Rgba(1.0, 0.56, 0.04, 1.0); //const RAGE_COLOR: Color = Color::Rgba(0.5, 0.04, 0.13, 1.0); @@ -2727,10 +2728,18 @@ impl Hud { }); self.floaters.combo_floater = self.floaters.combo_floater.filter(|f| f.timer > 0_f64); - if let (Some(health), Some(inventory), Some(energy), Some(skillset), Some(body)) = ( + if let ( + Some(health), + Some(inventory), + Some(energy), + Some(poise), + Some(skillset), + Some(body), + ) = ( healths.get(entity), inventories.get(entity), energies.get(entity), + poises.get(entity), skillsets.get(entity), bodies.get(entity), ) { @@ -2745,6 +2754,7 @@ impl Hud { health, inventory, energy, + poise, skillset, active_abilities.get(entity), body, diff --git a/voxygen/src/hud/skillbar.rs b/voxygen/src/hud/skillbar.rs index d9e0ac459f..0697112865 100644 --- a/voxygen/src/hud/skillbar.rs +++ b/voxygen/src/hud/skillbar.rs @@ -3,7 +3,7 @@ use super::{ img_ids::{Imgs, ImgsRot}, item_imgs::ItemImgs, slots, util, BarNumbers, HudInfo, ShortcutNumbers, BLACK, CRITICAL_HP_COLOR, HP_COLOR, - LOW_HP_COLOR, QUALITY_EPIC, STAMINA_COLOR, TEXT_COLOR, UI_HIGHLIGHT_0, + LOW_HP_COLOR, POISE_COLOR, QUALITY_EPIC, STAMINA_COLOR, TEXT_COLOR, UI_HIGHLIGHT_0, }; use crate::{ game_input::GameInput, @@ -24,7 +24,7 @@ use common::comp::{ self, ability::AbilityInput, item::{ItemDesc, MaterialStatManifest}, - Ability, ActiveAbilities, Body, Energy, Health, Inventory, SkillSet, + Ability, ActiveAbilities, Body, Energy, Health, Inventory, Poise, SkillSet, }; use conrod_core::{ color, @@ -57,6 +57,8 @@ widget_ids! { frame_health, bg_energy, frame_energy, + bg_poise, + frame_poise, m1_ico, m2_ico, // Level @@ -79,6 +81,12 @@ widget_ids! { energy_txt_alignment, energy_txt_bg, energy_txt, + // Poise-Bar + poise_alignment, + poise_filling, + poise_txt_alignment, + poise_txt_bg, + poise_txt, // Combo Counter combo_align, combo_bg, @@ -251,6 +259,7 @@ pub struct Skillbar<'a> { health: &'a Health, inventory: &'a Inventory, energy: &'a Energy, + poise: &'a Poise, skillset: &'a SkillSet, active_abilities: Option<&'a ActiveAbilities>, body: &'a Body, @@ -281,6 +290,7 @@ impl<'a> Skillbar<'a> { health: &'a Health, inventory: &'a Inventory, energy: &'a Energy, + poise: &'a Poise, skillset: &'a SkillSet, active_abilities: Option<&'a ActiveAbilities>, body: &'a Body, @@ -306,6 +316,7 @@ impl<'a> Skillbar<'a> { health, inventory, energy, + poise, skillset, active_abilities, body, @@ -365,16 +376,18 @@ impl<'a> Skillbar<'a> { } fn show_stat_bars(&self, state: &State, ui: &mut UiCell) { - let (hp_percentage, energy_percentage): (f64, f64) = if self.health.is_dead { - (0.0, 0.0) - } else { - let max_hp = f64::from(self.health.base_max().max(self.health.maximum())); - let current_hp = f64::from(self.health.current()); - ( - current_hp / max_hp * 100.0, - f64::from(self.energy.fraction() * 100.0), - ) - }; + let (hp_percentage, energy_percentage, poise_percentage): (f64, f64, f64) = + if self.health.is_dead { + (0.0, 0.0, 0.0) + } else { + let max_hp = f64::from(self.health.base_max().max(self.health.maximum())); + let current_hp = f64::from(self.health.current()); + ( + current_hp / max_hp * 100.0, + f64::from(self.energy.fraction() * 100.0), + f64::from(self.poise.fraction() * 100.0), + ) + }; // Animation timer let hp_ani = (self.pulse * 4.0/* speed factor */).cos() * 0.5 + 0.8; @@ -384,6 +397,8 @@ impl<'a> Skillbar<'a> { || (self.health.current() - self.health.maximum()).abs() > Health::HEALTH_EPSILON; let show_energy = self.global_state.settings.interface.always_show_bars || (self.energy.current() - self.energy.maximum()).abs() > Energy::ENERGY_EPSILON; + let show_poise = self.global_state.settings.interface.always_show_bars + || (self.poise.current() - self.poise.maximum()).abs() > Poise::POISE_EPSILON; let decayed_health = 1.0 - self.health.maximum() as f64 / self.health.base_max() as f64; if show_health && !self.health.is_dead || decayed_health > 0.0 { @@ -452,6 +467,30 @@ impl<'a> Skillbar<'a> { .middle_of(state.ids.bg_energy) .set(state.ids.frame_energy, ui); } + if show_poise && !self.health.is_dead { + let offset = if show_health || decayed_health > 0.0 { + 70.0 + } else { + 1.0 + }; + Image::new(self.imgs.poise_bg) + .w_h(323.0, 14.0) + .mid_top_with_margin_on(state.ids.frame, -offset) + .set(state.ids.bg_poise, ui); + Rectangle::fill_with([319.0, 10.0], color::TRANSPARENT) + .top_left_with_margins_on(state.ids.bg_poise, 2.0, 2.0) + .set(state.ids.poise_alignment, ui); + Image::new(self.imgs.bar_content) + .w_h(319.0 * poise_percentage / 100.0, 10.0) + .color(Some(POISE_COLOR)) + .top_left_with_margins_on(state.ids.poise_alignment, 0.0, 0.0) + .set(state.ids.poise_filling, ui); + Image::new(self.imgs.poise_frame) + .w_h(323.0, 16.0) + .color(Some(UI_HIGHLIGHT_0)) + .middle_of(state.ids.bg_poise) + .set(state.ids.frame_poise, ui); + } // Bar Text let bar_text = if self.health.is_dead { Some(( @@ -461,6 +500,9 @@ impl<'a> Skillbar<'a> { self.localized_strings .get_msg("hud-group-dead") .into_owned(), + self.localized_strings + .get_msg("hud-group-dead") + .into_owned(), )) } else if let BarNumbers::Values = bar_values { Some(( @@ -475,16 +517,22 @@ impl<'a> Skillbar<'a> { self.energy.current().round() as u32, self.energy.maximum().round() as u32 ), + format!( + "{}/{}", + self.poise.current().round() as u32, + self.poise.maximum().round() as u32 + ), )) } else if let BarNumbers::Percent = bar_values { Some(( format!("{}%", hp_percentage as u32), format!("{}%", energy_percentage as u32), + format!("{}%", poise_percentage as u32), )) } else { None }; - if let Some((hp_txt, energy_txt)) = bar_text { + if let Some((hp_txt, energy_txt, poise_txt)) = bar_text { Text::new(&hp_txt) .middle_of(state.ids.frame_health) .font_size(self.fonts.cyri.scale(12)) @@ -510,6 +558,19 @@ impl<'a> Skillbar<'a> { .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.energy_txt, ui); + + Text::new(&poise_txt) + .middle_of(state.ids.frame_poise) + .font_size(self.fonts.cyri.scale(12)) + .font_id(self.fonts.cyri.conrod_id) + .color(Color::Rgba(0.0, 0.0, 0.0, 1.0)) + .set(state.ids.poise_txt_bg, ui); + Text::new(&poise_txt) + .bottom_left_with_margins_on(state.ids.poise_txt_bg, 2.0, 2.0) + .font_size(self.fonts.cyri.scale(12)) + .font_id(self.fonts.cyri.conrod_id) + .color(TEXT_COLOR) + .set(state.ids.poise_txt, ui); } }