add setting to change reticule/pointer

This commit is contained in:
yuni 2024-10-12 05:16:04 +02:00
parent abb900d3f2
commit 847c824307
5 changed files with 94 additions and 24 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View file

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

View file

@ -17,6 +17,7 @@ use bevy::prelude::*;
use bevy::scene::SceneInstance; use bevy::scene::SceneInstance;
use bevy::transform::TransformSystem; use bevy::transform::TransformSystem;
use bevy_xpbd_3d::prelude::*; use bevy_xpbd_3d::prelude::*;
use serde::{Deserialize, Serialize};
use std::collections::VecDeque; use std::collections::VecDeque;
use std::time::SystemTime; use std::time::SystemTime;
@ -57,6 +58,12 @@ pub const PLAYER_AR_AVATARS: &[(Avatar, &str, f32, &str)] = &[
(Avatar::Asteroid, "metis", 1.3, "Asteroid"), (Avatar::Asteroid, "metis", 1.3, "Asteroid"),
]; ];
pub const POINTERS: &[(Pointer, Option<&str>, &str)] = &[
(Pointer::None, None, "Off"),
(Pointer::Tri, Some("sprites/pointer_tri.png"), "Default"),
(Pointer::Dot, Some("sprites/pointer_dot.png"), "Dot"),
];
pub struct HudPlugin; pub struct HudPlugin;
impl Plugin for HudPlugin { impl Plugin for HudPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
@ -77,6 +84,7 @@ impl Plugin for HudPlugin {
( (
update_overlay_visibility, update_overlay_visibility,
update_avatar.run_if(on_event::<UpdateAvatarEvent>()), update_avatar.run_if(on_event::<UpdateAvatarEvent>()),
update_pointer.run_if(on_event::<UpdatePointerEvent>()),
update_ar_overlays update_ar_overlays
.run_if(game_running) .run_if(game_running)
.after(camera::position_to_transform) .after(camera::position_to_transform)
@ -105,6 +113,7 @@ impl Plugin for HudPlugin {
))); )));
app.add_event::<TargetEvent>(); app.add_event::<TargetEvent>();
app.add_event::<UpdateAvatarEvent>(); app.add_event::<UpdateAvatarEvent>();
app.add_event::<UpdatePointerEvent>();
app.add_event::<UpdateOverlayVisibility>(); app.add_event::<UpdateOverlayVisibility>();
} }
} }
@ -115,6 +124,8 @@ pub struct TargetEvent(pub Option<Entity>);
pub struct UpdateOverlayVisibility; pub struct UpdateOverlayVisibility;
#[derive(Event)] #[derive(Event)]
pub struct UpdateAvatarEvent; pub struct UpdateAvatarEvent;
#[derive(Event)]
pub struct UpdatePointerEvent;
#[derive(Component)] #[derive(Component)]
struct NodeHud; struct NodeHud;
#[derive(Component)] #[derive(Component)]
@ -126,7 +137,7 @@ struct NodeSpeedometerText;
#[derive(Component)] #[derive(Component)]
struct NodeCurrentChatLine; struct NodeCurrentChatLine;
#[derive(Component)] #[derive(Component)]
struct Reticule; struct PointerComponent(pub Pointer);
#[derive(Component)] #[derive(Component)]
struct Speedometer; struct Speedometer;
#[derive(Component)] #[derive(Component)]
@ -180,6 +191,14 @@ pub struct AugmentedRealityOverlay {
#[derive(Resource)] #[derive(Resource)]
struct FPSUpdateTimer(Timer); struct FPSUpdateTimer(Timer);
#[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize)]
pub enum Pointer {
None,
#[default]
Tri,
Dot,
}
pub enum Avatar { pub enum Avatar {
None, None,
ChefHat, ChefHat,
@ -296,6 +315,7 @@ impl Log {
pub fn setup( pub fn setup(
mut commands: Commands, mut commands: Commands,
settings: Res<Settings>, settings: Res<Settings>,
prefs: Res<Preferences>,
asset_server: Res<AssetServer>, asset_server: Res<AssetServer>,
mut ew_updateoverlays: EventWriter<UpdateOverlayVisibility>, mut ew_updateoverlays: EventWriter<UpdateOverlayVisibility>,
) { ) {
@ -387,8 +407,13 @@ pub fn setup(
parent.spawn((bundle_chatbox, NodeConsole)); parent.spawn((bundle_chatbox, NodeConsole));
}); });
// Add Reticule // Add Pointer
let reticule_handle: Handle<Image> = asset_server.load("sprites/reticule4.png"); for (pointer_enum, sprite, _) in POINTERS {
if sprite.is_none() {
continue;
}
let sprite = sprite.unwrap();
let pointer_handle: Handle<Image> = asset_server.load(sprite.to_string());
commands commands
.spawn(( .spawn((
NodeBundle { NodeBundle {
@ -401,17 +426,19 @@ pub fn setup(
.with_children(|builder| { .with_children(|builder| {
builder.spawn(( builder.spawn((
ImageBundle { ImageBundle {
image: UiImage::new(reticule_handle), image: UiImage::new(pointer_handle),
style: Style { style: Style {
width: Val::VMin(5.0), width: Val::VMin(5.0),
height: Val::VMin(5.0), height: Val::VMin(5.0),
..Default::default() ..Default::default()
}, },
visibility: bool2vis(prefs.pointer == *pointer_enum),
..Default::default() ..Default::default()
}, },
Reticule, PointerComponent(pointer_enum.clone()),
)); ));
}); });
}
// HP/O2/Suit Integrity/Power Gauges // HP/O2/Suit Integrity/Power Gauges
let gauges_handle: Handle<Image> = asset_server.load("sprites/gauge_horizontal.png"); let gauges_handle: Handle<Image> = asset_server.load("sprites/gauge_horizontal.png");
@ -1300,6 +1327,19 @@ fn update_overlay_visibility(
}; };
} }
fn update_pointer(
prefs: ResMut<Preferences>,
mut q_pointer: Query<(&PointerComponent, &mut Visibility)>,
) {
for (pointer, mut vis) in &mut q_pointer {
*vis = if pointer.0 == prefs.pointer {
Visibility::Inherited
} else {
Visibility::Hidden
}
}
}
fn update_avatar( fn update_avatar(
mut commands: Commands, mut commands: Commands,
mut settings: ResMut<Settings>, mut settings: ResMut<Settings>,

View file

@ -65,6 +65,7 @@ pub enum DeathScreenEvent {
pub const MENUDEF: &[(&str, MenuAction)] = &[ pub const MENUDEF: &[(&str, MenuAction)] = &[
("", MenuAction::ToggleAR), ("", MenuAction::ToggleAR),
("", MenuAction::ChangeARAvatar), ("", MenuAction::ChangeARAvatar),
("", MenuAction::ChangePointer),
("", MenuAction::ToggleMap), ("", MenuAction::ToggleMap),
("", MenuAction::ModLightAmp), ("", MenuAction::ModLightAmp),
("", MenuAction::ModFlashlightPower), ("", MenuAction::ModFlashlightPower),
@ -84,6 +85,7 @@ pub enum MenuAction {
ToggleMap, ToggleMap,
ToggleAR, ToggleAR,
ChangeARAvatar, ChangeARAvatar,
ChangePointer,
ModLightAmp, ModLightAmp,
ModFlashlightPower, ModFlashlightPower,
ModThrusterBoost, ModThrusterBoost,
@ -544,6 +546,14 @@ pub fn update_menu(
text.sections[i].value = format!("Avatar: {avatar_title}\n"); text.sections[i].value = format!("Avatar: {avatar_title}\n");
} }
} }
MenuAction::ChangePointer => {
for pointer in hud::POINTERS {
if pointer.0 == prefs.pointer {
text.sections[i].value = format!("Pointer: {}\n", pointer.2);
break;
}
}
}
MenuAction::ToggleMap => { MenuAction::ToggleMap => {
let onoff = bool2string(settings.map_active); let onoff = bool2string(settings.map_active);
text.sections[i].value = format!("Map: {onoff} [M]\n"); text.sections[i].value = format!("Map: {onoff} [M]\n");
@ -577,6 +587,7 @@ pub fn handle_input(
mut ew_sfx: EventWriter<audio::PlaySfxEvent>, mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
mut ew_updatemenu: EventWriter<UpdateMenuEvent>, mut ew_updatemenu: EventWriter<UpdateMenuEvent>,
mut ew_updateavatar: EventWriter<hud::UpdateAvatarEvent>, mut ew_updateavatar: EventWriter<hud::UpdateAvatarEvent>,
mut ew_updatepointer: EventWriter<hud::UpdatePointerEvent>,
mut ew_updateoverlays: EventWriter<hud::UpdateOverlayVisibility>, mut ew_updateoverlays: EventWriter<hud::UpdateOverlayVisibility>,
) { ) {
let last_menu_entry = MENUDEF.len() - 1; let last_menu_entry = MENUDEF.len() - 1;
@ -631,6 +642,24 @@ pub fn handle_input(
settings.ar_avatar += 1; settings.ar_avatar += 1;
ew_updateavatar.send(hud::UpdateAvatarEvent); ew_updateavatar.send(hud::UpdateAvatarEvent);
} }
MenuAction::ChangePointer => {
let mut index = 0;
for (i, pointer) in hud::POINTERS.iter().enumerate() {
if pointer.0 == prefs.pointer {
index = i;
break;
}
}
index = (index + 1) % hud::POINTERS.len();
for (i, pointer) in hud::POINTERS.iter().enumerate() {
if i == index {
prefs.pointer = pointer.0;
break;
}
}
ew_updatepointer.send(hud::UpdatePointerEvent);
ew_updatemenu.send(UpdateMenuEvent);
}
MenuAction::ModLightAmp => { MenuAction::ModLightAmp => {
prefs.light_amp += 1; prefs.light_amp += 1;
if prefs.light_amp > 3 { if prefs.light_amp > 3 {

View file

@ -473,6 +473,7 @@ pub struct Preferences {
pub third_person: bool, pub third_person: bool,
pub shadows_sun: bool, pub shadows_sun: bool,
pub avatar: usize, pub avatar: usize,
pub pointer: hud::Pointer,
#[serde(default = "Preferences::default_light_amp")] #[serde(default = "Preferences::default_light_amp")]
pub light_amp: usize, // 0-3 pub light_amp: usize, // 0-3
#[serde(default = "Preferences::default_flashlight_power")] #[serde(default = "Preferences::default_flashlight_power")]