upgrade to hui = "0.1.0-alpha.4"

This commit is contained in:
griffi-gh 2024-03-25 19:06:35 +01:00
parent f0270e3ce5
commit 7ead258028
7 changed files with 174 additions and 103 deletions

106
Cargo.lock generated
View file

@ -382,6 +382,12 @@ dependencies = [
"crossbeam-utils",
]
[[package]]
name = "convert_case"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
[[package]]
name = "core-foundation"
version = "0.9.4"
@ -489,7 +495,7 @@ dependencies = [
"proc-macro2",
"quote",
"strsim",
"syn",
"syn 2.0.49",
]
[[package]]
@ -500,7 +506,7 @@ checksum = "c5a91391accf613803c2a9bf9abccdbaa07c54b4244a5b64883f9c3c137c86be"
dependencies = [
"darling_core",
"quote",
"syn",
"syn 2.0.49",
]
[[package]]
@ -513,6 +519,31 @@ dependencies = [
"serde",
]
[[package]]
name = "derive_more"
version = "0.99.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321"
dependencies = [
"convert_case",
"proc-macro2",
"quote",
"rustc_version",
"syn 1.0.109",
]
[[package]]
name = "derive_setters"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e8ef033054e131169b8f0f9a7af8f5533a9436fadf3c500ed547f730f07090d"
dependencies = [
"darling",
"proc-macro2",
"quote",
"syn 2.0.49",
]
[[package]]
name = "dispatch"
version = "0.2.0"
@ -649,7 +680,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.49",
]
[[package]]
@ -747,9 +778,9 @@ dependencies = [
[[package]]
name = "glam"
version = "0.25.0"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "151665d9be52f9bb40fc7966565d39666f2d1e69233571b71b87791c7e0528b3"
checksum = "9e05e7e6723e3455f4818c7b26e855439f7546cf617ef669d1adedb8669e5cb9"
dependencies = [
"serde",
]
@ -897,23 +928,36 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
[[package]]
name = "hui"
version = "0.1.0-alpha.3"
source = "git+https://github.com/griffi-gh/hui?rev=9bb95b3baff#9bb95b3baff69b0ddee67ee28c1d271e79668468"
version = "0.1.0-alpha.4"
source = "git+https://github.com/griffi-gh/hui?rev=dd5af8b9e2#dd5af8b9e2dc4cb2beb0b130d82167258ea2bd4e"
dependencies = [
"derive_more",
"derive_setters",
"document-features",
"fontdue",
"glam",
"hashbrown 0.14.3",
"hui-derive",
"image 0.25.0",
"log",
"nohash-hasher",
"nz",
"rect_packer",
"tinyset",
]
[[package]]
name = "hui-derive"
version = "0.1.0-alpha.4"
source = "git+https://github.com/griffi-gh/hui?rev=dd5af8b9e2#dd5af8b9e2dc4cb2beb0b130d82167258ea2bd4e"
dependencies = [
"quote",
"syn 2.0.49",
]
[[package]]
name = "hui-glium"
version = "0.1.0-alpha.3"
source = "git+https://github.com/griffi-gh/hui?rev=9bb95b3baff#9bb95b3baff69b0ddee67ee28c1d271e79668468"
version = "0.1.0-alpha.4"
source = "git+https://github.com/griffi-gh/hui?rev=dd5af8b9e2#dd5af8b9e2dc4cb2beb0b130d82167258ea2bd4e"
dependencies = [
"glam",
"glium",
@ -980,6 +1024,17 @@ dependencies = [
"png",
]
[[package]]
name = "image"
version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9b4f005360d32e9325029b38ba47ebd7a56f3316df09249368939562d518645"
dependencies = [
"bytemuck",
"byteorder",
"num-traits",
]
[[package]]
name = "indexmap"
version = "1.9.3"
@ -1110,7 +1165,7 @@ dependencies = [
"hashbrown 0.14.3",
"hui",
"hui-glium",
"image",
"image 0.24.8",
"kubi-logging",
"kubi-shared",
"log",
@ -1403,7 +1458,7 @@ dependencies = [
"proc-macro-crate",
"proc-macro2",
"quote",
"syn",
"syn 2.0.49",
]
[[package]]
@ -1824,7 +1879,7 @@ checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.49",
]
[[package]]
@ -1874,7 +1929,7 @@ dependencies = [
"darling",
"proc-macro2",
"quote",
"syn",
"syn 2.0.49",
]
[[package]]
@ -1897,7 +1952,7 @@ source = "git+https://github.com/leudz/shipyard?rev=9099b990e#9099b990e332229f7e
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.49",
]
[[package]]
@ -2013,7 +2068,18 @@ dependencies = [
"proc-macro2",
"quote",
"rustversion",
"syn",
"syn 2.0.49",
]
[[package]]
name = "syn"
version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
@ -2059,7 +2125,7 @@ checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.49",
]
[[package]]
@ -2270,7 +2336,7 @@ dependencies = [
"once_cell",
"proc-macro2",
"quote",
"syn",
"syn 2.0.49",
"wasm-bindgen-shared",
]
@ -2304,7 +2370,7 @@ checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.49",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
@ -2829,5 +2895,5 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.49",
]

View file

@ -11,7 +11,7 @@ log = "0.4"
shipyard = { git = "https://github.com/leudz/shipyard", rev = "9099b990e", default-features = false, features = ["std", "proc", "thread_local"] }
serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] }
toml = "0.8"
glam = { version = "0.25", features = ["debug-glam-assert", "fast-math"] }
glam = { version = "0.27", features = ["debug-glam-assert", "fast-math"] }
hashbrown = "0.14"
nohash-hasher = "0.2"
anyhow = "1.0"

View file

@ -5,7 +5,7 @@ edition = "2021"
publish = false
[dependencies]
glam = { version = "0.25", features = ["debug-glam-assert", "fast-math", "serde"] }
glam = { version = "0.27", features = ["debug-glam-assert", "fast-math", "serde"] }
shipyard = { git = "https://github.com/leudz/shipyard", rev = "9099b990e", default-features = false, features = ["std"] }
strum = { version = "0.26", features = ["derive"] }
num_enum = "0.7"

View file

@ -11,15 +11,15 @@ crate-type = ["lib", "cdylib"]
[dependencies]
kubi-shared = { path = "../kubi-shared" }
kubi-logging = { path = "../kubi-logging" }
hui = { version = "0.1.0-alpha.3", git = "https://github.com/griffi-gh/hui", rev = "9bb95b3baff" }
hui-glium = { version = "0.1.0-alpha.3", git = "https://github.com/griffi-gh/hui", rev = "9bb95b3baff" }
hui = { version = "0.1.0-alpha.4", git = "https://github.com/griffi-gh/hui", rev = "dd5af8b9e2" }
hui-glium = { version = "0.1.0-alpha.4", git = "https://github.com/griffi-gh/hui", rev = "dd5af8b9e2" }
log = "0.4"
glium = { git = "https://github.com/glium/glium", rev = "a352c667" }
glutin = "0.31"
winit = { version = "0.29", features = ["android-native-activity"] }
glutin-winit = "0.4"
raw-window-handle = "=0.5.*"
glam = { version = "0.25", features = ["debug-glam-assert", "fast-math"] }
glam = { version = "0.27", features = ["debug-glam-assert", "fast-math"] }
image = { version = "0.24", default_features = false, features = ["png"] }
strum = { version = "0.26", features = ["derive"] }
hashbrown = "0.14"

View file

@ -75,7 +75,8 @@ pub fn load_prefabs(
let asset_handle = assman.open_asset(Path::new("fonts/Crisp.ttf")).unwrap();
let mut font_data = vec![];
BufReader::new(asset_handle).read_to_end(&mut font_data).unwrap();
let font_handle = ui.hui.add_font_from_bytes(&font_data);
let font_handle = ui.hui.add_font(&font_data);
ui.hui.push_font(font_handle);
storages.add_unique(UiFontPrefab(font_handle));
}

View file

