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 ef03137c65
commit 99b3a4465a
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

@ -103,6 +103,7 @@ pub struct State {
pub enum Event {
MapZoom(f64),
MapDrag(Vec2<f64>),
ShowDifficulties,
ShowTowns,
ShowCastles,
@ -192,18 +193,6 @@ impl<'a> Widget for Map<'a> {
.color(TEXT_COLOR)
.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
/*match self.client.current_chunk() {
Some(chunk) => Text::new(chunk.meta().name())
@ -245,13 +234,31 @@ impl<'a> Widget for Map<'a> {
let w_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(
[
player_pos.x as f64 / TerrainChunkSize::RECT_SIZE.x as f64,
(worldsize.y - player_pos.y as f64) / TerrainChunkSize::RECT_SIZE.y 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) + drag.y,
],
[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)
.mid_top_with_margin_on(state.ids.map_align, 10.0)
.w_h(map_size.x, map_size.y)
@ -275,8 +282,14 @@ impl<'a> Widget for Map<'a> {
{
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
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))
@ -413,6 +426,7 @@ Text::new("Dungeons")
{
continue;
}
// TODO: Pass actual difficulty in here
let dif = (i as f64 / 100.0 * 6.0) as u8;
let title = match &site.kind {
SiteKind::Town => "Town",
@ -427,8 +441,8 @@ Text::new("Dungeons")
})
.x_y_position_relative_to(
state.ids.grid,
position::Relative::Scalar(rpos.x as f64),
position::Relative::Scalar(rpos.y as f64),
position::Relative::Scalar(rpos.x as f64 + drag.x * zoom_lvl),
position::Relative::Scalar(rpos.y as f64 + drag.y * zoom_lvl),
)
.w_h(20.0 * 1.2, 20.0 * 1.2)
.hover_image(match &site.kind {
@ -451,7 +465,6 @@ Text::new("Dungeons")
// Difficulty from 0-6
// 0 = towns and places without a difficulty level
// TODO: Pass actual difficulty in here
if self.show.map_difficulty {
let size = 1.8; // Size factor for difficulty indicators
@ -507,13 +520,14 @@ Text::new("Dungeons")
let scale = 0.6;
let arrow_sz = Vec2::new(32.0, 37.0) * scale;
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)
.color(Some(UI_HIGHLIGHT_0))
.floating(true)
.parent(ui.window)
.set(state.ids.indicator, ui);
events
}
}

View File

@ -325,6 +325,7 @@ pub enum Event {
ChangeGamma(f32),
ChangeAmbiance(f32),
MapZoom(f64),
MapDrag(Vec2<f64>),
AdjustWindowSize([u16; 2]),
ChangeFullscreenMode(FullScreenSettings),
ToggleParticlesEnabled(bool),
@ -2285,6 +2286,9 @@ impl Hud {
map::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.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) => {
global_state.settings.graphics.gamma = new_gamma;
global_state.settings.save_to_file_warn();

View File

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

View File

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

View File

@ -24,6 +24,7 @@ lazy_static! {
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_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);
@ -86,6 +87,7 @@ pub fn apply_trees_to(canvas: &mut Canvas) {
ForestKind::Pine => &PINES,
ForestKind::Birch => &BIRCHES,
ForestKind::Mangrove => &MANGROVE_TREES,
ForestKind::Swamp => &SWAMP_TREES,
}
};
Arc::clone(

View File

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