Batch render tooltips, completing section 5.30
This commit is contained in:
parent
0b82f12bd8
commit
9fa0b46a16
@ -12,7 +12,7 @@ pub enum ItemMenuResult {
|
|||||||
|
|
||||||
pub fn menu_box<T: ToString>(draw_batch: &mut DrawBatch, x: i32, y: i32, width: i32, title: T) {
|
pub fn menu_box<T: ToString>(draw_batch: &mut DrawBatch, x: i32, y: i32, width: i32, title: T) {
|
||||||
draw_batch.draw_box(
|
draw_batch.draw_box(
|
||||||
Rect::with_size(x, y - 2, 31, width),
|
Rect::with_size(x, y - 2, 51, width),
|
||||||
ColorPair::new(colors::WHITE, colors::BLACK),
|
ColorPair::new(colors::WHITE, colors::BLACK),
|
||||||
);
|
);
|
||||||
draw_batch.print_color(
|
draw_batch.print_color(
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use ::rltk::{Point, Rltk};
|
use ::rltk::prelude::*;
|
||||||
use ::specs::prelude::*;
|
use ::specs::prelude::*;
|
||||||
|
|
||||||
|
use super::get_item_display_name;
|
||||||
use crate::components::{Attributes, Duration, Hidden, Name, Pools, StatusEffect};
|
use crate::components::{Attributes, Duration, Hidden, Name, Pools, StatusEffect};
|
||||||
use crate::{camera, colors, Map};
|
use crate::{camera, colors, Map};
|
||||||
|
|
||||||
@ -32,14 +33,10 @@ impl Tooltip {
|
|||||||
self.lines.len() as i32 + 2
|
self.lines.len() as i32 + 2
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render(&self, ctx: &mut Rltk, x: i32, y: i32) {
|
fn render(&self, draw_batch: &mut DrawBatch, x: i32, y: i32) {
|
||||||
ctx.draw_box(
|
draw_batch.draw_box(
|
||||||
x,
|
Rect::with_size(x, y, self.width() - 1, self.height() - 1),
|
||||||
y,
|
ColorPair::new(colors::WHITE, colors::BOX_GRAY),
|
||||||
self.width() - 1,
|
|
||||||
self.height() - 1,
|
|
||||||
colors::WHITE,
|
|
||||||
colors::BOX_GRAY,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
for (i, s) in self.lines.iter().enumerate() {
|
for (i, s) in self.lines.iter().enumerate() {
|
||||||
@ -48,13 +45,17 @@ impl Tooltip {
|
|||||||
} else {
|
} else {
|
||||||
colors::LIGHT_GRAY
|
colors::LIGHT_GRAY
|
||||||
};
|
};
|
||||||
ctx.print_color(x + 1, y + i as i32 + 1, col, colors::BLACK, &s);
|
draw_batch.print_color(
|
||||||
|
Point::new(x + 1, y + i as i32 + 1),
|
||||||
|
&s,
|
||||||
|
ColorPair::new(col, colors::BLACK),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_tooltips(ecs: &World, ctx: &mut Rltk) {
|
pub fn draw_tooltips(ecs: &World, ctx: &mut Rltk) {
|
||||||
use ::rltk::{to_cp437, Algorithm2D};
|
let mut draw_batch = DrawBatch::new();
|
||||||
|
|
||||||
let (min_x, _max_x, min_y, _max_y) = camera::get_screen_bounds(ecs, ctx);
|
let (min_x, _max_x, min_y, _max_y) = camera::get_screen_bounds(ecs, ctx);
|
||||||
let map = ecs.fetch::<Map>();
|
let map = ecs.fetch::<Map>();
|
||||||
@ -94,7 +95,7 @@ pub fn draw_tooltips(ecs: &World, ctx: &mut Rltk) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut tip = Tooltip::new();
|
let mut tip = Tooltip::new();
|
||||||
tip.add(super::get_item_display_name(ecs, entity));
|
tip.add(get_item_display_name(ecs, entity));
|
||||||
|
|
||||||
// Comment on attributes
|
// Comment on attributes
|
||||||
if let Some(attr) = attributes.get(entity) {
|
if let Some(attr) = attributes.get(entity) {
|
||||||
@ -164,7 +165,11 @@ pub fn draw_tooltips(ecs: &World, ctx: &mut Rltk) {
|
|||||||
arrow = to_cp437('←');
|
arrow = to_cp437('←');
|
||||||
arrow_x = mouse_pos.0 + 1;
|
arrow_x = mouse_pos.0 + 1;
|
||||||
}
|
}
|
||||||
ctx.set(arrow_x, arrow_y, colors::WHITE, colors::BOX_GRAY, arrow);
|
draw_batch.set(
|
||||||
|
Point::new(arrow_x, arrow_y),
|
||||||
|
ColorPair::new(colors::WHITE, colors::BOX_GRAY),
|
||||||
|
arrow,
|
||||||
|
);
|
||||||
|
|
||||||
let mut total_height = 0;
|
let mut total_height = 0;
|
||||||
for tt in tip_boxes.iter() {
|
for tt in tip_boxes.iter() {
|
||||||
@ -182,7 +187,9 @@ pub fn draw_tooltips(ecs: &World, ctx: &mut Rltk) {
|
|||||||
} else {
|
} else {
|
||||||
mouse_pos.0 + (1 + tt.width())
|
mouse_pos.0 + (1 + tt.width())
|
||||||
};
|
};
|
||||||
tt.render(ctx, x, y);
|
tt.render(&mut draw_batch, x, y);
|
||||||
y += tt.height();
|
y += tt.height();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
draw_batch.submit(7000).expect("Failed to render tooltip");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user