Display grid coordinates

This commit is contained in:
Pierre HUBERT 2022-10-07 11:53:43 +02:00
parent 8728cbb612
commit aea9175b7e
2 changed files with 27 additions and 5 deletions

View File

@ -81,7 +81,12 @@ fn ui<B: Backend>(f: &mut Frame<B>, model: &mut SetBotsLayoutScreen, rules: &Gam
.set_default_empty_char(' ')
.add_colored_cells(current_boat)
.add_colored_cells(other_boats)
.set_legend("n next boat \nr rotate boat \n\n↓ ↑ → ← move boat \n\nEnter confirm layout");
.set_legend(
"n next boat \n\
r rotate boat \n\n\
move boat \n\n\
Enter confirm layout",
);
let (w, h) = game_map_widget.estimated_size();
let area = centered_rect_size(w, h, &f.size());

View File

@ -1,11 +1,14 @@
use crate::ui_screens::utils::centered_rect_size;
use sea_battle_backend::data::{Coordinates, GameRules, PlayConfiguration};
use std::fmt::Display;
use tui::buffer::Buffer;
use tui::layout::Rect;
use tui::style::{Color, Style};
use tui::widgets::{BorderType, Widget};
use sea_battle_backend::data::{Coordinates, GameRules, PlayConfiguration};
use crate::ui_screens::utils::centered_rect_size;
pub struct ColoredCells {
pub color: Color,
pub cells: Vec<Coordinates>,
@ -69,9 +72,23 @@ impl<'a> Widget for GameMapWidget<'a> {
// Paint game grid
for y in 0..(self.rules.map_height + 1) {
if y < self.rules.map_height {
buf.get_mut(area.x, area.y + 2 + (y as u16 * 2))
.set_char(alphabet.chars().nth(y).unwrap());
}
for x in 0..(self.rules.map_width + 1) {
let o_x = area.x + (x as u16 * 2);
let o_y = area.y + (y as u16 * 2);
if x < self.rules.map_width {
buf.set_string(
area.x + 2 + (x as u16 * 2) - (x as u16) / 10,
area.y,
x.to_string(),
Style::default(),
);
}
let o_x = 1 + area.x + (x as u16 * 2);
let o_y = 1 + area.y + (y as u16 * 2);
buf.get_mut(o_x, o_y).set_symbol(match (x, y) {
(0, 0) => symbols.top_left,