main menu runstate
This commit is contained in:
parent
ac0da55d14
commit
855304abc0
3 changed files with 131 additions and 129 deletions
149
src/gui/mod.rs
149
src/gui/mod.rs
|
|
@ -177,10 +177,6 @@ pub fn draw_ui2(
|
|||
&hunger,
|
||||
&skills,
|
||||
).join() {
|
||||
let initial_x = 24.0 * TILESIZE;
|
||||
let mut x = initial_x;
|
||||
let row1 = 53.0 * TILESIZE;
|
||||
let row2 = row1 + TILESIZE;
|
||||
const BAR_X: f32 = 1.0;
|
||||
const BAR_WIDTH: f32 = 22.0;
|
||||
draw_bar(
|
||||
|
|
@ -205,32 +201,51 @@ pub fn draw_ui2(
|
|||
Color::BLUE,
|
||||
Color::BLACK
|
||||
);
|
||||
/*draw_bar_sprite(
|
||||
draw,
|
||||
atlas,
|
||||
2.0 * TILESIZE,
|
||||
row1,
|
||||
22,
|
||||
stats.hit_points.current,
|
||||
stats.hit_points.max,
|
||||
"ui_hp"
|
||||
let initial_x = 24.0 * TILESIZE;
|
||||
let mut x = initial_x;
|
||||
let row1 = 53.0 * TILESIZE;
|
||||
let row2 = row1 + TILESIZE;
|
||||
let hp_colours: (RGB, RGB, RGB) = (
|
||||
RGB::named(GREEN),
|
||||
RGB::named(RED),
|
||||
RGB::from_f32(0.0, 0.5, 0.0),
|
||||
);
|
||||
draw_bar_sprite(
|
||||
draw,
|
||||
atlas,
|
||||
2.0 * TILESIZE,
|
||||
row2,
|
||||
22,
|
||||
stats.mana.current,
|
||||
stats.mana.max,
|
||||
"ui_mp"
|
||||
);*/
|
||||
draw.text(&font, &format!("HP{}({})", stats.hit_points.current, stats.hit_points.max))
|
||||
let mp_colours: (RGB, RGB, RGB) = (
|
||||
RGB::named(CYAN),
|
||||
RGB::named(RED),
|
||||
RGB::from_f32(0.0, 0.5, 0.5),
|
||||
);
|
||||
let hp: RGB = hp_colours.1.lerp(
|
||||
hp_colours.0,
|
||||
(stats.hit_points.current as f32) / (stats.hit_points.max as f32)
|
||||
);
|
||||
let mp: RGB = mp_colours.1.lerp(
|
||||
mp_colours.0,
|
||||
(stats.mana.current as f32) / (stats.mana.max as f32)
|
||||
);
|
||||
draw.text(&font, "HP").position(x, row1).size(FONTSIZE);
|
||||
x = draw.last_text_bounds().max_x();
|
||||
draw.text(&font, &format!("{}", stats.hit_points.current))
|
||||
.position(x, row1)
|
||||
.size(FONTSIZE);
|
||||
draw.text(&font, &format!("MP{}({})", stats.mana.current, stats.mana.max))
|
||||
.size(FONTSIZE)
|
||||
.color(Color::from_rgb(hp.r, hp.g, hp.b));
|
||||
x = draw.last_text_bounds().max_x();
|
||||
draw.text(&font, &format!("({})", stats.hit_points.max))
|
||||
.position(x, row1)
|
||||
.size(FONTSIZE)
|
||||
.color(Color::from_rgb(hp_colours.2.r, hp_colours.2.g, hp_colours.2.b));
|
||||
x = initial_x;
|
||||
draw.text(&font, "MP").position(x, row2).size(FONTSIZE);
|
||||
x = draw.last_text_bounds().max_x();
|
||||
draw.text(&font, &format!("{}", stats.mana.current))
|
||||
.position(x, row2)
|
||||
.size(FONTSIZE);
|
||||
.size(FONTSIZE)
|
||||
.color(Color::from_rgb(mp.r, mp.g, mp.b));
|
||||
x = draw.last_text_bounds().max_x();
|
||||
draw.text(&font, &format!("({})", stats.mana.max))
|
||||
.position(x, row2)
|
||||
.size(FONTSIZE)
|
||||
.color(Color::from_rgb(mp_colours.2.r, mp_colours.2.g, mp_colours.2.b));
|
||||
// Draw AC
|
||||
let skill_ac_bonus = gamesystem::skill_bonus(Skill::Defence, &*skills);
|
||||
let mut armour_ac_bonus = 0;
|
||||
|
|
@ -1631,68 +1646,27 @@ pub enum MainMenuResult {
|
|||
},
|
||||
}
|
||||
|
||||
pub fn main_menu(gs: &mut State, ctx: &mut BTerm) -> MainMenuResult {
|
||||
pub fn main_menu(gs: &mut State, ctx: &mut App) -> MainMenuResult {
|
||||
let save_exists = super::saveload_system::does_save_exist();
|
||||
let runstate = gs.ecs.fetch::<RunState>();
|
||||
let assets = gs.ecs.fetch::<RexAssets>();
|
||||
let selection = match *runstate {
|
||||
RunState::MainMenu { menu_selection: sel } => sel,
|
||||
_ => MainMenuSelection::NewGame,
|
||||
};
|
||||
|
||||
ctx.render_xp_sprite(&assets.menu, 0, 0);
|
||||
|
||||
let x = 46;
|
||||
let mut y = 26;
|
||||
let mut height = 8;
|
||||
if !save_exists {
|
||||
height -= 1;
|
||||
}
|
||||
|
||||
ctx.draw_box_double(x, y - 4, 13, height, RGB::named(WHITE), RGB::named(BLACK));
|
||||
ctx.print_color(x + 3, y - 2, RGB::named(YELLOW), RGB::named(BLACK), "RUST-RL!");
|
||||
|
||||
if let RunState::MainMenu { menu_selection: selection } = *runstate {
|
||||
if save_exists {
|
||||
if selection == MainMenuSelection::LoadGame {
|
||||
ctx.print_color(x + 2, y, RGB::named(YELLOW), RGB::named(BLACK), "[");
|
||||
ctx.print_color(x + 3, y, RGB::named(GREEN), RGB::named(BLACK), "continue");
|
||||
ctx.print_color(x + 11, y, RGB::named(YELLOW), RGB::named(BLACK), "]");
|
||||
} else {
|
||||
ctx.print_color(x + 3, y, RGB::named(WHITE), RGB::named(BLACK), "continue");
|
||||
}
|
||||
y += 1;
|
||||
}
|
||||
if selection == MainMenuSelection::NewGame {
|
||||
ctx.print_color(x + 2, y, RGB::named(YELLOW), RGB::named(BLACK), "[");
|
||||
ctx.print_color(x + 3, y, RGB::named(GREEN), RGB::named(BLACK), "new game");
|
||||
ctx.print_color(x + 11, y, RGB::named(YELLOW), RGB::named(BLACK), "]");
|
||||
} else {
|
||||
ctx.print_color(x + 3, y, RGB::named(WHITE), RGB::named(BLACK), "new game");
|
||||
}
|
||||
y += 1;
|
||||
if selection == MainMenuSelection::Quit {
|
||||
ctx.print_color(x + 2, y, RGB::named(YELLOW), RGB::named(BLACK), "[");
|
||||
ctx.print_color(x + 3, y, RGB::named(GREEN), RGB::named(BLACK), "goodbye!");
|
||||
ctx.print_color(x + 11, y, RGB::named(YELLOW), RGB::named(BLACK), "]");
|
||||
} else {
|
||||
ctx.print_color(x + 5, y, RGB::named(WHITE), RGB::named(BLACK), "quit");
|
||||
}
|
||||
|
||||
match ctx.key {
|
||||
None => {
|
||||
return MainMenuResult::NoSelection { selected: selection };
|
||||
}
|
||||
Some(key) =>
|
||||
match key {
|
||||
VirtualKeyCode::Escape | VirtualKeyCode::C => {
|
||||
let key = &ctx.keyboard;
|
||||
for keycode in key.pressed.iter() {
|
||||
match *keycode {
|
||||
KeyCode::Escape | KeyCode::C => {
|
||||
return MainMenuResult::NoSelection { selected: MainMenuSelection::Quit };
|
||||
}
|
||||
VirtualKeyCode::N => {
|
||||
KeyCode::N => {
|
||||
return MainMenuResult::NoSelection { selected: MainMenuSelection::NewGame };
|
||||
}
|
||||
VirtualKeyCode::L => {
|
||||
return MainMenuResult::NoSelection {
|
||||
selected: MainMenuSelection::LoadGame,
|
||||
};
|
||||
KeyCode::L => {
|
||||
return MainMenuResult::NoSelection { selected: MainMenuSelection::LoadGame };
|
||||
}
|
||||
VirtualKeyCode::Up | VirtualKeyCode::Numpad8 | VirtualKeyCode::K => {
|
||||
KeyCode::Up | KeyCode::Numpad8 | KeyCode::K => {
|
||||
let mut new_selection;
|
||||
match selection {
|
||||
MainMenuSelection::NewGame => {
|
||||
|
|
@ -1710,7 +1684,7 @@ pub fn main_menu(gs: &mut State, ctx: &mut BTerm) -> MainMenuResult {
|
|||
}
|
||||
return MainMenuResult::NoSelection { selected: new_selection };
|
||||
}
|
||||
VirtualKeyCode::Down | VirtualKeyCode::Numpad2 | VirtualKeyCode::J => {
|
||||
KeyCode::Down | KeyCode::Numpad2 | KeyCode::J => {
|
||||
let mut new_selection;
|
||||
match selection {
|
||||
MainMenuSelection::NewGame => {
|
||||
|
|
@ -1728,16 +1702,13 @@ pub fn main_menu(gs: &mut State, ctx: &mut BTerm) -> MainMenuResult {
|
|||
}
|
||||
return MainMenuResult::NoSelection { selected: new_selection };
|
||||
}
|
||||
VirtualKeyCode::Return | VirtualKeyCode::NumpadEnter => {
|
||||
KeyCode::Return | KeyCode::NumpadEnter => {
|
||||
return MainMenuResult::Selected { selected: selection };
|
||||
}
|
||||
_ => {
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
return MainMenuResult::NoSelection { selected: selection };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
MainMenuResult::NoSelection { selected: MainMenuSelection::NewGame }
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Copy, Clone)]
|
||||
|
|
|
|||
13
src/main.rs
13
src/main.rs
|
|
@ -139,7 +139,7 @@ fn setup(gfx: &mut Graphics) -> State {
|
|||
gs.ecs.insert(gui::Ancestry::Human); // ancestry
|
||||
let player_entity = spawner::player(&mut gs.ecs, 0, 0);
|
||||
gs.ecs.insert(player_entity); // Player entity
|
||||
gs.ecs.insert(RunState::AwaitingInput {}); // TODO: Set this back to RunState::MapGen
|
||||
gs.ecs.insert(RunState::MapGeneration {}); // TODO: Set this back to RunState::MapGen
|
||||
gs.ecs.insert(particle_system::ParticleBuilder::new());
|
||||
gs.ecs.insert(rex_assets::RexAssets::new());
|
||||
|
||||
|
|
@ -492,9 +492,13 @@ fn draw(_app: &mut App, gfx: &mut Graphics, gs: &mut State) {
|
|||
let mut log = false;
|
||||
let runstate = *gs.ecs.fetch::<RunState>();
|
||||
match runstate {
|
||||
| RunState::MainMenu { .. }
|
||||
| RunState::CharacterCreation { .. }
|
||||
| RunState::PreRun { .. } => {}
|
||||
RunState::MainMenu { .. } => {
|
||||
// Draw main menu
|
||||
}
|
||||
RunState::CharacterCreation { .. } => {
|
||||
// Draw character creation
|
||||
}
|
||||
RunState::PreRun { .. } => {}
|
||||
RunState::MapGeneration => {
|
||||
draw_bg(&gs.ecs, &mut draw, &gs.atlas);
|
||||
if config::CONFIG.logging.show_mapgen && gs.mapgen_history.len() > 0 {
|
||||
|
|
@ -506,6 +510,7 @@ fn draw(_app: &mut App, gfx: &mut Graphics, gs: &mut State) {
|
|||
true
|
||||
);
|
||||
}
|
||||
gui::draw_ui2(&gs.ecs, &mut draw, &gs.atlas, &gs.font);
|
||||
}
|
||||
_ => {
|
||||
let map = gs.ecs.fetch::<Map>();
|
||||
|
|
|
|||
|
|
@ -282,7 +282,31 @@ impl State {
|
|||
RunState::ActionWithDirection { function } => {
|
||||
new_runstate = gui::get_input_direction(&mut self.ecs, ctx, function);
|
||||
}
|
||||
// RunState::MainMenu
|
||||
RunState::MainMenu { .. } => {
|
||||
let result = gui::main_menu(self, ctx);
|
||||
match result {
|
||||
gui::MainMenuResult::NoSelection { selected } => {
|
||||
new_runstate = RunState::MainMenu { menu_selection: selected };
|
||||
}
|
||||
gui::MainMenuResult::Selected { selected } =>
|
||||
match selected {
|
||||
gui::MainMenuSelection::NewGame => {
|
||||
new_runstate = RunState::CharacterCreation {
|
||||
ancestry: gui::Ancestry::Human,
|
||||
class: gui::Class::Fighter,
|
||||
};
|
||||
}
|
||||
gui::MainMenuSelection::LoadGame => {
|
||||
saveload_system::load_game(&mut self.ecs);
|
||||
new_runstate = RunState::AwaitingInput;
|
||||
saveload_system::delete_save();
|
||||
}
|
||||
gui::MainMenuSelection::Quit => {
|
||||
::std::process::exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// RunState::CharacterCreation
|
||||
RunState::SaveGame => {
|
||||
saveload_system::save_game(&mut self.ecs);
|
||||
|
|
@ -669,7 +693,9 @@ impl State {
|
|||
new_runstate = RunState::AwaitingInput; //gui::get_input_direction(&mut self.ecs, ctx, function);
|
||||
}
|
||||
RunState::MainMenu { .. } => {
|
||||
let result = gui::main_menu(self, ctx);
|
||||
let result = gui::MainMenuResult::Selected {
|
||||
selected: gui::MainMenuSelection::NewGame,
|
||||
}; //gui::main_menu(self, ctx);
|
||||
match result {
|
||||
gui::MainMenuResult::NoSelection { selected } => {
|
||||
new_runstate = RunState::MainMenu { menu_selection: selected };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue