diff --git a/jong/src/tui/layout.rs b/jong/src/tui/layout.rs index 827c6ea..8c106c7 100644 --- a/jong/src/tui/layout.rs +++ b/jong/src/tui/layout.rs @@ -1,7 +1,7 @@ use bevy::prelude::*; use bevy_ratatui::RatatuiContext; use ratatui::{ - layout::{Constraint, Layout, Margin}, + layout::{Constraint, Flex, Layout, Margin}, prelude::Rect, }; @@ -12,15 +12,19 @@ pub(crate) struct Overlays { pub(crate) enum Overlay {} -#[derive(Resource, Clone, Copy)] +#[derive(Resource, Clone)] pub(crate) struct HandLayouts { pub(crate) left_pond: Rect, - pub(crate) cross_pond: Rect, - pub(crate) right_pond: Rect, - pub(crate) this_pond: Rect, pub(crate) left_hand: Rect, + + pub(crate) cross_pond: Rect, pub(crate) cross_hand: Rect, + + pub(crate) right_pond: Rect, pub(crate) right_hand: Rect, + + pub(crate) this_pond: Rect, + pub(crate) this_pond_slots: Vec, pub(crate) this_hand: Rect, } @@ -69,14 +73,28 @@ fn tiles_areas(term_area: Rect) -> HandLayouts { right_pond.height = cross_pond.height; right_pond.y += cross_pond.height / 2; + let this_pond_row_constraints = [Constraint::Max(4); 3]; + let this_pond_col_constraints = [Constraint::Max(5); 6]; + let this_pond_row_layouts = Layout::vertical(this_pond_row_constraints).flex(Flex::Start); + let this_pond_col_layouts = Layout::horizontal(this_pond_col_constraints).flex(Flex::Start); + let mut this_pond_rows = this_pond_row_layouts.areas::<3>(this_pond); + let this_pond_slots: Vec<_> = this_pond_rows + .iter() + .flat_map(|row| this_pond_col_layouts.areas::<6>(*row)) + .collect(); + HandLayouts { left_pond, - cross_pond, - right_pond, - this_pond, left_hand, + + cross_pond, cross_hand, + + right_pond, right_hand, + + this_pond, this_hand, + this_pond_slots, } } diff --git a/jong/src/tui/render.rs b/jong/src/tui/render.rs index c12dfdf..c93a578 100644 --- a/jong/src/tui/render.rs +++ b/jong/src/tui/render.rs @@ -93,21 +93,6 @@ pub(crate) fn render( Ok(()) } -pub(crate) fn query_tester( - mut commands: Commands, - mut tui: ResMut, - - hovered: Query>, - layouts: Res, - - tiles: Query<&jong_types::Tile>, - // main_player: Single<(&Player, Entity /* , &Wind */), With>, - hand: Single<(&Children, Entity), With>, - drawn_tile: Option>>, -) { - trace!("owo") -} - // FIXME we don't care about other players atm #[allow(clippy::too_many_arguments, clippy::type_complexity)] pub(crate) fn render_hand( @@ -123,7 +108,7 @@ pub(crate) fn render_hand( drawn_tile: Option>>, ) -> Result { let mut frame = tui.get_frame(); - debug_blocks(*layouts, &mut frame); + debug_blocks(layouts.clone(), &mut frame); let hand: Vec<_> = hand .0 @@ -234,19 +219,8 @@ pub(crate) fn render_pond( }) .collect::>()?; - let mut this_pond = layouts.this_pond; - let row_constraints = [Constraint::Max(4); 3]; - let col_constraints = [Constraint::Max(5); 6]; - let row_layouts = Layout::vertical(row_constraints).flex(Flex::Start); - let col_layouts = Layout::horizontal(col_constraints).flex(Flex::Start); - let mut rows = row_layouts.areas::<3>(this_pond); - - for (rect, (_, tile)) in rows - .iter() - .flat_map(|row| col_layouts.areas::<6>(*row)) - .zip(pond) - { - frame.render_widget(tile, rect); + for (rect, (_, tile)) in layouts.this_pond_slots.iter().zip(pond) { + frame.render_widget(tile, *rect); } Ok(())