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

View file

@ -85,21 +85,24 @@ pub fn draw_lerping_bar(
max: i32,
full_colour: RGB,
empty_colour: RGB,
with_text: bool
with_text: bool,
with_bg: bool
) {
let percent = (n as f32) / (max as f32);
let fill_width = (percent * (width as f32)) as i32;
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 {
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 {
ctx.print(sx - 1, sy, "[");
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, "]");
}
}
@ -126,23 +129,25 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) {
draw_lerping_bar(
ctx,
2 * TEXT_FONT_MOD,
53 * TEXT_FONT_MOD,
22,
53,
22 * TEXT_FONT_MOD,
stats.hit_points.current,
stats.hit_points.max,
RGB::from_u8(0, 255, 0),
RGB::from_u8(255, 0, 0),
true,
true
);
draw_lerping_bar(
ctx,
2 * TEXT_FONT_MOD,
54 * TEXT_FONT_MOD,
22,
54,
22 * TEXT_FONT_MOD,
stats.mana.current,
stats.mana.max,
RGB::named(rltk::BLUE),
RGB::named(rltk::BLACK),
true,
true
);
// 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::data::ids::*;
use rltk::prelude::*;
@ -34,10 +46,19 @@ impl Tooltip {
return (self.lines.len() as i32) + 2i32;
}
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() {
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 {
// Render to the left
arrow = to_cp437('→');
arrow_x = mouse_pos.0 - 1;
arrow_x = mouse_pos.0 * 2 - 1;
} else {
// Render to the right
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_active_console(0);
let mut total_height = 0;
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() {
let x = if mouse_pos.0 > 35 {
mouse_pos.0 - (1 + t.width())
(mouse_pos.0 * 2) - (1 + t.width())
} else {
mouse_pos.0 + (1 + 1)
(mouse_pos.0 * 2) + 2 + 1
};
t.render(ctx, x, y);
y += t.height();