Add main menu

This commit is contained in:
Kasper Juul Hermansen 2022-01-29 14:31:02 +01:00
parent 62240a42c1
commit 835a416013
Signed by: kjuulh
GPG Key ID: DCD9397082D97069
5 changed files with 43 additions and 18 deletions

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@ -1,14 +1,15 @@
use rltk::Rltk;
use rltk::RGB;
use rltk::{Point, VirtualKeyCode}; use rltk::{Point, VirtualKeyCode};
use rltk::RGB;
use rltk::Rltk;
use specs::prelude::*; use specs::prelude::*;
use crate::gamelog::GameLog;
use crate::Player;
use crate::Position;
use crate::{CombatStats, InBackpack, RunState, State, Viewshed}; use crate::{CombatStats, InBackpack, RunState, State, Viewshed};
use crate::{Equipped, Map}; use crate::{Equipped, Map};
use crate::{HungerClock, HungerState, Name}; use crate::{HungerClock, HungerState, Name};
use crate::gamelog::GameLog;
use crate::Player;
use crate::Position;
use crate::rex_assets::RexAssets;
pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { pub fn draw_ui(ecs: &World, ctx: &mut Rltk) {
ctx.draw_box( ctx.draw_box(
@ -442,60 +443,64 @@ pub fn main_menu(gs: &mut State, ctx: &mut Rltk) -> MainMenuResult {
let save_exists = super::save_load_system::does_save_exist(); let save_exists = super::save_load_system::does_save_exist();
let runstate = gs.ecs.fetch::<RunState>(); let runstate = gs.ecs.fetch::<RunState>();
ctx.print_color_centered( let assets = gs.ecs.fetch::<RexAssets>();
15, ctx.render_xp_sprite(&assets.menu, 0, 0);
RGB::named(rltk::YELLOW),
RGB::named(rltk::BLACK),
"Rust Roguelike Tutorial",
);
ctx.draw_box_double(24, 18, 31, 10, RGB::named(rltk::WHEAT), RGB::named(rltk::BLACK));
ctx.print_color_centered(20, RGB::named(rltk::YELLOW), RGB::named(rltk::BLACK), "Rust Roguelike Tutorial");
ctx.print_color_centered(21, RGB::named(rltk::CYAN), RGB::named(rltk::BLACK), "by Herbert Wolverson");
ctx.print_color_centered(22, RGB::named(rltk::GRAY), RGB::named(rltk::BLACK), "Use Up/Down Arrows and Enter");
let mut y = 24;
if let RunState::MainMenu { if let RunState::MainMenu {
menu_selection: selection, menu_selection: selection,
} = *runstate } = *runstate
{ {
if selection == MainMenuSelection::NewGame { if selection == MainMenuSelection::NewGame {
ctx.print_color_centered( ctx.print_color_centered(
24, y,
RGB::named(rltk::MAGENTA), RGB::named(rltk::MAGENTA),
RGB::named(rltk::BLACK), RGB::named(rltk::BLACK),
"Begin New Game", "Begin New Game",
); );
} else { } else {
ctx.print_color_centered( ctx.print_color_centered(
24, y,
RGB::named(rltk::WHITE), RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK), RGB::named(rltk::BLACK),
"Begin New Game", "Begin New Game",
); );
} }
y += 1;
if save_exists { if save_exists {
if selection == MainMenuSelection::LoadGame { if selection == MainMenuSelection::LoadGame {
ctx.print_color_centered( ctx.print_color_centered(
25, y,
RGB::named(rltk::MAGENTA), RGB::named(rltk::MAGENTA),
RGB::named(rltk::BLACK), RGB::named(rltk::BLACK),
"Load Game", "Load Game",
); );
} else { } else {
ctx.print_color_centered( ctx.print_color_centered(
25, y,
RGB::named(rltk::WHITE), RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK), RGB::named(rltk::BLACK),
"Load Game", "Load Game",
); );
} }
y += 1;
} }
if selection == MainMenuSelection::Quit { if selection == MainMenuSelection::Quit {
ctx.print_color_centered( ctx.print_color_centered(
26, y,
RGB::named(rltk::MAGENTA), RGB::named(rltk::MAGENTA),
RGB::named(rltk::BLACK), RGB::named(rltk::BLACK),
"Quit", "Quit",
); );
} else { } else {
ctx.print_color_centered(26, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK), "Quit"); ctx.print_color_centered(y, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK), "Quit");
} }
return match ctx.key { return match ctx.key {

View File

@ -39,6 +39,7 @@ mod rect;
mod save_load_system; mod save_load_system;
mod spawner; mod spawner;
mod visibility_system; mod visibility_system;
mod rex_assets;
#[derive(PartialEq, Copy, Clone)] #[derive(PartialEq, Copy, Clone)]
pub enum RunState { pub enum RunState {
@ -457,6 +458,7 @@ fn main() -> rltk::BError {
gs.ecs.insert(rltk::RandomNumberGenerator::new()); gs.ecs.insert(rltk::RandomNumberGenerator::new());
gs.ecs.insert(particle_system::ParticleBuilder::new()); gs.ecs.insert(particle_system::ParticleBuilder::new());
gs.ecs.insert(rex_assets::RexAssets::new());
gs.ecs.register::<Position>(); gs.ecs.register::<Position>();
gs.ecs.register::<Renderable>(); gs.ecs.register::<Renderable>();

18
src/rex_assets.rs Normal file
View File

@ -0,0 +1,18 @@
use rltk::rex::XpFile;
rltk::embedded_resource!(SMALL_DUNGEON, "../resources/SmallDungeon_80x50.xp");
pub struct RexAssets {
pub menu: XpFile,
}
impl RexAssets {
#[allow(clippy::new_without_default)]
pub fn new() -> RexAssets {
rltk::link_resource!(SMALL_DUNGEON, "../resources/SmallDungeon_80x50.xp");
RexAssets {
menu: XpFile::from_resource("../resources/SmallDungeon_80x50.xp").unwrap()
}
}
}