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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//! Main menu systems.
use bevy::prelude::*;
use game_library::font_resource::FontResource;
use game_library::state::AppState;

use crate::resources::style_prefab;

use super::{
    base::SettingsMenuEntity,
    button_actions::{ButtonAction, SettingsMenuButton},
};

/// Tags for the (main) menu buttons/text/etc.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Component)]
pub struct BaseSettingsMenuEntity;

/// Show the main menu.
#[allow(clippy::too_many_lines)]
pub fn show_main_menu(
    mut commands: Commands,
    fonts: Res<FontResource>,
    current_state: Res<State<AppState>>,
) {
    commands
        .spawn((
            style_prefab::settings_menu_full_node_bundle(),
            BaseSettingsMenuEntity,
            SettingsMenuEntity,
        ))
        .with_children(|parent| {
            // Game Title
            parent.spawn(style_prefab::settings_menu_title_bundle(
                "Settings",
                fonts.display_font.clone(),
            ));
            // #### MENU BUTTONS #####
            parent
                .spawn(style_prefab::settings_menu_column_node_bundle())
                .with_children(|menu_buttons| {
                    // Audio button
                    menu_buttons
                        .spawn((
                            style_prefab::menu_button_bundle(),
                            ButtonAction::SettingsAudio,
                            SettingsMenuButton,
                        ))
                        .with_children(|button| {
                            button.spawn(style_prefab::menu_button_text(
                                "Audio",
                                fonts.interface_font.clone(),
                            ));
                        });
                    // Video button
                    menu_buttons
                        .spawn((
                            style_prefab::menu_button_bundle(),
                            ButtonAction::SettingsDisplay,
                            SettingsMenuButton,
                        ))
                        .with_children(|button| {
                            button.spawn(style_prefab::menu_button_text(
                                "Video",
                                fonts.interface_font.clone(),
                            ));
                        });
                    // Controls button
                    menu_buttons
                        .spawn((
                            style_prefab::menu_button_bundle(),
                            ButtonAction::SettingsControls,
                            SettingsMenuButton,
                        ))
                        .with_children(|button| {
                            button.spawn(style_prefab::menu_button_text(
                                "Controls",
                                fonts.interface_font.clone(),
                            ));
                        });
                    // Gameplay button
                    menu_buttons
                        .spawn((
                            style_prefab::menu_button_bundle(),
                            ButtonAction::SettingsGameplay,
                            SettingsMenuButton,
                        ))
                        .with_children(|button| {
                            button.spawn(style_prefab::menu_button_text(
                                "Gameplay",
                                fonts.interface_font.clone(),
                            ));
                        });
                    // Accessibility button
                    menu_buttons
                        .spawn((
                            style_prefab::menu_button_bundle(),
                            ButtonAction::SettingsAccessibility,
                            SettingsMenuButton,
                        ))
                        .with_children(|button| {
                            button.spawn(style_prefab::menu_button_text(
                                "Accessibility",
                                fonts.interface_font.clone(),
                            ));
                        });
                    // Back button (=> return to where we came from)
                    menu_buttons
                        .spawn((
                            style_prefab::menu_button_bundle(),
                            ButtonAction::CloseMenu,
                            SettingsMenuButton,
                        ))
                        .with_children(|button| {
                            button.spawn(style_prefab::menu_button_text(
                                "Back",
                                fonts.interface_font.clone(),
                            ));
                        });
                    // Back to MainMenu (show when we came from InGame)
                    if *current_state == AppState::InGame {
                        menu_buttons
                            .spawn((
                                style_prefab::menu_button_bundle(),
                                ButtonAction::GoToMainGameMenu,
                                SettingsMenuButton,
                            ))
                            .with_children(|button| {
                                button.spawn(style_prefab::menu_button_text(
                                    "Quit to Main Menu",
                                    fonts.interface_font.clone(),
                                ));
                            });
                    }
                });
        });
}