Merge branch 'display-best-times' into master
This commit is contained in:
commit
075084cbdf
@ -1,6 +1,6 @@
|
||||
use std::ops::{Div, Sub};
|
||||
use std::{collections::hash_map::Iter, iter::Enumerate, ops::{Div, Sub}};
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
use chrono::{DateTime, Duration, Utc};
|
||||
use dirty_fsm::{Action, ActionFlag};
|
||||
use discord_sdk::activity::{ActivityBuilder, Assets};
|
||||
use pkg_version::pkg_version_major;
|
||||
@ -27,6 +27,7 @@ pub struct MainMenuScreen {
|
||||
is_htp_pressed: bool, //Is how to play button pressed
|
||||
is_options_pressed: bool, //Is options button pressed
|
||||
is_quit_pressed: bool, //Is quit button pressed
|
||||
level_times: Option<Vec<(usize, (usize, i64))>>
|
||||
}
|
||||
|
||||
impl MainMenuScreen {
|
||||
@ -37,6 +38,7 @@ impl MainMenuScreen {
|
||||
is_htp_pressed: false,
|
||||
is_options_pressed: false,
|
||||
is_quit_pressed: false,
|
||||
level_times: None
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -70,6 +72,9 @@ impl Action<Scenes, ScreenError, GameContext> for MainMenuScreen {
|
||||
trace!("execute() called on MainMenuScreen");
|
||||
self.render_screen_space(&mut context.renderer.borrow_mut(), &context.config);
|
||||
|
||||
|
||||
self.level_times = Some(context.player_progress.level_best_times.iter().map(|x| (*x.0, *x.1)).collect::<Vec<(_,_)>>().iter().map(|x| *x).enumerate().collect());
|
||||
|
||||
if self.is_start_pressed {
|
||||
context
|
||||
.flag_send
|
||||
@ -128,6 +133,8 @@ impl ScreenSpaceRender for MainMenuScreen {
|
||||
config.colors.white,
|
||||
);
|
||||
|
||||
|
||||
|
||||
// Calculate the logo position
|
||||
let screen_size = raylib.get_screen_size();
|
||||
|
||||
@ -280,6 +287,28 @@ impl ScreenSpaceRender for MainMenuScreen {
|
||||
Color::WHITE,
|
||||
);
|
||||
};
|
||||
|
||||
// Best Times
|
||||
raylib.draw_text(
|
||||
"BEST TIMES",
|
||||
screen_size.x as i32 - 200,
|
||||
40,
|
||||
25,
|
||||
Color::DARKGRAY,
|
||||
);
|
||||
|
||||
if let Some(times) = &self.level_times{
|
||||
for (i, (level, time)) in times.iter() {
|
||||
let time = Duration::seconds(*time);
|
||||
raylib.draw_text(
|
||||
&format!("Lvl {} {}:{}", level + 1, time.num_minutes(), time.num_seconds() % 60),
|
||||
screen_size.x as i32 - 200,
|
||||
100 + (25 * (*i as i32)),
|
||||
20,
|
||||
Color::DARKGRAY,
|
||||
);
|
||||
}
|
||||
}
|
||||
self.is_quit_pressed = mouse_pressed && hovering_quit;
|
||||
|
||||
// for
|
||||
|
@ -69,6 +69,7 @@ impl Action<Scenes, ScreenError, GameContext> for WinScreen {
|
||||
.flag_send
|
||||
.send(Some(ControlFlag::SoundTrigger("button-press".to_string())))
|
||||
.unwrap();
|
||||
context.flag_send.send(Some(ControlFlag::SwitchLevel(0))).unwrap();
|
||||
Ok(ActionFlag::SwitchState(Scenes::MainMenuScreen))
|
||||
} else {
|
||||
Ok(ActionFlag::Continue)
|
||||
@ -79,6 +80,7 @@ impl Action<Scenes, ScreenError, GameContext> for WinScreen {
|
||||
debug!("Finished WinScreen");
|
||||
self.is_menu_pressed = false;
|
||||
self.counter = 0;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user