Merge branch 'huettner94/minimap_settings_persistence' into 'master'

Persist minimap settings

See merge request veloren/veloren!1785
This commit is contained in:
Imbris 2021-02-17 00:57:07 +00:00
commit 1a3e015da7
4 changed files with 45 additions and 29 deletions

View File

@ -1,9 +1,12 @@
use super::{ use super::{
img_ids::{Imgs, ImgsRot}, img_ids::{Imgs, ImgsRot},
Show, QUALITY_COMMON, QUALITY_DEBUG, QUALITY_EPIC, QUALITY_HIGH, QUALITY_LOW, QUALITY_MODERATE, QUALITY_COMMON, QUALITY_DEBUG, QUALITY_EPIC, QUALITY_HIGH, QUALITY_LOW, QUALITY_MODERATE,
TEXT_COLOR, UI_HIGHLIGHT_0, UI_MAIN, TEXT_COLOR, UI_HIGHLIGHT_0, UI_MAIN,
}; };
use crate::ui::{fonts::Fonts, img_ids}; use crate::{
ui::{fonts::Fonts, img_ids},
GlobalState,
};
use client::{self, Client}; use client::{self, Client};
use common::{comp, comp::group::Role, terrain::TerrainChunkSize, vol::RectVolSize}; use common::{comp, comp::group::Role, terrain::TerrainChunkSize, vol::RectVolSize};
use common_net::msg::world_msg::SiteKind; use common_net::msg::world_msg::SiteKind;
@ -40,8 +43,6 @@ widget_ids! {
#[derive(WidgetCommon)] #[derive(WidgetCommon)]
pub struct MiniMap<'a> { pub struct MiniMap<'a> {
show: &'a Show,
client: &'a Client, client: &'a Client,
imgs: &'a Imgs, imgs: &'a Imgs,
@ -51,20 +52,20 @@ pub struct MiniMap<'a> {
#[conrod(common_builder)] #[conrod(common_builder)]
common: widget::CommonBuilder, common: widget::CommonBuilder,
ori: Vec3<f32>, ori: Vec3<f32>,
global_state: &'a GlobalState,
} }
impl<'a> MiniMap<'a> { impl<'a> MiniMap<'a> {
pub fn new( pub fn new(
show: &'a Show,
client: &'a Client, client: &'a Client,
imgs: &'a Imgs, imgs: &'a Imgs,
rot_imgs: &'a ImgsRot, rot_imgs: &'a ImgsRot,
world_map: &'a (img_ids::Rotations, Vec2<u32>), world_map: &'a (img_ids::Rotations, Vec2<u32>),
fonts: &'a Fonts, fonts: &'a Fonts,
ori: Vec3<f32>, ori: Vec3<f32>,
global_state: &'a GlobalState,
) -> Self { ) -> Self {
Self { Self {
show,
client, client,
imgs, imgs,
rot_imgs, rot_imgs,
@ -72,6 +73,7 @@ impl<'a> MiniMap<'a> {
fonts, fonts,
common: widget::CommonBuilder::default(), common: widget::CommonBuilder::default(),
ori, ori,
global_state,
} }
} }
} }
@ -80,12 +82,11 @@ pub struct State {
ids: Ids, ids: Ids,
zoom: f64, zoom: f64,
is_facing_north: bool,
} }
pub enum Event { pub enum Event {
Toggle, Show(bool),
FaceNorth(bool),
} }
impl<'a> Widget for MiniMap<'a> { impl<'a> Widget for MiniMap<'a> {
@ -105,8 +106,6 @@ impl<'a> Widget for MiniMap<'a> {
* (16.0 / 1024.0), * (16.0 / 1024.0),
) )
}, },
is_facing_north: false,
} }
} }
@ -117,13 +116,15 @@ impl<'a> Widget for MiniMap<'a> {
let widget::UpdateArgs { state, ui, .. } = args; let widget::UpdateArgs { state, ui, .. } = args;
let zoom = state.zoom; let zoom = state.zoom;
const SCALE: f64 = 1.5; // TODO Make this a setting const SCALE: f64 = 1.5; // TODO Make this a setting
let orientation = if state.is_facing_north { let show_minimap = self.global_state.settings.gameplay.minimap_show;
let is_facing_north = self.global_state.settings.gameplay.minimap_face_north;
let orientation = if is_facing_north {
Vec3::new(0.0, 1.0, 0.0) Vec3::new(0.0, 1.0, 0.0)
} else { } else {
self.ori self.ori
}; };
if self.show.mini_map { if show_minimap {
Image::new(self.imgs.mmap_frame) Image::new(self.imgs.mmap_frame)
.w_h(174.0 * SCALE, 190.0 * SCALE) .w_h(174.0 * SCALE, 190.0 * SCALE)
.top_right_with_margins_on(ui.window, 5.0, 5.0) .top_right_with_margins_on(ui.window, 5.0, 5.0)
@ -194,18 +195,18 @@ impl<'a> Widget for MiniMap<'a> {
} }
// Always northfacing button // Always northfacing button
if Button::image(if state.is_facing_north { if Button::image(if is_facing_north {
self.imgs.mmap_north_press self.imgs.mmap_north_press
} else { } else {
self.imgs.mmap_north self.imgs.mmap_north
}) })
.w_h(18.0 * SCALE, 18.0 * SCALE) .w_h(18.0 * SCALE, 18.0 * SCALE)
.hover_image(if state.is_facing_north { .hover_image(if is_facing_north {
self.imgs.mmap_north_press_hover self.imgs.mmap_north_press_hover
} else { } else {
self.imgs.mmap_north_hover self.imgs.mmap_north_hover
}) })
.press_image(if state.is_facing_north { .press_image(if is_facing_north {
self.imgs.mmap_north_press_hover self.imgs.mmap_north_press_hover
} else { } else {
self.imgs.mmap_north_press self.imgs.mmap_north_press
@ -215,7 +216,7 @@ impl<'a> Widget for MiniMap<'a> {
.set(state.ids.mmap_north_button, ui) .set(state.ids.mmap_north_button, ui)
.was_clicked() .was_clicked()
{ {
state.update(|s| s.is_facing_north = !s.is_facing_north); return Some(Event::FaceNorth(!is_facing_north));
} }
// Reload zoom in case it changed. // Reload zoom in case it changed.
@ -247,7 +248,7 @@ impl<'a> Widget for MiniMap<'a> {
let map_size = Vec2::new(170.0 * SCALE, 170.0 * SCALE); let map_size = Vec2::new(170.0 * SCALE, 170.0 * SCALE);
// Map Image // Map Image
let world_map_rotation = if state.is_facing_north { let world_map_rotation = if is_facing_north {
world_map.none world_map.none
} else { } else {
world_map.source_north world_map.source_north
@ -405,7 +406,7 @@ impl<'a> Widget for MiniMap<'a> {
// Indicator // Indicator
let ind_scale = 0.4; let ind_scale = 0.4;
let ind_rotation = if state.is_facing_north { let ind_rotation = if is_facing_north {
self.rot_imgs.indicator_mmap_small.target_north self.rot_imgs.indicator_mmap_small.target_north
} else { } else {
self.rot_imgs.indicator_mmap_small.none self.rot_imgs.indicator_mmap_small.none
@ -453,18 +454,18 @@ impl<'a> Widget for MiniMap<'a> {
.set(state.ids.mmap_frame, ui); .set(state.ids.mmap_frame, ui);
} }
if Button::image(if self.show.mini_map { if Button::image(if show_minimap {
self.imgs.mmap_open self.imgs.mmap_open
} else { } else {
self.imgs.mmap_closed self.imgs.mmap_closed
}) })
.w_h(18.0 * SCALE, 18.0 * SCALE) .w_h(18.0 * SCALE, 18.0 * SCALE)
.hover_image(if self.show.mini_map { .hover_image(if show_minimap {
self.imgs.mmap_open_hover self.imgs.mmap_open_hover
} else { } else {
self.imgs.mmap_closed_hover self.imgs.mmap_closed_hover
}) })
.press_image(if self.show.mini_map { .press_image(if show_minimap {
self.imgs.mmap_open_press self.imgs.mmap_open_press
} else { } else {
self.imgs.mmap_closed_press self.imgs.mmap_closed_press
@ -474,7 +475,7 @@ impl<'a> Widget for MiniMap<'a> {
.set(state.ids.mmap_button, ui) .set(state.ids.mmap_button, ui)
.was_clicked() .was_clicked()
{ {
return Some(Event::Toggle); return Some(Event::Show(!show_minimap));
} }
// TODO: Subregion name display // TODO: Subregion name display

View File

@ -419,6 +419,8 @@ pub enum Event {
AssignLeader(Uid), AssignLeader(Uid),
RemoveBuff(BuffKind), RemoveBuff(BuffKind),
UnlockSkill(Skill), UnlockSkill(Skill),
MinimapShow(bool),
MinimapFaceNorth(bool),
} }
// TODO: Are these the possible layouts we want? // TODO: Are these the possible layouts we want?
@ -495,7 +497,6 @@ pub struct Show {
esc_menu: bool, esc_menu: bool,
open_windows: Windows, open_windows: Windows,
map: bool, map: bool,
mini_map: bool,
ingame: bool, ingame: bool,
settings_tab: SettingsTab, settings_tab: SettingsTab,
skilltreetab: SelectedSkillTree, skilltreetab: SelectedSkillTree,
@ -569,8 +570,6 @@ impl Show {
fn toggle_map(&mut self) { self.map(!self.map) } fn toggle_map(&mut self) { self.map(!self.map) }
fn toggle_mini_map(&mut self) { self.mini_map = !self.mini_map; }
fn settings(&mut self, open: bool) { fn settings(&mut self, open: bool) {
if !self.esc_menu { if !self.esc_menu {
self.open_windows = if open { self.open_windows = if open {
@ -805,7 +804,6 @@ impl Hud {
diary: false, diary: false,
group: false, group: false,
group_menu: false, group_menu: false,
mini_map: true,
settings_tab: SettingsTab::Interface, settings_tab: SettingsTab::Interface,
skilltreetab: SelectedSkillTree::General, skilltreetab: SelectedSkillTree::General,
social_tab: SocialTab::Online, social_tab: SocialTab::Online,
@ -1992,17 +1990,22 @@ impl Hud {
// MiniMap // MiniMap
match MiniMap::new( match MiniMap::new(
&self.show,
client, client,
&self.imgs, &self.imgs,
&self.rot_imgs, &self.rot_imgs,
&self.world_map, &self.world_map,
&self.fonts, &self.fonts,
camera.get_orientation(), camera.get_orientation(),
&global_state,
) )
.set(self.ids.minimap, ui_widgets) .set(self.ids.minimap, ui_widgets)
{ {
Some(minimap::Event::Toggle) => self.show.toggle_mini_map(), Some(minimap::Event::Show(show)) => {
events.push(Event::MinimapShow(show));
},
Some(minimap::Event::FaceNorth(should_face_north)) => {
events.push(Event::MinimapFaceNorth(should_face_north))
},
None => {}, None => {},
} }

View File

@ -1273,6 +1273,14 @@ impl PlayState for SessionState {
HudEvent::AssignLeader(uid) => { HudEvent::AssignLeader(uid) => {
self.client.borrow_mut().assign_group_leader(uid); self.client.borrow_mut().assign_group_leader(uid);
}, },
HudEvent::MinimapShow(state) => {
global_state.settings.gameplay.minimap_show = state;
global_state.settings.save_to_file_warn();
},
HudEvent::MinimapFaceNorth(state) => {
global_state.settings.gameplay.minimap_face_north = state;
global_state.settings.save_to_file_warn();
},
} }
} }

View File

@ -524,6 +524,8 @@ pub struct GameplaySettings {
pub map_show_castles: bool, pub map_show_castles: bool,
pub loading_tips: bool, pub loading_tips: bool,
pub map_show_caves: bool, pub map_show_caves: bool,
pub minimap_show: bool,
pub minimap_face_north: bool,
} }
impl Default for GameplaySettings { impl Default for GameplaySettings {
@ -561,6 +563,8 @@ impl Default for GameplaySettings {
map_show_castles: true, map_show_castles: true,
loading_tips: true, loading_tips: true,
map_show_caves: true, map_show_caves: true,
minimap_show: true,
minimap_face_north: false,
} }
} }
} }