diff --git a/assets/voxygen/element/skill_bar/xp_bar2.png b/assets/voxygen/element/skill_bar/xp_bar2.png deleted file mode 100644 index 15ddbb5c8a..0000000000 Binary files a/assets/voxygen/element/skill_bar/xp_bar2.png and /dev/null differ diff --git a/assets/voxygen/element/skill_bar/xp_bar_l.png b/assets/voxygen/element/skill_bar/xp_bar_l.png deleted file mode 100644 index d2218dd26d..0000000000 Binary files a/assets/voxygen/element/skill_bar/xp_bar_l.png and /dev/null differ diff --git a/assets/voxygen/element/skill_bar/xp_bar_l_filled.png b/assets/voxygen/element/skill_bar/xp_bar_l_filled.png deleted file mode 100644 index 71f8e1ae74..0000000000 Binary files a/assets/voxygen/element/skill_bar/xp_bar_l_filled.png and /dev/null differ diff --git a/assets/voxygen/element/skill_bar/xp_bar_r.png b/assets/voxygen/element/skill_bar/xp_bar_r.png deleted file mode 100644 index 81e3f11b9f..0000000000 Binary files a/assets/voxygen/element/skill_bar/xp_bar_r.png and /dev/null differ diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index dde053f24c..0278649d0e 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -276,16 +276,24 @@ impl Hud { let ecs = client.state().ecs(); let actor = ecs.read_storage::(); let pos = ecs.read_storage::(); - let stats = ecs.read_storage::(); + let stats = ecs.read_storage::(); + let entities = ecs.entities(); + let player = client.entity(); let mut id_walker = self.ids.ingame_elements.walk(); - for (pos, name) in (&pos, &actor) - .join() - .filter_map(|(pos, actor)| match actor { - comp::Actor::Character { name, .. } => Some((pos.0, name)), - _ => None, - }) + for (pos, name) in + (&entities, &pos, &actor) + .join() + .filter_map(|(entity, pos, actor)| match actor { + comp::Actor::Character { name, .. } if entity != player => { + Some((pos.0, name)) + } + _ => None, + }) { - let id = id_walker.next(&mut self.ids.ingame_elements, &mut ui_widgets.widget_id_generator()); + 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)) @@ -294,15 +302,30 @@ impl Hud { .resolution(100.0) .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()); + for (pos, hp) in (&entities, &pos, &stats) + .join() + .filter_map(|(entity, pos, stats)| { + if entity != player { + Some((pos.0, stats.hp)) + } else { + None + } + }) + { + 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) + Rectangle::fill_with([120.0, 8.0], Color::Rgba(0.3, 0.3, 0.3, 0.5)) .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), + Rectangle::fill_with( + [120.0 * (hp.current as f64 / hp.maximum as f64), 8.0], + HP_COLOR, + ) + .x_y(0.0, -25.0), ) .position_ingame(pos + Vec3::new(0.0, 0.0, 3.0)) .resolution(100.0) @@ -418,7 +441,15 @@ impl Hud { } // Skillbar - Skillbar::new(&self.imgs, &self.fonts).set(self.ids.skillbar, ui_widgets); + // Get player stats + let stats = client + .state() + .ecs() + .read_storage::() + .get(client.entity()) + .map(|&s| s) + .unwrap_or_default(); + Skillbar::new(&self.imgs, &self.fonts, stats).set(self.ids.skillbar, ui_widgets); // Chat box match Chat::new(&mut self.new_messages, &self.imgs, &self.fonts) diff --git a/voxygen/src/hud/skillbar.rs b/voxygen/src/hud/skillbar.rs index 2bfc8a307d..7e2fc45207 100644 --- a/voxygen/src/hud/skillbar.rs +++ b/voxygen/src/hud/skillbar.rs @@ -1,4 +1,5 @@ use super::{img_ids::Imgs, Fonts, HP_COLOR, MANA_COLOR, TEXT_COLOR, XP_COLOR}; +use common::comp::Stats; use conrod_core::{ widget::{self, Image, Rectangle, Text}, widget_ids, Colorable, Positionable, Sizeable, Widget, WidgetCommon, @@ -30,15 +31,18 @@ pub struct Skillbar<'a> { imgs: &'a Imgs, fonts: &'a Fonts, + stats: Stats, + #[conrod(common_builder)] common: widget::CommonBuilder, } impl<'a> Skillbar<'a> { - pub fn new(imgs: &'a Imgs, fonts: &'a Fonts) -> Self { + pub fn new(imgs: &'a Imgs, fonts: &'a Fonts, stats: Stats) -> Self { Self { imgs, fonts, + stats, common: widget::CommonBuilder::default(), } } @@ -68,9 +72,13 @@ impl<'a> Widget for Skillbar<'a> { fn update(self, args: widget::UpdateArgs) -> Self::Event { let widget::UpdateArgs { state, ui, .. } = args; - // TODO: Read from parameter/character struct - let xp_percentage = 0.4; - let hp_percentage = 1.0; + // TODO: remove this + let level = (self.stats.xp as f64).log(4.0).trunc() as u32 + 1; + let start_level_xp = ((level - 1) as f64).powi(4); + let next_level_xp = (level as f64).powi(4) - start_level_xp; + // TODO: We need a max xp value + let xp_percentage = (self.stats.xp as f64 - start_level_xp) / next_level_xp; + let hp_percentage = self.stats.hp.current as f64 / self.stats.hp.maximum as f64; let mana_percentage = 1.0; // TODO: Only show while aiming with a bow or when casting a spell. @@ -82,7 +90,7 @@ impl<'a> Widget for Skillbar<'a> { // Experience-Bar Image::new(self.imgs.xp_bar) - .w_h(2688.0 / 6.0, 116.0 / 6.0) + .w_h(672.0 / 1.5, 29.0 / 1.5) .mid_bottom_of(ui.window) .set(state.ids.xp_bar, ui); @@ -92,37 +100,37 @@ impl<'a> Widget for Skillbar<'a> { // Left Grid Image::new(self.imgs.sb_grid) - .w_h(2240.0 / 12.0, 448.0 / 12.0) + .w_h(280.0 / 1.5, 56.0 / 1.5) .up_from(state.ids.xp_bar, 0.0) .align_left_of(state.ids.xp_bar) .set(state.ids.sb_grid_l, ui); Image::new(self.imgs.sb_grid_bg) - .w_h(2240.0 / 12.0, 448.0 / 12.0) + .w_h(280.0 / 1.5, 56.0 / 1.5) .middle_of(state.ids.sb_grid_l) .set(state.ids.sb_grid_bg_l, ui); // Right Grid Image::new(self.imgs.sb_grid) - .w_h(2240.0 / 12.0, 448.0 / 12.0) + .w_h(280.0 / 1.5, 56.0 / 1.5) .up_from(state.ids.xp_bar, 0.0) .align_right_of(state.ids.xp_bar) .set(state.ids.sb_grid_r, ui); Image::new(self.imgs.sb_grid_bg) - .w_h(2240.0 / 12.0, 448.0 / 12.0) + .w_h(280.0 / 1.5, 56.0 / 1.5) .middle_of(state.ids.sb_grid_r) .set(state.ids.sb_grid_bg_r, ui); // Right and Left Click Image::new(self.imgs.l_click) - .w_h(224.0 / 6.0, 320.0 / 6.0) + .w_h(56.0 / 1.5, 80.0 / 1.5) .right_from(state.ids.sb_grid_bg_l, 0.0) .align_bottom_of(state.ids.sb_grid_bg_l) .set(state.ids.l_click, ui); Image::new(self.imgs.r_click) - .w_h(224.0 / 6.0, 320.0 / 6.0) + .w_h(56.0 / 1.5, 80.0 / 1.5) .left_from(state.ids.sb_grid_bg_r, 0.0) .align_bottom_of(state.ids.sb_grid_bg_r) .set(state.ids.r_click, ui); @@ -135,7 +143,7 @@ impl<'a> Widget for Skillbar<'a> { .set(state.ids.health_bar, ui); // Filling - Rectangle::fill_with([182.0 * (hp_percentage), 6.0], HP_COLOR) // "W=182.0 * [Health. %]" + Rectangle::fill_with([182.0 * hp_percentage, 6.0], HP_COLOR) // "W=182.0 * [Health. %]" .top_right_with_margins_on(state.ids.health_bar, 5.0, 0.0) .set(state.ids.health_bar_color, ui); @@ -147,7 +155,7 @@ impl<'a> Widget for Skillbar<'a> { .set(state.ids.mana_bar, ui); // Filling - Rectangle::fill_with([182.0 * (mana_percentage), 6.0], MANA_COLOR) // "W=182.0 * [Mana. %]" + Rectangle::fill_with([182.0 * mana_percentage, 6.0], MANA_COLOR) // "W=182.0 * [Mana. %]" .top_left_with_margins_on(state.ids.mana_bar, 5.0, 0.0) .set(state.ids.mana_bar_color, ui); @@ -159,15 +167,16 @@ impl<'a> Widget for Skillbar<'a> { // Level Display + // TODO: don't construct a new string here // TODO: Insert actual Level here. - Text::new("1") + Text::new(&level.to_string()) .left_from(state.ids.xp_bar, -15.0) .font_size(10) .color(TEXT_COLOR) .set(state.ids.level_text, ui); // TODO: Insert next Level here. - Text::new("2") + Text::new(&(level + 1).to_string()) .right_from(state.ids.xp_bar, -15.0) .font_size(10) .color(TEXT_COLOR) diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index d095dfffcc..8be80e3703 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -171,10 +171,8 @@ impl PlayState for SessionState { global_state.maintain(); // Maintain the scene. - self.scene.maintain( - global_state.window.renderer_mut(), - &self.client.borrow(), - ); + self.scene + .maintain(global_state.window.renderer_mut(), &self.client.borrow()); // extract HUD events ensuring the client borrow gets dropped let hud_events = self.hud.maintain( diff --git a/voxygen/src/ui/widgets/ingame.rs b/voxygen/src/ui/widgets/ingame.rs index 4f6cd8eee3..c360d73672 100644 --- a/voxygen/src/ui/widgets/ingame.rs +++ b/voxygen/src/ui/widgets/ingame.rs @@ -65,7 +65,7 @@ where } } -trait IngameWidget: Ingameable + Widget {} +pub trait IngameWidget: Ingameable + Widget {} impl IngameWidget for T where T: Ingameable + Widget {} impl Ingameable for (W, E) @@ -148,7 +148,7 @@ where } #[derive(Clone, Copy)] -enum Ids { +pub enum Ids { None, One(Id), Two([Id; 2]),