2019-05-08 20:25:15 +00:00
|
|
|
use super::{img_ids::Imgs, Fonts, HP_COLOR, MANA_COLOR, TEXT_COLOR, XP_COLOR};
|
2019-05-19 18:07:50 +00:00
|
|
|
use common::comp::Stats;
|
2019-05-04 06:07:23 +00:00
|
|
|
use conrod_core::{
|
2019-05-07 03:25:25 +00:00
|
|
|
widget::{self, Image, Rectangle, Text},
|
|
|
|
widget_ids, Colorable, Positionable, Sizeable, Widget, WidgetCommon,
|
2019-05-04 06:07:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
widget_ids! {
|
|
|
|
struct Ids {
|
|
|
|
health_bar,
|
|
|
|
health_bar_color,
|
|
|
|
l_click,
|
|
|
|
level_text,
|
|
|
|
mana_bar,
|
|
|
|
mana_bar_color,
|
|
|
|
next_level_text,
|
|
|
|
r_click,
|
|
|
|
sb_grid_bg_l,
|
|
|
|
sb_grid_bg_r,
|
|
|
|
sb_grid_l,
|
|
|
|
sb_grid_r,
|
|
|
|
test,
|
|
|
|
xp_bar,
|
|
|
|
xp_bar_progress,
|
2019-05-11 15:36:10 +00:00
|
|
|
crosshair,
|
2019-05-04 06:07:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(WidgetCommon)]
|
|
|
|
pub struct Skillbar<'a> {
|
|
|
|
imgs: &'a Imgs,
|
2019-07-02 21:25:07 +00:00
|
|
|
_fonts: &'a Fonts,
|
2019-06-30 11:48:28 +00:00
|
|
|
stats: &'a Stats,
|
2019-05-19 18:07:50 +00:00
|
|
|
|
2019-05-04 06:07:23 +00:00
|
|
|
#[conrod(common_builder)]
|
|
|
|
common: widget::CommonBuilder,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Skillbar<'a> {
|
2019-06-30 11:48:28 +00:00
|
|
|
pub fn new(imgs: &'a Imgs, fonts: &'a Fonts, stats: &'a Stats) -> Self {
|
2019-05-04 06:07:23 +00:00
|
|
|
Self {
|
|
|
|
imgs,
|
2019-07-02 21:25:07 +00:00
|
|
|
_fonts: fonts,
|
2019-05-19 18:07:50 +00:00
|
|
|
stats,
|
2019-05-04 06:07:23 +00:00
|
|
|
common: widget::CommonBuilder::default(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct State {
|
|
|
|
ids: Ids,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum Event {}
|
|
|
|
|
|
|
|
impl<'a> Widget for Skillbar<'a> {
|
|
|
|
type State = State;
|
|
|
|
type Style = ();
|
|
|
|
type Event = Option<Event>;
|
|
|
|
|
|
|
|
fn init_state(&self, id_gen: widget::id::Generator) -> Self::State {
|
|
|
|
State {
|
|
|
|
ids: Ids::new(id_gen),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn style(&self) -> Self::Style {
|
|
|
|
()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
|
2019-05-07 05:40:03 +00:00
|
|
|
let widget::UpdateArgs { state, ui, .. } = args;
|
2019-05-04 06:07:23 +00:00
|
|
|
|
2019-05-19 18:07:50 +00:00
|
|
|
// 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;
|
2019-06-30 11:48:28 +00:00
|
|
|
let hp_percentage =
|
|
|
|
self.stats.health.get_current() as f64 / self.stats.health.get_maximum() as f64;
|
2019-05-10 21:49:14 +00:00
|
|
|
let mana_percentage = 1.0;
|
2019-05-04 06:07:23 +00:00
|
|
|
|
2019-05-17 09:22:32 +00:00
|
|
|
// TODO: Only show while aiming with a bow or when casting a spell.
|
|
|
|
// Crosshair
|
2019-05-11 15:36:10 +00:00
|
|
|
// Image::new(self.imgs.crosshair)
|
|
|
|
// .w_h(101.0 * 0.5, 101.0 * 0.5)
|
|
|
|
// .mid_top_with_margin_on(ui.window, 500.0)
|
|
|
|
// .set(state.ids.crosshair, ui);
|
|
|
|
|
2019-05-04 06:07:23 +00:00
|
|
|
// Experience-Bar
|
|
|
|
Image::new(self.imgs.xp_bar)
|
2019-05-19 18:07:50 +00:00
|
|
|
.w_h(672.0 / 1.5, 29.0 / 1.5)
|
2019-05-04 06:07:23 +00:00
|
|
|
.mid_bottom_of(ui.window)
|
|
|
|
.set(state.ids.xp_bar, ui);
|
|
|
|
|
|
|
|
Rectangle::fill_with([406.0 * (xp_percentage), 5.0], XP_COLOR) // "W=406*[Exp. %]"
|
|
|
|
.top_left_with_margins_on(state.ids.xp_bar, 5.0, 21.0)
|
|
|
|
.set(state.ids.xp_bar_progress, ui);
|
|
|
|
|
|
|
|
// Left Grid
|
|
|
|
Image::new(self.imgs.sb_grid)
|
2019-05-19 18:07:50 +00:00
|
|
|
.w_h(280.0 / 1.5, 56.0 / 1.5)
|
2019-05-04 06:07:23 +00:00
|
|
|
.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)
|
2019-05-19 18:07:50 +00:00
|
|
|
.w_h(280.0 / 1.5, 56.0 / 1.5)
|
2019-05-04 06:07:23 +00:00
|
|
|
.middle_of(state.ids.sb_grid_l)
|
|
|
|
.set(state.ids.sb_grid_bg_l, ui);
|
|
|
|
|
|
|
|
// Right Grid
|
|
|
|
Image::new(self.imgs.sb_grid)
|
2019-05-19 18:07:50 +00:00
|
|
|
.w_h(280.0 / 1.5, 56.0 / 1.5)
|
2019-05-04 06:07:23 +00:00
|
|
|
.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)
|
2019-05-19 18:07:50 +00:00
|
|
|
.w_h(280.0 / 1.5, 56.0 / 1.5)
|
2019-05-04 06:07:23 +00:00
|
|
|
.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)
|
2019-05-19 18:07:50 +00:00
|
|
|
.w_h(56.0 / 1.5, 80.0 / 1.5)
|
2019-05-04 06:07:23 +00:00
|
|
|
.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)
|
2019-05-19 18:07:50 +00:00
|
|
|
.w_h(56.0 / 1.5, 80.0 / 1.5)
|
2019-05-04 06:07:23 +00:00
|
|
|
.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);
|
|
|
|
|
|
|
|
// Health Bar
|
|
|
|
Image::new(self.imgs.health_bar)
|
|
|
|
.w_h(1120.0 / 6.0, 96.0 / 6.0)
|
|
|
|
.left_from(state.ids.l_click, 0.0)
|
|
|
|
.align_top_of(state.ids.l_click)
|
|
|
|
.set(state.ids.health_bar, ui);
|
|
|
|
|
|
|
|
// Filling
|
2019-05-19 18:07:50 +00:00
|
|
|
Rectangle::fill_with([182.0 * hp_percentage, 6.0], HP_COLOR) // "W=182.0 * [Health. %]"
|
2019-05-04 06:07:23 +00:00
|
|
|
.top_right_with_margins_on(state.ids.health_bar, 5.0, 0.0)
|
|
|
|
.set(state.ids.health_bar_color, ui);
|
|
|
|
|
|
|
|
// Mana Bar
|
|
|
|
Image::new(self.imgs.mana_bar)
|
|
|
|
.w_h(1120.0 / 6.0, 96.0 / 6.0)
|
|
|
|
.right_from(state.ids.r_click, 0.0)
|
|
|
|
.align_top_of(state.ids.r_click)
|
|
|
|
.set(state.ids.mana_bar, ui);
|
|
|
|
|
|
|
|
// Filling
|
2019-05-19 18:07:50 +00:00
|
|
|
Rectangle::fill_with([182.0 * mana_percentage, 6.0], MANA_COLOR) // "W=182.0 * [Mana. %]"
|
2019-05-04 06:07:23 +00:00
|
|
|
.top_left_with_margins_on(state.ids.mana_bar, 5.0, 0.0)
|
|
|
|
.set(state.ids.mana_bar_color, ui);
|
|
|
|
|
|
|
|
// Buffs/Debuffs
|
|
|
|
|
|
|
|
// Buffs
|
|
|
|
|
|
|
|
// Debuffs
|
|
|
|
|
|
|
|
// Level Display
|
|
|
|
|
2019-05-19 18:07:50 +00:00
|
|
|
// TODO: don't construct a new string here
|
2019-05-17 09:22:32 +00:00
|
|
|
// TODO: Insert actual Level here.
|
2019-05-19 18:07:50 +00:00
|
|
|
Text::new(&level.to_string())
|
2019-05-04 06:07:23 +00:00
|
|
|
.left_from(state.ids.xp_bar, -15.0)
|
|
|
|
.font_size(10)
|
|
|
|
.color(TEXT_COLOR)
|
|
|
|
.set(state.ids.level_text, ui);
|
|
|
|
|
2019-05-17 09:22:32 +00:00
|
|
|
// TODO: Insert next Level here.
|
2019-05-19 18:07:50 +00:00
|
|
|
Text::new(&(level + 1).to_string())
|
2019-05-04 06:07:23 +00:00
|
|
|
.right_from(state.ids.xp_bar, -15.0)
|
|
|
|
.font_size(10)
|
|
|
|
.color(TEXT_COLOR)
|
|
|
|
.set(state.ids.next_level_text, ui);
|
|
|
|
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|