back to curses -- still needs tweaking

box drawing glyphs are misaligned, etc
This commit is contained in:
Llywelwyn 2023-09-03 08:42:10 +01:00
parent ebcce3183b
commit ae3e061ce8
7 changed files with 60 additions and 31 deletions

BIN
resources/curses8x16.pdn Normal file

Binary file not shown.

BIN
resources/curses8x16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

View file

@ -132,13 +132,14 @@ pub fn render_camera(ecs: &World, ctx: &mut Rltk) {
ctx.set_active_console(2); ctx.set_active_console(2);
crate::gui::draw_lerping_bar( crate::gui::draw_lerping_bar(
ctx, ctx,
(entity_offset_x + x_offset) * 22 + 2, (entity_offset_x + x_offset) * 16 + 2,
(entity_offset_y + y_offset) * 20 - 2, (entity_offset_y + y_offset) * 16 - 1,
18, 14,
pool.hit_points.current, pool.hit_points.current,
pool.hit_points.max, pool.hit_points.max,
RGB::named(GREEN), RGB::named(GREEN),
RGB::named(RED), RGB::named(RED),
false,
false false
); );
ctx.set_active_console(0); ctx.set_active_console(0);

View file

@ -1,7 +1,7 @@
// POST-PROCESSING // POST-PROCESSING
pub const WITH_DARKEN_BY_DISTANCE: bool = true; // If further away tiles should get darkened, instead of a harsh transition to non-visible. pub const WITH_DARKEN_BY_DISTANCE: bool = true; // If further away tiles should get darkened, instead of a harsh transition to non-visible.
pub const VIEWPORT_W: i32 = 40; pub const VIEWPORT_W: i32 = 69;
pub const VIEWPORT_H: i32 = 30; pub const VIEWPORT_H: i32 = 41;
pub const BRIGHTEN_FG_COLOUR_BY: i32 = 16; pub const BRIGHTEN_FG_COLOUR_BY: i32 = 16;
pub const GLOBAL_OFFSET_MIN_CLAMP: f32 = -0.5; pub const GLOBAL_OFFSET_MIN_CLAMP: f32 = -0.5;

View file

@ -85,21 +85,24 @@ pub fn draw_lerping_bar(
max: i32, max: i32,
full_colour: RGB, full_colour: RGB,
empty_colour: RGB, empty_colour: RGB,
with_text: bool with_text: bool,
with_bg: bool
) { ) {
let percent = (n as f32) / (max as f32); let percent = (n as f32) / (max as f32);
let fill_width = (percent * (width as f32)) as i32; let fill_width = (percent * (width as f32)) as i32;
let bg = empty_colour.lerp(full_colour, percent); let bg = empty_colour.lerp(full_colour, percent);
let fg = RGB::named(rltk::BLACK); let black = RGB::named(rltk::BLACK);
for x in 0..width { for x in 0..width {
if x <= fill_width { if x <= fill_width {
ctx.set(sx + x, sy, fg, bg, to_cp437(' ')); ctx.print_color(sx + x, sy, black, bg, ' ');
} else if with_bg {
ctx.print_color(sx + x, sy, black, black, ' ');
} }
} }
if with_text { if with_text {
ctx.print(sx - 1, sy, "["); ctx.print(sx - 1, sy, "[");
let health = format!("{}/{}", n, max); let health = format!("{}/{}", n, max);
ctx.print_color(sx + 1, sy, fg, bg, health); ctx.print_color(sx + 1, sy, black, bg, health);
ctx.print(sx + width, sy, "]"); ctx.print(sx + width, sy, "]");
} }
} }
@ -126,23 +129,25 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) {
draw_lerping_bar( draw_lerping_bar(
ctx, ctx,
2 * TEXT_FONT_MOD, 2 * TEXT_FONT_MOD,
53 * TEXT_FONT_MOD, 53,
22, 22 * TEXT_FONT_MOD,
stats.hit_points.current, stats.hit_points.current,
stats.hit_points.max, stats.hit_points.max,
RGB::from_u8(0, 255, 0), RGB::from_u8(0, 255, 0),
RGB::from_u8(255, 0, 0), RGB::from_u8(255, 0, 0),
true,
true true
); );
draw_lerping_bar( draw_lerping_bar(
ctx, ctx,
2 * TEXT_FONT_MOD, 2 * TEXT_FONT_MOD,
54 * TEXT_FONT_MOD, 54,
22, 22 * TEXT_FONT_MOD,
stats.mana.current, stats.mana.current,
stats.mana.max, stats.mana.max,
RGB::named(rltk::BLUE), RGB::named(rltk::BLUE),
RGB::named(rltk::BLACK), RGB::named(rltk::BLACK),
true,
true true
); );
// Draw AC // Draw AC

View file

@ -1,4 +1,16 @@
use super::{ camera::get_screen_bounds, Attributes, Hidden, Map, Name, Pools, Position, Renderable, Rltk, World, RGB }; use super::{
camera::get_screen_bounds,
Attributes,
Hidden,
Map,
Name,
Pools,
Position,
Renderable,
Rltk,
World,
RGB,
};
use crate::TileType; use crate::TileType;
use crate::data::ids::*; use crate::data::ids::*;
use rltk::prelude::*; use rltk::prelude::*;
@ -34,10 +46,19 @@ impl Tooltip {
return (self.lines.len() as i32) + 2i32; return (self.lines.len() as i32) + 2i32;
} }
fn render(&self, ctx: &mut Rltk, x: i32, y: i32) { fn render(&self, ctx: &mut Rltk, x: i32, y: i32) {
ctx.draw_box(x, y, self.width() - 1, self.height() - 1, RGB::named(WHITE), RGB::named(BLACK)); ctx.set_active_console(1);
ctx.draw_box(
x,
y,
self.width() - 1,
self.height() - 1,
RGB::named(WHITE),
RGB::named(BLACK)
);
for (i, s) in self.lines.iter().enumerate() { for (i, s) in self.lines.iter().enumerate() {
ctx.print_color(x + 1, y + (i as i32) + 1, s.1, RGB::named(BLACK), &s.0); ctx.print_color(x + 1, y + (i as i32) + 1, s.1, RGB::named(BLACK), &s.0);
} }
ctx.set_active_console(0);
} }
} }
@ -151,13 +172,15 @@ pub fn draw_tooltips(ecs: &World, ctx: &mut Rltk, xy: Option<(i32, i32)>) {
if mouse_pos.0 > 35 { if mouse_pos.0 > 35 {
// Render to the left // Render to the left
arrow = to_cp437('→'); arrow = to_cp437('→');
arrow_x = mouse_pos.0 - 1; arrow_x = mouse_pos.0 * 2 - 1;
} else { } else {
// Render to the right // Render to the right
arrow = to_cp437('←'); arrow = to_cp437('←');
arrow_x = mouse_pos.0 + 1; arrow_x = (mouse_pos.0 + 1) * 2;
} }
ctx.set_active_console(1);
ctx.set(arrow_x, arrow_y, white, RGB::named(rltk::BLACK), arrow); ctx.set(arrow_x, arrow_y, white, RGB::named(rltk::BLACK), arrow);
ctx.set_active_console(0);
let mut total_height = 0; let mut total_height = 0;
for t in tooltips.iter() { for t in tooltips.iter() {
@ -171,9 +194,9 @@ pub fn draw_tooltips(ecs: &World, ctx: &mut Rltk, xy: Option<(i32, i32)>) {
for t in tooltips.iter() { for t in tooltips.iter() {
let x = if mouse_pos.0 > 35 { let x = if mouse_pos.0 > 35 {
mouse_pos.0 - (1 + t.width()) (mouse_pos.0 * 2) - (1 + t.width())
} else { } else {
mouse_pos.0 + (1 + 1) (mouse_pos.0 * 2) + 2 + 1
}; };
t.render(ctx, x, y); t.render(ctx, x, y);
y += t.height(); y += t.height();

View file

@ -3,20 +3,20 @@ use specs::prelude::*;
use specs::saveload::{ SimpleMarker, SimpleMarkerAllocator }; use specs::saveload::{ SimpleMarker, SimpleMarkerAllocator };
use rltk::prelude::*; use rltk::prelude::*;
const DISPLAYWIDTH: i32 = 72; const DISPLAYWIDTH: i32 = 105;
const DISPLAYHEIGHT: i32 = 40; const DISPLAYHEIGHT: i32 = 56;
fn main() -> rltk::BError { fn main() -> rltk::BError {
// Embedded resources for use in wasm build // Embedded resources for use in wasm build
const MAIN_22_20_BYTES: &[u8] = include_bytes!("../resources/nagidal22x20_centred.png"); const CURSES_16_16_BYTES: &[u8] = include_bytes!("../resources/curses16x16.png");
const TEXT_11_20_BYTES: &[u8] = include_bytes!("../resources/curses11x20.png"); const CURSES_8_16_BYTES: &[u8] = include_bytes!("../resources/curses8x16.png");
const SINGLE_1_1_BYTES: &[u8] = include_bytes!("../resources/healthbar22x2.png"); const SINGLE_1_1_BYTES: &[u8] = include_bytes!("../resources/healthbar22x2.png");
rltk::embedding::EMBED rltk::embedding::EMBED
.lock() .lock()
.add_resource("resources/nagidal22x20_centred.png".to_string(), MAIN_22_20_BYTES); .add_resource("resources/curses16x16.png".to_string(), CURSES_16_16_BYTES);
rltk::embedding::EMBED rltk::embedding::EMBED
.lock() .lock()
.add_resource("resources/curses11x20.png".to_string(), TEXT_11_20_BYTES); .add_resource("resources/curses8x16.png".to_string(), CURSES_8_16_BYTES);
rltk::embedding::EMBED rltk::embedding::EMBED
.lock() .lock()
.add_resource("resources/healthbar22x2.png".to_string(), SINGLE_1_1_BYTES); .add_resource("resources/healthbar22x2.png".to_string(), SINGLE_1_1_BYTES);
@ -24,14 +24,14 @@ fn main() -> rltk::BError {
let mut context = RltkBuilder::new() let mut context = RltkBuilder::new()
.with_title("rust-rl") .with_title("rust-rl")
.with_dimensions(DISPLAYWIDTH, DISPLAYHEIGHT) .with_dimensions(DISPLAYWIDTH, DISPLAYHEIGHT)
.with_font("nagidal22x20_centred.png", 22, 20) .with_font("curses16x16.png", 16, 16)
.with_font("curses11x20.png", 11, 20) .with_font("curses8x16.png", 8, 16)
.with_font("healthbar22x2.png", 1, 1) .with_font("healthbar22x2.png", 1, 1)
.with_tile_dimensions(22, 20) .with_tile_dimensions(16, 16)
.with_gutter(2) .with_gutter(2)
.with_simple_console(DISPLAYWIDTH, DISPLAYHEIGHT, "nagidal22x20_centred.png") .with_simple_console(DISPLAYWIDTH, DISPLAYHEIGHT, "curses16x16.png")
.with_sparse_console(DISPLAYWIDTH * 2, DISPLAYHEIGHT, "curses11x20.png") .with_sparse_console(DISPLAYWIDTH * 2, DISPLAYHEIGHT, "curses8x16.png")
.with_sparse_console(DISPLAYWIDTH * 22, DISPLAYHEIGHT * 20, "healthbar22x2.png") .with_sparse_console(DISPLAYWIDTH * 16, DISPLAYHEIGHT * 16, "healthbar22x2.png")
.build()?; .build()?;
if config::CONFIG.visuals.with_scanlines { if config::CONFIG.visuals.with_scanlines {
context.with_post_scanlines(config::CONFIG.visuals.with_screen_burn); context.with_post_scanlines(config::CONFIG.visuals.with_screen_burn);