mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-12-26 05:38:20 -06:00
separate loading screen base
This commit is contained in:
parent
bd6fef60a0
commit
b9c721f9b6
|
@ -1,7 +1,7 @@
|
||||||
use hui::{
|
use hui::{
|
||||||
element::{container::Container, progress_bar::ProgressBar, text::Text},
|
element::{container::Container, progress_bar::ProgressBar, text::Text, UiElement},
|
||||||
layout::{Alignment, UiDirection, UiSize},
|
layout::{Alignment, UiDirection, UiSize},
|
||||||
rectangle::{Corners, Sides}
|
rectangle::{Corners, Sides}, UiInstance
|
||||||
};
|
};
|
||||||
use shipyard::{UniqueView, UniqueViewMut, Workload, NonSendSync, IntoWorkload};
|
use shipyard::{UniqueView, UniqueViewMut, Workload, NonSendSync, IntoWorkload};
|
||||||
use winit::keyboard::KeyCode;
|
use winit::keyboard::KeyCode;
|
||||||
|
@ -13,6 +13,25 @@ use crate::{
|
||||||
hui_integration::UiState,
|
hui_integration::UiState,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub fn loading_screen_base(elements: Vec<Box<dyn UiElement>>, bg_alpha: f32) -> Container {
|
||||||
|
Container {
|
||||||
|
size: (UiSize::Fraction(1.), UiSize::Fraction(1.)),
|
||||||
|
background: (0.1, 0.1, 0.1, bg_alpha).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,
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
],
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn render_loading_ui(
|
fn render_loading_ui(
|
||||||
mut ui: NonSendSync<UniqueViewMut<UiState>>,
|
mut ui: NonSendSync<UniqueViewMut<UiState>>,
|
||||||
world: UniqueView<ChunkStorage>,
|
world: UniqueView<ChunkStorage>,
|
||||||
|
@ -24,48 +43,30 @@ fn render_loading_ui(
|
||||||
let total = world.chunks.len();
|
let total = world.chunks.len();
|
||||||
let value = loaded as f32 / total as f32;
|
let value = loaded as f32 / total as f32;
|
||||||
let percentage = value * 100.;
|
let percentage = value * 100.;
|
||||||
ui.hui.add(
|
ui.hui.add(loading_screen_base(vec![
|
||||||
Container {
|
Box::new(Text {
|
||||||
size: (UiSize::Fraction(1.), UiSize::Fraction(1.)),
|
text: "Loading...".into(),
|
||||||
background: (0.1, 0.1, 0.1, 1. - (value - 0.75).max(0.)).into(),
|
..Default::default()
|
||||||
align: Alignment::Center.into(),
|
}),
|
||||||
|
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::Begin).into(),
|
||||||
|
direction: UiDirection::Horizontal,
|
||||||
elements: vec![
|
elements: vec![
|
||||||
Box::new(Container {
|
Box::new(Text {
|
||||||
padding: Sides::all(10.),
|
text: format!("{loaded}/{total} ({percentage:.1}%)").into(),
|
||||||
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::Begin).into(),
|
|
||||||
direction: UiDirection::Horizontal,
|
|
||||||
elements: vec![
|
|
||||||
Box::new(Text {
|
|
||||||
text: format!("{loaded}/{total} ({percentage:.1}%)").into(),
|
|
||||||
..Default::default()
|
|
||||||
})
|
|
||||||
],
|
|
||||||
..Default::default()
|
|
||||||
})
|
|
||||||
],
|
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
}),
|
||||||
size.0.as_vec2()
|
], 1. - (value - 0.75).max(0.)), size.0.as_vec2());
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn switch_to_ingame_if_loaded(
|
fn switch_to_ingame_if_loaded(
|
||||||
|
|
Loading…
Reference in a new issue