2019-04-26 20:24:05 +00:00
|
|
|
use conrod_core::{
|
2019-04-28 04:54:59 +00:00
|
|
|
builder_methods, color,
|
2019-04-28 04:44:13 +00:00
|
|
|
text::font,
|
|
|
|
widget::{self, Button, Image, Rectangle, Text},
|
2019-04-28 04:54:59 +00:00
|
|
|
widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
2019-04-26 20:24:05 +00:00
|
|
|
};
|
2019-04-28 04:54:59 +00:00
|
|
|
use super::{
|
2019-04-30 20:43:55 +00:00
|
|
|
img_ids::Imgs,
|
|
|
|
font_ids::Fonts,
|
|
|
|
TEXT_COLOR,
|
|
|
|
XP_COLOR,
|
2019-04-28 04:54:59 +00:00
|
|
|
};
|
2019-04-26 20:24:05 +00:00
|
|
|
|
|
|
|
widget_ids! {
|
2019-04-30 20:43:55 +00:00
|
|
|
pub struct Ids {
|
2019-04-26 20:24:05 +00:00
|
|
|
charwindow,
|
|
|
|
charwindow_bg,
|
|
|
|
charwindow_close,
|
|
|
|
charwindow_exp_progress_rectangle,
|
|
|
|
charwindow_exp_rectangle,
|
|
|
|
charwindow_frame,
|
|
|
|
charwindow_icon,
|
|
|
|
charwindow_rectangle,
|
|
|
|
charwindow_tab1,
|
|
|
|
charwindow_tab1_exp,
|
|
|
|
charwindow_tab1_expbar,
|
|
|
|
charwindow_tab1_level,
|
|
|
|
charwindow_tab1_statnames,
|
|
|
|
charwindow_tab1_stats,
|
|
|
|
charwindow_tab_bg,
|
|
|
|
charwindow_title,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(WidgetCommon)]
|
2019-04-28 04:44:13 +00:00
|
|
|
pub struct CharacterWindow<'a> {
|
2019-04-26 20:24:05 +00:00
|
|
|
xp_percentage: f64,
|
2019-04-28 04:44:13 +00:00
|
|
|
imgs: &'a Imgs,
|
2019-04-30 20:43:55 +00:00
|
|
|
fonts: &'a Fonts,
|
2019-04-26 20:24:05 +00:00
|
|
|
|
|
|
|
#[conrod(common_builder)]
|
|
|
|
common: widget::CommonBuilder,
|
2019-04-30 20:43:55 +00:00
|
|
|
style: (),
|
2019-04-26 20:24:05 +00:00
|
|
|
}
|
|
|
|
|
2019-04-28 04:44:13 +00:00
|
|
|
impl<'a> CharacterWindow<'a> {
|
2019-04-30 20:43:55 +00:00
|
|
|
pub fn new(imgs: &'a Imgs, fonts: &'a Fonts) -> Self {
|
2019-04-26 20:24:05 +00:00
|
|
|
Self {
|
|
|
|
xp_percentage: 0.4,
|
2019-04-28 04:44:13 +00:00
|
|
|
imgs,
|
2019-04-30 20:43:55 +00:00
|
|
|
fonts,
|
2019-04-26 20:24:05 +00:00
|
|
|
common: widget::CommonBuilder::default(),
|
2019-04-30 20:43:55 +00:00
|
|
|
style: (),
|
2019-04-26 20:24:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-28 04:44:13 +00:00
|
|
|
pub enum Event {
|
2019-04-26 20:24:05 +00:00
|
|
|
Close,
|
|
|
|
}
|
|
|
|
|
2019-04-28 04:44:13 +00:00
|
|
|
impl<'a> Widget for CharacterWindow<'a> {
|
2019-04-30 20:43:55 +00:00
|
|
|
type State = Ids;
|
|
|
|
type Style = ();
|
2019-04-26 20:24:05 +00:00
|
|
|
type Event = Option<Event>;
|
|
|
|
|
|
|
|
fn init_state(&self, id_gen: widget::id::Generator) -> Self::State {
|
2019-04-30 20:43:55 +00:00
|
|
|
Ids::new(id_gen)
|
2019-04-26 20:24:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn style(&self) -> Self::Style {
|
2019-04-30 20:43:55 +00:00
|
|
|
()
|
2019-04-26 20:24:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
|
2019-04-28 04:54:59 +00:00
|
|
|
let widget::UpdateArgs {
|
|
|
|
id,
|
|
|
|
state,
|
|
|
|
ui,
|
|
|
|
style,
|
|
|
|
..
|
|
|
|
} = args;
|
2019-04-28 04:44:13 +00:00
|
|
|
|
2019-04-26 20:24:05 +00:00
|
|
|
// Frame
|
2019-04-28 16:44:44 +00:00
|
|
|
Image::new(self.imgs.window_frame)
|
2019-04-28 04:44:13 +00:00
|
|
|
.middle_of(id)
|
2019-04-30 20:43:55 +00:00
|
|
|
.set(state.charwindow_frame, ui);
|
2019-04-26 20:24:05 +00:00
|
|
|
|
|
|
|
// BG
|
|
|
|
Image::new(self.imgs.window_bg)
|
|
|
|
.w_h(348.0, 404.0)
|
2019-04-30 20:43:55 +00:00
|
|
|
.mid_top_with_margin_on(state.charwindow_frame, 48.0)
|
|
|
|
.set(state.charwindow_bg, ui);
|
2019-04-26 20:24:05 +00:00
|
|
|
|
|
|
|
// Overlay
|
|
|
|
Image::new(self.imgs.charwindow)
|
2019-04-30 20:43:55 +00:00
|
|
|
.middle_of(state.charwindow_bg)
|
|
|
|
.set(state.charwindow, ui);
|
2019-04-26 20:24:05 +00:00
|
|
|
|
|
|
|
// Icon
|
|
|
|
//Image::new(self.imgs.charwindow_icon)
|
|
|
|
//.w_h(224.0 / 3.0, 224.0 / 3.0)
|
2019-04-30 20:43:55 +00:00
|
|
|
//.top_left_with_margins_on(state.charwindow_frame, -10.0, -10.0)
|
|
|
|
//.set(state.charwindow_icon, ui);
|
2019-04-26 20:24:05 +00:00
|
|
|
|
|
|
|
// X-Button
|
2019-04-30 14:39:19 +00:00
|
|
|
if Button::image(self.imgs.close_button)
|
2019-04-26 20:24:05 +00:00
|
|
|
.w_h(244.0 * 0.22 / 4.0, 244.0 * 0.22 / 4.0)
|
2019-04-28 16:44:44 +00:00
|
|
|
.hover_image(self.imgs.close_button_hover)
|
|
|
|
.press_image(self.imgs.close_button_press)
|
2019-04-30 20:43:55 +00:00
|
|
|
.top_right_with_margins_on(state.charwindow_frame, 4.0, 4.0)
|
|
|
|
.set(state.charwindow_close, ui)
|
2019-04-30 14:39:19 +00:00
|
|
|
.was_clicked() {
|
|
|
|
return Some(Event::Close);
|
|
|
|
}
|
2019-04-26 20:24:05 +00:00
|
|
|
|
|
|
|
// Title
|
|
|
|
Text::new("Character Name") // Add in actual Character Name
|
2019-04-30 20:43:55 +00:00
|
|
|
.mid_top_with_margin_on(state.charwindow_frame, 7.0)
|
|
|
|
.color(TEXT_COLOR)
|
|
|
|
.set(state.charwindow_title, ui);
|
2019-04-30 14:39:19 +00:00
|
|
|
|
2019-04-26 20:24:05 +00:00
|
|
|
// Tab BG
|
|
|
|
Image::new(self.imgs.charwindow_tab_bg)
|
|
|
|
.w_h(205.0, 412.0)
|
2019-04-30 20:43:55 +00:00
|
|
|
.mid_left_with_margin_on(state.charwindow_frame, -205.0)
|
|
|
|
.set(state.charwindow_tab_bg, ui);
|
2019-04-30 14:39:19 +00:00
|
|
|
|
2019-04-26 20:24:05 +00:00
|
|
|
// Tab Rectangle
|
|
|
|
Rectangle::fill_with([192.0, 371.0], color::rgba(0.0, 0.0, 0.0, 0.8))
|
2019-04-30 20:43:55 +00:00
|
|
|
.top_right_with_margins_on(state.charwindow_tab_bg, 20.0, 0.0)
|
|
|
|
.set(state.charwindow_rectangle, ui);
|
2019-04-30 14:39:19 +00:00
|
|
|
|
2019-04-26 20:24:05 +00:00
|
|
|
// Tab Button
|
|
|
|
Button::image(self.imgs.charwindow_tab)
|
|
|
|
.w_h(65.0, 23.0)
|
2019-04-30 20:43:55 +00:00
|
|
|
.top_left_with_margins_on(state.charwindow_tab_bg, -18.0, 2.0)
|
2019-04-26 20:24:05 +00:00
|
|
|
.label("Stats")
|
2019-04-30 20:43:55 +00:00
|
|
|
.label_color(TEXT_COLOR)
|
2019-04-26 20:24:05 +00:00
|
|
|
.label_font_size(14)
|
2019-04-30 20:43:55 +00:00
|
|
|
.set(state.charwindow_tab1, ui);
|
2019-04-30 14:39:19 +00:00
|
|
|
|
2019-04-26 20:24:05 +00:00
|
|
|
Text::new("1") //Add in actual Character Level
|
2019-04-30 20:43:55 +00:00
|
|
|
.mid_top_with_margin_on(state.charwindow_rectangle, 10.0)
|
|
|
|
.font_id(self.fonts.opensans)
|
2019-04-26 20:24:05 +00:00
|
|
|
.font_size(30)
|
2019-04-30 20:43:55 +00:00
|
|
|
.color(TEXT_COLOR)
|
|
|
|
.set(state.charwindow_tab1_level, ui);
|
2019-04-30 14:39:19 +00:00
|
|
|
|
2019-04-26 20:24:05 +00:00
|
|
|
// Exp-Bar Background
|
|
|
|
Rectangle::fill_with([170.0, 10.0], color::BLACK)
|
2019-04-30 20:43:55 +00:00
|
|
|
.mid_top_with_margin_on(state.charwindow_rectangle, 50.0)
|
|
|
|
.set(state.charwindow_exp_rectangle, ui);
|
2019-04-30 14:39:19 +00:00
|
|
|
|
2019-04-26 20:24:05 +00:00
|
|
|
// Exp-Bar Progress
|
2019-04-30 20:43:55 +00:00
|
|
|
Rectangle::fill_with([170.0 * (self.xp_percentage), 6.0], XP_COLOR) // 0.8 = Experience percentage
|
|
|
|
.mid_left_with_margin_on(state.charwindow_tab1_expbar, 1.0)
|
|
|
|
.set(state.charwindow_exp_progress_rectangle, ui);
|
2019-04-30 14:39:19 +00:00
|
|
|
|
2019-04-26 20:24:05 +00:00
|
|
|
// Exp-Bar Foreground Frame
|
|
|
|
Image::new(self.imgs.progress_frame)
|
|
|
|
.w_h(170.0, 10.0)
|
2019-04-30 20:43:55 +00:00
|
|
|
.middle_of(state.charwindow_exp_rectangle)
|
|
|
|
.set(state.charwindow_tab1_expbar, ui);
|
2019-04-30 14:39:19 +00:00
|
|
|
|
2019-04-26 20:24:05 +00:00
|
|
|
// Exp-Text
|
|
|
|
Text::new("120/170") // Shows the Exp / Exp to reach the next level
|
2019-04-30 20:43:55 +00:00
|
|
|
.mid_top_with_margin_on(state.charwindow_tab1_expbar, 10.0)
|
|
|
|
.font_id(self.fonts.opensans)
|
2019-04-26 20:24:05 +00:00
|
|
|
.font_size(15)
|
2019-04-30 20:43:55 +00:00
|
|
|
.color(TEXT_COLOR)
|
|
|
|
.set(state.charwindow_tab1_exp, ui);
|
2019-04-26 20:24:05 +00:00
|
|
|
|
|
|
|
// Stats
|
|
|
|
Text::new(
|
|
|
|
"Stamina\n\
|
|
|
|
\n\
|
|
|
|
Strength\n\
|
|
|
|
\n\
|
|
|
|
Dexterity\n\
|
|
|
|
\n\
|
|
|
|
Intelligence",
|
|
|
|
)
|
2019-04-30 20:43:55 +00:00
|
|
|
.top_left_with_margins_on(state.charwindow_rectangle, 100.0, 20.0)
|
|
|
|
.font_id(self.fonts.opensans)
|
2019-04-30 14:39:19 +00:00
|
|
|
.font_size(16)
|
2019-04-30 20:43:55 +00:00
|
|
|
.color(TEXT_COLOR)
|
|
|
|
.set(state.charwindow_tab1_statnames, ui);
|
2019-04-26 20:24:05 +00:00
|
|
|
|
|
|
|
Text::new(
|
|
|
|
"1234\n\
|
|
|
|
\n\
|
|
|
|
12312\n\
|
|
|
|
\n\
|
|
|
|
12414\n\
|
|
|
|
\n\
|
|
|
|
124124",
|
|
|
|
)
|
2019-04-30 20:43:55 +00:00
|
|
|
.right_from(state.charwindow_tab1_statnames, 10.0)
|
|
|
|
.font_id(self.fonts.opensans)
|
2019-04-30 14:39:19 +00:00
|
|
|
.font_size(16)
|
2019-04-30 20:43:55 +00:00
|
|
|
.color(TEXT_COLOR)
|
|
|
|
.set(state.charwindow_tab1_stats, ui);
|
2019-04-30 14:39:19 +00:00
|
|
|
|
|
|
|
None
|
2019-04-26 20:24:05 +00:00
|
|
|
}
|
|
|
|
}
|