Added quit window

Rather than instant quit
This commit is contained in:
2025-06-27 22:27:52 +01:00
parent f7c5e68860
commit 3bc26915d1

View File

@@ -19,6 +19,7 @@ pub struct App {
selected_card: Option<card_stuffs::Card>,
exit: bool,
show_help: bool,
show_exit: bool,
}
const CARD_HEIGHT: u16 = 11;
@@ -223,6 +224,8 @@ impl App {
if self.show_help {
show_help(frame, &area);
} else if self.show_exit {
show_exit(frame, &area);
}
}
@@ -240,7 +243,11 @@ impl App {
fn handle_key_event(&mut self, key_event: KeyEvent) {
match key_event.code {
KeyCode::Char('q') => self.exit(),
KeyCode::Char('q') => {
if self.show_exit { self.exit() }
self.show_exit = true;
},
KeyCode::Char('b') => self.show_exit = false,
KeyCode::Char('d') => self.cards.deck_to_waste(),
KeyCode::Char('w') => self.cards.waste_to_deck(),
KeyCode::Char('1') => self.cards.num_cards_turned = 1,
@@ -279,6 +286,21 @@ Press 'w' to put the waste pile back into the deck (you can only do this when th
frame.render_widget(p.block(block), area);
}
fn show_exit(frame: &mut Frame, area: &Rect) {
let block = Block::bordered().title("Exit?");
let text =
"Really want to exit Legend of Soltar?
Press 'q' to Quit or 'b' to go back";
let p = Paragraph::new(text).wrap(Wrap { trim: true });
let vertical = Layout::vertical([Constraint::Max(10)]).flex(Flex::Center);
let horizontal = Layout::horizontal([Constraint::Percentage(70)]).flex(Flex::Center);
let [area] = vertical.areas(*area);
let [area] = horizontal.areas(area);
frame.render_widget(Clear, area);
frame.render_widget(p.block(block), area);
}
fn deck_widget(cards_in_deck: &Vec<card_stuffs::Card>) -> Paragraph<'static> {
let card_image = format!(