Fix main menu selection if there is no save file. Also remove redundant variables and returns

This commit is contained in:
Timothy Warren 2021-11-29 15:10:56 -05:00
parent 79d9c569d3
commit 32874bf9f5

View File

@ -623,53 +623,49 @@ 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"); ctx.print_color_centered(y, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK), "Quit");
} }
match ctx.key { return match ctx.key {
None => { None => MainMenuResult::NoSelection {
return MainMenuResult::NoSelection {
selected: selection, selected: selection,
} },
}
Some(key) => match key { Some(key) => match key {
VirtualKeyCode::Escape => { VirtualKeyCode::Escape => MainMenuResult::NoSelection {
return MainMenuResult::NoSelection {
selected: MainMenuSelection::Quit, selected: MainMenuSelection::Quit,
} },
} VirtualKeyCode::Up => MainMenuResult::NoSelection {
VirtualKeyCode::Up => { selected: match selection {
let newselection; MainMenuSelection::NewGame => MainMenuSelection::Quit,
match selection { MainMenuSelection::LoadGame => MainMenuSelection::NewGame,
MainMenuSelection::NewGame => newselection = MainMenuSelection::Quit, MainMenuSelection::Quit => {
MainMenuSelection::LoadGame => newselection = MainMenuSelection::NewGame, if save_exists {
MainMenuSelection::Quit => newselection = MainMenuSelection::LoadGame, MainMenuSelection::LoadGame
} } else {
return MainMenuResult::NoSelection { MainMenuSelection::NewGame
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,
} }
} }
}, },
},
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 { MainMenuResult::NoSelection {
selected: MainMenuSelection::NewGame, selected: MainMenuSelection::NewGame,