konnektoren_bevy/screens/settings/
plugin.rs1use super::*;
2use bevy::prelude::*;
3
4pub struct SettingsScreenPlugin;
6
7impl Plugin for SettingsScreenPlugin {
8 fn build(&self, app: &mut App) {
9 app.add_event::<SettingsScreenEvent>()
10 .add_event::<ComponentSettingsEvent>()
11 .add_systems(
12 Update,
13 (
14 check_settings_screen_config,
15 handle_settings_screen_events,
16 update_settings_screen_values,
17 cleanup_component_settings,
18 ),
19 )
20 .add_systems(bevy_egui::EguiContextPass, render_settings_screen_ui)
21 .add_plugins(InputConfigurationPlugin);
23
24 #[cfg(feature = "settings")]
26 {
27 app.add_systems(
28 Update,
29 (check_component_settings, process_pending_setting_updates),
30 )
31 .add_systems(bevy_egui::EguiContextPass, render_component_settings_ui);
32 }
33 }
34}
35
36pub trait SettingsScreenExt {
38 fn spawn_settings_screen(&mut self, config: SettingsScreenConfig) -> Entity;
40
41 fn spawn_simple_settings_screen(&mut self, title: impl Into<String>) -> Entity;
43
44 fn spawn_component_settings_screen(&mut self, title: impl Into<String>) -> Entity;
46
47 fn spawn_input_configuration(&mut self, max_players: u32) -> Entity;
49}
50
51impl SettingsScreenExt for Commands<'_, '_> {
52 fn spawn_settings_screen(&mut self, config: SettingsScreenConfig) -> Entity {
53 self.spawn((Name::new("Settings Screen"), config)).id()
54 }
55
56 fn spawn_simple_settings_screen(&mut self, title: impl Into<String>) -> Entity {
57 let audio_section = SettingsSection::audio_section();
58 let config = SettingsScreenConfig::new(title).add_section(audio_section);
59 self.spawn_settings_screen(config)
60 }
61
62 fn spawn_component_settings_screen(&mut self, title: impl Into<String>) -> Entity {
63 self.spawn((
64 Name::new("Component-Based Settings Trigger"),
65 ActiveComponentSettings {
66 title: title.into(),
67 allow_dismissal: true,
68 back_button_text: "Back".to_string(),
69 navigation_state: ComponentSettingsNavigationState::default(),
70 },
71 ))
72 .id()
73 }
74
75 fn spawn_input_configuration(&mut self, max_players: u32) -> Entity {
76 self.spawn((
77 Name::new("Input Configuration Screen"),
78 ActiveInputConfiguration {
79 max_players,
80 current_players: max_players.min(4), },
82 ))
83 .id()
84 }
85}