summaryrefslogtreecommitdiff
path: root/pixel-client/src/menu.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-07-25 13:50:09 +0200
committermetamuffin <metamuffin@disroot.org>2024-07-25 13:50:09 +0200
commitecb6ff15c24841dc08ab8f5c3b347c8080720ac4 (patch)
treed53db2a61a6151af970f9d27a617d12e0cac7588 /pixel-client/src/menu.rs
parentbc210b2632891ca163d31fb57bc0c41769249bf5 (diff)
downloadhurrycurry-ecb6ff15c24841dc08ab8f5c3b347c8080720ac4.tar
hurrycurry-ecb6ff15c24841dc08ab8f5c3b347c8080720ac4.tar.bz2
hurrycurry-ecb6ff15c24841dc08ab8f5c3b347c8080720ac4.tar.zst
pc: main menu background
Diffstat (limited to 'pixel-client/src/menu.rs')
-rw-r--r--pixel-client/src/menu.rs52
1 files changed, 47 insertions, 5 deletions
diff --git a/pixel-client/src/menu.rs b/pixel-client/src/menu.rs
index 22a0244a..0d63d4e7 100644
--- a/pixel-client/src/menu.rs
+++ b/pixel-client/src/menu.rs
@@ -1,6 +1,7 @@
use crate::{
- render::{AtlasLayout, Renderer},
+ render::{sprite::SpriteDraw, AtlasLayout, Renderer},
tilemap::Tilemap,
+ ui::UiState,
};
use hurrycurry_protocol::{
glam::{IVec2, Vec2},
@@ -12,6 +13,9 @@ use sdl2::keyboard::KeyboardState;
#[derive(Debug)]
pub struct Menu {
map: Tilemap,
+ fade_in: f32,
+ ui_state: UiState,
+ background: Vec2,
}
impl Menu {
@@ -44,15 +48,53 @@ impl Menu {
}
}
- Self { map }
+ Self {
+ map,
+ fade_in: 0.,
+ ui_state: UiState::default(),
+ background: Vec2::ZERO,
+ }
+ }
+ pub fn tick(&mut self, dt: f32, _keyboard: &KeyboardState, _layout: &AtlasLayout) {
+ self.fade_in = (self.fade_in + dt).min(1.);
+ self.background += Vec2::new(2., 3.) * dt;
}
- pub fn tick(&mut self, _dt: f32, _keyboard: &KeyboardState, _layout: &AtlasLayout) {}
- pub fn draw(&self, ctx: &mut Renderer) {
+ pub fn draw(&mut self, ctx: &mut Renderer) {
ctx.set_world_view(
ctx.size / ctx.get_world_scale() * Vec2::new(0.8, 0.2),
ctx.size.max_element() / 32. / 15.,
);
+
+ for x in -1..=2 {
+ for y in -1..=2 {
+ ctx.draw_ui(SpriteDraw::underlay(
+ ctx.misc_textures.clouds,
+ Vec2::new(x as f32, y as f32) * 256. + self.background,
+ Vec2::ONE * 256.,
+ None,
+ ));
+ }
+ }
+ ctx.draw_ui(SpriteDraw::underlay(
+ ctx.misc_textures.solid,
+ Vec2::ZERO,
+ ctx.ui_size,
+ Some([0, 0, 0, 50]),
+ ));
+
self.map.draw(ctx);
- ctx.draw_text(Vec2::new(1., 1.), "Hello world!");
+
+ self.ui_state.draw(ctx, |ui| {
+ ui.button("Join");
+ ui.button("Settings");
+ ui.button("Quit");
+ });
+
+ ctx.draw_ui(SpriteDraw::overlay(
+ ctx.misc_textures.solid,
+ Vec2::ZERO,
+ ctx.ui_size,
+ Some([0, 0, 0, 255 - (self.fade_in * 255.) as u8]),
+ ));
}
}