Skip to content

Commit

Permalink
tweak loading screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Nertsal committed Dec 16, 2024
1 parent 9725cd8 commit 62fd5aa
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 deletions.
Binary file added assets/sprites/loading_background.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions src/assets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub use self::font::Font;

use ctl_client::core::types::MusicInfo;
use geng::prelude::*;
pub use geng_utils::gif::GifFrame;

use crate::prelude::Modifier;

Expand All @@ -20,6 +21,30 @@ pub struct LoadingAssets {
pub title: ugli::Texture,
#[load(path = "fonts/pixel.ttf")]
pub font: Font,
#[load(load_with = "load_gif(&manager, &base_path.join(\"sprites/loading_background.gif\"))")]
pub background: Vec<GifFrame>,
}

fn load_gif(
manager: &geng::asset::Manager,
path: &std::path::Path,
) -> geng::asset::Future<Vec<GifFrame>> {
let manager = manager.clone();
let path = path.to_owned();
async move {
geng_utils::gif::load_gif(
&manager,
&path,
geng_utils::gif::GifOptions {
frame: geng::asset::TextureOptions {
filter: ugli::Filter::Nearest,
..Default::default()
},
},
)
.await
}
.boxed_local()
}

#[derive(geng::asset::Load)]
Expand Down
35 changes: 27 additions & 8 deletions src/menu/loading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl<T: 'static> LoadingScreen<T> {
future: Some(Task::new(geng, future)),
result: None,

min_load_time: if insta_load { 0.0 } else { 4.6 },
min_load_time: if insta_load { 0.0 } else { 4.3 },
real_time: 0.0,
texts: vec![
"Loading assets...",
Expand Down Expand Up @@ -127,12 +127,31 @@ impl<T: 'static> geng::State for LoadingScreen<T> {
ugli::clear(framebuffer, Some(self.options.theme.dark), None, None);

let framebuffer_size = framebuffer.size().as_f32();
let font_size = framebuffer_size.y * 0.07;
let font_size = framebuffer_size.y * 0.09;
let theme = self.options.theme;

let screen = Aabb2::ZERO.extend_positive(framebuffer_size);
let camera = &geng::PixelPerfectCamera;

// Background
{
let gif = &self.assets.background;
let duration: f32 = gif.iter().map(|frame| frame.duration).sum();
let mut time = (self.real_time as f32 / duration).fract() * duration;
if let Some(frame) = gif.iter().find(|frame| {
time -= frame.duration;
time <= 0.0
}) {
self.geng.draw2d().textured_quad(
framebuffer,
camera,
screen,
&frame.texture,
Color::WHITE,
);
}
}

// Fake loading bar
let size = vec2(10.0, 0.8) * font_size;
let load_bar = Aabb2::point(screen.center() + vec2(0.0, -font_size * 2.0))
Expand All @@ -152,7 +171,7 @@ impl<T: 'static> geng::State for LoadingScreen<T> {
let title = geng_utils::pixel::pixel_perfect_aabb(
screen.align_pos(vec2(0.5, 0.8)),
vec2(0.5, 0.5),
self.assets.title.size() * (framebuffer.size().y / 360),
self.assets.title.size() * 2 * (framebuffer.size().y / 360),
camera,
framebuffer_size,
);
Expand All @@ -166,7 +185,7 @@ impl<T: 'static> geng::State for LoadingScreen<T> {

// Funny text
if let Some(text) = self.texts.get(self.current_text) {
let pos = screen.align_pos(vec2(0.5, 0.5));
let pos = screen.align_pos(vec2(0.5, 0.45));
self.draw_text(
framebuffer,
camera,
Expand All @@ -177,21 +196,21 @@ impl<T: 'static> geng::State for LoadingScreen<T> {
}

{
let font_size = font_size * 0.7;
let font_size = font_size * 0.9;
self.draw_text(
framebuffer,
camera,
"music by IcyLava",
vec2(2.0, 2.0) * font_size,
screen.align_pos(vec2(0.5, 0.65)) + vec2(7.0, 0.0) * font_size,
TextRenderOptions::new(font_size)
.align(vec2(0.0, 0.5))
.align(vec2(1.0, 0.5))
.color(theme.light),
);
self.draw_text(
framebuffer,
camera,
"by Nertsal",
vec2(2.0, 3.2) * font_size,
screen.align_pos(vec2(0.5, 0.65)) - vec2(7.0, 0.0) * font_size,
TextRenderOptions::new(font_size)
.align(vec2(0.0, 0.5))
.color(theme.light),
Expand Down

0 comments on commit 62fd5aa

Please sign in to comment.