2020-01-26 19:29:46 +00:00
|
|
|
use super::{img_ids::Imgs, settings_window::SettingsTab, TEXT_COLOR};
|
|
|
|
use crate::{i18n::VoxygenLocalization, ui::fonts::ConrodVoxygenFonts};
|
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
|
|
|
};
|
|
|
|
|
|
|
|
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-06-02 02:17:36 +00:00
|
|
|
menu_button_6,
|
2019-04-30 20:43:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(WidgetCommon)]
|
|
|
|
pub struct EscMenu<'a> {
|
|
|
|
imgs: &'a Imgs,
|
2020-01-26 19:29:46 +00:00
|
|
|
fonts: &'a ConrodVoxygenFonts,
|
2020-01-17 23:43:18 +00:00
|
|
|
localized_strings: &'a std::sync::Arc<VoxygenLocalization>,
|
|
|
|
|
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> {
|
2020-01-17 23:43:18 +00:00
|
|
|
pub fn new(
|
|
|
|
imgs: &'a Imgs,
|
2020-01-26 19:29:46 +00:00
|
|
|
fonts: &'a ConrodVoxygenFonts,
|
2020-01-17 23:43:18 +00:00
|
|
|
localized_strings: &'a std::sync::Arc<VoxygenLocalization>,
|
|
|
|
) -> Self {
|
2019-04-30 20:43:55 +00:00
|
|
|
Self {
|
|
|
|
imgs,
|
2020-01-26 19:29:46 +00:00
|
|
|
fonts,
|
2020-01-17 23:43:18 +00:00
|
|
|
localized_strings,
|
2019-04-30 20:43:55 +00:00
|
|
|
common: widget::CommonBuilder::default(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct State {
|
|
|
|
ids: Ids,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum Event {
|
2019-06-02 02:17:36 +00:00
|
|
|
OpenSettings(SettingsTab),
|
|
|
|
CharacterSelection,
|
2019-05-03 16:56:18 +00:00
|
|
|
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> {
|
2020-02-01 20:39:39 +00:00
|
|
|
type Event = Option<Event>;
|
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
|
|
|
|
|
|
|
fn init_state(&self, id_gen: widget::id::Generator) -> Self::State {
|
|
|
|
State {
|
|
|
|
ids: Ids::new(id_gen),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-01 20:39:39 +00:00
|
|
|
fn style(&self) -> Self::Style { () }
|
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-06-02 02:17:36 +00:00
|
|
|
Image::new(self.imgs.esc_frame)
|
|
|
|
.w_h(240.0, 440.0)
|
2019-05-03 16:56:18 +00:00
|
|
|
.middle_of(ui.window)
|
|
|
|
.set(state.ids.esc_bg, ui);
|
|
|
|
|
|
|
|
Image::new(self.imgs.fireplace)
|
2019-06-02 02:17:36 +00:00
|
|
|
.w_h(210.0, 60.0)
|
|
|
|
.mid_top_with_margin_on(state.ids.esc_bg, 15.0)
|
2019-05-03 16:56:18 +00:00
|
|
|
.set(state.ids.fireplace, ui);
|
|
|
|
|
2019-06-02 02:17:36 +00:00
|
|
|
// Resume
|
|
|
|
if Button::image(self.imgs.button)
|
|
|
|
.mid_bottom_with_margin_on(state.ids.fireplace, -55.0)
|
|
|
|
.w_h(210.0, 50.0)
|
|
|
|
.hover_image(self.imgs.button_hover)
|
|
|
|
.press_image(self.imgs.button_press)
|
2020-01-17 23:43:18 +00:00
|
|
|
.label(&self.localized_strings.get("common.resume"))
|
2019-06-02 02:17:36 +00:00
|
|
|
.label_y(conrod_core::position::Relative::Scalar(3.0))
|
|
|
|
.label_color(TEXT_COLOR)
|
2020-01-26 19:29:46 +00:00
|
|
|
.label_font_size(self.fonts.cyri.scale(20))
|
|
|
|
.label_font_id(self.fonts.cyri.conrod_id)
|
2019-06-02 02:17:36 +00:00
|
|
|
.set(state.ids.menu_button_1, ui)
|
|
|
|
.was_clicked()
|
|
|
|
{
|
|
|
|
return Some(Event::Close);
|
|
|
|
};
|
|
|
|
|
2019-05-03 16:56:18 +00:00
|
|
|
// Settings
|
2019-05-04 17:29:19 +00:00
|
|
|
if Button::image(self.imgs.button)
|
2019-06-02 02:17:36 +00:00
|
|
|
.mid_bottom_with_margin_on(state.ids.menu_button_1, -65.0)
|
|
|
|
.w_h(210.0, 50.0)
|
2019-05-04 17:29:19 +00:00
|
|
|
.hover_image(self.imgs.button_hover)
|
|
|
|
.press_image(self.imgs.button_press)
|
2020-01-17 23:43:18 +00:00
|
|
|
.label(&self.localized_strings.get("common.settings"))
|
2019-06-02 02:17:36 +00:00
|
|
|
.label_y(conrod_core::position::Relative::Scalar(3.0))
|
2019-05-03 16:56:18 +00:00
|
|
|
.label_color(TEXT_COLOR)
|
2020-01-26 19:29:46 +00:00
|
|
|
.label_font_size(self.fonts.cyri.scale(20))
|
|
|
|
.label_font_id(self.fonts.cyri.conrod_id)
|
2019-06-02 02:17:36 +00:00
|
|
|
.set(state.ids.menu_button_2, ui)
|
2019-05-03 16:56:18 +00:00
|
|
|
.was_clicked()
|
|
|
|
{
|
2019-06-02 02:17:36 +00:00
|
|
|
return Some(Event::OpenSettings(SettingsTab::Interface));
|
2019-05-03 16:56:18 +00:00
|
|
|
};
|
|
|
|
// Controls
|
2019-05-04 17:29:19 +00:00
|
|
|
if Button::image(self.imgs.button)
|
2019-06-02 02:17:36 +00:00
|
|
|
.mid_bottom_with_margin_on(state.ids.menu_button_2, -55.0)
|
|
|
|
.w_h(210.0, 50.0)
|
2019-05-04 17:29:19 +00:00
|
|
|
.hover_image(self.imgs.button_hover)
|
|
|
|
.press_image(self.imgs.button_press)
|
2020-01-17 23:43:18 +00:00
|
|
|
.label(&self.localized_strings.get("common.controls"))
|
2019-06-02 02:17:36 +00:00
|
|
|
.label_y(conrod_core::position::Relative::Scalar(3.0))
|
2019-05-03 16:56:18 +00:00
|
|
|
.label_color(TEXT_COLOR)
|
2020-01-26 19:29:46 +00:00
|
|
|
.label_font_size(self.fonts.cyri.scale(20))
|
|
|
|
.label_font_id(self.fonts.cyri.conrod_id)
|
2019-06-02 02:17:36 +00:00
|
|
|
.set(state.ids.menu_button_3, ui)
|
2019-05-03 16:56:18 +00:00
|
|
|
.was_clicked()
|
|
|
|
{
|
2019-06-02 02:17:36 +00:00
|
|
|
return Some(Event::OpenSettings(SettingsTab::Controls));
|
2019-05-03 16:56:18 +00:00
|
|
|
};
|
2019-06-02 02:17:36 +00:00
|
|
|
// Characters
|
2019-05-04 17:29:19 +00:00
|
|
|
if Button::image(self.imgs.button)
|
2019-06-02 02:17:36 +00:00
|
|
|
.mid_bottom_with_margin_on(state.ids.menu_button_3, -55.0)
|
|
|
|
.w_h(210.0, 50.0)
|
2019-05-04 17:29:19 +00:00
|
|
|
.hover_image(self.imgs.button_hover)
|
|
|
|
.press_image(self.imgs.button_press)
|
2020-01-17 23:43:18 +00:00
|
|
|
.label(&self.localized_strings.get("common.characters"))
|
2019-06-02 02:17:36 +00:00
|
|
|
.label_y(conrod_core::position::Relative::Scalar(3.0))
|
2019-05-03 16:56:18 +00:00
|
|
|
.label_color(TEXT_COLOR)
|
2020-01-26 19:29:46 +00:00
|
|
|
.label_font_size(self.fonts.cyri.scale(20))
|
|
|
|
.label_font_id(self.fonts.cyri.conrod_id)
|
2019-06-02 02:17:36 +00:00
|
|
|
.set(state.ids.menu_button_4, ui)
|
2019-05-03 16:56:18 +00:00
|
|
|
.was_clicked()
|
|
|
|
{
|
2019-06-02 02:17:36 +00:00
|
|
|
return Some(Event::CharacterSelection);
|
2019-05-03 16:56:18 +00:00
|
|
|
};
|
|
|
|
// Logout
|
2019-05-04 17:29:19 +00:00
|
|
|
if Button::image(self.imgs.button)
|
2019-06-02 02:17:36 +00:00
|
|
|
.mid_bottom_with_margin_on(state.ids.menu_button_4, -65.0)
|
|
|
|
.w_h(210.0, 50.0)
|
2019-05-04 17:29:19 +00:00
|
|
|
.hover_image(self.imgs.button_hover)
|
|
|
|
.press_image(self.imgs.button_press)
|
2020-01-17 23:43:18 +00:00
|
|
|
.label(&self.localized_strings.get("esc_menu.logout"))
|
2019-06-02 02:17:36 +00:00
|
|
|
.label_y(conrod_core::position::Relative::Scalar(3.0))
|
2019-05-03 16:56:18 +00:00
|
|
|
.label_color(TEXT_COLOR)
|
2020-01-26 19:29:46 +00:00
|
|
|
.label_font_size(self.fonts.cyri.scale(20))
|
|
|
|
.label_font_id(self.fonts.cyri.conrod_id)
|
2019-06-02 02:17:36 +00:00
|
|
|
.set(state.ids.menu_button_5, ui)
|
2019-05-03 16:56:18 +00:00
|
|
|
.was_clicked()
|
|
|
|
{
|
|
|
|
return Some(Event::Logout);
|
|
|
|
};
|
|
|
|
// Quit
|
2019-05-04 17:29:19 +00:00
|
|
|
if Button::image(self.imgs.button)
|
2019-06-02 02:17:36 +00:00
|
|
|
.mid_bottom_with_margin_on(state.ids.menu_button_5, -55.0)
|
|
|
|
.w_h(210.0, 50.0)
|
2019-05-04 17:29:19 +00:00
|
|
|
.hover_image(self.imgs.button_hover)
|
|
|
|
.press_image(self.imgs.button_press)
|
2020-01-17 23:43:18 +00:00
|
|
|
.label(&self.localized_strings.get("esc_menu.quit_game"))
|
2019-06-02 02:17:36 +00:00
|
|
|
.label_y(conrod_core::position::Relative::Scalar(3.0))
|
2019-05-03 16:56:18 +00:00
|
|
|
.label_color(TEXT_COLOR)
|
2020-01-26 19:29:46 +00:00
|
|
|
.label_font_size(self.fonts.cyri.scale(20))
|
|
|
|
.label_font_id(self.fonts.cyri.conrod_id)
|
2019-06-02 02:17:36 +00:00
|
|
|
.set(state.ids.menu_button_6, ui)
|
2019-05-03 16:56:18 +00:00
|
|
|
.was_clicked()
|
|
|
|
{
|
|
|
|
return Some(Event::Quit);
|
|
|
|
};
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|