Add title to game map
This commit is contained in:
parent
b7d2cceff6
commit
13fa2ef87d
@ -81,7 +81,7 @@ fn ui<B: Backend>(f: &mut Frame<B>, model: &mut SetBotsLayoutScreen, rules: &Gam
|
|||||||
.set_default_empty_char(' ')
|
.set_default_empty_char(' ')
|
||||||
.add_colored_cells(current_boat)
|
.add_colored_cells(current_boat)
|
||||||
.add_colored_cells(other_boats)
|
.add_colored_cells(other_boats)
|
||||||
.set_title("Now, configure your boats")
|
.set_title("Choose your boat layout")
|
||||||
.set_legend(
|
.set_legend(
|
||||||
"n next boat \n\
|
"n next boat \n\
|
||||||
r rotate boat \n\n\
|
r rotate boat \n\n\
|
||||||
|
@ -63,6 +63,10 @@ impl<'a> GameMapWidget<'a> {
|
|||||||
pub fn estimated_size(&self) -> (u16, u16) {
|
pub fn estimated_size(&self) -> (u16, u16) {
|
||||||
let (w, mut h) = self.grid_size();
|
let (w, mut h) = self.grid_size();
|
||||||
|
|
||||||
|
if self.title.is_some() {
|
||||||
|
h += 2;
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(l) = &self.legend {
|
if let Some(l) = &self.legend {
|
||||||
h += 1 + l.split('\n').count() as u16;
|
h += 1 + l.split('\n').count() as u16;
|
||||||
}
|
}
|
||||||
@ -77,12 +81,19 @@ impl<'a> Widget for GameMapWidget<'a> {
|
|||||||
|
|
||||||
let symbols = BorderType::line_symbols(BorderType::Plain);
|
let symbols = BorderType::line_symbols(BorderType::Plain);
|
||||||
|
|
||||||
// TODO : render title
|
let mut start_y = area.y;
|
||||||
|
|
||||||
|
// Render title
|
||||||
|
if let Some(title) = &self.title {
|
||||||
|
let x = centered_rect_size(title.len() as u16, 1, &area).x;
|
||||||
|
buf.set_string(x, start_y, title, Style::default());
|
||||||
|
start_y += 2;
|
||||||
|
}
|
||||||
|
|
||||||
// Paint game grid
|
// Paint game grid
|
||||||
for y in 0..(self.rules.map_height + 1) {
|
for y in 0..(self.rules.map_height + 1) {
|
||||||
if y < self.rules.map_height {
|
if y < self.rules.map_height {
|
||||||
buf.get_mut(area.x, area.y + 2 + (y as u16 * 2))
|
buf.get_mut(area.x, start_y + 2 + (y as u16 * 2))
|
||||||
.set_char(alphabet.chars().nth(y).unwrap());
|
.set_char(alphabet.chars().nth(y).unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,14 +101,14 @@ impl<'a> Widget for GameMapWidget<'a> {
|
|||||||
if x < self.rules.map_width {
|
if x < self.rules.map_width {
|
||||||
buf.set_string(
|
buf.set_string(
|
||||||
area.x + 2 + (x as u16 * 2) - (x as u16) / 10,
|
area.x + 2 + (x as u16 * 2) - (x as u16) / 10,
|
||||||
area.y,
|
start_y,
|
||||||
x.to_string(),
|
x.to_string(),
|
||||||
Style::default(),
|
Style::default(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let o_x = 1 + area.x + (x as u16 * 2);
|
let o_x = 1 + area.x + (x as u16 * 2);
|
||||||
let o_y = 1 + area.y + (y as u16 * 2);
|
let o_y = 1 + start_y + (y as u16 * 2);
|
||||||
|
|
||||||
buf.get_mut(o_x, o_y).set_symbol(match (x, y) {
|
buf.get_mut(o_x, o_y).set_symbol(match (x, y) {
|
||||||
(0, 0) => symbols.top_left,
|
(0, 0) => symbols.top_left,
|
||||||
@ -142,16 +153,16 @@ impl<'a> Widget for GameMapWidget<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
start_y += self.grid_size().1;
|
||||||
|
|
||||||
// Paint legend (if any)
|
// Paint legend (if any)
|
||||||
if let Some(legend) = &self.legend {
|
if let Some(legend) = &self.legend {
|
||||||
let (_, mut y) = self.grid_size();
|
start_y += 1;
|
||||||
y += area.y + 1;
|
|
||||||
|
|
||||||
for line in legend.split('\n') {
|
for line in legend.split('\n') {
|
||||||
let center_rect = centered_rect_size(line.len() as u16, 1, &area);
|
let center_rect = centered_rect_size(line.len() as u16, 1, &area);
|
||||||
let x = center_rect.x;
|
let x = center_rect.x;
|
||||||
buf.set_string(x, y, line, Style::default());
|
buf.set_string(x, start_y, line, Style::default());
|
||||||
y += 1;
|
start_y += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user