1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use crate::*;
pub struct CombatText {
pub position: Vec2,
pub text: String,
pub color: Color,
pub size: f32,
}
impl CombatText {
pub fn new(position: Vec2, text: String, color: Color, size: f32) -> Self {
Self { position, text, color, size }
}
}
pub fn spawn_combat_text(
commands: &mut CommandBuffer,
text: String,
color: Color,
size: f32,
position: Vec2,
) {
commands.spawn((
CombatText::new(position, text, color, size),
DespawnAfter(COMBAT_TEXT_LIFETIME),
));
}
pub fn combat_text_system() {
for (_, (combat_text, lifetime)) in
world_mut().query_mut::<(&mut CombatText, &DespawnAfter)>()
{
let progress =
(COMBAT_TEXT_LIFETIME - lifetime.0) / COMBAT_TEXT_LIFETIME;
// let dims = measure_text(
// &combat_text.text,
// Some(c.font),
// font_size,
// font_scale,
// );
let off = 0.5;
// TODO: re-center
let pos = combat_text.position + vec2(0.0, 1.0) * progress + off;
// let pos = pos - vec2(dims.width / 2.0, dims.height / 2.0 + off);
// let screen_pos = world_to_screen(pos) / egui_scale_factor();
draw_text_ex(
&combat_text.text,
pos,
// screen_pos.x,
// screen_pos.y,
// pos.x,
// pos.y,
TextAlign::Center,
TextParams {
font: egui::FontId::new(16.0, egui::FontFamily::Proportional),
color: combat_text.color,
..Default::default()
},
);
}
}