update hui to 0.1.0-alpha.3, new loading screen

This commit is contained in:
griffi-gh 2024-02-20 22:23:34 +01:00
parent d5b23f62a4
commit 83353b4fd6
3 changed files with 74 additions and 17 deletions

25
Cargo.lock generated
View file

@ -528,6 +528,15 @@ dependencies = [
"libloading", "libloading",
] ]
[[package]]
name = "document-features"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef5282ad69563b5fc40319526ba27e0e7363d552a896f0297d54f767717f9b95"
dependencies = [
"litrs",
]
[[package]] [[package]]
name = "downcast-rs" name = "downcast-rs"
version = "1.2.0" version = "1.2.0"
@ -888,21 +897,23 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
[[package]] [[package]]
name = "hui" name = "hui"
version = "0.1.0-alpha.1" version = "0.1.0-alpha.3"
source = "git+https://github.com/griffi-gh/hui?rev=41049e5f#41049e5f59ab56d0e0bd3f813a6789d0935b5460" source = "git+https://github.com/griffi-gh/hui?rev=9bb95b3baff#9bb95b3baff69b0ddee67ee28c1d271e79668468"
dependencies = [ dependencies = [
"document-features",
"fontdue", "fontdue",
"glam", "glam",
"hashbrown 0.14.3", "hashbrown 0.14.3",
"log", "log",
"nohash-hasher", "nohash-hasher",
"nz",
"rect_packer", "rect_packer",
] ]
[[package]] [[package]]
name = "hui-glium" name = "hui-glium"
version = "0.1.0-alpha.1" version = "0.1.0-alpha.3"
source = "git+https://github.com/griffi-gh/hui?rev=41049e5f#41049e5f59ab56d0e0bd3f813a6789d0935b5460" source = "git+https://github.com/griffi-gh/hui?rev=9bb95b3baff#9bb95b3baff69b0ddee67ee28c1d271e79668468"
dependencies = [ dependencies = [
"glam", "glam",
"glium", "glium",
@ -1231,6 +1242,12 @@ version = "0.4.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c"
[[package]]
name = "litrs"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4ce301924b7887e9d637144fdade93f9dfff9b60981d4ac161db09720d39aa5"
[[package]] [[package]]
name = "lock_api" name = "lock_api"
version = "0.4.11" version = "0.4.11"

View file

@ -11,8 +11,8 @@ crate-type = ["lib", "cdylib"]
[dependencies] [dependencies]
kubi-shared = { path = "../kubi-shared" } kubi-shared = { path = "../kubi-shared" }
kubi-logging = { path = "../kubi-logging" } kubi-logging = { path = "../kubi-logging" }
hui = { version = "0.1.0-alpha.1", git = "https://github.com/griffi-gh/hui", rev = "41049e5f" } hui = { version = "0.1.0-alpha.3", git = "https://github.com/griffi-gh/hui", rev = "9bb95b3baff" }
hui-glium = { version = "0.1.0-alpha.1", git = "https://github.com/griffi-gh/hui", rev = "41049e5f" } hui-glium = { version = "0.1.0-alpha.3", git = "https://github.com/griffi-gh/hui", rev = "9bb95b3baff" }
log = "0.4" log = "0.4"
glium = { git = "https://github.com/glium/glium", rev = "a352c667" } glium = { git = "https://github.com/glium/glium", rev = "a352c667" }
glutin = "0.31" glutin = "0.31"

View file

@ -1,4 +1,8 @@
use hui::element::progress_bar::ProgressBar; use hui::{
element::{container::Container, progress_bar::ProgressBar, text::Text},
layout::{Alignment, UiSize},
rectangle::{Corners, Sides}
};
use shipyard::{UniqueView, UniqueViewMut, Workload, NonSendSync, IntoWorkload}; use shipyard::{UniqueView, UniqueViewMut, Workload, NonSendSync, IntoWorkload};
use winit::keyboard::KeyCode; use winit::keyboard::KeyCode;
use crate::{ use crate::{
@ -9,20 +13,56 @@ use crate::{
hui_integration::UiState, hui_integration::UiState,
}; };
fn render_progressbar( fn render_loading_ui(
mut ui: NonSendSync<UniqueViewMut<UiState>>, mut ui: NonSendSync<UniqueViewMut<UiState>>,
world: UniqueView<ChunkStorage>, world: UniqueView<ChunkStorage>,
size: UniqueView<WindowSize> size: UniqueView<WindowSize>
) { ) {
let value = {
let loaded = world.chunks.iter().fold(0, |acc, (&_, chunk)| { let loaded = world.chunks.iter().fold(0, |acc, (&_, chunk)| {
acc + chunk.desired_state.matches_current(chunk.current_state) as usize acc + chunk.desired_state.matches_current(chunk.current_state) as usize
}); });
let total = world.chunks.len(); let total = world.chunks.len();
loaded as f32 / total as f32 let value = loaded as f32 / total as f32;
}; let percentage = value * 100.;
ui.hui.add( ui.hui.add(
ProgressBar { value, ..Default::default() }, Container {
size: (UiSize::Fraction(1.), UiSize::Fraction(1.)),
background: (0.1, 0.1, 0.1, 1. - (value - 0.75).max(0.)).into(),
align: Alignment::Center.into(),
elements: vec![
Box::new(Container {
padding: Sides::all(10.),
gap: 10.,
background: (0.2, 0.2, 0.2).into(),
corner_radius: Corners::all(8.),
elements: vec![
Box::new(Text {
text: "Loading...".into(),
..Default::default()
}),
Box::new(ProgressBar {
value,
size: (UiSize::Static(400.), UiSize::Auto),
corner_radius: Corners::all(2.),
..Default::default()
}),
Box::new(Container {
size: (UiSize::Static(400.), UiSize::Auto),
align: (Alignment::End, Alignment::End).into(),
elements: vec![
Box::new(Text {
text: format!("{loaded}/{total} ({percentage:.1}%)").into(),
..Default::default()
})
],
..Default::default()
})
],
..Default::default()
})
],
..Default::default()
},
size.0.as_vec2() size.0.as_vec2()
); );
} }
@ -53,7 +93,7 @@ fn override_loading(
pub fn update_loading_screen() -> Workload { pub fn update_loading_screen() -> Workload {
( (
render_progressbar, render_loading_ui,
override_loading, override_loading,
switch_to_ingame_if_loaded, switch_to_ingame_if_loaded,
).into_sequential_workload() ).into_sequential_workload()