guest selection
This commit is contained in:
parent
5dee5f499c
commit
1471751231
49
src/app.rs
49
src/app.rs
|
@ -1,7 +1,9 @@
|
|||
use std::rc::Rc;
|
||||
|
||||
use crossterm::event::{read, Event, KeyCode};
|
||||
use tui::{Terminal, backend::Backend, Frame};
|
||||
|
||||
use crate::state::{self, GameState};
|
||||
use crate::{state::{self, GameState}, person::Person};
|
||||
|
||||
/**
|
||||
* |........................|
|
||||
|
@ -15,6 +17,7 @@ use crate::state::{self, GameState};
|
|||
enum AppStatus {
|
||||
Initial,
|
||||
GuestSelection,
|
||||
TalkToGuest(Rc<Person>),
|
||||
}
|
||||
|
||||
pub struct App<'a> {
|
||||
|
@ -35,7 +38,7 @@ impl<'a> App<'a> {
|
|||
}
|
||||
|
||||
pub fn step(&mut self) -> bool {
|
||||
match self.status {
|
||||
match &self.status {
|
||||
AppStatus::Initial => {
|
||||
// determine guests
|
||||
self.guest_list = self.state.people.iter().map(|guest| {
|
||||
|
@ -62,6 +65,11 @@ impl<'a> App<'a> {
|
|||
self.guest_state.select(Some(selected + 1));
|
||||
}
|
||||
},
|
||||
KeyCode::Enter => {
|
||||
let selected = self.guest_state.selected().unwrap();
|
||||
let guest = &self.state.people[selected];
|
||||
self.status = AppStatus::TalkToGuest(guest.clone());
|
||||
},
|
||||
KeyCode::Esc => {
|
||||
return false;
|
||||
},
|
||||
|
@ -71,12 +79,42 @@ impl<'a> App<'a> {
|
|||
_ => {}
|
||||
}
|
||||
true
|
||||
},
|
||||
AppStatus::TalkToGuest(guest) => {
|
||||
match read() {
|
||||
Ok(Event::Key(event)) => {
|
||||
match event.code {
|
||||
KeyCode::Esc => {
|
||||
self.status = AppStatus::GuestSelection;
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw<B: Backend>(&mut self, f: &mut Frame<B>) {
|
||||
match &self.status {
|
||||
AppStatus::Initial => {
|
||||
self.draw_initial(f);
|
||||
},
|
||||
AppStatus::GuestSelection => {
|
||||
self.draw_guest_selection(f);
|
||||
},
|
||||
AppStatus::TalkToGuest(guest) => {
|
||||
self.draw_talk_to_guest(f, guest.clone());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub fn draw_initial<B: Backend>(&mut self, f: &mut Frame<B>) {}
|
||||
|
||||
pub fn draw_guest_selection<B: Backend>(&mut self, f: &mut Frame<B>) {
|
||||
let main_window = tui::widgets::List::new(self.guest_list.clone())
|
||||
.block(tui::widgets::Block::default().title("Guests").borders(tui::widgets::Borders::ALL))
|
||||
.style(tui::style::Style::default().fg(tui::style::Color::White))
|
||||
|
@ -85,4 +123,11 @@ impl<'a> App<'a> {
|
|||
|
||||
f.render_stateful_widget(main_window, f.size(), &mut self.guest_state);
|
||||
}
|
||||
|
||||
fn draw_talk_to_guest<B: Backend>(&self, f: &mut Frame<B>, guest: Rc<Person>) {
|
||||
let main_window = tui::widgets::Paragraph::new(guest.name.clone())
|
||||
.block(tui::widgets::Block::default().title("Guests").borders(tui::widgets::Borders::ALL))
|
||||
.style(tui::style::Style::default().fg(tui::style::Color::White));
|
||||
f.render_widget(main_window, f.size());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue