2019-05-07 17:21:53 +00:00
|
|
|
use conrod_core::{
|
|
|
|
color,
|
2019-05-07 17:50:53 +00:00
|
|
|
widget::{self, Button, Image, Rectangle, Text},
|
2019-05-07 17:21:53 +00:00
|
|
|
widget_ids, Colorable, Positionable, Sizeable, Widget, WidgetCommon,
|
|
|
|
};
|
|
|
|
|
2019-05-08 20:25:15 +00:00
|
|
|
use super::{img_ids::Imgs, Fonts, Show, TEXT_COLOR};
|
2019-05-07 17:21:53 +00:00
|
|
|
|
|
|
|
widget_ids! {
|
|
|
|
struct Ids {
|
|
|
|
mmap_frame,
|
|
|
|
mmap_frame_bg,
|
|
|
|
mmap_location,
|
|
|
|
mmap_button,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(WidgetCommon)]
|
|
|
|
pub struct MiniMap<'a> {
|
2019-05-07 17:50:53 +00:00
|
|
|
show: &'a Show,
|
2019-05-07 17:21:53 +00:00
|
|
|
|
|
|
|
imgs: &'a Imgs,
|
|
|
|
fonts: &'a Fonts,
|
|
|
|
|
|
|
|
#[conrod(common_builder)]
|
|
|
|
common: widget::CommonBuilder,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> MiniMap<'a> {
|
2019-05-07 17:50:53 +00:00
|
|
|
pub fn new(show: &'a Show, imgs: &'a Imgs, fonts: &'a Fonts) -> Self {
|
2019-05-07 17:21:53 +00:00
|
|
|
Self {
|
|
|
|
show,
|
|
|
|
imgs,
|
|
|
|
fonts,
|
|
|
|
common: widget::CommonBuilder::default(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct State {
|
|
|
|
ids: Ids,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum Event {
|
2019-05-07 17:50:53 +00:00
|
|
|
Toggle,
|
2019-05-07 17:21:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Widget for MiniMap<'a> {
|
|
|
|
type State = State;
|
|
|
|
type Style = ();
|
|
|
|
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 {
|
|
|
|
()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
|
|
|
|
let widget::UpdateArgs { state, ui, .. } = args;
|
|
|
|
|
|
|
|
if self.show.mini_map {
|
|
|
|
Image::new(self.imgs.mmap_frame)
|
|
|
|
.w_h(100.0 * 2.0, 100.0 * 2.0)
|
|
|
|
.top_right_with_margins_on(ui.window, 5.0, 5.0)
|
|
|
|
.set(state.ids.mmap_frame, ui);
|
|
|
|
|
|
|
|
Rectangle::fill_with([92.0 * 2.0, 82.0 * 2.0], color::TRANSPARENT)
|
|
|
|
.mid_top_with_margin_on(state.ids.mmap_frame, 13.0 * 2.0 + 2.0)
|
|
|
|
.set(state.ids.mmap_frame_bg, ui);
|
|
|
|
} else {
|
|
|
|
Image::new(self.imgs.mmap_frame_closed)
|
|
|
|
.w_h(100.0 * 2.0, 11.0 * 2.0)
|
|
|
|
.top_right_with_margins_on(ui.window, 5.0, 5.0)
|
|
|
|
.set(state.ids.mmap_frame, ui);
|
|
|
|
}
|
|
|
|
|
|
|
|
if Button::image(if self.show.mini_map {
|
|
|
|
self.imgs.mmap_open
|
|
|
|
} else {
|
|
|
|
self.imgs.mmap_closed
|
|
|
|
})
|
|
|
|
.w_h(100.0 * 0.2, 100.0 * 0.2)
|
|
|
|
.hover_image(if self.show.mini_map {
|
|
|
|
self.imgs.mmap_open_hover
|
|
|
|
} else {
|
|
|
|
self.imgs.mmap_closed_hover
|
|
|
|
})
|
|
|
|
.press_image(if self.show.mini_map {
|
|
|
|
self.imgs.mmap_open_press
|
|
|
|
} else {
|
|
|
|
self.imgs.mmap_closed_press
|
|
|
|
})
|
|
|
|
.top_right_with_margins_on(state.ids.mmap_frame, 0.0, 0.0)
|
|
|
|
.set(state.ids.mmap_button, ui)
|
|
|
|
.was_clicked()
|
|
|
|
{
|
2019-05-07 17:50:53 +00:00
|
|
|
return Some(Event::Toggle);
|
2019-05-07 17:21:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Title
|
2019-05-17 09:22:32 +00:00
|
|
|
// TODO: Make it display the actual location.
|
2019-05-07 17:21:53 +00:00
|
|
|
Text::new("Uncanny Valley")
|
|
|
|
.mid_top_with_margin_on(state.ids.mmap_frame, 3.0)
|
|
|
|
.font_size(14)
|
|
|
|
.color(TEXT_COLOR)
|
|
|
|
.set(state.ids.mmap_location, ui);
|
|
|
|
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|