Skip to content

Commit

Permalink
Fix timeout flag animations
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanDebrunner committed Jul 17, 2024
1 parent 01a20f2 commit 54f4fa7
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 146 deletions.
247 changes: 131 additions & 116 deletions overlay/src/pages/in_game.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,39 @@
use super::draw_texture_both;
use super::fit_text;
use super::Interpolate;
use super::PageRenderer;
use crate::pages::draw_text_both;
use crate::pages::draw_text_both_ex;
use crate::pages::draw_texture_both_ex;
use crate::pages::Justify;
use crate::State;
use super::{draw_texture_both, fit_text, Interpolate, PageRenderer};
use crate::{
pages::{draw_text_both, draw_text_both_ex, draw_texture_both_ex, Justify},
State,
};
use coarsetime::Instant;
use macroquad::prelude::*;
use uwh_common::game_snapshot::GamePeriod;
use uwh_common::game_snapshot::TimeoutSnapshot;
use uwh_common::game_snapshot::{GamePeriod, TimeoutSnapshot};

#[macro_export]
macro_rules! draw_timeout_flag {
($asset: expr, $timeout_offset: expr, $timeout_alpha_offset: expr, $width: literal) => {
draw_texture_both_ex!(
$asset,
580f32,
35f32,
Color {
a: $timeout_alpha_offset,
..WHITE
},
DrawTextureParams {
source: if $timeout_offset == 0f32 {
None
} else {
Some(Rect {
x: -$timeout_offset,
y: 0f32,
w: f32::max($timeout_offset + $width, 0f32),
h: 73f32,
})
},
..Default::default()
}
)
};
}

