2019-05-07 05:40:03 +00:00
|
|
|
use super::{font_ids::Fonts, img_ids::Imgs, TEXT_COLOR, XP_COLOR};
|
2019-04-26 20:24:05 +00:00
|
|
|
use conrod_core::{
|
2019-05-07 03:25:25 +00:00
|
|
|
color,
|
2019-04-28 04:44:13 +00:00
|
|
|
widget::{self, Button, Image, Rectangle, Text},
|
2019-05-07 03:25:25 +00:00
|
|
|
widget_ids, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
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> {
|
|
|
|
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-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 {
|
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-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-05-07 05:40:03 +00:00
|
|
|
let widget::UpdateArgs { id, state, ui, .. } = args;
|
2019-04-28 04:44:13 +00:00
|
|
|
|
2019-05-03 16:56:18 +00:00
|
|
|
// TODO: Read from parameter / character struct
|
|
|
|
let xp_percentage = 0.4;
|
|
|
|
|
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-05-04 17:29:19 +00:00
|
|
|
.top_left_with_margins_on(ui.window, 200.0, 215.0)
|
2019-05-07 05:40:03 +00:00
|
|
|
.w_h(107.0 * 4.0, 125.0 * 4.0)
|
|
|
|
.set(state.charwindow_frame, 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-05-04 17:29:19 +00:00
|
|
|
.w_h(28.0, 28.0)
|
2019-04-28 16:44:44 +00:00
|
|
|
.hover_image(self.imgs.close_button_hover)
|
|
|
|
.press_image(self.imgs.close_button_press)
|
2019-05-06 18:28:08 +00:00
|
|
|
.top_right_with_margins_on(state.charwindow_frame, 12.0, 0.0)
|
2019-04-30 20:43:55 +00:00
|
|
|
.set(state.charwindow_close, ui)
|
2019-05-07 05:40:03 +00:00
|
|
|
.was_clicked()
|
|
|
|
{
|
|
|
|
return Some(Event::Close);
|
2019-04-30 14:39:19 +00:00
|
|
|
}
|
2019-04-26 20:24:05 +00:00
|
|
|
|
|
|
|
// Title
|
|
|
|
Text::new("Character Name") // Add in actual Character Name
|
2019-05-06 18:49:12 +00:00
|
|
|
.mid_top_with_margin_on(state.charwindow_frame, 17.0)
|
|
|
|
.font_id(self.fonts.metamorph)
|
|
|
|
.font_size(14)
|
2019-04-30 20:43:55 +00:00
|
|
|
.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-05-03 16:56:18 +00:00
|
|
|
Rectangle::fill_with([170.0 * (xp_percentage), 6.0], XP_COLOR) // 0.8 = Experience percentage
|
2019-04-30 20:43:55 +00:00
|
|
|
.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-05-07 05:40:03 +00:00
|
|
|
.top_left_with_margins_on(state.charwindow_rectangle, 100.0, 20.0)
|
|
|
|
.font_id(self.fonts.opensans)
|
|
|
|
.font_size(16)
|
|
|
|
.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-05-07 05:40:03 +00:00
|
|
|
.right_from(state.charwindow_tab1_statnames, 10.0)
|
|
|
|
.font_id(self.fonts.opensans)
|
|
|
|
.font_size(16)
|
|
|
|
.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
|
|
|
}
|
|
|
|
}
|