2020-02-06 17:34:32 +00:00
|
|
|
use super::{
|
|
|
|
img_ids::{Imgs, ImgsRot},
|
2020-01-26 19:29:46 +00:00
|
|
|
Show, TEXT_COLOR,
|
2020-02-06 17:34:32 +00:00
|
|
|
};
|
2020-01-26 19:29:46 +00:00
|
|
|
use crate::ui::{fonts::ConrodVoxygenFonts, img_ids};
|
2019-10-02 10:05:17 +00:00
|
|
|
use client::{self, Client};
|
2020-01-11 19:25:48 +00:00
|
|
|
use common::{comp, terrain::TerrainChunkSize, vol::RectVolSize};
|
2019-04-30 14:39:19 +00:00
|
|
|
use conrod_core::{
|
2019-05-07 03:25:25 +00:00
|
|
|
color,
|
2019-06-22 14:30:53 +00:00
|
|
|
widget::{self, Button, Image, Rectangle, Text},
|
2019-12-30 12:16:35 +00:00
|
|
|
widget_ids, Color, Colorable, Positionable, Sizeable, Widget, WidgetCommon,
|
2019-04-30 14:39:19 +00:00
|
|
|
};
|
2019-11-30 06:41:20 +00:00
|
|
|
use specs::WorldExt;
|
2019-10-02 10:05:17 +00:00
|
|
|
use vek::*;
|
2020-01-26 19:29:46 +00:00
|
|
|
|
2019-04-30 14:39:19 +00:00
|
|
|
widget_ids! {
|
|
|
|
struct Ids {
|
2019-05-04 17:29:19 +00:00
|
|
|
map_frame,
|
2019-04-30 14:39:19 +00:00
|
|
|
map_bg,
|
2019-05-04 17:29:19 +00:00
|
|
|
map_icon,
|
2019-04-30 14:39:19 +00:00
|
|
|
map_close,
|
2019-05-04 17:29:19 +00:00
|
|
|
map_title,
|
2019-04-30 14:39:19 +00:00
|
|
|
map_frame_l,
|
|
|
|
map_frame_r,
|
2019-05-04 17:29:19 +00:00
|
|
|
map_frame_bl,
|
|
|
|
map_frame_br,
|
2019-06-22 14:30:53 +00:00
|
|
|
location_name,
|
2019-10-02 10:05:17 +00:00
|
|
|
indicator,
|
|
|
|
grid,
|
2019-04-30 14:39:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(WidgetCommon)]
|
|
|
|
pub struct Map<'a> {
|
2019-07-02 21:25:07 +00:00
|
|
|
_show: &'a Show,
|
2019-06-22 14:30:53 +00:00
|
|
|
client: &'a Client,
|
2020-02-06 17:34:32 +00:00
|
|
|
world_map: &'a (img_ids::Rotations, Vec2<u32>),
|
2019-04-30 14:39:19 +00:00
|
|
|
imgs: &'a Imgs,
|
2020-02-06 17:34:32 +00:00
|
|
|
rot_imgs: &'a ImgsRot,
|
2020-01-26 19:29:46 +00:00
|
|
|
fonts: &'a ConrodVoxygenFonts,
|
2019-04-30 14:39:19 +00:00
|
|
|
#[conrod(common_builder)]
|
|
|
|
common: widget::CommonBuilder,
|
2020-02-06 17:34:32 +00:00
|
|
|
_pulse: f32,
|
2020-01-10 00:33:38 +00:00
|
|
|
velocity: f32,
|
2019-04-30 14:39:19 +00:00
|
|
|
}
|
|
|
|
impl<'a> Map<'a> {
|
2019-10-16 11:39:41 +00:00
|
|
|
pub fn new(
|
|
|
|
show: &'a Show,
|
|
|
|
client: &'a Client,
|
|
|
|
imgs: &'a Imgs,
|
2020-02-06 17:34:32 +00:00
|
|
|
rot_imgs: &'a ImgsRot,
|
|
|
|
world_map: &'a (img_ids::Rotations, Vec2<u32>),
|
2020-01-26 19:29:46 +00:00
|
|
|
fonts: &'a ConrodVoxygenFonts,
|
2019-12-30 12:16:35 +00:00
|
|
|
pulse: f32,
|
2020-01-10 00:33:38 +00:00
|
|
|
velocity: f32,
|
2019-10-16 11:39:41 +00:00
|
|
|
) -> Self {
|
2019-04-30 14:39:19 +00:00
|
|
|
Self {
|
2019-07-02 21:25:07 +00:00
|
|
|
_show: show,
|
2019-04-30 14:39:19 +00:00
|
|
|
imgs,
|
2020-02-06 17:34:32 +00:00
|
|
|
rot_imgs,
|
2020-01-11 19:25:48 +00:00
|
|
|
world_map,
|
2019-06-22 14:30:53 +00:00
|
|
|
client,
|
2020-02-01 20:39:39 +00:00
|
|
|
fonts,
|
2019-04-30 14:39:19 +00:00
|
|
|
common: widget::CommonBuilder::default(),
|
2020-02-06 17:34:32 +00:00
|
|
|
_pulse: pulse,
|
2020-01-10 00:33:38 +00:00
|
|
|
velocity,
|
2019-04-30 14:39:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct State {
|
|
|
|
ids: Ids,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum Event {
|
|
|
|
Close,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Widget for Map<'a> {
|
2020-02-01 20:39:39 +00:00
|
|
|
type Event = Option<Event>;
|
2019-04-30 14:39:19 +00:00
|
|
|
type State = State;
|
2019-04-30 20:43:55 +00:00
|
|
|
type Style = ();
|
2019-04-30 14:39:19 +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 14:39:19 +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;
|
2020-01-10 00:33:38 +00:00
|
|
|
// Set map transparency to 0.5 when player is moving
|
|
|
|
let mut fade = 1.0;
|
2020-01-12 19:01:02 +00:00
|
|
|
if self.velocity > 2.5 {
|
2020-01-10 00:33:38 +00:00
|
|
|
fade = 0.7
|
|
|
|
};
|
2019-04-30 14:39:19 +00:00
|
|
|
|
|
|
|
// BG
|
2019-05-07 05:40:03 +00:00
|
|
|
Rectangle::fill_with([824.0, 976.0], color::TRANSPARENT)
|
|
|
|
.mid_top_with_margin_on(ui.window, 15.0)
|
|
|
|
.scroll_kids()
|
|
|
|
.scroll_kids_vertically()
|
|
|
|
.set(state.ids.map_bg, ui);
|
2019-05-12 04:17:10 +00:00
|
|
|
|
2019-05-07 05:40:03 +00:00
|
|
|
// Frame
|
|
|
|
Image::new(self.imgs.map_frame_l)
|
|
|
|
.top_left_with_margins_on(state.ids.map_bg, 0.0, 0.0)
|
|
|
|
.w_h(412.0, 488.0)
|
2020-01-10 00:33:38 +00:00
|
|
|
.color(Some(Color::Rgba(1.0, 1.0, 1.0, fade)))
|
2019-05-07 05:40:03 +00:00
|
|
|
.set(state.ids.map_frame_l, ui);
|
|
|
|
Image::new(self.imgs.map_frame_r)
|
|
|
|
.right_from(state.ids.map_frame_l, 0.0)
|
2020-01-10 00:33:38 +00:00
|
|
|
.color(Some(Color::Rgba(1.0, 1.0, 1.0, fade)))
|
2019-05-07 05:40:03 +00:00
|
|
|
.w_h(412.0, 488.0)
|
|
|
|
.set(state.ids.map_frame_r, ui);
|
|
|
|
Image::new(self.imgs.map_frame_br)
|
|
|
|
.down_from(state.ids.map_frame_r, 0.0)
|
|
|
|
.w_h(412.0, 488.0)
|
2020-01-10 00:33:38 +00:00
|
|
|
.color(Some(Color::Rgba(1.0, 1.0, 1.0, fade)))
|
2019-05-07 05:40:03 +00:00
|
|
|
.set(state.ids.map_frame_br, ui);
|
|
|
|
Image::new(self.imgs.map_frame_bl)
|
|
|
|
.down_from(state.ids.map_frame_l, 0.0)
|
|
|
|
.w_h(412.0, 488.0)
|
2020-01-10 00:33:38 +00:00
|
|
|
.color(Some(Color::Rgba(1.0, 1.0, 1.0, fade)))
|
2019-05-07 05:40:03 +00:00
|
|
|
.set(state.ids.map_frame_bl, ui);
|
2019-05-04 17:29:19 +00:00
|
|
|
|
2019-05-07 05:40:03 +00:00
|
|
|
// Icon
|
|
|
|
Image::new(self.imgs.map_icon)
|
|
|
|
.w_h(224.0 / 3.0, 224.0 / 3.0)
|
|
|
|
.top_left_with_margins_on(state.ids.map_frame, -10.0, -10.0)
|
2020-01-10 00:33:38 +00:00
|
|
|
.color(Some(Color::Rgba(1.0, 1.0, 1.0, fade)))
|
2019-05-07 05:40:03 +00:00
|
|
|
.set(state.ids.map_icon, ui);
|
2019-04-30 14:39:19 +00:00
|
|
|
|
|
|
|
// X-Button
|
2019-05-07 05:40:03 +00:00
|
|
|
if Button::image(self.imgs.close_button)
|
|
|
|
.w_h(28.0, 28.0)
|
|
|
|
.hover_image(self.imgs.close_button_hover)
|
|
|
|
.press_image(self.imgs.close_button_press)
|
2020-01-10 00:33:38 +00:00
|
|
|
.color(Color::Rgba(1.0, 1.0, 1.0, fade - 0.5))
|
2019-05-07 05:40:03 +00:00
|
|
|
.top_right_with_margins_on(state.ids.map_frame_r, 0.0, 0.0)
|
|
|
|
.set(state.ids.map_close, ui)
|
|
|
|
.was_clicked()
|
2019-04-30 14:39:19 +00:00
|
|
|
{
|
|
|
|
return Some(Event::Close);
|
2019-05-07 05:40:03 +00:00
|
|
|
}
|
2019-04-30 14:39:19 +00:00
|
|
|
|
2019-06-22 14:30:53 +00:00
|
|
|
// Location Name
|
|
|
|
match self.client.current_chunk() {
|
|
|
|
Some(chunk) => Text::new(chunk.meta().name())
|
2019-12-30 12:16:35 +00:00
|
|
|
.mid_top_with_margin_on(state.ids.map_bg, 55.0)
|
2020-01-26 19:29:46 +00:00
|
|
|
.font_size(self.fonts.alkhemi.scale(60))
|
2019-10-04 18:27:12 +00:00
|
|
|
.color(TEXT_COLOR)
|
2020-01-26 19:29:46 +00:00
|
|
|
.font_id(self.fonts.alkhemi.conrod_id)
|
2019-06-22 14:30:53 +00:00
|
|
|
.parent(state.ids.map_frame_r)
|
|
|
|
.set(state.ids.location_name, ui),
|
|
|
|
None => Text::new(" ")
|
|
|
|
.mid_top_with_margin_on(state.ids.map_bg, 3.0)
|
2020-01-26 19:29:46 +00:00
|
|
|
.font_size(self.fonts.alkhemi.scale(40))
|
|
|
|
.font_id(self.fonts.alkhemi.conrod_id)
|
2019-10-04 18:27:12 +00:00
|
|
|
.color(TEXT_COLOR)
|
2019-06-22 14:30:53 +00:00
|
|
|
.set(state.ids.location_name, ui),
|
|
|
|
}
|
2020-01-10 00:33:38 +00:00
|
|
|
|
2019-10-02 10:05:17 +00:00
|
|
|
// Map Image
|
2020-01-11 19:25:48 +00:00
|
|
|
let (world_map, worldsize) = self.world_map;
|
|
|
|
let worldsize = worldsize.map2(TerrainChunkSize::RECT_SIZE, |e, f| e as f64 * f as f64);
|
|
|
|
|
2020-02-06 17:34:32 +00:00
|
|
|
Image::new(world_map.none)
|
2019-10-02 10:05:17 +00:00
|
|
|
.middle_of(state.ids.map_bg)
|
2020-02-06 17:34:32 +00:00
|
|
|
.color(Some(Color::Rgba(1.0, 1.0, 1.0, fade + 0.5)))
|
2019-10-02 10:05:17 +00:00
|
|
|
.w_h(700.0, 700.0)
|
|
|
|
.parent(state.ids.map_bg)
|
|
|
|
.set(state.ids.grid, ui);
|
|
|
|
// Coordinates
|
|
|
|
let player_pos = self
|
|
|
|
.client
|
|
|
|
.state()
|
|
|
|
.ecs()
|
|
|
|
.read_storage::<comp::Pos>()
|
|
|
|
.get(self.client.entity())
|
|
|
|
.map_or(Vec3::zero(), |pos| pos.0);
|
|
|
|
|
2020-01-22 13:35:13 +00:00
|
|
|
let x = player_pos.x as f64 / worldsize.x * 700.0;
|
2020-01-11 23:04:15 +00:00
|
|
|
let y = player_pos.y as f64 / worldsize.y * 700.0;
|
2020-02-06 17:34:32 +00:00
|
|
|
let indic_scale = 0.6;
|
|
|
|
Image::new(self.rot_imgs.indicator_mmap_small.target_north)
|
|
|
|
.bottom_left_with_margins_on(
|
|
|
|
state.ids.grid,
|
|
|
|
y - 37.0 * indic_scale / 2.0,
|
|
|
|
x - 32.0 * indic_scale / 2.0,
|
|
|
|
)
|
|
|
|
.w_h(32.0 * indic_scale, 37.0 * indic_scale)
|
|
|
|
.color(Some(Color::Rgba(1.0, 1.0, 1.0, 1.0)))
|
|
|
|
.floating(true)
|
|
|
|
.parent(ui.window)
|
|
|
|
.set(state.ids.indicator, ui);
|
2019-06-22 14:30:53 +00:00
|
|
|
|
2019-04-30 14:39:19 +00:00
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|