Corrected Waste and Foundation highlighting
And moved a function to a more logical place in file
This commit is contained in:
@@ -27,7 +27,7 @@ impl Default for App {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
cards: card_stuffs::Klondike::default(),
|
cards: card_stuffs::Klondike::default(),
|
||||||
highlighted_card: card_stuffs::CardPosition::Pile(0,0),
|
highlighted_card: card_stuffs::CardPosition::TopWaste,
|
||||||
selected_card: None,
|
selected_card: None,
|
||||||
exit: false,
|
exit: false,
|
||||||
show_exit: false,
|
show_exit: false,
|
||||||
@@ -50,7 +50,7 @@ fn draw_waste(cards_in_waste: &Vec<card_stuffs::Card>, area: Rect, frame: &mut F
|
|||||||
// There must be a better way to do all of this
|
// There must be a better way to do all of this
|
||||||
if cards_in_waste.len() == 0 {
|
if cards_in_waste.len() == 0 {
|
||||||
frame.render_widget(
|
frame.render_widget(
|
||||||
empty_pile(),
|
empty_pile(highlight),
|
||||||
top_waste
|
top_waste
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -85,37 +85,6 @@ fn draw_waste(cards_in_waste: &Vec<card_stuffs::Card>, area: Rect, frame: &mut F
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn card_widget<'a>(card: &'a card_stuffs::Card, top: bool, highlight: bool, select: bool) -> Paragraph<'a> {
|
|
||||||
if !card.visible {
|
|
||||||
return facedown_card(top);
|
|
||||||
}
|
|
||||||
|
|
||||||
let card_image = card_paragraph(&card);
|
|
||||||
|
|
||||||
let card_style = match card.suit.colour() {
|
|
||||||
card_stuffs::Colour::Black => Style::new().black().bg(Color::White),
|
|
||||||
card_stuffs::Colour::Red => Style::new().red().bg(Color::White),
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut borders = Borders::TOP | Borders::LEFT | Borders::RIGHT;
|
|
||||||
if top {
|
|
||||||
borders |= Borders::BOTTOM;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut border_style = Style::new().white().on_black();
|
|
||||||
if highlight {
|
|
||||||
border_style = border_style.fg(Color::Blue);
|
|
||||||
} else if select {
|
|
||||||
border_style = border_style.fg(Color::Green);
|
|
||||||
}
|
|
||||||
|
|
||||||
Paragraph::new(card_image)
|
|
||||||
.style(card_style)
|
|
||||||
.block(Block::new()
|
|
||||||
.style(border_style)
|
|
||||||
.borders(borders)
|
|
||||||
.border_type(BorderType::Rounded))
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
@@ -176,10 +145,10 @@ impl App {
|
|||||||
|
|
||||||
draw_waste(&self.cards.waste, waste_area, frame, self.highlighted_card == CardPosition::TopWaste);
|
draw_waste(&self.cards.waste, waste_area, frame, self.highlighted_card == CardPosition::TopWaste);
|
||||||
|
|
||||||
for fa in foundation_areas {
|
for (i, fa) in foundation_areas.iter().enumerate() {
|
||||||
frame.render_widget(
|
frame.render_widget(
|
||||||
empty_pile(),
|
empty_pile(self.highlighted_card == CardPosition::Foundation(i)),
|
||||||
fa
|
*fa
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -363,6 +332,38 @@ Press 'q' to Quit or 'b' to go back";
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn card_widget<'a>(card: &'a card_stuffs::Card, top: bool, highlight: bool, select: bool) -> Paragraph<'a> {
|
||||||
|
if !card.visible {
|
||||||
|
return facedown_card(top);
|
||||||
|
}
|
||||||
|
|
||||||
|
let card_image = card_paragraph(&card);
|
||||||
|
|
||||||
|
let card_style = match card.suit.colour() {
|
||||||
|
card_stuffs::Colour::Black => Style::new().black().bg(Color::White),
|
||||||
|
card_stuffs::Colour::Red => Style::new().red().bg(Color::White),
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut borders = Borders::TOP | Borders::LEFT | Borders::RIGHT;
|
||||||
|
if top {
|
||||||
|
borders |= Borders::BOTTOM;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut border_style = Style::new().white().on_black();
|
||||||
|
if highlight {
|
||||||
|
border_style = border_style.fg(Color::Blue);
|
||||||
|
} else if select {
|
||||||
|
border_style = border_style.fg(Color::Green);
|
||||||
|
}
|
||||||
|
|
||||||
|
Paragraph::new(card_image)
|
||||||
|
.style(card_style)
|
||||||
|
.block(Block::new()
|
||||||
|
.style(border_style)
|
||||||
|
.borders(borders)
|
||||||
|
.border_type(BorderType::Rounded))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fn deck_widget(cards_in_deck: &Vec<card_stuffs::Card>) -> Paragraph<'static> {
|
fn deck_widget(cards_in_deck: &Vec<card_stuffs::Card>) -> Paragraph<'static> {
|
||||||
let card_image = format!(
|
let card_image = format!(
|
||||||
@@ -425,7 +426,7 @@ fn facedown_card(top: bool) -> Paragraph<'static> {
|
|||||||
.border_type(BorderType::Rounded))
|
.border_type(BorderType::Rounded))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn empty_pile() -> Paragraph<'static> {
|
fn empty_pile(highlight: bool) -> Paragraph<'static> {
|
||||||
// made using https://www.asciiart.eu/
|
// made using https://www.asciiart.eu/
|
||||||
let hidden_card = format!(
|
let hidden_card = format!(
|
||||||
"
|
"
|
||||||
@@ -438,8 +439,14 @@ fn empty_pile() -> Paragraph<'static> {
|
|||||||
XXXXXXX"
|
XXXXXXX"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let mut border_style = Style::new();
|
||||||
|
if highlight {
|
||||||
|
border_style = border_style.fg(Color::Blue);
|
||||||
|
}
|
||||||
|
|
||||||
Paragraph::new(hidden_card)
|
Paragraph::new(hidden_card)
|
||||||
.block(Block::new()
|
.block(Block::new()
|
||||||
|
.style(border_style)
|
||||||
.borders(Borders::ALL)
|
.borders(Borders::ALL)
|
||||||
.border_type(BorderType::Rounded))
|
.border_type(BorderType::Rounded))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user