//bevy system signatures often violate these rules #![allow(clippy::type_complexity)] #![allow(clippy::too_many_arguments)] use bevy::{audio::Volume, prelude::*}; use bevy_egui::{ EguiContexts, EguiPrimaryContextPass, PrimaryEguiContext, egui::{self, Align2, RichText}, }; use combat::Difficulty; use state::AppState; pub struct UiMenuPlugin; impl Plugin for UiMenuPlugin { fn build(&self, app: &mut App) { app.add_systems(OnEnter(AppState::Menu), setup_menu) .add_systems( EguiPrimaryContextPass, ( main_screen.run_if(in_state(MenuScreen::Main)), difficulty_screen.run_if(in_state(MenuScreen::Difficulty)), info_screen.run_if(in_state(MenuScreen::Info)), settings_screen.run_if(in_state(MenuScreen::Settings)), ), ) .add_sub_state::(); } } const VERY_LARGE_FONT_SIZE: f32 = 48.; const FONT_SIZE: f32 = 16.; #[derive(Debug, Clone, Eq, PartialEq, Hash, SubStates, Default)] #[source(AppState = AppState::Menu)] enum MenuScreen { #[default] Main, Info, Difficulty, Settings, } fn setup_menu(mut commands: Commands) { commands.spawn(( StateScoped(AppState::Menu), Camera3d::default(), Camera { hdr: true, ..default() }, PrimaryEguiContext, Transform::default(), )); } fn main_screen(mut contexts: EguiContexts, mut next_screen: ResMut>) { let ctx = contexts.ctx_mut().unwrap(); egui::Window::new("Title") .resizable(false) .collapsible(false) .title_bar(false) .anchor(Align2::CENTER_TOP, [0., 48.]) .fixed_size([600., 100.]) .show(ctx, |ui| { ui.label(RichText::new("COREHEART").size(72.)); }); egui::Window::new("MainScreen") .resizable(false) .collapsible(false) .title_bar(false) .anchor(Align2::CENTER_CENTER, [0., 0.]) .fixed_size([600., 100.]) .show(ctx, |ui| { ui.centered_and_justified(|ui| { if ui .button(RichText::new("CONNECT").size(VERY_LARGE_FONT_SIZE)) .clicked() { next_screen.set(MenuScreen::Difficulty); } }); ui.centered_and_justified(|ui| { if ui .button(RichText::new("INFO").size(VERY_LARGE_FONT_SIZE)) .clicked() { next_screen.set(MenuScreen::Info); } }); ui.centered_and_justified(|ui| { if ui .button(RichText::new("SETTINGS").size(VERY_LARGE_FONT_SIZE)) .clicked() { next_screen.set(MenuScreen::Settings); } }); }); } fn difficulty_screen( mut contexts: EguiContexts, mut next_screen: ResMut>, mut next_state: ResMut>, mut difficulty: ResMut, ) { let ctx = contexts.ctx_mut().unwrap(); egui::Window::new("DifficultyScreen") .resizable(false) .collapsible(false) .title_bar(false) .anchor(Align2::CENTER_CENTER, [0., 0.]) .fixed_size([600., 100.]) .show(ctx, |ui| { ui.columns(2, |columns| { if columns[0] .button(RichText::new("STANDARD").size(VERY_LARGE_FONT_SIZE)) .clicked() { *difficulty = Difficulty::Standard; next_state.set(AppState::Game); } columns[1].label("The intended experience, which is quite difficult.") }); ui.centered_and_justified(|ui| { ui.label("——————————"); }); ui.columns(2, |columns| { if columns[0] .button(RichText::new("CHILL").size(VERY_LARGE_FONT_SIZE)) .clicked() { *difficulty = Difficulty::Chill; next_state.set(AppState::Game); } columns[1].label( "Enemies deal significantly less damage. Good to chill and check out the game!", ) }); ui.columns(2, |columns| { if columns[0] .button(RichText::new("CASUAL").size(VERY_LARGE_FONT_SIZE)) .clicked() { *difficulty = Difficulty::Casual; next_state.set(AppState::Game); } columns[1].label( "Enemies deal less damage. Good for players who don't want to sweat as much.", ) }); ui.columns(2, |columns| { if columns[0] .button(RichText::new("INSTENSE").size(VERY_LARGE_FONT_SIZE)) .clicked() { *difficulty = Difficulty::Intense; next_state.set(AppState::Game); } columns[1].label("Enemies deal more damage. Significantly harder.") }); }); egui::Window::new("DifficultyBack") .resizable(false) .collapsible(false) .title_bar(false) .anchor(Align2::LEFT_TOP, [0., 0.]) .show(ctx, |ui| { if ui .button(RichText::new("BACK").size(VERY_LARGE_FONT_SIZE)) .clicked() { next_screen.set(MenuScreen::Main); } }); } fn info_screen(mut contexts: EguiContexts, mut next_screen: ResMut>) { let ctx = contexts.ctx_mut().unwrap(); egui::Window::new("InfoScreen") .resizable(false) .collapsible(false) .title_bar(false) .anchor(Align2::CENTER_CENTER, [0., 0.]) .fixed_size([800., 100.]) .show(ctx, |ui| { ui.label(RichText::new("You must place the Core and increase its reach as much as possible. Keep the Core alive as long as you can.\n").size(FONT_SIZE)); ui.label(RichText::new("Left click and drag to move the camera around. Middle click to rotate the camera. \nRight click to place buildings. Left click to view information about objects. \nEscape will cancel your current selection or pause the game.\n").size(FONT_SIZE)); ui.label(RichText::new("You will see different boxes places on the map. You can asssign workers to harvest them for resources. Upgrading the Core will form more workers to gather more resources.\n").size(FONT_SIZE)); ui.label(RichText::new("Upgrading towers increases their strength dramatically and heals them.\n").size(FONT_SIZE)); ui.label(RichText::new("Defeating an Inhabitants will grant you its soul. Use these, along with the bones you harvest from the environment, to build your strength. \n\n").size(FONT_SIZE)); ui.label(RichText::new("TIP: Holding shift allows you to place multiple buildings. It is very nice.").size(FONT_SIZE)); }); egui::Window::new("InfoBack") .resizable(false) .collapsible(false) .title_bar(false) .anchor(Align2::LEFT_TOP, [0., 0.]) .show(ctx, |ui| { if ui .button(RichText::new("BACK").size(VERY_LARGE_FONT_SIZE)) .clicked() { next_screen.set(MenuScreen::Main); } }); } fn settings_screen( mut contexts: EguiContexts, mut next_screen: ResMut>, mut global_volume: ResMut, mut volume: Local, mut init: Local, ) { if !*init { *init = true; *volume = 100.; } let ctx = contexts.ctx_mut().unwrap(); egui::Window::new("SettingsScreen") .resizable(false) .collapsible(false) .title_bar(false) .anchor(Align2::CENTER_CENTER, [0., 0.]) .fixed_size([800., 100.]) .show(ctx, |ui| { ui.label(RichText::new("Volume").size(FONT_SIZE)); ui.add(egui::Slider::new(&mut *volume, 0.0..=100.)); global_volume.volume = Volume::Linear(*volume / 100.); }); egui::Window::new("SettingsBack") .resizable(false) .collapsible(false) .title_bar(false) .anchor(Align2::LEFT_TOP, [0., 0.]) .show(ctx, |ui| { if ui .button(RichText::new("BACK").size(VERY_LARGE_FONT_SIZE)) .clicked() { next_screen.set(MenuScreen::Main); } }); }