|
|
|
@ -22,28 +22,17 @@ use self::{chat::{Chat, ChatLine}, controls::Controls, debug_view::DebugView, gu |
|
|
|
|
* |........................| |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
pub enum AppStatus<'a> { |
|
|
|
|
pub enum AppStatus { |
|
|
|
|
Initial, |
|
|
|
|
GuestSelection(GuestSelectionView<'a>), |
|
|
|
|
GuestSelection(GuestSelectionView), |
|
|
|
|
TalkToGuest(TalkToGuestView), |
|
|
|
|
BuyFromGuest(EntityId), |
|
|
|
|
Debug(DebugView<'a>), |
|
|
|
|
Debug(DebugView), |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub struct App<'a> { |
|
|
|
|
pub struct App { |
|
|
|
|
game: Game, |
|
|
|
|
status: AppStatus<'a>, |
|
|
|
|
next_status: Option<AppStatus<'a>>, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Conversation
|
|
|
|
|
conversation: Chat, |
|
|
|
|
conversation_scroll: u16, |
|
|
|
|
|
|
|
|
|
// // Guest Selection
|
|
|
|
|
// guest_selection: Option<GuestSelectionView<'a>>,
|
|
|
|
|
// // Debug
|
|
|
|
|
// debug_view: Option<DebugView<'a>>,
|
|
|
|
|
status: AppStatus, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub struct DefaultLayout { |
|
|
|
@ -73,30 +62,15 @@ impl DefaultLayout { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl<'a> App<'a> { |
|
|
|
|
pub fn new(state: Game) -> App<'a> { |
|
|
|
|
impl App { |
|
|
|
|
pub fn new(state: Game) -> App { |
|
|
|
|
App { |
|
|
|
|
game: state, |
|
|
|
|
status: AppStatus::Initial, |
|
|
|
|
conversation: Chat::new(), |
|
|
|
|
conversation_scroll: 0, |
|
|
|
|
next_status: None, |
|
|
|
|
// guest_selection: None,
|
|
|
|
|
// debug_view: None,
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn do_loop<B: Backend>(&'a mut self, terminal: &mut Terminal<B>) -> bool { |
|
|
|
|
terminal.draw(|f| self.draw(f)).unwrap(); |
|
|
|
|
self.step() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn step(&'a mut self) -> bool { |
|
|
|
|
if let Some(next_status) = self.next_status.take() { |
|
|
|
|
self.status = next_status; |
|
|
|
|
self.next_status = None; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn step(&mut self) -> bool { |
|
|
|
|
let mut ret = (true, None); |
|
|
|
|
match &mut self.status { |
|
|
|
|
AppStatus::Initial => { |
|
|
|
@ -125,7 +99,9 @@ impl<'a> App<'a> { |
|
|
|
|
ret = debug_view.control(&mut self.game); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
self.next_status = ret.1; |
|
|
|
|
if let Some(next_status) = ret.1 { |
|
|
|
|
self.status = next_status; |
|
|
|
|
} |
|
|
|
|
ret.0 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -181,51 +157,6 @@ impl<'a> App<'a> { |
|
|
|
|
|
|
|
|
|
pub fn draw_initial<B: Backend>(&mut self, _f: &mut Frame<B>) {} |
|
|
|
|
|
|
|
|
|
fn draw_talk_to_guest<B: Backend>(&self, f: &mut Frame<B>, guest: Option<EntityId>) { |
|
|
|
|
let chunks = DefaultLayout::default(f.size()); |
|
|
|
|
|
|
|
|
|
let guest = self.game.state.get_creature(guest.unwrap()).unwrap(); |
|
|
|
|
|
|
|
|
|
let key_style = tui::style::Style::default() |
|
|
|
|
.add_modifier(tui::style::Modifier::BOLD) |
|
|
|
|
.fg(tui::style::Color::Green) |
|
|
|
|
.bg(tui::style::Color::Black); |
|
|
|
|
|
|
|
|
|
let mut full_text = self.conversation.to_spans(); |
|
|
|
|
full_text.push(tui::text::Spans::from(vec![ |
|
|
|
|
tui::text::Span::styled("(a) ", key_style), |
|
|
|
|
tui::text::Span::raw("What's your business?"), |
|
|
|
|
])); |
|
|
|
|
full_text.push(tui::text::Spans::from(vec![ |
|
|
|
|
tui::text::Span::styled("(b) ", key_style), |
|
|
|
|
tui::text::Span::raw("What do you have to sell?"), |
|
|
|
|
])); |
|
|
|
|
full_text.push(tui::text::Spans::from(vec![ |
|
|
|
|
tui::text::Span::styled("(c) ", key_style), |
|
|
|
|
tui::text::Span::raw("Heard of anything interesting?"), |
|
|
|
|
])); |
|
|
|
|
let text = tui::text::Text::from(full_text); |
|
|
|
|
let scroll: u16 = ((text.lines.len() as u16) ) |
|
|
|
|
.saturating_sub( |
|
|
|
|
(chunks.main.height as u16).saturating_sub(2) // 2 lines for the border
|
|
|
|
|
) |
|
|
|
|
.saturating_sub(self.conversation_scroll); |
|
|
|
|
|
|
|
|
|
let main_window = tui::widgets::Paragraph::new(text) |
|
|
|
|
.block(tui::widgets::Block::default().title(guest.name.clone()).borders(tui::widgets::Borders::ALL)) |
|
|
|
|
.style(tui::style::Style::default().fg(tui::style::Color::White)) |
|
|
|
|
.scroll((scroll, 0)); |
|
|
|
|
|
|
|
|
|
let mut binding = Controls::new(); |
|
|
|
|
let controls = binding |
|
|
|
|
.add("a-z".to_owned(), "Talk".to_owned()) |
|
|
|
|
.add("Esc".to_owned(), "Back".to_owned()) |
|
|
|
|
.render(); |
|
|
|
|
|
|
|
|
|
self.draw_status(f, chunks.status); |
|
|
|
|
f.render_widget(main_window, chunks.main); |
|
|
|
|
f.render_widget(controls, chunks.controls); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn draw_buy_from_guest<B: Backend>(&self, f: &mut Frame<B>, guest_id: EntityId) { |
|
|
|
|
let chunks = DefaultLayout::default(f.size()); |
|
|
|
@ -256,42 +187,4 @@ impl<'a> App<'a> { |
|
|
|
|
f.render_widget(controls, chunks.controls);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Conversation |
|
|
|
|
*/ |
|
|
|
|
fn greet_guest(&mut self, guest_id: Option<EntityId>) { |
|
|
|
|
let guest = self.game.state.get_creature(guest_id.unwrap()).unwrap(); |
|
|
|
|
self.conversation.add_line(ChatLine::new( |
|
|
|
|
(EntityType::Creature, 0), |
|
|
|
|
"You".to_owned(), |
|
|
|
|
"Greetings traveller!".to_owned(), |
|
|
|
|
false |
|
|
|
|
)); |
|
|
|
|
self.conversation.add_line(ChatLine::new( |
|
|
|
|
guest_id.unwrap(), |
|
|
|
|
guest.name.clone(), |
|
|
|
|
"Hello, I'm ".to_owned() + &guest.name + ", nice to meet you! " |
|
|
|
|
+ "I'm a " + &guest.profession.to_string() + ".", |
|
|
|
|
false |
|
|
|
|
)); |
|
|
|
|
self.conversation_scroll = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn ask_business(&mut self, guest: Option<EntityId>) { |
|
|
|
|
let guest = self.game.state.get_creature(guest.unwrap()).unwrap(); |
|
|
|
|
self.conversation.add_line(ChatLine::new( |
|
|
|
|
(EntityType::Creature, 0), |
|
|
|
|
"You".to_owned(), |
|
|
|
|
"What's your business?".to_owned(), |
|
|
|
|
false |
|
|
|
|
)); |
|
|
|
|
self.conversation.add_line(ChatLine::new( |
|
|
|
|
guest.entity.id, |
|
|
|
|
guest.name.clone(), |
|
|
|
|
guest.say_agenda(& self.game.state), |
|
|
|
|
false |
|
|
|
|
)); |
|
|
|
|
self.conversation_scroll = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |