From 6dcdd80ec8d2d0d8a5e9ac9d31e680e453345a6e Mon Sep 17 00:00:00 2001 From: Pfauenauge Date: Wed, 8 Apr 2020 01:01:46 +0200 Subject: [PATCH] smarter code --- assets/voxygen/item_image_manifest.ron | 2 +- voxygen/src/hud/map.rs | 29 ++++++++++---------------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/assets/voxygen/item_image_manifest.ron b/assets/voxygen/item_image_manifest.ron index f7aa8bc366..78e4f1d861 100644 --- a/assets/voxygen/item_image_manifest.ron +++ b/assets/voxygen/item_image_manifest.ron @@ -241,7 +241,7 @@ ), // Lanterns Armor(Lantern(Black0)): Png( - "voxel.element.icons.lantern_grey-0", + "element.icons.lantern_black-0", ), Armor(Lantern(Green0)): Png( "element.icons.lantern_green-0", diff --git a/voxygen/src/hud/map.rs b/voxygen/src/hud/map.rs index 69a4efb66a..82c07d7c54 100644 --- a/voxygen/src/hud/map.rs +++ b/voxygen/src/hud/map.rs @@ -15,7 +15,6 @@ use conrod_core::{ }; use specs::WorldExt; use vek::*; - widget_ids! { struct Ids { frame, @@ -193,27 +192,21 @@ impl<'a> Widget for Map<'a> { .read_storage::() .get(self.client.entity()) .map_or(Vec3::zero(), |pos| pos.0); - - let x = player_pos.x as f64 / worldsize.x * 760.0; - let y = player_pos.y as f64 / worldsize.y * 760.0; - let x_rel = player_pos.x as f64 / worldsize.x; - let y_rel = player_pos.y as f64 / worldsize.y; - let indic_scale = 0.6; + // 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; Image::new(self.rot_imgs.indicator_mmap_small.target_north) .bottom_left_with_margins_on( state.ids.grid, - if y_rel > 0.0 && y_rel < 1.0 { - y - 37.0 * indic_scale / 2.0 - } else { - 760.0 - 37.0 * indic_scale / 2.0 - }, - if x_rel > 0.0 && x_rel < 1.0 { - x - 32.0 * indic_scale / 2.0 - } else { - 760.0 - 32.0 * indic_scale / 2.0 - }, + xy.y - arrow_sz.y / 2.0, + xy.x - arrow_sz.x / 2.0, ) - .w_h(32.0 * indic_scale, 37.0 * indic_scale) + .w_h(arrow_sz.x, arrow_sz.y) .color(Some(UI_HIGHLIGHT_0)) .floating(true) .parent(ui.window)