1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use bevy::{color::palettes::css::BLACK, prelude::*, window::PrimaryWindow};
use bevy_lunex::{prelude::*, Base};

use crate::widgets::{
    panel::components::Panel,
    slider::components::{Knob, Rack},
};

use super::{
    components::{SettingsPanel, SettingsPg, SettingsPgUi},
    resources::Settings,
};

pub fn build_settings(
    mut commands: Commands,
    asset_server: Res<AssetServer>,
    window: Query<&Window, With<PrimaryWindow>>,

    query: Query<Entity, Added<SettingsPg>>,
) {
        for route_entity in &query {
            if let Ok(resolution) = window.get_single() {
                let r_size = (resolution.width(), resolution.height());
                commands
                    .entity(route_entity)
                    .insert(SpatialBundle::default())
                    .with_children(|route| {
                        route
                            .spawn((
                                UiTreeBundle::<MainUi>::from(UiTree::new2d("MainMenu")),
                                MovableByCamera,
                            ))
                            .with_children(|ui| {
                                let root = UiLink::<MainUi>::path("Root");
                                ui.spawn((
                                    root.clone(),
                                    UiLayout::window().size(r_size).pack::<Base>(),
                                ));
                                let background = UiLink::<SettingsPgUi>::path("Background");
                                ui.spawn((
                                    background.clone(),
                                    UiLayout::window_full().pack::<Base>(),
                                    Pickable::IGNORE,
                                    UiImage2dBundle::from(
                                        asset_server.load("Level_base_diffuse.png"),
                                    ),
                                ));
                                ui.spawn((
                                    background.add("Panel"),
                                    UiLayout::window()
                                        .size(Rl((40.0, 80.0)))
                                        .pos(Rl((10.0, 10.0)))
                                        .pack::<Base>(),
                                    Panel {
                                        text: Some("Settings".to_string()),
                                        color: BLACK.into(),
                                        ..default()
                                    },
                                    SettingsPanel,
                                    Pickable::IGNORE,
                                ));
                            });
                    });
            }
        }
    }


pub fn init_settings(
    mut commands: Commands,
    panel: Query<Entity, Added<SettingsPanel>>,
    settings: Res<Settings>,
) {
    let mut knobs = vec![];
    for p in &panel {
        for (label, value) in settings.sound_settings.iter() {
            knobs.push(
                commands
                    .spawn(Knob {
                        index_tag: label.to_string(),
                        value: *value,
                    })
                    .id(),
            );
        }
        commands.entity(p).insert_children(0, &knobs);
    }
}