diff --git a/Cargo.lock b/Cargo.lock index c6c45a6..6421221 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -5310,6 +5310,7 @@ dependencies = [ "bevy", "bevy_egui", "building", + "building_core", "building_placement", "combat", "input", diff --git a/assets/settings/input_map.ron b/assets/settings/input_map.ron index b82ce27..03d50a5 100755 --- a/assets/settings/input_map.ron +++ b/assets/settings/input_map.ron @@ -1,22 +1,22 @@ ( map: { - MouseButton(Middle): [ - CameraOrbitEnable, - ], KeyCode(ShiftLeft): [ MultiPlaceTower, ], - KeyCode(F1): [ - ToggleDebugUI, - ], MouseButton(Right): [ PlaceTower, ], + MouseButton(Left): [ + CameraPanEnable, + ], + MouseButton(Middle): [ + CameraOrbitEnable, + ], MouseScroll: [ CameraZoom, ], - MouseButton(Left): [ - CameraPanEnable, + KeyCode(F1): [ + ToggleDebugUI, ], MouseMovementX: [ CameraYaw, diff --git a/crates/building_core/src/lib.rs b/crates/building_core/src/lib.rs index 34528fa..e1dfca8 100755 --- a/crates/building_core/src/lib.rs +++ b/crates/building_core/src/lib.rs @@ -5,6 +5,7 @@ use bevy::prelude::*; use building::{BuildingInfo, BuildingPreview, Core, PREVIEW_ALPHA, PopulatePlacedBuilding}; use combat::{Defense, Health, Range}; +use state::CoreState; use ui_range_indicator::CustomRangeIndicator; pub struct BuildingCorePlugin; @@ -22,6 +23,9 @@ struct CoreResources { info_entity: Entity, } +#[derive(Component)] +pub struct CorePreview; + const SIZE: UVec3 = UVec3::new(2, 2, 2); fn register( @@ -50,6 +54,7 @@ fn register( Visibility::Hidden, Mesh3d(mesh.clone()), MeshMaterial3d(preview_material), + CorePreview, )) .id(); commands.entity(info).insert(( @@ -74,6 +79,7 @@ fn populate( trigger: Trigger, mut commands: Commands, mut materials: ResMut>, + mut next_core_state: ResMut>, res: Res, ) { if trigger.event().info != res.info_entity { @@ -91,4 +97,5 @@ fn populate( ..default() })), )); + next_core_state.set(CoreState::Placed); } diff --git a/crates/level/src/lib.rs b/crates/level/src/lib.rs index c0fa77e..ded9b89 100755 --- a/crates/level/src/lib.rs +++ b/crates/level/src/lib.rs @@ -12,7 +12,6 @@ use bevy::{ render::camera::Exposure, }; use bevy_egui::PrimaryEguiContext; -use building::{BuildingTypes, PlaceBuilding}; use camera::ControlledCamera; use inhabitant::Inhabitant; use inhabitant_coranth::SpawnCoranth; @@ -54,8 +53,6 @@ fn setup( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, - buildings: Res, - mut place_writer: EventWriter, mut coranth_writer: EventWriter, mut graveyard_writer: EventWriter, ) { @@ -85,11 +82,6 @@ fn setup( graveyard_writer.write(PlaceGraveyard(Vec3::new(-10., 0.25, -10.))); - place_writer.write(PlaceBuilding { - info: buildings.info.get("Core").unwrap().0, - location: IVec3 { x: 5, y: 0, z: 5 }, - }); - // Light commands.spawn(( DirectionalLight { diff --git a/crates/state/src/lib.rs b/crates/state/src/lib.rs index 685f058..5159158 100755 --- a/crates/state/src/lib.rs +++ b/crates/state/src/lib.rs @@ -13,6 +13,7 @@ impl Plugin for StatePlugin { .enable_state_scoped_entities::() .add_sub_state::() .add_sub_state::() + .add_sub_state::() .enable_state_scoped_entities::() .add_computed_state::() .configure_sets( @@ -112,17 +113,31 @@ pub enum Phase { } impl ComputedStates for Phase { - type SourceStates = (BasePhaseState, GameState); + type SourceStates = (BasePhaseState, GameState, CoreState); fn compute(sources: Self::SourceStates) -> Option { match sources { - (_, GameState::Loading) | (_, GameState::Paused) => None, - (BasePhaseState::Execute { .. }, GameState::Running) => Some(Self::Execute), - (BasePhaseState::Plan { .. }, GameState::Running) => Some(Self::Plan), + (_, GameState::Loading, _) | (_, GameState::Paused, _) => None, + (_, _, CoreState::Dead) | (_, _, CoreState::Unplaced) => None, + (BasePhaseState::Execute { .. }, GameState::Running, CoreState::Placed) => { + Some(Self::Execute) + } + (BasePhaseState::Plan { .. }, GameState::Running, CoreState::Placed) => { + Some(Self::Plan) + } } } } +#[derive(Default, Debug, Clone, Eq, PartialEq, Hash, SubStates)] +#[source(AppState = AppState::Game)] +pub enum CoreState { + #[default] + Unplaced, + Placed, + Dead, +} + #[derive(SystemSet, Debug, Hash, PartialEq, Eq, Clone)] pub enum GameSystemSet { // fixed update - contains all gameplay logic. does not run when game is paused diff --git a/crates/ui_ingame/Cargo.toml b/crates/ui_ingame/Cargo.toml index df537fe..a3f6e45 100644 --- a/crates/ui_ingame/Cargo.toml +++ b/crates/ui_ingame/Cargo.toml @@ -13,6 +13,7 @@ resources = { path = "../resources" } building = { path = "../building" } input = { path = "../input" } building_placement = { path = "../building_placement" } +building_core = { path = "../building_core" } upgrade = { path = "../upgrade" } combat = { path = "../combat" } diff --git a/crates/ui_ingame/src/lib.rs b/crates/ui_ingame/src/lib.rs index 2400869..98bd049 100644 --- a/crates/ui_ingame/src/lib.rs +++ b/crates/ui_ingame/src/lib.rs @@ -10,11 +10,12 @@ use bevy_egui::{ egui::{self, Align2, RichText}, }; use building::{BuildingInfo, Core}; +use building_core::CorePreview; use building_placement::SelectBuildingPreview; use combat::Range; use input::{SelectEntity, Selected}; use resources::{AvailableWorkers, Cost, ResourceDeposit, Resources, WorkedResourceDeposit}; -use state::{BasePhaseState, Phase}; +use state::{BasePhaseState, CoreState, Phase}; use ui_state::GameUIState; use upgrade::{UnlockUpgrade, Upgradable, Upgrade}; @@ -27,7 +28,10 @@ impl Plugin for UiIngamePlugin { .add_systems( EguiPrimaryContextPass, ( - side_panel.run_if(in_state(GameUIState::Default)), + place_core + .run_if(in_state(GameUIState::Default).and(in_state(CoreState::Unplaced))), + side_panel + .run_if(in_state(GameUIState::Default).and(in_state(CoreState::Placed))), plan_ui.run_if(in_state(GameUIState::Default).and(in_state(Phase::Plan))), execute_ui.run_if(in_state(GameUIState::Default).and(in_state(Phase::Execute))), transition_ui.run_if( @@ -56,6 +60,7 @@ impl Plugin for UiIngamePlugin { } } +const VERY_LARGE_FONT_SIZE: f32 = 48.; const LARGE_FONT_SIZE: f32 = 24.; const FONT_SIZE: f32 = 16.; @@ -80,7 +85,7 @@ fn plan_ui( .anchor(Align2::CENTER_BOTTOM, [0., 0.]) .show(ctx, |ui| { if ui - .button(RichText::new("EXECUTE").size(LARGE_FONT_SIZE)) + .button(RichText::new("EXECUTE").size(VERY_LARGE_FONT_SIZE)) .clicked() { next_phase.set(BasePhaseState::Execute { @@ -334,3 +339,21 @@ fn side_panel( } }); } + +fn place_core( + mut contexts: EguiContexts, + mut selected_preview_writer: EventWriter, + core_preview: Single>, +) { + let ctx = contexts.ctx_mut().unwrap(); + egui::Window::new("PlaceCore") + .resizable(false) + .collapsible(false) + .title_bar(false) + .anchor(Align2::CENTER_BOTTOM, [0., 0.]) + .show(ctx, |ui| { + if ui.button(RichText::new("COLONIZE").size(64.)).clicked() { + selected_preview_writer.write(SelectBuildingPreview(Some(*core_preview))); + } + }); +} diff --git a/crates/ui_pause/src/lib.rs b/crates/ui_pause/src/lib.rs index 41681a8..4680390 100755 --- a/crates/ui_pause/src/lib.rs +++ b/crates/ui_pause/src/lib.rs @@ -39,11 +39,15 @@ fn pause_screen(mut contexts: EguiContexts) { fn toggle_pause( state: Res>, + mut removed_cancellations: RemovedComponents, mut next_state: ResMut>, query: Query<(), With>, ) { - if !query.is_empty() { + // sometimes race condition can happen where the cancellable component gets cancelled before this system runs + // instead of actually scheduling systems, I will just do this. + if !query.is_empty() || !removed_cancellations.is_empty() { // cancelling takes priority over pausing + removed_cancellations.clear(); return; } let next = match state.get() {