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,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"); 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 {
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,
}
}
}, },
} 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 { MainMenuResult::NoSelection {