diff options
Diffstat (limited to 'graphics/src/render.rs')
| -rw-r--r-- | graphics/src/render.rs | 68 |
1 files changed, 63 insertions, 5 deletions
diff --git a/graphics/src/render.rs b/graphics/src/render.rs index 340189b..996aa37 100644 --- a/graphics/src/render.rs +++ b/graphics/src/render.rs @@ -496,13 +496,16 @@ impl Renderer { if self.debug { self.draw_debug_ui(r, dungeon); - return; + } else { + // Draw core ui components + self.draw_minimap(r, dungeon); + self.draw_inventory(r, &dungeon.player); + self.draw_stats(r, &dungeon.player); } - // Draw core ui components - self.draw_minimap(r, dungeon); - self.draw_inventory(r, &dungeon.player); - self.draw_stats(r, &dungeon.player); + if let Some(buf) = dungeon.msg.current() { + self.draw_msg(r, buf); + } } /// Draw in game minimap @@ -686,6 +689,61 @@ impl Renderer { draw_text!(self, r, UI_COL2, UI_ROW3, "FRAME {frame}"); } + /// Draw msg box + fn draw_msg<R>(&self, r: &mut R, msg: &[u8]) + where + R: RaylibDraw, + { + const MAX_LINES: u16 = 5; + const MSG_LEN: u16 = 20; + + const HEIGHT: u16 = MAX_LINES * FONT_SIZE + UI_PADDING * 2; + const WIDTH: u16 = MSG_LEN * FONT_SIZE + UI_PADDING * 2; + const X: u16 = RENDER_WIDTH / 2 - WIDTH / 2; + const Y: u16 = RENDER_HEIGHT - HEIGHT - UI_PADDING; + + // draw background + r.draw_rectangle( + X.into(), + Y.into(), + WIDTH.into(), + HEIGHT.into(), + Color::BLACK, + ); + r.draw_rectangle_lines( + X.into(), + Y.into(), + WIDTH.into(), + HEIGHT.into(), + Color::WHITE, + ); + + let mut x = 0; + let mut y = 0; + + let words = msg.split(u8::is_ascii_whitespace); + for word in words { + let left = MSG_LEN.saturating_sub(x); + if word.len() > left as usize { + y += 1; + x = 0; + } + + for char in word { + self.draw_char( + r, + *char, + X + UI_PADDING + x * FONT_SIZE, + Y + UI_PADDING + y * FONT_SIZE, + ); + + x += 1; + } + + x += 1; + } + } + /// Draws vertical text fn draw_text_vertical<R>(&self, r: &mut R, text: &[u8], x: u16, y_start: u16) where |