reorder stuff for tui main menu
This commit is contained in:
parent
3417384b86
commit
130bb38725
4 changed files with 60 additions and 34 deletions
|
|
@ -1,82 +0,0 @@
|
|||
use bevy::ecs::system::SystemParam;
|
||||
use bevy::prelude::*;
|
||||
use bevy_ratatui::RatatuiContext;
|
||||
use ratatui::widgets::Paragraph;
|
||||
|
||||
use jong::{
|
||||
game::{
|
||||
player::{Hand, HandTiles},
|
||||
wall::{Wall, WallTiles},
|
||||
},
|
||||
tiles::Tile,
|
||||
};
|
||||
|
||||
mod tiles;
|
||||
|
||||
#[derive(Component)]
|
||||
pub(crate) struct RenderedHand<'a>(Vec<Paragraph<'a>>);
|
||||
|
||||
pub(crate) fn render_changed_hand(
|
||||
hand: Single<&HandTiles, Changed<HandTiles>>,
|
||||
// hand_tiles: Query<&HandTiles, With<Hand>>,
|
||||
tiles: Query<&Tile>,
|
||||
mut target: Single<&'static mut RenderedHand>,
|
||||
) -> Result {
|
||||
let hand_tiles = hand
|
||||
.iter()
|
||||
.map(|inhand| -> Result<_> { Ok(tiles.get(inhand).map(tiles::draw_tile)?) })
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
|
||||
target.0 = hand_tiles;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn draw_ingame(
|
||||
// tiles: Query<&Tile>,
|
||||
// wall_tiles: Option<Single<&WallTiles, With<Wall>>>,
|
||||
// hand_tiles: Query<&HandTiles, With<Hand>>,
|
||||
rendered_hand: Single<&'static RenderedHand>,
|
||||
mut tui_ctx: ResMut<RatatuiContext>,
|
||||
) -> Result {
|
||||
use ratatui::layout::Flex;
|
||||
use ratatui::prelude::*;
|
||||
|
||||
// let title = ratatui::text::Text::raw("tiny riichi");
|
||||
|
||||
// let wall = if let Some(wall_tiles) = wall_tiles {
|
||||
// let wall_tiles = wall_tiles
|
||||
// .iter()
|
||||
// .map(|inwall| -> Result<_> { Ok(tiles.get(inwall).map(tiles::draw_tile)?) })
|
||||
// .collect::<Result<Vec<_>>>()?;
|
||||
|
||||
// // let paragraph = Paragraph::new(wall.join(", ")).wrap(ratatui::widgets::Wrap { trim: true });
|
||||
// Some(wall_tiles)
|
||||
// } else {
|
||||
// None
|
||||
// };
|
||||
|
||||
tui_ctx.draw(|frame| {
|
||||
// frame.render_widget(title, frame.area());
|
||||
debug!("{}", frame.area());
|
||||
|
||||
// if let Some(wall) = wall {
|
||||
// // let tile_area = Rect::new(0, 0, 5, 4);
|
||||
let layout = Layout::horizontal(vec![Constraint::Max(5); 13]).flex(Flex::Start);
|
||||
let mut area = frame.area();
|
||||
area.height = 4;
|
||||
let areas = layout.areas::<13>(area);
|
||||
for (tile, area) in rendered_hand.0.iter().zip(areas.iter()) {
|
||||
frame.render_widget(tile, *area);
|
||||
}
|
||||
|
||||
// // debug!("wall.len(): {}, areas.len(): {}", wall.len(), areas.len());
|
||||
// for (tile, rect) in wall.iter().zip(areas.iter()) {
|
||||
// // debug!("{rect:?}");
|
||||
// frame.render_widget(tile, *rect);
|
||||
// }
|
||||
// }
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue