add some color to tiles
This commit is contained in:
parent
922413cc93
commit
e8dd782f59
1 changed files with 67 additions and 21 deletions
|
|
@ -3,7 +3,8 @@ use std::io::Write as _;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_ratatui::RatatuiContext;
|
use bevy_ratatui::RatatuiContext;
|
||||||
use ratatui::layout::{Constraint, Flex, Layout, Offset, Rect, Size};
|
use ratatui::layout::{Constraint, Flex, Layout, Offset, Rect, Size};
|
||||||
use ratatui::style::{Modifier, Stylize};
|
use ratatui::style::{Color, Modifier, Style, Stylize};
|
||||||
|
use ratatui::text::{Line, Span, Text};
|
||||||
use ratatui::widgets::{Block, Borders, Clear, Paragraph};
|
use ratatui::widgets::{Block, Borders, Clear, Paragraph};
|
||||||
|
|
||||||
use jong::riichi::player::*;
|
use jong::riichi::player::*;
|
||||||
|
|
@ -21,26 +22,71 @@ pub(crate) struct PickRegion {
|
||||||
fn render_tile(tile: &jong_types::Tile, hovered: bool) -> Paragraph<'_> {
|
fn render_tile(tile: &jong_types::Tile, hovered: bool) -> Paragraph<'_> {
|
||||||
use jong_types::*;
|
use jong_types::*;
|
||||||
let block = ratatui::widgets::Block::bordered();
|
let block = ratatui::widgets::Block::bordered();
|
||||||
let mut widget = Paragraph::new(match &tile.suit {
|
let mut lines = vec![];
|
||||||
Suit::Pin(rank) => format!("{}\np", rank.number),
|
match &tile.suit {
|
||||||
Suit::Sou(rank) => format!("{}\ns", rank.number),
|
Suit::Pin(rank) => {
|
||||||
Suit::Man(rank) => format!("{}\nm", rank.number),
|
lines.push(Line::from(Span::styled(
|
||||||
Suit::Wind(wind) => (match wind {
|
format!("{}", rank.number),
|
||||||
Wind::Ton => "e\nw",
|
Style::default(),
|
||||||
Wind::Nan => "s\nw",
|
)));
|
||||||
Wind::Shaa => "w\nw",
|
lines.push("p".into());
|
||||||
Wind::Pei => "n\nw",
|
}
|
||||||
})
|
Suit::Sou(rank) if (rank.number == 1 || rank.number == 5 || rank.number == 9) => {
|
||||||
.into(),
|
lines.push(Line::from(Span::styled(
|
||||||
Suit::Dragon(dragon) => (match dragon {
|
format!("{}", rank.number),
|
||||||
Dragon::Haku => "w\nd",
|
Color::Red,
|
||||||
Dragon::Hatsu => "g\nd",
|
)));
|
||||||
Dragon::Chun => "r\nd",
|
lines.push(Line::from(Span::styled("s", Color::Green)));
|
||||||
})
|
}
|
||||||
.into(),
|
Suit::Sou(rank) => {
|
||||||
})
|
lines.push(Line::from(Span::styled(
|
||||||
.block(block)
|
format!("{}", rank.number),
|
||||||
.centered();
|
Style::default(),
|
||||||
|
)));
|
||||||
|
lines.push(Line::from(Span::styled("s", Color::Green)));
|
||||||
|
}
|
||||||
|
Suit::Man(rank) => {
|
||||||
|
lines.push(Line::from(Span::styled(
|
||||||
|
format!("{}", rank.number),
|
||||||
|
Style::default(),
|
||||||
|
)));
|
||||||
|
lines.push(Line::from(Span::styled("m", Color::Red)));
|
||||||
|
}
|
||||||
|
Suit::Wind(wind) => match wind {
|
||||||
|
Wind::Ton => {
|
||||||
|
lines.push(Line::from(Span::styled("e", Color::Blue)));
|
||||||
|
lines.push(Line::from(Span::styled("w", Color::Blue)));
|
||||||
|
}
|
||||||
|
Wind::Nan => {
|
||||||
|
lines.push(Line::from(Span::styled("s", Color::Blue)));
|
||||||
|
lines.push(Line::from(Span::styled("w", Color::Blue)));
|
||||||
|
}
|
||||||
|
Wind::Shaa => {
|
||||||
|
lines.push(Line::from(Span::styled("w", Color::Blue)));
|
||||||
|
lines.push(Line::from(Span::styled("w", Color::Blue)));
|
||||||
|
}
|
||||||
|
Wind::Pei => {
|
||||||
|
lines.push(Line::from(Span::styled("n", Color::Blue)));
|
||||||
|
lines.push(Line::from(Span::styled("w", Color::Blue)));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Suit::Dragon(dragon) => match dragon {
|
||||||
|
Dragon::Haku => {
|
||||||
|
lines.push(Line::from(Span::styled("w", Style::default())));
|
||||||
|
lines.push(Line::from(Span::styled("d", Style::default())));
|
||||||
|
}
|
||||||
|
Dragon::Hatsu => {
|
||||||
|
lines.push(Line::from(Span::styled("g", Color::Green)));
|
||||||
|
lines.push(Line::from(Span::styled("d", Color::Green)));
|
||||||
|
}
|
||||||
|
Dragon::Chun => {
|
||||||
|
lines.push(Line::from(Span::styled("r", Color::Red)));
|
||||||
|
lines.push(Line::from(Span::styled("d", Color::Red)));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut widget = Paragraph::new(Text::from(lines)).block(block).centered();
|
||||||
|
|
||||||
if hovered {
|
if hovered {
|
||||||
widget = widget.add_modifier(Modifier::BOLD);
|
widget = widget.add_modifier(Modifier::BOLD);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue