diff --git a/jong/src/tui/render.rs b/jong/src/tui/render.rs index 34f5495..817e713 100644 --- a/jong/src/tui/render.rs +++ b/jong/src/tui/render.rs @@ -3,7 +3,8 @@ use std::io::Write as _; use bevy::prelude::*; use bevy_ratatui::RatatuiContext; 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 jong::riichi::player::*; @@ -21,26 +22,71 @@ pub(crate) struct PickRegion { fn render_tile(tile: &jong_types::Tile, hovered: bool) -> Paragraph<'_> { use jong_types::*; let block = ratatui::widgets::Block::bordered(); - let mut widget = Paragraph::new(match &tile.suit { - Suit::Pin(rank) => format!("{}\np", rank.number), - Suit::Sou(rank) => format!("{}\ns", rank.number), - Suit::Man(rank) => format!("{}\nm", rank.number), - Suit::Wind(wind) => (match wind { - Wind::Ton => "e\nw", - Wind::Nan => "s\nw", - Wind::Shaa => "w\nw", - Wind::Pei => "n\nw", - }) - .into(), - Suit::Dragon(dragon) => (match dragon { - Dragon::Haku => "w\nd", - Dragon::Hatsu => "g\nd", - Dragon::Chun => "r\nd", - }) - .into(), - }) - .block(block) - .centered(); + let mut lines = vec![]; + match &tile.suit { + Suit::Pin(rank) => { + lines.push(Line::from(Span::styled( + format!("{}", rank.number), + Style::default(), + ))); + lines.push("p".into()); + } + Suit::Sou(rank) if (rank.number == 1 || rank.number == 5 || rank.number == 9) => { + lines.push(Line::from(Span::styled( + format!("{}", rank.number), + Color::Red, + ))); + lines.push(Line::from(Span::styled("s", Color::Green))); + } + Suit::Sou(rank) => { + lines.push(Line::from(Span::styled( + format!("{}", rank.number), + 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 { widget = widget.add_modifier(Modifier::BOLD);