@ -1,11 +1,10 @@
use hui::element::text::Text;
use hui::element::{text::Text, UiElementExt};
use kubi_shared::networking::state::ClientJoinState;
use shipyard::{IntoWorkload, NonSendSync, UniqueView, UniqueViewMut, Workload};
use crate::{
hui_integration::UiState,
loading_screen::loading_screen_base,
networking::{ConnectionRejectionReason, ServerAddress},
prefabs::UiFontPrefab,
rendering::WindowSize,
state::{GameState, NextState}
};
@ -15,24 +14,25 @@ fn render_connecting_ui(
rejection: Option<UniqueView<ConnectionRejectionReason>>,
join_state: UniqueView<ClientJoinState>,
mut ui: NonSendSync<UniqueViewMut<UiState>>,
font: UniqueView<UiFontPrefab>,
size: UniqueView<WindowSize>,
) {
ui.hui.add(
loading_screen_base(vec![
Box::new(Text {
text: match (rejection, *join_state) {
(Some(err), _) => format!("Connection rejected by {}\n\n{}", addr.0, err.reason).into(),
(_, ClientJoinState::Disconnected) => format!("Lost connection to {}", addr.0).into(),
_ => format!("Connecting to {}...", addr.0).into(),
},
font: font.0,
text_size: 16,
..Default::default()
}),
], 1.),
size.0.as_vec2(),
);
let text = match (rejection, *join_state) {
(Some(err), _) => {
format!("Connection rejected by {}\n\n{}", addr.0, err.reason)
},
(_, ClientJoinState::Disconnected) => {
format!("Lost connection to {}", addr.0)
},
_ => {
format!("Connecting to {}...", addr.0)
},
};
loading_screen_base(1., |ui| {
Text::new(text)
.with_text_size(16)
.add_child(ui);
}).add_root(&mut ui.hui, size.0.as_vec2())
}
fn switch_to_loading_if_connected(

View file

@ -1,38 +1,48 @@
use hui::{
element::{container::Container, progress_bar::ProgressBar, text::Text, UiElement},
layout::{Alignment, UiDirection, UiSize},
rectangle::{Corners, Sides},
element::{
container::Container,
progress_bar::ProgressBar,
text::Text,
ElementList,
UiElementExt,
},
layout::{Alignment, Direction},
frame_rect, size,
};
use shipyard::{UniqueView, UniqueViewMut, Workload, NonSendSync, IntoWorkload};
use winit::keyboard::KeyCode;
use crate::{
hui_integration::UiState, input::RawKbmInputState, networking::ServerAddress, prefabs::UiFontPrefab, rendering::WindowSize, state::{GameState, NextState}, world::ChunkStorage
hui_integration::UiState,
input::RawKbmInputState,
networking::ServerAddress,
rendering::WindowSize,
state::{GameState, NextState},
world::ChunkStorage,
};
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: 5.,
background: (0.2, 0.2, 0.2).into(),
corner_radius: Corners::all(8.),
elements,
..Default::default()
})
],
..Default::default()
}
pub fn loading_screen_base(bg_alpha: f32, xui: impl FnOnce(&mut ElementList)) -> Container {
Container::default()
.with_size(size!(100%))
.with_background((0.1, 0.1, 0.1, bg_alpha))
.with_align(Alignment::Center)
.with_children(|ui| {
Container::default()
.with_size(size!(400, auto))
.with_background(frame_rect! {
color: (0.2, 0.2, 0.2),
corner_radius: 8.
})
.with_gap(5.)
.with_padding(10.)
.with_children(xui)
.add_child(ui);
})
}
fn render_loading_ui(
addr: Option<UniqueView<ServerAddress>>,
world: UniqueView<ChunkStorage>,
mut ui: NonSendSync<UniqueViewMut<UiState>>,
font: UniqueView<UiFontPrefab>,
size: UniqueView<WindowSize>
) {
let loaded = world.chunks.iter().fold(0, |acc, (&_, chunk)| {
@ -42,44 +52,38 @@ fn render_loading_ui(
let value = loaded as f32 / total as f32;
let percentage = value * 100.;
ui.hui.add(loading_screen_base(vec![
Box::new(Text {
text: match addr {
Some(addr) => format!("Connected to {}\nDownloading world data...", addr.0).into(),
loading_screen_base(1. - (value - 0.75).max(0.), |ui| {
Text::new(match addr {
Some(addr) => format!("Connected to {}\nDownloading world data...", addr.0),
_ => "Loading...".into(),
},
font: font.0,
text_size: 16,
..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(),
font: font.0,
text_size: 16,
..Default::default()
})
],
..Default::default()
}),
// Box::new(Text {
// text: "--------------------------------------------------\nTip: You can press F to skip this loading screen".into(),
// font: font_handle,
// text_size: 16,
// color: (0.5, 0.5, 0.5, 1.).into(),
// ..Default::default()
// })
], 1. - (value - 0.75).max(0.)), size.0.as_vec2());
})
.with_text_size(16)
.add_child(ui);
ProgressBar::default()
.with_value(value)
.with_size(size!(100%, 15))
.with_background(frame_rect! {
color: (0.1, 0.1, 0.1),
corner_radius: 2.
})
.with_foreground(frame_rect! {
color: (0.4, 0.4, 1.0),
corner_radius: 2.
})
.add_child(ui);
Container::default()
.with_size(size!(100%, auto))
.with_align((Alignment::End, Alignment::Begin))
.with_direction(Direction::Horizontal)
.with_children(|ui| {
Text::new(format!("{loaded}/{total} ({percentage:.1}%)"))
.with_text_size(16)
.add_child(ui)
})
.add_child(ui);
}).add_root(&mut ui.hui, size.0.as_vec2());
}
fn switch_to_ingame_if_loaded(