Bad deck -> waste working-ish
Display looks alright, so that's good!
This commit is contained in:
@@ -24,43 +24,50 @@ pub struct App {
|
||||
const CARD_HEIGHT: u16 = 11;
|
||||
const CARD_WIDTH: u16 = 15;
|
||||
|
||||
fn waste_widget(cards_in_waste: &Vec<card_stuffs::Card>) -> List {
|
||||
let mut cards_to_display = Vec::new();
|
||||
fn draw_waste(cards_in_waste: &Vec<card_stuffs::Card>, area: Rect, frame: &mut Frame) {
|
||||
if cards_in_waste.len() == 0 {
|
||||
frame.render_widget(
|
||||
// TODO something different here to show empty stack - also it's too tall for some reason
|
||||
facedown_card(false),
|
||||
area
|
||||
);
|
||||
}
|
||||
let horizontal = Layout::horizontal([
|
||||
Constraint::Length(3),
|
||||
Constraint::Length(3),
|
||||
Constraint::Length(CARD_WIDTH),
|
||||
]);
|
||||
let [w1, w2, top_waste] = horizontal.areas(area);
|
||||
// There must be a better way to do this
|
||||
if cards_in_waste.len() >= 3 {
|
||||
cards_to_display.push(cards_in_waste.windows(3).last());
|
||||
frame.render_widget(
|
||||
partially_covered_card(&cards_in_waste[cards_in_waste.len() - 1]),
|
||||
w1
|
||||
);
|
||||
frame.render_widget(
|
||||
partially_covered_card(&cards_in_waste[cards_in_waste.len() - 2]),
|
||||
w2
|
||||
);
|
||||
frame.render_widget(
|
||||
card_widget(&cards_in_waste[cards_in_waste.len() - 3], true, false, false),
|
||||
top_waste
|
||||
);
|
||||
} else if cards_in_waste.len() == 2 {
|
||||
cards_to_display.push(cards_in_waste.windows(2).last());
|
||||
frame.render_widget(
|
||||
partially_covered_card(&cards_in_waste[cards_in_waste.len() - 1]),
|
||||
w2
|
||||
);
|
||||
frame.render_widget(
|
||||
card_widget(&cards_in_waste[cards_in_waste.len() - 2], true, false, false),
|
||||
top_waste
|
||||
);
|
||||
} else if cards_in_waste.len() == 1 {
|
||||
cards_to_display.push(cards_in_waste.windows(1).last());
|
||||
frame.render_widget(
|
||||
card_widget(&cards_in_waste[cards_in_waste.len() - 1], true, false, false),
|
||||
top_waste
|
||||
);
|
||||
}
|
||||
|
||||
// Eeeek - we're no longer a basic "List"... I think maybe I need
|
||||
// a new widget I've make myself... I probably should do that for all cards
|
||||
// to be toootaly honest
|
||||
|
||||
|
||||
// This (and the rest) probably shouldn't be ListItems
|
||||
let hidden_card = [
|
||||
format!("#############"),
|
||||
format!("#############"),
|
||||
format!("#############"),
|
||||
format!("#####TODO####"),
|
||||
format!("#############"),
|
||||
format!("#############"),
|
||||
format!("#############"),
|
||||
format!("#############"),
|
||||
format!("#############"),
|
||||
];
|
||||
|
||||
let card_image: Vec<ListItem> = hidden_card.iter().map(|m| {
|
||||
ListItem::new(m.to_string())
|
||||
})
|
||||
.collect();
|
||||
|
||||
List::new(card_image)
|
||||
.block(Block::new()
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded))
|
||||
}
|
||||
|
||||
fn deck_widget(cards_in_deck: &Vec<card_stuffs::Card>) -> Paragraph<'static> {
|
||||
@@ -138,6 +145,7 @@ fn partially_covered_card(card: &card_stuffs::Card) -> Paragraph {
|
||||
.border_type(BorderType::Rounded))
|
||||
}
|
||||
|
||||
/*
|
||||
struct CardWidget {
|
||||
card: card_stuffs::Card,
|
||||
// put display stuff in here?
|
||||
@@ -149,6 +157,7 @@ impl Widget for CardWidget {
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
fn facedown_card(top: bool) -> Paragraph<'static> {
|
||||
let hidden_card = format!(
|
||||
@@ -218,29 +227,12 @@ impl App {
|
||||
let [deck_area, waste_area, fa, fb, fc, fd] = horizontal.areas(dwf_area);
|
||||
let foundation_areas = [fa, fb, fc, fd];
|
||||
|
||||
let horizontal = Layout::horizontal([
|
||||
Constraint::Length(3),
|
||||
Constraint::Length(3),
|
||||
Constraint::Length(CARD_WIDTH),
|
||||
]);
|
||||
let [w1, w2, waste_area] = horizontal.areas(waste_area);
|
||||
|
||||
frame.render_widget(
|
||||
deck_widget(&self.cards.deck),
|
||||
deck_area
|
||||
);
|
||||
frame.render_widget(
|
||||
partially_covered_card(&self.cards.piles[0][0]),
|
||||
w1
|
||||
);
|
||||
frame.render_widget(
|
||||
partially_covered_card(&self.cards.piles[1][0]),
|
||||
w2
|
||||
);
|
||||
frame.render_widget(
|
||||
waste_widget(&self.cards.waste),
|
||||
waste_area
|
||||
);
|
||||
|
||||
draw_waste(&self.cards.waste, waste_area, frame);
|
||||
|
||||
for fa in foundation_areas {
|
||||
frame.render_widget(
|
||||
@@ -318,6 +310,7 @@ impl App {
|
||||
fn handle_key_event(&mut self, key_event: KeyEvent) {
|
||||
match key_event.code {
|
||||
KeyCode::Char('q') => self.exit(),
|
||||
KeyCode::Char('d') => self.cards.draw(),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user