Debug info for menus

This commit is contained in:
Evan Pratten 2022-04-03 16:41:51 -04:00
parent 8d26ea38c8
commit 4d6974d70f
2 changed files with 43 additions and 5 deletions

View File

@ -29,6 +29,7 @@ pub enum MenuStateSignal {
pub struct MainMenu {
pub has_updated_discord_rpc: bool,
volume_percentage: f32,
show_debug_info: bool,
}
impl MainMenu {
@ -42,6 +43,7 @@ impl MainMenu {
Self {
has_updated_discord_rpc: false,
volume_percentage: game_settings.volume.unwrap_or(0.5),
show_debug_info: false,
}
}
@ -78,9 +80,21 @@ impl MainMenu {
let mouse_x = draw.get_mouse_x();
let mouse_y = draw.get_mouse_y();
//TODO Errase later
draw.draw_text(&mouse_x.to_string(), 20, 5, 20, Color::BLACK);
draw.draw_text(&mouse_y.to_string(), 70, 5, 20, Color::BLACK);
// Optionally display debug info
if draw.is_key_pressed(KeyboardKey::KEY_F3) {
self.show_debug_info = !self.show_debug_info;
}
if self.show_debug_info {
// Draw FPS and mouse location
draw.draw_fps(10, 10);
draw.draw_text(
format!("Mouse position: ({}, {})", mouse_x, mouse_y).as_str(),
10,
30,
20,
Color::GREEN,
);
}
//Screen Size
let window_height = draw.get_screen_height();

View File

@ -17,7 +17,9 @@ use crate::{
use super::main_menu::MenuStateSignal;
#[derive(Debug)]
pub struct PauseMenu {}
pub struct PauseMenu {
show_debug_info: bool,
}
impl PauseMenu {
/// Construct a new `PauseMenu`
@ -27,7 +29,9 @@ impl PauseMenu {
constants: &ProjectConstants,
game_settings: &mut PersistentGameSettings,
) -> Self {
Self {}
Self {
show_debug_info: false,
}
}
pub async fn render_pause_menu_frame(
@ -45,6 +49,26 @@ impl PauseMenu {
// Clear the screen
draw.clear_background(Color::WHITE);
//Obtain mouse position
let mouse_x = draw.get_mouse_x();
let mouse_y = draw.get_mouse_y();
// Optionally display debug info
if draw.is_key_pressed(KeyboardKey::KEY_F3) {
self.show_debug_info = !self.show_debug_info;
}
if self.show_debug_info {
// Draw FPS and mouse location
draw.draw_fps(10, 10);
draw.draw_text(
format!("Mouse position: ({}, {})", mouse_x, mouse_y).as_str(),
10,
30,
20,
Color::GREEN,
);
}
// Title
draw.draw_text("Paused", 100, 90, 60, Color::BLACK);