impl PageRenderer {
/// Display info during game play
Expand All @@ -28,12 +51,12 @@ impl PageRenderer {
self.last_snapshot_timeout = state.snapshot.timeout;
if time < 1f32 {
(
(0f32, -200f32).interpolate_linear(1f32 - time),
(0f32, -270f32).interpolate_linear(1f32 - time),
(0f32, 1f32).interpolate_exponential_end(time),
)
} else {
(
(0f32, -200f32).interpolate_linear(0f32),
(0f32, -270f32).interpolate_linear(0f32),
(0f32, 1f32).interpolate_exponential_end(1f32),
)
}
Expand All @@ -50,33 +73,30 @@ impl PageRenderer {
self.animation_register2 = Instant::now();
self.last_snapshot_timeout = TimeoutSnapshot::None;
(
(0f32, -200f32).interpolate_linear(1f32),
(0f32, -270f32).interpolate_linear(1f32),
(0f32, 1f32).interpolate_exponential_end(0f32),
)
} else {
(
(0f32, -200f32).interpolate_linear(time),
(0f32, -270f32).interpolate_linear(time),
(0f32, 1f32).interpolate_exponential_end(1f32 - time),
)
}
} else {
// return any values when both are None, cause we won't be redering anyways
(
(0f32, -200f32).interpolate_linear(0f32),
(0f32, -270f32).interpolate_linear(0f32),
(0f32, 1f32).interpolate_exponential_end(1f32),
)
};
match self.last_snapshot_timeout {
// draw text for each type of penalty
TimeoutSnapshot::Ref(_) => {
draw_texture_both!(
draw_timeout_flag!(
self.assets.referee_timout,
timeout_offset + 580f32,
35f32,
Color {
a: timeout_alpha_offset,
..WHITE
}
timeout_offset,
timeout_alpha_offset,
205f32
);
draw_text_both_ex!(
"REFEREE",
Expand Down Expand Up @@ -126,61 +146,60 @@ impl PageRenderer {
);
}
TimeoutSnapshot::White(time) => {
draw_texture_both!(
draw_timeout_flag!(
self.assets.white_timout,
timeout_offset + 580f32,
35f32,
Color {
a: timeout_alpha_offset,
..WHITE
}
);
draw_text_both_ex!(
"WHITE",
675f32 + timeout_offset,
67f32,
TextParams {
font: self.assets.font,
font_size: 20,
color: Color {
a: timeout_alpha_offset,
..BLACK
},
..Default::default()
},
TextParams {
font: self.assets.font,
font_size: 20,
color: Color {
a: timeout_alpha_offset,
..WHITE
},
..Default::default()
}
timeout_offset,
timeout_alpha_offset,
276f32
);
draw_text_both_ex!(
"TIMEOUT",
665f32 + timeout_offset,
95f32,
TextParams {
font: self.assets.font,
font_size: 20,
color: Color {
a: timeout_alpha_offset,
..BLACK
if timeout_offset > -175f32 {
draw_text_both_ex!(
"WHITE",
675f32 + timeout_offset,
67f32,
TextParams {
font: self.assets.font,
font_size: 20,
color: Color {
a: timeout_alpha_offset,
..BLACK
},
..Default::default()
},
..Default::default()
},
TextParams {
font: self.assets.font,
font_size: 20,
color: Color {
a: timeout_alpha_offset,
..WHITE
TextParams {
font: self.assets.font,
font_size: 20,
color: Color {
a: timeout_alpha_offset,
..WHITE
},
..Default::default()
}
);
draw_text_both_ex!(
"TIMEOUT",
665f32 + timeout_offset,
95f32,
TextParams {
font: self.assets.font,
font_size: 20,
color: Color {
a: timeout_alpha_offset,
..BLACK
},
..Default::default()
},
..Default::default()
}
);
TextParams {
font: self.assets.font,
font_size: 20,
color: Color {
a: timeout_alpha_offset,
..WHITE
},
..Default::default()
}
);
}
draw_text_both_ex!(
format!("{time}").as_str(),
773f32 + timeout_offset,
Expand All @@ -206,43 +225,42 @@ impl PageRenderer {
);
}
TimeoutSnapshot::Black(time) => {
draw_texture_both!(
draw_timeout_flag!(
self.assets.black_timout,
timeout_offset + 580f32,
35f32,
Color {
a: timeout_alpha_offset,
..WHITE
}
);
draw_text_both!(
"BLACK",
675f32 + timeout_offset,
67f32,
TextParams {
font: self.assets.font,
font_size: 20,
color: Color {
a: timeout_alpha_offset,
..WHITE
},
..Default::default()
}
);
draw_text_both!(
"TIMEOUT",
665f32 + timeout_offset,
95f32,
TextParams {
font: self.assets.font,
font_size: 20,
color: Color {
a: timeout_alpha_offset,
..WHITE
},
..Default::default()
}
timeout_offset,
timeout_alpha_offset,
276f32
);
if timeout_offset > -175f32 {
draw_text_both!(
"BLACK",
675f32 + timeout_offset,
67f32,
TextParams {
font: self.assets.font,
font_size: 20,
color: Color {
a: timeout_alpha_offset,
..WHITE
},
..Default::default()
}
);
draw_text_both!(
"TIMEOUT",
665f32 + timeout_offset,
95f32,
TextParams {
font: self.assets.font,
font_size: 20,
color: Color {
a: timeout_alpha_offset,
..WHITE
},
..Default::default()
}
);
}
draw_text_both!(
format!("{time}").as_str(),
773f32 + timeout_offset,
Expand All @@ -259,14 +277,11 @@ impl PageRenderer {
);
}
TimeoutSnapshot::PenaltyShot(_) => {
draw_texture_both!(
draw_timeout_flag!(
self.assets.penalty,
timeout_offset + 580f32,
35f32,
Color {
a: timeout_alpha_offset,
..WHITE
}
timeout_offset,
timeout_alpha_offset,
205f32
);
draw_text_both_ex!(
"PENALTY",
Expand Down
Loading

0 comments on commit 54f4fa7

Please sign in to comment.