diff options
author | metamuffin <metamuffin@disroot.org> | 2024-07-25 14:53:55 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-07-25 14:53:55 +0200 |
commit | bd777ff17258293c83b3a086d765b38bb9fe5197 (patch) | |
tree | 253fba54bfcee9be97311900a0b361c1bcc3951e /pixel-client/src/menu.rs | |
parent | 3c056d68fe9c28b0c867a8d8bb3d4394745296d0 (diff) | |
download | hurrycurry-bd777ff17258293c83b3a086d765b38bb9fe5197.tar hurrycurry-bd777ff17258293c83b3a086d765b38bb9fe5197.tar.bz2 hurrycurry-bd777ff17258293c83b3a086d765b38bb9fe5197.tar.zst |
pc: join and quit button
Diffstat (limited to 'pixel-client/src/menu.rs')
-rw-r--r-- | pixel-client/src/menu.rs | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/pixel-client/src/menu.rs b/pixel-client/src/menu.rs index bce5198b..9ebe525e 100644 --- a/pixel-client/src/menu.rs +++ b/pixel-client/src/menu.rs @@ -1,7 +1,10 @@ use crate::{ + game::Game, + network::Network, render::{sprite::SpriteDraw, AtlasLayout, Renderer}, tilemap::Tilemap, ui::UiState, + State, }; use hurrycurry_protocol::{ glam::{IVec2, Vec2}, @@ -13,12 +16,12 @@ use sdl2::{ mouse::MouseState, }; -#[derive(Debug)] pub struct Menu { map: Tilemap, fade_in: f32, ui_state: UiState, background: Vec2, + next_state: Option<Box<State>>, } impl Menu { @@ -56,6 +59,7 @@ impl Menu { fade_in: 0., ui_state: UiState::default(), background: Vec2::ZERO, + next_state: None, } } pub fn tick( @@ -64,10 +68,12 @@ impl Menu { keyboard: &KeyboardState, mouse: &MouseState, _layout: &AtlasLayout, - ) { + ) -> Option<Box<State>> { self.fade_in = (self.fade_in + dt).min(1.); self.background += Vec2::new(2., 3.) * dt; self.ui_state.update(keyboard, mouse, dt); + + self.next_state.take() } pub fn keyboard_event(&mut self, keycode: Keycode, down: bool) { self.ui_state.keyboard_event(keycode, down); @@ -97,18 +103,25 @@ impl Menu { self.map.draw(ctx); + let mut request_join = false; self.ui_state.draw(ctx, |ui| { if ui.button(80., "Join") { - eprintln!("join button") + request_join = true } if ui.button(80., "Settings") { eprintln!("settings button") } if ui.button(80., "Quit") { - eprintln!("quit button") + self.next_state = Some(Box::new(State::Quit)); } ui.fill(); }); + if request_join { + self.next_state = Some(Box::new(State::Ingame(Box::new(Game::new( + Network::connect("ws://127.0.0.1").unwrap(), + ctx.atlas_layout(), + ))))) + } ctx.draw_ui(SpriteDraw::overlay( ctx.misc_textures.solid, |