WIP map zooming and dragging

This commit is contained in:
Monty Marz 2020-11-17 04:17:03 +01:00 committed by Joshua Barretto
parent 13ebbbf76d
commit 80ee7e80cf
8 changed files with 86 additions and 33 deletions

View File

@ -0,0 +1,20 @@
#![enable(unwrap_newtypes)]
[
(
specifier: "world.tree.willow.1",
center: (18, 18, 8)
),
(
specifier: "world.tree.willow.2",
center: (17, 18, 7)
),
(
specifier: "world.tree.willow.3",
center: (15, 17, 8)
),
(
specifier: "world.tree.willow.4",
center: (15, 16, 8)
),
]

View File

@ -65,7 +65,7 @@ pub struct Map<'a> {
localized_strings: &'a Localization, localized_strings: &'a Localization,
global_state: &'a GlobalState, global_state: &'a GlobalState,
rot_imgs: &'a ImgsRot, rot_imgs: &'a ImgsRot,
tooltip_manager: &'a mut TooltipManager, tooltip_manager: &'a mut TooltipManager,
} }
impl<'a> Map<'a> { impl<'a> Map<'a> {
#[allow(clippy::too_many_arguments)] // TODO: Pending review in #587 #[allow(clippy::too_many_arguments)] // TODO: Pending review in #587
@ -79,7 +79,7 @@ impl<'a> Map<'a> {
pulse: f32, pulse: f32,
localized_strings: &'a Localization, localized_strings: &'a Localization,
global_state: &'a GlobalState, global_state: &'a GlobalState,
tooltip_manager: &'a mut TooltipManager, tooltip_manager: &'a mut TooltipManager,
) -> Self { ) -> Self {
Self { Self {
show: show, show: show,
@ -92,7 +92,7 @@ impl<'a> Map<'a> {
_pulse: pulse, _pulse: pulse,
localized_strings, localized_strings,
global_state, global_state,
tooltip_manager, tooltip_manager,
} }
} }
} }
@ -103,6 +103,7 @@ pub struct State {
pub enum Event { pub enum Event {
MapZoom(f64), MapZoom(f64),
MapDrag(Vec2<f64>),
ShowDifficulties, ShowDifficulties,
ShowTowns, ShowTowns,
ShowCastles, ShowCastles,
@ -190,19 +191,7 @@ impl<'a> Widget for Map<'a> {
.font_id(self.fonts.cyri.conrod_id) .font_id(self.fonts.cyri.conrod_id)
.font_size(self.fonts.cyri.scale(21)) .font_size(self.fonts.cyri.scale(21))
.color(TEXT_COLOR) .color(TEXT_COLOR)
.set(state.ids.qlog_title, ui); .set(state.ids.qlog_title, ui);
// X-Button
if Button::image(self.imgs.close_button)
.w_h(24.0, 25.0)
.hover_image(self.imgs.close_btn_hover)
.press_image(self.imgs.close_btn_press)
.top_right_with_margins_on(state.ids.frame, 0.0, 0.0)
.set(state.ids.close, ui)
.was_clicked()
{
events.push(Event::Close);
}
// Location Name // Location Name
/*match self.client.current_chunk() { /*match self.client.current_chunk() {
@ -245,13 +234,31 @@ impl<'a> Widget for Map<'a> {
let w_src = max_zoom / zoom; let w_src = max_zoom / zoom;
let h_src = max_zoom / zoom; let h_src = max_zoom / zoom;
// Handle dragging
let drag = self.global_state.settings.gameplay.map_drag;
let dragged: Vec2::<f64> = ui.widget_input(state.ids.grid).drags().left().map(|drag| Vec2::<f64>::from(drag.delta_xy)).sum();
let drag_new = drag + dragged;
events.push(Event::MapDrag(drag_new));
let rect_src = position::Rect::from_xy_dim( let rect_src = position::Rect::from_xy_dim(
[ [
player_pos.x as f64 / TerrainChunkSize::RECT_SIZE.x as f64, (player_pos.x as f64 / TerrainChunkSize::RECT_SIZE.x as f64) - drag.x,
(worldsize.y - player_pos.y as f64) / TerrainChunkSize::RECT_SIZE.y as f64, ((worldsize.y - player_pos.y as f64) / TerrainChunkSize::RECT_SIZE.y as f64) + drag.y,
], ],
[w_src, h_src], [w_src, h_src],
); );
// X-Button
if Button::image(self.imgs.close_button)
.w_h(24.0, 25.0)
.hover_image(self.imgs.close_btn_hover)
.press_image(self.imgs.close_btn_press)
.top_right_with_margins_on(state.ids.frame, 0.0, 0.0)
.set(state.ids.close, ui)
.was_clicked()
{
events.push(Event::Close);
events.push(Event::MapDrag(drag_new - drag_new));
}
Image::new(world_map.none) Image::new(world_map.none)
.mid_top_with_margin_on(state.ids.map_align, 10.0) .mid_top_with_margin_on(state.ids.map_align, 10.0)
.w_h(map_size.x, map_size.y) .w_h(map_size.x, map_size.y)
@ -274,9 +281,15 @@ impl<'a> Widget for Map<'a> {
.set(state.ids.zoom_slider, ui) .set(state.ids.zoom_slider, ui)
{ {
events.push(Event::MapZoom(new_val as f64)); events.push(Event::MapZoom(new_val as f64));
} }
// Icon settings // Handle zooming with the mousewheel
let zoom_lvl = self.global_state.settings.gameplay.map_zoom;
let scrolled: f64 = ui.widget_input(state.ids.grid).scrolls().map(|scroll| scroll.y).sum();
let new_zoom_lvl = (zoom_lvl + scrolled * 0.1).clamped(1.0, max_zoom);
events.push(Event::MapZoom(new_zoom_lvl as f64));
// Icon settings
// Alignment // Alignment
Rectangle::fill_with([tweak!(150.0), tweak!(200.0)], color::TRANSPARENT) Rectangle::fill_with([tweak!(150.0), tweak!(200.0)], color::TRANSPARENT)
.top_right_with_margins_on(state.ids.frame, tweak!(55.0), tweak!(10.0)) .top_right_with_margins_on(state.ids.frame, tweak!(55.0), tweak!(10.0))
@ -413,6 +426,7 @@ Text::new("Dungeons")
{ {
continue; continue;
} }
// TODO: Pass actual difficulty in here
let dif = (i as f64 / 100.0 * 6.0) as u8; let dif = (i as f64 / 100.0 * 6.0) as u8;
let title = match &site.kind { let title = match &site.kind {
SiteKind::Town => "Town", SiteKind::Town => "Town",
@ -427,8 +441,8 @@ Text::new("Dungeons")
}) })
.x_y_position_relative_to( .x_y_position_relative_to(
state.ids.grid, state.ids.grid,
position::Relative::Scalar(rpos.x as f64), position::Relative::Scalar(rpos.x as f64 + drag.x * zoom_lvl),
position::Relative::Scalar(rpos.y as f64), position::Relative::Scalar(rpos.y as f64 + drag.y * zoom_lvl),
) )
.w_h(20.0 * 1.2, 20.0 * 1.2) .w_h(20.0 * 1.2, 20.0 * 1.2)
.hover_image(match &site.kind { .hover_image(match &site.kind {
@ -450,8 +464,7 @@ Text::new("Dungeons")
.set(state.ids.mmap_site_icons[i], ui); .set(state.ids.mmap_site_icons[i], ui);
// Difficulty from 0-6 // Difficulty from 0-6
// 0 = towns and places without a difficulty level // 0 = towns and places without a difficulty level
// TODO: Pass actual difficulty in here
if self.show.map_difficulty { if self.show.map_difficulty {
let size = 1.8; // Size factor for difficulty indicators let size = 1.8; // Size factor for difficulty indicators
@ -507,12 +520,13 @@ Text::new("Dungeons")
let scale = 0.6; let scale = 0.6;
let arrow_sz = Vec2::new(32.0, 37.0) * scale; let arrow_sz = Vec2::new(32.0, 37.0) * scale;
Image::new(self.rot_imgs.indicator_mmap_small.target_north) Image::new(self.rot_imgs.indicator_mmap_small.target_north)
.middle_of(state.ids.grid) .top_left_with_margins_on(state.ids.grid, 407.0 + drag.y * zoom_lvl, 417.0 + drag.x * zoom_lvl)
.w_h(arrow_sz.x, arrow_sz.y) .w_h(arrow_sz.x, arrow_sz.y)
.color(Some(UI_HIGHLIGHT_0)) .color(Some(UI_HIGHLIGHT_0))
.floating(true) .floating(true)
.parent(ui.window) .parent(ui.window)
.set(state.ids.indicator, ui); .set(state.ids.indicator, ui);
events events
} }

View File

@ -325,6 +325,7 @@ pub enum Event {
ChangeGamma(f32), ChangeGamma(f32),
ChangeAmbiance(f32), ChangeAmbiance(f32),
MapZoom(f64), MapZoom(f64),
MapDrag(Vec2<f64>),
AdjustWindowSize([u16; 2]), AdjustWindowSize([u16; 2]),
ChangeFullscreenMode(FullScreenSettings), ChangeFullscreenMode(FullScreenSettings),
ToggleParticlesEnabled(bool), ToggleParticlesEnabled(bool),
@ -624,7 +625,7 @@ pub struct Hud {
force_chat_input: Option<String>, force_chat_input: Option<String>,
force_chat_cursor: Option<Index>, force_chat_cursor: Option<Index>,
tab_complete: Option<String>, tab_complete: Option<String>,
pulse: f32, pulse: f32,
velocity: f32, velocity: f32,
i18n: std::sync::Arc<Localization>, i18n: std::sync::Arc<Localization>,
slot_manager: slots::SlotManager, slot_manager: slots::SlotManager,
@ -728,7 +729,7 @@ impl Hud {
force_chat_input: None, force_chat_input: None,
force_chat_cursor: None, force_chat_cursor: None,
tab_complete: None, tab_complete: None,
pulse: 0.0, pulse: 0.0,
velocity: 0.0, velocity: 0.0,
i18n, i18n,
slot_manager, slot_manager,
@ -2260,7 +2261,7 @@ impl Hud {
self.pulse, self.pulse,
&self.i18n, &self.i18n,
&global_state, &global_state,
tooltip_manager, tooltip_manager,
) )
.set(self.ids.map, ui_widgets) .set(self.ids.map, ui_widgets)
{ {
@ -2268,7 +2269,7 @@ impl Hud {
map::Event::Close => { map::Event::Close => {
self.show.map(false); self.show.map(false);
self.show.want_grab = true; self.show.want_grab = true;
self.force_ungrab = false; self.force_ungrab = false;
}, },
map::Event::ShowDifficulties => { map::Event::ShowDifficulties => {
self.show.map_difficulty = !self.show.map_difficulty self.show.map_difficulty = !self.show.map_difficulty
@ -2285,6 +2286,9 @@ impl Hud {
map::Event::MapZoom(map_zoom) => { map::Event::MapZoom(map_zoom) => {
events.push(Event::MapZoom(map_zoom)); events.push(Event::MapZoom(map_zoom));
}, },
map::Event::MapDrag(map_drag) => {
events.push(Event::MapDrag(map_drag));
},
} }
} }
} }

View File

@ -964,6 +964,10 @@ impl PlayState for SessionState {
global_state.settings.gameplay.map_zoom = map_zoom; global_state.settings.gameplay.map_zoom = map_zoom;
global_state.settings.save_to_file_warn(); global_state.settings.save_to_file_warn();
}, },
HudEvent::MapDrag(map_drag) => {
global_state.settings.gameplay.map_drag = map_drag;
global_state.settings.save_to_file_warn();
},
HudEvent::ChangeGamma(new_gamma) => { HudEvent::ChangeGamma(new_gamma) => {
global_state.settings.graphics.gamma = new_gamma; global_state.settings.graphics.gamma = new_gamma;
global_state.settings.save_to_file_warn(); global_state.settings.save_to_file_warn();

View File

@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize};
use std::{fs, path::PathBuf}; use std::{fs, path::PathBuf};
use tracing::warn; use tracing::warn;
use winit::event::{MouseButton, VirtualKeyCode}; use winit::event::{MouseButton, VirtualKeyCode};
use vek::*;
// ControlSetting-like struct used by Serde, to handle not serializing/building // ControlSetting-like struct used by Serde, to handle not serializing/building
// post-deserializing the inverse_keybindings hashmap // post-deserializing the inverse_keybindings hashmap
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
@ -516,6 +516,7 @@ pub struct GameplaySettings {
pub auto_walk_behavior: PressBehavior, pub auto_walk_behavior: PressBehavior,
pub stop_auto_walk_on_input: bool, pub stop_auto_walk_on_input: bool,
pub map_zoom: f64, pub map_zoom: f64,
pub map_drag: Vec2<f64>,
pub loading_tips: bool, pub loading_tips: bool,
} }
@ -547,6 +548,7 @@ impl Default for GameplaySettings {
auto_walk_behavior: PressBehavior::Toggle, auto_walk_behavior: PressBehavior::Toggle,
stop_auto_walk_on_input: true, stop_auto_walk_on_input: true,
map_zoom: 4.0, map_zoom: 4.0,
map_drag: Vec2 { x: 0.0, y: 0.0},
loading_tips: true, loading_tips: true,
} }
} }

View File

@ -6,4 +6,5 @@ pub enum ForestKind {
Pine, Pine,
Birch, Birch,
Mangrove, Mangrove,
Swamp,
} }

View File

@ -14,7 +14,7 @@ use std::{collections::HashMap, f32, sync::Arc};
use vek::*; use vek::*;
lazy_static! { lazy_static! {
pub static ref OAKS: Vec<Arc<Structure>> = Structure::load_group("oaks"); pub static ref OAKS: Vec<Arc<Structure>> = Structure::load_group("oaks");
pub static ref OAK_STUMPS: Vec<Arc<Structure>> = Structure::load_group("oak_stumps"); pub static ref OAK_STUMPS: Vec<Arc<Structure>> = Structure::load_group("oak_stumps");
pub static ref PINES: Vec<Arc<Structure>> = Structure::load_group("pines"); pub static ref PINES: Vec<Arc<Structure>> = Structure::load_group("pines");
pub static ref PALMS: Vec<Arc<Structure>> = Structure::load_group("palms"); pub static ref PALMS: Vec<Arc<Structure>> = Structure::load_group("palms");
@ -24,6 +24,7 @@ lazy_static! {
pub static ref MANGROVE_TREES: Vec<Arc<Structure>> = Structure::load_group("mangrove_trees"); pub static ref MANGROVE_TREES: Vec<Arc<Structure>> = Structure::load_group("mangrove_trees");
pub static ref QUIRKY: Vec<Arc<Structure>> = Structure::load_group("quirky"); pub static ref QUIRKY: Vec<Arc<Structure>> = Structure::load_group("quirky");
pub static ref QUIRKY_DRY: Vec<Arc<Structure>> = Structure::load_group("quirky_dry"); pub static ref QUIRKY_DRY: Vec<Arc<Structure>> = Structure::load_group("quirky_dry");
pub static ref SWAMP_TREES: Vec<Arc<Structure>> = Structure::load_group("swamp_trees");
} }
static MODEL_RAND: RandomPerm = RandomPerm::new(0xDB21C052); static MODEL_RAND: RandomPerm = RandomPerm::new(0xDB21C052);
@ -86,6 +87,7 @@ pub fn apply_trees_to(canvas: &mut Canvas) {
ForestKind::Pine => &PINES, ForestKind::Pine => &PINES,
ForestKind::Birch => &BIRCHES, ForestKind::Birch => &BIRCHES,
ForestKind::Mangrove => &MANGROVE_TREES, ForestKind::Mangrove => &MANGROVE_TREES,
ForestKind::Swamp => &SWAMP_TREES,
} }
}; };
Arc::clone( Arc::clone(

View File

@ -2254,6 +2254,12 @@ impl SimChunk {
(CONFIG.temperate_temp, 1.5), (CONFIG.temperate_temp, 1.5),
(0.0, 1.0), (0.0, 1.0),
), ),
(
ForestKind::Swamp,
(CONFIG.desert_hum, 1.5),
(CONFIG.temperate_temp, 1.5),
(0.0, 1.0),
),
]; ];
candidates candidates