Add healthbars, rebase fixes, warning fixes

Former-commit-id: e293133eb18452a53446d2d765ecbe00e50720ba
This commit is contained in:
Imbris 2019-05-19 12:25:02 -04:00
parent 93ec66a8b1
commit 45bea22727
5 changed files with 31 additions and 18 deletions

View File

@ -48,7 +48,7 @@ const MANA_COLOR: Color = Color::Rgba(0.42, 0.41, 0.66, 1.0);
widget_ids! {
struct Ids {
// Character Names
name_tags[],
ingame_elements[],
// Test
temp,
@ -271,29 +271,42 @@ impl Hud {
return events;
}
// Nametags
// Nametags and healthbars
{
let ecs = client.state().ecs();
{
let actor_read_storage = ecs.read_storage::<comp::Actor>();
let pos_read_storage = ecs.read_storage::<comp::phys::Pos>();
let num = (&actor_read_storage, &pos_read_storage).join().count();
self.ids
.name_tags
.resize(num, &mut ui_widgets.widget_id_generator());
for (i, (name, pos)) in (&actor_read_storage, &pos_read_storage)
let actor = ecs.read_storage::<comp::Actor>();
let pos = ecs.read_storage::<comp::phys::Pos>();
let stats = ecs.read_storage::<comp::stats::Stats>();
let mut id_walker = self.ids.ingame_elements.walk();
for (pos, name) in (&pos, &actor)
.join()
.map(|(actor, pos)| match actor {
comp::Actor::Character { name, .. } => (name, pos.0),
.filter_map(|(pos, actor)| match actor {
comp::Actor::Character { name, .. } => Some((pos.0, name)),
_ => None,
})
.enumerate()
{
let id = id_walker.next(&mut self.ids.ingame_elements, &mut ui_widgets.widget_id_generator());
Text::new(&name)
.font_size(20)
.color(Color::Rgba(1.0, 1.0, 1.0, 1.0))
.x_y(0.0, 0.0)
.position_ingame(pos + Vec3::new(0.0, 0.0, 3.0))
.resolution(100.0)
.set(self.ids.name_tags[i], ui_widgets);
.set(id, ui_widgets);
}
for (pos, hp) in (&pos, &stats).join().map(|(pos, stats)| (pos.0, stats.hp)) {
let id = id_walker.next(&mut self.ids.ingame_elements, &mut ui_widgets.widget_id_generator());
(
// Healh Bar
Rectangle::fill_with([120.0, 12.0], color::BLACK)
.x_y(0.0, -25.0),
// Filling
Rectangle::fill_with([114.0 * (hp.current as f64 / hp.maximum as f64), 6.0], HP_COLOR)
.x_y(0.0, -25.0),
)
.position_ingame(pos + Vec3::new(0.0, 0.0, 3.0))
.resolution(100.0)
.set(id, ui_widgets);
}
}
// test

View File

@ -314,7 +314,7 @@ impl Renderer {
memory::Typed,
};
type WinSurfaceData = <<WinColorFmt as Formatted>::Surface as SurfaceTyped>::DataType;
let mut download = self
let download = self
.factory
.create_download_buffer::<WinSurfaceData>(width as usize * height as usize)
.map_err(|err| RenderError::BufferCreationError(err))?;

View File

@ -173,7 +173,7 @@ impl PlayState for SessionState {
// Maintain the scene.
self.scene.maintain(
global_state.window.renderer_mut(),
&self.client.borrow_mut(),
&self.client.borrow(),
);
// extract HUD events ensuring the client borrow gets dropped

View File

@ -223,7 +223,7 @@ impl<W: Ingameable> Widget for Ingame<W> {
type Style = Style;
type Event = W::Event;
fn init_state(&self, mut id_gen: widget::id::Generator) -> Self::State {
fn init_state(&self, id_gen: widget::id::Generator) -> Self::State {
State {
ids: W::init_ids(id_gen),
parameters: self.parameters,

View File

@ -219,7 +219,7 @@ impl Window {
std::thread::spawn(move || {
use std::{path::PathBuf, time::SystemTime};
// Check if folder exists and create it if it does not
let mut path = std::path::PathBuf::from("./screenshots");
let mut path = PathBuf::from("./screenshots");
if !path.exists() {
if let Err(err) = std::fs::create_dir(&path) {
log::error!("Coudn't create folder for screenshot: {:?}", err);