From c28e61383de2a40b8c75c2363d8dcc24a73589ef Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Fri, 31 Mar 2023 16:25:24 +0100 Subject: [PATCH] Added target to starting site map --- .../element/ui/char_select/icons/target.png | 3 ++ voxygen/src/menu/char_selection/ui/mod.rs | 40 ++++++++++++++++--- voxygen/src/ui/ice/widget/overlay.rs | 16 ++++++-- 3 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 assets/voxygen/element/ui/char_select/icons/target.png diff --git a/assets/voxygen/element/ui/char_select/icons/target.png b/assets/voxygen/element/ui/char_select/icons/target.png new file mode 100644 index 0000000000..8ed3e01069 --- /dev/null +++ b/assets/voxygen/element/ui/char_select/icons/target.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0e6e9f0c838783bf16e9396a3bd8840bfe9953bc82e468b617260a9245a62e44 +size 717 diff --git a/voxygen/src/menu/char_selection/ui/mod.rs b/voxygen/src/menu/char_selection/ui/mod.rs index ed2958f403..759b4049b7 100644 --- a/voxygen/src/menu/char_selection/ui/mod.rs +++ b/voxygen/src/menu/char_selection/ui/mod.rs @@ -24,6 +24,8 @@ use client::{Client, ServerInfo}; use common::{ character::{CharacterId, CharacterItem, MAX_CHARACTERS_PER_PLAYER, MAX_NAME_LENGTH}, comp::{self, humanoid, inventory::slot::EquipSlot, Inventory, Item}, + terrain::TerrainChunkSize, + vol::RectVolSize, LoadoutBuilder, }; use common_net::msg::world_msg::{SiteId, SiteInfo, SiteKind}; @@ -36,7 +38,7 @@ use iced::{ button, scrollable, slider, text_input, Align, Button, Column, Container, HorizontalAlignment, Length, Row, Scrollable, Slider, Space, Text, TextInput, }; -use vek::Rgba; +use vek::{Rgba, Vec2}; pub const TEXT_COLOR: iced::Color = iced::Color::from_rgb(1.0, 1.0, 1.0); pub const DISABLED_TEXT_COLOR: iced::Color = iced::Color::from_rgba(1.0, 1.0, 1.0, 0.2); @@ -123,6 +125,9 @@ image_ids_ice! { // Tooltips tt_edge: "voxygen.element.ui.generic.frames.tooltip.edge", tt_corner: "voxygen.element.ui.generic.frames.tooltip.corner", + + // Map things + target: "voxygen.element.ui.char_select.icons.target", } } @@ -293,6 +298,7 @@ struct Controls { default_name: String, map_img: GraphicId, possible_starting_sites: Vec, + world_sz: Vec2, } #[derive(Clone)] @@ -338,6 +344,7 @@ impl Controls { server_info: &ServerInfo, map_img: GraphicId, possible_starting_sites: Vec, + world_sz: Vec2, ) -> Self { let version = common::util::DISPLAY_VERSION_LONG.clone(); let alpha = format!("Veloren {}", common::util::DISPLAY_VERSION.as_str()); @@ -358,6 +365,7 @@ impl Controls { default_name, map_img, possible_starting_sites, + world_sz, } } @@ -1245,11 +1253,32 @@ impl Controls { ]; let right_column_content = if character_id.is_none() { + let map_sz = Vec2::new(300, 300); + let map_img = Image::new(self.map_img) + .height(Length::Units(map_sz.x)) + .width(Length::Units(map_sz.y)); + let map = if let Some(info) = self.possible_starting_sites.get(*start_site_idx) + { + let pos_frac = info + .wpos + .map2(self.world_sz * TerrainChunkSize::RECT_SIZE, |e, sz| { + e as f32 / sz as f32 + }); + let point = Vec2::new(pos_frac.x, 1.0 - pos_frac.y) + .map2(map_sz, |e, sz| e * sz as f32 - 12.0); + Overlay::new( + Image::new(imgs.target) + .height(Length::Units(24)) + .width(Length::Units(24)), + map_img, + ) + .over_position(iced::Point::new(point.x, point.y)) + .into() + } else { + map_img.into() + }; vec![ - Image::new(self.map_img) - .height(Length::Units(300)) - .width(Length::Units(300)) - .into(), + map, Column::with_children(if self.possible_starting_sites.is_empty() { Vec::new() } else { @@ -1807,6 +1836,7 @@ impl CharSelectionUi { .filter(|info| matches!(&info.site.kind, SiteKind::Town | SiteKind::Castle | SiteKind::Bridge)) .map(|info| info.site.clone()) .collect(), + client.world_data().chunk_size().as_(), ); Self { diff --git a/voxygen/src/ui/ice/widget/overlay.rs b/voxygen/src/ui/ice/widget/overlay.rs index 8ca69aa745..e1903bcae6 100644 --- a/voxygen/src/ui/ice/widget/overlay.rs +++ b/voxygen/src/ui/ice/widget/overlay.rs @@ -19,6 +19,7 @@ pub struct Overlay<'a, M, R: Renderer> { vertical_alignment: Align, over: Element<'a, M, R>, under: Element<'a, M, R>, + pos: Option, // add style etc as needed } @@ -41,9 +42,16 @@ where vertical_alignment: Align::Start, over: over.into(), under: under.into(), + pos: None, } } + #[must_use] + pub fn over_position(mut self, pos: Point) -> Self { + self.pos = Some(pos); + self + } + #[must_use] pub fn padding>(mut self, pad: P) -> Self { self.padding = pad.into(); @@ -130,10 +138,10 @@ where .pad(self.padding), ); - over.move_to(Point::new( - self.padding.left.into(), - self.padding.top.into(), - )); + over.move_to( + self.pos + .unwrap_or_else(|| Point::new(self.padding.left.into(), self.padding.top.into())), + ); over.align(self.horizontal_alignment, self.vertical_alignment, size); layout::Node::with_children(size, vec![over, under])