Voxygen: Allow zoom on minimap with kbd

This commit is contained in:
João Capucho 2021-04-19 19:51:53 +01:00
parent 7589331785
commit 7a9876760b
No known key found for this signature in database
GPG Key ID: 1AD5CE7CCAEBDA21
4 changed files with 38 additions and 36 deletions

View File

@ -81,8 +81,6 @@ impl<'a> MiniMap<'a> {
pub struct State {
ids: Ids,
zoom: f64,
}
pub enum Event {
@ -90,22 +88,13 @@ pub enum Event {
}
impl<'a> Widget for MiniMap<'a> {
type Event = Option<Event>;
type Event = Vec<Event>;
type State = State;
type Style = ();
fn init_state(&self, id_gen: widget::id::Generator) -> Self::State {
State {
ids: Ids::new(id_gen),
zoom: {
let min_world_dim = self.world_map.1.reduce_partial_min() as f64;
min_world_dim.min(
min_world_dim
* (TerrainChunkSize::RECT_SIZE.reduce_partial_max() as f64 / 32.0)
* (16.0 / 1024.0),
)
},
}
}
@ -113,8 +102,10 @@ impl<'a> Widget for MiniMap<'a> {
fn style(&self) -> Self::Style { () }
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
let mut events = Vec::new();
let widget::UpdateArgs { state, ui, .. } = args;
let zoom = state.zoom;
let mut zoom = self.global_state.settings.interface.minimap_zoom;
const SCALE: f64 = 1.5; // TODO Make this a setting
let show_minimap = self.global_state.settings.interface.minimap_show;
let is_facing_north = self.global_state.settings.interface.minimap_face_north;
@ -185,8 +176,7 @@ impl<'a> Widget for MiniMap<'a> {
&& can_zoom_out
{
// Set the image dimensions here, rather than recomputing each time.
let zoom = min_zoom.max(zoom / ZOOM_FACTOR);
state.update(|s| s.zoom = zoom);
zoom = min_zoom.max(zoom / ZOOM_FACTOR);
// set_image_dims(zoom);
}
if Button::image(self.imgs.mmap_plus)
@ -200,8 +190,7 @@ impl<'a> Widget for MiniMap<'a> {
.was_clicked()
&& can_zoom_in
{
let zoom = max_zoom.min(zoom * ZOOM_FACTOR);
state.update(|s| s.zoom = zoom);
zoom = min_zoom.max(zoom * ZOOM_FACTOR);
// set_image_dims(zoom);
}
@ -227,11 +216,10 @@ impl<'a> Widget for MiniMap<'a> {
.set(state.ids.mmap_north_button, ui)
.was_clicked()
{
return Some(Event::SettingsChange(MinimapFaceNorth(!is_facing_north)));
events.push(Event::SettingsChange(MinimapFaceNorth(!is_facing_north)));
}
// Reload zoom in case it changed.
let zoom = state.zoom;
events.push(Event::SettingsChange(MinimapZoom(zoom)));
// Coordinates
let player_pos = self
@ -502,7 +490,7 @@ impl<'a> Widget for MiniMap<'a> {
.set(state.ids.mmap_button, ui)
.was_clicked()
{
return Some(Event::SettingsChange(MinimapShow(!show_minimap)));
events.push(Event::SettingsChange(MinimapShow(!show_minimap)));
}
// TODO: Subregion name display
@ -534,6 +522,6 @@ impl<'a> Widget for MiniMap<'a> {
.set(state.ids.mmap_location, ui),
}
None
events
}
}

View File

@ -2182,7 +2182,7 @@ impl Hud {
.set(self.ids.popup, ui_widgets);
// MiniMap
match MiniMap::new(
for event in MiniMap::new(
client,
&self.imgs,
&self.rot_imgs,
@ -2193,10 +2193,11 @@ impl Hud {
)
.set(self.ids.minimap, ui_widgets)
{
Some(minimap::Event::SettingsChange(interface_change)) => {
match event {
minimap::Event::SettingsChange(interface_change) => {
events.push(Event::SettingsChange(interface_change.into()));
},
None => {},
}
}
if let Some(prompt_dialog_settings) = &self.show.prompt_dialog {
@ -3095,18 +3096,25 @@ impl Hud {
}
fn handle_map_zoom(
change: f64,
factor: f64,
world_size: Vec2<u32>,
show: &Show,
global_state: &mut GlobalState,
) -> bool {
let max_zoom = world_size.reduce_partial_max() as f64;
let new_zoom_lvl =
(global_state.settings.interface.map_zoom + change).clamped(1.25, max_zoom / 64.0);
if show.map {
let new_zoom_lvl = (global_state.settings.interface.map_zoom * factor)
.clamped(1.25, max_zoom / 64.0);
global_state.settings.interface.map_zoom = new_zoom_lvl;
} else if global_state.settings.interface.minimap_show {
let new_zoom_lvl = global_state.settings.interface.minimap_zoom * factor;
true
global_state.settings.interface.minimap_zoom = new_zoom_lvl;
}
show.map && global_state.settings.interface.minimap_show
}
let cursor_grabbed = global_state.window.is_cursor_grabbed();
@ -3235,11 +3243,11 @@ impl Hud {
self.show.ingame = !self.show.ingame;
true
},
GameInput::MapZoomIn if state && self.show.map => {
handle_map_zoom(1.0, self.world_map.1, global_state)
GameInput::MapZoomIn if state => {
handle_map_zoom(2.0, self.world_map.1, &self.show, global_state)
},
GameInput::MapZoomOut if state && self.show.map => {
handle_map_zoom(-1.0, self.world_map.1, global_state)
GameInput::MapZoomOut if state => {
handle_map_zoom(0.5, self.world_map.1, &self.show, global_state)
},
// Skillbar
input => {

View File

@ -99,6 +99,7 @@ pub enum Interface {
//Minimap
MinimapShow(bool),
MinimapFaceNorth(bool),
MinimapZoom(f64),
//Map settings
MapZoom(f64),
MapDrag(Vec2<f64>),
@ -413,6 +414,9 @@ impl SettingsChange {
Interface::MinimapFaceNorth(state) => {
settings.interface.minimap_face_north = state;
},
Interface::MinimapZoom(minimap_zoom) => {
settings.interface.minimap_zoom = minimap_zoom;
},
Interface::MapZoom(map_zoom) => {
settings.interface.map_zoom = map_zoom;
},

View File

@ -37,6 +37,7 @@ pub struct InterfaceSettings {
pub map_show_trees: bool,
pub minimap_show: bool,
pub minimap_face_north: bool,
pub minimap_zoom: f64,
}
impl Default for InterfaceSettings {
@ -70,6 +71,7 @@ impl Default for InterfaceSettings {
map_show_trees: true,
minimap_show: true,
minimap_face_north: false,
minimap_zoom: 10.0,
}
}
}