diff --git a/src/gui.rs b/src/gui.rs index b409add..c2498da 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -623,52 +623,48 @@ pub fn main_menu(gs: &mut State, ctx: &mut Rltk) -> MainMenuResult { ctx.print_color_centered(y, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK), "Quit"); } - match ctx.key { - None => { - return MainMenuResult::NoSelection { - selected: selection, - } - } - Some(key) => match key { - VirtualKeyCode::Escape => { - return MainMenuResult::NoSelection { - selected: MainMenuSelection::Quit, - } - } - VirtualKeyCode::Up => { - let newselection; - match selection { - MainMenuSelection::NewGame => newselection = MainMenuSelection::Quit, - MainMenuSelection::LoadGame => newselection = MainMenuSelection::NewGame, - MainMenuSelection::Quit => newselection = MainMenuSelection::LoadGame, - } - return MainMenuResult::NoSelection { - selected: newselection, - }; - } - VirtualKeyCode::Down => { - let newselection; - match selection { - MainMenuSelection::NewGame => newselection = MainMenuSelection::LoadGame, - MainMenuSelection::LoadGame => newselection = MainMenuSelection::Quit, - MainMenuSelection::Quit => newselection = MainMenuSelection::NewGame, - } - return MainMenuResult::NoSelection { - selected: newselection, - }; - } - VirtualKeyCode::Return => { - return MainMenuResult::Selected { - selected: selection, - } - } - _ => { - return MainMenuResult::NoSelection { - selected: selection, - } - } + return match ctx.key { + None => MainMenuResult::NoSelection { + selected: selection, }, - } + Some(key) => match key { + VirtualKeyCode::Escape => MainMenuResult::NoSelection { + selected: MainMenuSelection::Quit, + }, + VirtualKeyCode::Up => MainMenuResult::NoSelection { + selected: match selection { + MainMenuSelection::NewGame => MainMenuSelection::Quit, + MainMenuSelection::LoadGame => MainMenuSelection::NewGame, + MainMenuSelection::Quit => { + if save_exists { + MainMenuSelection::LoadGame + } else { + MainMenuSelection::NewGame + } + } + }, + }, + VirtualKeyCode::Down => MainMenuResult::NoSelection { + selected: match selection { + MainMenuSelection::NewGame => { + if save_exists { + MainMenuSelection::LoadGame + } else { + MainMenuSelection::Quit + } + } + MainMenuSelection::LoadGame => MainMenuSelection::Quit, + MainMenuSelection::Quit => MainMenuSelection::NewGame, + }, + }, + VirtualKeyCode::Return => MainMenuResult::Selected { + selected: selection, + }, + _ => MainMenuResult::NoSelection { + selected: selection, + }, + }, + }; } MainMenuResult::NoSelection {