Add main menu file

This commit is contained in:
Evan Pratten 2022-04-01 23:48:05 -04:00
parent 18942b5db8
commit 33e21f2759
2 changed files with 84 additions and 5 deletions

View File

@ -0,0 +1,67 @@
//! This scene encompasses the main menu system
use nalgebra as na;
use raylib::prelude::*;
use crate::{
discord::{DiscordChannel, DiscordRpcSignal},
global_resource_package::GlobalResources,
project_constants::ProjectConstants,
};
#[derive(Debug)]
pub struct MainMenu {
has_updated_discord_rpc: bool,
}
impl MainMenu {
/// Construct a new `MainMenu`
pub fn new(
raylib_handle: &mut RaylibHandle,
thread: &RaylibThread,
constants: &ProjectConstants,
) -> Self {
Self {
has_updated_discord_rpc: false,
}
}
/// Handler for each frame
pub async fn render_frame(
&mut self,
raylib: &mut RaylibHandle,
rl_thread: &RaylibThread,
discord: &DiscordChannel,
global_resources: &GlobalResources,
constants: &ProjectConstants,
) -> bool {
// Handle updating discord RPC
if !self.has_updated_discord_rpc {
discord
.send(DiscordRpcSignal::EndGameTimer)
.await
.unwrap();
discord
.send(DiscordRpcSignal::ChangeDetails {
details: "Looking at a menu".to_string(),
party_status: None,
})
.await
.unwrap();
self.has_updated_discord_rpc = true;
}
// Get a drawing handle
let mut draw = raylib.begin_drawing(rl_thread);
// Clear the screen
draw.clear_background(Color::WHITE);
// TODO: Render stuff
// Return true if you want the game to start.
// Otherwise, keep returning false until the player clicks the start button
return false;
}
}

View File

@ -10,16 +10,19 @@ use crate::{
project_constants::ProjectConstants,
};
use self::{player_interaction::PlayableScene, test_fox::TestFoxScene};
use self::{player_interaction::PlayableScene, test_fox::TestFoxScene, main_menu::MainMenu};
mod player_interaction;
mod test_fox;
mod main_menu;
/// Delegate for handling rendering.
/// This is a struct to allow for stateful data (like sub-screens) to be set up
pub struct SceneRenderDelegate {
is_in_main_menu: bool,
/* Scenes */
scene_test_fox: TestFoxScene,
scene_playable: PlayableScene,
scene_main_menu: MainMenu
}
impl SceneRenderDelegate {
@ -34,10 +37,13 @@ impl SceneRenderDelegate {
// Init some scenes
let scene_test_fox = TestFoxScene::new(raylib, rl_thread);
let scene_playable = PlayableScene::new(raylib, rl_thread, constants);
let scene_main_menu = MainMenu::new(raylib, rl_thread, constants);
Self {
is_in_main_menu: true,
scene_test_fox,
scene_playable,
scene_main_menu,
}
}
@ -52,10 +58,16 @@ impl SceneRenderDelegate {
global_resources: &GlobalResources,
constants: &ProjectConstants,
) {
// For now, we will just render the game scene
self.scene_playable
.render_frame(raylib, rl_thread, &discord, global_resources, constants)
.await;
// Render the main menu if in it, otherwise, render the game
if self.is_in_main_menu {
self.is_in_main_menu = !self.scene_main_menu
.render_frame(raylib, rl_thread, discord, global_resources, constants)
.await;
}else {
self.scene_playable
.render_frame(raylib, rl_thread, &discord, global_resources, constants)
.await;
}
}
}