add grid in map, so the player actually knows wtf is going on
This commit is contained in:
parent
098c47b030
commit
4daa0e8a68
BIN
assets/models/mapgrid.glb
Normal file
BIN
assets/models/mapgrid.glb
Normal file
Binary file not shown.
BIN
src/blender/mapgrid.blend
Normal file
BIN
src/blender/mapgrid.blend
Normal file
Binary file not shown.
|
@ -90,6 +90,12 @@ impl Plugin for CameraPlugin {
|
|||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub enum MapGrid {
|
||||
HighRes,
|
||||
LowRes,
|
||||
}
|
||||
|
||||
#[derive(Component, Default)]
|
||||
pub struct ShowOnlyInMap {
|
||||
pub min_distance: f64,
|
||||
pub distance_to_id: String,
|
||||
|
@ -126,6 +132,7 @@ impl Default for MapCam {
|
|||
pub fn setup_camera(
|
||||
mut commands: Commands,
|
||||
settings: Res<var::Settings>,
|
||||
asset_server: Res<AssetServer>,
|
||||
prefs: Res<var::Preferences>,
|
||||
) {
|
||||
// Add player
|
||||
|
@ -201,6 +208,28 @@ pub fn setup_camera(
|
|||
commands.insert_resource(DirectionalLightShadowMap {
|
||||
size: settings.shadowmap_resolution,
|
||||
});
|
||||
|
||||
// Add map grid
|
||||
let mut entitycmd = commands.spawn((
|
||||
MapGrid::HighRes,
|
||||
hud::ToggleableHudElement,
|
||||
ShowOnlyInMap::default(),
|
||||
bevy::pbr::NotShadowCaster,
|
||||
bevy::pbr::NotShadowReceiver,
|
||||
visual::IsEffect,
|
||||
SpatialBundle::default(),
|
||||
));
|
||||
load_asset("mapgrid", &mut entitycmd, &*asset_server);
|
||||
let mut entitycmd = commands.spawn((
|
||||
MapGrid::LowRes,
|
||||
hud::ToggleableHudElement,
|
||||
ShowOnlyInMap::default(),
|
||||
bevy::pbr::NotShadowCaster,
|
||||
bevy::pbr::NotShadowReceiver,
|
||||
visual::IsEffect,
|
||||
SpatialBundle::default(),
|
||||
));
|
||||
load_asset("mapgrid", &mut entitycmd, &*asset_server);
|
||||
}
|
||||
|
||||
pub fn sync_camera_to_player(
|
||||
|
@ -259,6 +288,14 @@ pub fn update_map_camera(
|
|||
),
|
||||
>,
|
||||
q_target_changed: Query<(), Changed<hud::IsTargeted>>,
|
||||
mut q_mapgrid: Query<
|
||||
(&mut Transform, &MapGrid),
|
||||
(
|
||||
Without<hud::IsTargeted>,
|
||||
Without<Camera>,
|
||||
Without<actor::PlayerCamera>,
|
||||
),
|
||||
>,
|
||||
mut mouse_events: EventReader<MouseMotion>,
|
||||
mut er_mousewheel: EventReader<MouseWheel>,
|
||||
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||
|
@ -275,6 +312,18 @@ pub fn update_map_camera(
|
|||
};
|
||||
mapcam.center_on_entity = Some(target_entity);
|
||||
|
||||
// Update map grid
|
||||
let step: f64 = 5.0;
|
||||
for (mut trans, mapgrid) in &mut q_mapgrid {
|
||||
trans.translation = Vec3::ZERO;
|
||||
let scale = step.powf(mapcam.zoom_level.log(step).floor());
|
||||
let scale = match mapgrid {
|
||||
MapGrid::HighRes => scale,
|
||||
MapGrid::LowRes => scale * step,
|
||||
};
|
||||
trans.scale = Vec3::splat(scale as f32);
|
||||
}
|
||||
|
||||
// Get mouse movement
|
||||
let mut mouse_delta = Vec2::ZERO;
|
||||
for mouse_event in mouse_events.read() {
|
||||
|
@ -625,19 +674,23 @@ pub fn update_map_only_object_visibility(
|
|||
let cam_pos: Vec3 = cam.translation + player_pos.as_vec3();
|
||||
for (mut vis, onlyinmap) in &mut q_onlyinmap {
|
||||
if settings.map_active && settings.hud_active {
|
||||
if let Some(pos) = id2pos.0.get(&onlyinmap.distance_to_id) {
|
||||
let dist = cam_pos.distance(pos.as_vec3());
|
||||
if dist >= onlyinmap.min_distance as f32 {
|
||||
*vis = Visibility::Inherited;
|
||||
if onlyinmap.distance_to_id.is_empty() {
|
||||
*vis = Visibility::Inherited;
|
||||
} else {
|
||||
if let Some(pos) = id2pos.0.get(&onlyinmap.distance_to_id) {
|
||||
let dist = cam_pos.distance(pos.as_vec3());
|
||||
if dist >= onlyinmap.min_distance as f32 {
|
||||
*vis = Visibility::Inherited;
|
||||
} else {
|
||||
*vis = Visibility::Hidden;
|
||||
}
|
||||
} else {
|
||||
error!(
|
||||
"Failed get position of actor ID '{}'",
|
||||
&onlyinmap.distance_to_id
|
||||
);
|
||||
*vis = Visibility::Hidden;
|
||||
}
|
||||
} else {
|
||||
error!(
|
||||
"Failed get position of actor ID '{}'",
|
||||
&onlyinmap.distance_to_id
|
||||
);
|
||||
*vis = Visibility::Hidden;
|
||||
}
|
||||
} else {
|
||||
*vis = Visibility::Hidden;
|
||||
|
|
|
@ -63,6 +63,7 @@ pub fn asset_name_to_path(name: &str) -> &'static str {
|
|||
"pizzasign" => "models/pizzasign.glb#Scene0",
|
||||
"selectagon" => "models/selectagon.glb#Scene0",
|
||||
"orbitring" => "models/orbitring.glb#Scene0",
|
||||
"mapgrid" => "models/mapgrid.glb#Scene0",
|
||||
"clippy" => "models/clippy/clippy.glb#Scene0",
|
||||
"clippy_ar" => "models/clippy/ar_happy.glb#Scene0",
|
||||
"whale" => "models/whale.gltf#Scene0",
|
||||
|
|
Loading…
Reference in a new issue