mainmenu draw

This commit is contained in:
Llywelwyn 2023-09-30 03:24:30 +01:00
parent 855304abc0
commit ec8793180d
3 changed files with 49 additions and 1 deletions

46
src/gui/main_menu.rs Normal file
View file

@ -0,0 +1,46 @@
use notan::prelude::*;
use notan::draw::{ Draw, CreateDraw, DrawTextSection, Font };
use specs::prelude::*;
use std::collections::HashMap;
use super::{ FONTSIZE, RunState, DISPLAYWIDTH, TILESIZE, MainMenuSelection };
use crate::consts::DISPLAYHEIGHT;
pub fn draw_mainmenu(ecs: &World, draw: &mut Draw, atlas: &HashMap<String, Texture>, font: &Font) {
let runstate = ecs.read_resource::<RunState>();
let selected = match *runstate {
RunState::MainMenu { menu_selection } => menu_selection,
_ => unreachable!("draw_mainmenu() called outside of MainMenu runstate."),
};
let save_exists = crate::saveload_system::does_save_exist();
const MID_X: f32 = ((DISPLAYWIDTH as f32) * TILESIZE) / 2.0;
let (x, mut y) = (MID_X, ((DISPLAYHEIGHT as f32) * TILESIZE) / 3.0);
draw.text(font, "RUST-RL")
.size(FONTSIZE * 2.0)
.position(x, y)
.h_align_center();
y = draw.last_text_bounds().max_y();
draw.text(font, "New Game")
.size(FONTSIZE)
.position(x, y)
.h_align_center()
.color(get_colour(selected, MainMenuSelection::NewGame));
if save_exists {
y = draw.last_text_bounds().max_y();
draw.text(font, "Load Game")
.size(FONTSIZE)
.position(x, y)
.h_align_center()
.color(get_colour(selected, MainMenuSelection::LoadGame));
}
y = draw.last_text_bounds().max_y();
draw.text(font, "Quit")
.size(FONTSIZE)
.position(x, y)
.h_align_center()
.color(get_colour(selected, MainMenuSelection::Quit));
}
fn get_colour(selected: MainMenuSelection, desired: MainMenuSelection) -> Color {
if selected == desired { Color::from_rgb(0.0, 1.0, 0.0) } else { Color::WHITE }
}

View file

@ -64,6 +64,8 @@ pub use cheat_menu::*;
use crate::consts::events::*; use crate::consts::events::*;
mod farlook; mod farlook;
pub use farlook::*; pub use farlook::*;
mod main_menu;
pub use main_menu::*;
/// Gives a popup box with a message and a title, and waits for a keypress. /// Gives a popup box with a message and a title, and waits for a keypress.
#[allow(unused)] #[allow(unused)]

View file

@ -493,7 +493,7 @@ fn draw(_app: &mut App, gfx: &mut Graphics, gs: &mut State) {
let runstate = *gs.ecs.fetch::<RunState>(); let runstate = *gs.ecs.fetch::<RunState>();
match runstate { match runstate {
RunState::MainMenu { .. } => { RunState::MainMenu { .. } => {
// Draw main menu gui::draw_mainmenu(&gs.ecs, &mut draw, &gs.atlas, &gs.font);
} }
RunState::CharacterCreation { .. } => { RunState::CharacterCreation { .. } => {
// Draw character creation // Draw character creation