Colour reflects old poise state

This commit is contained in:
kitswas 2022-09-04 10:23:07 +05:30
parent 6ff5f540bf
commit e29a9f4e36
2 changed files with 34 additions and 8 deletions

View File

@ -54,7 +54,9 @@ pub struct Poise {
/// Rate of poise regeneration per tick. Starts at zero and accelerates.
pub regen_rate: f32,
/// Time that entity was last in a poise state
last_stun_time: Option<Time>,
pub last_stun_time: Option<Time>,
/// The previous poise state
pub previous_state: PoiseState,
/// Next threshold for the poise change
next_threshold: f32,
}
@ -148,7 +150,7 @@ impl Poise {
const MAX_SCALED_POISE: u32 = Self::MAX_POISE as u32 * Self::SCALING_FACTOR_INT;
/// The amount of time after being in a poise state before you can take
/// poise damage again
const POISE_BUFFER_TIME: f64 = 1.0;
pub const POISE_BUFFER_TIME: f64 = 1.0;
/// Used when comparisons to poise are needed outside this module.
// This value is chosen as anything smaller than this is more precise than our
// units of poise.
@ -195,6 +197,7 @@ impl Poise {
regen_rate: 0.0,
last_stun_time: None,
next_threshold: self::Poise::POISE_THRESHOLDS[0],
previous_state: PoiseState::Normal,
}
}
@ -202,6 +205,9 @@ impl Poise {
match self.last_stun_time {
Some(last_time) if last_time.0 + Poise::POISE_BUFFER_TIME > change.time.0 => {},
_ => {
// if self.previous_state != self.poise_state() {
self.previous_state = self.poise_state();
// };
self.current = (((self.current() + change.amount)
.clamp(0.0, f32::from(Self::MAX_POISE))
* Self::SCALING_FACTOR_FLOAT) as u32)

View File

@ -21,11 +21,14 @@ use i18n::Localization;
use std::borrow::Cow;
use client::{self, Client};
use common::comp::{
self,
ability::AbilityInput,
item::{ItemDesc, MaterialStatManifest},
Ability, ActiveAbilities, Body, Energy, Health, Inventory, Poise, PoiseState, SkillSet,
use common::{
comp::{
self,
ability::AbilityInput,
item::{ItemDesc, MaterialStatManifest},
Ability, ActiveAbilities, Body, Energy, Health, Inventory, Poise, PoiseState, SkillSet,
},
resources::Time,
};
use conrod_core::{
color,
@ -482,7 +485,22 @@ impl<'a> Skillbar<'a> {
state.ids.poise_tick_4,
];
let poise_colour = match self.poise.poise_state() {
// println!(.poise
// .last_stun_time
// .unwrap_or(Time(self::Poise::POISE_BUFFER_TIME))
// .0);
// let poise_state = if self
// .poise
// .last_stun_time
// .unwrap_or(Time(self::Poise::POISE_BUFFER_TIME))
// .0
// >= 2.0
// {
// self.poise.poise_state()
// } else {
// self.poise.previous_state
// };
let poise_colour = match self.poise.previous_state {
self::PoiseState::KnockedDown => BLACK,
self::PoiseState::Dazed => Color::Rgba(0.25, 0.0, 0.15, 1.0),
self::PoiseState::Stunned => Color::Rgba(0.40, 0.0, 0.30, 1.0),
@ -502,6 +520,8 @@ impl<'a> Skillbar<'a> {
.color(Some(poise_colour))
.top_left_with_margins_on(state.ids.poise_alignment, 0.0, 0.0)
.set(state.ids.poise_filling, ui);
// (ui.widget_graph().node(state.ids.poise_filling).unwrap().clone() as
// Image).color(color) ;
for (i, threshold) in self::Poise::POISE_THRESHOLDS.iter().enumerate() {
Image::new(self.imgs.poise_tick)
.w_h(3.0, 10.0)