From 776e190d30e16a9b9eea5e1d95b22850628cb10b Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 3 Oct 2021 14:08:39 -0400 Subject: [PATCH] display best times --- game/src/scenes/main_menu_screen.rs | 33 +++++++++++++++++++++++++++-- game/src/scenes/win_screen.rs | 10 ++++----- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/game/src/scenes/main_menu_screen.rs b/game/src/scenes/main_menu_screen.rs index d32187e..62c2d5b 100644 --- a/game/src/scenes/main_menu_screen.rs +++ b/game/src/scenes/main_menu_screen.rs @@ -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> } 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 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::>().iter().map(|x| *x).enumerate().collect()); + if self.is_start_pressed { Ok(ActionFlag::SwitchState(Scenes::InGameScene)) } else if self.is_htp_pressed { @@ -112,6 +117,8 @@ impl ScreenSpaceRender for MainMenuScreen { config.colors.white, ); + + // Calculate the logo position let screen_size = raylib.get_screen_size(); @@ -264,6 +271,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; } } diff --git a/game/src/scenes/win_screen.rs b/game/src/scenes/win_screen.rs index dc2851f..5353068 100644 --- a/game/src/scenes/win_screen.rs +++ b/game/src/scenes/win_screen.rs @@ -6,17 +6,13 @@ use discord_sdk::activity::{ActivityBuilder, Assets}; use pkg_version::pkg_version_major; use raylib::prelude::*; -use crate::{ - context::GameContext, - utilities::{ +use crate::{GameConfig, context::{ControlFlag, GameContext}, utilities::{ datastore::{load_texture_from_internal_data, ResourceLoadError}, game_version::get_version_string, math::interpolate_exp, non_ref_raylib::HackedRaylibHandle, render_layer::ScreenSpaceRender, - }, - GameConfig, -}; + }}; use super::{Scenes, ScreenError}; use tracing::{debug, error, info, trace}; @@ -69,6 +65,7 @@ impl Action for WinScreen { self.counter += 1; if self.is_menu_pressed { + context.flag_send.send(Some(ControlFlag::SwitchLevel(0))).unwrap(); Ok(ActionFlag::SwitchState(Scenes::MainMenuScreen)) } else { Ok(ActionFlag::Continue) @@ -79,6 +76,7 @@ impl Action for WinScreen { debug!("Finished WinScreen"); self.is_menu_pressed = false; self.counter = 0; + Ok(()) } }