Add background image to main menu
This commit is contained in:
parent
9d1851be17
commit
1f8869879c
42
src/gui.rs
42
src/gui.rs
@ -1,7 +1,7 @@
|
||||
use crate::components::{
|
||||
CombatStats, HungerClock, HungerState, InBackpack, Name, Player, Position, Viewshed,
|
||||
};
|
||||
use crate::{game_log::GameLog, Equipped, Map, RunState, State};
|
||||
use crate::{game_log::GameLog, rex_assets::RexAssets, Equipped, Map, RunState, State};
|
||||
use rltk::{Point, Rltk, VirtualKeyCode, RGB};
|
||||
use specs::prelude::*;
|
||||
|
||||
@ -540,61 +540,87 @@ pub enum MainMenuResult {
|
||||
pub fn main_menu(gs: &mut State, ctx: &mut Rltk) -> MainMenuResult {
|
||||
let save_exists = crate::saveload_system::does_save_exist();
|
||||
let runstate = gs.ecs.fetch::<RunState>();
|
||||
let assets = gs.ecs.fetch::<RexAssets>();
|
||||
ctx.render_xp_sprite(&assets.menu, 0, 0);
|
||||
|
||||
ctx.draw_box_double(
|
||||
24,
|
||||
18,
|
||||
31,
|
||||
10,
|
||||
RGB::named(rltk::WHEAT),
|
||||
RGB::named(rltk::BLACK),
|
||||
);
|
||||
|
||||
ctx.print_color_centered(
|
||||
15,
|
||||
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 {
|
||||
menu_selection: selection,
|
||||
} = *runstate
|
||||
{
|
||||
if selection == MainMenuSelection::NewGame {
|
||||
ctx.print_color_centered(
|
||||
24,
|
||||
y,
|
||||
RGB::named(rltk::MAGENTA),
|
||||
RGB::named(rltk::BLACK),
|
||||
"Begin New Game",
|
||||
);
|
||||
} else {
|
||||
ctx.print_color_centered(
|
||||
24,
|
||||
y,
|
||||
RGB::named(rltk::WHITE),
|
||||
RGB::named(rltk::BLACK),
|
||||
"Begin New Game",
|
||||
);
|
||||
}
|
||||
y += 1;
|
||||
|
||||
if save_exists {
|
||||
if selection == MainMenuSelection::LoadGame {
|
||||
ctx.print_color_centered(
|
||||
25,
|
||||
y,
|
||||
RGB::named(rltk::MAGENTA),
|
||||
RGB::named(rltk::BLACK),
|
||||
"Load Game",
|
||||
);
|
||||
} else {
|
||||
ctx.print_color_centered(
|
||||
25,
|
||||
y,
|
||||
RGB::named(rltk::WHITE),
|
||||
RGB::named(rltk::BLACK),
|
||||
"Load Game",
|
||||
);
|
||||
}
|
||||
y += 1;
|
||||
}
|
||||
|
||||
if selection == MainMenuSelection::Quit {
|
||||
ctx.print_color_centered(
|
||||
26,
|
||||
y,
|
||||
RGB::named(rltk::MAGENTA),
|
||||
RGB::named(rltk::BLACK),
|
||||
"Quit",
|
||||
);
|
||||
} 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");
|
||||
}
|
||||
|
||||
match ctx.key {
|
||||
|
@ -16,6 +16,7 @@ mod particle_system;
|
||||
mod player;
|
||||
pub mod random_table;
|
||||
mod rect;
|
||||
mod rex_assets;
|
||||
pub mod saveload_system;
|
||||
mod spawner;
|
||||
mod visibility_system;
|
||||
@ -532,6 +533,7 @@ fn main() -> rltk::BError {
|
||||
});
|
||||
gs.ecs.insert(GameLog::new("Welcome to Rusty Roguelike"));
|
||||
gs.ecs.insert(particle_system::ParticleBuilder::new());
|
||||
gs.ecs.insert(rex_assets::RexAssets::new());
|
||||
|
||||
rltk::main_loop(context, gs)
|
||||
}
|
||||
|
17
src/rex_assets.rs
Normal file
17
src/rex_assets.rs
Normal file
@ -0,0 +1,17 @@
|
||||
use rltk::rex::XpFile;
|
||||
|
||||
rltk::embedded_resource!(SMALL_DUNGEON, "../resources/SmallDungeon_80x50.xp");
|
||||
|
||||
pub struct RexAssets {
|
||||
pub menu: XpFile,
|
||||
}
|
||||
|
||||
impl RexAssets {
|
||||
pub fn new() -> RexAssets {
|
||||
rltk::link_resource!(SMALL_DUNGEON, "../resources/SmallDungeon_80x50.xp");
|
||||
|
||||
RexAssets {
|
||||
menu: XpFile::from_resource("../resources/SmallDungeon_80x50.xp").unwrap(),
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user