mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'capucho/map-kb-zoom' into 'master'
Add keybindings for map/minimap zoom See merge request veloren/veloren!2161
This commit is contained in:
commit
c5caec4921
@ -62,6 +62,8 @@
|
|||||||
"gameinput.sneak": "Sneak",
|
"gameinput.sneak": "Sneak",
|
||||||
"gameinput.swimdown": "Swim downwards",
|
"gameinput.swimdown": "Swim downwards",
|
||||||
"gameinput.swimup": "Swim upwards",
|
"gameinput.swimup": "Swim upwards",
|
||||||
|
"gameinput.mapzoomin": "Increase map zoom",
|
||||||
|
"gameinput.mapzoomout": "Decrease map zoom",
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,8 +81,6 @@ impl<'a> MiniMap<'a> {
|
|||||||
|
|
||||||
pub struct State {
|
pub struct State {
|
||||||
ids: Ids,
|
ids: Ids,
|
||||||
|
|
||||||
zoom: f64,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
@ -90,22 +88,13 @@ pub enum Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Widget for MiniMap<'a> {
|
impl<'a> Widget for MiniMap<'a> {
|
||||||
type Event = Option<Event>;
|
type Event = Vec<Event>;
|
||||||
type State = State;
|
type State = State;
|
||||||
type Style = ();
|
type Style = ();
|
||||||
|
|
||||||
fn init_state(&self, id_gen: widget::id::Generator) -> Self::State {
|
fn init_state(&self, id_gen: widget::id::Generator) -> Self::State {
|
||||||
State {
|
State {
|
||||||
ids: Ids::new(id_gen),
|
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 style(&self) -> Self::Style { () }
|
||||||
|
|
||||||
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
|
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
|
||||||
|
let mut events = Vec::new();
|
||||||
|
|
||||||
let widget::UpdateArgs { state, ui, .. } = args;
|
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
|
const SCALE: f64 = 1.5; // TODO Make this a setting
|
||||||
let show_minimap = self.global_state.settings.interface.minimap_show;
|
let show_minimap = self.global_state.settings.interface.minimap_show;
|
||||||
let is_facing_north = self.global_state.settings.interface.minimap_face_north;
|
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
|
&& can_zoom_out
|
||||||
{
|
{
|
||||||
// Set the image dimensions here, rather than recomputing each time.
|
// Set the image dimensions here, rather than recomputing each time.
|
||||||
let zoom = min_zoom.max(zoom / ZOOM_FACTOR);
|
zoom = min_zoom.max(zoom / ZOOM_FACTOR);
|
||||||
state.update(|s| s.zoom = zoom);
|
|
||||||
// set_image_dims(zoom);
|
// set_image_dims(zoom);
|
||||||
}
|
}
|
||||||
if Button::image(self.imgs.mmap_plus)
|
if Button::image(self.imgs.mmap_plus)
|
||||||
@ -200,8 +190,7 @@ impl<'a> Widget for MiniMap<'a> {
|
|||||||
.was_clicked()
|
.was_clicked()
|
||||||
&& can_zoom_in
|
&& can_zoom_in
|
||||||
{
|
{
|
||||||
let zoom = max_zoom.min(zoom * ZOOM_FACTOR);
|
zoom = min_zoom.max(zoom * ZOOM_FACTOR);
|
||||||
state.update(|s| s.zoom = zoom);
|
|
||||||
// set_image_dims(zoom);
|
// set_image_dims(zoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,11 +216,10 @@ impl<'a> Widget for MiniMap<'a> {
|
|||||||
.set(state.ids.mmap_north_button, ui)
|
.set(state.ids.mmap_north_button, ui)
|
||||||
.was_clicked()
|
.was_clicked()
|
||||||
{
|
{
|
||||||
return Some(Event::SettingsChange(MinimapFaceNorth(!is_facing_north)));
|
events.push(Event::SettingsChange(MinimapFaceNorth(!is_facing_north)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reload zoom in case it changed.
|
events.push(Event::SettingsChange(MinimapZoom(zoom)));
|
||||||
let zoom = state.zoom;
|
|
||||||
|
|
||||||
// Coordinates
|
// Coordinates
|
||||||
let player_pos = self
|
let player_pos = self
|
||||||
@ -502,7 +490,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::SettingsChange(MinimapShow(!show_minimap)));
|
events.push(Event::SettingsChange(MinimapShow(!show_minimap)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Subregion name display
|
// TODO: Subregion name display
|
||||||
@ -534,6 +522,6 @@ impl<'a> Widget for MiniMap<'a> {
|
|||||||
.set(state.ids.mmap_location, ui),
|
.set(state.ids.mmap_location, ui),
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
events
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2182,7 +2182,7 @@ impl Hud {
|
|||||||
.set(self.ids.popup, ui_widgets);
|
.set(self.ids.popup, ui_widgets);
|
||||||
|
|
||||||
// MiniMap
|
// MiniMap
|
||||||
match MiniMap::new(
|
for event in MiniMap::new(
|
||||||
client,
|
client,
|
||||||
&self.imgs,
|
&self.imgs,
|
||||||
&self.rot_imgs,
|
&self.rot_imgs,
|
||||||
@ -2193,10 +2193,11 @@ impl Hud {
|
|||||||
)
|
)
|
||||||
.set(self.ids.minimap, ui_widgets)
|
.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()));
|
events.push(Event::SettingsChange(interface_change.into()));
|
||||||
},
|
},
|
||||||
None => {},
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(prompt_dialog_settings) = &self.show.prompt_dialog {
|
if let Some(prompt_dialog_settings) = &self.show.prompt_dialog {
|
||||||
@ -3094,6 +3095,28 @@ impl Hud {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn handle_map_zoom(
|
||||||
|
factor: f64,
|
||||||
|
world_size: Vec2<u32>,
|
||||||
|
show: &Show,
|
||||||
|
global_state: &mut GlobalState,
|
||||||
|
) -> bool {
|
||||||
|
let max_zoom = world_size.reduce_partial_max() as f64;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
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();
|
let cursor_grabbed = global_state.window.is_cursor_grabbed();
|
||||||
let handled = match event {
|
let handled = match event {
|
||||||
WinEvent::Ui(event) => {
|
WinEvent::Ui(event) => {
|
||||||
@ -3220,6 +3243,12 @@ impl Hud {
|
|||||||
self.show.ingame = !self.show.ingame;
|
self.show.ingame = !self.show.ingame;
|
||||||
true
|
true
|
||||||
},
|
},
|
||||||
|
GameInput::MapZoomIn if state => {
|
||||||
|
handle_map_zoom(2.0, self.world_map.1, &self.show, global_state)
|
||||||
|
},
|
||||||
|
GameInput::MapZoomOut if state => {
|
||||||
|
handle_map_zoom(0.5, self.world_map.1, &self.show, global_state)
|
||||||
|
},
|
||||||
// Skillbar
|
// Skillbar
|
||||||
input => {
|
input => {
|
||||||
if let Some(slot) = try_hotbar_slot_from_input(input) {
|
if let Some(slot) = try_hotbar_slot_from_input(input) {
|
||||||
|
@ -99,6 +99,7 @@ pub enum Interface {
|
|||||||
//Minimap
|
//Minimap
|
||||||
MinimapShow(bool),
|
MinimapShow(bool),
|
||||||
MinimapFaceNorth(bool),
|
MinimapFaceNorth(bool),
|
||||||
|
MinimapZoom(f64),
|
||||||
//Map settings
|
//Map settings
|
||||||
MapZoom(f64),
|
MapZoom(f64),
|
||||||
MapDrag(Vec2<f64>),
|
MapDrag(Vec2<f64>),
|
||||||
@ -413,6 +414,9 @@ impl SettingsChange {
|
|||||||
Interface::MinimapFaceNorth(state) => {
|
Interface::MinimapFaceNorth(state) => {
|
||||||
settings.interface.minimap_face_north = state;
|
settings.interface.minimap_face_north = state;
|
||||||
},
|
},
|
||||||
|
Interface::MinimapZoom(minimap_zoom) => {
|
||||||
|
settings.interface.minimap_zoom = minimap_zoom;
|
||||||
|
},
|
||||||
Interface::MapZoom(map_zoom) => {
|
Interface::MapZoom(map_zoom) => {
|
||||||
settings.interface.map_zoom = map_zoom;
|
settings.interface.map_zoom = map_zoom;
|
||||||
},
|
},
|
||||||
|
@ -166,6 +166,8 @@ impl ControlSettings {
|
|||||||
GameInput::Select => KeyMouse::Key(VirtualKeyCode::Y),
|
GameInput::Select => KeyMouse::Key(VirtualKeyCode::Y),
|
||||||
GameInput::AcceptGroupInvite => KeyMouse::Key(VirtualKeyCode::U),
|
GameInput::AcceptGroupInvite => KeyMouse::Key(VirtualKeyCode::U),
|
||||||
GameInput::DeclineGroupInvite => KeyMouse::Key(VirtualKeyCode::I),
|
GameInput::DeclineGroupInvite => KeyMouse::Key(VirtualKeyCode::I),
|
||||||
|
GameInput::MapZoomIn => KeyMouse::Key(VirtualKeyCode::Plus),
|
||||||
|
GameInput::MapZoomOut => KeyMouse::Key(VirtualKeyCode::Minus),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@ pub struct InterfaceSettings {
|
|||||||
pub map_show_trees: bool,
|
pub map_show_trees: bool,
|
||||||
pub minimap_show: bool,
|
pub minimap_show: bool,
|
||||||
pub minimap_face_north: bool,
|
pub minimap_face_north: bool,
|
||||||
|
pub minimap_zoom: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for InterfaceSettings {
|
impl Default for InterfaceSettings {
|
||||||
@ -70,6 +71,7 @@ impl Default for InterfaceSettings {
|
|||||||
map_show_trees: true,
|
map_show_trees: true,
|
||||||
minimap_show: true,
|
minimap_show: true,
|
||||||
minimap_face_north: false,
|
minimap_face_north: false,
|
||||||
|
minimap_zoom: 10.0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,6 +76,8 @@ pub enum GameInput {
|
|||||||
Select,
|
Select,
|
||||||
AcceptGroupInvite,
|
AcceptGroupInvite,
|
||||||
DeclineGroupInvite,
|
DeclineGroupInvite,
|
||||||
|
MapZoomIn,
|
||||||
|
MapZoomOut,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GameInput {
|
impl GameInput {
|
||||||
@ -138,6 +140,8 @@ impl GameInput {
|
|||||||
GameInput::Select => "gameinput.select",
|
GameInput::Select => "gameinput.select",
|
||||||
GameInput::AcceptGroupInvite => "gameinput.acceptgroupinvite",
|
GameInput::AcceptGroupInvite => "gameinput.acceptgroupinvite",
|
||||||
GameInput::DeclineGroupInvite => "gameinput.declinegroupinvite",
|
GameInput::DeclineGroupInvite => "gameinput.declinegroupinvite",
|
||||||
|
GameInput::MapZoomIn => "gameinput.mapzoomin",
|
||||||
|
GameInput::MapZoomOut => "gameinput.mapzoomout",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,6 +204,8 @@ impl GameInput {
|
|||||||
GameInput::Select,
|
GameInput::Select,
|
||||||
GameInput::AcceptGroupInvite,
|
GameInput::AcceptGroupInvite,
|
||||||
GameInput::DeclineGroupInvite,
|
GameInput::DeclineGroupInvite,
|
||||||
|
GameInput::MapZoomIn,
|
||||||
|
GameInput::MapZoomOut,
|
||||||
]
|
]
|
||||||
.iter()
|
.iter()
|
||||||
.copied()
|
.copied()
|
||||||
|
Loading…
Reference in New Issue
Block a user