Extract 'create_debuff_widget' function from 'update'

This commit is contained in:
Dr. Dystopia 2021-06-10 13:47:10 +02:00
parent 1d70b76ff0
commit d58d7205b2

View File

@ -356,25 +356,16 @@ impl<'a> Widget for BuffsBar<'a> {
max_duration max_duration
.map_or(1000.0, |max| cur.as_secs_f32() / max.as_secs_f32() * 1000.0) .map_or(1000.0, |max| cur.as_secs_f32() / max.as_secs_f32() * 1000.0)
}) as u32; }) as u32;
let buff_img = hud::get_buff_image(buff.kind, self.imgs); self.create_debuff_widget(
let buff_widget = Image::new(buff_img).w_h(40.0, 40.0); state,
// Sort buffs into rows of 6 slots ui,
let x = i % 6; pulsating_col,
let y = i / 6; norm_col,
let buff_widget = buff_widget.top_right_with_margins_on( i,
state.ids.align, id,
0.0 + y as f64 * (54.0), buff,
0.0 + x as f64 * (42.0), current_duration,
); );
buff_widget
.color(
if current_duration.map_or(false, |cur| cur.as_secs_f32() < 10.0) {
Some(pulsating_col)
} else {
Some(norm_col)
},
)
.set(*id, ui);
// Create Buff tooltip // Create Buff tooltip
let title = hud::get_buff_title(buff.kind, localized_strings); let title = hud::get_buff_title(buff.kind, localized_strings);
let desc_txt = hud::get_buff_desc(buff.kind, buff.data, localized_strings); let desc_txt = hud::get_buff_desc(buff.kind, buff.data, localized_strings);
@ -452,6 +443,38 @@ impl<'a> BuffsBar<'a> {
.set(*id, ui); .set(*id, ui);
} }
fn create_debuff_widget(
&self,
state: &State,
ui: &mut UiCell,
pulsating_col: Color,
norm_col: Color,
i: usize,
id: &conrod_core::widget::id::Id,
buff: &BuffInfo,
current_duration: Option<Duration>,
) {
let buff_img = hud::get_buff_image(buff.kind, self.imgs);
let buff_widget = Image::new(buff_img).w_h(40.0, 40.0);
// Sort buffs into rows of 6 slots
let x = i % 6;
let y = i / 6;
let buff_widget = buff_widget.top_right_with_margins_on(
state.ids.align,
y as f64 * (54.0),
x as f64 * (42.0),
);
buff_widget
.color(
if current_duration.map_or(false, |cur| cur.as_secs_f32() < 10.0) {
Some(pulsating_col)
} else {
Some(norm_col)
},
)
.set(*id, ui);
}
fn get_duration_image(&self, duration_percentage: u32) -> Id { fn get_duration_image(&self, duration_percentage: u32) -> Id {
match duration_percentage as u64 { match duration_percentage as u64 {
875..=1000 => self.imgs.nothing, // 8/8 875..=1000 => self.imgs.nothing, // 8/8