WIP generating chunks at player position
This commit is contained in:
+31
-12
@@ -5,6 +5,9 @@ use futures::executor::LocalPool;
|
||||
use futures::task::SpawnExt;
|
||||
|
||||
const WHITE: [f32; 4] = [1.0, 1.0, 1.0, 1.0];
|
||||
const BLUE: [f32; 4] = [0.0, 0.2, 1.0, 1.0];
|
||||
const GREEN: [f32; 4] = [0.1, 1.0, 0.0, 1.0];
|
||||
|
||||
|
||||
pub struct UserInterface {
|
||||
// Glyph drawing
|
||||
@@ -12,7 +15,7 @@ pub struct UserInterface {
|
||||
local_pool: LocalPool,
|
||||
brush: GlyphBrush<()>,
|
||||
// Texts
|
||||
texts: HashMap<u32, String>
|
||||
texts: HashMap<String, Vec<String>>
|
||||
}
|
||||
|
||||
impl UserInterface {
|
||||
@@ -27,20 +30,36 @@ impl UserInterface {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_text(&mut self, index: u32, text: String) {
|
||||
self.texts.insert(index, text);
|
||||
fn print(brush: &mut GlyphBrush<()>, line: u32, text: &str, color: [f32; 4]) {
|
||||
let t = Text::new(text).with_color(color);
|
||||
brush.queue(Section {
|
||||
screen_position: (5 as f32, (5 + line*15) as f32),
|
||||
bounds: (t.scale.x * t.text.len() as f32, t.scale.y),
|
||||
text: vec![t],
|
||||
..Section::default()
|
||||
});
|
||||
}
|
||||
|
||||
pub fn set_text(&mut self, cat: &str, line: usize, text: String) {
|
||||
// Category
|
||||
let c = &cat.to_string();
|
||||
if !self.texts.contains_key(c) {self.texts.insert(c.clone(), Vec::new());}
|
||||
// Texts
|
||||
let v = self.texts.get_mut(c).unwrap();
|
||||
while v.len() < line+1 { v.push(String::new()); }
|
||||
v[line] = text;
|
||||
}
|
||||
|
||||
pub fn render(&mut self, device: &wgpu::Device, encoder: &mut wgpu::CommandEncoder, target: &wgpu::TextureView, width: u32, height: u32) {
|
||||
for (id, text) in self.texts.iter() {
|
||||
|
||||
let text = Text::new(text).with_color(WHITE);
|
||||
self.brush.queue(Section {
|
||||
screen_position: (5 as f32, (5 + id*15) as f32),
|
||||
bounds: (text.scale.x * text.text.len() as f32, text.scale.y),
|
||||
text: vec![text],
|
||||
..Section::default()
|
||||
});
|
||||
let mut line = 0;
|
||||
for (cat, texts) in self.texts.iter_mut() {
|
||||
UserInterface::print(&mut self.brush, line, cat, GREEN);
|
||||
line += 1;
|
||||
for text in texts.iter() {
|
||||
UserInterface::print(&mut self.brush, line, text, WHITE);
|
||||
line += 1;
|
||||
}
|
||||
line += 1;
|
||||
}
|
||||
|
||||
// Draw
|
||||
|
||||
Reference in New Issue
Block a user