2020-02-06 17:34:32 +00:00
|
|
|
use super::{
|
|
|
|
img_ids::{Imgs, ImgsRot},
|
2020-03-27 03:05:04 +00:00
|
|
|
Show, TEXT_COLOR, UI_HIGHLIGHT_0, UI_MAIN,
|
|
|
|
};
|
|
|
|
use crate::{
|
|
|
|
i18n::VoxygenLocalization,
|
|
|
|
ui::{fonts::ConrodVoxygenFonts, img_ids},
|
2020-02-06 17:34:32 +00:00
|
|
|
};
|
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},
|
2020-03-27 03:05:04 +00:00
|
|
|
widget_ids, 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::*;
|
2019-04-30 14:39:19 +00:00
|
|
|
widget_ids! {
|
|
|
|
struct Ids {
|
2020-03-27 03:05:04 +00:00
|
|
|
frame,
|
|
|
|
bg,
|
|
|
|
icon,
|
|
|
|
close,
|
|
|
|
title,
|
|
|
|
map_align,
|
|
|
|
qlog_align,
|
2019-06-22 14:30:53 +00:00
|
|
|
location_name,
|
2019-10-02 10:05:17 +00:00
|
|
|
indicator,
|
|
|
|
grid,
|
2020-03-27 03:05:04 +00:00
|
|
|
map_title,
|
|
|
|
qlog_title,
|
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-03-27 03:05:04 +00:00
|
|
|
localized_strings: &'a std::sync::Arc<VoxygenLocalization>,
|
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-03-27 03:05:04 +00:00
|
|
|
localized_strings: &'a std::sync::Arc<VoxygenLocalization>,
|
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-03-27 03:05:04 +00:00
|
|
|
localized_strings,
|
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;
|
2019-05-12 04:17:10 +00:00
|
|
|
|
2019-05-07 05:40:03 +00:00
|
|
|
// Frame
|
2020-03-27 03:05:04 +00:00
|
|
|
Image::new(self.imgs.map_bg)
|
|
|
|
.w_h(1052.0, 886.0)
|
|
|
|
.mid_top_with_margin_on(ui.window, 5.0)
|
|
|
|
.color(Some(UI_MAIN))
|
|
|
|
.set(state.ids.bg, ui);
|
|
|
|
|
|
|
|
Image::new(self.imgs.map_frame)
|
|
|
|
.w_h(1052.0, 886.0)
|
|
|
|
.middle_of(state.ids.bg)
|
|
|
|
.color(Some(UI_HIGHLIGHT_0))
|
|
|
|
.set(state.ids.frame, ui);
|
|
|
|
|
|
|
|
// Map Content Alignment
|
|
|
|
Rectangle::fill_with([814.0, 834.0], color::TRANSPARENT)
|
|
|
|
.top_right_with_margins_on(state.ids.frame, 46.0, 2.0)
|
|
|
|
.set(state.ids.map_align, ui);
|
|
|
|
|
|
|
|
// Questlog Content Alignment
|
|
|
|
Rectangle::fill_with([232.0, 814.0], color::TRANSPARENT)
|
|
|
|
.top_left_with_margins_on(state.ids.frame, 44.0, 2.0)
|
|
|
|
.set(state.ids.qlog_align, ui);
|
2019-05-04 17:29:19 +00:00
|
|
|
|
2019-05-07 05:40:03 +00:00
|
|
|
// Icon
|
|
|
|
Image::new(self.imgs.map_icon)
|
2020-03-27 03:05:04 +00:00
|
|
|
.w_h(30.0, 30.0)
|
|
|
|
.top_left_with_margins_on(state.ids.frame, 6.0, 8.0)
|
|
|
|
.set(state.ids.icon, ui);
|
|
|
|
|
|
|
|
// Map Title
|
|
|
|
Text::new(&self.localized_strings.get("hud.map.map_title"))
|
|
|
|
.mid_top_with_margin_on(state.ids.frame, 3.0)
|
|
|
|
.font_id(self.fonts.cyri.conrod_id)
|
|
|
|
.font_size(self.fonts.cyri.scale(29))
|
|
|
|
.color(TEXT_COLOR)
|
|
|
|
.set(state.ids.map_title, ui);
|
|
|
|
|
|
|
|
// Questlog Title
|
|
|
|
Text::new(&format!(
|
|
|
|
"{}",
|
|
|
|
&self.localized_strings.get("hud.map.qlog_title")
|
|
|
|
))
|
|
|
|
.mid_top_with_margin_on(state.ids.qlog_align, 6.0)
|
|
|
|
.font_id(self.fonts.cyri.conrod_id)
|
|
|
|
.font_size(self.fonts.cyri.scale(21))
|
|
|
|
.color(TEXT_COLOR)
|
|
|
|
.set(state.ids.qlog_title, 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)
|
2020-03-27 03:05:04 +00:00
|
|
|
.w_h(24.0, 25.0)
|
|
|
|
.hover_image(self.imgs.close_btn_hover)
|
|
|
|
.press_image(self.imgs.close_btn_press)
|
|
|
|
.top_right_with_margins_on(state.ids.frame, 0.0, 0.0)
|
|
|
|
.set(state.ids.close, ui)
|
2019-05-07 05:40:03 +00:00
|
|
|
.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
|
2020-03-27 03:05:04 +00:00
|
|
|
/*match self.client.current_chunk() {
|
2019-06-22 14:30:53 +00:00
|
|
|
Some(chunk) => Text::new(chunk.meta().name())
|
2020-03-27 03:05:04 +00:00
|
|
|
.mid_top_with_margin_on(state.ids.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)
|
2020-03-27 03:05:04 +00:00
|
|
|
.parent(state.ids.frame)
|
2019-06-22 14:30:53 +00:00
|
|
|
.set(state.ids.location_name, ui),
|
|
|
|
None => Text::new(" ")
|
2020-03-27 03:05:04 +00:00
|
|
|
.mid_top_with_margin_on(state.ids.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-03-27 03:05:04 +00:00
|
|
|
}*/
|
|
|
|
Image::new(self.imgs.map_frame_art)
|
|
|
|
.mid_top_with_margin_on(state.ids.map_align, 5.0)
|
|
|
|
.w_h(765.0, 765.0)
|
|
|
|
.parent(state.ids.bg)
|
|
|
|
.set(state.ids.grid, ui);
|
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)
|
2020-03-27 03:05:04 +00:00
|
|
|
.mid_top_with_margin_on(state.ids.map_align, 10.0)
|
|
|
|
.w_h(760.0, 760.0)
|
|
|
|
.parent(state.ids.bg)
|
2019-10-02 10:05:17 +00:00
|
|
|
.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-04-07 23:01:46 +00:00
|
|
|
// Cursor pos relative to playerpos and widget size
|
|
|
|
// Cursor stops moving on an axis as soon as it's position exceeds the maximum size of the widget
|
|
|
|
let rel = Vec2::from(player_pos).map2(worldsize, |e: f32, sz: f64| {
|
|
|
|
(e as f64 / sz).clamped(0.0, 1.0)
|
|
|
|
});
|
|
|
|
let xy = rel * 760.0;
|
|
|
|
let scale = 0.6;
|
|
|
|
let arrow_sz = Vec2::new(32.0, 37.0) * scale;
|
2020-02-06 17:34:32 +00:00
|
|
|
Image::new(self.rot_imgs.indicator_mmap_small.target_north)
|
|
|
|
.bottom_left_with_margins_on(
|
|
|
|
state.ids.grid,
|
2020-04-07 23:01:46 +00:00
|
|
|
xy.y - arrow_sz.y / 2.0,
|
|
|
|
xy.x - arrow_sz.x / 2.0,
|
2020-02-06 17:34:32 +00:00
|
|
|
)
|
2020-04-07 23:01:46 +00:00
|
|
|
.w_h(arrow_sz.x, arrow_sz.y)
|
2020-03-27 03:05:04 +00:00
|
|
|
.color(Some(UI_HIGHLIGHT_0))
|
2020-02-06 17:34:32 +00:00
|
|
|
.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
|
|
|
|
}
|
|
|
|
}
|