diff --git a/Cargo.lock b/Cargo.lock index 4603a8f..e6731dc 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -2056,6 +2056,7 @@ dependencies = [ "ui_debug", "ui_health_bar", "ui_ingame", + "ui_menu", "ui_pause", "ui_range_indicator", "ui_state", @@ -5403,6 +5404,16 @@ dependencies = [ "upgrade", ] +[[package]] +name = "ui_menu" +version = "0.1.0" +dependencies = [ + "bevy", + "bevy_egui", + "combat", + "state", +] + [[package]] name = "ui_pause" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index f3664d2..31dc002 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,4 +63,5 @@ inhabitant_endrake = { path = "crates/inhabitant_endrake" } resource_soul_spot = { path = "crates/resource_soul_spot" } building_ramtower = { path = "crates/building_ramtower" } building_suncannon = { path = "crates/building_suncannon" } +ui_menu = { path = "crates/ui_menu" } #new internal crates go here diff --git a/assets/settings/input_map.ron b/assets/settings/input_map.ron index b82ce27..954bb8b 100755 --- a/assets/settings/input_map.ron +++ b/assets/settings/input_map.ron @@ -1,11 +1,11 @@ ( map: { - MouseButton(Middle): [ - CameraOrbitEnable, - ], KeyCode(ShiftLeft): [ MultiPlaceTower, ], + MouseButton(Middle): [ + CameraOrbitEnable, + ], KeyCode(F1): [ ToggleDebugUI, ], diff --git a/crates/level/src/lib.rs b/crates/level/src/lib.rs index 7ba61ff..839d1e8 100755 --- a/crates/level/src/lib.rs +++ b/crates/level/src/lib.rs @@ -129,6 +129,7 @@ fn setup( // Camera commands.spawn(( + StateScoped(AppState::Game), Camera3d::default(), Camera { hdr: true, diff --git a/crates/setup/src/lib.rs b/crates/setup/src/lib.rs index 235a4a7..9055e9b 100755 --- a/crates/setup/src/lib.rs +++ b/crates/setup/src/lib.rs @@ -36,7 +36,7 @@ fn start_loading(mut next_state: ResMut>) { fn finish_loading(mut next_state: ResMut>) { info!("finished loading"); - next_state.set(AppState::Game); + next_state.set(AppState::Menu); } #[derive(Debug, Clone, Eq, PartialEq, Hash, SubStates, Default)] diff --git a/crates/ui_menu/Cargo.toml b/crates/ui_menu/Cargo.toml new file mode 100644 index 0000000..e6f385e --- /dev/null +++ b/crates/ui_menu/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "ui_menu" +version = "0.1.0" +edition = "2024" + +[dependencies] +bevy = { workspace = true } +bevy_egui = { workspace = true } +state = { path = "../state" } +combat = { path = "../combat" } + +[lints] +workspace = true diff --git a/crates/ui_menu/src/lib.rs b/crates/ui_menu/src/lib.rs new file mode 100644 index 0000000..c0c323f --- /dev/null +++ b/crates/ui_menu/src/lib.rs @@ -0,0 +1,247 @@ +//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); + } + }); +} diff --git a/src/main.rs b/src/main.rs index 25a6baf..a4a54ef 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,6 +46,7 @@ fn main() { ), building_ramtower::BuildingRamtowerPlugin, building_suncannon::BuildingSuncannonPlugin, + ui_menu::UiMenuPlugin, // new internal crates go here )); diff --git a/todo.txt b/todo.txt index 40816a7..70ffa49 100644 --- a/todo.txt +++ b/todo.txt @@ -3,7 +3,7 @@ - sound - music x limit workers per resource deposit -- main menu +x main menu x improve enemy AI x balance (maybe) @@ -12,7 +12,7 @@ x More towers x More upgrades x More enemy types x More resource deposit types -- Improve wave generation +x Improve wave generation --- STILL PRETTY IMPORTANT --- ~~Building repair: actually not doing this as it would be very hard to balance~~