Add topographic option to map

This commit is contained in:
James Melkonian 2021-04-05 22:15:42 -07:00
parent f2ebbb7f7f
commit 16871208f2
13 changed files with 272 additions and 134 deletions

View File

@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Attacks now emit sound effects from the target on hit.
- Crafting menu tabs
- Auto camera setting, making the game easier to play with one hand
- Topographic map option
### Changed

View File

@ -31,7 +31,7 @@ debug = false
codegen-units = 8
lto = false
# TEMP false to avoid fingerprints bug
incremental = true
incremental = false
# All dependencies (but not this crate itself)
[profile.dev.package."*"]
opt-level = 3

BIN
assets/voxygen/element/map/topographic.png (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -6,6 +6,7 @@
// Map and Questlog
"hud.map.map_title": "Map",
"hud.map.qlog_title": "Quests",
"hud.map.topo_map": "Topographic",
"hud.map.difficulty": "Difficulty",
"hud.map.towns": "Towns",
"hud.map.castles": "Castles",

View File

@ -34,7 +34,10 @@ use common::{
outcome::Outcome,
recipe::RecipeBook,
resources::{DeltaTime, PlayerEntity, TimeOfDay},
terrain::{block::Block, map::MapConfig, neighbors, BiomeKind, SitesKind, TerrainChunk, TerrainChunkSize},
terrain::{
block::Block, map::MapConfig, neighbors, BiomeKind, SitesKind, TerrainChunk,
TerrainChunkSize,
},
trade::{PendingTrade, SitePrices, TradeAction, TradeId, TradeResult},
uid::{Uid, UidAllocator},
vol::RectVolSize,
@ -326,8 +329,9 @@ impl Client {
let horizons = [unzip_horizons(&west), unzip_horizons(&east)];
// Redraw map (with shadows this time).
let mut world_map_political = vec![0u32; rgba.size().product() as usize];
let mut world_map_rgba = vec![0u32; rgba.size().product() as usize];
let mut world_map_political = vec![0u32; rgba.size().product() as usize];
let mut world_map_rgba_half_alpha = vec![0u32; rgba.size().product() as usize];
let mut world_map_topo = vec![0u32; rgba.size().product() as usize];
let mut map_config = common::terrain::map::MapConfig::orthographic(
map_size_lg,
@ -341,7 +345,15 @@ impl Client {
&& pos.y < map_size.y as i32
};
ping_stream.send(PingMsg::Ping)?;
fn sample_pos(map_config: &MapConfig, pos: Vec2<i32>, alt: &Grid<u32>, rgba: &Grid<u32>, map_size: &Vec2<u16>, map_size_lg: &common::terrain::MapSizeLg, max_height: f32) -> common::terrain::map::MapSample {
fn sample_pos(
map_config: &MapConfig,
pos: Vec2<i32>,
alt: &Grid<u32>,
rgba: &Grid<u32>,
map_size: &Vec2<u16>,
map_size_lg: &common::terrain::MapSizeLg,
max_height: f32,
) -> common::terrain::map::MapSample {
let rescale_height = |h: f32| h / max_height;
let scale_height_big = |h: u32| (h >> 3) as f32 / 8191.0 * max_height;
let bounds_check = |pos: Vec2<i32>| {
@ -355,6 +367,7 @@ impl Client {
is_height_map,
is_political,
is_roads,
rgba_alpha,
..
} = *map_config;
let mut is_contour_line = false;
@ -442,8 +455,9 @@ impl Client {
} else if is_contours && is_contour_line {
Rgba::new(0.15, 0.15, 0.15, 0.8)
} else {
Rgba::new(rgba.r, rgba.g, rgba.b, 0.5)
}.map(|e| (e * 255.0) as u8);
Rgba::new(rgba.r, rgba.g, rgba.b, rgba_alpha)
}
.map(|e| (e * 255.0) as u8);
common::terrain::map::MapSample {
rgba,
alt,
@ -453,9 +467,45 @@ impl Client {
}
}
map_config.is_shaded = true;
map_config.rgba_alpha = 1.0;
map_config.generate(
|pos| {
sample_pos(
&map_config,
pos,
&alt,
&rgba,
&map_size,
&map_size_lg,
max_height,
)
},
|wpos| {
let pos = wpos.map2(TerrainChunkSize::RECT_SIZE, |e, f| e / f as i32);
rescale_height(if bounds_check(pos) {
scale_height_big(alt[pos])
} else {
0.0
})
},
|pos, (r, g, b, a)| {
world_map_rgba[pos.y * map_size.x as usize + pos.x] =
u32::from_le_bytes([r, g, b, a]);
},
);
map_config.is_political = true;
map_config.generate(
|pos| sample_pos(&map_config, pos, &alt, &rgba, &map_size, &map_size_lg, max_height),
|pos| {
sample_pos(
&map_config,
pos,
&alt,
&rgba,
&map_size,
&map_size_lg,
max_height,
)
},
|wpos| {
let pos = wpos.map2(TerrainChunkSize::RECT_SIZE, |e, f| e / f as i32);
rescale_height(if bounds_check(pos) {
@ -471,9 +521,20 @@ impl Client {
);
map_config.is_shaded = false;
map_config.rgba_alpha = 0.5;
map_config.is_political = false;
map_config.generate(
|pos| sample_pos(&map_config, pos, &alt, &rgba, &map_size, &map_size_lg, max_height),
|pos| {
sample_pos(
&map_config,
pos,
&alt,
&rgba,
&map_size,
&map_size_lg,
max_height,
)
},
|wpos| {
let pos = wpos.map2(TerrainChunkSize::RECT_SIZE, |e, f| e / f as i32);
rescale_height(if bounds_check(pos) {
@ -483,7 +544,7 @@ impl Client {
})
},
|pos, (r, g, b, a)| {
world_map_rgba[pos.y * map_size.x as usize + pos.x] =
world_map_rgba_half_alpha[pos.y * map_size.x as usize + pos.x] =
u32::from_le_bytes([r, g, b, a]);
},
);
@ -491,7 +552,17 @@ impl Client {
map_config.is_contours = true;
map_config.is_roads = true;
map_config.generate(
|pos| sample_pos(&map_config, pos, &alt, &rgba, &map_size, &map_size_lg, max_height),
|pos| {
sample_pos(
&map_config,
pos,
&alt,
&rgba,
&map_size,
&map_size_lg,
max_height,
)
},
|wpos| {
let pos = wpos.map2(TerrainChunkSize::RECT_SIZE, |e, f| e / f as i32);
rescale_height(if bounds_check(pos) {
@ -525,9 +596,15 @@ impl Client {
let lod_base = rgba;
let lod_alt = alt;
let world_map_rgba_img = make_raw(&world_map_rgba)?;
let world_map_topo_img = make_raw(&world_map_topo)?;
let world_map_political_img = make_raw(&world_map_political)?;
let world_map_layers = vec!(world_map_political_img, world_map_rgba_img, world_map_topo_img);
let world_map_rgba_half_alpha_img = make_raw(&world_map_rgba_half_alpha)?;
let world_map_topo_img = make_raw(&world_map_topo)?;
let world_map_layers = vec![
world_map_rgba_img,
world_map_political_img,
world_map_rgba_half_alpha_img,
world_map_topo_img,
];
let horizons = (west.0, west.1, east.0, east.1)
.into_par_iter()
.map(|(wa, wh, ea, eh)| u32::from_le_bytes([wa, wh, ea, eh]))

View File

@ -334,6 +334,10 @@ pub struct MapConfig<'a> {
///
/// Defaults to false
pub is_roads: bool,
/// Alpha value for rgba. Handled by the sample_pos closure
///
/// Defaults to 1.0
pub rgba_alpha: f64,
}
pub const QUADRANTS: usize = 4;
@ -418,6 +422,7 @@ impl<'a> MapConfig<'a> {
is_height_map: false,
is_political: false,
is_roads: false,
rgba_alpha: 1.0,
}
}
@ -736,4 +741,3 @@ impl<'a> MapConfig<'a> {
}
}
}

View File

@ -336,6 +336,7 @@ image_ids! {
crosshair_bg_pressed: "voxygen.element.misc_bg.crosshair_bg_pressed",
// Map
map_topo: "voxygen.element.map.topographic",
map_bg: "voxygen.element.misc_bg.map_bg",
map_frame: "voxygen.element.misc_bg.map_frame",
map_frame_art: "voxygen.element.misc_bg.map_frame_art",

View File

@ -40,6 +40,9 @@ widget_ids! {
member_indicators[],
member_height_indicators[],
map_settings_align,
show_topo_map_img,
show_topo_map_box,
show_topo_map_text,
show_towns_img,
show_towns_box,
show_towns_text,
@ -123,6 +126,7 @@ pub enum Event {
ShowDungeons(bool),
ShowCaves(bool),
ShowTrees(bool),
ShowTopoMap(bool),
Close,
RequestSiteInfo(SiteId),
}
@ -184,6 +188,7 @@ impl<'a> Widget for Map<'a> {
let show_castles = self.global_state.settings.interface.map_show_castles;
let show_caves = self.global_state.settings.interface.map_show_caves;
let show_trees = self.global_state.settings.interface.map_show_trees;
let show_topo_map = self.global_state.settings.interface.map_show_topo_map;
let mut events = Vec::new();
let i18n = &self.localized_strings;
// Tooltips
@ -342,7 +347,7 @@ impl<'a> Widget for Map<'a> {
.parent(state.ids.bg)
.source_rectangle(rect_src)
.set(state.ids.map_layers[index], ui);
} else {
} else if show_topo_map {
Image::new(layer.none)
.mid_top_with_margin_on(state.ids.map_align, 10.0)
.w_h(map_size.x, map_size.y)
@ -369,9 +374,44 @@ impl<'a> Widget for Map<'a> {
.top_right_with_margins_on(state.ids.frame, 55.0, 10.0)
.set(state.ids.map_settings_align, ui);
// Checkboxes
// Show topographic map
Image::new(self.imgs.map_topo)
.top_left_with_margins_on(state.ids.map_settings_align, 5.0, 5.0)
.w_h(20.0, 20.0)
.set(state.ids.show_topo_map_img, ui);
if Button::image(if show_topo_map {
self.imgs.checkbox_checked
} else {
self.imgs.checkbox
})
.w_h(18.0, 18.0)
.hover_image(if show_topo_map {
self.imgs.checkbox_checked_mo
} else {
self.imgs.checkbox_mo
})
.press_image(if show_topo_map {
self.imgs.checkbox_checked
} else {
self.imgs.checkbox_press
})
.right_from(state.ids.show_topo_map_img, 10.0)
.set(state.ids.show_topo_map_box, ui)
.was_clicked()
{
events.push(Event::ShowTopoMap(!show_topo_map));
}
Text::new(i18n.get("hud.map.topo_map"))
.right_from(state.ids.show_topo_map_box, 10.0)
.font_size(self.fonts.cyri.scale(14))
.font_id(self.fonts.cyri.conrod_id)
.graphics_for(state.ids.show_topo_map_box)
.color(TEXT_COLOR)
.set(state.ids.show_topo_map_text, ui);
// Show difficulties
Image::new(self.imgs.map_dif_6)
.top_left_with_margins_on(state.ids.map_settings_align, 5.0, 5.0)
.down_from(state.ids.show_topo_map_img, 10.0)
.w_h(20.0, 20.0)
.set(state.ids.show_difficulty_img, ui);
if Button::image(if show_difficulty {

View File

@ -118,6 +118,7 @@ impl<'a> Widget for MiniMap<'a> {
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;
let show_topo_map = self.global_state.settings.interface.map_show_topo_map;
let orientation = if is_facing_north {
Vec3::new(0.0, 1.0, 0.0)
} else {
@ -272,7 +273,7 @@ impl<'a> Widget for MiniMap<'a> {
.parent(state.ids.mmap_frame_bg)
.source_rectangle(rect_src)
.set(state.ids.map_layers[index], ui);
} else {
} else if show_topo_map {
Image::new(world_map_rotation)
.middle_of(state.ids.mmap_frame_bg)
.w_h(map_size.x, map_size.y)
@ -350,7 +351,7 @@ impl<'a> Widget for MiniMap<'a> {
SiteKind::Cave => Color::Rgba(1.0, 1.0, 1.0, 0.0),
SiteKind::Tree => Color::Rgba(1.0, 1.0, 1.0, 0.0),
}))
.parent(state.ids.map_layers[2])
.parent(state.ids.map_layers[3])
.set(state.ids.mmap_site_icons_bgs[i], ui);
Image::new(match &site.kind {
SiteKind::Town => self.imgs.mmap_site_town,

View File

@ -374,6 +374,7 @@ pub enum Event {
ChangeAmbiance(f32),
MapZoom(f64),
MapDrag(Vec2<f64>),
MapShowTopoMap(bool),
MapShowDifficulty(bool),
MapShowTowns(bool),
MapShowDungeons(bool),
@ -777,7 +778,7 @@ impl PromptDialogSettings {
pub struct Hud {
ui: Ui,
ids: Ids,
world_map_layers: (/* Id */ Vec<Rotations>, Vec2<u32>),
world_map: (/* Id */ Vec<Rotations>, Vec2<u32>),
imgs: Imgs,
item_imgs: ItemImgs,
fonts: Fonts,
@ -820,15 +821,11 @@ impl Hud {
// Load world map
let mut layers = Vec::new();
for layer in client.world_data().map_layers() {
layers.push(ui.add_graphic_with_rotations(Graphic::Image(
Arc::clone(layer),
Some(water_color),
)));
}
let world_map_layers = (
layers,
client.world_data().chunk_size().map(|e| e as u32),
layers.push(
ui.add_graphic_with_rotations(Graphic::Image(Arc::clone(layer), Some(water_color))),
);
}
let world_map = (layers, client.world_data().chunk_size().map(|e| e as u32));
// Load images.
let imgs = Imgs::load(&mut ui).expect("Failed to load images!");
// Load rotation images.
@ -865,7 +862,7 @@ impl Hud {
Self {
ui,
imgs,
world_map_layers,
world_map,
rot_imgs,
item_imgs,
fonts,
@ -2233,7 +2230,7 @@ impl Hud {
client,
&self.imgs,
&self.rot_imgs,
&self.world_map_layers,
&self.world_map,
&self.fonts,
camera.get_orientation(),
&global_state,
@ -2786,7 +2783,7 @@ impl Hud {
client,
&self.imgs,
&self.rot_imgs,
&self.world_map_layers,
&self.world_map,
&self.fonts,
self.pulse,
i18n,
@ -2801,6 +2798,9 @@ impl Hud {
self.show.want_grab = true;
self.force_ungrab = false;
},
map::Event::ShowTopoMap(map_show_topo_map) => {
events.push(Event::MapShowTopoMap(map_show_topo_map));
},
map::Event::ShowDifficulties(map_show_difficulties) => {
events.push(Event::MapShowDifficulty(map_show_difficulties));
},

View File

@ -1332,6 +1332,10 @@ impl PlayState for SessionState {
global_state.settings.interface.map_drag = map_drag;
global_state.settings.save_to_file_warn();
},
HudEvent::MapShowTopoMap(map_show_topo_map) => {
global_state.settings.interface.map_show_topo_map = map_show_topo_map;
global_state.settings.save_to_file_warn();
},
HudEvent::MapShowDifficulty(map_show_difficulty) => {
global_state.settings.interface.map_show_difficulty = map_show_difficulty;
global_state.settings.save_to_file_warn();

View File

@ -444,6 +444,7 @@ pub struct InterfaceSettings {
pub ui_scale: ScaleMode,
pub map_zoom: f64,
pub map_drag: Vec2<f64>,
pub map_show_topo_map: bool,
pub map_show_difficulty: bool,
pub map_show_towns: bool,
pub map_show_dungeons: bool,
@ -451,7 +452,6 @@ pub struct InterfaceSettings {
pub loading_tips: bool,
pub map_show_caves: bool,
pub map_show_trees: bool,
pub map_show_topo: bool,
pub minimap_show: bool,
pub minimap_face_north: bool,
}
@ -477,6 +477,7 @@ impl Default for InterfaceSettings {
ui_scale: ScaleMode::RelativeToWindow([1920.0, 1080.0].into()),
map_zoom: 10.0,
map_drag: Vec2 { x: 0.0, y: 0.0 },
map_show_topo_map: false,
map_show_difficulty: true,
map_show_towns: true,
map_show_dungeons: true,
@ -484,7 +485,6 @@ impl Default for InterfaceSettings {
loading_tips: true,
map_show_caves: true,
map_show_trees: true,
map_show_topo: false,
minimap_show: true,
minimap_face_north: false,
}

View File

@ -91,9 +91,10 @@ fn main() {
} else {
MapSample {
alt: 0.0,
rgb: Rgb::new(0, 0, 0),
rgba: Rgba::new(0, 0, 0, 255),
connections: None,
downhill_wpos: (pos + 1) * TerrainChunkSize::RECT_SIZE.map(|e| e as i32),
is_path: false,
}
}
};
@ -178,6 +179,11 @@ fn main() {
is_temperature,
is_humidity,
is_debug: true,
is_contours: false,
is_height_map: false,
is_political: false,
is_roads: false,
rgba_alpha: 1.0,
};
if samples_changed {