Merge branch 'tygyh/Extract-get-duration-image-from-update' into 'master'

Extract 'get_duration_image' function from 'update'

See merge request veloren/veloren!2407
This commit is contained in:
Marcel 2021-06-09 14:08:38 +00:00
commit f255f01ac0

View File

@ -12,6 +12,7 @@ use crate::{
use common::comp::{BuffKind, Buffs, Energy, Health}; use common::comp::{BuffKind, Buffs, Energy, Health};
use conrod_core::{ use conrod_core::{
color, color,
image::Id,
widget::{self, Button, Image, Rectangle, Text}, widget::{self, Button, Image, Rectangle, Text},
widget_ids, Color, Colorable, Positionable, Sizeable, Widget, WidgetCommon, widget_ids, Color, Colorable, Positionable, Sizeable, Widget, WidgetCommon,
}; };
@ -230,28 +231,18 @@ impl<'a> Widget for BuffsBar<'a> {
let click_to_remove = format!("<{}>", &localized_strings.get("buff.remove")); let click_to_remove = format!("<{}>", &localized_strings.get("buff.remove"));
let desc = format!("{}\n\n{}\n\n{}", desc_txt, remaining_time, click_to_remove); let desc = format!("{}\n\n{}\n\n{}", desc_txt, remaining_time, click_to_remove);
// Timer overlay // Timer overlay
if Button::image(match duration_percentage as u64 { if Button::image(self.get_duration_image(duration_percentage))
875..=1000 => self.imgs.nothing, // 8/8 .w_h(40.0, 40.0)
750..=874 => self.imgs.buff_0, // 7/8 .middle_of(*id)
625..=749 => self.imgs.buff_1, // 6/8 .with_tooltip(
500..=624 => self.imgs.buff_2, // 5/8 self.tooltip_manager,
375..=499 => self.imgs.buff_3, // 4/8 title,
250..=374 => self.imgs.buff_4, //3/8 &desc,
125..=249 => self.imgs.buff_5, // 2/8 &buffs_tooltip,
0..=124 => self.imgs.buff_6, // 1/8 BUFF_COLOR,
_ => self.imgs.nothing, )
}) .set(*timer_id, ui)
.w_h(40.0, 40.0) .was_clicked()
.middle_of(*id)
.with_tooltip(
self.tooltip_manager,
title,
&desc,
&buffs_tooltip,
BUFF_COLOR,
)
.set(*timer_id, ui)
.was_clicked()
{ {
event.push(Event::RemoveBuff(buff.kind)); event.push(Event::RemoveBuff(buff.kind));
}; };
@ -310,27 +301,17 @@ impl<'a> Widget for BuffsBar<'a> {
let desc_txt = hud::get_buff_desc(debuff.kind, debuff.data, localized_strings); let desc_txt = hud::get_buff_desc(debuff.kind, debuff.data, localized_strings);
let remaining_time = hud::get_buff_time(*debuff); let remaining_time = hud::get_buff_time(*debuff);
let desc = format!("{}\n\n{}", desc_txt, remaining_time); let desc = format!("{}\n\n{}", desc_txt, remaining_time);
Image::new(match duration_percentage as u64 { Image::new(self.get_duration_image(duration_percentage))
875..=1000 => self.imgs.nothing, // 8/8 .w_h(40.0, 40.0)
750..=874 => self.imgs.buff_0, // 7/8 .middle_of(*id)
625..=749 => self.imgs.buff_1, // 6/8 .with_tooltip(
500..=624 => self.imgs.buff_2, // 5/8 self.tooltip_manager,
375..=499 => self.imgs.buff_3, // 4/8 title,
250..=374 => self.imgs.buff_4, //3/8 &desc,
125..=249 => self.imgs.buff_5, // 2/8 &buffs_tooltip,
0..=124 => self.imgs.buff_6, // 1/8 DEBUFF_COLOR,
_ => self.imgs.nothing, )
}) .set(*timer_id, ui);
.w_h(40.0, 40.0)
.middle_of(*id)
.with_tooltip(
self.tooltip_manager,
title,
&desc,
&buffs_tooltip,
DEBUFF_COLOR,
)
.set(*timer_id, ui);
}); });
} }
@ -412,32 +393,22 @@ impl<'a> Widget for BuffsBar<'a> {
desc_txt.to_string() desc_txt.to_string()
}; };
// Timer overlay // Timer overlay
if Button::image(match duration_percentage as u64 { if Button::image(self.get_duration_image(duration_percentage))
875..=1000 => self.imgs.nothing, // 8/8 .w_h(40.0, 40.0)
750..=874 => self.imgs.buff_0, // 7/8 .middle_of(*id)
625..=749 => self.imgs.buff_1, // 6/8 .with_tooltip(
500..=624 => self.imgs.buff_2, // 5/8 self.tooltip_manager,
375..=499 => self.imgs.buff_3, // 4/8 title,
250..=374 => self.imgs.buff_4, // 3/8 &desc,
125..=249 => self.imgs.buff_5, // 2/8 &buffs_tooltip,
0..=124 => self.imgs.buff_6, // 1/8 if buff.is_buff {
_ => self.imgs.nothing, BUFF_COLOR
}) } else {
.w_h(40.0, 40.0) DEBUFF_COLOR
.middle_of(*id) },
.with_tooltip( )
self.tooltip_manager, .set(*timer_id, ui)
title, .was_clicked()
&desc,
&buffs_tooltip,
if buff.is_buff {
BUFF_COLOR
} else {
DEBUFF_COLOR
},
)
.set(*timer_id, ui)
.was_clicked()
{ {
event.push(Event::RemoveBuff(buff.kind)); event.push(Event::RemoveBuff(buff.kind));
} }
@ -453,3 +424,19 @@ impl<'a> Widget for BuffsBar<'a> {
event event
} }
} }
impl<'a> BuffsBar<'a> {
fn get_duration_image(&self, duration_percentage: u32) -> Id {
match duration_percentage as u64 {
875..=1000 => self.imgs.nothing, // 8/8
750..=874 => self.imgs.buff_0, // 7/8
625..=749 => self.imgs.buff_1, // 6/8
500..=624 => self.imgs.buff_2, // 5/8
375..=499 => self.imgs.buff_3, // 4/8
250..=374 => self.imgs.buff_4, // 3/8
125..=249 => self.imgs.buff_5, // 2/8
0..=124 => self.imgs.buff_6, // 1/8
_ => self.imgs.nothing,
}
}
}