Add main menu file
This commit is contained in:
parent
18942b5db8
commit
33e21f2759
67
game/game_logic/src/scenes/main_menu.rs
Normal file
67
game/game_logic/src/scenes/main_menu.rs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -10,16 +10,19 @@ use crate::{
|
|||||||
project_constants::ProjectConstants,
|
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 player_interaction;
|
||||||
mod test_fox;
|
mod test_fox;
|
||||||
|
mod main_menu;
|
||||||
|
|
||||||
/// Delegate for handling rendering.
|
/// Delegate for handling rendering.
|
||||||
/// This is a struct to allow for stateful data (like sub-screens) to be set up
|
/// This is a struct to allow for stateful data (like sub-screens) to be set up
|
||||||
pub struct SceneRenderDelegate {
|
pub struct SceneRenderDelegate {
|
||||||
|
is_in_main_menu: bool,
|
||||||
/* Scenes */
|
/* Scenes */
|
||||||
scene_test_fox: TestFoxScene,
|
scene_test_fox: TestFoxScene,
|
||||||
scene_playable: PlayableScene,
|
scene_playable: PlayableScene,
|
||||||
|
scene_main_menu: MainMenu
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SceneRenderDelegate {
|
impl SceneRenderDelegate {
|
||||||
@ -34,10 +37,13 @@ impl SceneRenderDelegate {
|
|||||||
// Init some scenes
|
// Init some scenes
|
||||||
let scene_test_fox = TestFoxScene::new(raylib, rl_thread);
|
let scene_test_fox = TestFoxScene::new(raylib, rl_thread);
|
||||||
let scene_playable = PlayableScene::new(raylib, rl_thread, constants);
|
let scene_playable = PlayableScene::new(raylib, rl_thread, constants);
|
||||||
|
let scene_main_menu = MainMenu::new(raylib, rl_thread, constants);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
is_in_main_menu: true,
|
||||||
scene_test_fox,
|
scene_test_fox,
|
||||||
scene_playable,
|
scene_playable,
|
||||||
|
scene_main_menu,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,10 +58,16 @@ impl SceneRenderDelegate {
|
|||||||
global_resources: &GlobalResources,
|
global_resources: &GlobalResources,
|
||||||
constants: &ProjectConstants,
|
constants: &ProjectConstants,
|
||||||
) {
|
) {
|
||||||
// For now, we will just render the game scene
|
// Render the main menu if in it, otherwise, render the game
|
||||||
self.scene_playable
|
if self.is_in_main_menu {
|
||||||
.render_frame(raylib, rl_thread, &discord, global_resources, constants)
|
self.is_in_main_menu = !self.scene_main_menu
|
||||||
.await;
|
.render_frame(raylib, rl_thread, discord, global_resources, constants)
|
||||||
|
.await;
|
||||||
|
}else {
|
||||||
|
self.scene_playable
|
||||||
|
.render_frame(raylib, rl_thread, &discord, global_resources, constants)
|
||||||
|
.await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user