Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement loading screen #148

Merged
merged 2 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ wasm = [
[dependencies]
bevy = { version = "^0.9.1", default-features = false }
bevy_kira_audio = "0.13"
bevy_asset_loader = { git = "https://github.com/NiklasEi/bevy_asset_loader.git", rev = "9a7966c9e7a44026a2192292390b315d28c88ca7" }
bevy_asset_loader = { git = "https://github.com/NiklasEi/bevy_asset_loader.git", rev = "9a7966c9e7a44026a2192292390b315d28c88ca7", features = ["progress_tracking"] }
bevy_common_assets = { version = "0.4.0", features = ["ron", "toml"] }
bevy_egui = "0.19"
serde = { version = "1", features = ["derive"] }
Expand All @@ -63,6 +63,7 @@ glob = "0.3.1"
polyanya = "0.2.0"
bevy_pathmesh = "0.3.0"
bitflags = "1.3.2"
iyes_progress = "0.7.1"

# keep the following in sync with Bevy's dependencies
winit = { version = "0.27", default-features = false }
Expand Down
5 changes: 3 additions & 2 deletions src/dev.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::dev::scene_editor::SceneEditorPlugin;
use bevy::diagnostic::LogDiagnosticsPlugin;
use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin};
use bevy::prelude::*;
use bevy_editor_pls::prelude::*;
use bevy_prototype_debug_lines::DebugLinesPlugin;
Expand All @@ -15,9 +15,10 @@ impl Plugin for DevPlugin {
fn build(&self, app: &mut App) {
{
app.add_plugin(EditorPlugin)
.add_plugin(FrameTimeDiagnosticsPlugin::default())
.add_plugin(DebugLinesPlugin::default())
.add_plugin(SceneEditorPlugin)
.add_plugin(LogDiagnosticsPlugin::default())
.add_plugin(LogDiagnosticsPlugin::filtered(vec![]))
.add_plugin(RapierDebugRenderPlugin {
enabled: false,
..default()
Expand Down
32 changes: 29 additions & 3 deletions src/file_system_interaction/asset_loading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use bevy::utils::HashMap;
use bevy_asset_loader::prelude::*;
use bevy_common_assets::ron::RonAssetPlugin;
use bevy_common_assets::toml::TomlAssetPlugin;
use bevy_egui::egui::ProgressBar;
use bevy_egui::{egui, EguiContext};
use bevy_kira_audio::AudioSource;
use iyes_progress::{ProgressCounter, ProgressPlugin};

pub struct LoadingPlugin;

Expand All @@ -17,6 +20,7 @@ impl Plugin for LoadingPlugin {
app.add_plugin(RonAssetPlugin::<SerializedLevel>::new(&["lvl.ron"]))
.add_plugin(RonAssetPlugin::<Dialog>::new(&["dlg.ron"]))
.add_plugin(TomlAssetPlugin::<GameConfig>::new(&["game.toml"]))
.add_plugin(ProgressPlugin::new(GameState::Loading).continue_to(GameState::Menu))
.add_loading_state(
LoadingState::new(GameState::Loading)
.with_collection::<FontAssets>()
Expand All @@ -26,9 +30,9 @@ impl Plugin for LoadingPlugin {
.with_collection::<LevelAssets>()
.with_collection::<DialogAssets>()
.with_collection::<TextureAssets>()
.with_collection::<ConfigAssets>()
.continue_to_state(GameState::Menu),
);
.with_collection::<ConfigAssets>(),
)
.add_system_set(SystemSet::on_update(GameState::Loading).with_system(show_progress));
}
}

Expand Down Expand Up @@ -90,3 +94,25 @@ pub struct ConfigAssets {
#[asset(path = "config/config.game.toml")]
pub game: Handle<GameConfig>,
}

fn show_progress(
progress: Option<Res<ProgressCounter>>,
mut egui_context: ResMut<EguiContext>,
mut last_done: Local<u32>,
) {
if let Some(progress) = progress.map(|counter| counter.progress()) {
if progress.done > *last_done {
*last_done = progress.done;
}

egui::CentralPanel::default().show(egui_context.ctx_mut(), |ui| {
ui.vertical_centered_justified(|ui| {
ui.add_space(100.0);
ui.heading("Loading...");
ui.add(
ProgressBar::new(progress.done as f32 / progress.total as f32).animate(true),
);
});
});
}
}
2 changes: 1 addition & 1 deletion src/player_control/camera/third_person.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Default for ThirdPersonCamera {
Self {
up: Vec3::Y,
transform: default(),
distance: 1.,
distance: 5.,
target: default(),
secondary_target: default(),
config: default(),
Expand Down