From e9379a6a945596cc21211b23a7cf35694ea22d19 Mon Sep 17 00:00:00 2001 From: Jim Date: Mon, 1 Sep 2025 22:05:18 -0400 Subject: [PATCH] add game_over --- assets/settings/input_map.ron | 8 +++---- crates/building_core/src/lib.rs | 40 +++++++++++++++++++++------------ crates/state/src/lib.rs | 7 ++++-- crates/ui_ingame/src/lib.rs | 24 +++++++++++++++++--- crates/ui_pause/src/lib.rs | 1 + 5 files changed, 57 insertions(+), 23 deletions(-) diff --git a/assets/settings/input_map.ron b/assets/settings/input_map.ron index 03d50a5..ed21f50 100755 --- a/assets/settings/input_map.ron +++ b/assets/settings/input_map.ron @@ -1,7 +1,7 @@ ( map: { - KeyCode(ShiftLeft): [ - MultiPlaceTower, + MouseButton(Middle): [ + CameraOrbitEnable, ], MouseButton(Right): [ PlaceTower, @@ -9,8 +9,8 @@ MouseButton(Left): [ CameraPanEnable, ], - MouseButton(Middle): [ - CameraOrbitEnable, + KeyCode(ShiftLeft): [ + MultiPlaceTower, ], MouseScroll: [ CameraZoom, diff --git a/crates/building_core/src/lib.rs b/crates/building_core/src/lib.rs index e1dfca8..4f53f26 100755 --- a/crates/building_core/src/lib.rs +++ b/crates/building_core/src/lib.rs @@ -4,8 +4,8 @@ use bevy::prelude::*; use building::{BuildingInfo, BuildingPreview, Core, PREVIEW_ALPHA, PopulatePlacedBuilding}; -use combat::{Defense, Health, Range}; -use state::CoreState; +use combat::{Defense, Died, Health, Range}; +use state::{CoreState, GameState}; use ui_range_indicator::CustomRangeIndicator; pub struct BuildingCorePlugin; @@ -85,17 +85,29 @@ fn populate( if trigger.event().info != res.info_entity { return; } - commands.entity(trigger.target()).insert(( - Core, - Mesh3d(res.mesh.clone()), - MeshMaterial3d(res.material.clone()), - CustomRangeIndicator::new(materials.add(StandardMaterial { - alpha_mode: AlphaMode::Blend, - base_color: Color::srgba(0.6, 0.2, 0.2, 0.4), - unlit: true, - double_sided: true, - ..default() - })), - )); + commands + .entity(trigger.target()) + .insert(( + Core, + Mesh3d(res.mesh.clone()), + MeshMaterial3d(res.material.clone()), + CustomRangeIndicator::new(materials.add(StandardMaterial { + alpha_mode: AlphaMode::Blend, + base_color: Color::srgba(0.6, 0.2, 0.2, 0.4), + unlit: true, + double_sided: true, + ..default() + })), + )) + .observe(core_dead); next_core_state.set(CoreState::Placed); } + +fn core_dead( + _trigger: Trigger, + mut next_core_state: ResMut>, + mut next_game_state: ResMut>, +) { + next_core_state.set(CoreState::Dead); + next_game_state.set(GameState::GameOver); +} diff --git a/crates/state/src/lib.rs b/crates/state/src/lib.rs index 5159158..f4bb35b 100755 --- a/crates/state/src/lib.rs +++ b/crates/state/src/lib.rs @@ -73,13 +73,14 @@ pub enum AppState { Game, } -#[derive(Debug, Clone, Eq, PartialEq, Hash, SubStates, Default)] +#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, SubStates, Default)] #[source(AppState = AppState::Game)] pub enum GameState { Loading, #[default] Running, Paused, + GameOver, } /// this is what you should set to change the state. do not read this for scheduling @@ -117,7 +118,9 @@ impl ComputedStates for Phase { fn compute(sources: Self::SourceStates) -> Option { match sources { - (_, GameState::Loading, _) | (_, GameState::Paused, _) => None, + (_, GameState::Loading, _) + | (_, GameState::Paused, _) + | (_, GameState::GameOver, _) => None, (_, _, CoreState::Dead) | (_, _, CoreState::Unplaced) => None, (BasePhaseState::Execute { .. }, GameState::Running, CoreState::Placed) => { Some(Self::Execute) diff --git a/crates/ui_ingame/src/lib.rs b/crates/ui_ingame/src/lib.rs index 98bd049..3d4f23f 100644 --- a/crates/ui_ingame/src/lib.rs +++ b/crates/ui_ingame/src/lib.rs @@ -15,7 +15,7 @@ use building_placement::SelectBuildingPreview; use combat::Range; use input::{SelectEntity, Selected}; use resources::{AvailableWorkers, Cost, ResourceDeposit, Resources, WorkedResourceDeposit}; -use state::{BasePhaseState, CoreState, Phase}; +use state::{BasePhaseState, CoreState, GameState, Phase}; use ui_state::GameUIState; use upgrade::{UnlockUpgrade, Upgradable, Upgrade}; @@ -32,6 +32,7 @@ impl Plugin for UiIngamePlugin { .run_if(in_state(GameUIState::Default).and(in_state(CoreState::Unplaced))), side_panel .run_if(in_state(GameUIState::Default).and(in_state(CoreState::Placed))), + game_over.run_if(in_state(GameState::GameOver)), 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( @@ -60,6 +61,7 @@ impl Plugin for UiIngamePlugin { } } +const MEGA_FONT_SIZE: f32 = 64.; const VERY_LARGE_FONT_SIZE: f32 = 48.; const LARGE_FONT_SIZE: f32 = 24.; const FONT_SIZE: f32 = 16.; @@ -176,7 +178,7 @@ fn transition_ui( }, curr_state.get().phase_count() )) - .size(64.), + .size(MEGA_FONT_SIZE), ); }); } @@ -352,8 +354,24 @@ fn place_core( .title_bar(false) .anchor(Align2::CENTER_BOTTOM, [0., 0.]) .show(ctx, |ui| { - if ui.button(RichText::new("COLONIZE").size(64.)).clicked() { + if ui + .button(RichText::new("COLONIZE").size(MEGA_FONT_SIZE)) + .clicked() + { selected_preview_writer.write(SelectBuildingPreview(Some(*core_preview))); } }); } + +fn game_over(mut contexts: EguiContexts) { + let ctx = contexts.ctx_mut().unwrap(); + + egui::Window::new("TRANSITION") + .collapsible(false) + .title_bar(false) + .anchor(Align2::CENTER_CENTER, [0., 0.]) + .fixed_size([600., 200.]) + .show(ctx, |ui| { + ui.label(RichText::new("TRANSMISSION END").size(MEGA_FONT_SIZE)); + }); +} diff --git a/crates/ui_pause/src/lib.rs b/crates/ui_pause/src/lib.rs index 4680390..d7ecbca 100755 --- a/crates/ui_pause/src/lib.rs +++ b/crates/ui_pause/src/lib.rs @@ -54,6 +54,7 @@ fn toggle_pause( GameState::Loading => GameState::Loading, GameState::Running => GameState::Paused, GameState::Paused => GameState::Running, + s @ _ => *s, }; info!("toggle pause, changing to {:?}", next); next_state.set(next);