2024-03-18 00:52:41 +00:00
|
|
|
use crate::{settings, actor, audio};
|
2024-03-17 14:23:22 +00:00
|
|
|
use bevy::prelude::*;
|
|
|
|
use bevy::diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin};
|
2024-03-18 13:08:11 +00:00
|
|
|
use bevy::core_pipeline::bloom::{BloomCompositeMode, BloomSettings};
|
2024-03-17 23:36:56 +00:00
|
|
|
use std::collections::VecDeque;
|
2024-03-18 00:02:17 +00:00
|
|
|
use std::time::SystemTime;
|
2024-03-17 14:23:22 +00:00
|
|
|
|
2024-03-20 01:03:42 +00:00
|
|
|
pub const HUD_REFRESH_TIME: f32 = 0.5;
|
|
|
|
pub const FONT: &str = "external/NotoSansSC-Thin.ttf";
|
|
|
|
pub const LOG_MAX: usize = 20;
|
|
|
|
pub const LOG_MAX_TIME_S: u64 = 20;
|
|
|
|
pub const CHOICE_NONE: &str = "";
|
2024-03-20 05:55:54 +00:00
|
|
|
pub const AMBIENT_LIGHT: f32 = 0.0; // Space is DARK
|
2024-03-21 03:34:09 +00:00
|
|
|
pub const AMBIENT_LIGHT_AR: f32 = 15.0;
|
2024-03-20 17:54:22 +00:00
|
|
|
//pub const REPLY_NUMBERS: [char; 10] = ['❶', '❷', '❸', '❹', '❺', '❻', '❼', '❽', '❾', '⓿'];
|
|
|
|
pub const REPLY_NUMBERS: [char; 10] = ['①', '②', '③', '④', '⑤', '⑥', '⑦', '⑧', '⑨', '⑩'];
|
2024-03-17 20:57:30 +00:00
|
|
|
|
2024-03-17 22:49:50 +00:00
|
|
|
pub struct HudPlugin;
|
|
|
|
impl Plugin for HudPlugin {
|
2024-03-17 14:23:22 +00:00
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
app.add_systems(Startup, setup);
|
2024-03-17 18:03:02 +00:00
|
|
|
app.add_systems(Update, (update, handle_input));
|
2024-03-20 01:03:42 +00:00
|
|
|
app.add_systems(PostUpdate, despawn_old_choices);
|
2024-03-19 02:18:16 +00:00
|
|
|
app.insert_resource(Log {
|
|
|
|
logs: VecDeque::with_capacity(LOG_MAX),
|
|
|
|
needs_rerendering: true,
|
|
|
|
});
|
2024-03-17 20:57:30 +00:00
|
|
|
app.insert_resource(FPSUpdateTimer(
|
|
|
|
Timer::from_seconds(HUD_REFRESH_TIME, TimerMode::Repeating)));
|
2024-03-17 14:23:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-19 00:24:27 +00:00
|
|
|
#[derive(Component)] struct GaugesText;
|
|
|
|
#[derive(Component)] struct ChatText;
|
2024-03-17 14:23:22 +00:00
|
|
|
|
|
|
|
#[derive(Resource)]
|
|
|
|
struct FPSUpdateTimer(Timer);
|
|
|
|
|
2024-03-20 01:03:42 +00:00
|
|
|
#[derive(Component)]
|
|
|
|
pub struct ChoiceAvailable {
|
|
|
|
pub conv_id: String,
|
|
|
|
pub conv_label: String,
|
|
|
|
pub recipient: String,
|
|
|
|
pub text: String,
|
|
|
|
}
|
|
|
|
|
2024-03-19 02:18:16 +00:00
|
|
|
pub enum LogLevel {
|
|
|
|
Warning,
|
|
|
|
//Error,
|
|
|
|
Info,
|
|
|
|
//Debug,
|
|
|
|
Chat,
|
|
|
|
//Ping,
|
|
|
|
}
|
|
|
|
|
2024-03-18 00:02:17 +00:00
|
|
|
struct Message {
|
|
|
|
text: String,
|
2024-03-19 02:18:16 +00:00
|
|
|
sender: String,
|
|
|
|
level: LogLevel,
|
2024-03-18 00:02:17 +00:00
|
|
|
time: u64,
|
|
|
|
}
|
|
|
|
|
2024-03-17 23:36:56 +00:00
|
|
|
#[derive(Resource)]
|
2024-03-19 00:24:27 +00:00
|
|
|
pub struct Log {
|
2024-03-18 00:02:17 +00:00
|
|
|
logs: VecDeque<Message>,
|
2024-03-19 02:18:16 +00:00
|
|
|
needs_rerendering: bool,
|
2024-03-17 23:36:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Log {
|
2024-03-19 02:18:16 +00:00
|
|
|
pub fn info(&mut self, message: String) {
|
|
|
|
self.add(message, "System".to_string(), LogLevel::Info);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn chat(&mut self, message: String, sender: String) {
|
|
|
|
self.add(message, sender, LogLevel::Chat);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn warning(&mut self, message: String) {
|
|
|
|
self.add(message, "WARNING".to_string(), LogLevel::Warning);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add(&mut self, message: String, sender: String, level: LogLevel) {
|
2024-03-17 23:36:56 +00:00
|
|
|
if self.logs.len() == LOG_MAX {
|
|
|
|
self.logs.pop_front();
|
|
|
|
}
|
2024-03-18 00:02:17 +00:00
|
|
|
if let Ok(epoch) = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) {
|
|
|
|
self.logs.push_back(Message {
|
|
|
|
text: message,
|
2024-03-19 02:18:16 +00:00
|
|
|
sender: sender,
|
|
|
|
level: level,
|
2024-03-18 00:02:17 +00:00
|
|
|
time: epoch.as_secs(),
|
|
|
|
});
|
2024-03-19 02:18:16 +00:00
|
|
|
self.needs_rerendering = true;
|
2024-03-18 00:02:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn remove_old(&mut self) {
|
|
|
|
if let Some(message) = self.logs.front() {
|
|
|
|
if let Ok(epoch) = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) {
|
|
|
|
if epoch.as_secs() - message.time > LOG_MAX_TIME_S {
|
|
|
|
self.logs.pop_front();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-03-17 23:36:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-17 14:23:22 +00:00
|
|
|
fn setup(
|
|
|
|
mut commands: Commands,
|
2024-03-17 18:03:02 +00:00
|
|
|
settings: Res<settings::Settings>,
|
2024-03-17 19:04:16 +00:00
|
|
|
asset_server: Res<AssetServer>,
|
2024-03-17 23:36:56 +00:00
|
|
|
mut log: ResMut<Log>,
|
2024-03-20 05:55:54 +00:00
|
|
|
mut ambient_light: ResMut<AmbientLight>,
|
2024-03-17 14:23:22 +00:00
|
|
|
) {
|
2024-03-19 02:18:16 +00:00
|
|
|
log.info("Customer wake-up registered.".to_string());
|
|
|
|
log.info("Systems reactivated.".to_string());
|
|
|
|
log.warning("Oxygen Low".to_string());
|
2024-03-17 21:28:10 +00:00
|
|
|
let visibility = if settings.hud_active {
|
2024-03-17 18:03:02 +00:00
|
|
|
Visibility::Inherited
|
|
|
|
} else {
|
|
|
|
Visibility::Hidden
|
|
|
|
};
|
|
|
|
let mut bundle_fps = TextBundle::from_sections([
|
|
|
|
TextSection::new(
|
2024-03-17 23:42:10 +00:00
|
|
|
"帧率 ",
|
2024-03-17 18:03:02 +00:00
|
|
|
TextStyle {
|
2024-03-17 19:28:45 +00:00
|
|
|
font: asset_server.load(FONT),
|
2024-03-17 19:31:16 +00:00
|
|
|
font_size: settings.font_size_hud,
|
2024-03-17 19:04:16 +00:00
|
|
|
color: Color::GRAY,
|
2024-03-17 18:03:02 +00:00
|
|
|
..default()
|
|
|
|
},
|
|
|
|
),
|
2024-03-17 19:04:16 +00:00
|
|
|
TextSection::new(
|
|
|
|
"",
|
2024-03-17 18:03:02 +00:00
|
|
|
TextStyle {
|
2024-03-17 19:28:45 +00:00
|
|
|
font: asset_server.load(FONT),
|
2024-03-17 19:31:16 +00:00
|
|
|
font_size: settings.font_size_hud,
|
2024-03-17 19:04:16 +00:00
|
|
|
color: Color::GRAY,
|
2024-03-17 18:03:02 +00:00
|
|
|
..default()
|
|
|
|
}
|
2024-03-17 19:04:16 +00:00
|
|
|
),
|
2024-03-17 20:29:27 +00:00
|
|
|
TextSection::new(
|
2024-03-17 23:42:10 +00:00
|
|
|
"\n电量 ",
|
2024-03-17 21:28:10 +00:00
|
|
|
TextStyle {
|
|
|
|
font: asset_server.load(FONT),
|
|
|
|
font_size: settings.font_size_hud,
|
|
|
|
color: Color::GRAY,
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
),
|
|
|
|
TextSection::new(
|
|
|
|
"",
|
|
|
|
TextStyle {
|
|
|
|
font: asset_server.load(FONT),
|
|
|
|
font_size: settings.font_size_hud,
|
|
|
|
color: Color::GRAY,
|
|
|
|
..default()
|
|
|
|
}
|
|
|
|
),
|
|
|
|
TextSection::new(
|
2024-03-17 23:42:10 +00:00
|
|
|
"\n氧 OXYGEN ",
|
2024-03-17 20:29:27 +00:00
|
|
|
TextStyle {
|
|
|
|
font: asset_server.load(FONT),
|
|
|
|
font_size: settings.font_size_hud,
|
|
|
|
color: Color::GRAY,
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
),
|
|
|
|
TextSection::new(
|
|
|
|
"",
|
|
|
|
TextStyle {
|
|
|
|
font: asset_server.load(FONT),
|
|
|
|
font_size: settings.font_size_hud,
|
2024-03-18 02:47:31 +00:00
|
|
|
color: Color::MAROON,
|
2024-03-17 20:29:27 +00:00
|
|
|
..default()
|
|
|
|
}
|
|
|
|
),
|
|
|
|
TextSection::new(
|
2024-03-17 23:42:10 +00:00
|
|
|
"\nAdren水平 ",
|
2024-03-17 20:29:27 +00:00
|
|
|
TextStyle {
|
|
|
|
font: asset_server.load(FONT),
|
|
|
|
font_size: settings.font_size_hud,
|
|
|
|
color: Color::GRAY,
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
),
|
|
|
|
TextSection::new(
|
|
|
|
"",
|
|
|
|
TextStyle {
|
|
|
|
font: asset_server.load(FONT),
|
|
|
|
font_size: settings.font_size_hud,
|
|
|
|
color: Color::GRAY,
|
|
|
|
..default()
|
|
|
|
}
|
|
|
|
),
|
2024-03-20 01:23:29 +00:00
|
|
|
TextSection::new(
|
|
|
|
"\n雌激素水平 172pg/mL",
|
|
|
|
TextStyle {
|
|
|
|
font: asset_server.load(FONT),
|
|
|
|
font_size: settings.font_size_hud,
|
|
|
|
color: Color::GRAY,
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
),
|
2024-03-18 02:42:14 +00:00
|
|
|
TextSection::new(
|
|
|
|
"\nProximity 警告 ",
|
|
|
|
TextStyle {
|
|
|
|
font: asset_server.load(FONT),
|
|
|
|
font_size: settings.font_size_hud,
|
|
|
|
color: Color::GRAY,
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
),
|
|
|
|
TextSection::new(
|
|
|
|
"",
|
|
|
|
TextStyle {
|
|
|
|
font: asset_server.load(FONT),
|
|
|
|
font_size: settings.font_size_hud,
|
|
|
|
color: Color::GRAY,
|
|
|
|
..default()
|
|
|
|
}
|
|
|
|
),
|
2024-03-20 17:37:10 +00:00
|
|
|
TextSection::new(
|
|
|
|
"\nSuit Integrity ",
|
|
|
|
TextStyle {
|
|
|
|
font: asset_server.load(FONT),
|
|
|
|
font_size: settings.font_size_hud,
|
|
|
|
color: Color::GRAY,
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
),
|
|
|
|
TextSection::new(
|
|
|
|
"",
|
|
|
|
TextStyle {
|
|
|
|
font: asset_server.load(FONT),
|
|
|
|
font_size: settings.font_size_hud,
|
|
|
|
color: Color::GRAY,
|
|
|
|
..default()
|
|
|
|
}
|
|
|
|
),
|
2024-03-17 23:36:56 +00:00
|
|
|
TextSection::new(
|
|
|
|
"\n\n",
|
|
|
|
TextStyle {
|
|
|
|
font: asset_server.load(FONT),
|
|
|
|
font_size: settings.font_size_hud,
|
|
|
|
color: Color::GRAY,
|
|
|
|
..default()
|
|
|
|
}
|
|
|
|
),
|
2024-03-17 23:42:10 +00:00
|
|
|
TextSection::from_style(
|
2024-03-17 23:36:56 +00:00
|
|
|
TextStyle {
|
|
|
|
font: asset_server.load(FONT),
|
|
|
|
font_size: settings.font_size_hud,
|
|
|
|
color: Color::GRAY,
|
|
|
|
..default()
|
|
|
|
}
|
|
|
|
),
|
2024-03-17 23:42:10 +00:00
|
|
|
]).with_style(Style {
|
2024-03-18 00:23:35 +00:00
|
|
|
top: Val::VMin(2.0),
|
2024-03-17 23:42:10 +00:00
|
|
|
left: Val::VMin(3.0),
|
|
|
|
..default()
|
|
|
|
});
|
2024-03-17 18:03:02 +00:00
|
|
|
bundle_fps.visibility = visibility;
|
2024-03-17 14:23:22 +00:00
|
|
|
commands.spawn((
|
2024-03-17 18:03:02 +00:00
|
|
|
bundle_fps,
|
2024-03-17 20:29:27 +00:00
|
|
|
GaugesText,
|
2024-03-17 14:23:22 +00:00
|
|
|
));
|
2024-03-19 00:24:27 +00:00
|
|
|
|
|
|
|
// Add Chat Box
|
2024-03-19 02:18:16 +00:00
|
|
|
let bundle_chatbox = TextBundle::from_sections([
|
|
|
|
TextSection::new(
|
2024-03-19 05:24:27 +00:00
|
|
|
"Warning: System Log Uninitialized",
|
2024-03-19 02:18:16 +00:00
|
|
|
TextStyle {
|
|
|
|
font: asset_server.load(FONT),
|
|
|
|
font_size: settings.font_size_hud,
|
2024-03-21 05:04:06 +00:00
|
|
|
color: Color::rgb(0.7, 0.7, 0.7),
|
2024-03-19 02:18:16 +00:00
|
|
|
..default()
|
|
|
|
}
|
|
|
|
),
|
2024-03-20 01:03:42 +00:00
|
|
|
TextSection::new(
|
|
|
|
"\n",
|
|
|
|
TextStyle {
|
|
|
|
font: asset_server.load(FONT),
|
|
|
|
font_size: settings.font_size_hud,
|
|
|
|
color: Color::WHITE,
|
|
|
|
..default()
|
|
|
|
}
|
|
|
|
),
|
|
|
|
TextSection::new(
|
2024-03-21 05:04:06 +00:00
|
|
|
"\n\n\n",
|
2024-03-20 01:03:42 +00:00
|
|
|
TextStyle {
|
|
|
|
font: asset_server.load(FONT),
|
|
|
|
font_size: settings.font_size_hud,
|
|
|
|
color: Color::WHITE,
|
|
|
|
..default()
|
|
|
|
}
|
|
|
|
),
|
2024-03-19 02:18:16 +00:00
|
|
|
]).with_style(Style {
|
|
|
|
position_type: PositionType::Absolute,
|
2024-03-19 14:51:08 +00:00
|
|
|
bottom: Val::VMin(0.0),
|
|
|
|
left: Val::VMin(0.0),
|
2024-03-19 02:18:16 +00:00
|
|
|
//bottom: Val::VMin(40.0),
|
|
|
|
//left: Val::VMin(30.0),
|
|
|
|
..default()
|
2024-03-19 05:14:25 +00:00
|
|
|
}).with_text_justify(JustifyText::Left);
|
2024-03-19 02:18:16 +00:00
|
|
|
commands.spawn((
|
2024-03-19 14:51:08 +00:00
|
|
|
NodeBundle {
|
|
|
|
border_color: { BorderColor(Color::RED) },
|
|
|
|
style: Style {
|
|
|
|
width: Val::Percent(50.),
|
|
|
|
align_items: AlignItems::Start,
|
|
|
|
position_type: PositionType::Absolute,
|
|
|
|
bottom: Val::VMin(10.0),
|
|
|
|
left: Val::VMin(25.0),
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
)).with_children(|parent| {
|
|
|
|
parent.spawn((
|
|
|
|
bundle_chatbox,
|
|
|
|
ChatText,
|
|
|
|
));
|
|
|
|
});
|
2024-03-20 05:55:54 +00:00
|
|
|
|
|
|
|
// AR-related things
|
|
|
|
ambient_light.brightness = if settings.hud_active {
|
|
|
|
AMBIENT_LIGHT_AR
|
|
|
|
} else {
|
|
|
|
AMBIENT_LIGHT
|
|
|
|
};
|
2024-03-17 14:23:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn update(
|
|
|
|
diagnostics: Res<DiagnosticsStore>,
|
2024-03-17 22:49:50 +00:00
|
|
|
time: Res<Time>,
|
2024-03-18 00:02:17 +00:00
|
|
|
mut log: ResMut<Log>,
|
2024-03-17 22:49:50 +00:00
|
|
|
player: Query<(&actor::Suit, &actor::LifeForm), With<actor::Player>>,
|
2024-03-17 14:23:22 +00:00
|
|
|
mut timer: ResMut<FPSUpdateTimer>,
|
2024-03-17 20:29:27 +00:00
|
|
|
mut query: Query<&mut Text, With<GaugesText>>,
|
2024-03-20 01:03:42 +00:00
|
|
|
q_choices: Query<&ChoiceAvailable>,
|
2024-03-19 02:18:16 +00:00
|
|
|
mut query_chat: Query<&mut Text, (With<ChatText>, Without<GaugesText>)>,
|
2024-03-18 02:42:14 +00:00
|
|
|
query_all_actors: Query<&actor::Actor>,
|
2024-03-19 02:18:16 +00:00
|
|
|
settings: Res<settings::Settings>,
|
2024-03-17 14:23:22 +00:00
|
|
|
) {
|
2024-03-18 03:57:17 +00:00
|
|
|
// TODO only when hud is actually on
|
2024-03-19 02:18:16 +00:00
|
|
|
if timer.0.tick(time.delta()).just_finished() || log.needs_rerendering {
|
2024-03-17 22:49:50 +00:00
|
|
|
let player = player.get_single();
|
|
|
|
if player.is_ok() {
|
|
|
|
let (suit, lifeform) = player.unwrap();
|
|
|
|
for mut text in &mut query {
|
|
|
|
if let Some(fps) = diagnostics.get(&FrameTimeDiagnosticsPlugin::FPS) {
|
|
|
|
if let Some(value) = fps.smoothed() {
|
|
|
|
// Update the value of the second section
|
|
|
|
text.sections[1].value = format!("{value:.0}");
|
|
|
|
}
|
2024-03-17 14:23:22 +00:00
|
|
|
}
|
2024-03-17 22:49:50 +00:00
|
|
|
let power = suit.power;
|
|
|
|
text.sections[3].value = format!("{power:}Wh");
|
|
|
|
let oxy_percent = suit.oxygen / suit.oxygen_max * 100.0;
|
|
|
|
let oxy_total = suit.oxygen * 1e6;
|
|
|
|
text.sections[5].value = format!("{oxy_percent:.1}% [{oxy_total:.0}mg]");
|
|
|
|
let adrenaline = lifeform.adrenaline * 990.0 + 10.0;
|
|
|
|
text.sections[7].value = format!("{adrenaline:.0}pg/mL");
|
2024-03-18 02:42:14 +00:00
|
|
|
let all_actors = query_all_actors.iter().len();
|
2024-03-20 01:23:29 +00:00
|
|
|
text.sections[10].value = format!("{all_actors:.0}");
|
2024-03-20 17:37:10 +00:00
|
|
|
let integrity = suit.integrity * 100.0;
|
|
|
|
text.sections[12].value = format!("{integrity:.0}%");
|
2024-03-17 14:23:22 +00:00
|
|
|
}
|
|
|
|
}
|
2024-03-19 02:18:16 +00:00
|
|
|
|
|
|
|
if let Ok(mut chat) = query_chat.get_single_mut() {
|
2024-03-20 01:03:42 +00:00
|
|
|
// Choices
|
|
|
|
let mut choices: Vec<String> = Vec::new();
|
2024-03-20 17:54:22 +00:00
|
|
|
let mut count = 0;
|
2024-03-20 01:03:42 +00:00
|
|
|
for choice in &q_choices {
|
2024-03-20 17:54:22 +00:00
|
|
|
if count > 9 {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
let press_this = REPLY_NUMBERS[count];
|
|
|
|
let reply = &choice.text;
|
|
|
|
//let recipient = &choice.recipient;
|
|
|
|
// TODO: indicate recipients if there's more than one
|
|
|
|
choices.push(format!("{press_this} {reply}"));
|
2024-03-20 01:03:42 +00:00
|
|
|
count += 1;
|
|
|
|
}
|
2024-03-21 05:04:06 +00:00
|
|
|
if count < 4 {
|
|
|
|
for _padding in 0..(4-count) {
|
|
|
|
choices.push(" ".to_string());
|
|
|
|
}
|
|
|
|
chat.sections[2].value = choices.join("\n");
|
|
|
|
}
|
2024-03-20 01:03:42 +00:00
|
|
|
|
|
|
|
// Chat Log and System Log
|
2024-03-19 02:18:16 +00:00
|
|
|
let logfilter = if settings.hud_active {
|
|
|
|
|_msg: &&Message| { true }
|
|
|
|
} else {
|
|
|
|
|msg: &&Message| { match msg.level {
|
|
|
|
LogLevel::Chat => true,
|
|
|
|
LogLevel::Warning => true,
|
2024-03-21 05:04:06 +00:00
|
|
|
LogLevel::Info => true,
|
|
|
|
//_ => false
|
2024-03-19 02:18:16 +00:00
|
|
|
}}
|
|
|
|
};
|
|
|
|
let logs_vec: Vec<String> = log.logs.iter()
|
|
|
|
.filter(logfilter)
|
|
|
|
.map(|s| format!("{}: {}", s.sender, s.text)).collect();
|
|
|
|
chat.sections[0].value = logs_vec.join("\n");
|
2024-03-17 23:36:56 +00:00
|
|
|
}
|
2024-03-19 02:18:16 +00:00
|
|
|
log.needs_rerendering = false;
|
2024-03-18 00:02:17 +00:00
|
|
|
log.remove_old();
|
2024-03-17 14:23:22 +00:00
|
|
|
}
|
|
|
|
}
|
2024-03-17 18:03:02 +00:00
|
|
|
|
|
|
|
fn handle_input(
|
|
|
|
keyboard_input: Res<ButtonInput<KeyCode>>,
|
2024-03-18 02:01:47 +00:00
|
|
|
mut settings: ResMut<settings::Settings>,
|
2024-03-17 20:29:27 +00:00
|
|
|
mut query: Query<&mut Visibility, With<GaugesText>>,
|
2024-03-18 13:08:11 +00:00
|
|
|
mut query_bloomsettings: Query<&mut BloomSettings>,
|
2024-03-20 01:03:42 +00:00
|
|
|
mut evwriter_sendmsg: EventWriter<actor::SendMessageEvent>,
|
2024-03-19 02:18:16 +00:00
|
|
|
mut evwriter_sfx: EventWriter<audio::PlaySfxEvent>,
|
2024-03-18 02:01:47 +00:00
|
|
|
mut evwriter_togglemusic: EventWriter<audio::ToggleMusicEvent>,
|
2024-03-20 01:03:42 +00:00
|
|
|
q_choices: Query<&ChoiceAvailable>,
|
2024-03-20 05:55:54 +00:00
|
|
|
mut ambient_light: ResMut<AmbientLight>,
|
2024-03-17 18:03:02 +00:00
|
|
|
) {
|
|
|
|
if keyboard_input.just_pressed(settings.key_togglehud) {
|
2024-03-19 02:18:16 +00:00
|
|
|
if let Ok(mut vis) = query.get_single_mut() {
|
2024-03-18 13:08:11 +00:00
|
|
|
if let Ok(mut bloomsettings) = query_bloomsettings.get_single_mut() {
|
2024-03-18 03:57:17 +00:00
|
|
|
if *vis == Visibility::Inherited {
|
|
|
|
*vis = Visibility::Hidden;
|
|
|
|
settings.hud_active = false;
|
2024-03-20 05:55:54 +00:00
|
|
|
ambient_light.brightness = AMBIENT_LIGHT;
|
2024-03-18 13:08:11 +00:00
|
|
|
bloomsettings.composite_mode = BloomCompositeMode::EnergyConserving;
|
2024-03-18 03:57:17 +00:00
|
|
|
} else {
|
|
|
|
*vis = Visibility::Inherited;
|
|
|
|
settings.hud_active = true;
|
2024-03-20 05:55:54 +00:00
|
|
|
ambient_light.brightness = AMBIENT_LIGHT_AR;
|
2024-03-19 02:18:16 +00:00
|
|
|
bloomsettings.composite_mode = BloomCompositeMode::EnergyConserving;
|
|
|
|
//bloomsettings.composite_mode = BloomCompositeMode::Additive;
|
2024-03-18 03:57:17 +00:00
|
|
|
}
|
2024-03-19 02:18:16 +00:00
|
|
|
evwriter_sfx.send(audio::PlaySfxEvent(audio::Sfx::Switch));
|
2024-03-18 03:57:17 +00:00
|
|
|
evwriter_togglemusic.send(audio::ToggleMusicEvent());
|
2024-03-18 13:08:11 +00:00
|
|
|
}
|
2024-03-17 18:03:02 +00:00
|
|
|
}
|
|
|
|
}
|
2024-03-20 01:03:42 +00:00
|
|
|
|
|
|
|
let mut selected_choice = 1;
|
|
|
|
'outer: for key in settings.get_reply_keys() {
|
|
|
|
if keyboard_input.just_pressed(key) {
|
|
|
|
let mut count = 1;
|
|
|
|
for choice in &q_choices {
|
|
|
|
if count == selected_choice {
|
|
|
|
evwriter_sfx.send(audio::PlaySfxEvent(audio::Sfx::Click));
|
|
|
|
evwriter_sendmsg.send(actor::SendMessageEvent {
|
|
|
|
conv_id: choice.conv_id.clone(),
|
|
|
|
conv_label: choice.conv_label.clone(),
|
|
|
|
text: choice.text.clone(),
|
|
|
|
});
|
|
|
|
break 'outer;
|
|
|
|
}
|
|
|
|
count += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
selected_choice += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn despawn_old_choices(
|
|
|
|
mut commands: Commands,
|
|
|
|
q_conv: Query<&actor::Chat>,
|
|
|
|
q_choices: Query<(Entity, &ChoiceAvailable)>,
|
|
|
|
) {
|
|
|
|
let chats: Vec<&actor::Chat> = q_conv.iter().collect();
|
|
|
|
'outer: for (entity, choice) in &q_choices {
|
|
|
|
// Let's see if this choice still has a chat in the appropriate state
|
|
|
|
for chat in &chats {
|
|
|
|
if choice.conv_id == chat.id && choice.conv_label == chat.label {
|
|
|
|
continue 'outer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Despawn the choice, since no matching chat was found
|
|
|
|
commands.entity(entity).despawn();
|
|
|
|
}
|
2024-03-17 18:03:02 +00:00
|
|
|
}
|