From 4e506cd0bebbac385780ec86b4992c79c3b58311 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Wed, 2 Feb 2022 09:34:20 -0500 Subject: [PATCH] Use multiple console instances so we can render the log in a larger font --- src/gamelog.rs | 2 +- src/gamelog/logstore.rs | 25 ++++++++++++++++--------- src/main.rs | 2 ++ src/state.rs | 6 ++++++ 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/gamelog.rs b/src/gamelog.rs index fd39ded..6d4c897 100644 --- a/src/gamelog.rs +++ b/src/gamelog.rs @@ -10,7 +10,7 @@ use ::serde::{Deserialize, Serialize}; pub use builder::*; pub use events::*; use logstore::*; -pub use logstore::{clear_log, clone_log, log_display, restore_log}; +pub use logstore::{clear_log, clone_log, print_log, restore_log}; /// A section of colored text for the game log #[derive(Serialize, Deserialize, Clone)] diff --git a/src/gamelog/logstore.rs b/src/gamelog/logstore.rs index 47bcdd1..9a632ba 100644 --- a/src/gamelog/logstore.rs +++ b/src/gamelog/logstore.rs @@ -3,6 +3,7 @@ use std::sync::Mutex; use ::rltk::prelude::*; use super::LogFragment; +use crate::colors; lazy_static! { static ref LOG: Mutex>> = Mutex::new(Vec::new()); @@ -21,18 +22,24 @@ pub fn clear_log() { LOG.lock().unwrap().clear(); } -pub fn log_display() -> TextBuilder { - let mut buf = TextBuilder::empty(); - - LOG.lock().unwrap().iter().rev().take(12).for_each(|log| { +pub fn print_log(console: &mut Box, pos: Point) { + let mut y = pos.y; + let mut x = pos.x; + LOG.lock().unwrap().iter().rev().take(6).for_each(|log| { log.iter().for_each(|frag| { - buf.fg(frag.color); - buf.line_wrap(&frag.text); + console.print_color( + x, + y, + frag.color.to_rgba(1.0), + colors::BLACK.to_rgba(1.0), + &frag.text, + ); + x += frag.text.len() as i32; + x += 1; }); - buf.ln(); + y += 1; + x = pos.x; }); - - buf } pub fn clone_log() -> Vec> { diff --git a/src/main.rs b/src/main.rs index dc99908..d161732 100644 --- a/src/main.rs +++ b/src/main.rs @@ -200,6 +200,8 @@ fn main() -> ::rltk::BError { let context = RltkBuilder::simple(80, 60) .unwrap() .with_title("Roguelike Tutorial") + .with_font("vga8x16.png", 8, 16) + .with_sparse_console(80, 30, "vga8x16.png") .build()?; main_loop(context, init_state()) diff --git a/src/state.rs b/src/state.rs index 916ecc4..19948e0 100644 --- a/src/state.rs +++ b/src/state.rs @@ -184,6 +184,9 @@ impl GameState for State { newrunstate = *runstate; } + ctx.set_active_console(1); + ctx.cls(); + ctx.set_active_console(0); ctx.cls(); particle_system::update_particles(&mut self.ecs, ctx); @@ -201,6 +204,9 @@ impl GameState for State { if !SHOW_MAPGEN_VISUALIZER { newrunstate = self.mapgen_next_state.unwrap(); } + ctx.set_active_console(1); + ctx.cls(); + ctx.set_active_console(0); ctx.cls(); if self.mapgen_index < self.mapgen_history.len() { camera::render_debug_map(&self.mapgen_history[self.mapgen_index], ctx);