From b8d5b812e13ec636e2f23a0aa4e320c9a902d939 Mon Sep 17 00:00:00 2001 From: Felix Huettner Date: Wed, 10 Feb 2021 20:37:09 +0100 Subject: [PATCH] Allow minimap to always face north Some players prefer their minimap to always face north for better orientation. --- .../buttons/min_plus/mmap_button-north.png | 3 + .../min_plus/mmap_button-north_hover.png | 3 + .../min_plus/mmap_button-north_press.png | 3 + .../mmap_button-north_press_hover.png | 3 + voxygen/src/hud/img_ids.rs | 4 ++ voxygen/src/hud/minimap.rs | 62 ++++++++++++++++--- voxygen/src/hud/settings_window.rs | 1 + 7 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 assets/voxygen/element/buttons/min_plus/mmap_button-north.png create mode 100644 assets/voxygen/element/buttons/min_plus/mmap_button-north_hover.png create mode 100644 assets/voxygen/element/buttons/min_plus/mmap_button-north_press.png create mode 100644 assets/voxygen/element/buttons/min_plus/mmap_button-north_press_hover.png diff --git a/assets/voxygen/element/buttons/min_plus/mmap_button-north.png b/assets/voxygen/element/buttons/min_plus/mmap_button-north.png new file mode 100644 index 0000000000..ed9623f83a --- /dev/null +++ b/assets/voxygen/element/buttons/min_plus/mmap_button-north.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c7dc2d6ee1f90766190dce1007977e7ecab23010ef55feb4c8f814d0b1053375 +size 8696 diff --git a/assets/voxygen/element/buttons/min_plus/mmap_button-north_hover.png b/assets/voxygen/element/buttons/min_plus/mmap_button-north_hover.png new file mode 100644 index 0000000000..842ac14c2d --- /dev/null +++ b/assets/voxygen/element/buttons/min_plus/mmap_button-north_hover.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:430ee88475bc31d25481ad0f19698ca01ae50e6bb61e6e422ca29c789657742a +size 558 diff --git a/assets/voxygen/element/buttons/min_plus/mmap_button-north_press.png b/assets/voxygen/element/buttons/min_plus/mmap_button-north_press.png new file mode 100644 index 0000000000..29cba90fef --- /dev/null +++ b/assets/voxygen/element/buttons/min_plus/mmap_button-north_press.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8fdfc722ac9657129f2321dd30b5a16a4d31bf00e2200de6acc4f36428474b9e +size 594 diff --git a/assets/voxygen/element/buttons/min_plus/mmap_button-north_press_hover.png b/assets/voxygen/element/buttons/min_plus/mmap_button-north_press_hover.png new file mode 100644 index 0000000000..231debd3e5 --- /dev/null +++ b/assets/voxygen/element/buttons/min_plus/mmap_button-north_press_hover.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:659c12df2919e0bb65fed687bdc76fbc24bf274c1cac1da2e9538bc2ffeba82f +size 555 diff --git a/voxygen/src/hud/img_ids.rs b/voxygen/src/hud/img_ids.rs index 0ed9ad1332..58b9f19799 100644 --- a/voxygen/src/hud/img_ids.rs +++ b/voxygen/src/hud/img_ids.rs @@ -252,6 +252,10 @@ image_ids! { mmap_minus: "voxygen.element.buttons.min_plus.mmap_button-min", mmap_minus_hover: "voxygen.element.buttons.min_plus.mmap_button-min_hover", mmap_minus_press: "voxygen.element.buttons.min_plus.mmap_button-min_press", + mmap_north: "voxygen.element.buttons.min_plus.mmap_button-north", + mmap_north_hover: "voxygen.element.buttons.min_plus.mmap_button-north_hover", + mmap_north_press: "voxygen.element.buttons.min_plus.mmap_button-north_press", + mmap_north_press_hover: "voxygen.element.buttons.min_plus.mmap_button-north_press_hover", map_dif_1: "voxygen.element.map.dif_1", map_dif_2: "voxygen.element.map.dif_2", map_dif_3: "voxygen.element.map.dif_3", diff --git a/voxygen/src/hud/minimap.rs b/voxygen/src/hud/minimap.rs index e5de2b90ed..387062e4bd 100644 --- a/voxygen/src/hud/minimap.rs +++ b/voxygen/src/hud/minimap.rs @@ -25,6 +25,7 @@ widget_ids! { mmap_button, mmap_plus, mmap_minus, + mmap_north_button, grid, indicator, mmap_north, @@ -79,6 +80,8 @@ pub struct State { ids: Ids, zoom: f64, + + is_facing_north: bool, } pub enum Event { @@ -102,6 +105,8 @@ impl<'a> Widget for MiniMap<'a> { * (16.0 / 1024.0), ) }, + + is_facing_north: false, } } @@ -112,6 +117,12 @@ impl<'a> Widget for MiniMap<'a> { let widget::UpdateArgs { state, ui, .. } = args; let zoom = state.zoom; const SCALE: f64 = 1.5; // TODO Make this a setting + let orientation = if state.is_facing_north { + Vec3::new(0.0, 1.0, 0.0) + } else { + self.ori + }; + if self.show.mini_map { Image::new(self.imgs.mmap_frame) .w_h(174.0 * SCALE, 190.0 * SCALE) @@ -182,6 +193,31 @@ impl<'a> Widget for MiniMap<'a> { // set_image_dims(zoom); } + // Always northfacing button + if Button::image(if state.is_facing_north { + self.imgs.mmap_north_press + } else { + self.imgs.mmap_north + }) + .w_h(18.0 * SCALE, 18.0 * SCALE) + .hover_image(if state.is_facing_north { + self.imgs.mmap_north_press_hover + } else { + self.imgs.mmap_north_hover + }) + .press_image(if state.is_facing_north { + self.imgs.mmap_north_press_hover + } else { + self.imgs.mmap_north_press + }) + .left_from(state.ids.mmap_button, 0.0) + .image_color(UI_HIGHLIGHT_0) + .set(state.ids.mmap_north_button, ui) + .was_clicked() + { + state.update(|s| s.is_facing_north = !s.is_facing_north); + } + // Reload zoom in case it changed. let zoom = state.zoom; @@ -211,7 +247,12 @@ impl<'a> Widget for MiniMap<'a> { let map_size = Vec2::new(170.0 * SCALE, 170.0 * SCALE); // Map Image - Image::new(world_map.source_north) + let world_map_rotation = if state.is_facing_north { + world_map.none + } else { + world_map.source_north + }; + Image::new(world_map_rotation) .middle_of(state.ids.mmap_frame_bg) .w_h(map_size.x, map_size.y) .parent(state.ids.mmap_frame_bg) @@ -246,8 +287,8 @@ impl<'a> Widget for MiniMap<'a> { // (the center) // Accounting for zooming let rpixpos = rfpos.map2(map_size, |e, sz| e * sz as f32 * zoom as f32); - let rpos = Vec2::unit_x().rotated_z(self.ori.x) * rpixpos.x - + Vec2::unit_y().rotated_z(self.ori.x) * rpixpos.y; + let rpos = Vec2::unit_x().rotated_z(orientation.x) * rpixpos.x + + Vec2::unit_y().rotated_z(orientation.x) * rpixpos.y; if rpos .map2(map_size, |e, sz| e.abs() > sz as f32 / 2.0) @@ -335,8 +376,8 @@ impl<'a> Widget for MiniMap<'a> { // (the center) // Accounting for zooming let rpixpos = rfpos.map2(map_size, |e, sz| e * sz as f32 * zoom as f32); - let rpos = Vec2::unit_x().rotated_z(self.ori.x) * rpixpos.x - + Vec2::unit_y().rotated_z(self.ori.x) * rpixpos.y; + let rpos = Vec2::unit_x().rotated_z(orientation.x) * rpixpos.x + + Vec2::unit_y().rotated_z(orientation.x) * rpixpos.y; if rpos .map2(map_size, |e, sz| e.abs() > sz as f32 / 2.0) @@ -364,7 +405,12 @@ impl<'a> Widget for MiniMap<'a> { // Indicator let ind_scale = 0.4; - Image::new(self.rot_imgs.indicator_mmap_small.none) + let ind_rotation = if state.is_facing_north { + self.rot_imgs.indicator_mmap_small.target_north + } else { + self.rot_imgs.indicator_mmap_small.none + }; + Image::new(ind_rotation) .middle_of(state.ids.grid) .w_h(32.0 * ind_scale, 37.0 * ind_scale) .color(Some(UI_HIGHLIGHT_0)) @@ -379,8 +425,8 @@ impl<'a> Widget for MiniMap<'a> { (Vec2::new(-1.0, 0.0), state.ids.mmap_west, "W", false), ]; for (dir, id, name, bold) in dirs.iter() { - let cardinal_dir = Vec2::unit_x().rotated_z(self.ori.x as f64) * dir.x - + Vec2::unit_y().rotated_z(self.ori.x as f64) * dir.y; + let cardinal_dir = Vec2::unit_x().rotated_z(orientation.x as f64) * dir.x + + Vec2::unit_y().rotated_z(orientation.x as f64) * dir.y; let clamped = cardinal_dir / cardinal_dir.map(|e| e.abs()).reduce_partial_max(); let pos = clamped * (map_size / 2.0 - 10.0); Text::new(name) diff --git a/voxygen/src/hud/settings_window.rs b/voxygen/src/hud/settings_window.rs index 3ec8fd7d9c..def979106b 100644 --- a/voxygen/src/hud/settings_window.rs +++ b/voxygen/src/hud/settings_window.rs @@ -925,6 +925,7 @@ impl<'a> Widget for SettingsWindow<'a> { .graphics_for(state.ids.show_shortcuts_button) .color(TEXT_COLOR) .set(state.ids.buff_pos_map_text, ui); + // Content Right Side /*Scrolling Combat text