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