2019-04-30 20:43:55 +00:00
|
|
|
use conrod_core::{
|
2019-05-07 03:25:25 +00:00
|
|
|
widget::{self, Button, Image},
|
|
|
|
widget_ids, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
2019-04-30 20:43:55 +00:00
|
|
|
};
|
|
|
|
|
2019-05-07 05:40:03 +00:00
|
|
|
use super::{font_ids::Fonts, img_ids::Imgs, TEXT_COLOR};
|
2019-04-30 20:43:55 +00:00
|
|
|
|
|
|
|
widget_ids! {
|
|
|
|
struct Ids {
|
2019-05-03 16:56:18 +00:00
|
|
|
esc_bg,
|
|
|
|
fireplace,
|
|
|
|
menu_button_1,
|
|
|
|
menu_button_2,
|
|
|
|
menu_button_3,
|
|
|
|
menu_button_4,
|
|
|
|
menu_button_5,
|
2019-04-30 20:43:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(WidgetCommon)]
|
|
|
|
pub struct EscMenu<'a> {
|
|
|
|
imgs: &'a Imgs,
|
2019-05-03 16:56:18 +00:00
|
|
|
fonts: &'a Fonts,
|
2019-04-30 20:43:55 +00:00
|
|
|
|
|
|
|
#[conrod(common_builder)]
|
|
|
|
common: widget::CommonBuilder,
|
|
|
|
}
|
|
|
|
|
2019-05-03 16:56:18 +00:00
|
|
|
impl<'a> EscMenu<'a> {
|
|
|
|
pub fn new(imgs: &'a Imgs, fonts: &'a Fonts) -> Self {
|
2019-04-30 20:43:55 +00:00
|
|
|
Self {
|
|
|
|
imgs,
|
2019-05-03 16:56:18 +00:00
|
|
|
fonts,
|
2019-04-30 20:43:55 +00:00
|
|
|
common: widget::CommonBuilder::default(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct State {
|
|
|
|
ids: Ids,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum Event {
|
2019-05-03 16:56:18 +00:00
|
|
|
OpenSettings,
|
|
|
|
Logout,
|
|
|
|
Quit,
|
2019-04-30 20:43:55 +00:00
|
|
|
Close,
|
|
|
|
}
|
|
|
|
|
2019-05-03 16:56:18 +00:00
|
|
|
impl<'a> Widget for EscMenu<'a> {
|
2019-04-30 20:43:55 +00:00
|
|
|
type State = State;
|
2019-05-03 16:56:18 +00:00
|
|
|
type Style = ();
|
2019-04-30 20:43:55 +00:00
|
|
|
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 {
|
2019-05-03 16:56:18 +00:00
|
|
|
()
|
2019-04-30 20:43:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
|
2019-05-07 05:40:03 +00:00
|
|
|
let widget::UpdateArgs { state, ui, .. } = args;
|
2019-04-30 20:43:55 +00:00
|
|
|
|
2019-05-03 16:56:18 +00:00
|
|
|
Image::new(self.imgs.esc_bg)
|
|
|
|
.w_h(228.0, 450.0)
|
|
|
|
.middle_of(ui.window)
|
|
|
|
.set(state.ids.esc_bg, ui);
|
|
|
|
|
|
|
|
Image::new(self.imgs.fireplace)
|
|
|
|
.w_h(180.0, 60.0)
|
|
|
|
.mid_top_with_margin_on(state.ids.esc_bg, 50.0)
|
|
|
|
.set(state.ids.fireplace, ui);
|
|
|
|
|
|
|
|
// Settings
|
2019-05-04 17:29:19 +00:00
|
|
|
if Button::image(self.imgs.button)
|
2019-05-03 16:56:18 +00:00
|
|
|
.mid_top_with_margin_on(state.ids.esc_bg, 115.0)
|
|
|
|
.w_h(170.0, 50.0)
|
2019-05-04 17:29:19 +00:00
|
|
|
.hover_image(self.imgs.button_hover)
|
|
|
|
.press_image(self.imgs.button_press)
|
2019-05-03 16:56:18 +00:00
|
|
|
.label("Settings")
|
|
|
|
.label_y(conrod_core::position::Relative::Scalar(2.0))
|
|
|
|
.label_color(TEXT_COLOR)
|
|
|
|
.label_font_size(17)
|
|
|
|
.set(state.ids.menu_button_1, ui)
|
|
|
|
.was_clicked()
|
|
|
|
{
|
|
|
|
return Some(Event::OpenSettings);
|
|
|
|
};
|
|
|
|
// Controls
|
2019-05-04 17:29:19 +00:00
|
|
|
if Button::image(self.imgs.button)
|
2019-05-03 16:56:18 +00:00
|
|
|
.mid_top_with_margin_on(state.ids.esc_bg, 175.0)
|
|
|
|
.w_h(170.0, 50.0)
|
2019-05-04 17:29:19 +00:00
|
|
|
.hover_image(self.imgs.button_hover)
|
|
|
|
.press_image(self.imgs.button_press)
|
2019-05-03 16:56:18 +00:00
|
|
|
.label("Controls")
|
|
|
|
.label_y(conrod_core::position::Relative::Scalar(2.0))
|
|
|
|
.label_color(TEXT_COLOR)
|
|
|
|
.label_font_size(17)
|
|
|
|
.set(state.ids.menu_button_2, ui)
|
|
|
|
.was_clicked()
|
|
|
|
{
|
|
|
|
//self.menu_open = false;
|
|
|
|
};
|
|
|
|
// Servers
|
2019-05-04 17:29:19 +00:00
|
|
|
if Button::image(self.imgs.button)
|
2019-05-03 16:56:18 +00:00
|
|
|
.mid_top_with_margin_on(state.ids.esc_bg, 235.0)
|
|
|
|
.w_h(170.0, 50.0)
|
2019-05-04 17:29:19 +00:00
|
|
|
.hover_image(self.imgs.button_hover)
|
|
|
|
.press_image(self.imgs.button_press)
|
2019-05-03 16:56:18 +00:00
|
|
|
.label("Servers")
|
|
|
|
.label_y(conrod_core::position::Relative::Scalar(2.0))
|
|
|
|
.label_color(TEXT_COLOR)
|
|
|
|
.label_font_size(17)
|
|
|
|
.set(state.ids.menu_button_3, ui)
|
|
|
|
.was_clicked()
|
|
|
|
{
|
|
|
|
//self.menu_open = false;
|
|
|
|
};
|
|
|
|
// Logout
|
2019-05-04 17:29:19 +00:00
|
|
|
if Button::image(self.imgs.button)
|
2019-05-03 16:56:18 +00:00
|
|
|
.mid_top_with_margin_on(state.ids.esc_bg, 295.0)
|
|
|
|
.w_h(170.0, 50.0)
|
2019-05-04 17:29:19 +00:00
|
|
|
.hover_image(self.imgs.button_hover)
|
|
|
|
.press_image(self.imgs.button_press)
|
2019-05-03 16:56:18 +00:00
|
|
|
.label("Logout")
|
|
|
|
.label_y(conrod_core::position::Relative::Scalar(2.0))
|
|
|
|
.label_color(TEXT_COLOR)
|
|
|
|
.label_font_size(17)
|
|
|
|
.set(state.ids.menu_button_4, ui)
|
|
|
|
.was_clicked()
|
|
|
|
{
|
|
|
|
return Some(Event::Logout);
|
|
|
|
};
|
|
|
|
// Quit
|
2019-05-04 17:29:19 +00:00
|
|
|
if Button::image(self.imgs.button)
|
2019-05-03 16:56:18 +00:00
|
|
|
.mid_top_with_margin_on(state.ids.esc_bg, 355.0)
|
|
|
|
.w_h(170.0, 50.0)
|
2019-05-04 17:29:19 +00:00
|
|
|
.hover_image(self.imgs.button_hover)
|
|
|
|
.press_image(self.imgs.button_press)
|
2019-05-03 16:56:18 +00:00
|
|
|
.label("Quit")
|
|
|
|
.label_y(conrod_core::position::Relative::Scalar(2.0))
|
|
|
|
.label_color(TEXT_COLOR)
|
|
|
|
.label_font_size(17)
|
|
|
|
.set(state.ids.menu_button_5, ui)
|
|
|
|
.was_clicked()
|
|
|
|
{
|
|
|
|
return Some(Event::Quit);
|
|
|
|
};
|
|
|
|
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|