display best times
This commit is contained in:
parent
8a911eaacf
commit
776e190d30
@ -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 dirty_fsm::{Action, ActionFlag};
|
||||||
use discord_sdk::activity::{ActivityBuilder, Assets};
|
use discord_sdk::activity::{ActivityBuilder, Assets};
|
||||||
use pkg_version::pkg_version_major;
|
use pkg_version::pkg_version_major;
|
||||||
@ -27,6 +27,7 @@ pub struct MainMenuScreen {
|
|||||||
is_htp_pressed: bool, //Is how to play button pressed
|
is_htp_pressed: bool, //Is how to play button pressed
|
||||||
is_options_pressed: bool, //Is options button pressed
|
is_options_pressed: bool, //Is options button pressed
|
||||||
is_quit_pressed: bool, //Is quit button pressed
|
is_quit_pressed: bool, //Is quit button pressed
|
||||||
|
level_times: Option<Vec<(usize, (usize, i64))>>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MainMenuScreen {
|
impl MainMenuScreen {
|
||||||
@ -37,6 +38,7 @@ impl MainMenuScreen {
|
|||||||
is_htp_pressed: false,
|
is_htp_pressed: false,
|
||||||
is_options_pressed: false,
|
is_options_pressed: false,
|
||||||
is_quit_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");
|
trace!("execute() called on MainMenuScreen");
|
||||||
self.render_screen_space(&mut context.renderer.borrow_mut(), &context.config);
|
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 {
|
if self.is_start_pressed {
|
||||||
Ok(ActionFlag::SwitchState(Scenes::InGameScene))
|
Ok(ActionFlag::SwitchState(Scenes::InGameScene))
|
||||||
} else if self.is_htp_pressed {
|
} else if self.is_htp_pressed {
|
||||||
@ -112,6 +117,8 @@ impl ScreenSpaceRender for MainMenuScreen {
|
|||||||
config.colors.white,
|
config.colors.white,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Calculate the logo position
|
// Calculate the logo position
|
||||||
let screen_size = raylib.get_screen_size();
|
let screen_size = raylib.get_screen_size();
|
||||||
|
|
||||||
@ -264,6 +271,28 @@ impl ScreenSpaceRender for MainMenuScreen {
|
|||||||
Color::WHITE,
|
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;
|
self.is_quit_pressed = mouse_pressed && hovering_quit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,17 +6,13 @@ use discord_sdk::activity::{ActivityBuilder, Assets};
|
|||||||
use pkg_version::pkg_version_major;
|
use pkg_version::pkg_version_major;
|
||||||
use raylib::prelude::*;
|
use raylib::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{GameConfig, context::{ControlFlag, GameContext}, utilities::{
|
||||||
context::GameContext,
|
|
||||||
utilities::{
|
|
||||||
datastore::{load_texture_from_internal_data, ResourceLoadError},
|
datastore::{load_texture_from_internal_data, ResourceLoadError},
|
||||||
game_version::get_version_string,
|
game_version::get_version_string,
|
||||||
math::interpolate_exp,
|
math::interpolate_exp,
|
||||||
non_ref_raylib::HackedRaylibHandle,
|
non_ref_raylib::HackedRaylibHandle,
|
||||||
render_layer::ScreenSpaceRender,
|
render_layer::ScreenSpaceRender,
|
||||||
},
|
}};
|
||||||
GameConfig,
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::{Scenes, ScreenError};
|
use super::{Scenes, ScreenError};
|
||||||
use tracing::{debug, error, info, trace};
|
use tracing::{debug, error, info, trace};
|
||||||
@ -69,6 +65,7 @@ impl Action<Scenes, ScreenError, GameContext> for WinScreen {
|
|||||||
self.counter += 1;
|
self.counter += 1;
|
||||||
|
|
||||||
if self.is_menu_pressed {
|
if self.is_menu_pressed {
|
||||||
|
context.flag_send.send(Some(ControlFlag::SwitchLevel(0))).unwrap();
|
||||||
Ok(ActionFlag::SwitchState(Scenes::MainMenuScreen))
|
Ok(ActionFlag::SwitchState(Scenes::MainMenuScreen))
|
||||||
} else {
|
} else {
|
||||||
Ok(ActionFlag::Continue)
|
Ok(ActionFlag::Continue)
|
||||||
@ -79,6 +76,7 @@ impl Action<Scenes, ScreenError, GameContext> for WinScreen {
|
|||||||
debug!("Finished WinScreen");
|
debug!("Finished WinScreen");
|
||||||
self.is_menu_pressed = false;
|
self.is_menu_pressed = false;
|
||||||
self.counter = 0;
|
self.counter = 0;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user